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