blob: 6d5bf490a81fedce913520f999e82df7b2c54a42 [file] [log] [blame]
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +01001//
2// Copyright © 2019 Arm Ltd. All rights reserved.
3// 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);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000057 BOOST_CHECK(dataLength == 419);
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");
101 BOOST_CHECK(swTraceMessage.m_ArgTypes.size() == 1);
102 BOOST_CHECK(swTraceMessage.m_ArgTypes[0] == 'p');
103 BOOST_CHECK(swTraceMessage.m_ArgNames.size() == 1);
104 BOOST_CHECK(swTraceMessage.m_ArgNames[0] == "guid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100105
Finn Williamse63a0262019-10-22 10:30:49 +0100106 swTraceMessage = ReadSwTraceMessage(packetBuffer->GetReadableData(), offset);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100107
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000108 BOOST_CHECK(swTraceMessage.m_Id == 3);
109 BOOST_CHECK(swTraceMessage.m_Name == "declareRelationship");
110 BOOST_CHECK(swTraceMessage.m_UiName == "declare relationship");
111 BOOST_CHECK(swTraceMessage.m_ArgTypes.size() == 4);
112 BOOST_CHECK(swTraceMessage.m_ArgTypes[0] == 'I');
113 BOOST_CHECK(swTraceMessage.m_ArgTypes[1] == 'p');
114 BOOST_CHECK(swTraceMessage.m_ArgTypes[2] == 'p');
115 BOOST_CHECK(swTraceMessage.m_ArgTypes[3] == 'p');
116 BOOST_CHECK(swTraceMessage.m_ArgNames.size() == 4);
117 BOOST_CHECK(swTraceMessage.m_ArgNames[0] == "relationshipType");
118 BOOST_CHECK(swTraceMessage.m_ArgNames[1] == "relationshipGuid");
119 BOOST_CHECK(swTraceMessage.m_ArgNames[2] == "headGuid");
120 BOOST_CHECK(swTraceMessage.m_ArgNames[3] == "tailGuid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100121
Finn Williamse63a0262019-10-22 10:30:49 +0100122 swTraceMessage = ReadSwTraceMessage(packetBuffer->GetReadableData(), offset);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100123
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000124 BOOST_CHECK(swTraceMessage.m_Id == 4);
125 BOOST_CHECK(swTraceMessage.m_Name == "declareEvent");
126 BOOST_CHECK(swTraceMessage.m_UiName == "declare event");
127 BOOST_CHECK(swTraceMessage.m_ArgTypes.size() == 3);
128 BOOST_CHECK(swTraceMessage.m_ArgTypes[0] == '@');
129 BOOST_CHECK(swTraceMessage.m_ArgTypes[1] == 't');
130 BOOST_CHECK(swTraceMessage.m_ArgTypes[2] == 'p');
131 BOOST_CHECK(swTraceMessage.m_ArgNames.size() == 3);
132 BOOST_CHECK(swTraceMessage.m_ArgNames[0] == "timestamp");
133 BOOST_CHECK(swTraceMessage.m_ArgNames[1] == "threadId");
134 BOOST_CHECK(swTraceMessage.m_ArgNames[2] == "eventGuid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100135}
136
Keith Davis97da5e22020-03-05 16:25:28 +0000137BOOST_AUTO_TEST_CASE(SendTimelineEntityWithEventClassPacketTest)
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100138{
139 MockBufferManager bufferManager(40);
140 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
141 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
142
143 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
144 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
145
146 const uint64_t eventClassBinaryPacketProfilingGuid = 789123u;
147 sendTimelinePacket->SendTimelineEventClassBinaryPacket(eventClassBinaryPacketProfilingGuid);
148
149 // Commit the messages
150 sendTimelinePacket->Commit();
151
152 // Get the readable buffer
153 auto packetBuffer = bufferManager.GetReadableBuffer();
154
155 unsigned int uint32_t_size = sizeof(uint32_t);
156 unsigned int uint64_t_size = sizeof(uint64_t);
157
158 // Check the packet header
159 unsigned int offset = 0;
160
161 // Reading TimelineEntityClassBinaryPacket
Keith Davis97da5e22020-03-05 16:25:28 +0000162 uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
163 uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
164 uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
165 uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007;
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100166 uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007;
167
Keith Davis97da5e22020-03-05 16:25:28 +0000168 BOOST_CHECK(entityBinaryPacketFamily == 1);
169 BOOST_CHECK(entityBinaryPacketClass == 0);
170 BOOST_CHECK(entityBinaryPacketType == 1);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100171 BOOST_CHECK(entityBinaryPacketStreamId == 0);
172
173 offset += uint32_t_size;
Keith Davis97da5e22020-03-05 16:25:28 +0000174
175 uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
176
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100177 uint32_t entityBinaryPacketSequenceNumbered = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001;
178 uint32_t entityBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
Keith Davis97da5e22020-03-05 16:25:28 +0000179
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100180 BOOST_CHECK(entityBinaryPacketSequenceNumbered == 0);
Keith Davis97da5e22020-03-05 16:25:28 +0000181 BOOST_CHECK(entityBinaryPacketDataLength == 24);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100182
183 // Check the decl_id
184 offset += uint32_t_size;
185 uint32_t entitytDecId = ReadUint32(packetBuffer, offset);
186
187 BOOST_CHECK(entitytDecId == uint32_t(1));
188
189 // Check the profiling GUID
190 offset += uint32_t_size;
191 uint64_t readProfilingGuid = ReadUint64(packetBuffer, offset);
192
193 BOOST_CHECK(readProfilingGuid == entityBinaryPacketProfilingGuid);
194
195 // Reading TimelineEventClassBinaryPacket
196 offset += uint64_t_size;
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100197
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100198 uint32_t eventClassDeclId = ReadUint32(packetBuffer, offset);
199 BOOST_CHECK(eventClassDeclId == uint32_t(2));
200
201 // Check the profiling GUID
202 offset += uint32_t_size;
203 readProfilingGuid = ReadUint64(packetBuffer, offset);
204 BOOST_CHECK(readProfilingGuid == eventClassBinaryPacketProfilingGuid);
205
206 bufferManager.MarkRead(packetBuffer);
207}
208
Keith Davis97da5e22020-03-05 16:25:28 +0000209BOOST_AUTO_TEST_CASE(SendEventClassAfterTimelineEntityPacketTest)
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100210{
211 unsigned int uint32_t_size = sizeof(uint32_t);
212 unsigned int uint64_t_size = sizeof(uint64_t);
213
214 MockBufferManager bufferManager(512);
215 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
216 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
217
218 // Send TimelineEntityClassBinaryPacket
219 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
220 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
221
222 // Commit the buffer
223 sendTimelinePacket->Commit();
224
225 // Get the readable buffer
226 auto packetBuffer = bufferManager.GetReadableBuffer();
227
228 // Check the packet header
229 unsigned int offset = 0;
230
231 // Reading TimelineEntityClassBinaryPacket
232 uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
233 uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
234 uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
235 uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007;
236 uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007;
237
238 BOOST_CHECK(entityBinaryPacketFamily == 1);
239 BOOST_CHECK(entityBinaryPacketClass == 0);
240 BOOST_CHECK(entityBinaryPacketType == 1);
241 BOOST_CHECK(entityBinaryPacketStreamId == 0);
242
243 offset += uint32_t_size;
244 uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
245 uint32_t entityBinaryPacketSequenceNumbered = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001;
246 uint32_t entityBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
247 BOOST_CHECK(entityBinaryPacketSequenceNumbered == 0);
Finn Williamse63a0262019-10-22 10:30:49 +0100248 BOOST_CHECK(entityBinaryPacketDataLength == 12);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100249
250 // Check the decl_id
251 offset += uint32_t_size;
252 uint32_t entitytDecId = ReadUint32(packetBuffer, offset);
253
254 BOOST_CHECK(entitytDecId == uint32_t(1));
255
256 // Check the profiling GUID
257 offset += uint32_t_size;
258 uint64_t readProfilingGuid = ReadUint64(packetBuffer, offset);
259
260 BOOST_CHECK(readProfilingGuid == entityBinaryPacketProfilingGuid);
261
262 bufferManager.MarkRead(packetBuffer);
263
264 // Send TimelineEventClassBinaryPacket
265 const uint64_t eventClassBinaryPacketProfilingGuid = 789123u;
266 sendTimelinePacket->SendTimelineEventClassBinaryPacket(eventClassBinaryPacketProfilingGuid);
267
268 // Commit the buffer
269 sendTimelinePacket->Commit();
270
271 // Get the readable buffer
272 packetBuffer = bufferManager.GetReadableBuffer();
273
274 // Check the packet header
275 offset = 0;
276
277 // Reading TimelineEventClassBinaryPacket
278 uint32_t eventClassBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
279 uint32_t eventClassBinaryPacketFamily = (eventClassBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
280 uint32_t eventClassBinaryPacketClass = (eventClassBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
281 uint32_t eventClassBinaryPacketType = (eventClassBinaryPacketHeaderWord0 >> 16) & 0x00000007;
282 uint32_t eventClassBinaryPacketStreamId = (eventClassBinaryPacketHeaderWord0 >> 0) & 0x00000007;
283
284 BOOST_CHECK(eventClassBinaryPacketFamily == 1);
285 BOOST_CHECK(eventClassBinaryPacketClass == 0);
286 BOOST_CHECK(eventClassBinaryPacketType == 1);
287 BOOST_CHECK(eventClassBinaryPacketStreamId == 0);
288
289 offset += uint32_t_size;
290 uint32_t eventClassBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
291 uint32_t eventClassBinaryPacketSequenceNumbered = (eventClassBinaryPacketHeaderWord1 >> 24) & 0x00000001;
292 uint32_t eventClassBinaryPacketDataLength = (eventClassBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
293 BOOST_CHECK(eventClassBinaryPacketSequenceNumbered == 0);
294 BOOST_CHECK(eventClassBinaryPacketDataLength == 12);
295
296 offset += uint32_t_size;
297 uint32_t eventClassDeclId = ReadUint32(packetBuffer, offset);
298 BOOST_CHECK(eventClassDeclId == uint32_t(2));
299
300 // Check the profiling GUID
301 offset += uint32_t_size;
302 readProfilingGuid = ReadUint64(packetBuffer, offset);
303 BOOST_CHECK(readProfilingGuid == eventClassBinaryPacketProfilingGuid);
304
305 bufferManager.MarkRead(packetBuffer);
306
307 // Send TimelineEventBinaryPacket
308 const uint64_t timestamp = 456789u;
Matteo Martincigh378bbfc2019-11-04 14:05:28 +0000309 const std::thread::id threadId = std::this_thread::get_id();
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100310 const uint64_t eventProfilingGuid = 123456u;
311 sendTimelinePacket->SendTimelineEventBinaryPacket(timestamp, threadId, eventProfilingGuid);
312
313 // Commit the buffer
314 sendTimelinePacket->Commit();
315
316 // Get the readable buffer
317 packetBuffer = bufferManager.GetReadableBuffer();
318
319 // Check the packet header
320 offset = 0;
321
322 // Reading TimelineEventBinaryPacket
323 uint32_t eventBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
324 uint32_t eventBinaryPacketFamily = (eventBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
325 uint32_t eventBinaryPacketClass = (eventBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
326 uint32_t eventBinaryPacketType = (eventBinaryPacketHeaderWord0 >> 16) & 0x00000007;
327 uint32_t eventBinaryPacketStreamId = (eventBinaryPacketHeaderWord0 >> 0) & 0x00000007;
328
329 BOOST_CHECK(eventBinaryPacketFamily == 1);
330 BOOST_CHECK(eventBinaryPacketClass == 0);
331 BOOST_CHECK(eventBinaryPacketType == 1);
332 BOOST_CHECK(eventBinaryPacketStreamId == 0);
333
334 offset += uint32_t_size;
335 uint32_t eventBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
336 uint32_t eventBinaryPacketSequenceNumbered = (eventBinaryPacketHeaderWord1 >> 24) & 0x00000001;
337 uint32_t eventBinaryPacketDataLength = (eventBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
338 BOOST_CHECK(eventBinaryPacketSequenceNumbered == 0);
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100339 BOOST_CHECK(eventBinaryPacketDataLength == 20 + ThreadIdSize);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100340
341 // Check the decl_id
342 offset += uint32_t_size;
343 uint32_t eventDeclId = ReadUint32(packetBuffer, offset);
344 BOOST_CHECK(eventDeclId == 4);
345
346 // Check the timestamp
347 offset += uint32_t_size;
348 uint64_t eventTimestamp = ReadUint64(packetBuffer, offset);
349 BOOST_CHECK(eventTimestamp == timestamp);
350
351 // Check the thread id
352 offset += uint64_t_size;
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100353 std::vector<uint8_t> readThreadId(ThreadIdSize, 0);
354 ReadBytes(packetBuffer, offset, ThreadIdSize, readThreadId.data());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100355 BOOST_CHECK(readThreadId == threadId);
356
357 // Check the profiling GUID
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100358 offset += ThreadIdSize;
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100359 readProfilingGuid = ReadUint64(packetBuffer, offset);
360 BOOST_CHECK(readProfilingGuid == eventProfilingGuid);
361}
362
363BOOST_AUTO_TEST_CASE(SendTimelinePacketTests2)
364{
365 MockBufferManager bufferManager(40);
366 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
367 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
368
369 BOOST_CHECK_THROW(sendTimelinePacket->SendTimelineMessageDirectoryPackage(),
370 armnn::RuntimeException);
371}
372
373BOOST_AUTO_TEST_CASE(SendTimelinePacketTests3)
374{
375 MockBufferManager bufferManager(512);
376 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
377 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
378
379 // Send TimelineEntityClassBinaryPacket
380 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
381 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
382
383 // Commit the buffer
384 sendTimelinePacket->Commit();
385
386 // Get the readable buffer
387 auto packetBuffer = bufferManager.GetReadableBuffer();
388
389 // Send TimelineEventClassBinaryPacket
390 const uint64_t eventClassBinaryPacketProfilingGuid = 789123u;
391 BOOST_CHECK_THROW(sendTimelinePacket->SendTimelineEventClassBinaryPacket(eventClassBinaryPacketProfilingGuid),
392 armnn::RuntimeException);
393}
394
Jim Flynn00f3aaf2019-10-24 11:58:06 +0100395BOOST_AUTO_TEST_CASE(GetGuidsFromProfilingService)
396{
Keith Davis33ed2212020-03-30 10:43:41 +0100397 armnn::IRuntime::CreationOptions options;
398 options.m_ProfilingOptions.m_EnableProfiling = true;
399 armnn::Runtime runtime(options);
400 armnn::profiling::ProfilingService profilingService(runtime);
401
402 profilingService.ResetExternalProfilingOptions(options.m_ProfilingOptions, true);
Sadik Armagan3184c902020-03-18 10:57:30 +0000403 ProfilingStaticGuid staticGuid = profilingService.GetStaticId("dummy");
Jim Flynnab845752019-10-25 13:17:30 +0100404 std::hash<std::string> hasher;
405 uint64_t hash = static_cast<uint64_t>(hasher("dummy"));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000406 ProfilingStaticGuid expectedStaticValue(hash | MIN_STATIC_GUID);
Jim Flynn00f3aaf2019-10-24 11:58:06 +0100407 BOOST_CHECK(staticGuid == expectedStaticValue);
Sadik Armagan3184c902020-03-18 10:57:30 +0000408 ProfilingDynamicGuid dynamicGuid = profilingService.GetNextGuid();
Jim Flynnab845752019-10-25 13:17:30 +0100409 uint64_t dynamicGuidValue = static_cast<uint64_t>(dynamicGuid);
410 ++dynamicGuidValue;
411 ProfilingDynamicGuid expectedDynamicValue(dynamicGuidValue);
Sadik Armagan3184c902020-03-18 10:57:30 +0000412 dynamicGuid = profilingService.GetNextGuid();
Jim Flynn00f3aaf2019-10-24 11:58:06 +0100413 BOOST_CHECK(dynamicGuid == expectedDynamicValue);
414}
415
Jim Flynn8b200652019-10-24 18:07:44 +0100416BOOST_AUTO_TEST_CASE(GetTimelinePackerWriterFromProfilingService)
417{
Narumol Prangnawarat85ad78c2019-11-18 15:34:23 +0000418 armnn::IRuntime::CreationOptions::ExternalProfilingOptions options;
Jim Flynn8b200652019-10-24 18:07:44 +0100419 options.m_EnableProfiling = true;
Sadik Armagan3184c902020-03-18 10:57:30 +0000420 armnn::profiling::ProfilingService profilingService;
Jim Flynn8b200652019-10-24 18:07:44 +0100421 profilingService.ResetExternalProfilingOptions(options, true);
422
423 std::unique_ptr<ISendTimelinePacket> writer = profilingService.GetSendTimelinePacket();
424 BOOST_CHECK(writer != nullptr);
425}
426
Jim Flynnab845752019-10-25 13:17:30 +0100427BOOST_AUTO_TEST_CASE(CheckStaticGuidsAndEvents)
428{
429 BOOST_CHECK("name" == LabelsAndEventClasses::NAME_LABEL);
430 BOOST_CHECK("type" == LabelsAndEventClasses::TYPE_LABEL);
431 BOOST_CHECK("index" == LabelsAndEventClasses::INDEX_LABEL);
432
433 std::hash<std::string> hasher;
434
435 uint64_t hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::NAME_LABEL));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000436 ProfilingStaticGuid expectedNameGuid(hash | MIN_STATIC_GUID);
Jim Flynnab845752019-10-25 13:17:30 +0100437 BOOST_CHECK(LabelsAndEventClasses::NAME_GUID == expectedNameGuid);
438
439 hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::TYPE_LABEL));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000440 ProfilingStaticGuid expectedTypeGuid(hash | MIN_STATIC_GUID);
Jim Flynnab845752019-10-25 13:17:30 +0100441 BOOST_CHECK(LabelsAndEventClasses::TYPE_GUID == expectedTypeGuid);
442
443 hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::INDEX_LABEL));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000444 ProfilingStaticGuid expectedIndexGuid(hash | MIN_STATIC_GUID);
Jim Flynnab845752019-10-25 13:17:30 +0100445 BOOST_CHECK(LabelsAndEventClasses::INDEX_GUID == expectedIndexGuid);
446
447 hash = static_cast<uint64_t>(hasher("ARMNN_PROFILING_SOL"));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000448 ProfilingStaticGuid expectedSol(hash | MIN_STATIC_GUID);
Jim Flynnab845752019-10-25 13:17:30 +0100449 BOOST_CHECK(LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS == expectedSol);
450
451 hash = static_cast<uint64_t>(hasher("ARMNN_PROFILING_EOL"));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000452 ProfilingStaticGuid expectedEol(hash | MIN_STATIC_GUID);
Jim Flynnab845752019-10-25 13:17:30 +0100453 BOOST_CHECK(LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS == expectedEol);
454}
455
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100456BOOST_AUTO_TEST_SUITE_END()