Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 1 | // |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 2 | // Copyright © 2019 Arm Ltd and Contributors. All rights reserved. |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
Jim Flynn | c454ac9 | 2022-03-16 18:43:18 +0000 | [diff] [blame^] | 8 | #include <common/include/ICounterDirectory.hpp> |
Jim Flynn | f9db3ef | 2022-03-08 21:23:44 +0000 | [diff] [blame] | 9 | #include <common/include/ProfilingException.hpp> |
| 10 | |
Colm Donelan | 5ccb33d | 2020-01-24 16:27:02 +0000 | [diff] [blame] | 11 | #include <armnn/profiling/ISendTimelinePacket.hpp> |
Francis Murtagh | 3a16198 | 2019-09-04 15:25:02 +0100 | [diff] [blame] | 12 | |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 13 | #include "IPacketBuffer.hpp" |
Finn Williams | 0c8cb99 | 2020-05-07 10:38:15 +0100 | [diff] [blame] | 14 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 15 | #include <common/include/Packet.hpp> |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 16 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 17 | #include <algorithm> |
| 18 | #include <cstring> |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 19 | #include <memory> |
| 20 | #include <string> |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 21 | #include <thread> |
Colm Donelan | 5ccb33d | 2020-01-24 16:27:02 +0000 | [diff] [blame] | 22 | #include <vector> |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 23 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 24 | namespace arm |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 25 | { |
| 26 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 27 | namespace pipe |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 28 | { |
| 29 | |
Jim Flynn | 1fdeb99 | 2020-07-09 07:28:37 +0100 | [diff] [blame] | 30 | constexpr unsigned int ThreadIdSize = sizeof(int); // Is platform dependent |
Colm Donelan | 5bb3d8a | 2020-05-12 16:36:46 +0100 | [diff] [blame] | 31 | |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 32 | void WriteBytes(const IPacketBuffer& packetBuffer, unsigned int offset, const void* value, unsigned int valueSize); |
| 33 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 34 | uint32_t ConstructHeader(uint32_t packetFamily, uint32_t packetId); |
| 35 | |
Jim Flynn | 83d08a9 | 2020-07-09 13:48:16 +0100 | [diff] [blame] | 36 | uint32_t ConstructHeader(uint32_t packetFamily, uint32_t packetClass, uint32_t packetType); |
| 37 | |
Matteo Martincigh | 2ffcc41 | 2019-11-05 11:47:40 +0000 | [diff] [blame] | 38 | void WriteUint64(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint64_t value); |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 39 | |
Matteo Martincigh | 2ffcc41 | 2019-11-05 11:47:40 +0000 | [diff] [blame] | 40 | void WriteUint32(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint32_t value); |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 41 | |
Matteo Martincigh | 2ffcc41 | 2019-11-05 11:47:40 +0000 | [diff] [blame] | 42 | void WriteUint16(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint16_t value); |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 43 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 44 | void WriteUint8(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint8_t value); |
| 45 | |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 46 | void WriteBytes(unsigned char* buffer, unsigned int offset, const void* value, unsigned int valueSize); |
| 47 | |
Francis Murtagh | 3a16198 | 2019-09-04 15:25:02 +0100 | [diff] [blame] | 48 | void WriteUint64(unsigned char* buffer, unsigned int offset, uint64_t value); |
| 49 | |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 50 | void WriteUint32(unsigned char* buffer, unsigned int offset, uint32_t value); |
| 51 | |
| 52 | void WriteUint16(unsigned char* buffer, unsigned int offset, uint16_t value); |
| 53 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 54 | void WriteUint8(unsigned char* buffer, unsigned int offset, uint8_t value); |
| 55 | |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 56 | void ReadBytes(const IPacketBufferPtr& packetBuffer, unsigned int offset, unsigned int valueSize, uint8_t outValue[]); |
| 57 | |
Matteo Martincigh | 2ffcc41 | 2019-11-05 11:47:40 +0000 | [diff] [blame] | 58 | uint64_t ReadUint64(const IPacketBufferPtr& packetBuffer, unsigned int offset); |
Francis Murtagh | 3a16198 | 2019-09-04 15:25:02 +0100 | [diff] [blame] | 59 | |
Matteo Martincigh | 2ffcc41 | 2019-11-05 11:47:40 +0000 | [diff] [blame] | 60 | uint32_t ReadUint32(const IPacketBufferPtr& packetBuffer, unsigned int offset); |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 61 | |
Matteo Martincigh | 2ffcc41 | 2019-11-05 11:47:40 +0000 | [diff] [blame] | 62 | uint16_t ReadUint16(const IPacketBufferPtr& packetBuffer, unsigned int offset); |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 63 | |
Matteo Martincigh | 2ffcc41 | 2019-11-05 11:47:40 +0000 | [diff] [blame] | 64 | uint8_t ReadUint8(const IPacketBufferPtr& packetBuffer, unsigned int offset); |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 65 | |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 66 | void ReadBytes(const unsigned char* buffer, unsigned int offset, unsigned int valueSize, uint8_t outValue[]); |
| 67 | |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 68 | uint64_t ReadUint64(unsigned const char* buffer, unsigned int offset); |
| 69 | |
| 70 | uint32_t ReadUint32(unsigned const char* buffer, unsigned int offset); |
| 71 | |
| 72 | uint16_t ReadUint16(unsigned const char* buffer, unsigned int offset); |
| 73 | |
| 74 | uint8_t ReadUint8(unsigned const char* buffer, unsigned int offset); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 75 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 76 | std::pair<uint32_t, uint32_t> CreateTimelinePacketHeader(uint32_t packetFamily, |
| 77 | uint32_t packetClass, |
| 78 | uint32_t packetType, |
| 79 | uint32_t streamId, |
| 80 | uint32_t sequenceNumbered, |
| 81 | uint32_t dataLength); |
| 82 | |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 83 | std::string GetProcessName(); |
| 84 | |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 85 | enum class TimelinePacketStatus |
| 86 | { |
| 87 | Ok, |
| 88 | Error, |
| 89 | BufferExhaustion |
| 90 | }; |
| 91 | |
| 92 | TimelinePacketStatus WriteTimelineLabelBinaryPacket(uint64_t profilingGuid, |
| 93 | const std::string& label, |
| 94 | unsigned char* buffer, |
| 95 | unsigned int bufferSize, |
| 96 | unsigned int& numberOfBytesWritten); |
| 97 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 98 | TimelinePacketStatus WriteTimelineEntityBinary(uint64_t profilingGuid, |
| 99 | unsigned char* buffer, |
| 100 | unsigned int bufferSize, |
| 101 | unsigned int& numberOfBytesWritten); |
| 102 | |
| 103 | TimelinePacketStatus WriteTimelineRelationshipBinary(ProfilingRelationshipType relationshipType, |
| 104 | uint64_t relationshipGuid, |
| 105 | uint64_t headGuid, |
| 106 | uint64_t tailGuid, |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 107 | uint64_t attributeGuid, |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 108 | unsigned char* buffer, |
| 109 | unsigned int bufferSize, |
| 110 | unsigned int& numberOfBytesWritten); |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 111 | |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 112 | TimelinePacketStatus WriteTimelineMessageDirectoryPackage(unsigned char* buffer, |
| 113 | unsigned int bufferSize, |
| 114 | unsigned int& numberOfBytesWritten); |
| 115 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 116 | TimelinePacketStatus WriteTimelineEventClassBinary(uint64_t profilingGuid, |
Jim Flynn | 1892d21 | 2020-05-26 21:10:49 +0100 | [diff] [blame] | 117 | uint64_t nameGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 118 | unsigned char* buffer, |
| 119 | unsigned int bufferSize, |
| 120 | unsigned int& numberOfBytesWritten); |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 121 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 122 | TimelinePacketStatus WriteTimelineEventBinary(uint64_t timestamp, |
Jim Flynn | 1fdeb99 | 2020-07-09 07:28:37 +0100 | [diff] [blame] | 123 | int threadId, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 124 | uint64_t profilingGuid, |
| 125 | unsigned char* buffer, |
| 126 | unsigned int bufferSize, |
| 127 | unsigned int& numberOfBytesWritten); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 128 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 129 | std::string CentreAlignFormatting(const std::string& stringToPass, const int spacingWidth); |
| 130 | |
Matteo Martincigh | 5dc816e | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 131 | uint64_t GetTimestamp(); |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 132 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 133 | arm::pipe::Packet ReceivePacket(const unsigned char* buffer, uint32_t length); |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 134 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 135 | } // namespace pipe |
Matteo Martincigh | 5dc816e | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 136 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 137 | } // namespace arm |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 138 | |
| 139 | namespace std |
| 140 | { |
| 141 | |
Jim Flynn | 1fdeb99 | 2020-07-09 07:28:37 +0100 | [diff] [blame] | 142 | bool operator==(const std::vector<uint8_t>& left, int right); |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 143 | |
| 144 | } // namespace std |