Instrument-vixl.h (3443B)
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 "mozilla/Vector.h" 31 32 #include "jit/arm64/vixl/Constants-vixl.h" 33 #include "jit/arm64/vixl/Decoder-vixl.h" 34 #include "jit/arm64/vixl/Globals-vixl.h" 35 #include "jit/arm64/vixl/Utils-vixl.h" 36 #include "js/AllocPolicy.h" 37 38 namespace vixl { 39 40 const int kCounterNameMaxLength = 256; 41 const uint64_t kDefaultInstrumentationSamplingPeriod = 1 << 22; 42 43 44 enum InstrumentState { 45 InstrumentStateDisable = 0, 46 InstrumentStateEnable = 1 47 }; 48 49 50 enum CounterType { 51 Gauge = 0, // Gauge counters reset themselves after reading. 52 Cumulative = 1 // Cumulative counters keep their value after reading. 53 }; 54 55 56 class Counter { 57 public: 58 explicit Counter(const char* name, CounterType type = Gauge); 59 60 void Increment(); 61 void Enable(); 62 void Disable(); 63 bool IsEnabled(); 64 uint64_t count(); 65 const char* name(); 66 CounterType type(); 67 68 private: 69 char name_[kCounterNameMaxLength]; 70 uint64_t count_; 71 bool enabled_; 72 CounterType type_; 73 }; 74 75 76 class Instrument: public DecoderVisitor { 77 public: 78 explicit Instrument(const char* datafile = NULL, 79 uint64_t sample_period = kDefaultInstrumentationSamplingPeriod); 80 ~Instrument(); 81 82 void Enable(); 83 void Disable(); 84 85 // Declare all Visitor functions. 86 #define DECLARE(A) void Visit##A(const Instruction* instr) override; 87 VISITOR_LIST(DECLARE) 88 #undef DECLARE 89 90 private: 91 void Update(); 92 void DumpCounters(); 93 void DumpCounterNames(); 94 void DumpEventMarker(unsigned marker); 95 void HandleInstrumentationEvent(unsigned event); 96 Counter* GetCounter(const char* name); 97 98 void InstrumentLoadStore(const Instruction* instr); 99 void InstrumentLoadStorePair(const Instruction* instr); 100 101 mozilla::Vector<Counter*, 8, js::SystemAllocPolicy> counters_; 102 103 FILE *output_stream_; 104 uint64_t sample_period_; 105 }; 106 107 } // namespace vixl 108 109 #endif // VIXL_A64_INSTRUMENT_A64_H_