2 // Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
8 #include <armnn/Exceptions.hpp>
9 #include <armnn/profiling/ISendTimelinePacket.hpp>
11 #include <armnn/utility/NumericCast.hpp>
13 #include "ICounterDirectory.hpp"
14 #include "IPacketBuffer.hpp"
16 #include <common/include/Packet.hpp>
31 constexpr unsigned int ThreadIdSize = sizeof(int); // Is platform dependent
33 uint16_t GetNextUid(bool peekOnly = false);
35 std::vector<uint16_t> GetNextCounterUids(uint16_t firstUid, uint16_t cores);
37 void WriteBytes(const IPacketBuffer& packetBuffer, unsigned int offset, const void* value, unsigned int valueSize);
39 uint32_t ConstructHeader(uint32_t packetFamily, uint32_t packetId);
41 uint32_t ConstructHeader(uint32_t packetFamily, uint32_t packetClass, uint32_t packetType);
43 void WriteUint64(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint64_t value);
45 void WriteUint32(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint32_t value);
47 void WriteUint16(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint16_t value);
49 void WriteUint8(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint8_t value);
51 void WriteBytes(unsigned char* buffer, unsigned int offset, const void* value, unsigned int valueSize);
53 void WriteUint64(unsigned char* buffer, unsigned int offset, uint64_t value);
55 void WriteUint32(unsigned char* buffer, unsigned int offset, uint32_t value);
57 void WriteUint16(unsigned char* buffer, unsigned int offset, uint16_t value);
59 void WriteUint8(unsigned char* buffer, unsigned int offset, uint8_t value);
61 void ReadBytes(const IPacketBufferPtr& packetBuffer, unsigned int offset, unsigned int valueSize, uint8_t outValue[]);
63 uint64_t ReadUint64(const IPacketBufferPtr& packetBuffer, unsigned int offset);
65 uint32_t ReadUint32(const IPacketBufferPtr& packetBuffer, unsigned int offset);
67 uint16_t ReadUint16(const IPacketBufferPtr& packetBuffer, unsigned int offset);
69 uint8_t ReadUint8(const IPacketBufferPtr& packetBuffer, unsigned int offset);
71 void ReadBytes(const unsigned char* buffer, unsigned int offset, unsigned int valueSize, uint8_t outValue[]);
73 uint64_t ReadUint64(unsigned const char* buffer, unsigned int offset);
75 uint32_t ReadUint32(unsigned const char* buffer, unsigned int offset);
77 uint16_t ReadUint16(unsigned const char* buffer, unsigned int offset);
79 uint8_t ReadUint8(unsigned const char* buffer, unsigned int offset);
81 std::pair<uint32_t, uint32_t> CreateTimelinePacketHeader(uint32_t packetFamily,
85 uint32_t sequenceNumbered,
88 std::string GetSoftwareInfo();
90 std::string GetSoftwareVersion();
92 std::string GetHardwareVersion();
94 std::string GetProcessName();
96 enum class TimelinePacketStatus
103 TimelinePacketStatus WriteTimelineLabelBinaryPacket(uint64_t profilingGuid,
104 const std::string& label,
105 unsigned char* buffer,
106 unsigned int bufferSize,
107 unsigned int& numberOfBytesWritten);
109 TimelinePacketStatus WriteTimelineEntityBinary(uint64_t profilingGuid,
110 unsigned char* buffer,
111 unsigned int bufferSize,
112 unsigned int& numberOfBytesWritten);
114 TimelinePacketStatus WriteTimelineRelationshipBinary(ProfilingRelationshipType relationshipType,
115 uint64_t relationshipGuid,
118 uint64_t attributeGuid,
119 unsigned char* buffer,
120 unsigned int bufferSize,
121 unsigned int& numberOfBytesWritten);
123 TimelinePacketStatus WriteTimelineMessageDirectoryPackage(unsigned char* buffer,
124 unsigned int bufferSize,
125 unsigned int& numberOfBytesWritten);
127 TimelinePacketStatus WriteTimelineEventClassBinary(uint64_t profilingGuid,
129 unsigned char* buffer,
130 unsigned int bufferSize,
131 unsigned int& numberOfBytesWritten);
133 TimelinePacketStatus WriteTimelineEventBinary(uint64_t timestamp,
135 uint64_t profilingGuid,
136 unsigned char* buffer,
137 unsigned int bufferSize,
138 unsigned int& numberOfBytesWritten);
140 std::string CentreAlignFormatting(const std::string& stringToPass, const int spacingWidth);
142 void PrintCounterDirectory(ICounterDirectory& counterDirectory);
144 class BufferExhaustion : public armnn::Exception
146 using Exception::Exception;
149 uint64_t GetTimestamp();
151 arm::pipe::Packet ReceivePacket(const unsigned char* buffer, uint32_t length);
153 } // namespace profiling
160 bool operator==(const std::vector<uint8_t>& left, int right);