blob: 8a5241ff842d7b74c938ca703e4522228ad0842c [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;
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000029 armnn::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:
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 Flynnbbfe6032020-07-20 16:57:44 +010044 void operator()(const arm::pipe::Packet& packet) override;
Keith Davis3201eea2019-10-24 17:30:41 +010045
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
64private:
Jim Flynnbbfe6032020-07-20 16:57:44 +010065 void ParseData(const arm::pipe::Packet& packet);
Keith Davis3201eea2019-10-24 17:30:41 +010066
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
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000083} // namespace pipe
Keith Davis3201eea2019-10-24 17:30:41 +010084
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000085} // namespace arm