blob: 4b45cfef760aba2e6f7a90a749030ea14e6cb02a [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>
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010010#include <ProfilingUtils.hpp>
11#include <SendTimelinePacket.hpp>
12#include <TimelinePacketWriterFactory.hpp>
13
14#include <boost/test/unit_test.hpp>
Jim Flynnab845752019-10-25 13:17:30 +010015#include <LabelsAndEventClasses.hpp>
16
17#include <functional>
Keith Davis33ed2212020-03-30 10:43:41 +010018#include <Runtime.hpp>
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010019
20using namespace armnn::profiling;
21
22BOOST_AUTO_TEST_SUITE(SendTimelinePacketTests)
23
24BOOST_AUTO_TEST_CASE(SendTimelineMessageDirectoryPackageTest)
25{
26 MockBufferManager mockBuffer(512);
27 TimelinePacketWriterFactory timelinePacketWriterFactory(mockBuffer);
28 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
29
30 sendTimelinePacket->SendTimelineMessageDirectoryPackage();
31
32 // Get the readable buffer
33 auto packetBuffer = mockBuffer.GetReadableBuffer();
34
Matteo Martincigh34a407d2019-11-06 15:30:54 +000035 unsigned int uint8_t_size = sizeof(uint8_t);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010036 unsigned int uint32_t_size = sizeof(uint32_t);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000037 unsigned int uint64_t_size = sizeof(uint64_t);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000038
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010039 // Check the packet header
40 unsigned int offset = 0;
41 uint32_t packetHeaderWord0 = ReadUint32(packetBuffer, offset);
42 uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F;
43 uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F;
44 uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007;
45 uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007;
46
47 BOOST_CHECK(packetFamily == 1);
48 BOOST_CHECK(packetClass == 0);
49 BOOST_CHECK(packetType == 0);
50 BOOST_CHECK(streamId == 0);
51
52 offset += uint32_t_size;
53 uint32_t packetHeaderWord1 = ReadUint32(packetBuffer, offset);
54 uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001;
55 uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF;
56 BOOST_CHECK(sequenceNumbered == 0);
Jim Flynn6398a982020-05-27 17:05:21 +010057 BOOST_CHECK(dataLength == 443);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010058
59 offset += uint32_t_size;
Matteo Martincigh34a407d2019-11-06 15:30:54 +000060 uint8_t readStreamVersion = ReadUint8(packetBuffer, offset);
61 BOOST_CHECK(readStreamVersion == 4);
62 offset += uint8_t_size;
63 uint8_t readPointerBytes = ReadUint8(packetBuffer, offset);
64 BOOST_CHECK(readPointerBytes == uint64_t_size);
65 offset += uint8_t_size;
66 uint8_t readThreadIdBytes = ReadUint8(packetBuffer, offset);
Colm Donelan5bb3d8a2020-05-12 16:36:46 +010067 BOOST_CHECK(readThreadIdBytes == ThreadIdSize);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000068
69 offset += uint8_t_size;
Finn Williamse63a0262019-10-22 10:30:49 +010070 uint32_t DeclCount = ReadUint32(packetBuffer, offset);
71 BOOST_CHECK(DeclCount == 5);
72
73 offset += uint32_t_size;
74 SwTraceMessage swTraceMessage = ReadSwTraceMessage(packetBuffer->GetReadableData(), offset);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010075
Matteo Martincigh34a407d2019-11-06 15:30:54 +000076 BOOST_CHECK(swTraceMessage.m_Id == 0);
77 BOOST_CHECK(swTraceMessage.m_Name == "declareLabel");
78 BOOST_CHECK(swTraceMessage.m_UiName == "declare label");
79 BOOST_CHECK(swTraceMessage.m_ArgTypes.size() == 2);
80 BOOST_CHECK(swTraceMessage.m_ArgTypes[0] == 'p');
81 BOOST_CHECK(swTraceMessage.m_ArgTypes[1] == 's');
82 BOOST_CHECK(swTraceMessage.m_ArgNames.size() == 2);
83 BOOST_CHECK(swTraceMessage.m_ArgNames[0] == "guid");
84 BOOST_CHECK(swTraceMessage.m_ArgNames[1] == "value");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010085
Finn Williamse63a0262019-10-22 10:30:49 +010086 swTraceMessage = ReadSwTraceMessage(packetBuffer->GetReadableData(), offset);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010087
Matteo Martincigh34a407d2019-11-06 15:30:54 +000088 BOOST_CHECK(swTraceMessage.m_Id == 1);
89 BOOST_CHECK(swTraceMessage.m_Name == "declareEntity");
90 BOOST_CHECK(swTraceMessage.m_UiName == "declare entity");
91 BOOST_CHECK(swTraceMessage.m_ArgTypes.size() == 1);
92 BOOST_CHECK(swTraceMessage.m_ArgTypes[0] == 'p');
93 BOOST_CHECK(swTraceMessage.m_ArgNames.size() == 1);
94 BOOST_CHECK(swTraceMessage.m_ArgNames[0] == "guid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010095
Finn Williamse63a0262019-10-22 10:30:49 +010096 swTraceMessage = ReadSwTraceMessage(packetBuffer->GetReadableData(), offset);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010097
Matteo Martincigh34a407d2019-11-06 15:30:54 +000098 BOOST_CHECK(swTraceMessage.m_Id == 2);
99 BOOST_CHECK(swTraceMessage.m_Name == "declareEventClass");
100 BOOST_CHECK(swTraceMessage.m_UiName == "declare event class");
Jim Flynn6398a982020-05-27 17:05:21 +0100101 BOOST_CHECK(swTraceMessage.m_ArgTypes.size() == 2);
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000102 BOOST_CHECK(swTraceMessage.m_ArgTypes[0] == 'p');
Jim Flynn6398a982020-05-27 17:05:21 +0100103 BOOST_CHECK(swTraceMessage.m_ArgTypes[1] == 'p');
104 BOOST_CHECK(swTraceMessage.m_ArgNames.size() == 2);
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000105 BOOST_CHECK(swTraceMessage.m_ArgNames[0] == "guid");
Jim Flynn6398a982020-05-27 17:05:21 +0100106 BOOST_CHECK(swTraceMessage.m_ArgNames[1] == "nameGuid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100107
Finn Williamse63a0262019-10-22 10:30:49 +0100108 swTraceMessage = ReadSwTraceMessage(packetBuffer->GetReadableData(), offset);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100109
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000110 BOOST_CHECK(swTraceMessage.m_Id == 3);
111 BOOST_CHECK(swTraceMessage.m_Name == "declareRelationship");
112 BOOST_CHECK(swTraceMessage.m_UiName == "declare relationship");
Jim Flynn6398a982020-05-27 17:05:21 +0100113 BOOST_CHECK(swTraceMessage.m_ArgTypes.size() == 5);
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000114 BOOST_CHECK(swTraceMessage.m_ArgTypes[0] == 'I');
115 BOOST_CHECK(swTraceMessage.m_ArgTypes[1] == 'p');
116 BOOST_CHECK(swTraceMessage.m_ArgTypes[2] == 'p');
117 BOOST_CHECK(swTraceMessage.m_ArgTypes[3] == 'p');
Jim Flynn6398a982020-05-27 17:05:21 +0100118 BOOST_CHECK(swTraceMessage.m_ArgTypes[4] == 'p');
119 BOOST_CHECK(swTraceMessage.m_ArgNames.size() == 5);
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000120 BOOST_CHECK(swTraceMessage.m_ArgNames[0] == "relationshipType");
121 BOOST_CHECK(swTraceMessage.m_ArgNames[1] == "relationshipGuid");
122 BOOST_CHECK(swTraceMessage.m_ArgNames[2] == "headGuid");
123 BOOST_CHECK(swTraceMessage.m_ArgNames[3] == "tailGuid");
Jim Flynn6398a982020-05-27 17:05:21 +0100124 BOOST_CHECK(swTraceMessage.m_ArgNames[4] == "attributeGuid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100125
Finn Williamse63a0262019-10-22 10:30:49 +0100126 swTraceMessage = ReadSwTraceMessage(packetBuffer->GetReadableData(), offset);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100127
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000128 BOOST_CHECK(swTraceMessage.m_Id == 4);
129 BOOST_CHECK(swTraceMessage.m_Name == "declareEvent");
130 BOOST_CHECK(swTraceMessage.m_UiName == "declare event");
131 BOOST_CHECK(swTraceMessage.m_ArgTypes.size() == 3);
132 BOOST_CHECK(swTraceMessage.m_ArgTypes[0] == '@');
133 BOOST_CHECK(swTraceMessage.m_ArgTypes[1] == 't');
134 BOOST_CHECK(swTraceMessage.m_ArgTypes[2] == 'p');
135 BOOST_CHECK(swTraceMessage.m_ArgNames.size() == 3);
136 BOOST_CHECK(swTraceMessage.m_ArgNames[0] == "timestamp");
137 BOOST_CHECK(swTraceMessage.m_ArgNames[1] == "threadId");
138 BOOST_CHECK(swTraceMessage.m_ArgNames[2] == "eventGuid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100139}
140
Keith Davis97da5e22020-03-05 16:25:28 +0000141BOOST_AUTO_TEST_CASE(SendTimelineEntityWithEventClassPacketTest)
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100142{
143 MockBufferManager bufferManager(40);
144 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
145 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
146
147 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
148 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
149
150 const uint64_t eventClassBinaryPacketProfilingGuid = 789123u;
Jim Flynn1892d212020-05-26 21:10:49 +0100151 const uint64_t eventClassBinaryPacketNameGuid = 8845u;
152 sendTimelinePacket->SendTimelineEventClassBinaryPacket(
153 eventClassBinaryPacketProfilingGuid, eventClassBinaryPacketNameGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100154
155 // Commit the messages
156 sendTimelinePacket->Commit();
157
158 // Get the readable buffer
159 auto packetBuffer = bufferManager.GetReadableBuffer();
160
161 unsigned int uint32_t_size = sizeof(uint32_t);
162 unsigned int uint64_t_size = sizeof(uint64_t);
163
164 // Check the packet header
165 unsigned int offset = 0;
166
167 // Reading TimelineEntityClassBinaryPacket
Keith Davis97da5e22020-03-05 16:25:28 +0000168 uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
169 uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
170 uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
171 uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007;
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100172 uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007;
173
Keith Davis97da5e22020-03-05 16:25:28 +0000174 BOOST_CHECK(entityBinaryPacketFamily == 1);
175 BOOST_CHECK(entityBinaryPacketClass == 0);
176 BOOST_CHECK(entityBinaryPacketType == 1);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100177 BOOST_CHECK(entityBinaryPacketStreamId == 0);
178
179 offset += uint32_t_size;
Keith Davis97da5e22020-03-05 16:25:28 +0000180
181 uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
182
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100183 uint32_t entityBinaryPacketSequenceNumbered = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001;
184 uint32_t entityBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
Keith Davis97da5e22020-03-05 16:25:28 +0000185
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100186 BOOST_CHECK(entityBinaryPacketSequenceNumbered == 0);
Jim Flynn1892d212020-05-26 21:10:49 +0100187 BOOST_CHECK(entityBinaryPacketDataLength == 32);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100188
189 // Check the decl_id
190 offset += uint32_t_size;
191 uint32_t entitytDecId = ReadUint32(packetBuffer, offset);
192
193 BOOST_CHECK(entitytDecId == uint32_t(1));
194
195 // Check the profiling GUID
196 offset += uint32_t_size;
197 uint64_t readProfilingGuid = ReadUint64(packetBuffer, offset);
198
199 BOOST_CHECK(readProfilingGuid == entityBinaryPacketProfilingGuid);
200
201 // Reading TimelineEventClassBinaryPacket
202 offset += uint64_t_size;
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100203
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100204 uint32_t eventClassDeclId = ReadUint32(packetBuffer, offset);
205 BOOST_CHECK(eventClassDeclId == uint32_t(2));
206
207 // Check the profiling GUID
208 offset += uint32_t_size;
209 readProfilingGuid = ReadUint64(packetBuffer, offset);
210 BOOST_CHECK(readProfilingGuid == eventClassBinaryPacketProfilingGuid);
211
Jim Flynn1892d212020-05-26 21:10:49 +0100212 offset += uint64_t_size;
213 uint64_t readEventClassNameGuid = ReadUint64(packetBuffer, offset);
214 BOOST_CHECK(readEventClassNameGuid == eventClassBinaryPacketNameGuid);
215
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100216 bufferManager.MarkRead(packetBuffer);
217}
218
Keith Davis97da5e22020-03-05 16:25:28 +0000219BOOST_AUTO_TEST_CASE(SendEventClassAfterTimelineEntityPacketTest)
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100220{
221 unsigned int uint32_t_size = sizeof(uint32_t);
222 unsigned int uint64_t_size = sizeof(uint64_t);
223
224 MockBufferManager bufferManager(512);
225 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
226 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
227
228 // Send TimelineEntityClassBinaryPacket
229 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
230 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
231
232 // Commit the buffer
233 sendTimelinePacket->Commit();
234
235 // Get the readable buffer
236 auto packetBuffer = bufferManager.GetReadableBuffer();
237
238 // Check the packet header
239 unsigned int offset = 0;
240
241 // Reading TimelineEntityClassBinaryPacket
242 uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
243 uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
244 uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
245 uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007;
246 uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007;
247
248 BOOST_CHECK(entityBinaryPacketFamily == 1);
249 BOOST_CHECK(entityBinaryPacketClass == 0);
250 BOOST_CHECK(entityBinaryPacketType == 1);
251 BOOST_CHECK(entityBinaryPacketStreamId == 0);
252
253 offset += uint32_t_size;
254 uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
255 uint32_t entityBinaryPacketSequenceNumbered = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001;
256 uint32_t entityBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
257 BOOST_CHECK(entityBinaryPacketSequenceNumbered == 0);
Finn Williamse63a0262019-10-22 10:30:49 +0100258 BOOST_CHECK(entityBinaryPacketDataLength == 12);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100259
260 // Check the decl_id
261 offset += uint32_t_size;
262 uint32_t entitytDecId = ReadUint32(packetBuffer, offset);
263
264 BOOST_CHECK(entitytDecId == uint32_t(1));
265
266 // Check the profiling GUID
267 offset += uint32_t_size;
268 uint64_t readProfilingGuid = ReadUint64(packetBuffer, offset);
269
270 BOOST_CHECK(readProfilingGuid == entityBinaryPacketProfilingGuid);
271
272 bufferManager.MarkRead(packetBuffer);
273
274 // Send TimelineEventClassBinaryPacket
275 const uint64_t eventClassBinaryPacketProfilingGuid = 789123u;
Jim Flynn1892d212020-05-26 21:10:49 +0100276 const uint64_t eventClassBinaryPacketNameGuid = 8845u;
277 sendTimelinePacket->SendTimelineEventClassBinaryPacket(
278 eventClassBinaryPacketProfilingGuid, eventClassBinaryPacketNameGuid);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100279
280 // Commit the buffer
281 sendTimelinePacket->Commit();
282
283 // Get the readable buffer
284 packetBuffer = bufferManager.GetReadableBuffer();
285
286 // Check the packet header
287 offset = 0;
288
289 // Reading TimelineEventClassBinaryPacket
290 uint32_t eventClassBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
291 uint32_t eventClassBinaryPacketFamily = (eventClassBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
292 uint32_t eventClassBinaryPacketClass = (eventClassBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
293 uint32_t eventClassBinaryPacketType = (eventClassBinaryPacketHeaderWord0 >> 16) & 0x00000007;
294 uint32_t eventClassBinaryPacketStreamId = (eventClassBinaryPacketHeaderWord0 >> 0) & 0x00000007;
295
296 BOOST_CHECK(eventClassBinaryPacketFamily == 1);
297 BOOST_CHECK(eventClassBinaryPacketClass == 0);
298 BOOST_CHECK(eventClassBinaryPacketType == 1);
299 BOOST_CHECK(eventClassBinaryPacketStreamId == 0);
300
301 offset += uint32_t_size;
302 uint32_t eventClassBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
303 uint32_t eventClassBinaryPacketSequenceNumbered = (eventClassBinaryPacketHeaderWord1 >> 24) & 0x00000001;
304 uint32_t eventClassBinaryPacketDataLength = (eventClassBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
305 BOOST_CHECK(eventClassBinaryPacketSequenceNumbered == 0);
Jim Flynn1892d212020-05-26 21:10:49 +0100306 BOOST_CHECK(eventClassBinaryPacketDataLength == 20);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100307
308 offset += uint32_t_size;
309 uint32_t eventClassDeclId = ReadUint32(packetBuffer, offset);
310 BOOST_CHECK(eventClassDeclId == uint32_t(2));
311
312 // Check the profiling GUID
313 offset += uint32_t_size;
314 readProfilingGuid = ReadUint64(packetBuffer, offset);
315 BOOST_CHECK(readProfilingGuid == eventClassBinaryPacketProfilingGuid);
316
Jim Flynn1892d212020-05-26 21:10:49 +0100317 offset += uint64_t_size;
318 uint64_t readEventClassNameGuid = ReadUint64(packetBuffer, offset);
319 BOOST_CHECK(readEventClassNameGuid == eventClassBinaryPacketNameGuid);
320
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100321 bufferManager.MarkRead(packetBuffer);
322
323 // Send TimelineEventBinaryPacket
324 const uint64_t timestamp = 456789u;
Matteo Martincigh378bbfc2019-11-04 14:05:28 +0000325 const std::thread::id threadId = std::this_thread::get_id();
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100326 const uint64_t eventProfilingGuid = 123456u;
327 sendTimelinePacket->SendTimelineEventBinaryPacket(timestamp, threadId, eventProfilingGuid);
328
329 // Commit the buffer
330 sendTimelinePacket->Commit();
331
332 // Get the readable buffer
333 packetBuffer = bufferManager.GetReadableBuffer();
334
335 // Check the packet header
336 offset = 0;
337
338 // Reading TimelineEventBinaryPacket
339 uint32_t eventBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
340 uint32_t eventBinaryPacketFamily = (eventBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
341 uint32_t eventBinaryPacketClass = (eventBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
342 uint32_t eventBinaryPacketType = (eventBinaryPacketHeaderWord0 >> 16) & 0x00000007;
343 uint32_t eventBinaryPacketStreamId = (eventBinaryPacketHeaderWord0 >> 0) & 0x00000007;
344
345 BOOST_CHECK(eventBinaryPacketFamily == 1);
346 BOOST_CHECK(eventBinaryPacketClass == 0);
347 BOOST_CHECK(eventBinaryPacketType == 1);
348 BOOST_CHECK(eventBinaryPacketStreamId == 0);
349
350 offset += uint32_t_size;
351 uint32_t eventBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
352 uint32_t eventBinaryPacketSequenceNumbered = (eventBinaryPacketHeaderWord1 >> 24) & 0x00000001;
353 uint32_t eventBinaryPacketDataLength = (eventBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
354 BOOST_CHECK(eventBinaryPacketSequenceNumbered == 0);
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100355 BOOST_CHECK(eventBinaryPacketDataLength == 20 + ThreadIdSize);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100356
357 // Check the decl_id
358 offset += uint32_t_size;
359 uint32_t eventDeclId = ReadUint32(packetBuffer, offset);
360 BOOST_CHECK(eventDeclId == 4);
361
362 // Check the timestamp
363 offset += uint32_t_size;
364 uint64_t eventTimestamp = ReadUint64(packetBuffer, offset);
365 BOOST_CHECK(eventTimestamp == timestamp);
366
367 // Check the thread id
368 offset += uint64_t_size;
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100369 std::vector<uint8_t> readThreadId(ThreadIdSize, 0);
370 ReadBytes(packetBuffer, offset, ThreadIdSize, readThreadId.data());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100371 BOOST_CHECK(readThreadId == threadId);
372
373 // Check the profiling GUID
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100374 offset += ThreadIdSize;
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100375 readProfilingGuid = ReadUint64(packetBuffer, offset);
376 BOOST_CHECK(readProfilingGuid == eventProfilingGuid);
377}
378
379BOOST_AUTO_TEST_CASE(SendTimelinePacketTests2)
380{
381 MockBufferManager bufferManager(40);
382 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
383 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
384
385 BOOST_CHECK_THROW(sendTimelinePacket->SendTimelineMessageDirectoryPackage(),
386 armnn::RuntimeException);
387}
388
389BOOST_AUTO_TEST_CASE(SendTimelinePacketTests3)
390{
391 MockBufferManager bufferManager(512);
392 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
393 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
394
395 // Send TimelineEntityClassBinaryPacket
396 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
397 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
398
399 // Commit the buffer
400 sendTimelinePacket->Commit();
401
402 // Get the readable buffer
403 auto packetBuffer = bufferManager.GetReadableBuffer();
404
405 // Send TimelineEventClassBinaryPacket
406 const uint64_t eventClassBinaryPacketProfilingGuid = 789123u;
Jim Flynn1892d212020-05-26 21:10:49 +0100407 const uint64_t eventClassBinaryPacketNameGuid = 8845u;
408 BOOST_CHECK_THROW(sendTimelinePacket->SendTimelineEventClassBinaryPacket(
409 eventClassBinaryPacketProfilingGuid, eventClassBinaryPacketNameGuid),
Jim Flynn6398a982020-05-27 17:05:21 +0100410 armnn::profiling::BufferExhaustion);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100411}
412
Jim Flynn00f3aaf2019-10-24 11:58:06 +0100413BOOST_AUTO_TEST_CASE(GetGuidsFromProfilingService)
414{
Keith Davis33ed2212020-03-30 10:43:41 +0100415 armnn::IRuntime::CreationOptions options;
416 options.m_ProfilingOptions.m_EnableProfiling = true;
417 armnn::Runtime runtime(options);
418 armnn::profiling::ProfilingService profilingService(runtime);
419
420 profilingService.ResetExternalProfilingOptions(options.m_ProfilingOptions, true);
Sadik Armagan3184c902020-03-18 10:57:30 +0000421 ProfilingStaticGuid staticGuid = profilingService.GetStaticId("dummy");
Jim Flynnab845752019-10-25 13:17:30 +0100422 std::hash<std::string> hasher;
423 uint64_t hash = static_cast<uint64_t>(hasher("dummy"));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000424 ProfilingStaticGuid expectedStaticValue(hash | MIN_STATIC_GUID);
Jim Flynn00f3aaf2019-10-24 11:58:06 +0100425 BOOST_CHECK(staticGuid == expectedStaticValue);
Sadik Armagan3184c902020-03-18 10:57:30 +0000426 ProfilingDynamicGuid dynamicGuid = profilingService.GetNextGuid();
Jim Flynnab845752019-10-25 13:17:30 +0100427 uint64_t dynamicGuidValue = static_cast<uint64_t>(dynamicGuid);
428 ++dynamicGuidValue;
429 ProfilingDynamicGuid expectedDynamicValue(dynamicGuidValue);
Sadik Armagan3184c902020-03-18 10:57:30 +0000430 dynamicGuid = profilingService.GetNextGuid();
Jim Flynn00f3aaf2019-10-24 11:58:06 +0100431 BOOST_CHECK(dynamicGuid == expectedDynamicValue);
432}
433
Jim Flynn8b200652019-10-24 18:07:44 +0100434BOOST_AUTO_TEST_CASE(GetTimelinePackerWriterFromProfilingService)
435{
Narumol Prangnawarat85ad78c2019-11-18 15:34:23 +0000436 armnn::IRuntime::CreationOptions::ExternalProfilingOptions options;
Jim Flynn8b200652019-10-24 18:07:44 +0100437 options.m_EnableProfiling = true;
Sadik Armagan3184c902020-03-18 10:57:30 +0000438 armnn::profiling::ProfilingService profilingService;
Jim Flynn8b200652019-10-24 18:07:44 +0100439 profilingService.ResetExternalProfilingOptions(options, true);
440
441 std::unique_ptr<ISendTimelinePacket> writer = profilingService.GetSendTimelinePacket();
442 BOOST_CHECK(writer != nullptr);
443}
444
Jim Flynnab845752019-10-25 13:17:30 +0100445BOOST_AUTO_TEST_CASE(CheckStaticGuidsAndEvents)
446{
447 BOOST_CHECK("name" == LabelsAndEventClasses::NAME_LABEL);
448 BOOST_CHECK("type" == LabelsAndEventClasses::TYPE_LABEL);
449 BOOST_CHECK("index" == LabelsAndEventClasses::INDEX_LABEL);
450
451 std::hash<std::string> hasher;
452
453 uint64_t hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::NAME_LABEL));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000454 ProfilingStaticGuid expectedNameGuid(hash | MIN_STATIC_GUID);
Jim Flynnab845752019-10-25 13:17:30 +0100455 BOOST_CHECK(LabelsAndEventClasses::NAME_GUID == expectedNameGuid);
456
457 hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::TYPE_LABEL));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000458 ProfilingStaticGuid expectedTypeGuid(hash | MIN_STATIC_GUID);
Jim Flynnab845752019-10-25 13:17:30 +0100459 BOOST_CHECK(LabelsAndEventClasses::TYPE_GUID == expectedTypeGuid);
460
461 hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::INDEX_LABEL));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000462 ProfilingStaticGuid expectedIndexGuid(hash | MIN_STATIC_GUID);
Jim Flynnab845752019-10-25 13:17:30 +0100463 BOOST_CHECK(LabelsAndEventClasses::INDEX_GUID == expectedIndexGuid);
464
465 hash = static_cast<uint64_t>(hasher("ARMNN_PROFILING_SOL"));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000466 ProfilingStaticGuid expectedSol(hash | MIN_STATIC_GUID);
Jim Flynnab845752019-10-25 13:17:30 +0100467 BOOST_CHECK(LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS == expectedSol);
468
469 hash = static_cast<uint64_t>(hasher("ARMNN_PROFILING_EOL"));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000470 ProfilingStaticGuid expectedEol(hash | MIN_STATIC_GUID);
Jim Flynnab845752019-10-25 13:17:30 +0100471 BOOST_CHECK(LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS == expectedEol);
472}
473
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100474BOOST_AUTO_TEST_SUITE_END()