1 // 2 // Copyright © 2019 Arm Ltd and Contributors. All rights reserved. 3 // SPDX-License-Identifier: MIT 4 // 5 6 #pragma once 7 8 #include "ProfilingStateMachine.hpp" 9 #include "SendCounterPacket.hpp" 10 #include "IPeriodicCounterCapture.hpp" 11 12 #include <client/include/CounterIdMap.hpp> 13 #include <client/include/Holder.hpp> 14 #include <client/include/ICounterValues.hpp> 15 16 #include <client/include/backends/IBackendProfilingContext.hpp> 17 18 #include <common/include/CommandHandlerFunctor.hpp> 19 #include <common/include/Logging.hpp> 20 #include <common/include/Packet.hpp> 21 22 #include <set> 23 24 namespace arm 25 { 26 27 namespace pipe 28 { 29 30 31 class PeriodicCounterSelectionCommandHandler : public arm::pipe::CommandHandlerFunctor 32 { 33 34 public: PeriodicCounterSelectionCommandHandler(uint32_t familyId,uint32_t packetId,uint32_t version,const std::unordered_map<std::string,std::shared_ptr<IBackendProfilingContext>> & backendProfilingContexts,const ICounterMappings & counterIdMap,Holder & captureDataHolder,const uint16_t maxArmnnCounterId,IPeriodicCounterCapture & periodicCounterCapture,const IReadCounterValues & readCounterValue,ISendCounterPacket & sendCounterPacket,const ProfilingStateMachine & profilingStateMachine)35 PeriodicCounterSelectionCommandHandler(uint32_t familyId, 36 uint32_t packetId, 37 uint32_t version, 38 const std::unordered_map<std::string, 39 std::shared_ptr<IBackendProfilingContext>>& 40 backendProfilingContexts, 41 const ICounterMappings& counterIdMap, 42 Holder& captureDataHolder, 43 const uint16_t maxArmnnCounterId, 44 IPeriodicCounterCapture& periodicCounterCapture, 45 const IReadCounterValues& readCounterValue, 46 ISendCounterPacket& sendCounterPacket, 47 const ProfilingStateMachine& profilingStateMachine) 48 : CommandHandlerFunctor(familyId, packetId, version) 49 , m_BackendProfilingContexts(backendProfilingContexts) 50 , m_CounterIdMap(counterIdMap) 51 , m_CaptureDataHolder(captureDataHolder) 52 , m_MaxArmCounterId(maxArmnnCounterId) 53 , m_PeriodicCounterCapture(periodicCounterCapture) 54 , m_PrevCapturePeriod(0) 55 , m_ReadCounterValues(readCounterValue) 56 , m_SendCounterPacket(sendCounterPacket) 57 , m_StateMachine(profilingStateMachine) 58 59 { 60 61 } 62 63 void operator()(const arm::pipe::Packet& packet) override; 64 65 private: 66 67 std::unordered_map<std::string, std::vector<uint16_t>> m_BackendCounterMap; 68 const std::unordered_map<std::string, 69 std::shared_ptr<IBackendProfilingContext>>& m_BackendProfilingContexts; 70 const ICounterMappings& m_CounterIdMap; 71 Holder& m_CaptureDataHolder; 72 const uint16_t m_MaxArmCounterId; 73 IPeriodicCounterCapture& m_PeriodicCounterCapture; 74 uint32_t m_PrevCapturePeriod; 75 std::set<uint16_t> m_PrevBackendCounterIds; 76 const IReadCounterValues& m_ReadCounterValues; 77 ISendCounterPacket& m_SendCounterPacket; 78 const ProfilingStateMachine& m_StateMachine; 79 ActivateBackendCounters(const std::string backendId,const uint32_t capturePeriod,const std::vector<uint16_t> counterIds)80 void ActivateBackendCounters(const std::string backendId, 81 const uint32_t capturePeriod, 82 const std::vector<uint16_t> counterIds) 83 { 84 arm::pipe::Optional<std::string> errorMsg = 85 m_BackendProfilingContexts.at(backendId)->ActivateCounters(capturePeriod, counterIds); 86 87 if(errorMsg.has_value()) 88 { 89 ARM_PIPE_LOG(warning) << "An error has occurred when activating counters of " << backendId << ": " 90 << errorMsg.value(); 91 } 92 } 93 void ParseData(const arm::pipe::Packet& packet, CaptureData& captureData); 94 std::set<std::string> ProcessBackendCounterIds(const uint32_t capturePeriod, 95 const std::set<uint16_t> newCounterIds, 96 const std::set<uint16_t> unusedCounterIds); 97 98 }; 99 100 } // namespace pipe 101 102 } // namespace arm 103