• 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(const char* datafile = NULL,
56     uint64_t sample_period = kDefaultInstrumentationSamplingPeriod);
57   ~Instrument();
58 
59   // Declare all Visitor functions.
60   #define DECLARE(A) void Visit##A(Instruction* instr);
61   VISITOR_LIST(DECLARE)
62   #undef DECLARE
63 
64  private:
65   void Update();
66   void Enable();
67   void Disable();
68   void DumpCounters();
69   void DumpCounterNames();
70   void DumpEventMarker(unsigned marker);
71   void HandleInstrumentationEvent(unsigned event);
72   Counter* GetCounter(const char* name);
73 
74   void InstrumentLoadStore(Instruction* instr);
75   void InstrumentLoadStorePair(Instruction* instr);
76 
77   std::list<Counter*> counters_;
78 
79   FILE *output_stream_;
80   uint64_t sample_period_;
81 };
82 
83 }  // namespace internal
84 }  // namespace v8
85 
86 #endif  // V8_ARM64_INSTRUMENT_ARM64_H_
87