blob: 4e32149e44a35c9799cbe342aff556b99d97551c [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
8#include <BufferManager.hpp>
Jim Flynn00f3aaf2019-10-24 11:58:06 +01009#include <ProfilingService.hpp>
Jim Flynn4c9ed1d2022-01-23 23:57:20 +000010#include "ProfilingOptionsConverter.hpp"
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010011#include <ProfilingUtils.hpp>
12#include <SendTimelinePacket.hpp>
Rob Hughes9542f902021-07-14 09:48:54 +010013#include <armnnUtils/Threads.hpp>
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010014#include <TimelinePacketWriterFactory.hpp>
15
Jim Flynnbbfe6032020-07-20 16:57:44 +010016#include <common/include/SwTrace.hpp>
Nikhil Raj77fe76b2021-06-09 14:55:32 +010017#include <common/include/LabelsAndEventClasses.hpp>
Jim Flynnbbfe6032020-07-20 16:57:44 +010018
Sadik Armagan1625efc2021-06-10 18:24:34 +010019#include <doctest/doctest.h>
Jim Flynnab845752019-10-25 13:17:30 +010020
21#include <functional>
Keith Davis33ed2212020-03-30 10:43:41 +010022#include <Runtime.hpp>
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010023
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000024using namespace arm::pipe;
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010025
Sadik Armagan1625efc2021-06-10 18:24:34 +010026TEST_SUITE("SendTimelinePacketTests")
27{
28TEST_CASE("SendTimelineMessageDirectoryPackageTest")
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010029{
30 MockBufferManager mockBuffer(512);
31 TimelinePacketWriterFactory timelinePacketWriterFactory(mockBuffer);
32 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
33
34 sendTimelinePacket->SendTimelineMessageDirectoryPackage();
35
36 // Get the readable buffer
37 auto packetBuffer = mockBuffer.GetReadableBuffer();
38
Matteo Martincigh34a407d2019-11-06 15:30:54 +000039 unsigned int uint8_t_size = sizeof(uint8_t);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010040 unsigned int uint32_t_size = sizeof(uint32_t);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000041 unsigned int uint64_t_size = sizeof(uint64_t);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000042
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010043 // Check the packet header
44 unsigned int offset = 0;
45 uint32_t packetHeaderWord0 = ReadUint32(packetBuffer, offset);
46 uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F;
47 uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F;
48 uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007;
49 uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007;
50
Sadik Armagan1625efc2021-06-10 18:24:34 +010051 CHECK(packetFamily == 1);
52 CHECK(packetClass == 0);
53 CHECK(packetType == 0);
54 CHECK(streamId == 0);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010055
56 offset += uint32_t_size;
57 uint32_t packetHeaderWord1 = ReadUint32(packetBuffer, offset);
58 uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001;
59 uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF;
Sadik Armagan1625efc2021-06-10 18:24:34 +010060 CHECK(sequenceNumbered == 0);
61 CHECK(dataLength == 443);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010062
63 offset += uint32_t_size;
Matteo Martincigh34a407d2019-11-06 15:30:54 +000064 uint8_t readStreamVersion = ReadUint8(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +010065 CHECK(readStreamVersion == 4);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000066 offset += uint8_t_size;
67 uint8_t readPointerBytes = ReadUint8(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +010068 CHECK(readPointerBytes == uint64_t_size);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000069 offset += uint8_t_size;
70 uint8_t readThreadIdBytes = ReadUint8(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +010071 CHECK(readThreadIdBytes == ThreadIdSize);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000072
73 offset += uint8_t_size;
Finn Williamse63a0262019-10-22 10:30:49 +010074 uint32_t DeclCount = ReadUint32(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +010075 CHECK(DeclCount == 5);
Finn Williamse63a0262019-10-22 10:30:49 +010076
77 offset += uint32_t_size;
Jim Flynnbbfe6032020-07-20 16:57:44 +010078 arm::pipe::SwTraceMessage swTraceMessage = arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
79 offset,
80 packetBuffer->GetSize());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010081
Sadik Armagan1625efc2021-06-10 18:24:34 +010082 CHECK(swTraceMessage.m_Id == 0);
83 CHECK(swTraceMessage.m_Name == "declareLabel");
84 CHECK(swTraceMessage.m_UiName == "declare label");
85 CHECK(swTraceMessage.m_ArgTypes.size() == 2);
86 CHECK(swTraceMessage.m_ArgTypes[0] == 'p');
87 CHECK(swTraceMessage.m_ArgTypes[1] == 's');
88 CHECK(swTraceMessage.m_ArgNames.size() == 2);
89 CHECK(swTraceMessage.m_ArgNames[0] == "guid");
90 CHECK(swTraceMessage.m_ArgNames[1] == "value");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010091
Jim Flynnbbfe6032020-07-20 16:57:44 +010092 swTraceMessage = arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
93 offset,
94 packetBuffer->GetSize());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010095
Sadik Armagan1625efc2021-06-10 18:24:34 +010096 CHECK(swTraceMessage.m_Id == 1);
97 CHECK(swTraceMessage.m_Name == "declareEntity");
98 CHECK(swTraceMessage.m_UiName == "declare entity");
99 CHECK(swTraceMessage.m_ArgTypes.size() == 1);
100 CHECK(swTraceMessage.m_ArgTypes[0] == 'p');
101 CHECK(swTraceMessage.m_ArgNames.size() == 1);
102 CHECK(swTraceMessage.m_ArgNames[0] == "guid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100103
Jim Flynnbbfe6032020-07-20 16:57:44 +0100104 swTraceMessage = arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
105 offset,
106 packetBuffer->GetSize());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100107
Sadik Armagan1625efc2021-06-10 18:24:34 +0100108 CHECK(swTraceMessage.m_Id == 2);
109 CHECK(swTraceMessage.m_Name == "declareEventClass");
110 CHECK(swTraceMessage.m_UiName == "declare event class");
111 CHECK(swTraceMessage.m_ArgTypes.size() == 2);
112 CHECK(swTraceMessage.m_ArgTypes[0] == 'p');
113 CHECK(swTraceMessage.m_ArgTypes[1] == 'p');
114 CHECK(swTraceMessage.m_ArgNames.size() == 2);
115 CHECK(swTraceMessage.m_ArgNames[0] == "guid");
116 CHECK(swTraceMessage.m_ArgNames[1] == "nameGuid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100117
Jim Flynnbbfe6032020-07-20 16:57:44 +0100118 swTraceMessage = arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
119 offset,
120 packetBuffer->GetSize());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100121
Sadik Armagan1625efc2021-06-10 18:24:34 +0100122 CHECK(swTraceMessage.m_Id == 3);
123 CHECK(swTraceMessage.m_Name == "declareRelationship");
124 CHECK(swTraceMessage.m_UiName == "declare relationship");
125 CHECK(swTraceMessage.m_ArgTypes.size() == 5);
126 CHECK(swTraceMessage.m_ArgTypes[0] == 'I');
127 CHECK(swTraceMessage.m_ArgTypes[1] == 'p');
128 CHECK(swTraceMessage.m_ArgTypes[2] == 'p');
129 CHECK(swTraceMessage.m_ArgTypes[3] == 'p');
130 CHECK(swTraceMessage.m_ArgTypes[4] == 'p');
131 CHECK(swTraceMessage.m_ArgNames.size() == 5);
132 CHECK(swTraceMessage.m_ArgNames[0] == "relationshipType");
133 CHECK(swTraceMessage.m_ArgNames[1] == "relationshipGuid");
134 CHECK(swTraceMessage.m_ArgNames[2] == "headGuid");
135 CHECK(swTraceMessage.m_ArgNames[3] == "tailGuid");
136 CHECK(swTraceMessage.m_ArgNames[4] == "attributeGuid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100137
Jim Flynnbbfe6032020-07-20 16:57:44 +0100138 swTraceMessage = arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
139 offset,
140 packetBuffer->GetSize());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100141
Sadik Armagan1625efc2021-06-10 18:24:34 +0100142 CHECK(swTraceMessage.m_Id == 4);
143 CHECK(swTraceMessage.m_Name == "declareEvent");
144 CHECK(swTraceMessage.m_UiName == "declare event");
145 CHECK(swTraceMessage.m_ArgTypes.size() == 3);
146 CHECK(swTraceMessage.m_ArgTypes[0] == '@');
147 CHECK(swTraceMessage.m_ArgTypes[1] == 't');
148 CHECK(swTraceMessage.m_ArgTypes[2] == 'p');
149 CHECK(swTraceMessage.m_ArgNames.size() == 3);
150 CHECK(swTraceMessage.m_ArgNames[0] == "timestamp");
151 CHECK(swTraceMessage.m_ArgNames[1] == "threadId");
152 CHECK(swTraceMessage.m_ArgNames[2] == "eventGuid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100153}
154
Sadik Armagan1625efc2021-06-10 18:24:34 +0100155TEST_CASE("SendTimelineEntityWithEventClassPacketTest")
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100156{
157 MockBufferManager bufferManager(40);
158 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
159 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
160
161 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
162 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
163
164 const uint64_t eventClassBinaryPacketProfilingGuid = 789123u;
Jim Flynn1892d212020-05-26 21:10:49 +0100165 const uint64_t eventClassBinaryPacketNameGuid = 8845u;
166 sendTimelinePacket->SendTimelineEventClassBinaryPacket(
167 eventClassBinaryPacketProfilingGuid, eventClassBinaryPacketNameGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100168
169 // Commit the messages
170 sendTimelinePacket->Commit();
171
172 // Get the readable buffer
173 auto packetBuffer = bufferManager.GetReadableBuffer();
174
175 unsigned int uint32_t_size = sizeof(uint32_t);
176 unsigned int uint64_t_size = sizeof(uint64_t);
177
178 // Check the packet header
179 unsigned int offset = 0;
180
181 // Reading TimelineEntityClassBinaryPacket
Keith Davis97da5e22020-03-05 16:25:28 +0000182 uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
183 uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
184 uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
185 uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007;
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100186 uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007;
187
Sadik Armagan1625efc2021-06-10 18:24:34 +0100188 CHECK(entityBinaryPacketFamily == 1);
189 CHECK(entityBinaryPacketClass == 0);
190 CHECK(entityBinaryPacketType == 1);
191 CHECK(entityBinaryPacketStreamId == 0);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100192
193 offset += uint32_t_size;
Keith Davis97da5e22020-03-05 16:25:28 +0000194
195 uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
196
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100197 uint32_t entityBinaryPacketSequenceNumbered = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001;
198 uint32_t entityBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
Keith Davis97da5e22020-03-05 16:25:28 +0000199
Sadik Armagan1625efc2021-06-10 18:24:34 +0100200 CHECK(entityBinaryPacketSequenceNumbered == 0);
201 CHECK(entityBinaryPacketDataLength == 32);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100202
203 // Check the decl_id
204 offset += uint32_t_size;
205 uint32_t entitytDecId = ReadUint32(packetBuffer, offset);
206
Sadik Armagan1625efc2021-06-10 18:24:34 +0100207 CHECK(entitytDecId == uint32_t(1));
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100208
209 // Check the profiling GUID
210 offset += uint32_t_size;
211 uint64_t readProfilingGuid = ReadUint64(packetBuffer, offset);
212
Sadik Armagan1625efc2021-06-10 18:24:34 +0100213 CHECK(readProfilingGuid == entityBinaryPacketProfilingGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100214
215 // Reading TimelineEventClassBinaryPacket
216 offset += uint64_t_size;
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100217
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100218 uint32_t eventClassDeclId = ReadUint32(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100219 CHECK(eventClassDeclId == uint32_t(2));
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100220
221 // Check the profiling GUID
222 offset += uint32_t_size;
223 readProfilingGuid = ReadUint64(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100224 CHECK(readProfilingGuid == eventClassBinaryPacketProfilingGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100225
Jim Flynn1892d212020-05-26 21:10:49 +0100226 offset += uint64_t_size;
227 uint64_t readEventClassNameGuid = ReadUint64(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100228 CHECK(readEventClassNameGuid == eventClassBinaryPacketNameGuid);
Jim Flynn1892d212020-05-26 21:10:49 +0100229
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100230 bufferManager.MarkRead(packetBuffer);
231}
232
Sadik Armagan1625efc2021-06-10 18:24:34 +0100233TEST_CASE("SendEventClassAfterTimelineEntityPacketTest")
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100234{
235 unsigned int uint32_t_size = sizeof(uint32_t);
236 unsigned int uint64_t_size = sizeof(uint64_t);
237
238 MockBufferManager bufferManager(512);
239 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
240 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
241
242 // Send TimelineEntityClassBinaryPacket
243 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
244 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
245
246 // Commit the buffer
247 sendTimelinePacket->Commit();
248
249 // Get the readable buffer
250 auto packetBuffer = bufferManager.GetReadableBuffer();
251
252 // Check the packet header
253 unsigned int offset = 0;
254
255 // Reading TimelineEntityClassBinaryPacket
256 uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
257 uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
258 uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
259 uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007;
260 uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007;
261
Sadik Armagan1625efc2021-06-10 18:24:34 +0100262 CHECK(entityBinaryPacketFamily == 1);
263 CHECK(entityBinaryPacketClass == 0);
264 CHECK(entityBinaryPacketType == 1);
265 CHECK(entityBinaryPacketStreamId == 0);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100266
267 offset += uint32_t_size;
268 uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
269 uint32_t entityBinaryPacketSequenceNumbered = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001;
270 uint32_t entityBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100271 CHECK(entityBinaryPacketSequenceNumbered == 0);
272 CHECK(entityBinaryPacketDataLength == 12);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100273
274 // Check the decl_id
275 offset += uint32_t_size;
276 uint32_t entitytDecId = ReadUint32(packetBuffer, offset);
277
Sadik Armagan1625efc2021-06-10 18:24:34 +0100278 CHECK(entitytDecId == uint32_t(1));
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100279
280 // Check the profiling GUID
281 offset += uint32_t_size;
282 uint64_t readProfilingGuid = ReadUint64(packetBuffer, offset);
283
Sadik Armagan1625efc2021-06-10 18:24:34 +0100284 CHECK(readProfilingGuid == entityBinaryPacketProfilingGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100285
286 bufferManager.MarkRead(packetBuffer);
287
288 // Send TimelineEventClassBinaryPacket
289 const uint64_t eventClassBinaryPacketProfilingGuid = 789123u;
Jim Flynn1892d212020-05-26 21:10:49 +0100290 const uint64_t eventClassBinaryPacketNameGuid = 8845u;
291 sendTimelinePacket->SendTimelineEventClassBinaryPacket(
292 eventClassBinaryPacketProfilingGuid, eventClassBinaryPacketNameGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100293
294 // Commit the buffer
295 sendTimelinePacket->Commit();
296
297 // Get the readable buffer
298 packetBuffer = bufferManager.GetReadableBuffer();
299
300 // Check the packet header
301 offset = 0;
302
303 // Reading TimelineEventClassBinaryPacket
304 uint32_t eventClassBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
305 uint32_t eventClassBinaryPacketFamily = (eventClassBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
306 uint32_t eventClassBinaryPacketClass = (eventClassBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
307 uint32_t eventClassBinaryPacketType = (eventClassBinaryPacketHeaderWord0 >> 16) & 0x00000007;
308 uint32_t eventClassBinaryPacketStreamId = (eventClassBinaryPacketHeaderWord0 >> 0) & 0x00000007;
309
Sadik Armagan1625efc2021-06-10 18:24:34 +0100310 CHECK(eventClassBinaryPacketFamily == 1);
311 CHECK(eventClassBinaryPacketClass == 0);
312 CHECK(eventClassBinaryPacketType == 1);
313 CHECK(eventClassBinaryPacketStreamId == 0);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100314
315 offset += uint32_t_size;
316 uint32_t eventClassBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
317 uint32_t eventClassBinaryPacketSequenceNumbered = (eventClassBinaryPacketHeaderWord1 >> 24) & 0x00000001;
318 uint32_t eventClassBinaryPacketDataLength = (eventClassBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100319 CHECK(eventClassBinaryPacketSequenceNumbered == 0);
320 CHECK(eventClassBinaryPacketDataLength == 20);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100321
322 offset += uint32_t_size;
323 uint32_t eventClassDeclId = ReadUint32(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100324 CHECK(eventClassDeclId == uint32_t(2));
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100325
326 // Check the profiling GUID
327 offset += uint32_t_size;
328 readProfilingGuid = ReadUint64(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100329 CHECK(readProfilingGuid == eventClassBinaryPacketProfilingGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100330
Jim Flynn1892d212020-05-26 21:10:49 +0100331 offset += uint64_t_size;
332 uint64_t readEventClassNameGuid = ReadUint64(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100333 CHECK(readEventClassNameGuid == eventClassBinaryPacketNameGuid);
Jim Flynn1892d212020-05-26 21:10:49 +0100334
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100335 bufferManager.MarkRead(packetBuffer);
336
337 // Send TimelineEventBinaryPacket
338 const uint64_t timestamp = 456789u;
Jim Flynn1fdeb992020-07-09 07:28:37 +0100339 const int threadId = armnnUtils::Threads::GetCurrentThreadId();
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100340 const uint64_t eventProfilingGuid = 123456u;
341 sendTimelinePacket->SendTimelineEventBinaryPacket(timestamp, threadId, eventProfilingGuid);
342
343 // Commit the buffer
344 sendTimelinePacket->Commit();
345
346 // Get the readable buffer
347 packetBuffer = bufferManager.GetReadableBuffer();
348
349 // Check the packet header
350 offset = 0;
351
352 // Reading TimelineEventBinaryPacket
353 uint32_t eventBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
354 uint32_t eventBinaryPacketFamily = (eventBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
355 uint32_t eventBinaryPacketClass = (eventBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
356 uint32_t eventBinaryPacketType = (eventBinaryPacketHeaderWord0 >> 16) & 0x00000007;
357 uint32_t eventBinaryPacketStreamId = (eventBinaryPacketHeaderWord0 >> 0) & 0x00000007;
358
Sadik Armagan1625efc2021-06-10 18:24:34 +0100359 CHECK(eventBinaryPacketFamily == 1);
360 CHECK(eventBinaryPacketClass == 0);
361 CHECK(eventBinaryPacketType == 1);
362 CHECK(eventBinaryPacketStreamId == 0);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100363
364 offset += uint32_t_size;
365 uint32_t eventBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
366 uint32_t eventBinaryPacketSequenceNumbered = (eventBinaryPacketHeaderWord1 >> 24) & 0x00000001;
367 uint32_t eventBinaryPacketDataLength = (eventBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100368 CHECK(eventBinaryPacketSequenceNumbered == 0);
369 CHECK(eventBinaryPacketDataLength == 20 + ThreadIdSize);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100370
371 // Check the decl_id
372 offset += uint32_t_size;
373 uint32_t eventDeclId = ReadUint32(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100374 CHECK(eventDeclId == 4);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100375
376 // Check the timestamp
377 offset += uint32_t_size;
378 uint64_t eventTimestamp = ReadUint64(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100379 CHECK(eventTimestamp == timestamp);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100380
381 // Check the thread id
382 offset += uint64_t_size;
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100383 std::vector<uint8_t> readThreadId(ThreadIdSize, 0);
384 ReadBytes(packetBuffer, offset, ThreadIdSize, readThreadId.data());
Sadik Armagan1625efc2021-06-10 18:24:34 +0100385 CHECK(readThreadId == threadId);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100386
387 // Check the profiling GUID
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100388 offset += ThreadIdSize;
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100389 readProfilingGuid = ReadUint64(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100390 CHECK(readProfilingGuid == eventProfilingGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100391}
392
Sadik Armagan1625efc2021-06-10 18:24:34 +0100393TEST_CASE("SendTimelinePacketTests2")
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100394{
395 MockBufferManager bufferManager(40);
396 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
397 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
398
Sadik Armagan1625efc2021-06-10 18:24:34 +0100399 CHECK_THROWS_AS(sendTimelinePacket->SendTimelineMessageDirectoryPackage(),
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100400 armnn::RuntimeException);
401}
402
Sadik Armagan1625efc2021-06-10 18:24:34 +0100403TEST_CASE("SendTimelinePacketTests3")
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100404{
405 MockBufferManager bufferManager(512);
406 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
407 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
408
409 // Send TimelineEntityClassBinaryPacket
410 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
411 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
412
413 // Commit the buffer
414 sendTimelinePacket->Commit();
415
416 // Get the readable buffer
417 auto packetBuffer = bufferManager.GetReadableBuffer();
418
419 // Send TimelineEventClassBinaryPacket
420 const uint64_t eventClassBinaryPacketProfilingGuid = 789123u;
Jim Flynn1892d212020-05-26 21:10:49 +0100421 const uint64_t eventClassBinaryPacketNameGuid = 8845u;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100422 CHECK_THROWS_AS(sendTimelinePacket->SendTimelineEventClassBinaryPacket(
Jim Flynn1892d212020-05-26 21:10:49 +0100423 eventClassBinaryPacketProfilingGuid, eventClassBinaryPacketNameGuid),
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000424 BufferExhaustion);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100425}
426
Sadik Armagan1625efc2021-06-10 18:24:34 +0100427TEST_CASE("GetGuidsFromProfilingService")
Jim Flynn00f3aaf2019-10-24 11:58:06 +0100428{
Keith Davis33ed2212020-03-30 10:43:41 +0100429 armnn::IRuntime::CreationOptions options;
430 options.m_ProfilingOptions.m_EnableProfiling = true;
Kevin Mayd92a6e42021-02-04 10:27:41 +0000431 armnn::RuntimeImpl runtime(options);
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000432 ProfilingService profilingService(runtime);
Keith Davis33ed2212020-03-30 10:43:41 +0100433
Jim Flynn4c9ed1d2022-01-23 23:57:20 +0000434 profilingService.ResetExternalProfilingOptions(
435 ConvertExternalProfilingOptions(options.m_ProfilingOptions), true);
Sadik Armagan3184c902020-03-18 10:57:30 +0000436 ProfilingStaticGuid staticGuid = profilingService.GetStaticId("dummy");
Jim Flynnab845752019-10-25 13:17:30 +0100437 std::hash<std::string> hasher;
438 uint64_t hash = static_cast<uint64_t>(hasher("dummy"));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000439 ProfilingStaticGuid expectedStaticValue(hash | MIN_STATIC_GUID);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100440 CHECK(staticGuid == expectedStaticValue);
Sadik Armagan3184c902020-03-18 10:57:30 +0000441 ProfilingDynamicGuid dynamicGuid = profilingService.GetNextGuid();
Jim Flynnab845752019-10-25 13:17:30 +0100442 uint64_t dynamicGuidValue = static_cast<uint64_t>(dynamicGuid);
443 ++dynamicGuidValue;
444 ProfilingDynamicGuid expectedDynamicValue(dynamicGuidValue);
Sadik Armagan3184c902020-03-18 10:57:30 +0000445 dynamicGuid = profilingService.GetNextGuid();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100446 CHECK(dynamicGuid == expectedDynamicValue);
Jim Flynn00f3aaf2019-10-24 11:58:06 +0100447}
448
Sadik Armagan1625efc2021-06-10 18:24:34 +0100449TEST_CASE("GetTimelinePackerWriterFromProfilingService")
Jim Flynn8b200652019-10-24 18:07:44 +0100450{
Jim Flynn4c9ed1d2022-01-23 23:57:20 +0000451 ProfilingOptions options;
Jim Flynn8b200652019-10-24 18:07:44 +0100452 options.m_EnableProfiling = true;
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000453 ProfilingService profilingService;
Jim Flynn8b200652019-10-24 18:07:44 +0100454 profilingService.ResetExternalProfilingOptions(options, true);
455
456 std::unique_ptr<ISendTimelinePacket> writer = profilingService.GetSendTimelinePacket();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100457 CHECK(writer != nullptr);
Jim Flynn8b200652019-10-24 18:07:44 +0100458}
459
Sadik Armagan1625efc2021-06-10 18:24:34 +0100460TEST_CASE("CheckStaticGuidsAndEvents")
Jim Flynnab845752019-10-25 13:17:30 +0100461{
Sadik Armagan1625efc2021-06-10 18:24:34 +0100462 CHECK("name" == LabelsAndEventClasses::NAME_LABEL);
463 CHECK("type" == LabelsAndEventClasses::TYPE_LABEL);
464 CHECK("index" == LabelsAndEventClasses::INDEX_LABEL);
Jim Flynnab845752019-10-25 13:17:30 +0100465
466 std::hash<std::string> hasher;
467
468 uint64_t hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::NAME_LABEL));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000469 ProfilingStaticGuid expectedNameGuid(hash | MIN_STATIC_GUID);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100470 CHECK(LabelsAndEventClasses::NAME_GUID == expectedNameGuid);
Jim Flynnab845752019-10-25 13:17:30 +0100471
472 hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::TYPE_LABEL));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000473 ProfilingStaticGuid expectedTypeGuid(hash | MIN_STATIC_GUID);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100474 CHECK(LabelsAndEventClasses::TYPE_GUID == expectedTypeGuid);
Jim Flynnab845752019-10-25 13:17:30 +0100475
476 hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::INDEX_LABEL));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000477 ProfilingStaticGuid expectedIndexGuid(hash | MIN_STATIC_GUID);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100478 CHECK(LabelsAndEventClasses::INDEX_GUID == expectedIndexGuid);
Jim Flynnab845752019-10-25 13:17:30 +0100479
480 hash = static_cast<uint64_t>(hasher("ARMNN_PROFILING_SOL"));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000481 ProfilingStaticGuid expectedSol(hash | MIN_STATIC_GUID);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100482 CHECK(LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS == expectedSol);
Jim Flynnab845752019-10-25 13:17:30 +0100483
484 hash = static_cast<uint64_t>(hasher("ARMNN_PROFILING_EOL"));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000485 ProfilingStaticGuid expectedEol(hash | MIN_STATIC_GUID);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100486 CHECK(LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS == expectedEol);
Jim Flynnab845752019-10-25 13:17:30 +0100487}
488
Sadik Armagan1625efc2021-06-10 18:24:34 +0100489}