Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1 | // |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 2 | // Copyright © 2019 Arm Ltd and Contributors. All rights reserved. |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 8 | #include "CounterDirectory.hpp" |
| 9 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 10 | #include <common/include/CommandHandlerFunctor.hpp> |
| 11 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 12 | #include <atomic> |
| 13 | |
| 14 | namespace armnn |
| 15 | { |
| 16 | |
| 17 | namespace profiling |
| 18 | { |
| 19 | |
| 20 | struct CounterDirectoryEventRecord |
| 21 | { |
| 22 | uint16_t m_CounterClass; |
| 23 | std::string m_CounterDescription; |
| 24 | uint16_t m_CounterInterpolation; |
| 25 | double m_CounterMultiplier; |
| 26 | std::string m_CounterName; |
| 27 | uint16_t m_CounterSetUid; |
| 28 | uint16_t m_CounterUid; |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 29 | Optional<std::string> m_CounterUnits; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 30 | uint16_t m_DeviceUid; |
| 31 | uint16_t m_MaxCounterUid; |
| 32 | }; |
| 33 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 34 | class DirectoryCaptureCommandHandler : public arm::pipe::CommandHandlerFunctor |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 35 | { |
| 36 | |
| 37 | public: |
| 38 | DirectoryCaptureCommandHandler(uint32_t familyId, uint32_t packetId, uint32_t version, bool quietOperation = true) |
| 39 | : CommandHandlerFunctor(familyId, packetId, version) |
| 40 | , m_QuietOperation(quietOperation) |
| 41 | , m_AlreadyParsed(false) |
| 42 | {} |
| 43 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 44 | void operator()(const arm::pipe::Packet& packet) override; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 45 | |
| 46 | const ICounterDirectory& GetCounterDirectory() const; |
| 47 | |
| 48 | bool ParsedCounterDirectory() |
| 49 | { |
| 50 | return m_AlreadyParsed.load(); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Given a Uid that came from a copy of the counter directory translate it to the original. |
| 55 | * |
| 56 | * @param copyUid |
| 57 | * @return the original Uid that the copy maps to. |
| 58 | */ |
| 59 | uint16_t TranslateUIDCopyToOriginal(uint16_t copyUid) |
| 60 | { |
| 61 | return m_UidTranslation[copyUid]; |
| 62 | } |
| 63 | |
| 64 | private: |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 65 | void ParseData(const arm::pipe::Packet& packet); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 66 | |
| 67 | void ReadCategoryRecords(const unsigned char* data, uint32_t offset, std::vector<uint32_t> categoryOffsets); |
| 68 | |
| 69 | std::vector<CounterDirectoryEventRecord> |
| 70 | ReadEventRecords(const unsigned char* data, uint32_t offset, std::vector<uint32_t> eventRecordsOffsets); |
| 71 | |
| 72 | std::string GetStringNameFromBuffer(const unsigned char* data, uint32_t offset); |
| 73 | bool IsValidChar(unsigned char c); |
| 74 | |
| 75 | CounterDirectory m_CounterDirectory; |
| 76 | std::unordered_map<uint16_t, uint16_t> m_UidTranslation; |
| 77 | bool m_QuietOperation; |
| 78 | // We can only parse the counter directory once per instance. It won't change anyway as it's static |
| 79 | // per instance of ArmNN. |
| 80 | std::atomic<bool> m_AlreadyParsed; |
| 81 | }; |
| 82 | |
| 83 | } // namespace profiling |
| 84 | |
| 85 | } // namespace armnn |