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