blob: ed2c862b544a2238040199a67cd37dd6d8182592 [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"
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{
32TEST_CASE("SendTimelineMessageDirectoryPackageTest")
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010033{
34 MockBufferManager mockBuffer(512);
35 TimelinePacketWriterFactory timelinePacketWriterFactory(mockBuffer);
36 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
37
38 sendTimelinePacket->SendTimelineMessageDirectoryPackage();
39
40 // Get the readable buffer
41 auto packetBuffer = mockBuffer.GetReadableBuffer();
42
Matteo Martincigh34a407d2019-11-06 15:30:54 +000043 unsigned int uint8_t_size = sizeof(uint8_t);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010044 unsigned int uint32_t_size = sizeof(uint32_t);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000045 unsigned int uint64_t_size = sizeof(uint64_t);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000046
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010047 // Check the packet header
48 unsigned int offset = 0;
49 uint32_t packetHeaderWord0 = ReadUint32(packetBuffer, offset);
50 uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F;
51 uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F;
52 uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007;
53 uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007;
54
Sadik Armagan1625efc2021-06-10 18:24:34 +010055 CHECK(packetFamily == 1);
56 CHECK(packetClass == 0);
57 CHECK(packetType == 0);
58 CHECK(streamId == 0);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010059
60 offset += uint32_t_size;
61 uint32_t packetHeaderWord1 = ReadUint32(packetBuffer, offset);
62 uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001;
63 uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF;
Sadik Armagan1625efc2021-06-10 18:24:34 +010064 CHECK(sequenceNumbered == 0);
65 CHECK(dataLength == 443);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010066
67 offset += uint32_t_size;
Matteo Martincigh34a407d2019-11-06 15:30:54 +000068 uint8_t readStreamVersion = ReadUint8(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +010069 CHECK(readStreamVersion == 4);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000070 offset += uint8_t_size;
71 uint8_t readPointerBytes = ReadUint8(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +010072 CHECK(readPointerBytes == uint64_t_size);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000073 offset += uint8_t_size;
74 uint8_t readThreadIdBytes = ReadUint8(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +010075 CHECK(readThreadIdBytes == ThreadIdSize);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000076
77 offset += uint8_t_size;
Finn Williamse63a0262019-10-22 10:30:49 +010078 uint32_t DeclCount = ReadUint32(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +010079 CHECK(DeclCount == 5);
Finn Williamse63a0262019-10-22 10:30:49 +010080
81 offset += uint32_t_size;
Jim Flynnbbfe6032020-07-20 16:57:44 +010082 arm::pipe::SwTraceMessage swTraceMessage = arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
83 offset,
84 packetBuffer->GetSize());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010085
Sadik Armagan1625efc2021-06-10 18:24:34 +010086 CHECK(swTraceMessage.m_Id == 0);
87 CHECK(swTraceMessage.m_Name == "declareLabel");
88 CHECK(swTraceMessage.m_UiName == "declare label");
89 CHECK(swTraceMessage.m_ArgTypes.size() == 2);
90 CHECK(swTraceMessage.m_ArgTypes[0] == 'p');
91 CHECK(swTraceMessage.m_ArgTypes[1] == 's');
92 CHECK(swTraceMessage.m_ArgNames.size() == 2);
93 CHECK(swTraceMessage.m_ArgNames[0] == "guid");
94 CHECK(swTraceMessage.m_ArgNames[1] == "value");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010095
Jim Flynnbbfe6032020-07-20 16:57:44 +010096 swTraceMessage = arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
97 offset,
98 packetBuffer->GetSize());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010099
Sadik Armagan1625efc2021-06-10 18:24:34 +0100100 CHECK(swTraceMessage.m_Id == 1);
101 CHECK(swTraceMessage.m_Name == "declareEntity");
102 CHECK(swTraceMessage.m_UiName == "declare entity");
103 CHECK(swTraceMessage.m_ArgTypes.size() == 1);
104 CHECK(swTraceMessage.m_ArgTypes[0] == 'p');
105 CHECK(swTraceMessage.m_ArgNames.size() == 1);
106 CHECK(swTraceMessage.m_ArgNames[0] == "guid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100107
Jim Flynnbbfe6032020-07-20 16:57:44 +0100108 swTraceMessage = arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
109 offset,
110 packetBuffer->GetSize());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100111
Sadik Armagan1625efc2021-06-10 18:24:34 +0100112 CHECK(swTraceMessage.m_Id == 2);
113 CHECK(swTraceMessage.m_Name == "declareEventClass");
114 CHECK(swTraceMessage.m_UiName == "declare event class");
115 CHECK(swTraceMessage.m_ArgTypes.size() == 2);
116 CHECK(swTraceMessage.m_ArgTypes[0] == 'p');
117 CHECK(swTraceMessage.m_ArgTypes[1] == 'p');
118 CHECK(swTraceMessage.m_ArgNames.size() == 2);
119 CHECK(swTraceMessage.m_ArgNames[0] == "guid");
120 CHECK(swTraceMessage.m_ArgNames[1] == "nameGuid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100121
Jim Flynnbbfe6032020-07-20 16:57:44 +0100122 swTraceMessage = arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
123 offset,
124 packetBuffer->GetSize());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100125
Sadik Armagan1625efc2021-06-10 18:24:34 +0100126 CHECK(swTraceMessage.m_Id == 3);
127 CHECK(swTraceMessage.m_Name == "declareRelationship");
128 CHECK(swTraceMessage.m_UiName == "declare relationship");
129 CHECK(swTraceMessage.m_ArgTypes.size() == 5);
130 CHECK(swTraceMessage.m_ArgTypes[0] == 'I');
131 CHECK(swTraceMessage.m_ArgTypes[1] == 'p');
132 CHECK(swTraceMessage.m_ArgTypes[2] == 'p');
133 CHECK(swTraceMessage.m_ArgTypes[3] == 'p');
134 CHECK(swTraceMessage.m_ArgTypes[4] == 'p');
135 CHECK(swTraceMessage.m_ArgNames.size() == 5);
136 CHECK(swTraceMessage.m_ArgNames[0] == "relationshipType");
137 CHECK(swTraceMessage.m_ArgNames[1] == "relationshipGuid");
138 CHECK(swTraceMessage.m_ArgNames[2] == "headGuid");
139 CHECK(swTraceMessage.m_ArgNames[3] == "tailGuid");
140 CHECK(swTraceMessage.m_ArgNames[4] == "attributeGuid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100141
Jim Flynnbbfe6032020-07-20 16:57:44 +0100142 swTraceMessage = arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
143 offset,
144 packetBuffer->GetSize());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100145
Sadik Armagan1625efc2021-06-10 18:24:34 +0100146 CHECK(swTraceMessage.m_Id == 4);
147 CHECK(swTraceMessage.m_Name == "declareEvent");
148 CHECK(swTraceMessage.m_UiName == "declare event");
149 CHECK(swTraceMessage.m_ArgTypes.size() == 3);
150 CHECK(swTraceMessage.m_ArgTypes[0] == '@');
151 CHECK(swTraceMessage.m_ArgTypes[1] == 't');
152 CHECK(swTraceMessage.m_ArgTypes[2] == 'p');
153 CHECK(swTraceMessage.m_ArgNames.size() == 3);
154 CHECK(swTraceMessage.m_ArgNames[0] == "timestamp");
155 CHECK(swTraceMessage.m_ArgNames[1] == "threadId");
156 CHECK(swTraceMessage.m_ArgNames[2] == "eventGuid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100157}
158
Sadik Armagan1625efc2021-06-10 18:24:34 +0100159TEST_CASE("SendTimelineEntityWithEventClassPacketTest")
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100160{
161 MockBufferManager bufferManager(40);
162 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
163 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
164
165 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
166 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
167
168 const uint64_t eventClassBinaryPacketProfilingGuid = 789123u;
Jim Flynn1892d212020-05-26 21:10:49 +0100169 const uint64_t eventClassBinaryPacketNameGuid = 8845u;
170 sendTimelinePacket->SendTimelineEventClassBinaryPacket(
171 eventClassBinaryPacketProfilingGuid, eventClassBinaryPacketNameGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100172
173 // Commit the messages
174 sendTimelinePacket->Commit();
175
176 // Get the readable buffer
177 auto packetBuffer = bufferManager.GetReadableBuffer();
178
179 unsigned int uint32_t_size = sizeof(uint32_t);
180 unsigned int uint64_t_size = sizeof(uint64_t);
181
182 // Check the packet header
183 unsigned int offset = 0;
184
185 // Reading TimelineEntityClassBinaryPacket
Keith Davis97da5e22020-03-05 16:25:28 +0000186 uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
187 uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
188 uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
189 uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007;
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100190 uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007;
191
Sadik Armagan1625efc2021-06-10 18:24:34 +0100192 CHECK(entityBinaryPacketFamily == 1);
193 CHECK(entityBinaryPacketClass == 0);
194 CHECK(entityBinaryPacketType == 1);
195 CHECK(entityBinaryPacketStreamId == 0);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100196
197 offset += uint32_t_size;
Keith Davis97da5e22020-03-05 16:25:28 +0000198
199 uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
200
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100201 uint32_t entityBinaryPacketSequenceNumbered = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001;
202 uint32_t entityBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
Keith Davis97da5e22020-03-05 16:25:28 +0000203
Sadik Armagan1625efc2021-06-10 18:24:34 +0100204 CHECK(entityBinaryPacketSequenceNumbered == 0);
205 CHECK(entityBinaryPacketDataLength == 32);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100206
207 // Check the decl_id
208 offset += uint32_t_size;
209 uint32_t entitytDecId = ReadUint32(packetBuffer, offset);
210
Sadik Armagan1625efc2021-06-10 18:24:34 +0100211 CHECK(entitytDecId == uint32_t(1));
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100212
213 // Check the profiling GUID
214 offset += uint32_t_size;
215 uint64_t readProfilingGuid = ReadUint64(packetBuffer, offset);
216
Sadik Armagan1625efc2021-06-10 18:24:34 +0100217 CHECK(readProfilingGuid == entityBinaryPacketProfilingGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100218
219 // Reading TimelineEventClassBinaryPacket
220 offset += uint64_t_size;
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100221
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100222 uint32_t eventClassDeclId = ReadUint32(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100223 CHECK(eventClassDeclId == uint32_t(2));
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100224
225 // Check the profiling GUID
226 offset += uint32_t_size;
227 readProfilingGuid = ReadUint64(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100228 CHECK(readProfilingGuid == eventClassBinaryPacketProfilingGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100229
Jim Flynn1892d212020-05-26 21:10:49 +0100230 offset += uint64_t_size;
231 uint64_t readEventClassNameGuid = ReadUint64(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100232 CHECK(readEventClassNameGuid == eventClassBinaryPacketNameGuid);
Jim Flynn1892d212020-05-26 21:10:49 +0100233
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100234 bufferManager.MarkRead(packetBuffer);
235}
236
Sadik Armagan1625efc2021-06-10 18:24:34 +0100237TEST_CASE("SendEventClassAfterTimelineEntityPacketTest")
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100238{
239 unsigned int uint32_t_size = sizeof(uint32_t);
240 unsigned int uint64_t_size = sizeof(uint64_t);
241
242 MockBufferManager bufferManager(512);
243 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
244 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
245
246 // Send TimelineEntityClassBinaryPacket
247 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
248 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
249
250 // Commit the buffer
251 sendTimelinePacket->Commit();
252
253 // Get the readable buffer
254 auto packetBuffer = bufferManager.GetReadableBuffer();
255
256 // Check the packet header
257 unsigned int offset = 0;
258
259 // Reading TimelineEntityClassBinaryPacket
260 uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
261 uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
262 uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
263 uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007;
264 uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007;
265
Sadik Armagan1625efc2021-06-10 18:24:34 +0100266 CHECK(entityBinaryPacketFamily == 1);
267 CHECK(entityBinaryPacketClass == 0);
268 CHECK(entityBinaryPacketType == 1);
269 CHECK(entityBinaryPacketStreamId == 0);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100270
271 offset += uint32_t_size;
272 uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
273 uint32_t entityBinaryPacketSequenceNumbered = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001;
274 uint32_t entityBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100275 CHECK(entityBinaryPacketSequenceNumbered == 0);
276 CHECK(entityBinaryPacketDataLength == 12);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100277
278 // Check the decl_id
279 offset += uint32_t_size;
280 uint32_t entitytDecId = ReadUint32(packetBuffer, offset);
281
Sadik Armagan1625efc2021-06-10 18:24:34 +0100282 CHECK(entitytDecId == uint32_t(1));
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100283
284 // Check the profiling GUID
285 offset += uint32_t_size;
286 uint64_t readProfilingGuid = ReadUint64(packetBuffer, offset);
287
Sadik Armagan1625efc2021-06-10 18:24:34 +0100288 CHECK(readProfilingGuid == entityBinaryPacketProfilingGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100289
290 bufferManager.MarkRead(packetBuffer);
291
292 // Send TimelineEventClassBinaryPacket
293 const uint64_t eventClassBinaryPacketProfilingGuid = 789123u;
Jim Flynn1892d212020-05-26 21:10:49 +0100294 const uint64_t eventClassBinaryPacketNameGuid = 8845u;
295 sendTimelinePacket->SendTimelineEventClassBinaryPacket(
296 eventClassBinaryPacketProfilingGuid, eventClassBinaryPacketNameGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100297
298 // Commit the buffer
299 sendTimelinePacket->Commit();
300
301 // Get the readable buffer
302 packetBuffer = bufferManager.GetReadableBuffer();
303
304 // Check the packet header
305 offset = 0;
306
307 // Reading TimelineEventClassBinaryPacket
308 uint32_t eventClassBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
309 uint32_t eventClassBinaryPacketFamily = (eventClassBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
310 uint32_t eventClassBinaryPacketClass = (eventClassBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
311 uint32_t eventClassBinaryPacketType = (eventClassBinaryPacketHeaderWord0 >> 16) & 0x00000007;
312 uint32_t eventClassBinaryPacketStreamId = (eventClassBinaryPacketHeaderWord0 >> 0) & 0x00000007;
313
Sadik Armagan1625efc2021-06-10 18:24:34 +0100314 CHECK(eventClassBinaryPacketFamily == 1);
315 CHECK(eventClassBinaryPacketClass == 0);
316 CHECK(eventClassBinaryPacketType == 1);
317 CHECK(eventClassBinaryPacketStreamId == 0);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100318
319 offset += uint32_t_size;
320 uint32_t eventClassBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
321 uint32_t eventClassBinaryPacketSequenceNumbered = (eventClassBinaryPacketHeaderWord1 >> 24) & 0x00000001;
322 uint32_t eventClassBinaryPacketDataLength = (eventClassBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100323 CHECK(eventClassBinaryPacketSequenceNumbered == 0);
324 CHECK(eventClassBinaryPacketDataLength == 20);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100325
326 offset += uint32_t_size;
327 uint32_t eventClassDeclId = ReadUint32(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100328 CHECK(eventClassDeclId == uint32_t(2));
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100329
330 // Check the profiling GUID
331 offset += uint32_t_size;
332 readProfilingGuid = ReadUint64(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100333 CHECK(readProfilingGuid == eventClassBinaryPacketProfilingGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100334
Jim Flynn1892d212020-05-26 21:10:49 +0100335 offset += uint64_t_size;
336 uint64_t readEventClassNameGuid = ReadUint64(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100337 CHECK(readEventClassNameGuid == eventClassBinaryPacketNameGuid);
Jim Flynn1892d212020-05-26 21:10:49 +0100338
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100339 bufferManager.MarkRead(packetBuffer);
340
341 // Send TimelineEventBinaryPacket
342 const uint64_t timestamp = 456789u;
Jim Flynn9c85b412022-03-16 00:27:43 +0000343 const int threadId = arm::pipe::GetCurrentThreadId();
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100344 const uint64_t eventProfilingGuid = 123456u;
345 sendTimelinePacket->SendTimelineEventBinaryPacket(timestamp, threadId, eventProfilingGuid);
346
347 // Commit the buffer
348 sendTimelinePacket->Commit();
349
350 // Get the readable buffer
351 packetBuffer = bufferManager.GetReadableBuffer();
352
353 // Check the packet header
354 offset = 0;
355
356 // Reading TimelineEventBinaryPacket
357 uint32_t eventBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
358 uint32_t eventBinaryPacketFamily = (eventBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
359 uint32_t eventBinaryPacketClass = (eventBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
360 uint32_t eventBinaryPacketType = (eventBinaryPacketHeaderWord0 >> 16) & 0x00000007;
361 uint32_t eventBinaryPacketStreamId = (eventBinaryPacketHeaderWord0 >> 0) & 0x00000007;
362
Sadik Armagan1625efc2021-06-10 18:24:34 +0100363 CHECK(eventBinaryPacketFamily == 1);
364 CHECK(eventBinaryPacketClass == 0);
365 CHECK(eventBinaryPacketType == 1);
366 CHECK(eventBinaryPacketStreamId == 0);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100367
368 offset += uint32_t_size;
369 uint32_t eventBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
370 uint32_t eventBinaryPacketSequenceNumbered = (eventBinaryPacketHeaderWord1 >> 24) & 0x00000001;
371 uint32_t eventBinaryPacketDataLength = (eventBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100372 CHECK(eventBinaryPacketSequenceNumbered == 0);
373 CHECK(eventBinaryPacketDataLength == 20 + ThreadIdSize);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100374
375 // Check the decl_id
376 offset += uint32_t_size;
377 uint32_t eventDeclId = ReadUint32(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100378 CHECK(eventDeclId == 4);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100379
380 // Check the timestamp
381 offset += uint32_t_size;
382 uint64_t eventTimestamp = ReadUint64(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100383 CHECK(eventTimestamp == timestamp);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100384
385 // Check the thread id
386 offset += uint64_t_size;
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100387 std::vector<uint8_t> readThreadId(ThreadIdSize, 0);
388 ReadBytes(packetBuffer, offset, ThreadIdSize, readThreadId.data());
Sadik Armagan1625efc2021-06-10 18:24:34 +0100389 CHECK(readThreadId == threadId);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100390
391 // Check the profiling GUID
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100392 offset += ThreadIdSize;
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100393 readProfilingGuid = ReadUint64(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100394 CHECK(readProfilingGuid == eventProfilingGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100395}
396
Sadik Armagan1625efc2021-06-10 18:24:34 +0100397TEST_CASE("SendTimelinePacketTests2")
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100398{
399 MockBufferManager bufferManager(40);
400 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
401 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
402
Sadik Armagan1625efc2021-06-10 18:24:34 +0100403 CHECK_THROWS_AS(sendTimelinePacket->SendTimelineMessageDirectoryPackage(),
Jim Flynnf9db3ef2022-03-08 21:23:44 +0000404 arm::pipe::ProfilingException);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100405}
406
Sadik Armagan1625efc2021-06-10 18:24:34 +0100407TEST_CASE("SendTimelinePacketTests3")
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100408{
409 MockBufferManager bufferManager(512);
410 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
411 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
412
413 // Send TimelineEntityClassBinaryPacket
414 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
415 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
416
417 // Commit the buffer
418 sendTimelinePacket->Commit();
419
420 // Get the readable buffer
421 auto packetBuffer = bufferManager.GetReadableBuffer();
422
423 // Send TimelineEventClassBinaryPacket
424 const uint64_t eventClassBinaryPacketProfilingGuid = 789123u;
Jim Flynn1892d212020-05-26 21:10:49 +0100425 const uint64_t eventClassBinaryPacketNameGuid = 8845u;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100426 CHECK_THROWS_AS(sendTimelinePacket->SendTimelineEventClassBinaryPacket(
Jim Flynn1892d212020-05-26 21:10:49 +0100427 eventClassBinaryPacketProfilingGuid, eventClassBinaryPacketNameGuid),
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000428 BufferExhaustion);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100429}
430
Sadik Armagan1625efc2021-06-10 18:24:34 +0100431TEST_CASE("GetGuidsFromProfilingService")
Jim Flynn00f3aaf2019-10-24 11:58:06 +0100432{
Jim Flynn6c9f17d2022-03-10 23:13:01 +0000433 LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Fatal);
434
Keith Davis33ed2212020-03-30 10:43:41 +0100435 armnn::IRuntime::CreationOptions options;
436 options.m_ProfilingOptions.m_EnableProfiling = true;
Kevin Mayd92a6e42021-02-04 10:27:41 +0000437 armnn::RuntimeImpl runtime(options);
Jim Flynn34430252022-03-04 15:03:58 +0000438 armnn::ArmNNProfilingServiceInitialiser initialiser;
Jim Flynn9c85b412022-03-16 00:27:43 +0000439 ProfilingService profilingService(arm::pipe::MAX_ARMNN_COUNTER,
440 initialiser,
441 arm::pipe::ARMNN_SOFTWARE_INFO,
442 arm::pipe::ARMNN_SOFTWARE_VERSION,
443 arm::pipe::ARMNN_HARDWARE_VERSION,
444 runtime);
Keith Davis33ed2212020-03-30 10:43:41 +0100445
Jim Flynn4c9ed1d2022-01-23 23:57:20 +0000446 profilingService.ResetExternalProfilingOptions(
447 ConvertExternalProfilingOptions(options.m_ProfilingOptions), true);
Sadik Armagan3184c902020-03-18 10:57:30 +0000448 ProfilingStaticGuid staticGuid = profilingService.GetStaticId("dummy");
Jim Flynnab845752019-10-25 13:17:30 +0100449 std::hash<std::string> hasher;
450 uint64_t hash = static_cast<uint64_t>(hasher("dummy"));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000451 ProfilingStaticGuid expectedStaticValue(hash | MIN_STATIC_GUID);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100452 CHECK(staticGuid == expectedStaticValue);
Sadik Armagan3184c902020-03-18 10:57:30 +0000453 ProfilingDynamicGuid dynamicGuid = profilingService.GetNextGuid();
Jim Flynnab845752019-10-25 13:17:30 +0100454 uint64_t dynamicGuidValue = static_cast<uint64_t>(dynamicGuid);
455 ++dynamicGuidValue;
456 ProfilingDynamicGuid expectedDynamicValue(dynamicGuidValue);
Sadik Armagan3184c902020-03-18 10:57:30 +0000457 dynamicGuid = profilingService.GetNextGuid();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100458 CHECK(dynamicGuid == expectedDynamicValue);
Jim Flynn00f3aaf2019-10-24 11:58:06 +0100459}
460
Sadik Armagan1625efc2021-06-10 18:24:34 +0100461TEST_CASE("GetTimelinePackerWriterFromProfilingService")
Jim Flynn8b200652019-10-24 18:07:44 +0100462{
Jim Flynn6c9f17d2022-03-10 23:13:01 +0000463 LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Fatal);
464
Jim Flynn4c9ed1d2022-01-23 23:57:20 +0000465 ProfilingOptions options;
Jim Flynn8b200652019-10-24 18:07:44 +0100466 options.m_EnableProfiling = true;
Jim Flynn34430252022-03-04 15:03:58 +0000467 armnn::ArmNNProfilingServiceInitialiser initialiser;
Jim Flynn9c85b412022-03-16 00:27:43 +0000468 ProfilingService profilingService(arm::pipe::MAX_ARMNN_COUNTER,
469 initialiser,
470 arm::pipe::ARMNN_SOFTWARE_INFO,
471 arm::pipe::ARMNN_SOFTWARE_VERSION,
472 arm::pipe::ARMNN_HARDWARE_VERSION);
Jim Flynn8b200652019-10-24 18:07:44 +0100473 profilingService.ResetExternalProfilingOptions(options, true);
474
475 std::unique_ptr<ISendTimelinePacket> writer = profilingService.GetSendTimelinePacket();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100476 CHECK(writer != nullptr);
Jim Flynn8b200652019-10-24 18:07:44 +0100477}
478
Sadik Armagan1625efc2021-06-10 18:24:34 +0100479TEST_CASE("CheckStaticGuidsAndEvents")
Jim Flynnab845752019-10-25 13:17:30 +0100480{
Sadik Armagan1625efc2021-06-10 18:24:34 +0100481 CHECK("name" == LabelsAndEventClasses::NAME_LABEL);
482 CHECK("type" == LabelsAndEventClasses::TYPE_LABEL);
483 CHECK("index" == LabelsAndEventClasses::INDEX_LABEL);
Jim Flynnab845752019-10-25 13:17:30 +0100484
485 std::hash<std::string> hasher;
486
487 uint64_t hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::NAME_LABEL));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000488 ProfilingStaticGuid expectedNameGuid(hash | MIN_STATIC_GUID);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100489 CHECK(LabelsAndEventClasses::NAME_GUID == expectedNameGuid);
Jim Flynnab845752019-10-25 13:17:30 +0100490
491 hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::TYPE_LABEL));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000492 ProfilingStaticGuid expectedTypeGuid(hash | MIN_STATIC_GUID);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100493 CHECK(LabelsAndEventClasses::TYPE_GUID == expectedTypeGuid);
Jim Flynnab845752019-10-25 13:17:30 +0100494
495 hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::INDEX_LABEL));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000496 ProfilingStaticGuid expectedIndexGuid(hash | MIN_STATIC_GUID);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100497 CHECK(LabelsAndEventClasses::INDEX_GUID == expectedIndexGuid);
Jim Flynnab845752019-10-25 13:17:30 +0100498
499 hash = static_cast<uint64_t>(hasher("ARMNN_PROFILING_SOL"));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000500 ProfilingStaticGuid expectedSol(hash | MIN_STATIC_GUID);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100501 CHECK(LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS == expectedSol);
Jim Flynnab845752019-10-25 13:17:30 +0100502
503 hash = static_cast<uint64_t>(hasher("ARMNN_PROFILING_EOL"));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000504 ProfilingStaticGuid expectedEol(hash | MIN_STATIC_GUID);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100505 CHECK(LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS == expectedEol);
Jim Flynnab845752019-10-25 13:17:30 +0100506}
507
Sadik Armagan1625efc2021-06-10 18:24:34 +0100508}