Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "ProfilingUtils.hpp" |
| 7 | |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 8 | #include <armnn/Version.hpp> |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 9 | #include <armnn/Conversion.hpp> |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 10 | |
Matteo Martincigh | 5dc816e | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 11 | #include <WallClockTimer.hpp> |
| 12 | |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 13 | #include <boost/assert.hpp> |
| 14 | |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 15 | #include <fstream> |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 16 | #include <iostream> |
Matteo Martincigh | ab173e9 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 17 | #include <limits> |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 18 | |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 19 | namespace armnn |
| 20 | { |
| 21 | |
| 22 | namespace profiling |
| 23 | { |
| 24 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 25 | namespace |
Matteo Martincigh | ab173e9 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 26 | { |
Matteo Martincigh | ab173e9 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 27 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 28 | void ThrowIfCantGenerateNextUid(uint16_t uid, uint16_t cores = 0) |
| 29 | { |
Matteo Martincigh | ab173e9 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 30 | // Check that it is possible to generate the next UID without causing an overflow |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 31 | switch (cores) |
Matteo Martincigh | ab173e9 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 32 | { |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 33 | case 0: |
| 34 | case 1: |
| 35 | // Number of cores not specified or set to 1 (a value of zero indicates the device is not capable of |
| 36 | // running multiple parallel workloads and will not provide multiple streams of data for each event) |
| 37 | if (uid == std::numeric_limits<uint16_t>::max()) |
| 38 | { |
| 39 | throw RuntimeException("Generating the next UID for profiling would result in an overflow"); |
| 40 | } |
| 41 | break; |
| 42 | default: // cores > 1 |
| 43 | // Multiple cores available, as max_counter_uid has to be set to: counter_uid + cores - 1, the maximum |
| 44 | // allowed value for a counter UID is consequently: uint16_t_max - cores + 1 |
| 45 | if (uid >= std::numeric_limits<uint16_t>::max() - cores + 1) |
| 46 | { |
| 47 | throw RuntimeException("Generating the next UID for profiling would result in an overflow"); |
| 48 | } |
| 49 | break; |
Matteo Martincigh | ab173e9 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 50 | } |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 51 | } |
Matteo Martincigh | ab173e9 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 52 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 53 | } // Anonymous namespace |
| 54 | |
| 55 | uint16_t GetNextUid(bool peekOnly) |
| 56 | { |
| 57 | // The UID used for profiling objects and events. The first valid UID is 1, as 0 is a reserved value |
| 58 | static uint16_t uid = 1; |
| 59 | |
| 60 | // Check that it is possible to generate the next UID without causing an overflow (throws in case of error) |
| 61 | ThrowIfCantGenerateNextUid(uid); |
| 62 | |
| 63 | if (peekOnly) |
| 64 | { |
| 65 | // Peek only |
| 66 | return uid; |
| 67 | } |
| 68 | else |
| 69 | { |
| 70 | // Get the next UID |
| 71 | return uid++; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | std::vector<uint16_t> GetNextCounterUids(uint16_t cores) |
| 76 | { |
| 77 | // The UID used for counters only. The first valid UID is 0 |
| 78 | static uint16_t counterUid = 0; |
| 79 | |
| 80 | // Check that it is possible to generate the next counter UID without causing an overflow (throws in case of error) |
| 81 | ThrowIfCantGenerateNextUid(counterUid, cores); |
| 82 | |
| 83 | // Get the next counter UIDs |
| 84 | size_t counterUidsSize = cores == 0 ? 1 : cores; |
| 85 | std::vector<uint16_t> counterUids(counterUidsSize, 0); |
| 86 | for (size_t i = 0; i < counterUidsSize; i++) |
| 87 | { |
| 88 | counterUids[i] = counterUid++; |
| 89 | } |
| 90 | return counterUids; |
Matteo Martincigh | ab173e9 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 91 | } |
| 92 | |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 93 | void WriteBytes(const IPacketBufferPtr& packetBuffer, unsigned int offset, const void* value, unsigned int valueSize) |
| 94 | { |
| 95 | BOOST_ASSERT(packetBuffer); |
| 96 | |
| 97 | WriteBytes(packetBuffer->GetWritableData(), offset, value, valueSize); |
| 98 | } |
| 99 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 100 | uint32_t ConstructHeader(uint32_t packetFamily, |
| 101 | uint32_t packetId) |
| 102 | { |
| 103 | return ((packetFamily & 0x3F) << 26)| |
| 104 | ((packetId & 0x3FF) << 16); |
| 105 | } |
| 106 | |
| 107 | uint32_t ConstructHeader(uint32_t packetFamily, |
| 108 | uint32_t packetClass, |
| 109 | uint32_t packetType) |
| 110 | { |
| 111 | return ((packetFamily & 0x3F) << 26)| |
| 112 | ((packetClass & 0x3FF) << 19)| |
| 113 | ((packetType & 0x3FFF) << 16); |
| 114 | } |
| 115 | |
| 116 | void WriteUint64(const std::unique_ptr<IPacketBuffer>& packetBuffer, unsigned int offset, uint64_t value) |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 117 | { |
| 118 | BOOST_ASSERT(packetBuffer); |
| 119 | |
| 120 | WriteUint64(packetBuffer->GetWritableData(), offset, value); |
| 121 | } |
| 122 | |
Matteo Martincigh | 2ffcc41 | 2019-11-05 11:47:40 +0000 | [diff] [blame] | 123 | void WriteUint32(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint32_t value) |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 124 | { |
| 125 | BOOST_ASSERT(packetBuffer); |
| 126 | |
| 127 | WriteUint32(packetBuffer->GetWritableData(), offset, value); |
| 128 | } |
| 129 | |
Matteo Martincigh | 2ffcc41 | 2019-11-05 11:47:40 +0000 | [diff] [blame] | 130 | void WriteUint16(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint16_t value) |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 131 | { |
| 132 | BOOST_ASSERT(packetBuffer); |
| 133 | |
| 134 | WriteUint16(packetBuffer->GetWritableData(), offset, value); |
| 135 | } |
| 136 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 137 | void WriteUint8(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint8_t value) |
| 138 | { |
| 139 | BOOST_ASSERT(packetBuffer); |
| 140 | |
| 141 | WriteUint8(packetBuffer->GetWritableData(), offset, value); |
| 142 | } |
| 143 | |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 144 | void WriteBytes(unsigned char* buffer, unsigned int offset, const void* value, unsigned int valueSize) |
| 145 | { |
| 146 | BOOST_ASSERT(buffer); |
| 147 | BOOST_ASSERT(value); |
| 148 | |
| 149 | for (unsigned int i = 0; i < valueSize; i++, offset++) |
| 150 | { |
| 151 | buffer[offset] = *(reinterpret_cast<const unsigned char*>(value) + i); |
| 152 | } |
| 153 | } |
| 154 | |
Francis Murtagh | 3a16198 | 2019-09-04 15:25:02 +0100 | [diff] [blame] | 155 | void WriteUint64(unsigned char* buffer, unsigned int offset, uint64_t value) |
| 156 | { |
| 157 | BOOST_ASSERT(buffer); |
| 158 | |
| 159 | buffer[offset] = static_cast<unsigned char>(value & 0xFF); |
| 160 | buffer[offset + 1] = static_cast<unsigned char>((value >> 8) & 0xFF); |
| 161 | buffer[offset + 2] = static_cast<unsigned char>((value >> 16) & 0xFF); |
| 162 | buffer[offset + 3] = static_cast<unsigned char>((value >> 24) & 0xFF); |
| 163 | buffer[offset + 4] = static_cast<unsigned char>((value >> 32) & 0xFF); |
| 164 | buffer[offset + 5] = static_cast<unsigned char>((value >> 40) & 0xFF); |
| 165 | buffer[offset + 6] = static_cast<unsigned char>((value >> 48) & 0xFF); |
| 166 | buffer[offset + 7] = static_cast<unsigned char>((value >> 56) & 0xFF); |
| 167 | } |
| 168 | |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 169 | void WriteUint32(unsigned char* buffer, unsigned int offset, uint32_t value) |
| 170 | { |
| 171 | BOOST_ASSERT(buffer); |
| 172 | |
Matteo Martincigh | 149528e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 173 | buffer[offset] = static_cast<unsigned char>(value & 0xFF); |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 174 | buffer[offset + 1] = static_cast<unsigned char>((value >> 8) & 0xFF); |
| 175 | buffer[offset + 2] = static_cast<unsigned char>((value >> 16) & 0xFF); |
| 176 | buffer[offset + 3] = static_cast<unsigned char>((value >> 24) & 0xFF); |
| 177 | } |
| 178 | |
| 179 | void WriteUint16(unsigned char* buffer, unsigned int offset, uint16_t value) |
| 180 | { |
Matteo Martincigh | 149528e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 181 | BOOST_ASSERT(buffer); |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 182 | |
Matteo Martincigh | 149528e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 183 | buffer[offset] = static_cast<unsigned char>(value & 0xFF); |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 184 | buffer[offset + 1] = static_cast<unsigned char>((value >> 8) & 0xFF); |
| 185 | } |
| 186 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 187 | void WriteUint8(unsigned char* buffer, unsigned int offset, uint8_t value) |
| 188 | { |
| 189 | BOOST_ASSERT(buffer); |
| 190 | |
| 191 | buffer[offset] = static_cast<unsigned char>(value); |
| 192 | } |
| 193 | |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 194 | void ReadBytes(const IPacketBufferPtr& packetBuffer, unsigned int offset, unsigned int valueSize, uint8_t outValue[]) |
| 195 | { |
| 196 | BOOST_ASSERT(packetBuffer); |
| 197 | |
| 198 | ReadBytes(packetBuffer->GetReadableData(), offset, valueSize, outValue); |
| 199 | } |
| 200 | |
Matteo Martincigh | 2ffcc41 | 2019-11-05 11:47:40 +0000 | [diff] [blame] | 201 | uint64_t ReadUint64(const IPacketBufferPtr& packetBuffer, unsigned int offset) |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 202 | { |
| 203 | BOOST_ASSERT(packetBuffer); |
| 204 | |
| 205 | return ReadUint64(packetBuffer->GetReadableData(), offset); |
| 206 | } |
| 207 | |
Matteo Martincigh | 2ffcc41 | 2019-11-05 11:47:40 +0000 | [diff] [blame] | 208 | uint32_t ReadUint32(const IPacketBufferPtr& packetBuffer, unsigned int offset) |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 209 | { |
| 210 | BOOST_ASSERT(packetBuffer); |
| 211 | |
| 212 | return ReadUint32(packetBuffer->GetReadableData(), offset); |
| 213 | } |
| 214 | |
Matteo Martincigh | 2ffcc41 | 2019-11-05 11:47:40 +0000 | [diff] [blame] | 215 | uint16_t ReadUint16(const IPacketBufferPtr& packetBuffer, unsigned int offset) |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 216 | { |
| 217 | BOOST_ASSERT(packetBuffer); |
| 218 | |
| 219 | return ReadUint16(packetBuffer->GetReadableData(), offset); |
| 220 | } |
| 221 | |
Matteo Martincigh | 2ffcc41 | 2019-11-05 11:47:40 +0000 | [diff] [blame] | 222 | uint8_t ReadUint8(const IPacketBufferPtr& packetBuffer, unsigned int offset) |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 223 | { |
| 224 | BOOST_ASSERT(packetBuffer); |
| 225 | |
| 226 | return ReadUint8(packetBuffer->GetReadableData(), offset); |
| 227 | } |
| 228 | |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 229 | void ReadBytes(const unsigned char* buffer, unsigned int offset, unsigned int valueSize, uint8_t outValue[]) |
| 230 | { |
| 231 | BOOST_ASSERT(buffer); |
| 232 | BOOST_ASSERT(outValue); |
| 233 | |
| 234 | for (unsigned int i = 0; i < valueSize; i++, offset++) |
| 235 | { |
| 236 | outValue[i] = static_cast<uint8_t>(buffer[offset]); |
| 237 | } |
| 238 | } |
| 239 | |
Francis Murtagh | 3a16198 | 2019-09-04 15:25:02 +0100 | [diff] [blame] | 240 | uint64_t ReadUint64(const unsigned char* buffer, unsigned int offset) |
| 241 | { |
| 242 | BOOST_ASSERT(buffer); |
| 243 | |
| 244 | uint64_t value = 0; |
Matteo Martincigh | ab173e9 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 245 | value = static_cast<uint64_t>(buffer[offset]); |
Francis Murtagh | 3a16198 | 2019-09-04 15:25:02 +0100 | [diff] [blame] | 246 | value |= static_cast<uint64_t>(buffer[offset + 1]) << 8; |
| 247 | value |= static_cast<uint64_t>(buffer[offset + 2]) << 16; |
| 248 | value |= static_cast<uint64_t>(buffer[offset + 3]) << 24; |
| 249 | value |= static_cast<uint64_t>(buffer[offset + 4]) << 32; |
| 250 | value |= static_cast<uint64_t>(buffer[offset + 5]) << 40; |
| 251 | value |= static_cast<uint64_t>(buffer[offset + 6]) << 48; |
| 252 | value |= static_cast<uint64_t>(buffer[offset + 7]) << 56; |
| 253 | |
| 254 | return value; |
| 255 | } |
| 256 | |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 257 | uint32_t ReadUint32(const unsigned char* buffer, unsigned int offset) |
| 258 | { |
| 259 | BOOST_ASSERT(buffer); |
| 260 | |
| 261 | uint32_t value = 0; |
Matteo Martincigh | 149528e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 262 | value = static_cast<uint32_t>(buffer[offset]); |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 263 | value |= static_cast<uint32_t>(buffer[offset + 1]) << 8; |
| 264 | value |= static_cast<uint32_t>(buffer[offset + 2]) << 16; |
| 265 | value |= static_cast<uint32_t>(buffer[offset + 3]) << 24; |
| 266 | return value; |
| 267 | } |
| 268 | |
| 269 | uint16_t ReadUint16(const unsigned char* buffer, unsigned int offset) |
| 270 | { |
| 271 | BOOST_ASSERT(buffer); |
| 272 | |
| 273 | uint32_t value = 0; |
Matteo Martincigh | 149528e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 274 | value = static_cast<uint32_t>(buffer[offset]); |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 275 | value |= static_cast<uint32_t>(buffer[offset + 1]) << 8; |
| 276 | return static_cast<uint16_t>(value); |
| 277 | } |
| 278 | |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 279 | uint8_t ReadUint8(const unsigned char* buffer, unsigned int offset) |
| 280 | { |
| 281 | BOOST_ASSERT(buffer); |
| 282 | |
| 283 | return buffer[offset]; |
| 284 | } |
| 285 | |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 286 | std::string GetSoftwareInfo() |
| 287 | { |
| 288 | return std::string("ArmNN"); |
| 289 | } |
| 290 | |
| 291 | std::string GetHardwareVersion() |
| 292 | { |
| 293 | return std::string(); |
| 294 | } |
| 295 | |
| 296 | std::string GetSoftwareVersion() |
| 297 | { |
| 298 | std::string armnnVersion(ARMNN_VERSION); |
| 299 | std::string result = "Armnn " + armnnVersion.substr(2,2) + "." + armnnVersion.substr(4,2); |
| 300 | return result; |
| 301 | } |
| 302 | |
| 303 | std::string GetProcessName() |
| 304 | { |
| 305 | std::ifstream comm("/proc/self/comm"); |
| 306 | std::string name; |
| 307 | getline(comm, name); |
| 308 | return name; |
| 309 | } |
| 310 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 311 | // Calculate the actual length an SwString will be including the terminating null character |
| 312 | // padding to bring it to the next uint32_t boundary but minus the leading uint32_t encoding |
| 313 | // the size to allow the offset to be correctly updated when decoding a binary packet. |
| 314 | uint32_t CalculateSizeOfPaddedSwString(const std::string& str) |
| 315 | { |
| 316 | std::vector<uint32_t> swTraceString; |
| 317 | StringToSwTraceString<SwTraceCharPolicy>(str, swTraceString); |
| 318 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 319 | uint32_t size = (boost::numeric_cast<uint32_t>(swTraceString.size()) - 1) * uint32_t_size; |
| 320 | return size; |
| 321 | } |
| 322 | |
| 323 | // Read TimelineMessageDirectoryPacket from given IPacketBuffer and offset |
| 324 | SwTraceMessage ReadSwTraceMessage(const unsigned char* packetBuffer, unsigned int& offset) |
| 325 | { |
| 326 | BOOST_ASSERT(packetBuffer); |
| 327 | |
| 328 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 329 | |
| 330 | SwTraceMessage swTraceMessage; |
| 331 | |
| 332 | // Read the decl_id |
| 333 | uint32_t readDeclId = ReadUint32(packetBuffer, offset); |
| 334 | swTraceMessage.m_Id = readDeclId; |
| 335 | |
| 336 | // SWTrace "namestring" format |
| 337 | // length of the string (first 4 bytes) + string + null terminator |
| 338 | |
| 339 | // Check the decl_name |
| 340 | offset += uint32_t_size; |
| 341 | uint32_t swTraceDeclNameLength = ReadUint32(packetBuffer, offset); |
| 342 | |
| 343 | offset += uint32_t_size; |
| 344 | std::vector<unsigned char> swTraceStringBuffer(swTraceDeclNameLength - 1); |
| 345 | std::memcpy(swTraceStringBuffer.data(), |
| 346 | packetBuffer + offset, swTraceStringBuffer.size()); |
| 347 | |
| 348 | swTraceMessage.m_Name.assign(swTraceStringBuffer.begin(), swTraceStringBuffer.end()); // name |
| 349 | |
| 350 | // Check the ui_name |
| 351 | offset += CalculateSizeOfPaddedSwString(swTraceMessage.m_Name); |
| 352 | uint32_t swTraceUINameLength = ReadUint32(packetBuffer, offset); |
| 353 | |
| 354 | offset += uint32_t_size; |
| 355 | swTraceStringBuffer.resize(swTraceUINameLength - 1); |
| 356 | std::memcpy(swTraceStringBuffer.data(), |
| 357 | packetBuffer + offset, swTraceStringBuffer.size()); |
| 358 | |
| 359 | swTraceMessage.m_UiName.assign(swTraceStringBuffer.begin(), swTraceStringBuffer.end()); // ui_name |
| 360 | |
| 361 | // Check arg_types |
| 362 | offset += CalculateSizeOfPaddedSwString(swTraceMessage.m_UiName); |
| 363 | uint32_t swTraceArgTypesLength = ReadUint32(packetBuffer, offset); |
| 364 | |
| 365 | offset += uint32_t_size; |
| 366 | swTraceStringBuffer.resize(swTraceArgTypesLength - 1); |
| 367 | std::memcpy(swTraceStringBuffer.data(), |
| 368 | packetBuffer + offset, swTraceStringBuffer.size()); |
| 369 | |
| 370 | swTraceMessage.m_ArgTypes.assign(swTraceStringBuffer.begin(), swTraceStringBuffer.end()); // arg_types |
| 371 | |
| 372 | std::string swTraceString(swTraceStringBuffer.begin(), swTraceStringBuffer.end()); |
| 373 | |
| 374 | // Check arg_names |
| 375 | offset += CalculateSizeOfPaddedSwString(swTraceString); |
| 376 | uint32_t swTraceArgNamesLength = ReadUint32(packetBuffer, offset); |
| 377 | |
| 378 | offset += uint32_t_size; |
| 379 | swTraceStringBuffer.resize(swTraceArgNamesLength - 1); |
| 380 | std::memcpy(swTraceStringBuffer.data(), |
| 381 | packetBuffer + offset, swTraceStringBuffer.size()); |
| 382 | |
| 383 | swTraceString.assign(swTraceStringBuffer.begin(), swTraceStringBuffer.end()); |
| 384 | std::stringstream stringStream(swTraceString); |
| 385 | std::string argName; |
| 386 | while (std::getline(stringStream, argName, ',')) |
| 387 | { |
| 388 | swTraceMessage.m_ArgNames.push_back(argName); |
| 389 | } |
| 390 | |
| 391 | offset += CalculateSizeOfPaddedSwString(swTraceString); |
| 392 | |
| 393 | return swTraceMessage; |
| 394 | } |
| 395 | |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 396 | /// Creates a timeline packet header |
| 397 | /// |
| 398 | /// \params |
| 399 | /// packetFamiliy Timeline Packet Family |
| 400 | /// packetClass Timeline Packet Class |
| 401 | /// packetType Timeline Packet Type |
| 402 | /// streamId Stream identifier |
| 403 | /// seqeunceNumbered When non-zero the 4 bytes following the header is a u32 sequence number |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 404 | /// dataLength Unsigned 24-bit integer. Length of data, in bytes. Zero is permitted |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 405 | /// |
| 406 | /// \returns |
| 407 | /// Pair of uint32_t containing word0 and word1 of the header |
| 408 | std::pair<uint32_t, uint32_t> CreateTimelinePacketHeader(uint32_t packetFamily, |
| 409 | uint32_t packetClass, |
| 410 | uint32_t packetType, |
| 411 | uint32_t streamId, |
| 412 | uint32_t sequenceNumbered, |
| 413 | uint32_t dataLength) |
| 414 | { |
| 415 | // Packet header word 0: |
| 416 | // 26:31 [6] packet_family: timeline Packet Family, value 0b000001 |
| 417 | // 19:25 [7] packet_class: packet class |
| 418 | // 16:18 [3] packet_type: packet type |
| 419 | // 8:15 [8] reserved: all zeros |
| 420 | // 0:7 [8] stream_id: stream identifier |
| 421 | uint32_t packetHeaderWord0 = ((packetFamily & 0x0000003F) << 26) | |
| 422 | ((packetClass & 0x0000007F) << 19) | |
| 423 | ((packetType & 0x00000007) << 16) | |
| 424 | ((streamId & 0x00000007) << 0); |
| 425 | |
| 426 | // Packet header word 1: |
| 427 | // 25:31 [7] reserved: all zeros |
| 428 | // 24 [1] sequence_numbered: when non-zero the 4 bytes following the header is a u32 sequence number |
| 429 | // 0:23 [24] data_length: unsigned 24-bit integer. Length of data, in bytes. Zero is permitted |
| 430 | uint32_t packetHeaderWord1 = ((sequenceNumbered & 0x00000001) << 24) | |
| 431 | ((dataLength & 0x00FFFFFF) << 0); |
| 432 | |
| 433 | return std::make_pair(packetHeaderWord0, packetHeaderWord1); |
| 434 | } |
| 435 | |
| 436 | /// Creates a packet header for the timeline messages: |
| 437 | /// * declareLabel |
| 438 | /// * declareEntity |
| 439 | /// * declareEventClass |
| 440 | /// * declareRelationship |
| 441 | /// * declareEvent |
| 442 | /// |
| 443 | /// \param |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 444 | /// dataLength The length of the message body in bytes |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 445 | /// |
| 446 | /// \returns |
| 447 | /// Pair of uint32_t containing word0 and word1 of the header |
| 448 | std::pair<uint32_t, uint32_t> CreateTimelineMessagePacketHeader(unsigned int dataLength) |
| 449 | { |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 450 | return CreateTimelinePacketHeader(1, // Packet family |
| 451 | 0, // Packet class |
| 452 | 1, // Packet type |
| 453 | 0, // Stream id |
| 454 | 0, // Sequence number |
| 455 | dataLength); // Data length |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 456 | } |
| 457 | |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 458 | TimelinePacketStatus WriteTimelineLabelBinaryPacket(uint64_t profilingGuid, |
| 459 | const std::string& label, |
| 460 | unsigned char* buffer, |
| 461 | unsigned int bufferSize, |
| 462 | unsigned int& numberOfBytesWritten) |
| 463 | { |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 464 | // Initialize the output value |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 465 | numberOfBytesWritten = 0; |
| 466 | |
| 467 | // Check that the given buffer is valid |
| 468 | if (buffer == nullptr || bufferSize == 0) |
| 469 | { |
| 470 | return TimelinePacketStatus::BufferExhaustion; |
| 471 | } |
| 472 | |
| 473 | // Utils |
| 474 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 475 | unsigned int uint64_t_size = sizeof(uint64_t); |
| 476 | |
| 477 | // Convert the label into a SWTrace string |
| 478 | std::vector<uint32_t> swTraceLabel; |
| 479 | bool result = StringToSwTraceString<SwTraceCharPolicy>(label, swTraceLabel); |
| 480 | if (!result) |
| 481 | { |
| 482 | return TimelinePacketStatus::Error; |
| 483 | } |
| 484 | |
| 485 | // Calculate the size of the SWTrace string label (in bytes) |
| 486 | unsigned int swTraceLabelSize = boost::numeric_cast<unsigned int>(swTraceLabel.size()) * uint32_t_size; |
| 487 | |
| 488 | // Calculate the length of the data (in bytes) |
Jan Eilers | b884ea4 | 2019-10-16 09:54:15 +0100 | [diff] [blame] | 489 | unsigned int timelineLabelPacketDataLength = uint32_t_size + // decl_Id |
| 490 | uint64_t_size + // Profiling GUID |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 491 | swTraceLabelSize; // Label |
| 492 | |
| 493 | // Calculate the timeline binary packet size (in bytes) |
| 494 | unsigned int timelineLabelPacketSize = 2 * uint32_t_size + // Header (2 words) |
Jan Eilers | b884ea4 | 2019-10-16 09:54:15 +0100 | [diff] [blame] | 495 | timelineLabelPacketDataLength; // decl_Id + Profiling GUID + label |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 496 | |
| 497 | // Check whether the timeline binary packet fits in the given buffer |
| 498 | if (timelineLabelPacketSize > bufferSize) |
| 499 | { |
| 500 | return TimelinePacketStatus::BufferExhaustion; |
| 501 | } |
| 502 | |
Jan Eilers | b884ea4 | 2019-10-16 09:54:15 +0100 | [diff] [blame] | 503 | // Create packet header |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 504 | std::pair<uint32_t, uint32_t> packetHeader = CreateTimelineMessagePacketHeader(timelineLabelPacketDataLength); |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 505 | |
| 506 | // Initialize the offset for writing in the buffer |
| 507 | unsigned int offset = 0; |
| 508 | |
| 509 | // Write the timeline binary packet header to the buffer |
Jan Eilers | b884ea4 | 2019-10-16 09:54:15 +0100 | [diff] [blame] | 510 | WriteUint32(buffer, offset, packetHeader.first); |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 511 | offset += uint32_t_size; |
Jan Eilers | b884ea4 | 2019-10-16 09:54:15 +0100 | [diff] [blame] | 512 | WriteUint32(buffer, offset, packetHeader.second); |
| 513 | offset += uint32_t_size; |
| 514 | |
| 515 | // Write decl_Id to the buffer |
| 516 | WriteUint32(buffer, offset, 0u); |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 517 | offset += uint32_t_size; |
| 518 | |
| 519 | // Write the timeline binary packet payload to the buffer |
| 520 | WriteUint64(buffer, offset, profilingGuid); // Profiling GUID |
| 521 | offset += uint64_t_size; |
| 522 | for (uint32_t swTraceLabelWord : swTraceLabel) |
| 523 | { |
| 524 | WriteUint32(buffer, offset, swTraceLabelWord); // Label |
| 525 | offset += uint32_t_size; |
| 526 | } |
| 527 | |
| 528 | // Update the number of bytes written |
| 529 | numberOfBytesWritten = timelineLabelPacketSize; |
| 530 | |
| 531 | return TimelinePacketStatus::Ok; |
| 532 | } |
| 533 | |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 534 | TimelinePacketStatus WriteTimelineEntityBinaryPacket(uint64_t profilingGuid, |
| 535 | unsigned char* buffer, |
| 536 | unsigned int bufferSize, |
| 537 | unsigned int& numberOfBytesWritten) |
| 538 | { |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 539 | // Initialize the output value |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 540 | numberOfBytesWritten = 0; |
| 541 | |
| 542 | // Check that the given buffer is valid |
| 543 | if (buffer == nullptr || bufferSize == 0) |
| 544 | { |
| 545 | return TimelinePacketStatus::BufferExhaustion; |
| 546 | } |
| 547 | |
| 548 | // Utils |
| 549 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 550 | unsigned int uint64_t_size = sizeof(uint64_t); |
| 551 | |
| 552 | // Calculate the length of the data (in bytes) |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 553 | unsigned int timelineEntityPacketDataLength = uint32_t_size + uint64_t_size; // decl_id + Profiling GUID |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 554 | |
| 555 | |
| 556 | // Calculate the timeline binary packet size (in bytes) |
| 557 | unsigned int timelineEntityPacketSize = 2 * uint32_t_size + // Header (2 words) |
Jan Eilers | b884ea4 | 2019-10-16 09:54:15 +0100 | [diff] [blame] | 558 | timelineEntityPacketDataLength; // Profiling GUID |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 559 | |
| 560 | // Check whether the timeline binary packet fits in the given buffer |
| 561 | if (timelineEntityPacketSize > bufferSize) |
| 562 | { |
| 563 | return TimelinePacketStatus::BufferExhaustion; |
| 564 | } |
| 565 | |
Jan Eilers | b884ea4 | 2019-10-16 09:54:15 +0100 | [diff] [blame] | 566 | // Create packet header |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 567 | std::pair<uint32_t, uint32_t> packetHeader = CreateTimelineMessagePacketHeader(timelineEntityPacketDataLength); |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 568 | |
| 569 | // Initialize the offset for writing in the buffer |
| 570 | unsigned int offset = 0; |
| 571 | |
| 572 | // Write the timeline binary packet header to the buffer |
Jan Eilers | b884ea4 | 2019-10-16 09:54:15 +0100 | [diff] [blame] | 573 | WriteUint32(buffer, offset, packetHeader.first); |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 574 | offset += uint32_t_size; |
Jan Eilers | b884ea4 | 2019-10-16 09:54:15 +0100 | [diff] [blame] | 575 | WriteUint32(buffer, offset, packetHeader.second); |
| 576 | offset += uint32_t_size; |
| 577 | |
| 578 | // Write the decl_Id to the buffer |
| 579 | WriteUint32(buffer, offset, 1u); |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 580 | offset += uint32_t_size; |
| 581 | |
| 582 | // Write the timeline binary packet payload to the buffer |
| 583 | WriteUint64(buffer, offset, profilingGuid); // Profiling GUID |
| 584 | |
| 585 | // Update the number of bytes written |
| 586 | numberOfBytesWritten = timelineEntityPacketSize; |
| 587 | |
| 588 | return TimelinePacketStatus::Ok; |
| 589 | } |
| 590 | |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 591 | TimelinePacketStatus WriteTimelineRelationshipBinaryPacket(ProfilingRelationshipType relationshipType, |
| 592 | uint64_t relationshipGuid, |
| 593 | uint64_t headGuid, |
| 594 | uint64_t tailGuid, |
| 595 | unsigned char* buffer, |
| 596 | unsigned int bufferSize, |
| 597 | unsigned int& numberOfBytesWritten) |
| 598 | { |
| 599 | // Initialize the output value |
| 600 | numberOfBytesWritten = 0; |
| 601 | |
| 602 | // Check that the given buffer is valid |
| 603 | if (buffer == nullptr || bufferSize == 0) |
| 604 | { |
| 605 | return TimelinePacketStatus::BufferExhaustion; |
| 606 | } |
| 607 | |
| 608 | // Utils |
| 609 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 610 | unsigned int uint64_t_size = sizeof(uint64_t); |
| 611 | |
| 612 | // Calculate the length of the data (in bytes) |
| 613 | unsigned int timelineRelationshipPacketDataLength = uint32_t_size * 2 + // decl_id + Relationship Type |
| 614 | uint64_t_size * 3; // Relationship GUID + Head GUID + tail GUID |
| 615 | |
| 616 | // Calculate the timeline binary packet size (in bytes) |
| 617 | unsigned int timelineRelationshipPacketSize = 2 * uint32_t_size + // Header (2 words) |
| 618 | timelineRelationshipPacketDataLength; |
| 619 | |
| 620 | // Check whether the timeline binary packet fits in the given buffer |
| 621 | if (timelineRelationshipPacketSize > bufferSize) |
| 622 | { |
| 623 | return TimelinePacketStatus::BufferExhaustion; |
| 624 | } |
| 625 | |
| 626 | // Create packet header |
| 627 | uint32_t dataLength = boost::numeric_cast<uint32_t>(timelineRelationshipPacketDataLength); |
| 628 | std::pair<uint32_t, uint32_t> packetHeader = CreateTimelineMessagePacketHeader(dataLength); |
| 629 | |
| 630 | // Initialize the offset for writing in the buffer |
| 631 | unsigned int offset = 0; |
| 632 | |
| 633 | // Write the timeline binary packet header to the buffer |
| 634 | WriteUint32(buffer, offset, packetHeader.first); |
| 635 | offset += uint32_t_size; |
| 636 | WriteUint32(buffer, offset, packetHeader.second); |
| 637 | offset += uint32_t_size; |
| 638 | |
| 639 | uint32_t relationshipTypeUint = 0; |
| 640 | |
| 641 | switch (relationshipType) |
| 642 | { |
| 643 | case ProfilingRelationshipType::RetentionLink: |
| 644 | relationshipTypeUint = 0; |
| 645 | break; |
| 646 | case ProfilingRelationshipType::ExecutionLink: |
| 647 | relationshipTypeUint = 1; |
| 648 | break; |
| 649 | case ProfilingRelationshipType::DataLink: |
| 650 | relationshipTypeUint = 2; |
| 651 | break; |
| 652 | case ProfilingRelationshipType::LabelLink: |
| 653 | relationshipTypeUint = 3; |
| 654 | break; |
| 655 | default: |
| 656 | throw InvalidArgumentException("Unknown relationship type given."); |
| 657 | } |
| 658 | |
| 659 | // Write the timeline binary packet payload to the buffer |
| 660 | // decl_id of the timeline message |
| 661 | uint32_t declId = 3; |
| 662 | WriteUint32(buffer, offset, declId); // decl_id |
| 663 | offset += uint32_t_size; |
| 664 | WriteUint32(buffer, offset, relationshipTypeUint); // Relationship Type |
| 665 | offset += uint32_t_size; |
| 666 | WriteUint64(buffer, offset, relationshipGuid); // GUID of this relationship |
| 667 | offset += uint64_t_size; |
| 668 | WriteUint64(buffer, offset, headGuid); // head of relationship GUID |
| 669 | offset += uint64_t_size; |
| 670 | WriteUint64(buffer, offset, tailGuid); // tail of relationship GUID |
| 671 | |
| 672 | // Update the number of bytes written |
| 673 | numberOfBytesWritten = timelineRelationshipPacketSize; |
| 674 | |
| 675 | return TimelinePacketStatus::Ok; |
| 676 | } |
| 677 | |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 678 | TimelinePacketStatus WriteTimelineMessageDirectoryPackage(unsigned char* buffer, |
| 679 | unsigned int bufferSize, |
| 680 | unsigned int& numberOfBytesWritten) |
| 681 | { |
| 682 | // Initialize the output value |
| 683 | numberOfBytesWritten = 0; |
| 684 | |
| 685 | // Check that the given buffer is valid |
| 686 | if (buffer == nullptr || bufferSize == 0) |
| 687 | { |
| 688 | return TimelinePacketStatus::BufferExhaustion; |
| 689 | } |
| 690 | |
| 691 | // Utils |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 692 | unsigned int uint8_t_size = sizeof(uint8_t); |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 693 | unsigned int uint32_t_size = sizeof(uint32_t); |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 694 | unsigned int uint64_t_size = sizeof(uint64_t); |
| 695 | unsigned int threadId_size = sizeof(std::thread::id); |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 696 | |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 697 | // The payload/data of the packet consists of swtrace event definitions encoded according |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 698 | // to the swtrace directory specification. The messages being the five defined below: |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 699 | // |
| 700 | // | decl_id | decl_name | ui_name | arg_types | arg_names | |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 701 | // |-----------|---------------------|-----------------------|-------------|-------------------------------------| |
| 702 | // | 0 | declareLabel | declare label | ps | guid,value | |
| 703 | // | 1 | declareEntity | declare entity | p | guid | |
| 704 | // | 2 | declareEventClass | declare event class | p | guid | |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 705 | // | 3 | declareRelationship | declare relationship | Ippp | relationshipType,relationshipGuid, | |
| 706 | // | | | | | headGuid,tailGuid | |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 707 | // | 4 | declareEvent | declare event | @tp | timestamp,threadId,eventGuid | |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 708 | std::vector<std::vector<std::string>> timelineDirectoryMessages |
| 709 | { |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 710 | { "0", "declareLabel", "declare label", "ps", "guid,value" }, |
| 711 | { "1", "declareEntity", "declare entity", "p", "guid" }, |
| 712 | { "2", "declareEventClass", "declare event class", "p", "guid" }, |
| 713 | { "3", "declareRelationship", "declare relationship", "Ippp", |
| 714 | "relationshipType,relationshipGuid,headGuid,tailGuid" }, |
| 715 | { "4", "declareEvent", "declare event", "@tp", "timestamp,threadId,eventGuid" } |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 716 | }; |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 717 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 718 | // Build the message declarations |
| 719 | std::vector<uint32_t> swTraceBuffer; |
| 720 | for (const auto& directoryComponent : timelineDirectoryMessages) |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 721 | { |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 722 | // decl_id |
| 723 | uint32_t declId = 0; |
| 724 | try |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 725 | { |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 726 | declId = boost::numeric_cast<uint32_t>(std::stoul(directoryComponent[0])); |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 727 | } |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 728 | catch (const std::exception&) |
| 729 | { |
| 730 | return TimelinePacketStatus::Error; |
| 731 | } |
| 732 | swTraceBuffer.push_back(declId); |
| 733 | |
| 734 | bool result = true; |
| 735 | result &= ConvertDirectoryComponent<SwTraceNameCharPolicy>(directoryComponent[1], swTraceBuffer); // decl_name |
| 736 | result &= ConvertDirectoryComponent<SwTraceCharPolicy> (directoryComponent[2], swTraceBuffer); // ui_name |
| 737 | result &= ConvertDirectoryComponent<SwTraceTypeCharPolicy>(directoryComponent[3], swTraceBuffer); // arg_types |
| 738 | result &= ConvertDirectoryComponent<SwTraceCharPolicy> (directoryComponent[4], swTraceBuffer); // arg_names |
| 739 | if (!result) |
| 740 | { |
| 741 | return TimelinePacketStatus::Error; |
| 742 | } |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 743 | } |
| 744 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 745 | unsigned int dataLength = 3 * uint8_t_size + // Stream header (3 bytes) |
| 746 | boost::numeric_cast<unsigned int>(swTraceBuffer.size()) * |
| 747 | uint32_t_size; // Trace directory (5 messages) |
| 748 | |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 749 | // Calculate the timeline directory binary packet size (in bytes) |
| 750 | unsigned int timelineDirectoryPacketSize = 2 * uint32_t_size + // Header (2 words) |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 751 | dataLength; // Payload |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 752 | |
| 753 | // Check whether the timeline directory binary packet fits in the given buffer |
| 754 | if (timelineDirectoryPacketSize > bufferSize) |
| 755 | { |
| 756 | return TimelinePacketStatus::BufferExhaustion; |
| 757 | } |
| 758 | |
Jan Eilers | b884ea4 | 2019-10-16 09:54:15 +0100 | [diff] [blame] | 759 | // Create packet header |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 760 | auto packetHeader = CreateTimelinePacketHeader(1, 0, 0, 0, 0, boost::numeric_cast<uint32_t>(dataLength)); |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 761 | |
| 762 | // Initialize the offset for writing in the buffer |
| 763 | unsigned int offset = 0; |
| 764 | |
| 765 | // Write the timeline binary packet header to the buffer |
Jan Eilers | b884ea4 | 2019-10-16 09:54:15 +0100 | [diff] [blame] | 766 | WriteUint32(buffer, offset, packetHeader.first); |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 767 | offset += uint32_t_size; |
Jan Eilers | b884ea4 | 2019-10-16 09:54:15 +0100 | [diff] [blame] | 768 | WriteUint32(buffer, offset, packetHeader.second); |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 769 | offset += uint32_t_size; |
| 770 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 771 | // Write the stream header |
| 772 | uint8_t streamVersion = 4; |
| 773 | uint8_t pointerBytes = boost::numeric_cast<uint8_t>(uint64_t_size); // All GUIDs are uint64_t |
| 774 | uint8_t threadIdBytes = boost::numeric_cast<uint8_t>(threadId_size); |
| 775 | switch (threadIdBytes) |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 776 | { |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 777 | case 4: // Typically Windows and Android |
| 778 | case 8: // Typically Linux |
| 779 | break; // Valid values |
| 780 | default: |
| 781 | return TimelinePacketStatus::Error; // Invalid value |
| 782 | } |
| 783 | WriteUint8(buffer, offset, streamVersion); |
| 784 | offset += uint8_t_size; |
| 785 | WriteUint8(buffer, offset, pointerBytes); |
| 786 | offset += uint8_t_size; |
| 787 | WriteUint8(buffer, offset, threadIdBytes); |
| 788 | offset += uint8_t_size; |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 789 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 790 | // Write the SWTrace directory |
| 791 | uint32_t numberOfDeclarations = boost::numeric_cast<uint32_t>(timelineDirectoryMessages.size()); |
| 792 | WriteUint32(buffer, offset, numberOfDeclarations); // Number of declarations |
| 793 | offset += uint32_t_size; |
| 794 | for (uint32_t i : swTraceBuffer) |
| 795 | { |
| 796 | WriteUint32(buffer, offset, i); // Message declarations |
| 797 | offset += uint32_t_size; |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | // Update the number of bytes written |
| 801 | numberOfBytesWritten = timelineDirectoryPacketSize; |
| 802 | |
| 803 | return TimelinePacketStatus::Ok; |
| 804 | } |
| 805 | |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 806 | TimelinePacketStatus WriteTimelineEventClassBinaryPacket(uint64_t profilingGuid, |
| 807 | unsigned char* buffer, |
| 808 | unsigned int bufferSize, |
| 809 | unsigned int& numberOfBytesWritten) |
| 810 | { |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 811 | // Initialize the output value |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 812 | numberOfBytesWritten = 0; |
| 813 | |
| 814 | // Check that the given buffer is valid |
| 815 | if (buffer == nullptr || bufferSize == 0) |
| 816 | { |
| 817 | return TimelinePacketStatus::BufferExhaustion; |
| 818 | } |
| 819 | |
| 820 | // Utils |
| 821 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 822 | unsigned int uint64_t_size = sizeof(uint64_t); |
| 823 | |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 824 | // decl_id of the timeline message |
| 825 | uint32_t declId = 2; |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 826 | |
| 827 | // Calculate the length of the data (in bytes) |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 828 | unsigned int packetBodySize = uint32_t_size + uint64_t_size; // decl_id + Profiling GUID |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 829 | |
| 830 | // Calculate the timeline binary packet size (in bytes) |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 831 | unsigned int packetSize = 2 * uint32_t_size + // Header (2 words) |
| 832 | packetBodySize; // Body |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 833 | |
| 834 | // Check whether the timeline binary packet fits in the given buffer |
| 835 | if (packetSize > bufferSize) |
| 836 | { |
| 837 | return TimelinePacketStatus::BufferExhaustion; |
| 838 | } |
| 839 | |
| 840 | // Create packet header |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 841 | std::pair<uint32_t, uint32_t> packetHeader = CreateTimelineMessagePacketHeader(packetBodySize); |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 842 | |
| 843 | // Initialize the offset for writing in the buffer |
| 844 | unsigned int offset = 0; |
| 845 | |
| 846 | // Write the timeline binary packet header to the buffer |
| 847 | WriteUint32(buffer, offset, packetHeader.first); |
| 848 | offset += uint32_t_size; |
| 849 | WriteUint32(buffer, offset, packetHeader.second); |
| 850 | offset += uint32_t_size; |
| 851 | |
| 852 | // Write the timeline binary packet payload to the buffer |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 853 | WriteUint32(buffer, offset, declId); // decl_id |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 854 | offset += uint32_t_size; |
| 855 | WriteUint64(buffer, offset, profilingGuid); // Profiling GUID |
| 856 | |
| 857 | // Update the number of bytes written |
| 858 | numberOfBytesWritten = packetSize; |
| 859 | |
| 860 | return TimelinePacketStatus::Ok; |
| 861 | } |
| 862 | |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 863 | TimelinePacketStatus WriteTimelineEventBinaryPacket(uint64_t timestamp, |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 864 | std::thread::id threadId, |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 865 | uint64_t profilingGuid, |
| 866 | unsigned char* buffer, |
| 867 | unsigned int bufferSize, |
| 868 | unsigned int& numberOfBytesWritten) |
| 869 | { |
| 870 | // Initialize the output value |
| 871 | numberOfBytesWritten = 0; |
| 872 | |
| 873 | // Check that the given buffer is valid |
| 874 | if (buffer == nullptr || bufferSize == 0) |
| 875 | { |
| 876 | return TimelinePacketStatus::BufferExhaustion; |
| 877 | } |
| 878 | |
| 879 | // Utils |
| 880 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 881 | unsigned int uint64_t_size = sizeof(uint64_t); |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 882 | unsigned int threadId_size = sizeof(std::thread::id); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 883 | |
| 884 | // decl_id of the timeline message |
| 885 | uint32_t declId = 4; |
| 886 | |
| 887 | // Calculate the length of the data (in bytes) |
| 888 | unsigned int timelineEventPacketDataLength = uint32_t_size + // decl_id |
| 889 | uint64_t_size + // Timestamp |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 890 | threadId_size + // Thread id |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 891 | uint64_t_size; // Profiling GUID |
| 892 | |
| 893 | // Calculate the timeline binary packet size (in bytes) |
| 894 | unsigned int timelineEventPacketSize = 2 * uint32_t_size + // Header (2 words) |
| 895 | timelineEventPacketDataLength; // Timestamp + thread id + profiling GUID |
| 896 | |
| 897 | // Check whether the timeline binary packet fits in the given buffer |
| 898 | if (timelineEventPacketSize > bufferSize) |
| 899 | { |
| 900 | return TimelinePacketStatus::BufferExhaustion; |
| 901 | } |
| 902 | |
| 903 | // Create packet header |
| 904 | std::pair<uint32_t, uint32_t> packetHeader = CreateTimelineMessagePacketHeader(timelineEventPacketDataLength); |
| 905 | |
| 906 | // Initialize the offset for writing in the buffer |
| 907 | unsigned int offset = 0; |
| 908 | |
| 909 | // Write the timeline binary packet header to the buffer |
| 910 | WriteUint32(buffer, offset, packetHeader.first); |
| 911 | offset += uint32_t_size; |
| 912 | WriteUint32(buffer, offset, packetHeader.second); |
| 913 | offset += uint32_t_size; |
| 914 | |
| 915 | // Write the timeline binary packet payload to the buffer |
| 916 | WriteUint32(buffer, offset, declId); // decl_id |
| 917 | offset += uint32_t_size; |
| 918 | WriteUint64(buffer, offset, timestamp); // Timestamp |
| 919 | offset += uint64_t_size; |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 920 | WriteBytes(buffer, offset, &threadId, threadId_size); // Thread id |
| 921 | offset += threadId_size; |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 922 | WriteUint64(buffer, offset, profilingGuid); // Profiling GUID |
| 923 | offset += uint64_t_size; |
| 924 | |
| 925 | // Update the number of bytes written |
| 926 | numberOfBytesWritten = timelineEventPacketSize; |
| 927 | |
| 928 | return TimelinePacketStatus::Ok; |
| 929 | } |
| 930 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 931 | std::string CentreAlignFormatting(const std::string& stringToPass, const int spacingWidth) |
| 932 | { |
| 933 | std::stringstream outputStream, centrePadding; |
| 934 | int padding = spacingWidth - static_cast<int>(stringToPass.size()); |
| 935 | |
| 936 | for (int i = 0; i < padding / 2; ++i) |
| 937 | { |
| 938 | centrePadding << " "; |
| 939 | } |
| 940 | |
| 941 | outputStream << centrePadding.str() << stringToPass << centrePadding.str(); |
| 942 | |
| 943 | if (padding > 0 && padding %2 != 0) |
| 944 | { |
| 945 | outputStream << " "; |
| 946 | } |
| 947 | |
| 948 | return outputStream.str(); |
| 949 | } |
| 950 | |
| 951 | void PrintDeviceDetails(const std::pair<const unsigned short, std::unique_ptr<Device>>& devicePair) |
| 952 | { |
| 953 | std::string body; |
| 954 | |
| 955 | body.append(CentreAlignFormatting(devicePair.second->m_Name, 20)); |
| 956 | body.append(" | "); |
| 957 | body.append(CentreAlignFormatting(std::to_string(devicePair.first), 13)); |
| 958 | body.append(" | "); |
| 959 | body.append(CentreAlignFormatting(std::to_string(devicePair.second->m_Cores), 10)); |
| 960 | body.append("\n"); |
| 961 | |
| 962 | std::cout << std::string(body.size(), '-') << "\n"; |
| 963 | std::cout<< body; |
| 964 | } |
| 965 | |
| 966 | void PrintCounterSetDetails(const std::pair<const unsigned short, std::unique_ptr<CounterSet>>& counterSetPair) |
| 967 | { |
| 968 | std::string body; |
| 969 | |
| 970 | body.append(CentreAlignFormatting(counterSetPair.second->m_Name, 20)); |
| 971 | body.append(" | "); |
| 972 | body.append(CentreAlignFormatting(std::to_string(counterSetPair.first), 13)); |
| 973 | body.append(" | "); |
| 974 | body.append(CentreAlignFormatting(std::to_string(counterSetPair.second->m_Count), 10)); |
| 975 | body.append("\n"); |
| 976 | |
| 977 | std::cout << std::string(body.size(), '-') << "\n"; |
| 978 | |
| 979 | std::cout<< body; |
| 980 | } |
| 981 | |
| 982 | void PrintCounterDetails(std::shared_ptr<Counter>& counter) |
| 983 | { |
| 984 | std::string body; |
| 985 | |
| 986 | body.append(CentreAlignFormatting(counter->m_Name, 20)); |
| 987 | body.append(" | "); |
| 988 | body.append(CentreAlignFormatting(counter->m_Description, 50)); |
| 989 | body.append(" | "); |
| 990 | body.append(CentreAlignFormatting(counter->m_Units, 14)); |
| 991 | body.append(" | "); |
| 992 | body.append(CentreAlignFormatting(std::to_string(counter->m_Uid), 6)); |
| 993 | body.append(" | "); |
| 994 | body.append(CentreAlignFormatting(std::to_string(counter->m_MaxCounterUid), 10)); |
| 995 | body.append(" | "); |
| 996 | body.append(CentreAlignFormatting(std::to_string(counter->m_Class), 8)); |
| 997 | body.append(" | "); |
| 998 | body.append(CentreAlignFormatting(std::to_string(counter->m_Interpolation), 14)); |
| 999 | body.append(" | "); |
| 1000 | body.append(CentreAlignFormatting(std::to_string(counter->m_Multiplier), 20)); |
| 1001 | body.append(" | "); |
| 1002 | body.append(CentreAlignFormatting(std::to_string(counter->m_CounterSetUid), 16)); |
| 1003 | body.append(" | "); |
| 1004 | body.append(CentreAlignFormatting(std::to_string(counter->m_DeviceUid), 14)); |
| 1005 | |
| 1006 | body.append("\n"); |
| 1007 | |
| 1008 | std::cout << std::string(body.size(), '-') << "\n"; |
| 1009 | |
| 1010 | std::cout << body; |
| 1011 | } |
| 1012 | |
| 1013 | void PrintCategoryDetails(const std::unique_ptr<Category>& category, |
| 1014 | std::unordered_map<unsigned short, std::shared_ptr<Counter>> counterMap) |
| 1015 | { |
| 1016 | std::string categoryBody; |
| 1017 | std::string categoryHeader; |
| 1018 | |
| 1019 | categoryHeader.append(CentreAlignFormatting("Name", 20)); |
| 1020 | categoryHeader.append(" | "); |
| 1021 | categoryHeader.append(CentreAlignFormatting("Device", 12)); |
| 1022 | categoryHeader.append(" | "); |
| 1023 | categoryHeader.append(CentreAlignFormatting("Counter set UID:", 16)); |
| 1024 | categoryHeader.append(" | "); |
| 1025 | categoryHeader.append(CentreAlignFormatting("Event Count", 14)); |
| 1026 | categoryHeader.append("\n"); |
| 1027 | |
| 1028 | categoryBody.append(CentreAlignFormatting(category->m_Name, 20)); |
| 1029 | categoryBody.append(" | "); |
| 1030 | categoryBody.append(CentreAlignFormatting(std::to_string(category->m_DeviceUid), 12)); |
| 1031 | categoryBody.append(" | "); |
| 1032 | categoryBody.append(CentreAlignFormatting(std::to_string(category->m_CounterSetUid), 16)); |
| 1033 | categoryBody.append(" | "); |
| 1034 | categoryBody.append(CentreAlignFormatting(std::to_string(category->m_Counters.size()), 14)); |
| 1035 | |
| 1036 | std::cout << "\n" << "\n"; |
| 1037 | std::cout << CentreAlignFormatting("CATEGORY", static_cast<int>(categoryHeader.size())); |
| 1038 | std::cout << "\n"; |
| 1039 | std::cout << std::string(categoryHeader.size(), '=') << "\n"; |
| 1040 | |
| 1041 | std::cout << categoryHeader; |
| 1042 | |
| 1043 | std::cout << std::string(categoryBody.size(), '-') << "\n"; |
| 1044 | |
| 1045 | std::cout << categoryBody; |
| 1046 | |
| 1047 | std::string counterHeader; |
| 1048 | |
| 1049 | counterHeader.append(CentreAlignFormatting("Counter Name", 20)); |
| 1050 | counterHeader.append(" | "); |
| 1051 | counterHeader.append(CentreAlignFormatting("Description", 50)); |
| 1052 | counterHeader.append(" | "); |
| 1053 | counterHeader.append(CentreAlignFormatting("Units", 14)); |
| 1054 | counterHeader.append(" | "); |
| 1055 | counterHeader.append(CentreAlignFormatting("UID", 6)); |
| 1056 | counterHeader.append(" | "); |
| 1057 | counterHeader.append(CentreAlignFormatting("Max UID", 10)); |
| 1058 | counterHeader.append(" | "); |
| 1059 | counterHeader.append(CentreAlignFormatting("Class", 8)); |
| 1060 | counterHeader.append(" | "); |
| 1061 | counterHeader.append(CentreAlignFormatting("Interpolation", 14)); |
| 1062 | counterHeader.append(" | "); |
| 1063 | counterHeader.append(CentreAlignFormatting("Multiplier", 20)); |
| 1064 | counterHeader.append(" | "); |
| 1065 | counterHeader.append(CentreAlignFormatting("Counter set UID", 16)); |
| 1066 | counterHeader.append(" | "); |
| 1067 | counterHeader.append(CentreAlignFormatting("Device UID", 14)); |
| 1068 | counterHeader.append("\n"); |
| 1069 | |
| 1070 | std::cout << "\n" << "\n"; |
| 1071 | std::cout << CentreAlignFormatting("EVENTS IN CATEGORY: " + category->m_Name, |
| 1072 | static_cast<int>(counterHeader.size())); |
| 1073 | std::cout << "\n"; |
| 1074 | std::cout << std::string(counterHeader.size(), '=') << "\n"; |
| 1075 | std::cout << counterHeader; |
| 1076 | for (auto& it: category->m_Counters) { |
| 1077 | auto search = counterMap.find(it); |
| 1078 | if(search != counterMap.end()) { |
| 1079 | PrintCounterDetails(search->second); |
| 1080 | } |
| 1081 | } |
| 1082 | } |
| 1083 | |
| 1084 | void PrintCounterDirectory(ICounterDirectory& counterDirectory) |
| 1085 | { |
| 1086 | std::string devicesHeader; |
| 1087 | |
| 1088 | devicesHeader.append(CentreAlignFormatting("Device name", 20)); |
| 1089 | devicesHeader.append(" | "); |
| 1090 | devicesHeader.append(CentreAlignFormatting("UID", 13)); |
| 1091 | devicesHeader.append(" | "); |
| 1092 | devicesHeader.append(CentreAlignFormatting("Cores", 10)); |
| 1093 | devicesHeader.append("\n"); |
| 1094 | |
| 1095 | std::cout << "\n" << "\n"; |
| 1096 | std::cout << CentreAlignFormatting("DEVICES", static_cast<int>(devicesHeader.size())); |
| 1097 | std::cout << "\n"; |
| 1098 | std::cout << std::string(devicesHeader.size(), '=') << "\n"; |
| 1099 | std::cout << devicesHeader; |
| 1100 | for (auto& it: counterDirectory.GetDevices()) { |
| 1101 | PrintDeviceDetails(it); |
| 1102 | } |
| 1103 | |
| 1104 | std::string counterSetHeader; |
| 1105 | |
| 1106 | counterSetHeader.append(CentreAlignFormatting("Counter set name", 20)); |
| 1107 | counterSetHeader.append(" | "); |
| 1108 | counterSetHeader.append(CentreAlignFormatting("UID", 13)); |
| 1109 | counterSetHeader.append(" | "); |
| 1110 | counterSetHeader.append(CentreAlignFormatting("Count", 10)); |
| 1111 | counterSetHeader.append("\n"); |
| 1112 | |
| 1113 | std::cout << "\n" << "\n"; |
| 1114 | std::cout << CentreAlignFormatting("COUNTER SETS", static_cast<int>(counterSetHeader.size())); |
| 1115 | std::cout << "\n"; |
| 1116 | std::cout << std::string(counterSetHeader.size(), '=') << "\n"; |
| 1117 | |
| 1118 | std::cout << counterSetHeader; |
| 1119 | |
| 1120 | for (auto& it: counterDirectory.GetCounterSets()) { |
| 1121 | PrintCounterSetDetails(it); |
| 1122 | } |
| 1123 | |
| 1124 | auto counters = counterDirectory.GetCounters(); |
| 1125 | for (auto& it: counterDirectory.GetCategories()) { |
| 1126 | PrintCategoryDetails(it, counters); |
| 1127 | } |
| 1128 | std::cout << "\n"; |
| 1129 | } |
| 1130 | |
Matteo Martincigh | 5dc816e | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 1131 | uint64_t GetTimestamp() |
| 1132 | { |
| 1133 | #if USE_CLOCK_MONOTONIC_RAW |
| 1134 | using clock = MonotonicClockRaw; |
| 1135 | #else |
| 1136 | using clock = std::chrono::steady_clock; |
| 1137 | #endif |
| 1138 | |
| 1139 | // Take a timestamp |
| 1140 | auto timestamp = clock::now(); |
| 1141 | |
| 1142 | return static_cast<uint64_t>(timestamp.time_since_epoch().count()); |
| 1143 | } |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1144 | |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 1145 | } // namespace profiling |
| 1146 | |
Matteo Martincigh | 149528e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1147 | } // namespace armnn |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 1148 | |
| 1149 | namespace std |
| 1150 | { |
| 1151 | |
| 1152 | bool operator==(const std::vector<uint8_t>& left, std::thread::id right) |
| 1153 | { |
| 1154 | return std::memcmp(left.data(), &right, left.size()) == 0; |
| 1155 | } |
| 1156 | |
| 1157 | } // namespace std |