blob: 1d4341565953be34de707681013302a5050cbafd [file] [log] [blame]
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +01001//
Tracy Narine2883a862024-02-26 15:05:11 +00002// Copyright © 2019, 2024 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"
Jim Flynn6c9f17d2022-03-10 23:13:01 +00007#include "ProfilingTestUtils.hpp"
Jim Flynn4c9ed1d2022-01-23 23:57:20 +00008#include "ProfilingOptionsConverter.hpp"
Jim Flynn3e9bc192022-03-23 23:01:26 +00009#include <Runtime.hpp>
10#include <ArmNNProfilingServiceInitialiser.hpp>
11
Jim Flynn34430252022-03-04 15:03:58 +000012#include <armnn/profiling/ArmNNProfiling.hpp>
Jim Flynn3e9bc192022-03-23 23:01:26 +000013
14#include <client/src/BufferManager.hpp>
15#include <client/src/ProfilingService.hpp>
16#include <client/src/ProfilingUtils.hpp>
17#include <client/src/SendTimelinePacket.hpp>
18#include <client/src/TimelinePacketWriterFactory.hpp>
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010019
Nikhil Raj77fe76b2021-06-09 14:55:32 +010020#include <common/include/LabelsAndEventClasses.hpp>
Jim Flynn9c85b412022-03-16 00:27:43 +000021#include <common/include/SwTrace.hpp>
22#include <common/include/Threads.hpp>
Jim Flynnbbfe6032020-07-20 16:57:44 +010023
Sadik Armagan1625efc2021-06-10 18:24:34 +010024#include <doctest/doctest.h>
Jim Flynnab845752019-10-25 13:17:30 +010025
26#include <functional>
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010027
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000028using namespace arm::pipe;
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010029
Sadik Armagan1625efc2021-06-10 18:24:34 +010030TEST_SUITE("SendTimelinePacketTests")
31{
Tracy Narine2883a862024-02-26 15:05:11 +000032
33#if !defined(__APPLE__)
34
Sadik Armagan1625efc2021-06-10 18:24:34 +010035TEST_CASE("SendTimelineMessageDirectoryPackageTest")
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010036{
37 MockBufferManager mockBuffer(512);
38 TimelinePacketWriterFactory timelinePacketWriterFactory(mockBuffer);
39 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
40
41 sendTimelinePacket->SendTimelineMessageDirectoryPackage();
42
43 // Get the readable buffer
44 auto packetBuffer = mockBuffer.GetReadableBuffer();
45
Matteo Martincigh34a407d2019-11-06 15:30:54 +000046 unsigned int uint8_t_size = sizeof(uint8_t);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010047 unsigned int uint32_t_size = sizeof(uint32_t);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000048 unsigned int uint64_t_size = sizeof(uint64_t);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000049
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010050 // Check the packet header
51 unsigned int offset = 0;
52 uint32_t packetHeaderWord0 = ReadUint32(packetBuffer, offset);
53 uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F;
54 uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F;
55 uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007;
56 uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007;
57
Sadik Armagan1625efc2021-06-10 18:24:34 +010058 CHECK(packetFamily == 1);
59 CHECK(packetClass == 0);
60 CHECK(packetType == 0);
61 CHECK(streamId == 0);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010062
63 offset += uint32_t_size;
64 uint32_t packetHeaderWord1 = ReadUint32(packetBuffer, offset);
65 uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001;
66 uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF;
Sadik Armagan1625efc2021-06-10 18:24:34 +010067 CHECK(sequenceNumbered == 0);
68 CHECK(dataLength == 443);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010069
70 offset += uint32_t_size;
Matteo Martincigh34a407d2019-11-06 15:30:54 +000071 uint8_t readStreamVersion = ReadUint8(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +010072 CHECK(readStreamVersion == 4);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000073 offset += uint8_t_size;
74 uint8_t readPointerBytes = ReadUint8(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +010075 CHECK(readPointerBytes == uint64_t_size);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000076 offset += uint8_t_size;
77 uint8_t readThreadIdBytes = ReadUint8(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +010078 CHECK(readThreadIdBytes == ThreadIdSize);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000079
80 offset += uint8_t_size;
Finn Williamse63a0262019-10-22 10:30:49 +010081 uint32_t DeclCount = ReadUint32(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +010082 CHECK(DeclCount == 5);
Finn Williamse63a0262019-10-22 10:30:49 +010083
84 offset += uint32_t_size;
Jim Flynnbbfe6032020-07-20 16:57:44 +010085 arm::pipe::SwTraceMessage swTraceMessage = arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
86 offset,
87 packetBuffer->GetSize());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010088
Sadik Armagan1625efc2021-06-10 18:24:34 +010089 CHECK(swTraceMessage.m_Id == 0);
90 CHECK(swTraceMessage.m_Name == "declareLabel");
91 CHECK(swTraceMessage.m_UiName == "declare label");
92 CHECK(swTraceMessage.m_ArgTypes.size() == 2);
93 CHECK(swTraceMessage.m_ArgTypes[0] == 'p');
94 CHECK(swTraceMessage.m_ArgTypes[1] == 's');
95 CHECK(swTraceMessage.m_ArgNames.size() == 2);
96 CHECK(swTraceMessage.m_ArgNames[0] == "guid");
97 CHECK(swTraceMessage.m_ArgNames[1] == "value");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010098
Jim Flynnbbfe6032020-07-20 16:57:44 +010099 swTraceMessage = arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
100 offset,
101 packetBuffer->GetSize());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100102
Sadik Armagan1625efc2021-06-10 18:24:34 +0100103 CHECK(swTraceMessage.m_Id == 1);
104 CHECK(swTraceMessage.m_Name == "declareEntity");
105 CHECK(swTraceMessage.m_UiName == "declare entity");
106 CHECK(swTraceMessage.m_ArgTypes.size() == 1);
107 CHECK(swTraceMessage.m_ArgTypes[0] == 'p');
108 CHECK(swTraceMessage.m_ArgNames.size() == 1);
109 CHECK(swTraceMessage.m_ArgNames[0] == "guid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100110
Jim Flynnbbfe6032020-07-20 16:57:44 +0100111 swTraceMessage = arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
112 offset,
113 packetBuffer->GetSize());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100114
Sadik Armagan1625efc2021-06-10 18:24:34 +0100115 CHECK(swTraceMessage.m_Id == 2);
116 CHECK(swTraceMessage.m_Name == "declareEventClass");
117 CHECK(swTraceMessage.m_UiName == "declare event class");
118 CHECK(swTraceMessage.m_ArgTypes.size() == 2);
119 CHECK(swTraceMessage.m_ArgTypes[0] == 'p');
120 CHECK(swTraceMessage.m_ArgTypes[1] == 'p');
121 CHECK(swTraceMessage.m_ArgNames.size() == 2);
122 CHECK(swTraceMessage.m_ArgNames[0] == "guid");
123 CHECK(swTraceMessage.m_ArgNames[1] == "nameGuid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100124
Jim Flynnbbfe6032020-07-20 16:57:44 +0100125 swTraceMessage = arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
126 offset,
127 packetBuffer->GetSize());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100128
Sadik Armagan1625efc2021-06-10 18:24:34 +0100129 CHECK(swTraceMessage.m_Id == 3);
130 CHECK(swTraceMessage.m_Name == "declareRelationship");
131 CHECK(swTraceMessage.m_UiName == "declare relationship");
132 CHECK(swTraceMessage.m_ArgTypes.size() == 5);
133 CHECK(swTraceMessage.m_ArgTypes[0] == 'I');
134 CHECK(swTraceMessage.m_ArgTypes[1] == 'p');
135 CHECK(swTraceMessage.m_ArgTypes[2] == 'p');
136 CHECK(swTraceMessage.m_ArgTypes[3] == 'p');
137 CHECK(swTraceMessage.m_ArgTypes[4] == 'p');
138 CHECK(swTraceMessage.m_ArgNames.size() == 5);
139 CHECK(swTraceMessage.m_ArgNames[0] == "relationshipType");
140 CHECK(swTraceMessage.m_ArgNames[1] == "relationshipGuid");
141 CHECK(swTraceMessage.m_ArgNames[2] == "headGuid");
142 CHECK(swTraceMessage.m_ArgNames[3] == "tailGuid");
143 CHECK(swTraceMessage.m_ArgNames[4] == "attributeGuid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100144
Jim Flynnbbfe6032020-07-20 16:57:44 +0100145 swTraceMessage = arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
146 offset,
147 packetBuffer->GetSize());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100148
Sadik Armagan1625efc2021-06-10 18:24:34 +0100149 CHECK(swTraceMessage.m_Id == 4);
150 CHECK(swTraceMessage.m_Name == "declareEvent");
151 CHECK(swTraceMessage.m_UiName == "declare event");
152 CHECK(swTraceMessage.m_ArgTypes.size() == 3);
153 CHECK(swTraceMessage.m_ArgTypes[0] == '@');
154 CHECK(swTraceMessage.m_ArgTypes[1] == 't');
155 CHECK(swTraceMessage.m_ArgTypes[2] == 'p');
156 CHECK(swTraceMessage.m_ArgNames.size() == 3);
157 CHECK(swTraceMessage.m_ArgNames[0] == "timestamp");
158 CHECK(swTraceMessage.m_ArgNames[1] == "threadId");
159 CHECK(swTraceMessage.m_ArgNames[2] == "eventGuid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100160}
161
Sadik Armagan1625efc2021-06-10 18:24:34 +0100162TEST_CASE("SendTimelineEntityWithEventClassPacketTest")
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100163{
164 MockBufferManager bufferManager(40);
165 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
166 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
167
168 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
169 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
170
171 const uint64_t eventClassBinaryPacketProfilingGuid = 789123u;
Jim Flynn1892d212020-05-26 21:10:49 +0100172 const uint64_t eventClassBinaryPacketNameGuid = 8845u;
173 sendTimelinePacket->SendTimelineEventClassBinaryPacket(
174 eventClassBinaryPacketProfilingGuid, eventClassBinaryPacketNameGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100175
176 // Commit the messages
177 sendTimelinePacket->Commit();
178
179 // Get the readable buffer
180 auto packetBuffer = bufferManager.GetReadableBuffer();
181
182 unsigned int uint32_t_size = sizeof(uint32_t);
183 unsigned int uint64_t_size = sizeof(uint64_t);
184
185 // Check the packet header
186 unsigned int offset = 0;
187
188 // Reading TimelineEntityClassBinaryPacket
Keith Davis97da5e22020-03-05 16:25:28 +0000189 uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
190 uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
191 uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
192 uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007;
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100193 uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007;
194
Sadik Armagan1625efc2021-06-10 18:24:34 +0100195 CHECK(entityBinaryPacketFamily == 1);
196 CHECK(entityBinaryPacketClass == 0);
197 CHECK(entityBinaryPacketType == 1);
198 CHECK(entityBinaryPacketStreamId == 0);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100199
200 offset += uint32_t_size;
Keith Davis97da5e22020-03-05 16:25:28 +0000201
202 uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
203
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100204 uint32_t entityBinaryPacketSequenceNumbered = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001;
205 uint32_t entityBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
Keith Davis97da5e22020-03-05 16:25:28 +0000206
Sadik Armagan1625efc2021-06-10 18:24:34 +0100207 CHECK(entityBinaryPacketSequenceNumbered == 0);
208 CHECK(entityBinaryPacketDataLength == 32);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100209
210 // Check the decl_id
211 offset += uint32_t_size;
212 uint32_t entitytDecId = ReadUint32(packetBuffer, offset);
213
Sadik Armagan1625efc2021-06-10 18:24:34 +0100214 CHECK(entitytDecId == uint32_t(1));
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100215
216 // Check the profiling GUID
217 offset += uint32_t_size;
218 uint64_t readProfilingGuid = ReadUint64(packetBuffer, offset);
219
Sadik Armagan1625efc2021-06-10 18:24:34 +0100220 CHECK(readProfilingGuid == entityBinaryPacketProfilingGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100221
222 // Reading TimelineEventClassBinaryPacket
223 offset += uint64_t_size;
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100224
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100225 uint32_t eventClassDeclId = ReadUint32(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100226 CHECK(eventClassDeclId == uint32_t(2));
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100227
228 // Check the profiling GUID
229 offset += uint32_t_size;
230 readProfilingGuid = ReadUint64(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100231 CHECK(readProfilingGuid == eventClassBinaryPacketProfilingGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100232
Jim Flynn1892d212020-05-26 21:10:49 +0100233 offset += uint64_t_size;
234 uint64_t readEventClassNameGuid = ReadUint64(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100235 CHECK(readEventClassNameGuid == eventClassBinaryPacketNameGuid);
Jim Flynn1892d212020-05-26 21:10:49 +0100236
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100237 bufferManager.MarkRead(packetBuffer);
238}
239
Sadik Armagan1625efc2021-06-10 18:24:34 +0100240TEST_CASE("SendEventClassAfterTimelineEntityPacketTest")
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100241{
242 unsigned int uint32_t_size = sizeof(uint32_t);
243 unsigned int uint64_t_size = sizeof(uint64_t);
244
245 MockBufferManager bufferManager(512);
246 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
247 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
248
249 // Send TimelineEntityClassBinaryPacket
250 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
251 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
252
253 // Commit the buffer
254 sendTimelinePacket->Commit();
255
256 // Get the readable buffer
257 auto packetBuffer = bufferManager.GetReadableBuffer();
258
259 // Check the packet header
260 unsigned int offset = 0;
261
262 // Reading TimelineEntityClassBinaryPacket
263 uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
264 uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
265 uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
266 uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007;
267 uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007;
268
Sadik Armagan1625efc2021-06-10 18:24:34 +0100269 CHECK(entityBinaryPacketFamily == 1);
270 CHECK(entityBinaryPacketClass == 0);
271 CHECK(entityBinaryPacketType == 1);
272 CHECK(entityBinaryPacketStreamId == 0);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100273
274 offset += uint32_t_size;
275 uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
276 uint32_t entityBinaryPacketSequenceNumbered = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001;
277 uint32_t entityBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100278 CHECK(entityBinaryPacketSequenceNumbered == 0);
279 CHECK(entityBinaryPacketDataLength == 12);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100280
281 // Check the decl_id
282 offset += uint32_t_size;
283 uint32_t entitytDecId = ReadUint32(packetBuffer, offset);
284
Sadik Armagan1625efc2021-06-10 18:24:34 +0100285 CHECK(entitytDecId == uint32_t(1));
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100286
287 // Check the profiling GUID
288 offset += uint32_t_size;
289 uint64_t readProfilingGuid = ReadUint64(packetBuffer, offset);
290
Sadik Armagan1625efc2021-06-10 18:24:34 +0100291 CHECK(readProfilingGuid == entityBinaryPacketProfilingGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100292
293 bufferManager.MarkRead(packetBuffer);
294
295 // Send TimelineEventClassBinaryPacket
296 const uint64_t eventClassBinaryPacketProfilingGuid = 789123u;
Jim Flynn1892d212020-05-26 21:10:49 +0100297 const uint64_t eventClassBinaryPacketNameGuid = 8845u;
298 sendTimelinePacket->SendTimelineEventClassBinaryPacket(
299 eventClassBinaryPacketProfilingGuid, eventClassBinaryPacketNameGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100300
301 // Commit the buffer
302 sendTimelinePacket->Commit();
303
304 // Get the readable buffer
305 packetBuffer = bufferManager.GetReadableBuffer();
306
307 // Check the packet header
308 offset = 0;
309
310 // Reading TimelineEventClassBinaryPacket
311 uint32_t eventClassBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
312 uint32_t eventClassBinaryPacketFamily = (eventClassBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
313 uint32_t eventClassBinaryPacketClass = (eventClassBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
314 uint32_t eventClassBinaryPacketType = (eventClassBinaryPacketHeaderWord0 >> 16) & 0x00000007;
315 uint32_t eventClassBinaryPacketStreamId = (eventClassBinaryPacketHeaderWord0 >> 0) & 0x00000007;
316
Sadik Armagan1625efc2021-06-10 18:24:34 +0100317 CHECK(eventClassBinaryPacketFamily == 1);
318 CHECK(eventClassBinaryPacketClass == 0);
319 CHECK(eventClassBinaryPacketType == 1);
320 CHECK(eventClassBinaryPacketStreamId == 0);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100321
322 offset += uint32_t_size;
323 uint32_t eventClassBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
324 uint32_t eventClassBinaryPacketSequenceNumbered = (eventClassBinaryPacketHeaderWord1 >> 24) & 0x00000001;
325 uint32_t eventClassBinaryPacketDataLength = (eventClassBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100326 CHECK(eventClassBinaryPacketSequenceNumbered == 0);
327 CHECK(eventClassBinaryPacketDataLength == 20);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100328
329 offset += uint32_t_size;
330 uint32_t eventClassDeclId = ReadUint32(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100331 CHECK(eventClassDeclId == uint32_t(2));
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100332
333 // Check the profiling GUID
334 offset += uint32_t_size;
335 readProfilingGuid = ReadUint64(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100336 CHECK(readProfilingGuid == eventClassBinaryPacketProfilingGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100337
Jim Flynn1892d212020-05-26 21:10:49 +0100338 offset += uint64_t_size;
339 uint64_t readEventClassNameGuid = ReadUint64(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100340 CHECK(readEventClassNameGuid == eventClassBinaryPacketNameGuid);
Jim Flynn1892d212020-05-26 21:10:49 +0100341
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100342 bufferManager.MarkRead(packetBuffer);
343
344 // Send TimelineEventBinaryPacket
345 const uint64_t timestamp = 456789u;
Jim Flynn9c85b412022-03-16 00:27:43 +0000346 const int threadId = arm::pipe::GetCurrentThreadId();
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100347 const uint64_t eventProfilingGuid = 123456u;
348 sendTimelinePacket->SendTimelineEventBinaryPacket(timestamp, threadId, eventProfilingGuid);
349
350 // Commit the buffer
351 sendTimelinePacket->Commit();
352
353 // Get the readable buffer
354 packetBuffer = bufferManager.GetReadableBuffer();
355
356 // Check the packet header
357 offset = 0;
358
359 // Reading TimelineEventBinaryPacket
360 uint32_t eventBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
361 uint32_t eventBinaryPacketFamily = (eventBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
362 uint32_t eventBinaryPacketClass = (eventBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
363 uint32_t eventBinaryPacketType = (eventBinaryPacketHeaderWord0 >> 16) & 0x00000007;
364 uint32_t eventBinaryPacketStreamId = (eventBinaryPacketHeaderWord0 >> 0) & 0x00000007;
365
Sadik Armagan1625efc2021-06-10 18:24:34 +0100366 CHECK(eventBinaryPacketFamily == 1);
367 CHECK(eventBinaryPacketClass == 0);
368 CHECK(eventBinaryPacketType == 1);
369 CHECK(eventBinaryPacketStreamId == 0);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100370
371 offset += uint32_t_size;
372 uint32_t eventBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
373 uint32_t eventBinaryPacketSequenceNumbered = (eventBinaryPacketHeaderWord1 >> 24) & 0x00000001;
374 uint32_t eventBinaryPacketDataLength = (eventBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100375 CHECK(eventBinaryPacketSequenceNumbered == 0);
376 CHECK(eventBinaryPacketDataLength == 20 + ThreadIdSize);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100377
378 // Check the decl_id
379 offset += uint32_t_size;
380 uint32_t eventDeclId = ReadUint32(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100381 CHECK(eventDeclId == 4);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100382
383 // Check the timestamp
384 offset += uint32_t_size;
385 uint64_t eventTimestamp = ReadUint64(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100386 CHECK(eventTimestamp == timestamp);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100387
388 // Check the thread id
389 offset += uint64_t_size;
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100390 std::vector<uint8_t> readThreadId(ThreadIdSize, 0);
391 ReadBytes(packetBuffer, offset, ThreadIdSize, readThreadId.data());
Sadik Armagan1625efc2021-06-10 18:24:34 +0100392 CHECK(readThreadId == threadId);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100393
394 // Check the profiling GUID
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100395 offset += ThreadIdSize;
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100396 readProfilingGuid = ReadUint64(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100397 CHECK(readProfilingGuid == eventProfilingGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100398}
399
Sadik Armagan1625efc2021-06-10 18:24:34 +0100400TEST_CASE("SendTimelinePacketTests2")
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100401{
402 MockBufferManager bufferManager(40);
403 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
404 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
405
Sadik Armagan1625efc2021-06-10 18:24:34 +0100406 CHECK_THROWS_AS(sendTimelinePacket->SendTimelineMessageDirectoryPackage(),
Jim Flynnf9db3ef2022-03-08 21:23:44 +0000407 arm::pipe::ProfilingException);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100408}
409
Sadik Armagan1625efc2021-06-10 18:24:34 +0100410TEST_CASE("SendTimelinePacketTests3")
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100411{
412 MockBufferManager bufferManager(512);
413 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
414 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
415
416 // Send TimelineEntityClassBinaryPacket
417 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
418 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
419
420 // Commit the buffer
421 sendTimelinePacket->Commit();
422
423 // Get the readable buffer
424 auto packetBuffer = bufferManager.GetReadableBuffer();
425
426 // Send TimelineEventClassBinaryPacket
427 const uint64_t eventClassBinaryPacketProfilingGuid = 789123u;
Jim Flynn1892d212020-05-26 21:10:49 +0100428 const uint64_t eventClassBinaryPacketNameGuid = 8845u;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100429 CHECK_THROWS_AS(sendTimelinePacket->SendTimelineEventClassBinaryPacket(
Jim Flynn1892d212020-05-26 21:10:49 +0100430 eventClassBinaryPacketProfilingGuid, eventClassBinaryPacketNameGuid),
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000431 BufferExhaustion);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100432}
433
Sadik Armagan1625efc2021-06-10 18:24:34 +0100434TEST_CASE("GetGuidsFromProfilingService")
Jim Flynn00f3aaf2019-10-24 11:58:06 +0100435{
Jim Flynn6c9f17d2022-03-10 23:13:01 +0000436 LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Fatal);
437
Keith Davis33ed2212020-03-30 10:43:41 +0100438 armnn::IRuntime::CreationOptions options;
439 options.m_ProfilingOptions.m_EnableProfiling = true;
Kevin Mayd92a6e42021-02-04 10:27:41 +0000440 armnn::RuntimeImpl runtime(options);
Jim Flynn34430252022-03-04 15:03:58 +0000441 armnn::ArmNNProfilingServiceInitialiser initialiser;
Jim Flynn9c85b412022-03-16 00:27:43 +0000442 ProfilingService profilingService(arm::pipe::MAX_ARMNN_COUNTER,
443 initialiser,
444 arm::pipe::ARMNN_SOFTWARE_INFO,
445 arm::pipe::ARMNN_SOFTWARE_VERSION,
446 arm::pipe::ARMNN_HARDWARE_VERSION,
447 runtime);
Keith Davis33ed2212020-03-30 10:43:41 +0100448
Jim Flynn4c9ed1d2022-01-23 23:57:20 +0000449 profilingService.ResetExternalProfilingOptions(
450 ConvertExternalProfilingOptions(options.m_ProfilingOptions), true);
Sadik Armagan3184c902020-03-18 10:57:30 +0000451 ProfilingStaticGuid staticGuid = profilingService.GetStaticId("dummy");
Jim Flynnab845752019-10-25 13:17:30 +0100452 std::hash<std::string> hasher;
453 uint64_t hash = static_cast<uint64_t>(hasher("dummy"));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000454 ProfilingStaticGuid expectedStaticValue(hash | MIN_STATIC_GUID);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100455 CHECK(staticGuid == expectedStaticValue);
Sadik Armagan3184c902020-03-18 10:57:30 +0000456 ProfilingDynamicGuid dynamicGuid = profilingService.GetNextGuid();
Jim Flynnab845752019-10-25 13:17:30 +0100457 uint64_t dynamicGuidValue = static_cast<uint64_t>(dynamicGuid);
458 ++dynamicGuidValue;
459 ProfilingDynamicGuid expectedDynamicValue(dynamicGuidValue);
Sadik Armagan3184c902020-03-18 10:57:30 +0000460 dynamicGuid = profilingService.GetNextGuid();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100461 CHECK(dynamicGuid == expectedDynamicValue);
Jim Flynn00f3aaf2019-10-24 11:58:06 +0100462}
463
Sadik Armagan1625efc2021-06-10 18:24:34 +0100464TEST_CASE("GetTimelinePackerWriterFromProfilingService")
Jim Flynn8b200652019-10-24 18:07:44 +0100465{
Jim Flynn6c9f17d2022-03-10 23:13:01 +0000466 LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Fatal);
467
Jim Flynn4c9ed1d2022-01-23 23:57:20 +0000468 ProfilingOptions options;
Jim Flynn8b200652019-10-24 18:07:44 +0100469 options.m_EnableProfiling = true;
Jim Flynn34430252022-03-04 15:03:58 +0000470 armnn::ArmNNProfilingServiceInitialiser initialiser;
Jim Flynn9c85b412022-03-16 00:27:43 +0000471 ProfilingService profilingService(arm::pipe::MAX_ARMNN_COUNTER,
472 initialiser,
473 arm::pipe::ARMNN_SOFTWARE_INFO,
474 arm::pipe::ARMNN_SOFTWARE_VERSION,
475 arm::pipe::ARMNN_HARDWARE_VERSION);
Jim Flynn8b200652019-10-24 18:07:44 +0100476 profilingService.ResetExternalProfilingOptions(options, true);
477
478 std::unique_ptr<ISendTimelinePacket> writer = profilingService.GetSendTimelinePacket();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100479 CHECK(writer != nullptr);
Jim Flynn8b200652019-10-24 18:07:44 +0100480}
481
Sadik Armagan1625efc2021-06-10 18:24:34 +0100482TEST_CASE("CheckStaticGuidsAndEvents")
Jim Flynnab845752019-10-25 13:17:30 +0100483{
Sadik Armagan1625efc2021-06-10 18:24:34 +0100484 CHECK("name" == LabelsAndEventClasses::NAME_LABEL);
485 CHECK("type" == LabelsAndEventClasses::TYPE_LABEL);
486 CHECK("index" == LabelsAndEventClasses::INDEX_LABEL);
Jim Flynnab845752019-10-25 13:17:30 +0100487
488 std::hash<std::string> hasher;
489
490 uint64_t hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::NAME_LABEL));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000491 ProfilingStaticGuid expectedNameGuid(hash | MIN_STATIC_GUID);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100492 CHECK(LabelsAndEventClasses::NAME_GUID == expectedNameGuid);
Jim Flynnab845752019-10-25 13:17:30 +0100493
494 hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::TYPE_LABEL));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000495 ProfilingStaticGuid expectedTypeGuid(hash | MIN_STATIC_GUID);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100496 CHECK(LabelsAndEventClasses::TYPE_GUID == expectedTypeGuid);
Jim Flynnab845752019-10-25 13:17:30 +0100497
498 hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::INDEX_LABEL));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000499 ProfilingStaticGuid expectedIndexGuid(hash | MIN_STATIC_GUID);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100500 CHECK(LabelsAndEventClasses::INDEX_GUID == expectedIndexGuid);
Jim Flynnab845752019-10-25 13:17:30 +0100501
502 hash = static_cast<uint64_t>(hasher("ARMNN_PROFILING_SOL"));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000503 ProfilingStaticGuid expectedSol(hash | MIN_STATIC_GUID);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100504 CHECK(LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS == expectedSol);
Jim Flynnab845752019-10-25 13:17:30 +0100505
506 hash = static_cast<uint64_t>(hasher("ARMNN_PROFILING_EOL"));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000507 ProfilingStaticGuid expectedEol(hash | MIN_STATIC_GUID);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100508 CHECK(LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS == expectedEol);
Jim Flynnab845752019-10-25 13:17:30 +0100509}
510
Tracy Narine2883a862024-02-26 15:05:11 +0000511#endif
512
Sadik Armagan1625efc2021-06-10 18:24:34 +0100513}