• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_ARM64_INSTRUMENT_ARM64_H_
6 #define V8_ARM64_INSTRUMENT_ARM64_H_
7 
8 #include "src/globals.h"
9 #include "src/utils.h"
10 
11 #include "src/arm64/constants-arm64.h"
12 #include "src/arm64/decoder-arm64.h"
13 
14 namespace v8 {
15 namespace internal {
16 
17 const int kCounterNameMaxLength = 256;
18 const uint64_t kDefaultInstrumentationSamplingPeriod = 1 << 22;
19 
20 
21 enum InstrumentState {
22   InstrumentStateDisable = 0,
23   InstrumentStateEnable = 1
24 };
25 
26 
27 enum CounterType {
28   Gauge = 0,      // Gauge counters reset themselves after reading.
29   Cumulative = 1  // Cumulative counters keep their value after reading.
30 };
31 
32 
33 class Counter {
34  public:
35   explicit Counter(const char* name, CounterType type = Gauge);
36 
37   void Increment();
38   void Enable();
39   void Disable();
40   bool IsEnabled();
41   uint64_t count();
42   const char* name();
43   CounterType type();
44 
45  private:
46   char name_[kCounterNameMaxLength];
47   uint64_t count_;
48   bool enabled_;
49   CounterType type_;
50 };
51 
52 
53 class Instrument: public DecoderVisitor {
54  public:
55   explicit Instrument(
56       const char* datafile = nullptr,
57       uint64_t sample_period = kDefaultInstrumentationSamplingPeriod);
58   ~Instrument();
59 
60   // Declare all Visitor functions.
61   #define DECLARE(A) void Visit##A(Instruction* instr);
62   VISITOR_LIST(DECLARE)
63   #undef DECLARE
64 
65  private:
66   void Update();
67   void Enable();
68   void Disable();
69   void DumpCounters();
70   void DumpCounterNames();
71   void DumpEventMarker(unsigned marker);
72   void HandleInstrumentationEvent(unsigned event);
73   Counter* GetCounter(const char* name);
74 
75   void InstrumentLoadStore(Instruction* instr);
76   void InstrumentLoadStorePair(Instruction* instr);
77 
78   std::list<Counter*> counters_;
79 
80   FILE *output_stream_;
81   uint64_t sample_period_;
82 };
83 
84 }  // namespace internal
85 }  // namespace v8
86 
87 #endif  // V8_ARM64_INSTRUMENT_ARM64_H_
88