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