blob: ad71f8fd22a6732ccff293be3990d8b382fb8200 [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"
Jim Flynn6c9f17d2022-03-10 23:13:01 +00007#include "ProfilingTestUtils.hpp"
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +01008
Jim Flynn34430252022-03-04 15:03:58 +00009#include <ArmNNProfilingServiceInitialiser.hpp>
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010010#include <BufferManager.hpp>
Jim Flynn00f3aaf2019-10-24 11:58:06 +010011#include <ProfilingService.hpp>
Jim Flynn4c9ed1d2022-01-23 23:57:20 +000012#include "ProfilingOptionsConverter.hpp"
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010013#include <ProfilingUtils.hpp>
14#include <SendTimelinePacket.hpp>
Jim Flynn34430252022-03-04 15:03:58 +000015#include <armnn/profiling/ArmNNProfiling.hpp>
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010016#include <TimelinePacketWriterFactory.hpp>
17
Nikhil Raj77fe76b2021-06-09 14:55:32 +010018#include <common/include/LabelsAndEventClasses.hpp>
Jim Flynn9c85b412022-03-16 00:27:43 +000019#include <common/include/SwTrace.hpp>
20#include <common/include/Threads.hpp>
Jim Flynnbbfe6032020-07-20 16:57:44 +010021
Sadik Armagan1625efc2021-06-10 18:24:34 +010022#include <doctest/doctest.h>
Jim Flynnab845752019-10-25 13:17:30 +010023
24#include <functional>
Keith Davis33ed2212020-03-30 10:43:41 +010025#include <Runtime.hpp>
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010026
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000027using namespace arm::pipe;
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010028
Sadik Armagan1625efc2021-06-10 18:24:34 +010029TEST_SUITE("SendTimelinePacketTests")
30{
31TEST_CASE("SendTimelineMessageDirectoryPackageTest")
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010032{
33 MockBufferManager mockBuffer(512);
34 TimelinePacketWriterFactory timelinePacketWriterFactory(mockBuffer);
35 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
36
37 sendTimelinePacket->SendTimelineMessageDirectoryPackage();
38
39 // Get the readable buffer
40 auto packetBuffer = mockBuffer.GetReadableBuffer();
41
Matteo Martincigh34a407d2019-11-06 15:30:54 +000042 unsigned int uint8_t_size = sizeof(uint8_t);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010043 unsigned int uint32_t_size = sizeof(uint32_t);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000044 unsigned int uint64_t_size = sizeof(uint64_t);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000045
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010046 // Check the packet header
47 unsigned int offset = 0;
48 uint32_t packetHeaderWord0 = ReadUint32(packetBuffer, offset);
49 uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F;
50 uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F;
51 uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007;
52 uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007;
53
Sadik Armagan1625efc2021-06-10 18:24:34 +010054 CHECK(packetFamily == 1);
55 CHECK(packetClass == 0);
56 CHECK(packetType == 0);
57 CHECK(streamId == 0);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010058
59 offset += uint32_t_size;
60 uint32_t packetHeaderWord1 = ReadUint32(packetBuffer, offset);
61 uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001;
62 uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF;
Sadik Armagan1625efc2021-06-10 18:24:34 +010063 CHECK(sequenceNumbered == 0);
64 CHECK(dataLength == 443);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010065
66 offset += uint32_t_size;
Matteo Martincigh34a407d2019-11-06 15:30:54 +000067 uint8_t readStreamVersion = ReadUint8(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +010068 CHECK(readStreamVersion == 4);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000069 offset += uint8_t_size;
70 uint8_t readPointerBytes = ReadUint8(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +010071 CHECK(readPointerBytes == uint64_t_size);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000072 offset += uint8_t_size;
73 uint8_t readThreadIdBytes = ReadUint8(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +010074 CHECK(readThreadIdBytes == ThreadIdSize);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000075
76 offset += uint8_t_size;
Finn Williamse63a0262019-10-22 10:30:49 +010077 uint32_t DeclCount = ReadUint32(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +010078 CHECK(DeclCount == 5);
Finn Williamse63a0262019-10-22 10:30:49 +010079
80 offset += uint32_t_size;
Jim Flynnbbfe6032020-07-20 16:57:44 +010081 arm::pipe::SwTraceMessage swTraceMessage = arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
82 offset,
83 packetBuffer->GetSize());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010084
Sadik Armagan1625efc2021-06-10 18:24:34 +010085 CHECK(swTraceMessage.m_Id == 0);
86 CHECK(swTraceMessage.m_Name == "declareLabel");
87 CHECK(swTraceMessage.m_UiName == "declare label");
88 CHECK(swTraceMessage.m_ArgTypes.size() == 2);
89 CHECK(swTraceMessage.m_ArgTypes[0] == 'p');
90 CHECK(swTraceMessage.m_ArgTypes[1] == 's');
91 CHECK(swTraceMessage.m_ArgNames.size() == 2);
92 CHECK(swTraceMessage.m_ArgNames[0] == "guid");
93 CHECK(swTraceMessage.m_ArgNames[1] == "value");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010094
Jim Flynnbbfe6032020-07-20 16:57:44 +010095 swTraceMessage = arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
96 offset,
97 packetBuffer->GetSize());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010098
Sadik Armagan1625efc2021-06-10 18:24:34 +010099 CHECK(swTraceMessage.m_Id == 1);
100 CHECK(swTraceMessage.m_Name == "declareEntity");
101 CHECK(swTraceMessage.m_UiName == "declare entity");
102 CHECK(swTraceMessage.m_ArgTypes.size() == 1);
103 CHECK(swTraceMessage.m_ArgTypes[0] == 'p');
104 CHECK(swTraceMessage.m_ArgNames.size() == 1);
105 CHECK(swTraceMessage.m_ArgNames[0] == "guid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100106
Jim Flynnbbfe6032020-07-20 16:57:44 +0100107 swTraceMessage = arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
108 offset,
109 packetBuffer->GetSize());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100110
Sadik Armagan1625efc2021-06-10 18:24:34 +0100111 CHECK(swTraceMessage.m_Id == 2);
112 CHECK(swTraceMessage.m_Name == "declareEventClass");
113 CHECK(swTraceMessage.m_UiName == "declare event class");
114 CHECK(swTraceMessage.m_ArgTypes.size() == 2);
115 CHECK(swTraceMessage.m_ArgTypes[0] == 'p');
116 CHECK(swTraceMessage.m_ArgTypes[1] == 'p');
117 CHECK(swTraceMessage.m_ArgNames.size() == 2);
118 CHECK(swTraceMessage.m_ArgNames[0] == "guid");
119 CHECK(swTraceMessage.m_ArgNames[1] == "nameGuid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100120
Jim Flynnbbfe6032020-07-20 16:57:44 +0100121 swTraceMessage = arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
122 offset,
123 packetBuffer->GetSize());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100124
Sadik Armagan1625efc2021-06-10 18:24:34 +0100125 CHECK(swTraceMessage.m_Id == 3);
126 CHECK(swTraceMessage.m_Name == "declareRelationship");
127 CHECK(swTraceMessage.m_UiName == "declare relationship");
128 CHECK(swTraceMessage.m_ArgTypes.size() == 5);
129 CHECK(swTraceMessage.m_ArgTypes[0] == 'I');
130 CHECK(swTraceMessage.m_ArgTypes[1] == 'p');
131 CHECK(swTraceMessage.m_ArgTypes[2] == 'p');
132 CHECK(swTraceMessage.m_ArgTypes[3] == 'p');
133 CHECK(swTraceMessage.m_ArgTypes[4] == 'p');
134 CHECK(swTraceMessage.m_ArgNames.size() == 5);
135 CHECK(swTraceMessage.m_ArgNames[0] == "relationshipType");
136 CHECK(swTraceMessage.m_ArgNames[1] == "relationshipGuid");
137 CHECK(swTraceMessage.m_ArgNames[2] == "headGuid");
138 CHECK(swTraceMessage.m_ArgNames[3] == "tailGuid");
139 CHECK(swTraceMessage.m_ArgNames[4] == "attributeGuid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100140
Jim Flynnbbfe6032020-07-20 16:57:44 +0100141 swTraceMessage = arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
142 offset,
143 packetBuffer->GetSize());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100144
Sadik Armagan1625efc2021-06-10 18:24:34 +0100145 CHECK(swTraceMessage.m_Id == 4);
146 CHECK(swTraceMessage.m_Name == "declareEvent");
147 CHECK(swTraceMessage.m_UiName == "declare event");
148 CHECK(swTraceMessage.m_ArgTypes.size() == 3);
149 CHECK(swTraceMessage.m_ArgTypes[0] == '@');
150 CHECK(swTraceMessage.m_ArgTypes[1] == 't');
151 CHECK(swTraceMessage.m_ArgTypes[2] == 'p');
152 CHECK(swTraceMessage.m_ArgNames.size() == 3);
153 CHECK(swTraceMessage.m_ArgNames[0] == "timestamp");
154 CHECK(swTraceMessage.m_ArgNames[1] == "threadId");
155 CHECK(swTraceMessage.m_ArgNames[2] == "eventGuid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100156}
157
Sadik Armagan1625efc2021-06-10 18:24:34 +0100158TEST_CASE("SendTimelineEntityWithEventClassPacketTest")
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100159{
160 MockBufferManager bufferManager(40);
161 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
162 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
163
164 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
165 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
166
167 const uint64_t eventClassBinaryPacketProfilingGuid = 789123u;
Jim Flynn1892d212020-05-26 21:10:49 +0100168 const uint64_t eventClassBinaryPacketNameGuid = 8845u;
169 sendTimelinePacket->SendTimelineEventClassBinaryPacket(
170 eventClassBinaryPacketProfilingGuid, eventClassBinaryPacketNameGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100171
172 // Commit the messages
173 sendTimelinePacket->Commit();
174
175 // Get the readable buffer
176 auto packetBuffer = bufferManager.GetReadableBuffer();
177
178 unsigned int uint32_t_size = sizeof(uint32_t);
179 unsigned int uint64_t_size = sizeof(uint64_t);
180
181 // Check the packet header
182 unsigned int offset = 0;
183
184 // Reading TimelineEntityClassBinaryPacket
Keith Davis97da5e22020-03-05 16:25:28 +0000185 uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
186 uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
187 uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
188 uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007;
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100189 uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007;
190
Sadik Armagan1625efc2021-06-10 18:24:34 +0100191 CHECK(entityBinaryPacketFamily == 1);
192 CHECK(entityBinaryPacketClass == 0);
193 CHECK(entityBinaryPacketType == 1);
194 CHECK(entityBinaryPacketStreamId == 0);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100195
196 offset += uint32_t_size;
Keith Davis97da5e22020-03-05 16:25:28 +0000197
198 uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
199
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100200 uint32_t entityBinaryPacketSequenceNumbered = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001;
201 uint32_t entityBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
Keith Davis97da5e22020-03-05 16:25:28 +0000202
Sadik Armagan1625efc2021-06-10 18:24:34 +0100203 CHECK(entityBinaryPacketSequenceNumbered == 0);
204 CHECK(entityBinaryPacketDataLength == 32);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100205
206 // Check the decl_id
207 offset += uint32_t_size;
208 uint32_t entitytDecId = ReadUint32(packetBuffer, offset);
209
Sadik Armagan1625efc2021-06-10 18:24:34 +0100210 CHECK(entitytDecId == uint32_t(1));
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100211
212 // Check the profiling GUID
213 offset += uint32_t_size;
214 uint64_t readProfilingGuid = ReadUint64(packetBuffer, offset);
215
Sadik Armagan1625efc2021-06-10 18:24:34 +0100216 CHECK(readProfilingGuid == entityBinaryPacketProfilingGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100217
218 // Reading TimelineEventClassBinaryPacket
219 offset += uint64_t_size;
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100220
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100221 uint32_t eventClassDeclId = ReadUint32(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100222 CHECK(eventClassDeclId == uint32_t(2));
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100223
224 // Check the profiling GUID
225 offset += uint32_t_size;
226 readProfilingGuid = ReadUint64(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100227 CHECK(readProfilingGuid == eventClassBinaryPacketProfilingGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100228
Jim Flynn1892d212020-05-26 21:10:49 +0100229 offset += uint64_t_size;
230 uint64_t readEventClassNameGuid = ReadUint64(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100231 CHECK(readEventClassNameGuid == eventClassBinaryPacketNameGuid);
Jim Flynn1892d212020-05-26 21:10:49 +0100232
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100233 bufferManager.MarkRead(packetBuffer);
234}
235
Sadik Armagan1625efc2021-06-10 18:24:34 +0100236TEST_CASE("SendEventClassAfterTimelineEntityPacketTest")
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100237{
238 unsigned int uint32_t_size = sizeof(uint32_t);
239 unsigned int uint64_t_size = sizeof(uint64_t);
240
241 MockBufferManager bufferManager(512);
242 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
243 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
244
245 // Send TimelineEntityClassBinaryPacket
246 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
247 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
248
249 // Commit the buffer
250 sendTimelinePacket->Commit();
251
252 // Get the readable buffer
253 auto packetBuffer = bufferManager.GetReadableBuffer();
254
255 // Check the packet header
256 unsigned int offset = 0;
257
258 // Reading TimelineEntityClassBinaryPacket
259 uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
260 uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
261 uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
262 uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007;
263 uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007;
264
Sadik Armagan1625efc2021-06-10 18:24:34 +0100265 CHECK(entityBinaryPacketFamily == 1);
266 CHECK(entityBinaryPacketClass == 0);
267 CHECK(entityBinaryPacketType == 1);
268 CHECK(entityBinaryPacketStreamId == 0);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100269
270 offset += uint32_t_size;
271 uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
272 uint32_t entityBinaryPacketSequenceNumbered = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001;
273 uint32_t entityBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100274 CHECK(entityBinaryPacketSequenceNumbered == 0);
275 CHECK(entityBinaryPacketDataLength == 12);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100276
277 // Check the decl_id
278 offset += uint32_t_size;
279 uint32_t entitytDecId = ReadUint32(packetBuffer, offset);
280
Sadik Armagan1625efc2021-06-10 18:24:34 +0100281 CHECK(entitytDecId == uint32_t(1));
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100282
283 // Check the profiling GUID
284 offset += uint32_t_size;
285 uint64_t readProfilingGuid = ReadUint64(packetBuffer, offset);
286
Sadik Armagan1625efc2021-06-10 18:24:34 +0100287 CHECK(readProfilingGuid == entityBinaryPacketProfilingGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100288
289 bufferManager.MarkRead(packetBuffer);
290
291 // Send TimelineEventClassBinaryPacket
292 const uint64_t eventClassBinaryPacketProfilingGuid = 789123u;
Jim Flynn1892d212020-05-26 21:10:49 +0100293 const uint64_t eventClassBinaryPacketNameGuid = 8845u;
294 sendTimelinePacket->SendTimelineEventClassBinaryPacket(
295 eventClassBinaryPacketProfilingGuid, eventClassBinaryPacketNameGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100296
297 // Commit the buffer
298 sendTimelinePacket->Commit();
299
300 // Get the readable buffer
301 packetBuffer = bufferManager.GetReadableBuffer();
302
303 // Check the packet header
304 offset = 0;
305
306 // Reading TimelineEventClassBinaryPacket
307 uint32_t eventClassBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
308 uint32_t eventClassBinaryPacketFamily = (eventClassBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
309 uint32_t eventClassBinaryPacketClass = (eventClassBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
310 uint32_t eventClassBinaryPacketType = (eventClassBinaryPacketHeaderWord0 >> 16) & 0x00000007;
311 uint32_t eventClassBinaryPacketStreamId = (eventClassBinaryPacketHeaderWord0 >> 0) & 0x00000007;
312
Sadik Armagan1625efc2021-06-10 18:24:34 +0100313 CHECK(eventClassBinaryPacketFamily == 1);
314 CHECK(eventClassBinaryPacketClass == 0);
315 CHECK(eventClassBinaryPacketType == 1);
316 CHECK(eventClassBinaryPacketStreamId == 0);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100317
318 offset += uint32_t_size;
319 uint32_t eventClassBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
320 uint32_t eventClassBinaryPacketSequenceNumbered = (eventClassBinaryPacketHeaderWord1 >> 24) & 0x00000001;
321 uint32_t eventClassBinaryPacketDataLength = (eventClassBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100322 CHECK(eventClassBinaryPacketSequenceNumbered == 0);
323 CHECK(eventClassBinaryPacketDataLength == 20);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100324
325 offset += uint32_t_size;
326 uint32_t eventClassDeclId = ReadUint32(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100327 CHECK(eventClassDeclId == uint32_t(2));
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100328
329 // Check the profiling GUID
330 offset += uint32_t_size;
331 readProfilingGuid = ReadUint64(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100332 CHECK(readProfilingGuid == eventClassBinaryPacketProfilingGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100333
Jim Flynn1892d212020-05-26 21:10:49 +0100334 offset += uint64_t_size;
335 uint64_t readEventClassNameGuid = ReadUint64(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100336 CHECK(readEventClassNameGuid == eventClassBinaryPacketNameGuid);
Jim Flynn1892d212020-05-26 21:10:49 +0100337
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100338 bufferManager.MarkRead(packetBuffer);
339
340 // Send TimelineEventBinaryPacket
341 const uint64_t timestamp = 456789u;
Jim Flynn9c85b412022-03-16 00:27:43 +0000342 const int threadId = arm::pipe::GetCurrentThreadId();
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100343 const uint64_t eventProfilingGuid = 123456u;
344 sendTimelinePacket->SendTimelineEventBinaryPacket(timestamp, threadId, eventProfilingGuid);
345
346 // Commit the buffer
347 sendTimelinePacket->Commit();
348
349 // Get the readable buffer
350 packetBuffer = bufferManager.GetReadableBuffer();
351
352 // Check the packet header
353 offset = 0;
354
355 // Reading TimelineEventBinaryPacket
356 uint32_t eventBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
357 uint32_t eventBinaryPacketFamily = (eventBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
358 uint32_t eventBinaryPacketClass = (eventBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
359 uint32_t eventBinaryPacketType = (eventBinaryPacketHeaderWord0 >> 16) & 0x00000007;
360 uint32_t eventBinaryPacketStreamId = (eventBinaryPacketHeaderWord0 >> 0) & 0x00000007;
361
Sadik Armagan1625efc2021-06-10 18:24:34 +0100362 CHECK(eventBinaryPacketFamily == 1);
363 CHECK(eventBinaryPacketClass == 0);
364 CHECK(eventBinaryPacketType == 1);
365 CHECK(eventBinaryPacketStreamId == 0);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100366
367 offset += uint32_t_size;
368 uint32_t eventBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
369 uint32_t eventBinaryPacketSequenceNumbered = (eventBinaryPacketHeaderWord1 >> 24) & 0x00000001;
370 uint32_t eventBinaryPacketDataLength = (eventBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100371 CHECK(eventBinaryPacketSequenceNumbered == 0);
372 CHECK(eventBinaryPacketDataLength == 20 + ThreadIdSize);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100373
374 // Check the decl_id
375 offset += uint32_t_size;
376 uint32_t eventDeclId = ReadUint32(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100377 CHECK(eventDeclId == 4);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100378
379 // Check the timestamp
380 offset += uint32_t_size;
381 uint64_t eventTimestamp = ReadUint64(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100382 CHECK(eventTimestamp == timestamp);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100383
384 // Check the thread id
385 offset += uint64_t_size;
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100386 std::vector<uint8_t> readThreadId(ThreadIdSize, 0);
387 ReadBytes(packetBuffer, offset, ThreadIdSize, readThreadId.data());
Sadik Armagan1625efc2021-06-10 18:24:34 +0100388 CHECK(readThreadId == threadId);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100389
390 // Check the profiling GUID
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100391 offset += ThreadIdSize;
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100392 readProfilingGuid = ReadUint64(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100393 CHECK(readProfilingGuid == eventProfilingGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100394}
395
Sadik Armagan1625efc2021-06-10 18:24:34 +0100396TEST_CASE("SendTimelinePacketTests2")
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100397{
398 MockBufferManager bufferManager(40);
399 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
400 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
401
Sadik Armagan1625efc2021-06-10 18:24:34 +0100402 CHECK_THROWS_AS(sendTimelinePacket->SendTimelineMessageDirectoryPackage(),
Jim Flynnf9db3ef2022-03-08 21:23:44 +0000403 arm::pipe::ProfilingException);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100404}
405
Sadik Armagan1625efc2021-06-10 18:24:34 +0100406TEST_CASE("SendTimelinePacketTests3")
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100407{
408 MockBufferManager bufferManager(512);
409 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
410 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
411
412 // Send TimelineEntityClassBinaryPacket
413 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
414 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
415
416 // Commit the buffer
417 sendTimelinePacket->Commit();
418
419 // Get the readable buffer
420 auto packetBuffer = bufferManager.GetReadableBuffer();
421
422 // Send TimelineEventClassBinaryPacket
423 const uint64_t eventClassBinaryPacketProfilingGuid = 789123u;
Jim Flynn1892d212020-05-26 21:10:49 +0100424 const uint64_t eventClassBinaryPacketNameGuid = 8845u;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100425 CHECK_THROWS_AS(sendTimelinePacket->SendTimelineEventClassBinaryPacket(
Jim Flynn1892d212020-05-26 21:10:49 +0100426 eventClassBinaryPacketProfilingGuid, eventClassBinaryPacketNameGuid),
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000427 BufferExhaustion);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100428}
429
Sadik Armagan1625efc2021-06-10 18:24:34 +0100430TEST_CASE("GetGuidsFromProfilingService")
Jim Flynn00f3aaf2019-10-24 11:58:06 +0100431{
Jim Flynn6c9f17d2022-03-10 23:13:01 +0000432 LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Fatal);
433
Keith Davis33ed2212020-03-30 10:43:41 +0100434 armnn::IRuntime::CreationOptions options;
435 options.m_ProfilingOptions.m_EnableProfiling = true;
Kevin Mayd92a6e42021-02-04 10:27:41 +0000436 armnn::RuntimeImpl runtime(options);
Jim Flynn34430252022-03-04 15:03:58 +0000437 armnn::ArmNNProfilingServiceInitialiser initialiser;
Jim Flynn9c85b412022-03-16 00:27:43 +0000438 ProfilingService profilingService(arm::pipe::MAX_ARMNN_COUNTER,
439 initialiser,
440 arm::pipe::ARMNN_SOFTWARE_INFO,
441 arm::pipe::ARMNN_SOFTWARE_VERSION,
442 arm::pipe::ARMNN_HARDWARE_VERSION,
443 runtime);
Keith Davis33ed2212020-03-30 10:43:41 +0100444
Jim Flynn4c9ed1d2022-01-23 23:57:20 +0000445 profilingService.ResetExternalProfilingOptions(
446 ConvertExternalProfilingOptions(options.m_ProfilingOptions), true);
Sadik Armagan3184c902020-03-18 10:57:30 +0000447 ProfilingStaticGuid staticGuid = profilingService.GetStaticId("dummy");
Jim Flynnab845752019-10-25 13:17:30 +0100448 std::hash<std::string> hasher;
449 uint64_t hash = static_cast<uint64_t>(hasher("dummy"));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000450 ProfilingStaticGuid expectedStaticValue(hash | MIN_STATIC_GUID);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100451 CHECK(staticGuid == expectedStaticValue);
Sadik Armagan3184c902020-03-18 10:57:30 +0000452 ProfilingDynamicGuid dynamicGuid = profilingService.GetNextGuid();
Jim Flynnab845752019-10-25 13:17:30 +0100453 uint64_t dynamicGuidValue = static_cast<uint64_t>(dynamicGuid);
454 ++dynamicGuidValue;
455 ProfilingDynamicGuid expectedDynamicValue(dynamicGuidValue);
Sadik Armagan3184c902020-03-18 10:57:30 +0000456 dynamicGuid = profilingService.GetNextGuid();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100457 CHECK(dynamicGuid == expectedDynamicValue);
Jim Flynn00f3aaf2019-10-24 11:58:06 +0100458}
459
Sadik Armagan1625efc2021-06-10 18:24:34 +0100460TEST_CASE("GetTimelinePackerWriterFromProfilingService")
Jim Flynn8b200652019-10-24 18:07:44 +0100461{
Jim Flynn6c9f17d2022-03-10 23:13:01 +0000462 LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Fatal);
463
Jim Flynn4c9ed1d2022-01-23 23:57:20 +0000464 ProfilingOptions options;
Jim Flynn8b200652019-10-24 18:07:44 +0100465 options.m_EnableProfiling = true;
Jim Flynn34430252022-03-04 15:03:58 +0000466 armnn::ArmNNProfilingServiceInitialiser initialiser;
Jim Flynn9c85b412022-03-16 00:27:43 +0000467 ProfilingService profilingService(arm::pipe::MAX_ARMNN_COUNTER,
468 initialiser,
469 arm::pipe::ARMNN_SOFTWARE_INFO,
470 arm::pipe::ARMNN_SOFTWARE_VERSION,
471 arm::pipe::ARMNN_HARDWARE_VERSION);
Jim Flynn8b200652019-10-24 18:07:44 +0100472 profilingService.ResetExternalProfilingOptions(options, true);
473
474 std::unique_ptr<ISendTimelinePacket> writer = profilingService.GetSendTimelinePacket();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100475 CHECK(writer != nullptr);
Jim Flynn8b200652019-10-24 18:07:44 +0100476}
477
Sadik Armagan1625efc2021-06-10 18:24:34 +0100478TEST_CASE("CheckStaticGuidsAndEvents")
Jim Flynnab845752019-10-25 13:17:30 +0100479{
Sadik Armagan1625efc2021-06-10 18:24:34 +0100480 CHECK("name" == LabelsAndEventClasses::NAME_LABEL);
481 CHECK("type" == LabelsAndEventClasses::TYPE_LABEL);
482 CHECK("index" == LabelsAndEventClasses::INDEX_LABEL);
Jim Flynnab845752019-10-25 13:17:30 +0100483
484 std::hash<std::string> hasher;
485
486 uint64_t hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::NAME_LABEL));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000487 ProfilingStaticGuid expectedNameGuid(hash | MIN_STATIC_GUID);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100488 CHECK(LabelsAndEventClasses::NAME_GUID == expectedNameGuid);
Jim Flynnab845752019-10-25 13:17:30 +0100489
490 hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::TYPE_LABEL));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000491 ProfilingStaticGuid expectedTypeGuid(hash | MIN_STATIC_GUID);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100492 CHECK(LabelsAndEventClasses::TYPE_GUID == expectedTypeGuid);
Jim Flynnab845752019-10-25 13:17:30 +0100493
494 hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::INDEX_LABEL));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000495 ProfilingStaticGuid expectedIndexGuid(hash | MIN_STATIC_GUID);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100496 CHECK(LabelsAndEventClasses::INDEX_GUID == expectedIndexGuid);
Jim Flynnab845752019-10-25 13:17:30 +0100497
498 hash = static_cast<uint64_t>(hasher("ARMNN_PROFILING_SOL"));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000499 ProfilingStaticGuid expectedSol(hash | MIN_STATIC_GUID);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100500 CHECK(LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS == expectedSol);
Jim Flynnab845752019-10-25 13:17:30 +0100501
502 hash = static_cast<uint64_t>(hasher("ARMNN_PROFILING_EOL"));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000503 ProfilingStaticGuid expectedEol(hash | MIN_STATIC_GUID);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100504 CHECK(LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS == expectedEol);
Jim Flynnab845752019-10-25 13:17:30 +0100505}
506
Sadik Armagan1625efc2021-06-10 18:24:34 +0100507}