blob: 244f23dfb41ff074c1620f1cd4b2ab50478286f4 [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 Flynnbbfe6032020-07-20 16:57:44 +01009#include <LabelsAndEventClasses.hpp>
Jim Flynn00f3aaf2019-10-24 11:58:06 +010010#include <ProfilingService.hpp>
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010011#include <ProfilingUtils.hpp>
12#include <SendTimelinePacket.hpp>
Jim Flynnbbfe6032020-07-20 16:57:44 +010013#include <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>
17
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010018#include <boost/test/unit_test.hpp>
Jim Flynnab845752019-10-25 13:17:30 +010019
20#include <functional>
Keith Davis33ed2212020-03-30 10:43:41 +010021#include <Runtime.hpp>
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010022
23using namespace armnn::profiling;
24
25BOOST_AUTO_TEST_SUITE(SendTimelinePacketTests)
26
27BOOST_AUTO_TEST_CASE(SendTimelineMessageDirectoryPackageTest)
28{
29 MockBufferManager mockBuffer(512);
30 TimelinePacketWriterFactory timelinePacketWriterFactory(mockBuffer);
31 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
32
33 sendTimelinePacket->SendTimelineMessageDirectoryPackage();
34
35 // Get the readable buffer
36 auto packetBuffer = mockBuffer.GetReadableBuffer();
37
Matteo Martincigh34a407d2019-11-06 15:30:54 +000038 unsigned int uint8_t_size = sizeof(uint8_t);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010039 unsigned int uint32_t_size = sizeof(uint32_t);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000040 unsigned int uint64_t_size = sizeof(uint64_t);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000041
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010042 // Check the packet header
43 unsigned int offset = 0;
44 uint32_t packetHeaderWord0 = ReadUint32(packetBuffer, offset);
45 uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F;
46 uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F;
47 uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007;
48 uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007;
49
50 BOOST_CHECK(packetFamily == 1);
51 BOOST_CHECK(packetClass == 0);
52 BOOST_CHECK(packetType == 0);
53 BOOST_CHECK(streamId == 0);
54
55 offset += uint32_t_size;
56 uint32_t packetHeaderWord1 = ReadUint32(packetBuffer, offset);
57 uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001;
58 uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF;
59 BOOST_CHECK(sequenceNumbered == 0);
Jim Flynn6398a982020-05-27 17:05:21 +010060 BOOST_CHECK(dataLength == 443);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010061
62 offset += uint32_t_size;
Matteo Martincigh34a407d2019-11-06 15:30:54 +000063 uint8_t readStreamVersion = ReadUint8(packetBuffer, offset);
64 BOOST_CHECK(readStreamVersion == 4);
65 offset += uint8_t_size;
66 uint8_t readPointerBytes = ReadUint8(packetBuffer, offset);
67 BOOST_CHECK(readPointerBytes == uint64_t_size);
68 offset += uint8_t_size;
69 uint8_t readThreadIdBytes = ReadUint8(packetBuffer, offset);
Colm Donelan5bb3d8a2020-05-12 16:36:46 +010070 BOOST_CHECK(readThreadIdBytes == ThreadIdSize);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000071
72 offset += uint8_t_size;
Finn Williamse63a0262019-10-22 10:30:49 +010073 uint32_t DeclCount = ReadUint32(packetBuffer, offset);
74 BOOST_CHECK(DeclCount == 5);
75
76 offset += uint32_t_size;
Jim Flynnbbfe6032020-07-20 16:57:44 +010077 arm::pipe::SwTraceMessage swTraceMessage = arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
78 offset,
79 packetBuffer->GetSize());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010080
Matteo Martincigh34a407d2019-11-06 15:30:54 +000081 BOOST_CHECK(swTraceMessage.m_Id == 0);
82 BOOST_CHECK(swTraceMessage.m_Name == "declareLabel");
83 BOOST_CHECK(swTraceMessage.m_UiName == "declare label");
84 BOOST_CHECK(swTraceMessage.m_ArgTypes.size() == 2);
85 BOOST_CHECK(swTraceMessage.m_ArgTypes[0] == 'p');
86 BOOST_CHECK(swTraceMessage.m_ArgTypes[1] == 's');
87 BOOST_CHECK(swTraceMessage.m_ArgNames.size() == 2);
88 BOOST_CHECK(swTraceMessage.m_ArgNames[0] == "guid");
89 BOOST_CHECK(swTraceMessage.m_ArgNames[1] == "value");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010090
Jim Flynnbbfe6032020-07-20 16:57:44 +010091 swTraceMessage = arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
92 offset,
93 packetBuffer->GetSize());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010094
Matteo Martincigh34a407d2019-11-06 15:30:54 +000095 BOOST_CHECK(swTraceMessage.m_Id == 1);
96 BOOST_CHECK(swTraceMessage.m_Name == "declareEntity");
97 BOOST_CHECK(swTraceMessage.m_UiName == "declare entity");
98 BOOST_CHECK(swTraceMessage.m_ArgTypes.size() == 1);
99 BOOST_CHECK(swTraceMessage.m_ArgTypes[0] == 'p');
100 BOOST_CHECK(swTraceMessage.m_ArgNames.size() == 1);
101 BOOST_CHECK(swTraceMessage.m_ArgNames[0] == "guid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100102
Jim Flynnbbfe6032020-07-20 16:57:44 +0100103 swTraceMessage = arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
104 offset,
105 packetBuffer->GetSize());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100106
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000107 BOOST_CHECK(swTraceMessage.m_Id == 2);
108 BOOST_CHECK(swTraceMessage.m_Name == "declareEventClass");
109 BOOST_CHECK(swTraceMessage.m_UiName == "declare event class");
Jim Flynn6398a982020-05-27 17:05:21 +0100110 BOOST_CHECK(swTraceMessage.m_ArgTypes.size() == 2);
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000111 BOOST_CHECK(swTraceMessage.m_ArgTypes[0] == 'p');
Jim Flynn6398a982020-05-27 17:05:21 +0100112 BOOST_CHECK(swTraceMessage.m_ArgTypes[1] == 'p');
113 BOOST_CHECK(swTraceMessage.m_ArgNames.size() == 2);
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000114 BOOST_CHECK(swTraceMessage.m_ArgNames[0] == "guid");
Jim Flynn6398a982020-05-27 17:05:21 +0100115 BOOST_CHECK(swTraceMessage.m_ArgNames[1] == "nameGuid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100116
Jim Flynnbbfe6032020-07-20 16:57:44 +0100117 swTraceMessage = arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
118 offset,
119 packetBuffer->GetSize());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100120
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000121 BOOST_CHECK(swTraceMessage.m_Id == 3);
122 BOOST_CHECK(swTraceMessage.m_Name == "declareRelationship");
123 BOOST_CHECK(swTraceMessage.m_UiName == "declare relationship");
Jim Flynn6398a982020-05-27 17:05:21 +0100124 BOOST_CHECK(swTraceMessage.m_ArgTypes.size() == 5);
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000125 BOOST_CHECK(swTraceMessage.m_ArgTypes[0] == 'I');
126 BOOST_CHECK(swTraceMessage.m_ArgTypes[1] == 'p');
127 BOOST_CHECK(swTraceMessage.m_ArgTypes[2] == 'p');
128 BOOST_CHECK(swTraceMessage.m_ArgTypes[3] == 'p');
Jim Flynn6398a982020-05-27 17:05:21 +0100129 BOOST_CHECK(swTraceMessage.m_ArgTypes[4] == 'p');
130 BOOST_CHECK(swTraceMessage.m_ArgNames.size() == 5);
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000131 BOOST_CHECK(swTraceMessage.m_ArgNames[0] == "relationshipType");
132 BOOST_CHECK(swTraceMessage.m_ArgNames[1] == "relationshipGuid");
133 BOOST_CHECK(swTraceMessage.m_ArgNames[2] == "headGuid");
134 BOOST_CHECK(swTraceMessage.m_ArgNames[3] == "tailGuid");
Jim Flynn6398a982020-05-27 17:05:21 +0100135 BOOST_CHECK(swTraceMessage.m_ArgNames[4] == "attributeGuid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100136
Jim Flynnbbfe6032020-07-20 16:57:44 +0100137 swTraceMessage = arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
138 offset,
139 packetBuffer->GetSize());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100140
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000141 BOOST_CHECK(swTraceMessage.m_Id == 4);
142 BOOST_CHECK(swTraceMessage.m_Name == "declareEvent");
143 BOOST_CHECK(swTraceMessage.m_UiName == "declare event");
144 BOOST_CHECK(swTraceMessage.m_ArgTypes.size() == 3);
145 BOOST_CHECK(swTraceMessage.m_ArgTypes[0] == '@');
146 BOOST_CHECK(swTraceMessage.m_ArgTypes[1] == 't');
147 BOOST_CHECK(swTraceMessage.m_ArgTypes[2] == 'p');
148 BOOST_CHECK(swTraceMessage.m_ArgNames.size() == 3);
149 BOOST_CHECK(swTraceMessage.m_ArgNames[0] == "timestamp");
150 BOOST_CHECK(swTraceMessage.m_ArgNames[1] == "threadId");
151 BOOST_CHECK(swTraceMessage.m_ArgNames[2] == "eventGuid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100152}
153
Keith Davis97da5e22020-03-05 16:25:28 +0000154BOOST_AUTO_TEST_CASE(SendTimelineEntityWithEventClassPacketTest)
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100155{
156 MockBufferManager bufferManager(40);
157 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
158 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
159
160 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
161 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
162
163 const uint64_t eventClassBinaryPacketProfilingGuid = 789123u;
Jim Flynn1892d212020-05-26 21:10:49 +0100164 const uint64_t eventClassBinaryPacketNameGuid = 8845u;
165 sendTimelinePacket->SendTimelineEventClassBinaryPacket(
166 eventClassBinaryPacketProfilingGuid, eventClassBinaryPacketNameGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100167
168 // Commit the messages
169 sendTimelinePacket->Commit();
170
171 // Get the readable buffer
172 auto packetBuffer = bufferManager.GetReadableBuffer();
173
174 unsigned int uint32_t_size = sizeof(uint32_t);
175 unsigned int uint64_t_size = sizeof(uint64_t);
176
177 // Check the packet header
178 unsigned int offset = 0;
179
180 // Reading TimelineEntityClassBinaryPacket
Keith Davis97da5e22020-03-05 16:25:28 +0000181 uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
182 uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
183 uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
184 uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007;
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100185 uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007;
186
Keith Davis97da5e22020-03-05 16:25:28 +0000187 BOOST_CHECK(entityBinaryPacketFamily == 1);
188 BOOST_CHECK(entityBinaryPacketClass == 0);
189 BOOST_CHECK(entityBinaryPacketType == 1);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100190 BOOST_CHECK(entityBinaryPacketStreamId == 0);
191
192 offset += uint32_t_size;
Keith Davis97da5e22020-03-05 16:25:28 +0000193
194 uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
195
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100196 uint32_t entityBinaryPacketSequenceNumbered = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001;
197 uint32_t entityBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
Keith Davis97da5e22020-03-05 16:25:28 +0000198
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100199 BOOST_CHECK(entityBinaryPacketSequenceNumbered == 0);
Jim Flynn1892d212020-05-26 21:10:49 +0100200 BOOST_CHECK(entityBinaryPacketDataLength == 32);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100201
202 // Check the decl_id
203 offset += uint32_t_size;
204 uint32_t entitytDecId = ReadUint32(packetBuffer, offset);
205
206 BOOST_CHECK(entitytDecId == uint32_t(1));
207
208 // Check the profiling GUID
209 offset += uint32_t_size;
210 uint64_t readProfilingGuid = ReadUint64(packetBuffer, offset);
211
212 BOOST_CHECK(readProfilingGuid == entityBinaryPacketProfilingGuid);
213
214 // Reading TimelineEventClassBinaryPacket
215 offset += uint64_t_size;
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100216
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100217 uint32_t eventClassDeclId = ReadUint32(packetBuffer, offset);
218 BOOST_CHECK(eventClassDeclId == uint32_t(2));
219
220 // Check the profiling GUID
221 offset += uint32_t_size;
222 readProfilingGuid = ReadUint64(packetBuffer, offset);
223 BOOST_CHECK(readProfilingGuid == eventClassBinaryPacketProfilingGuid);
224
Jim Flynn1892d212020-05-26 21:10:49 +0100225 offset += uint64_t_size;
226 uint64_t readEventClassNameGuid = ReadUint64(packetBuffer, offset);
227 BOOST_CHECK(readEventClassNameGuid == eventClassBinaryPacketNameGuid);
228
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100229 bufferManager.MarkRead(packetBuffer);
230}
231
Keith Davis97da5e22020-03-05 16:25:28 +0000232BOOST_AUTO_TEST_CASE(SendEventClassAfterTimelineEntityPacketTest)
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100233{
234 unsigned int uint32_t_size = sizeof(uint32_t);
235 unsigned int uint64_t_size = sizeof(uint64_t);
236
237 MockBufferManager bufferManager(512);
238 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
239 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
240
241 // Send TimelineEntityClassBinaryPacket
242 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
243 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
244
245 // Commit the buffer
246 sendTimelinePacket->Commit();
247
248 // Get the readable buffer
249 auto packetBuffer = bufferManager.GetReadableBuffer();
250
251 // Check the packet header
252 unsigned int offset = 0;
253
254 // Reading TimelineEntityClassBinaryPacket
255 uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
256 uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
257 uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
258 uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007;
259 uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007;
260
261 BOOST_CHECK(entityBinaryPacketFamily == 1);
262 BOOST_CHECK(entityBinaryPacketClass == 0);
263 BOOST_CHECK(entityBinaryPacketType == 1);
264 BOOST_CHECK(entityBinaryPacketStreamId == 0);
265
266 offset += uint32_t_size;
267 uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
268 uint32_t entityBinaryPacketSequenceNumbered = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001;
269 uint32_t entityBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
270 BOOST_CHECK(entityBinaryPacketSequenceNumbered == 0);
Finn Williamse63a0262019-10-22 10:30:49 +0100271 BOOST_CHECK(entityBinaryPacketDataLength == 12);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100272
273 // Check the decl_id
274 offset += uint32_t_size;
275 uint32_t entitytDecId = ReadUint32(packetBuffer, offset);
276
277 BOOST_CHECK(entitytDecId == uint32_t(1));
278
279 // Check the profiling GUID
280 offset += uint32_t_size;
281 uint64_t readProfilingGuid = ReadUint64(packetBuffer, offset);
282
283 BOOST_CHECK(readProfilingGuid == entityBinaryPacketProfilingGuid);
284
285 bufferManager.MarkRead(packetBuffer);
286
287 // Send TimelineEventClassBinaryPacket
288 const uint64_t eventClassBinaryPacketProfilingGuid = 789123u;
Jim Flynn1892d212020-05-26 21:10:49 +0100289 const uint64_t eventClassBinaryPacketNameGuid = 8845u;
290 sendTimelinePacket->SendTimelineEventClassBinaryPacket(
291 eventClassBinaryPacketProfilingGuid, eventClassBinaryPacketNameGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100292
293 // Commit the buffer
294 sendTimelinePacket->Commit();
295
296 // Get the readable buffer
297 packetBuffer = bufferManager.GetReadableBuffer();
298
299 // Check the packet header
300 offset = 0;
301
302 // Reading TimelineEventClassBinaryPacket
303 uint32_t eventClassBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
304 uint32_t eventClassBinaryPacketFamily = (eventClassBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
305 uint32_t eventClassBinaryPacketClass = (eventClassBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
306 uint32_t eventClassBinaryPacketType = (eventClassBinaryPacketHeaderWord0 >> 16) & 0x00000007;
307 uint32_t eventClassBinaryPacketStreamId = (eventClassBinaryPacketHeaderWord0 >> 0) & 0x00000007;
308
309 BOOST_CHECK(eventClassBinaryPacketFamily == 1);
310 BOOST_CHECK(eventClassBinaryPacketClass == 0);
311 BOOST_CHECK(eventClassBinaryPacketType == 1);
312 BOOST_CHECK(eventClassBinaryPacketStreamId == 0);
313
314 offset += uint32_t_size;
315 uint32_t eventClassBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
316 uint32_t eventClassBinaryPacketSequenceNumbered = (eventClassBinaryPacketHeaderWord1 >> 24) & 0x00000001;
317 uint32_t eventClassBinaryPacketDataLength = (eventClassBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
318 BOOST_CHECK(eventClassBinaryPacketSequenceNumbered == 0);
Jim Flynn1892d212020-05-26 21:10:49 +0100319 BOOST_CHECK(eventClassBinaryPacketDataLength == 20);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100320
321 offset += uint32_t_size;
322 uint32_t eventClassDeclId = ReadUint32(packetBuffer, offset);
323 BOOST_CHECK(eventClassDeclId == uint32_t(2));
324
325 // Check the profiling GUID
326 offset += uint32_t_size;
327 readProfilingGuid = ReadUint64(packetBuffer, offset);
328 BOOST_CHECK(readProfilingGuid == eventClassBinaryPacketProfilingGuid);
329
Jim Flynn1892d212020-05-26 21:10:49 +0100330 offset += uint64_t_size;
331 uint64_t readEventClassNameGuid = ReadUint64(packetBuffer, offset);
332 BOOST_CHECK(readEventClassNameGuid == eventClassBinaryPacketNameGuid);
333
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100334 bufferManager.MarkRead(packetBuffer);
335
336 // Send TimelineEventBinaryPacket
337 const uint64_t timestamp = 456789u;
Jim Flynn1fdeb992020-07-09 07:28:37 +0100338 const int threadId = armnnUtils::Threads::GetCurrentThreadId();
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100339 const uint64_t eventProfilingGuid = 123456u;
340 sendTimelinePacket->SendTimelineEventBinaryPacket(timestamp, threadId, eventProfilingGuid);
341
342 // Commit the buffer
343 sendTimelinePacket->Commit();
344
345 // Get the readable buffer
346 packetBuffer = bufferManager.GetReadableBuffer();
347
348 // Check the packet header
349 offset = 0;
350
351 // Reading TimelineEventBinaryPacket
352 uint32_t eventBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
353 uint32_t eventBinaryPacketFamily = (eventBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
354 uint32_t eventBinaryPacketClass = (eventBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
355 uint32_t eventBinaryPacketType = (eventBinaryPacketHeaderWord0 >> 16) & 0x00000007;
356 uint32_t eventBinaryPacketStreamId = (eventBinaryPacketHeaderWord0 >> 0) & 0x00000007;
357
358 BOOST_CHECK(eventBinaryPacketFamily == 1);
359 BOOST_CHECK(eventBinaryPacketClass == 0);
360 BOOST_CHECK(eventBinaryPacketType == 1);
361 BOOST_CHECK(eventBinaryPacketStreamId == 0);
362
363 offset += uint32_t_size;
364 uint32_t eventBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
365 uint32_t eventBinaryPacketSequenceNumbered = (eventBinaryPacketHeaderWord1 >> 24) & 0x00000001;
366 uint32_t eventBinaryPacketDataLength = (eventBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
367 BOOST_CHECK(eventBinaryPacketSequenceNumbered == 0);
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100368 BOOST_CHECK(eventBinaryPacketDataLength == 20 + ThreadIdSize);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100369
370 // Check the decl_id
371 offset += uint32_t_size;
372 uint32_t eventDeclId = ReadUint32(packetBuffer, offset);
373 BOOST_CHECK(eventDeclId == 4);
374
375 // Check the timestamp
376 offset += uint32_t_size;
377 uint64_t eventTimestamp = ReadUint64(packetBuffer, offset);
378 BOOST_CHECK(eventTimestamp == timestamp);
379
380 // Check the thread id
381 offset += uint64_t_size;
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100382 std::vector<uint8_t> readThreadId(ThreadIdSize, 0);
383 ReadBytes(packetBuffer, offset, ThreadIdSize, readThreadId.data());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100384 BOOST_CHECK(readThreadId == threadId);
385
386 // Check the profiling GUID
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100387 offset += ThreadIdSize;
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100388 readProfilingGuid = ReadUint64(packetBuffer, offset);
389 BOOST_CHECK(readProfilingGuid == eventProfilingGuid);
390}
391
392BOOST_AUTO_TEST_CASE(SendTimelinePacketTests2)
393{
394 MockBufferManager bufferManager(40);
395 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
396 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
397
398 BOOST_CHECK_THROW(sendTimelinePacket->SendTimelineMessageDirectoryPackage(),
399 armnn::RuntimeException);
400}
401
402BOOST_AUTO_TEST_CASE(SendTimelinePacketTests3)
403{
404 MockBufferManager bufferManager(512);
405 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
406 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
407
408 // Send TimelineEntityClassBinaryPacket
409 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
410 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
411
412 // Commit the buffer
413 sendTimelinePacket->Commit();
414
415 // Get the readable buffer
416 auto packetBuffer = bufferManager.GetReadableBuffer();
417
418 // Send TimelineEventClassBinaryPacket
419 const uint64_t eventClassBinaryPacketProfilingGuid = 789123u;
Jim Flynn1892d212020-05-26 21:10:49 +0100420 const uint64_t eventClassBinaryPacketNameGuid = 8845u;
421 BOOST_CHECK_THROW(sendTimelinePacket->SendTimelineEventClassBinaryPacket(
422 eventClassBinaryPacketProfilingGuid, eventClassBinaryPacketNameGuid),
Jim Flynn6398a982020-05-27 17:05:21 +0100423 armnn::profiling::BufferExhaustion);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100424}
425
Jim Flynn00f3aaf2019-10-24 11:58:06 +0100426BOOST_AUTO_TEST_CASE(GetGuidsFromProfilingService)
427{
Keith Davis33ed2212020-03-30 10:43:41 +0100428 armnn::IRuntime::CreationOptions options;
429 options.m_ProfilingOptions.m_EnableProfiling = true;
Kevin Mayd92a6e42021-02-04 10:27:41 +0000430 armnn::RuntimeImpl runtime(options);
Keith Davis33ed2212020-03-30 10:43:41 +0100431 armnn::profiling::ProfilingService profilingService(runtime);
432
433 profilingService.ResetExternalProfilingOptions(options.m_ProfilingOptions, true);
Sadik Armagan3184c902020-03-18 10:57:30 +0000434 ProfilingStaticGuid staticGuid = profilingService.GetStaticId("dummy");
Jim Flynnab845752019-10-25 13:17:30 +0100435 std::hash<std::string> hasher;
436 uint64_t hash = static_cast<uint64_t>(hasher("dummy"));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000437 ProfilingStaticGuid expectedStaticValue(hash | MIN_STATIC_GUID);
Jim Flynn00f3aaf2019-10-24 11:58:06 +0100438 BOOST_CHECK(staticGuid == expectedStaticValue);
Sadik Armagan3184c902020-03-18 10:57:30 +0000439 ProfilingDynamicGuid dynamicGuid = profilingService.GetNextGuid();
Jim Flynnab845752019-10-25 13:17:30 +0100440 uint64_t dynamicGuidValue = static_cast<uint64_t>(dynamicGuid);
441 ++dynamicGuidValue;
442 ProfilingDynamicGuid expectedDynamicValue(dynamicGuidValue);
Sadik Armagan3184c902020-03-18 10:57:30 +0000443 dynamicGuid = profilingService.GetNextGuid();
Jim Flynn00f3aaf2019-10-24 11:58:06 +0100444 BOOST_CHECK(dynamicGuid == expectedDynamicValue);
445}
446
Jim Flynn8b200652019-10-24 18:07:44 +0100447BOOST_AUTO_TEST_CASE(GetTimelinePackerWriterFromProfilingService)
448{
Narumol Prangnawarat85ad78c2019-11-18 15:34:23 +0000449 armnn::IRuntime::CreationOptions::ExternalProfilingOptions options;
Jim Flynn8b200652019-10-24 18:07:44 +0100450 options.m_EnableProfiling = true;
Sadik Armagan3184c902020-03-18 10:57:30 +0000451 armnn::profiling::ProfilingService profilingService;
Jim Flynn8b200652019-10-24 18:07:44 +0100452 profilingService.ResetExternalProfilingOptions(options, true);
453
454 std::unique_ptr<ISendTimelinePacket> writer = profilingService.GetSendTimelinePacket();
455 BOOST_CHECK(writer != nullptr);
456}
457
Jim Flynnab845752019-10-25 13:17:30 +0100458BOOST_AUTO_TEST_CASE(CheckStaticGuidsAndEvents)
459{
460 BOOST_CHECK("name" == LabelsAndEventClasses::NAME_LABEL);
461 BOOST_CHECK("type" == LabelsAndEventClasses::TYPE_LABEL);
462 BOOST_CHECK("index" == LabelsAndEventClasses::INDEX_LABEL);
463
464 std::hash<std::string> hasher;
465
466 uint64_t hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::NAME_LABEL));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000467 ProfilingStaticGuid expectedNameGuid(hash | MIN_STATIC_GUID);
Jim Flynnab845752019-10-25 13:17:30 +0100468 BOOST_CHECK(LabelsAndEventClasses::NAME_GUID == expectedNameGuid);
469
470 hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::TYPE_LABEL));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000471 ProfilingStaticGuid expectedTypeGuid(hash | MIN_STATIC_GUID);
Jim Flynnab845752019-10-25 13:17:30 +0100472 BOOST_CHECK(LabelsAndEventClasses::TYPE_GUID == expectedTypeGuid);
473
474 hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::INDEX_LABEL));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000475 ProfilingStaticGuid expectedIndexGuid(hash | MIN_STATIC_GUID);
Jim Flynnab845752019-10-25 13:17:30 +0100476 BOOST_CHECK(LabelsAndEventClasses::INDEX_GUID == expectedIndexGuid);
477
478 hash = static_cast<uint64_t>(hasher("ARMNN_PROFILING_SOL"));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000479 ProfilingStaticGuid expectedSol(hash | MIN_STATIC_GUID);
Jim Flynnab845752019-10-25 13:17:30 +0100480 BOOST_CHECK(LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS == expectedSol);
481
482 hash = static_cast<uint64_t>(hasher("ARMNN_PROFILING_EOL"));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000483 ProfilingStaticGuid expectedEol(hash | MIN_STATIC_GUID);
Jim Flynnab845752019-10-25 13:17:30 +0100484 BOOST_CHECK(LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS == expectedEol);
485}
486
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100487BOOST_AUTO_TEST_SUITE_END()