Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2019 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
Jim Flynn | 6406355 | 2020-02-14 10:18:08 +0000 | [diff] [blame] | 6 | #include "ProfilingMocks.hpp" |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 7 | |
| 8 | #include <BufferManager.hpp> |
Jim Flynn | 00f3aaf | 2019-10-24 11:58:06 +0100 | [diff] [blame] | 9 | #include <ProfilingService.hpp> |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 10 | #include <ProfilingUtils.hpp> |
| 11 | #include <SendTimelinePacket.hpp> |
| 12 | #include <TimelinePacketWriterFactory.hpp> |
| 13 | |
| 14 | #include <boost/test/unit_test.hpp> |
Jim Flynn | ab84575 | 2019-10-25 13:17:30 +0100 | [diff] [blame] | 15 | #include <LabelsAndEventClasses.hpp> |
| 16 | |
| 17 | #include <functional> |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 18 | |
| 19 | using namespace armnn::profiling; |
| 20 | |
| 21 | BOOST_AUTO_TEST_SUITE(SendTimelinePacketTests) |
| 22 | |
| 23 | BOOST_AUTO_TEST_CASE(SendTimelineMessageDirectoryPackageTest) |
| 24 | { |
| 25 | MockBufferManager mockBuffer(512); |
| 26 | TimelinePacketWriterFactory timelinePacketWriterFactory(mockBuffer); |
| 27 | std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket(); |
| 28 | |
| 29 | sendTimelinePacket->SendTimelineMessageDirectoryPackage(); |
| 30 | |
| 31 | // Get the readable buffer |
| 32 | auto packetBuffer = mockBuffer.GetReadableBuffer(); |
| 33 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 34 | unsigned int uint8_t_size = sizeof(uint8_t); |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 35 | unsigned int uint32_t_size = sizeof(uint32_t); |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 36 | unsigned int uint64_t_size = sizeof(uint64_t); |
| 37 | unsigned int threadId_size = sizeof(std::thread::id); |
| 38 | |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 39 | // Check the packet header |
| 40 | unsigned int offset = 0; |
| 41 | uint32_t packetHeaderWord0 = ReadUint32(packetBuffer, offset); |
| 42 | uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F; |
| 43 | uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F; |
| 44 | uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007; |
| 45 | uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007; |
| 46 | |
| 47 | BOOST_CHECK(packetFamily == 1); |
| 48 | BOOST_CHECK(packetClass == 0); |
| 49 | BOOST_CHECK(packetType == 0); |
| 50 | BOOST_CHECK(streamId == 0); |
| 51 | |
| 52 | offset += uint32_t_size; |
| 53 | uint32_t packetHeaderWord1 = ReadUint32(packetBuffer, offset); |
| 54 | uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001; |
| 55 | uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF; |
| 56 | BOOST_CHECK(sequenceNumbered == 0); |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 57 | BOOST_CHECK(dataLength == 419); |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 58 | |
| 59 | offset += uint32_t_size; |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 60 | uint8_t readStreamVersion = ReadUint8(packetBuffer, offset); |
| 61 | BOOST_CHECK(readStreamVersion == 4); |
| 62 | offset += uint8_t_size; |
| 63 | uint8_t readPointerBytes = ReadUint8(packetBuffer, offset); |
| 64 | BOOST_CHECK(readPointerBytes == uint64_t_size); |
| 65 | offset += uint8_t_size; |
| 66 | uint8_t readThreadIdBytes = ReadUint8(packetBuffer, offset); |
| 67 | BOOST_CHECK(readThreadIdBytes == threadId_size); |
| 68 | |
| 69 | offset += uint8_t_size; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 70 | uint32_t DeclCount = ReadUint32(packetBuffer, offset); |
| 71 | BOOST_CHECK(DeclCount == 5); |
| 72 | |
| 73 | offset += uint32_t_size; |
| 74 | SwTraceMessage swTraceMessage = ReadSwTraceMessage(packetBuffer->GetReadableData(), offset); |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 75 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 76 | BOOST_CHECK(swTraceMessage.m_Id == 0); |
| 77 | BOOST_CHECK(swTraceMessage.m_Name == "declareLabel"); |
| 78 | BOOST_CHECK(swTraceMessage.m_UiName == "declare label"); |
| 79 | BOOST_CHECK(swTraceMessage.m_ArgTypes.size() == 2); |
| 80 | BOOST_CHECK(swTraceMessage.m_ArgTypes[0] == 'p'); |
| 81 | BOOST_CHECK(swTraceMessage.m_ArgTypes[1] == 's'); |
| 82 | BOOST_CHECK(swTraceMessage.m_ArgNames.size() == 2); |
| 83 | BOOST_CHECK(swTraceMessage.m_ArgNames[0] == "guid"); |
| 84 | BOOST_CHECK(swTraceMessage.m_ArgNames[1] == "value"); |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 85 | |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 86 | swTraceMessage = ReadSwTraceMessage(packetBuffer->GetReadableData(), offset); |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 87 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 88 | BOOST_CHECK(swTraceMessage.m_Id == 1); |
| 89 | BOOST_CHECK(swTraceMessage.m_Name == "declareEntity"); |
| 90 | BOOST_CHECK(swTraceMessage.m_UiName == "declare entity"); |
| 91 | BOOST_CHECK(swTraceMessage.m_ArgTypes.size() == 1); |
| 92 | BOOST_CHECK(swTraceMessage.m_ArgTypes[0] == 'p'); |
| 93 | BOOST_CHECK(swTraceMessage.m_ArgNames.size() == 1); |
| 94 | BOOST_CHECK(swTraceMessage.m_ArgNames[0] == "guid"); |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 95 | |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 96 | swTraceMessage = ReadSwTraceMessage(packetBuffer->GetReadableData(), offset); |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 97 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 98 | BOOST_CHECK(swTraceMessage.m_Id == 2); |
| 99 | BOOST_CHECK(swTraceMessage.m_Name == "declareEventClass"); |
| 100 | BOOST_CHECK(swTraceMessage.m_UiName == "declare event class"); |
| 101 | BOOST_CHECK(swTraceMessage.m_ArgTypes.size() == 1); |
| 102 | BOOST_CHECK(swTraceMessage.m_ArgTypes[0] == 'p'); |
| 103 | BOOST_CHECK(swTraceMessage.m_ArgNames.size() == 1); |
| 104 | BOOST_CHECK(swTraceMessage.m_ArgNames[0] == "guid"); |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 105 | |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 106 | swTraceMessage = ReadSwTraceMessage(packetBuffer->GetReadableData(), offset); |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 107 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 108 | BOOST_CHECK(swTraceMessage.m_Id == 3); |
| 109 | BOOST_CHECK(swTraceMessage.m_Name == "declareRelationship"); |
| 110 | BOOST_CHECK(swTraceMessage.m_UiName == "declare relationship"); |
| 111 | BOOST_CHECK(swTraceMessage.m_ArgTypes.size() == 4); |
| 112 | BOOST_CHECK(swTraceMessage.m_ArgTypes[0] == 'I'); |
| 113 | BOOST_CHECK(swTraceMessage.m_ArgTypes[1] == 'p'); |
| 114 | BOOST_CHECK(swTraceMessage.m_ArgTypes[2] == 'p'); |
| 115 | BOOST_CHECK(swTraceMessage.m_ArgTypes[3] == 'p'); |
| 116 | BOOST_CHECK(swTraceMessage.m_ArgNames.size() == 4); |
| 117 | BOOST_CHECK(swTraceMessage.m_ArgNames[0] == "relationshipType"); |
| 118 | BOOST_CHECK(swTraceMessage.m_ArgNames[1] == "relationshipGuid"); |
| 119 | BOOST_CHECK(swTraceMessage.m_ArgNames[2] == "headGuid"); |
| 120 | BOOST_CHECK(swTraceMessage.m_ArgNames[3] == "tailGuid"); |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 121 | |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 122 | swTraceMessage = ReadSwTraceMessage(packetBuffer->GetReadableData(), offset); |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 123 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 124 | BOOST_CHECK(swTraceMessage.m_Id == 4); |
| 125 | BOOST_CHECK(swTraceMessage.m_Name == "declareEvent"); |
| 126 | BOOST_CHECK(swTraceMessage.m_UiName == "declare event"); |
| 127 | BOOST_CHECK(swTraceMessage.m_ArgTypes.size() == 3); |
| 128 | BOOST_CHECK(swTraceMessage.m_ArgTypes[0] == '@'); |
| 129 | BOOST_CHECK(swTraceMessage.m_ArgTypes[1] == 't'); |
| 130 | BOOST_CHECK(swTraceMessage.m_ArgTypes[2] == 'p'); |
| 131 | BOOST_CHECK(swTraceMessage.m_ArgNames.size() == 3); |
| 132 | BOOST_CHECK(swTraceMessage.m_ArgNames[0] == "timestamp"); |
| 133 | BOOST_CHECK(swTraceMessage.m_ArgNames[1] == "threadId"); |
| 134 | BOOST_CHECK(swTraceMessage.m_ArgNames[2] == "eventGuid"); |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 135 | } |
| 136 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 137 | BOOST_AUTO_TEST_CASE(SendTimelineEntityWithEventClassPacketTest) |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 138 | { |
| 139 | MockBufferManager bufferManager(40); |
| 140 | TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager); |
| 141 | std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket(); |
| 142 | |
| 143 | const uint64_t entityBinaryPacketProfilingGuid = 123456u; |
| 144 | sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid); |
| 145 | |
| 146 | const uint64_t eventClassBinaryPacketProfilingGuid = 789123u; |
| 147 | sendTimelinePacket->SendTimelineEventClassBinaryPacket(eventClassBinaryPacketProfilingGuid); |
| 148 | |
| 149 | // Commit the messages |
| 150 | sendTimelinePacket->Commit(); |
| 151 | |
| 152 | // Get the readable buffer |
| 153 | auto packetBuffer = bufferManager.GetReadableBuffer(); |
| 154 | |
| 155 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 156 | unsigned int uint64_t_size = sizeof(uint64_t); |
| 157 | |
| 158 | // Check the packet header |
| 159 | unsigned int offset = 0; |
| 160 | |
| 161 | // Reading TimelineEntityClassBinaryPacket |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 162 | uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset); |
| 163 | uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F; |
| 164 | uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F; |
| 165 | uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007; |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 166 | uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007; |
| 167 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 168 | BOOST_CHECK(entityBinaryPacketFamily == 1); |
| 169 | BOOST_CHECK(entityBinaryPacketClass == 0); |
| 170 | BOOST_CHECK(entityBinaryPacketType == 1); |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 171 | BOOST_CHECK(entityBinaryPacketStreamId == 0); |
| 172 | |
| 173 | offset += uint32_t_size; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 174 | |
| 175 | uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset); |
| 176 | |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 177 | uint32_t entityBinaryPacketSequenceNumbered = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001; |
| 178 | uint32_t entityBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 179 | |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 180 | BOOST_CHECK(entityBinaryPacketSequenceNumbered == 0); |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 181 | BOOST_CHECK(entityBinaryPacketDataLength == 24); |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 182 | |
| 183 | // Check the decl_id |
| 184 | offset += uint32_t_size; |
| 185 | uint32_t entitytDecId = ReadUint32(packetBuffer, offset); |
| 186 | |
| 187 | BOOST_CHECK(entitytDecId == uint32_t(1)); |
| 188 | |
| 189 | // Check the profiling GUID |
| 190 | offset += uint32_t_size; |
| 191 | uint64_t readProfilingGuid = ReadUint64(packetBuffer, offset); |
| 192 | |
| 193 | BOOST_CHECK(readProfilingGuid == entityBinaryPacketProfilingGuid); |
| 194 | |
| 195 | // Reading TimelineEventClassBinaryPacket |
| 196 | offset += uint64_t_size; |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 197 | |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 198 | uint32_t eventClassDeclId = ReadUint32(packetBuffer, offset); |
| 199 | BOOST_CHECK(eventClassDeclId == uint32_t(2)); |
| 200 | |
| 201 | // Check the profiling GUID |
| 202 | offset += uint32_t_size; |
| 203 | readProfilingGuid = ReadUint64(packetBuffer, offset); |
| 204 | BOOST_CHECK(readProfilingGuid == eventClassBinaryPacketProfilingGuid); |
| 205 | |
| 206 | bufferManager.MarkRead(packetBuffer); |
| 207 | } |
| 208 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 209 | BOOST_AUTO_TEST_CASE(SendEventClassAfterTimelineEntityPacketTest) |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 210 | { |
| 211 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 212 | unsigned int uint64_t_size = sizeof(uint64_t); |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 213 | unsigned int threadId_size = sizeof(std::thread::id); |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 214 | |
| 215 | MockBufferManager bufferManager(512); |
| 216 | TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager); |
| 217 | std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket(); |
| 218 | |
| 219 | // Send TimelineEntityClassBinaryPacket |
| 220 | const uint64_t entityBinaryPacketProfilingGuid = 123456u; |
| 221 | sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid); |
| 222 | |
| 223 | // Commit the buffer |
| 224 | sendTimelinePacket->Commit(); |
| 225 | |
| 226 | // Get the readable buffer |
| 227 | auto packetBuffer = bufferManager.GetReadableBuffer(); |
| 228 | |
| 229 | // Check the packet header |
| 230 | unsigned int offset = 0; |
| 231 | |
| 232 | // Reading TimelineEntityClassBinaryPacket |
| 233 | uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset); |
| 234 | uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F; |
| 235 | uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F; |
| 236 | uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007; |
| 237 | uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007; |
| 238 | |
| 239 | BOOST_CHECK(entityBinaryPacketFamily == 1); |
| 240 | BOOST_CHECK(entityBinaryPacketClass == 0); |
| 241 | BOOST_CHECK(entityBinaryPacketType == 1); |
| 242 | BOOST_CHECK(entityBinaryPacketStreamId == 0); |
| 243 | |
| 244 | offset += uint32_t_size; |
| 245 | uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset); |
| 246 | uint32_t entityBinaryPacketSequenceNumbered = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001; |
| 247 | uint32_t entityBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF; |
| 248 | BOOST_CHECK(entityBinaryPacketSequenceNumbered == 0); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 249 | BOOST_CHECK(entityBinaryPacketDataLength == 12); |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 250 | |
| 251 | // Check the decl_id |
| 252 | offset += uint32_t_size; |
| 253 | uint32_t entitytDecId = ReadUint32(packetBuffer, offset); |
| 254 | |
| 255 | BOOST_CHECK(entitytDecId == uint32_t(1)); |
| 256 | |
| 257 | // Check the profiling GUID |
| 258 | offset += uint32_t_size; |
| 259 | uint64_t readProfilingGuid = ReadUint64(packetBuffer, offset); |
| 260 | |
| 261 | BOOST_CHECK(readProfilingGuid == entityBinaryPacketProfilingGuid); |
| 262 | |
| 263 | bufferManager.MarkRead(packetBuffer); |
| 264 | |
| 265 | // Send TimelineEventClassBinaryPacket |
| 266 | const uint64_t eventClassBinaryPacketProfilingGuid = 789123u; |
| 267 | sendTimelinePacket->SendTimelineEventClassBinaryPacket(eventClassBinaryPacketProfilingGuid); |
| 268 | |
| 269 | // Commit the buffer |
| 270 | sendTimelinePacket->Commit(); |
| 271 | |
| 272 | // Get the readable buffer |
| 273 | packetBuffer = bufferManager.GetReadableBuffer(); |
| 274 | |
| 275 | // Check the packet header |
| 276 | offset = 0; |
| 277 | |
| 278 | // Reading TimelineEventClassBinaryPacket |
| 279 | uint32_t eventClassBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset); |
| 280 | uint32_t eventClassBinaryPacketFamily = (eventClassBinaryPacketHeaderWord0 >> 26) & 0x0000003F; |
| 281 | uint32_t eventClassBinaryPacketClass = (eventClassBinaryPacketHeaderWord0 >> 19) & 0x0000007F; |
| 282 | uint32_t eventClassBinaryPacketType = (eventClassBinaryPacketHeaderWord0 >> 16) & 0x00000007; |
| 283 | uint32_t eventClassBinaryPacketStreamId = (eventClassBinaryPacketHeaderWord0 >> 0) & 0x00000007; |
| 284 | |
| 285 | BOOST_CHECK(eventClassBinaryPacketFamily == 1); |
| 286 | BOOST_CHECK(eventClassBinaryPacketClass == 0); |
| 287 | BOOST_CHECK(eventClassBinaryPacketType == 1); |
| 288 | BOOST_CHECK(eventClassBinaryPacketStreamId == 0); |
| 289 | |
| 290 | offset += uint32_t_size; |
| 291 | uint32_t eventClassBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset); |
| 292 | uint32_t eventClassBinaryPacketSequenceNumbered = (eventClassBinaryPacketHeaderWord1 >> 24) & 0x00000001; |
| 293 | uint32_t eventClassBinaryPacketDataLength = (eventClassBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF; |
| 294 | BOOST_CHECK(eventClassBinaryPacketSequenceNumbered == 0); |
| 295 | BOOST_CHECK(eventClassBinaryPacketDataLength == 12); |
| 296 | |
| 297 | offset += uint32_t_size; |
| 298 | uint32_t eventClassDeclId = ReadUint32(packetBuffer, offset); |
| 299 | BOOST_CHECK(eventClassDeclId == uint32_t(2)); |
| 300 | |
| 301 | // Check the profiling GUID |
| 302 | offset += uint32_t_size; |
| 303 | readProfilingGuid = ReadUint64(packetBuffer, offset); |
| 304 | BOOST_CHECK(readProfilingGuid == eventClassBinaryPacketProfilingGuid); |
| 305 | |
| 306 | bufferManager.MarkRead(packetBuffer); |
| 307 | |
| 308 | // Send TimelineEventBinaryPacket |
| 309 | const uint64_t timestamp = 456789u; |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 310 | const std::thread::id threadId = std::this_thread::get_id(); |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 311 | const uint64_t eventProfilingGuid = 123456u; |
| 312 | sendTimelinePacket->SendTimelineEventBinaryPacket(timestamp, threadId, eventProfilingGuid); |
| 313 | |
| 314 | // Commit the buffer |
| 315 | sendTimelinePacket->Commit(); |
| 316 | |
| 317 | // Get the readable buffer |
| 318 | packetBuffer = bufferManager.GetReadableBuffer(); |
| 319 | |
| 320 | // Check the packet header |
| 321 | offset = 0; |
| 322 | |
| 323 | // Reading TimelineEventBinaryPacket |
| 324 | uint32_t eventBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset); |
| 325 | uint32_t eventBinaryPacketFamily = (eventBinaryPacketHeaderWord0 >> 26) & 0x0000003F; |
| 326 | uint32_t eventBinaryPacketClass = (eventBinaryPacketHeaderWord0 >> 19) & 0x0000007F; |
| 327 | uint32_t eventBinaryPacketType = (eventBinaryPacketHeaderWord0 >> 16) & 0x00000007; |
| 328 | uint32_t eventBinaryPacketStreamId = (eventBinaryPacketHeaderWord0 >> 0) & 0x00000007; |
| 329 | |
| 330 | BOOST_CHECK(eventBinaryPacketFamily == 1); |
| 331 | BOOST_CHECK(eventBinaryPacketClass == 0); |
| 332 | BOOST_CHECK(eventBinaryPacketType == 1); |
| 333 | BOOST_CHECK(eventBinaryPacketStreamId == 0); |
| 334 | |
| 335 | offset += uint32_t_size; |
| 336 | uint32_t eventBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset); |
| 337 | uint32_t eventBinaryPacketSequenceNumbered = (eventBinaryPacketHeaderWord1 >> 24) & 0x00000001; |
| 338 | uint32_t eventBinaryPacketDataLength = (eventBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF; |
| 339 | BOOST_CHECK(eventBinaryPacketSequenceNumbered == 0); |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 340 | BOOST_CHECK(eventBinaryPacketDataLength == 28); |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 341 | |
| 342 | // Check the decl_id |
| 343 | offset += uint32_t_size; |
| 344 | uint32_t eventDeclId = ReadUint32(packetBuffer, offset); |
| 345 | BOOST_CHECK(eventDeclId == 4); |
| 346 | |
| 347 | // Check the timestamp |
| 348 | offset += uint32_t_size; |
| 349 | uint64_t eventTimestamp = ReadUint64(packetBuffer, offset); |
| 350 | BOOST_CHECK(eventTimestamp == timestamp); |
| 351 | |
| 352 | // Check the thread id |
| 353 | offset += uint64_t_size; |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 354 | std::vector<uint8_t> readThreadId(threadId_size, 0); |
| 355 | ReadBytes(packetBuffer, offset, threadId_size, readThreadId.data()); |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 356 | BOOST_CHECK(readThreadId == threadId); |
| 357 | |
| 358 | // Check the profiling GUID |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 359 | offset += threadId_size; |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 360 | readProfilingGuid = ReadUint64(packetBuffer, offset); |
| 361 | BOOST_CHECK(readProfilingGuid == eventProfilingGuid); |
| 362 | } |
| 363 | |
| 364 | BOOST_AUTO_TEST_CASE(SendTimelinePacketTests2) |
| 365 | { |
| 366 | MockBufferManager bufferManager(40); |
| 367 | TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager); |
| 368 | std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket(); |
| 369 | |
| 370 | BOOST_CHECK_THROW(sendTimelinePacket->SendTimelineMessageDirectoryPackage(), |
| 371 | armnn::RuntimeException); |
| 372 | } |
| 373 | |
| 374 | BOOST_AUTO_TEST_CASE(SendTimelinePacketTests3) |
| 375 | { |
| 376 | MockBufferManager bufferManager(512); |
| 377 | TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager); |
| 378 | std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket(); |
| 379 | |
| 380 | // Send TimelineEntityClassBinaryPacket |
| 381 | const uint64_t entityBinaryPacketProfilingGuid = 123456u; |
| 382 | sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid); |
| 383 | |
| 384 | // Commit the buffer |
| 385 | sendTimelinePacket->Commit(); |
| 386 | |
| 387 | // Get the readable buffer |
| 388 | auto packetBuffer = bufferManager.GetReadableBuffer(); |
| 389 | |
| 390 | // Send TimelineEventClassBinaryPacket |
| 391 | const uint64_t eventClassBinaryPacketProfilingGuid = 789123u; |
| 392 | BOOST_CHECK_THROW(sendTimelinePacket->SendTimelineEventClassBinaryPacket(eventClassBinaryPacketProfilingGuid), |
| 393 | armnn::RuntimeException); |
| 394 | } |
| 395 | |
Jim Flynn | 00f3aaf | 2019-10-24 11:58:06 +0100 | [diff] [blame] | 396 | BOOST_AUTO_TEST_CASE(GetGuidsFromProfilingService) |
| 397 | { |
Narumol Prangnawarat | 85ad78c | 2019-11-18 15:34:23 +0000 | [diff] [blame] | 398 | armnn::IRuntime::CreationOptions::ExternalProfilingOptions options; |
Jim Flynn | 00f3aaf | 2019-10-24 11:58:06 +0100 | [diff] [blame] | 399 | options.m_EnableProfiling = true; |
Sadik Armagan | 3184c90 | 2020-03-18 10:57:30 +0000 | [diff] [blame^] | 400 | armnn::profiling::ProfilingService profilingService; |
Jim Flynn | 00f3aaf | 2019-10-24 11:58:06 +0100 | [diff] [blame] | 401 | profilingService.ResetExternalProfilingOptions(options, true); |
Sadik Armagan | 3184c90 | 2020-03-18 10:57:30 +0000 | [diff] [blame^] | 402 | ProfilingStaticGuid staticGuid = profilingService.GetStaticId("dummy"); |
Jim Flynn | ab84575 | 2019-10-25 13:17:30 +0100 | [diff] [blame] | 403 | std::hash<std::string> hasher; |
| 404 | uint64_t hash = static_cast<uint64_t>(hasher("dummy")); |
Narumol Prangnawarat | dbdd1b4 | 2019-11-15 17:38:44 +0000 | [diff] [blame] | 405 | ProfilingStaticGuid expectedStaticValue(hash | MIN_STATIC_GUID); |
Jim Flynn | 00f3aaf | 2019-10-24 11:58:06 +0100 | [diff] [blame] | 406 | BOOST_CHECK(staticGuid == expectedStaticValue); |
Sadik Armagan | 3184c90 | 2020-03-18 10:57:30 +0000 | [diff] [blame^] | 407 | ProfilingDynamicGuid dynamicGuid = profilingService.GetNextGuid(); |
Jim Flynn | ab84575 | 2019-10-25 13:17:30 +0100 | [diff] [blame] | 408 | uint64_t dynamicGuidValue = static_cast<uint64_t>(dynamicGuid); |
| 409 | ++dynamicGuidValue; |
| 410 | ProfilingDynamicGuid expectedDynamicValue(dynamicGuidValue); |
Sadik Armagan | 3184c90 | 2020-03-18 10:57:30 +0000 | [diff] [blame^] | 411 | dynamicGuid = profilingService.GetNextGuid(); |
Jim Flynn | 00f3aaf | 2019-10-24 11:58:06 +0100 | [diff] [blame] | 412 | BOOST_CHECK(dynamicGuid == expectedDynamicValue); |
| 413 | } |
| 414 | |
Jim Flynn | 8b20065 | 2019-10-24 18:07:44 +0100 | [diff] [blame] | 415 | BOOST_AUTO_TEST_CASE(GetTimelinePackerWriterFromProfilingService) |
| 416 | { |
Narumol Prangnawarat | 85ad78c | 2019-11-18 15:34:23 +0000 | [diff] [blame] | 417 | armnn::IRuntime::CreationOptions::ExternalProfilingOptions options; |
Jim Flynn | 8b20065 | 2019-10-24 18:07:44 +0100 | [diff] [blame] | 418 | options.m_EnableProfiling = true; |
Sadik Armagan | 3184c90 | 2020-03-18 10:57:30 +0000 | [diff] [blame^] | 419 | armnn::profiling::ProfilingService profilingService; |
Jim Flynn | 8b20065 | 2019-10-24 18:07:44 +0100 | [diff] [blame] | 420 | profilingService.ResetExternalProfilingOptions(options, true); |
| 421 | |
| 422 | std::unique_ptr<ISendTimelinePacket> writer = profilingService.GetSendTimelinePacket(); |
| 423 | BOOST_CHECK(writer != nullptr); |
| 424 | } |
| 425 | |
Jim Flynn | ab84575 | 2019-10-25 13:17:30 +0100 | [diff] [blame] | 426 | BOOST_AUTO_TEST_CASE(CheckStaticGuidsAndEvents) |
| 427 | { |
| 428 | BOOST_CHECK("name" == LabelsAndEventClasses::NAME_LABEL); |
| 429 | BOOST_CHECK("type" == LabelsAndEventClasses::TYPE_LABEL); |
| 430 | BOOST_CHECK("index" == LabelsAndEventClasses::INDEX_LABEL); |
| 431 | |
| 432 | std::hash<std::string> hasher; |
| 433 | |
| 434 | uint64_t hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::NAME_LABEL)); |
Narumol Prangnawarat | dbdd1b4 | 2019-11-15 17:38:44 +0000 | [diff] [blame] | 435 | ProfilingStaticGuid expectedNameGuid(hash | MIN_STATIC_GUID); |
Jim Flynn | ab84575 | 2019-10-25 13:17:30 +0100 | [diff] [blame] | 436 | BOOST_CHECK(LabelsAndEventClasses::NAME_GUID == expectedNameGuid); |
| 437 | |
| 438 | hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::TYPE_LABEL)); |
Narumol Prangnawarat | dbdd1b4 | 2019-11-15 17:38:44 +0000 | [diff] [blame] | 439 | ProfilingStaticGuid expectedTypeGuid(hash | MIN_STATIC_GUID); |
Jim Flynn | ab84575 | 2019-10-25 13:17:30 +0100 | [diff] [blame] | 440 | BOOST_CHECK(LabelsAndEventClasses::TYPE_GUID == expectedTypeGuid); |
| 441 | |
| 442 | hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::INDEX_LABEL)); |
Narumol Prangnawarat | dbdd1b4 | 2019-11-15 17:38:44 +0000 | [diff] [blame] | 443 | ProfilingStaticGuid expectedIndexGuid(hash | MIN_STATIC_GUID); |
Jim Flynn | ab84575 | 2019-10-25 13:17:30 +0100 | [diff] [blame] | 444 | BOOST_CHECK(LabelsAndEventClasses::INDEX_GUID == expectedIndexGuid); |
| 445 | |
| 446 | hash = static_cast<uint64_t>(hasher("ARMNN_PROFILING_SOL")); |
Narumol Prangnawarat | dbdd1b4 | 2019-11-15 17:38:44 +0000 | [diff] [blame] | 447 | ProfilingStaticGuid expectedSol(hash | MIN_STATIC_GUID); |
Jim Flynn | ab84575 | 2019-10-25 13:17:30 +0100 | [diff] [blame] | 448 | BOOST_CHECK(LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS == expectedSol); |
| 449 | |
| 450 | hash = static_cast<uint64_t>(hasher("ARMNN_PROFILING_EOL")); |
Narumol Prangnawarat | dbdd1b4 | 2019-11-15 17:38:44 +0000 | [diff] [blame] | 451 | ProfilingStaticGuid expectedEol(hash | MIN_STATIC_GUID); |
Jim Flynn | ab84575 | 2019-10-25 13:17:30 +0100 | [diff] [blame] | 452 | BOOST_CHECK(LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS == expectedEol); |
| 453 | } |
| 454 | |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 455 | BOOST_AUTO_TEST_SUITE_END() |