blob: 007cf05d1881c0c8b3db9664542e94b8511dcc59 [file] [log] [blame]
Keith Davis3201eea2019-10-24 17:30:41 +01001//
Jim Flynnbbfe6032020-07-20 16:57:44 +01002// Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
Keith Davis3201eea2019-10-24 17:30:41 +01003// SPDX-License-Identifier: MIT
4//
5
6#pragma once
7
Keith Davis3201eea2019-10-24 17:30:41 +01008#include "CounterDirectory.hpp"
9
Jim Flynnbbfe6032020-07-20 16:57:44 +010010#include <common/include/CommandHandlerFunctor.hpp>
11
Keith Davis3201eea2019-10-24 17:30:41 +010012#include <atomic>
13
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000014namespace arm
Keith Davis3201eea2019-10-24 17:30:41 +010015{
16
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000017namespace pipe
Keith Davis3201eea2019-10-24 17:30:41 +010018{
19
20struct 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;
Jim Flynndecd08b2022-03-13 22:35:46 +000029 arm::pipe::Optional<std::string> m_CounterUnits;
Keith Davis3201eea2019-10-24 17:30:41 +010030 uint16_t m_DeviceUid;
31 uint16_t m_MaxCounterUid;
32};
33
Jim Flynnbbfe6032020-07-20 16:57:44 +010034class DirectoryCaptureCommandHandler : public arm::pipe::CommandHandlerFunctor
Keith Davis3201eea2019-10-24 17:30:41 +010035{
36
37public:
Jim Flynn4a962112022-03-13 20:18:58 +000038 DirectoryCaptureCommandHandler(const std::string& applicationName,
39 uint32_t familyId,
40 uint32_t packetId,
41 uint32_t version,
42 bool quietOperation = true)
Keith Davis3201eea2019-10-24 17:30:41 +010043 : CommandHandlerFunctor(familyId, packetId, version)
Jim Flynn4a962112022-03-13 20:18:58 +000044 , m_ApplicationName(applicationName)
Keith Davis3201eea2019-10-24 17:30:41 +010045 , m_QuietOperation(quietOperation)
46 , m_AlreadyParsed(false)
47 {}
48
Jim Flynnbbfe6032020-07-20 16:57:44 +010049 void operator()(const arm::pipe::Packet& packet) override;
Keith Davis3201eea2019-10-24 17:30:41 +010050
51 const ICounterDirectory& GetCounterDirectory() const;
52
53 bool ParsedCounterDirectory()
54 {
55 return m_AlreadyParsed.load();
56 }
57
58 /**
59 * Given a Uid that came from a copy of the counter directory translate it to the original.
60 *
61 * @param copyUid
62 * @return the original Uid that the copy maps to.
63 */
64 uint16_t TranslateUIDCopyToOriginal(uint16_t copyUid)
65 {
66 return m_UidTranslation[copyUid];
67 }
68
69private:
Jim Flynnbbfe6032020-07-20 16:57:44 +010070 void ParseData(const arm::pipe::Packet& packet);
Keith Davis3201eea2019-10-24 17:30:41 +010071
72 void ReadCategoryRecords(const unsigned char* data, uint32_t offset, std::vector<uint32_t> categoryOffsets);
73
74 std::vector<CounterDirectoryEventRecord>
75 ReadEventRecords(const unsigned char* data, uint32_t offset, std::vector<uint32_t> eventRecordsOffsets);
76
77 std::string GetStringNameFromBuffer(const unsigned char* data, uint32_t offset);
78 bool IsValidChar(unsigned char c);
79
Jim Flynn4a962112022-03-13 20:18:58 +000080 std::string m_ApplicationName;
Keith Davis3201eea2019-10-24 17:30:41 +010081 CounterDirectory m_CounterDirectory;
82 std::unordered_map<uint16_t, uint16_t> m_UidTranslation;
83 bool m_QuietOperation;
84 // We can only parse the counter directory once per instance. It won't change anyway as it's static
85 // per instance of ArmNN.
86 std::atomic<bool> m_AlreadyParsed;
87};
88
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000089} // namespace pipe
Keith Davis3201eea2019-10-24 17:30:41 +010090
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000091} // namespace arm