10cc8b6ece4b3e757e11a906a81ece292437713abarmvixl// Copyright 2014, ARM Limited 2578645f14e122d2b87d907e298cda7e7d0babf1farmvixl// All rights reserved. 3578645f14e122d2b87d907e298cda7e7d0babf1farmvixl// 4578645f14e122d2b87d907e298cda7e7d0babf1farmvixl// Redistribution and use in source and binary forms, with or without 5578645f14e122d2b87d907e298cda7e7d0babf1farmvixl// modification, are permitted provided that the following conditions are met: 6578645f14e122d2b87d907e298cda7e7d0babf1farmvixl// 7578645f14e122d2b87d907e298cda7e7d0babf1farmvixl// * Redistributions of source code must retain the above copyright notice, 8578645f14e122d2b87d907e298cda7e7d0babf1farmvixl// this list of conditions and the following disclaimer. 9578645f14e122d2b87d907e298cda7e7d0babf1farmvixl// * Redistributions in binary form must reproduce the above copyright notice, 10578645f14e122d2b87d907e298cda7e7d0babf1farmvixl// this list of conditions and the following disclaimer in the documentation 11578645f14e122d2b87d907e298cda7e7d0babf1farmvixl// and/or other materials provided with the distribution. 12578645f14e122d2b87d907e298cda7e7d0babf1farmvixl// * Neither the name of ARM Limited nor the names of its contributors may be 13578645f14e122d2b87d907e298cda7e7d0babf1farmvixl// used to endorse or promote products derived from this software without 14578645f14e122d2b87d907e298cda7e7d0babf1farmvixl// specific prior written permission. 15578645f14e122d2b87d907e298cda7e7d0babf1farmvixl// 16578645f14e122d2b87d907e298cda7e7d0babf1farmvixl// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND 17578645f14e122d2b87d907e298cda7e7d0babf1farmvixl// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18578645f14e122d2b87d907e298cda7e7d0babf1farmvixl// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19578645f14e122d2b87d907e298cda7e7d0babf1farmvixl// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20578645f14e122d2b87d907e298cda7e7d0babf1farmvixl// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21578645f14e122d2b87d907e298cda7e7d0babf1farmvixl// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22578645f14e122d2b87d907e298cda7e7d0babf1farmvixl// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23578645f14e122d2b87d907e298cda7e7d0babf1farmvixl// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24578645f14e122d2b87d907e298cda7e7d0babf1farmvixl// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25578645f14e122d2b87d907e298cda7e7d0babf1farmvixl// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26578645f14e122d2b87d907e298cda7e7d0babf1farmvixl 27578645f14e122d2b87d907e298cda7e7d0babf1farmvixl#ifndef VIXL_A64_INSTRUMENT_A64_H_ 28578645f14e122d2b87d907e298cda7e7d0babf1farmvixl#define VIXL_A64_INSTRUMENT_A64_H_ 29578645f14e122d2b87d907e298cda7e7d0babf1farmvixl 300cc8b6ece4b3e757e11a906a81ece292437713abarmvixl#include "vixl/globals.h" 310cc8b6ece4b3e757e11a906a81ece292437713abarmvixl#include "vixl/utils.h" 320cc8b6ece4b3e757e11a906a81ece292437713abarmvixl#include "vixl/a64/decoder-a64.h" 330cc8b6ece4b3e757e11a906a81ece292437713abarmvixl#include "vixl/a64/constants-a64.h" 340cc8b6ece4b3e757e11a906a81ece292437713abarmvixl#include "vixl/a64/instrument-a64.h" 35578645f14e122d2b87d907e298cda7e7d0babf1farmvixl 36578645f14e122d2b87d907e298cda7e7d0babf1farmvixlnamespace vixl { 37578645f14e122d2b87d907e298cda7e7d0babf1farmvixl 38578645f14e122d2b87d907e298cda7e7d0babf1farmvixlconst int kCounterNameMaxLength = 256; 39578645f14e122d2b87d907e298cda7e7d0babf1farmvixlconst uint64_t kDefaultInstrumentationSamplingPeriod = 1 << 22; 40578645f14e122d2b87d907e298cda7e7d0babf1farmvixl 41578645f14e122d2b87d907e298cda7e7d0babf1farmvixl 42578645f14e122d2b87d907e298cda7e7d0babf1farmvixlenum InstrumentState { 43578645f14e122d2b87d907e298cda7e7d0babf1farmvixl InstrumentStateDisable = 0, 44578645f14e122d2b87d907e298cda7e7d0babf1farmvixl InstrumentStateEnable = 1 45578645f14e122d2b87d907e298cda7e7d0babf1farmvixl}; 46578645f14e122d2b87d907e298cda7e7d0babf1farmvixl 47578645f14e122d2b87d907e298cda7e7d0babf1farmvixl 48578645f14e122d2b87d907e298cda7e7d0babf1farmvixlenum CounterType { 49578645f14e122d2b87d907e298cda7e7d0babf1farmvixl Gauge = 0, // Gauge counters reset themselves after reading. 50578645f14e122d2b87d907e298cda7e7d0babf1farmvixl Cumulative = 1 // Cumulative counters keep their value after reading. 51578645f14e122d2b87d907e298cda7e7d0babf1farmvixl}; 52578645f14e122d2b87d907e298cda7e7d0babf1farmvixl 53578645f14e122d2b87d907e298cda7e7d0babf1farmvixl 54578645f14e122d2b87d907e298cda7e7d0babf1farmvixlclass Counter { 55578645f14e122d2b87d907e298cda7e7d0babf1farmvixl public: 5639ee1f4b336c7e6b25be0df6375c18dcbd577c09armvixl explicit Counter(const char* name, CounterType type = Gauge); 57578645f14e122d2b87d907e298cda7e7d0babf1farmvixl 58578645f14e122d2b87d907e298cda7e7d0babf1farmvixl void Increment(); 59578645f14e122d2b87d907e298cda7e7d0babf1farmvixl void Enable(); 60578645f14e122d2b87d907e298cda7e7d0babf1farmvixl void Disable(); 61578645f14e122d2b87d907e298cda7e7d0babf1farmvixl bool IsEnabled(); 62578645f14e122d2b87d907e298cda7e7d0babf1farmvixl uint64_t count(); 63578645f14e122d2b87d907e298cda7e7d0babf1farmvixl const char* name(); 64578645f14e122d2b87d907e298cda7e7d0babf1farmvixl CounterType type(); 65578645f14e122d2b87d907e298cda7e7d0babf1farmvixl 66578645f14e122d2b87d907e298cda7e7d0babf1farmvixl private: 67578645f14e122d2b87d907e298cda7e7d0babf1farmvixl char name_[kCounterNameMaxLength]; 68578645f14e122d2b87d907e298cda7e7d0babf1farmvixl uint64_t count_; 69578645f14e122d2b87d907e298cda7e7d0babf1farmvixl bool enabled_; 70578645f14e122d2b87d907e298cda7e7d0babf1farmvixl CounterType type_; 71578645f14e122d2b87d907e298cda7e7d0babf1farmvixl}; 72578645f14e122d2b87d907e298cda7e7d0babf1farmvixl 73578645f14e122d2b87d907e298cda7e7d0babf1farmvixl 74578645f14e122d2b87d907e298cda7e7d0babf1farmvixlclass Instrument: public DecoderVisitor { 75578645f14e122d2b87d907e298cda7e7d0babf1farmvixl public: 76578645f14e122d2b87d907e298cda7e7d0babf1farmvixl explicit Instrument(const char* datafile = NULL, 77578645f14e122d2b87d907e298cda7e7d0babf1farmvixl uint64_t sample_period = kDefaultInstrumentationSamplingPeriod); 78578645f14e122d2b87d907e298cda7e7d0babf1farmvixl ~Instrument(); 79578645f14e122d2b87d907e298cda7e7d0babf1farmvixl 80578645f14e122d2b87d907e298cda7e7d0babf1farmvixl void Enable(); 81578645f14e122d2b87d907e298cda7e7d0babf1farmvixl void Disable(); 82578645f14e122d2b87d907e298cda7e7d0babf1farmvixl 83578645f14e122d2b87d907e298cda7e7d0babf1farmvixl // Declare all Visitor functions. 8439ee1f4b336c7e6b25be0df6375c18dcbd577c09armvixl #define DECLARE(A) void Visit##A(const Instruction* instr); 85578645f14e122d2b87d907e298cda7e7d0babf1farmvixl VISITOR_LIST(DECLARE) 86578645f14e122d2b87d907e298cda7e7d0babf1farmvixl #undef DECLARE 87578645f14e122d2b87d907e298cda7e7d0babf1farmvixl 88578645f14e122d2b87d907e298cda7e7d0babf1farmvixl private: 89578645f14e122d2b87d907e298cda7e7d0babf1farmvixl void Update(); 90578645f14e122d2b87d907e298cda7e7d0babf1farmvixl void DumpCounters(); 91578645f14e122d2b87d907e298cda7e7d0babf1farmvixl void DumpCounterNames(); 92578645f14e122d2b87d907e298cda7e7d0babf1farmvixl void DumpEventMarker(unsigned marker); 93578645f14e122d2b87d907e298cda7e7d0babf1farmvixl void HandleInstrumentationEvent(unsigned event); 94578645f14e122d2b87d907e298cda7e7d0babf1farmvixl Counter* GetCounter(const char* name); 95578645f14e122d2b87d907e298cda7e7d0babf1farmvixl 9639ee1f4b336c7e6b25be0df6375c18dcbd577c09armvixl void InstrumentLoadStore(const Instruction* instr); 9739ee1f4b336c7e6b25be0df6375c18dcbd577c09armvixl void InstrumentLoadStorePair(const Instruction* instr); 98578645f14e122d2b87d907e298cda7e7d0babf1farmvixl 99578645f14e122d2b87d907e298cda7e7d0babf1farmvixl std::list<Counter*> counters_; 100578645f14e122d2b87d907e298cda7e7d0babf1farmvixl 101578645f14e122d2b87d907e298cda7e7d0babf1farmvixl FILE *output_stream_; 102578645f14e122d2b87d907e298cda7e7d0babf1farmvixl uint64_t sample_period_; 103578645f14e122d2b87d907e298cda7e7d0babf1farmvixl}; 104578645f14e122d2b87d907e298cda7e7d0babf1farmvixl 105578645f14e122d2b87d907e298cda7e7d0babf1farmvixl} // namespace vixl 106578645f14e122d2b87d907e298cda7e7d0babf1farmvixl 107578645f14e122d2b87d907e298cda7e7d0babf1farmvixl#endif // VIXL_A64_INSTRUMENT_A64_H_ 108