blob: 76fa9c165744b848e2bd706cf846cbde18459d1a [file] [log] [blame]
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +01001//
Jim Flynn6398a982020-05-27 17:05:21 +01002// Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +01003// SPDX-License-Identifier: MIT
4//
5
Jim Flynn64063552020-02-14 10:18:08 +00006#include "ProfilingMocks.hpp"
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +01007
Jim Flynn34430252022-03-04 15:03:58 +00008#include <ArmNNProfilingServiceInitialiser.hpp>
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +01009#include <BufferManager.hpp>
Jim Flynn00f3aaf2019-10-24 11:58:06 +010010#include <ProfilingService.hpp>
Jim Flynn4c9ed1d2022-01-23 23:57:20 +000011#include "ProfilingOptionsConverter.hpp"
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010012#include <ProfilingUtils.hpp>
13#include <SendTimelinePacket.hpp>
Jim Flynn34430252022-03-04 15:03:58 +000014#include <armnn/profiling/ArmNNProfiling.hpp>
Rob Hughes9542f902021-07-14 09:48:54 +010015#include <armnnUtils/Threads.hpp>
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010016#include <TimelinePacketWriterFactory.hpp>
17
Jim Flynnbbfe6032020-07-20 16:57:44 +010018#include <common/include/SwTrace.hpp>
Nikhil Raj77fe76b2021-06-09 14:55:32 +010019#include <common/include/LabelsAndEventClasses.hpp>
Jim Flynnbbfe6032020-07-20 16:57:44 +010020
Sadik Armagan1625efc2021-06-10 18:24:34 +010021#include <doctest/doctest.h>
Jim Flynnab845752019-10-25 13:17:30 +010022
23#include <functional>
Keith Davis33ed2212020-03-30 10:43:41 +010024#include <Runtime.hpp>
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010025
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000026using namespace arm::pipe;
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010027
Sadik Armagan1625efc2021-06-10 18:24:34 +010028TEST_SUITE("SendTimelinePacketTests")
29{
30TEST_CASE("SendTimelineMessageDirectoryPackageTest")
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010031{
32 MockBufferManager mockBuffer(512);
33 TimelinePacketWriterFactory timelinePacketWriterFactory(mockBuffer);
34 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
35
36 sendTimelinePacket->SendTimelineMessageDirectoryPackage();
37
38 // Get the readable buffer
39 auto packetBuffer = mockBuffer.GetReadableBuffer();
40
Matteo Martincigh34a407d2019-11-06 15:30:54 +000041 unsigned int uint8_t_size = sizeof(uint8_t);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010042 unsigned int uint32_t_size = sizeof(uint32_t);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000043 unsigned int uint64_t_size = sizeof(uint64_t);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000044
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010045 // Check the packet header
46 unsigned int offset = 0;
47 uint32_t packetHeaderWord0 = ReadUint32(packetBuffer, offset);
48 uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F;
49 uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F;
50 uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007;
51 uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007;
52
Sadik Armagan1625efc2021-06-10 18:24:34 +010053 CHECK(packetFamily == 1);
54 CHECK(packetClass == 0);
55 CHECK(packetType == 0);
56 CHECK(streamId == 0);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010057
58 offset += uint32_t_size;
59 uint32_t packetHeaderWord1 = ReadUint32(packetBuffer, offset);
60 uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001;
61 uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF;
Sadik Armagan1625efc2021-06-10 18:24:34 +010062 CHECK(sequenceNumbered == 0);
63 CHECK(dataLength == 443);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010064
65 offset += uint32_t_size;
Matteo Martincigh34a407d2019-11-06 15:30:54 +000066 uint8_t readStreamVersion = ReadUint8(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +010067 CHECK(readStreamVersion == 4);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000068 offset += uint8_t_size;
69 uint8_t readPointerBytes = ReadUint8(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +010070 CHECK(readPointerBytes == uint64_t_size);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000071 offset += uint8_t_size;
72 uint8_t readThreadIdBytes = ReadUint8(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +010073 CHECK(readThreadIdBytes == ThreadIdSize);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000074
75 offset += uint8_t_size;
Finn Williamse63a0262019-10-22 10:30:49 +010076 uint32_t DeclCount = ReadUint32(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +010077 CHECK(DeclCount == 5);
Finn Williamse63a0262019-10-22 10:30:49 +010078
79 offset += uint32_t_size;
Jim Flynnbbfe6032020-07-20 16:57:44 +010080 arm::pipe::SwTraceMessage swTraceMessage = arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
81 offset,
82 packetBuffer->GetSize());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010083
Sadik Armagan1625efc2021-06-10 18:24:34 +010084 CHECK(swTraceMessage.m_Id == 0);
85 CHECK(swTraceMessage.m_Name == "declareLabel");
86 CHECK(swTraceMessage.m_UiName == "declare label");
87 CHECK(swTraceMessage.m_ArgTypes.size() == 2);
88 CHECK(swTraceMessage.m_ArgTypes[0] == 'p');
89 CHECK(swTraceMessage.m_ArgTypes[1] == 's');
90 CHECK(swTraceMessage.m_ArgNames.size() == 2);
91 CHECK(swTraceMessage.m_ArgNames[0] == "guid");
92 CHECK(swTraceMessage.m_ArgNames[1] == "value");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010093
Jim Flynnbbfe6032020-07-20 16:57:44 +010094 swTraceMessage = arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
95 offset,
96 packetBuffer->GetSize());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010097
Sadik Armagan1625efc2021-06-10 18:24:34 +010098 CHECK(swTraceMessage.m_Id == 1);
99 CHECK(swTraceMessage.m_Name == "declareEntity");
100 CHECK(swTraceMessage.m_UiName == "declare entity");
101 CHECK(swTraceMessage.m_ArgTypes.size() == 1);
102 CHECK(swTraceMessage.m_ArgTypes[0] == 'p');
103 CHECK(swTraceMessage.m_ArgNames.size() == 1);
104 CHECK(swTraceMessage.m_ArgNames[0] == "guid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100105
Jim Flynnbbfe6032020-07-20 16:57:44 +0100106 swTraceMessage = arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
107 offset,
108 packetBuffer->GetSize());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100109
Sadik Armagan1625efc2021-06-10 18:24:34 +0100110 CHECK(swTraceMessage.m_Id == 2);
111 CHECK(swTraceMessage.m_Name == "declareEventClass");
112 CHECK(swTraceMessage.m_UiName == "declare event class");
113 CHECK(swTraceMessage.m_ArgTypes.size() == 2);
114 CHECK(swTraceMessage.m_ArgTypes[0] == 'p');
115 CHECK(swTraceMessage.m_ArgTypes[1] == 'p');
116 CHECK(swTraceMessage.m_ArgNames.size() == 2);
117 CHECK(swTraceMessage.m_ArgNames[0] == "guid");
118 CHECK(swTraceMessage.m_ArgNames[1] == "nameGuid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100119
Jim Flynnbbfe6032020-07-20 16:57:44 +0100120 swTraceMessage = arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
121 offset,
122 packetBuffer->GetSize());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100123
Sadik Armagan1625efc2021-06-10 18:24:34 +0100124 CHECK(swTraceMessage.m_Id == 3);
125 CHECK(swTraceMessage.m_Name == "declareRelationship");
126 CHECK(swTraceMessage.m_UiName == "declare relationship");
127 CHECK(swTraceMessage.m_ArgTypes.size() == 5);
128 CHECK(swTraceMessage.m_ArgTypes[0] == 'I');
129 CHECK(swTraceMessage.m_ArgTypes[1] == 'p');
130 CHECK(swTraceMessage.m_ArgTypes[2] == 'p');
131 CHECK(swTraceMessage.m_ArgTypes[3] == 'p');
132 CHECK(swTraceMessage.m_ArgTypes[4] == 'p');
133 CHECK(swTraceMessage.m_ArgNames.size() == 5);
134 CHECK(swTraceMessage.m_ArgNames[0] == "relationshipType");
135 CHECK(swTraceMessage.m_ArgNames[1] == "relationshipGuid");
136 CHECK(swTraceMessage.m_ArgNames[2] == "headGuid");
137 CHECK(swTraceMessage.m_ArgNames[3] == "tailGuid");
138 CHECK(swTraceMessage.m_ArgNames[4] == "attributeGuid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100139
Jim Flynnbbfe6032020-07-20 16:57:44 +0100140 swTraceMessage = arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
141 offset,
142 packetBuffer->GetSize());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100143
Sadik Armagan1625efc2021-06-10 18:24:34 +0100144 CHECK(swTraceMessage.m_Id == 4);
145 CHECK(swTraceMessage.m_Name == "declareEvent");
146 CHECK(swTraceMessage.m_UiName == "declare event");
147 CHECK(swTraceMessage.m_ArgTypes.size() == 3);
148 CHECK(swTraceMessage.m_ArgTypes[0] == '@');
149 CHECK(swTraceMessage.m_ArgTypes[1] == 't');
150 CHECK(swTraceMessage.m_ArgTypes[2] == 'p');
151 CHECK(swTraceMessage.m_ArgNames.size() == 3);
152 CHECK(swTraceMessage.m_ArgNames[0] == "timestamp");
153 CHECK(swTraceMessage.m_ArgNames[1] == "threadId");
154 CHECK(swTraceMessage.m_ArgNames[2] == "eventGuid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100155}
156
Sadik Armagan1625efc2021-06-10 18:24:34 +0100157TEST_CASE("SendTimelineEntityWithEventClassPacketTest")
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100158{
159 MockBufferManager bufferManager(40);
160 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
161 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
162
163 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
164 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
165
166 const uint64_t eventClassBinaryPacketProfilingGuid = 789123u;
Jim Flynn1892d212020-05-26 21:10:49 +0100167 const uint64_t eventClassBinaryPacketNameGuid = 8845u;
168 sendTimelinePacket->SendTimelineEventClassBinaryPacket(
169 eventClassBinaryPacketProfilingGuid, eventClassBinaryPacketNameGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100170
171 // Commit the messages
172 sendTimelinePacket->Commit();
173
174 // Get the readable buffer
175 auto packetBuffer = bufferManager.GetReadableBuffer();
176
177 unsigned int uint32_t_size = sizeof(uint32_t);
178 unsigned int uint64_t_size = sizeof(uint64_t);
179
180 // Check the packet header
181 unsigned int offset = 0;
182
183 // Reading TimelineEntityClassBinaryPacket
Keith Davis97da5e22020-03-05 16:25:28 +0000184 uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
185 uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
186 uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
187 uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007;
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100188 uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007;
189
Sadik Armagan1625efc2021-06-10 18:24:34 +0100190 CHECK(entityBinaryPacketFamily == 1);
191 CHECK(entityBinaryPacketClass == 0);
192 CHECK(entityBinaryPacketType == 1);
193 CHECK(entityBinaryPacketStreamId == 0);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100194
195 offset += uint32_t_size;
Keith Davis97da5e22020-03-05 16:25:28 +0000196
197 uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
198
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100199 uint32_t entityBinaryPacketSequenceNumbered = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001;
200 uint32_t entityBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
Keith Davis97da5e22020-03-05 16:25:28 +0000201
Sadik Armagan1625efc2021-06-10 18:24:34 +0100202 CHECK(entityBinaryPacketSequenceNumbered == 0);
203 CHECK(entityBinaryPacketDataLength == 32);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100204
205 // Check the decl_id
206 offset += uint32_t_size;
207 uint32_t entitytDecId = ReadUint32(packetBuffer, offset);
208
Sadik Armagan1625efc2021-06-10 18:24:34 +0100209 CHECK(entitytDecId == uint32_t(1));
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100210
211 // Check the profiling GUID
212 offset += uint32_t_size;
213 uint64_t readProfilingGuid = ReadUint64(packetBuffer, offset);
214
Sadik Armagan1625efc2021-06-10 18:24:34 +0100215 CHECK(readProfilingGuid == entityBinaryPacketProfilingGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100216
217 // Reading TimelineEventClassBinaryPacket
218 offset += uint64_t_size;
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100219
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100220 uint32_t eventClassDeclId = ReadUint32(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100221 CHECK(eventClassDeclId == uint32_t(2));
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100222
223 // Check the profiling GUID
224 offset += uint32_t_size;
225 readProfilingGuid = ReadUint64(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100226 CHECK(readProfilingGuid == eventClassBinaryPacketProfilingGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100227
Jim Flynn1892d212020-05-26 21:10:49 +0100228 offset += uint64_t_size;
229 uint64_t readEventClassNameGuid = ReadUint64(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100230 CHECK(readEventClassNameGuid == eventClassBinaryPacketNameGuid);
Jim Flynn1892d212020-05-26 21:10:49 +0100231
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100232 bufferManager.MarkRead(packetBuffer);
233}
234
Sadik Armagan1625efc2021-06-10 18:24:34 +0100235TEST_CASE("SendEventClassAfterTimelineEntityPacketTest")
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100236{
237 unsigned int uint32_t_size = sizeof(uint32_t);
238 unsigned int uint64_t_size = sizeof(uint64_t);
239
240 MockBufferManager bufferManager(512);
241 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
242 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
243
244 // Send TimelineEntityClassBinaryPacket
245 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
246 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
247
248 // Commit the buffer
249 sendTimelinePacket->Commit();
250
251 // Get the readable buffer
252 auto packetBuffer = bufferManager.GetReadableBuffer();
253
254 // Check the packet header
255 unsigned int offset = 0;
256
257 // Reading TimelineEntityClassBinaryPacket
258 uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
259 uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
260 uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
261 uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007;
262 uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007;
263
Sadik Armagan1625efc2021-06-10 18:24:34 +0100264 CHECK(entityBinaryPacketFamily == 1);
265 CHECK(entityBinaryPacketClass == 0);
266 CHECK(entityBinaryPacketType == 1);
267 CHECK(entityBinaryPacketStreamId == 0);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100268
269 offset += uint32_t_size;
270 uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
271 uint32_t entityBinaryPacketSequenceNumbered = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001;
272 uint32_t entityBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100273 CHECK(entityBinaryPacketSequenceNumbered == 0);
274 CHECK(entityBinaryPacketDataLength == 12);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100275
276 // Check the decl_id
277 offset += uint32_t_size;
278 uint32_t entitytDecId = ReadUint32(packetBuffer, offset);
279
Sadik Armagan1625efc2021-06-10 18:24:34 +0100280 CHECK(entitytDecId == uint32_t(1));
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100281
282 // Check the profiling GUID
283 offset += uint32_t_size;
284 uint64_t readProfilingGuid = ReadUint64(packetBuffer, offset);
285
Sadik Armagan1625efc2021-06-10 18:24:34 +0100286 CHECK(readProfilingGuid == entityBinaryPacketProfilingGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100287
288 bufferManager.MarkRead(packetBuffer);
289
290 // Send TimelineEventClassBinaryPacket
291 const uint64_t eventClassBinaryPacketProfilingGuid = 789123u;
Jim Flynn1892d212020-05-26 21:10:49 +0100292 const uint64_t eventClassBinaryPacketNameGuid = 8845u;
293 sendTimelinePacket->SendTimelineEventClassBinaryPacket(
294 eventClassBinaryPacketProfilingGuid, eventClassBinaryPacketNameGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100295
296 // Commit the buffer
297 sendTimelinePacket->Commit();
298
299 // Get the readable buffer
300 packetBuffer = bufferManager.GetReadableBuffer();
301
302 // Check the packet header
303 offset = 0;
304
305 // Reading TimelineEventClassBinaryPacket
306 uint32_t eventClassBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
307 uint32_t eventClassBinaryPacketFamily = (eventClassBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
308 uint32_t eventClassBinaryPacketClass = (eventClassBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
309 uint32_t eventClassBinaryPacketType = (eventClassBinaryPacketHeaderWord0 >> 16) & 0x00000007;
310 uint32_t eventClassBinaryPacketStreamId = (eventClassBinaryPacketHeaderWord0 >> 0) & 0x00000007;
311
Sadik Armagan1625efc2021-06-10 18:24:34 +0100312 CHECK(eventClassBinaryPacketFamily == 1);
313 CHECK(eventClassBinaryPacketClass == 0);
314 CHECK(eventClassBinaryPacketType == 1);
315 CHECK(eventClassBinaryPacketStreamId == 0);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100316
317 offset += uint32_t_size;
318 uint32_t eventClassBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
319 uint32_t eventClassBinaryPacketSequenceNumbered = (eventClassBinaryPacketHeaderWord1 >> 24) & 0x00000001;
320 uint32_t eventClassBinaryPacketDataLength = (eventClassBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100321 CHECK(eventClassBinaryPacketSequenceNumbered == 0);
322 CHECK(eventClassBinaryPacketDataLength == 20);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100323
324 offset += uint32_t_size;
325 uint32_t eventClassDeclId = ReadUint32(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100326 CHECK(eventClassDeclId == uint32_t(2));
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100327
328 // Check the profiling GUID
329 offset += uint32_t_size;
330 readProfilingGuid = ReadUint64(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100331 CHECK(readProfilingGuid == eventClassBinaryPacketProfilingGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100332
Jim Flynn1892d212020-05-26 21:10:49 +0100333 offset += uint64_t_size;
334 uint64_t readEventClassNameGuid = ReadUint64(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100335 CHECK(readEventClassNameGuid == eventClassBinaryPacketNameGuid);
Jim Flynn1892d212020-05-26 21:10:49 +0100336
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100337 bufferManager.MarkRead(packetBuffer);
338
339 // Send TimelineEventBinaryPacket
340 const uint64_t timestamp = 456789u;
Jim Flynn1fdeb992020-07-09 07:28:37 +0100341 const int threadId = armnnUtils::Threads::GetCurrentThreadId();
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100342 const uint64_t eventProfilingGuid = 123456u;
343 sendTimelinePacket->SendTimelineEventBinaryPacket(timestamp, threadId, eventProfilingGuid);
344
345 // Commit the buffer
346 sendTimelinePacket->Commit();
347
348 // Get the readable buffer
349 packetBuffer = bufferManager.GetReadableBuffer();
350
351 // Check the packet header
352 offset = 0;
353
354 // Reading TimelineEventBinaryPacket
355 uint32_t eventBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
356 uint32_t eventBinaryPacketFamily = (eventBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
357 uint32_t eventBinaryPacketClass = (eventBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
358 uint32_t eventBinaryPacketType = (eventBinaryPacketHeaderWord0 >> 16) & 0x00000007;
359 uint32_t eventBinaryPacketStreamId = (eventBinaryPacketHeaderWord0 >> 0) & 0x00000007;
360
Sadik Armagan1625efc2021-06-10 18:24:34 +0100361 CHECK(eventBinaryPacketFamily == 1);
362 CHECK(eventBinaryPacketClass == 0);
363 CHECK(eventBinaryPacketType == 1);
364 CHECK(eventBinaryPacketStreamId == 0);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100365
366 offset += uint32_t_size;
367 uint32_t eventBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
368 uint32_t eventBinaryPacketSequenceNumbered = (eventBinaryPacketHeaderWord1 >> 24) & 0x00000001;
369 uint32_t eventBinaryPacketDataLength = (eventBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100370 CHECK(eventBinaryPacketSequenceNumbered == 0);
371 CHECK(eventBinaryPacketDataLength == 20 + ThreadIdSize);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100372
373 // Check the decl_id
374 offset += uint32_t_size;
375 uint32_t eventDeclId = ReadUint32(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100376 CHECK(eventDeclId == 4);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100377
378 // Check the timestamp
379 offset += uint32_t_size;
380 uint64_t eventTimestamp = ReadUint64(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100381 CHECK(eventTimestamp == timestamp);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100382
383 // Check the thread id
384 offset += uint64_t_size;
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100385 std::vector<uint8_t> readThreadId(ThreadIdSize, 0);
386 ReadBytes(packetBuffer, offset, ThreadIdSize, readThreadId.data());
Sadik Armagan1625efc2021-06-10 18:24:34 +0100387 CHECK(readThreadId == threadId);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100388
389 // Check the profiling GUID
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100390 offset += ThreadIdSize;
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100391 readProfilingGuid = ReadUint64(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100392 CHECK(readProfilingGuid == eventProfilingGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100393}
394
Sadik Armagan1625efc2021-06-10 18:24:34 +0100395TEST_CASE("SendTimelinePacketTests2")
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100396{
397 MockBufferManager bufferManager(40);
398 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
399 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
400
Sadik Armagan1625efc2021-06-10 18:24:34 +0100401 CHECK_THROWS_AS(sendTimelinePacket->SendTimelineMessageDirectoryPackage(),
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100402 armnn::RuntimeException);
403}
404
Sadik Armagan1625efc2021-06-10 18:24:34 +0100405TEST_CASE("SendTimelinePacketTests3")
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100406{
407 MockBufferManager bufferManager(512);
408 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
409 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
410
411 // Send TimelineEntityClassBinaryPacket
412 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
413 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
414
415 // Commit the buffer
416 sendTimelinePacket->Commit();
417
418 // Get the readable buffer
419 auto packetBuffer = bufferManager.GetReadableBuffer();
420
421 // Send TimelineEventClassBinaryPacket
422 const uint64_t eventClassBinaryPacketProfilingGuid = 789123u;
Jim Flynn1892d212020-05-26 21:10:49 +0100423 const uint64_t eventClassBinaryPacketNameGuid = 8845u;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100424 CHECK_THROWS_AS(sendTimelinePacket->SendTimelineEventClassBinaryPacket(
Jim Flynn1892d212020-05-26 21:10:49 +0100425 eventClassBinaryPacketProfilingGuid, eventClassBinaryPacketNameGuid),
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000426 BufferExhaustion);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100427}
428
Sadik Armagan1625efc2021-06-10 18:24:34 +0100429TEST_CASE("GetGuidsFromProfilingService")
Jim Flynn00f3aaf2019-10-24 11:58:06 +0100430{
Keith Davis33ed2212020-03-30 10:43:41 +0100431 armnn::IRuntime::CreationOptions options;
432 options.m_ProfilingOptions.m_EnableProfiling = true;
Kevin Mayd92a6e42021-02-04 10:27:41 +0000433 armnn::RuntimeImpl runtime(options);
Jim Flynn34430252022-03-04 15:03:58 +0000434 armnn::ArmNNProfilingServiceInitialiser initialiser;
435 ProfilingService profilingService(arm::pipe::MAX_ARMNN_COUNTER, initialiser, runtime);
Keith Davis33ed2212020-03-30 10:43:41 +0100436
Jim Flynn4c9ed1d2022-01-23 23:57:20 +0000437 profilingService.ResetExternalProfilingOptions(
438 ConvertExternalProfilingOptions(options.m_ProfilingOptions), true);
Sadik Armagan3184c902020-03-18 10:57:30 +0000439 ProfilingStaticGuid staticGuid = profilingService.GetStaticId("dummy");
Jim Flynnab845752019-10-25 13:17:30 +0100440 std::hash<std::string> hasher;
441 uint64_t hash = static_cast<uint64_t>(hasher("dummy"));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000442 ProfilingStaticGuid expectedStaticValue(hash | MIN_STATIC_GUID);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100443 CHECK(staticGuid == expectedStaticValue);
Sadik Armagan3184c902020-03-18 10:57:30 +0000444 ProfilingDynamicGuid dynamicGuid = profilingService.GetNextGuid();
Jim Flynnab845752019-10-25 13:17:30 +0100445 uint64_t dynamicGuidValue = static_cast<uint64_t>(dynamicGuid);
446 ++dynamicGuidValue;
447 ProfilingDynamicGuid expectedDynamicValue(dynamicGuidValue);
Sadik Armagan3184c902020-03-18 10:57:30 +0000448 dynamicGuid = profilingService.GetNextGuid();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100449 CHECK(dynamicGuid == expectedDynamicValue);
Jim Flynn00f3aaf2019-10-24 11:58:06 +0100450}
451
Sadik Armagan1625efc2021-06-10 18:24:34 +0100452TEST_CASE("GetTimelinePackerWriterFromProfilingService")
Jim Flynn8b200652019-10-24 18:07:44 +0100453{
Jim Flynn4c9ed1d2022-01-23 23:57:20 +0000454 ProfilingOptions options;
Jim Flynn8b200652019-10-24 18:07:44 +0100455 options.m_EnableProfiling = true;
Jim Flynn34430252022-03-04 15:03:58 +0000456 armnn::ArmNNProfilingServiceInitialiser initialiser;
457 ProfilingService profilingService(arm::pipe::MAX_ARMNN_COUNTER, initialiser);
Jim Flynn8b200652019-10-24 18:07:44 +0100458 profilingService.ResetExternalProfilingOptions(options, true);
459
460 std::unique_ptr<ISendTimelinePacket> writer = profilingService.GetSendTimelinePacket();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100461 CHECK(writer != nullptr);
Jim Flynn8b200652019-10-24 18:07:44 +0100462}
463
Sadik Armagan1625efc2021-06-10 18:24:34 +0100464TEST_CASE("CheckStaticGuidsAndEvents")
Jim Flynnab845752019-10-25 13:17:30 +0100465{
Sadik Armagan1625efc2021-06-10 18:24:34 +0100466 CHECK("name" == LabelsAndEventClasses::NAME_LABEL);
467 CHECK("type" == LabelsAndEventClasses::TYPE_LABEL);
468 CHECK("index" == LabelsAndEventClasses::INDEX_LABEL);
Jim Flynnab845752019-10-25 13:17:30 +0100469
470 std::hash<std::string> hasher;
471
472 uint64_t hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::NAME_LABEL));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000473 ProfilingStaticGuid expectedNameGuid(hash | MIN_STATIC_GUID);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100474 CHECK(LabelsAndEventClasses::NAME_GUID == expectedNameGuid);
Jim Flynnab845752019-10-25 13:17:30 +0100475
476 hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::TYPE_LABEL));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000477 ProfilingStaticGuid expectedTypeGuid(hash | MIN_STATIC_GUID);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100478 CHECK(LabelsAndEventClasses::TYPE_GUID == expectedTypeGuid);
Jim Flynnab845752019-10-25 13:17:30 +0100479
480 hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::INDEX_LABEL));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000481 ProfilingStaticGuid expectedIndexGuid(hash | MIN_STATIC_GUID);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100482 CHECK(LabelsAndEventClasses::INDEX_GUID == expectedIndexGuid);
Jim Flynnab845752019-10-25 13:17:30 +0100483
484 hash = static_cast<uint64_t>(hasher("ARMNN_PROFILING_SOL"));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000485 ProfilingStaticGuid expectedSol(hash | MIN_STATIC_GUID);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100486 CHECK(LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS == expectedSol);
Jim Flynnab845752019-10-25 13:17:30 +0100487
488 hash = static_cast<uint64_t>(hasher("ARMNN_PROFILING_EOL"));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000489 ProfilingStaticGuid expectedEol(hash | MIN_STATIC_GUID);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100490 CHECK(LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS == expectedEol);
Jim Flynnab845752019-10-25 13:17:30 +0100491}
492
Sadik Armagan1625efc2021-06-10 18:24:34 +0100493}