OLD | NEW |
| (Empty) |
1 // Copyright 2013 the V8 project authors. All rights reserved. | |
2 // Redistribution and use in source and binary forms, with or without | |
3 // modification, are permitted provided that the following conditions are | |
4 // met: | |
5 // | |
6 // * Redistributions of source code must retain the above copyright | |
7 // notice, this list of conditions and the following disclaimer. | |
8 // * Redistributions in binary form must reproduce the above | |
9 // copyright notice, this list of conditions and the following | |
10 // disclaimer in the documentation and/or other materials provided | |
11 // with the distribution. | |
12 // * Neither the name of Google Inc. nor the names of its | |
13 // contributors may be used to endorse or promote products derived | |
14 // from this software without specific prior written permission. | |
15 // | |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
27 | |
28 #ifndef V8_A64_INSTRUMENT_A64_H_ | |
29 #define V8_A64_INSTRUMENT_A64_H_ | |
30 | |
31 #include "globals.h" | |
32 #include "utils.h" | |
33 #include "a64/decoder-a64.h" | |
34 #include "a64/constants-a64.h" | |
35 | |
36 namespace v8 { | |
37 namespace internal { | |
38 | |
39 const int kCounterNameMaxLength = 256; | |
40 const uint64_t kDefaultInstrumentationSamplingPeriod = 1 << 22; | |
41 | |
42 | |
43 enum InstrumentState { | |
44 InstrumentStateDisable = 0, | |
45 InstrumentStateEnable = 1 | |
46 }; | |
47 | |
48 | |
49 enum CounterType { | |
50 Gauge = 0, // Gauge counters reset themselves after reading. | |
51 Cumulative = 1 // Cumulative counters keep their value after reading. | |
52 }; | |
53 | |
54 | |
55 class Counter { | |
56 public: | |
57 Counter(const char* name, CounterType type = Gauge); | |
58 | |
59 void Increment(); | |
60 void Enable(); | |
61 void Disable(); | |
62 bool IsEnabled(); | |
63 uint64_t count(); | |
64 const char* name(); | |
65 CounterType type(); | |
66 | |
67 private: | |
68 char name_[kCounterNameMaxLength]; | |
69 uint64_t count_; | |
70 bool enabled_; | |
71 CounterType type_; | |
72 }; | |
73 | |
74 | |
75 class Instrument: public DecoderVisitor { | |
76 public: | |
77 explicit Instrument(const char* datafile = NULL, | |
78 uint64_t sample_period = kDefaultInstrumentationSamplingPeriod); | |
79 ~Instrument(); | |
80 | |
81 // Declare all Visitor functions. | |
82 #define DECLARE(A) void Visit##A(Instruction* instr); | |
83 VISITOR_LIST(DECLARE) | |
84 #undef DECLARE | |
85 | |
86 private: | |
87 void Update(); | |
88 void Enable(); | |
89 void Disable(); | |
90 void DumpCounters(); | |
91 void DumpCounterNames(); | |
92 void DumpEventMarker(unsigned marker); | |
93 void HandleInstrumentationEvent(unsigned event); | |
94 Counter* GetCounter(const char* name); | |
95 | |
96 void InstrumentLoadStore(Instruction* instr); | |
97 void InstrumentLoadStorePair(Instruction* instr); | |
98 | |
99 std::list<Counter*> counters_; | |
100 | |
101 FILE *output_stream_; | |
102 uint64_t sample_period_; | |
103 }; | |
104 | |
105 } } // namespace v8::internal | |
106 | |
107 #endif // V8_A64_INSTRUMENT_A64_H_ | |
OLD | NEW |