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