blob: 2e64c75b902c51f468f4cb9c13b2d7d1f88f8a4d [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>
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010018
19using namespace armnn::profiling;
20
21BOOST_AUTO_TEST_SUITE(SendTimelinePacketTests)
22
23BOOST_AUTO_TEST_CASE(SendTimelineMessageDirectoryPackageTest)
24{
25 MockBufferManager mockBuffer(512);
26 TimelinePacketWriterFactory timelinePacketWriterFactory(mockBuffer);
27 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
28
29 sendTimelinePacket->SendTimelineMessageDirectoryPackage();
30
31 // Get the readable buffer
32 auto packetBuffer = mockBuffer.GetReadableBuffer();
33
Matteo Martincigh34a407d2019-11-06 15:30:54 +000034 unsigned int uint8_t_size = sizeof(uint8_t);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010035 unsigned int uint32_t_size = sizeof(uint32_t);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000036 unsigned int uint64_t_size = sizeof(uint64_t);
37 unsigned int threadId_size = sizeof(std::thread::id);
38
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);
67 BOOST_CHECK(readThreadIdBytes == threadId_size);
68
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);
Matteo Martincigh378bbfc2019-11-04 14:05:28 +0000213 unsigned int threadId_size = sizeof(std::thread::id);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100214
215 MockBufferManager bufferManager(512);
216 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
217 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
218
219 // Send TimelineEntityClassBinaryPacket
220 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
221 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
222
223 // Commit the buffer
224 sendTimelinePacket->Commit();
225
226 // Get the readable buffer
227 auto packetBuffer = bufferManager.GetReadableBuffer();
228
229 // Check the packet header
230 unsigned int offset = 0;
231
232 // Reading TimelineEntityClassBinaryPacket
233 uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
234 uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
235 uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
236 uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007;
237 uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007;
238
239 BOOST_CHECK(entityBinaryPacketFamily == 1);
240 BOOST_CHECK(entityBinaryPacketClass == 0);
241 BOOST_CHECK(entityBinaryPacketType == 1);
242 BOOST_CHECK(entityBinaryPacketStreamId == 0);
243
244 offset += uint32_t_size;
245 uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
246 uint32_t entityBinaryPacketSequenceNumbered = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001;
247 uint32_t entityBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
248 BOOST_CHECK(entityBinaryPacketSequenceNumbered == 0);
Finn Williamse63a0262019-10-22 10:30:49 +0100249 BOOST_CHECK(entityBinaryPacketDataLength == 12);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100250
251 // Check the decl_id
252 offset += uint32_t_size;
253 uint32_t entitytDecId = ReadUint32(packetBuffer, offset);
254
255 BOOST_CHECK(entitytDecId == uint32_t(1));
256
257 // Check the profiling GUID
258 offset += uint32_t_size;
259 uint64_t readProfilingGuid = ReadUint64(packetBuffer, offset);
260
261 BOOST_CHECK(readProfilingGuid == entityBinaryPacketProfilingGuid);
262
263 bufferManager.MarkRead(packetBuffer);
264
265 // Send TimelineEventClassBinaryPacket
266 const uint64_t eventClassBinaryPacketProfilingGuid = 789123u;
267 sendTimelinePacket->SendTimelineEventClassBinaryPacket(eventClassBinaryPacketProfilingGuid);
268
269 // Commit the buffer
270 sendTimelinePacket->Commit();
271
272 // Get the readable buffer
273 packetBuffer = bufferManager.GetReadableBuffer();
274
275 // Check the packet header
276 offset = 0;
277
278 // Reading TimelineEventClassBinaryPacket
279 uint32_t eventClassBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
280 uint32_t eventClassBinaryPacketFamily = (eventClassBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
281 uint32_t eventClassBinaryPacketClass = (eventClassBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
282 uint32_t eventClassBinaryPacketType = (eventClassBinaryPacketHeaderWord0 >> 16) & 0x00000007;
283 uint32_t eventClassBinaryPacketStreamId = (eventClassBinaryPacketHeaderWord0 >> 0) & 0x00000007;
284
285 BOOST_CHECK(eventClassBinaryPacketFamily == 1);
286 BOOST_CHECK(eventClassBinaryPacketClass == 0);
287 BOOST_CHECK(eventClassBinaryPacketType == 1);
288 BOOST_CHECK(eventClassBinaryPacketStreamId == 0);
289
290 offset += uint32_t_size;
291 uint32_t eventClassBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
292 uint32_t eventClassBinaryPacketSequenceNumbered = (eventClassBinaryPacketHeaderWord1 >> 24) & 0x00000001;
293 uint32_t eventClassBinaryPacketDataLength = (eventClassBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
294 BOOST_CHECK(eventClassBinaryPacketSequenceNumbered == 0);
295 BOOST_CHECK(eventClassBinaryPacketDataLength == 12);
296
297 offset += uint32_t_size;
298 uint32_t eventClassDeclId = ReadUint32(packetBuffer, offset);
299 BOOST_CHECK(eventClassDeclId == uint32_t(2));
300
301 // Check the profiling GUID
302 offset += uint32_t_size;
303 readProfilingGuid = ReadUint64(packetBuffer, offset);
304 BOOST_CHECK(readProfilingGuid == eventClassBinaryPacketProfilingGuid);
305
306 bufferManager.MarkRead(packetBuffer);
307
308 // Send TimelineEventBinaryPacket
309 const uint64_t timestamp = 456789u;
Matteo Martincigh378bbfc2019-11-04 14:05:28 +0000310 const std::thread::id threadId = std::this_thread::get_id();
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100311 const uint64_t eventProfilingGuid = 123456u;
312 sendTimelinePacket->SendTimelineEventBinaryPacket(timestamp, threadId, eventProfilingGuid);
313
314 // Commit the buffer
315 sendTimelinePacket->Commit();
316
317 // Get the readable buffer
318 packetBuffer = bufferManager.GetReadableBuffer();
319
320 // Check the packet header
321 offset = 0;
322
323 // Reading TimelineEventBinaryPacket
324 uint32_t eventBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
325 uint32_t eventBinaryPacketFamily = (eventBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
326 uint32_t eventBinaryPacketClass = (eventBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
327 uint32_t eventBinaryPacketType = (eventBinaryPacketHeaderWord0 >> 16) & 0x00000007;
328 uint32_t eventBinaryPacketStreamId = (eventBinaryPacketHeaderWord0 >> 0) & 0x00000007;
329
330 BOOST_CHECK(eventBinaryPacketFamily == 1);
331 BOOST_CHECK(eventBinaryPacketClass == 0);
332 BOOST_CHECK(eventBinaryPacketType == 1);
333 BOOST_CHECK(eventBinaryPacketStreamId == 0);
334
335 offset += uint32_t_size;
336 uint32_t eventBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
337 uint32_t eventBinaryPacketSequenceNumbered = (eventBinaryPacketHeaderWord1 >> 24) & 0x00000001;
338 uint32_t eventBinaryPacketDataLength = (eventBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
339 BOOST_CHECK(eventBinaryPacketSequenceNumbered == 0);
Matteo Martincigh378bbfc2019-11-04 14:05:28 +0000340 BOOST_CHECK(eventBinaryPacketDataLength == 28);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100341
342 // Check the decl_id
343 offset += uint32_t_size;
344 uint32_t eventDeclId = ReadUint32(packetBuffer, offset);
345 BOOST_CHECK(eventDeclId == 4);
346
347 // Check the timestamp
348 offset += uint32_t_size;
349 uint64_t eventTimestamp = ReadUint64(packetBuffer, offset);
350 BOOST_CHECK(eventTimestamp == timestamp);
351
352 // Check the thread id
353 offset += uint64_t_size;
Matteo Martincigh378bbfc2019-11-04 14:05:28 +0000354 std::vector<uint8_t> readThreadId(threadId_size, 0);
355 ReadBytes(packetBuffer, offset, threadId_size, readThreadId.data());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100356 BOOST_CHECK(readThreadId == threadId);
357
358 // Check the profiling GUID
Matteo Martincigh378bbfc2019-11-04 14:05:28 +0000359 offset += threadId_size;
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100360 readProfilingGuid = ReadUint64(packetBuffer, offset);
361 BOOST_CHECK(readProfilingGuid == eventProfilingGuid);
362}
363
364BOOST_AUTO_TEST_CASE(SendTimelinePacketTests2)
365{
366 MockBufferManager bufferManager(40);
367 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
368 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
369
370 BOOST_CHECK_THROW(sendTimelinePacket->SendTimelineMessageDirectoryPackage(),
371 armnn::RuntimeException);
372}
373
374BOOST_AUTO_TEST_CASE(SendTimelinePacketTests3)
375{
376 MockBufferManager bufferManager(512);
377 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
378 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
379
380 // Send TimelineEntityClassBinaryPacket
381 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
382 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
383
384 // Commit the buffer
385 sendTimelinePacket->Commit();
386
387 // Get the readable buffer
388 auto packetBuffer = bufferManager.GetReadableBuffer();
389
390 // Send TimelineEventClassBinaryPacket
391 const uint64_t eventClassBinaryPacketProfilingGuid = 789123u;
392 BOOST_CHECK_THROW(sendTimelinePacket->SendTimelineEventClassBinaryPacket(eventClassBinaryPacketProfilingGuid),
393 armnn::RuntimeException);
394}
395
Jim Flynn00f3aaf2019-10-24 11:58:06 +0100396BOOST_AUTO_TEST_CASE(GetGuidsFromProfilingService)
397{
Narumol Prangnawarat85ad78c2019-11-18 15:34:23 +0000398 armnn::IRuntime::CreationOptions::ExternalProfilingOptions options;
Jim Flynn00f3aaf2019-10-24 11:58:06 +0100399 options.m_EnableProfiling = true;
400 ProfilingService& profilingService = ProfilingService::Instance();
401 profilingService.ResetExternalProfilingOptions(options, true);
402 ProfilingStaticGuid staticGuid = profilingService.GenerateStaticId("dummy");
Jim Flynnab845752019-10-25 13:17:30 +0100403 std::hash<std::string> hasher;
404 uint64_t hash = static_cast<uint64_t>(hasher("dummy"));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000405 ProfilingStaticGuid expectedStaticValue(hash | MIN_STATIC_GUID);
Jim Flynn00f3aaf2019-10-24 11:58:06 +0100406 BOOST_CHECK(staticGuid == expectedStaticValue);
407 ProfilingDynamicGuid dynamicGuid = profilingService.NextGuid();
Jim Flynnab845752019-10-25 13:17:30 +0100408 uint64_t dynamicGuidValue = static_cast<uint64_t>(dynamicGuid);
409 ++dynamicGuidValue;
410 ProfilingDynamicGuid expectedDynamicValue(dynamicGuidValue);
411 dynamicGuid = profilingService.NextGuid();
Jim Flynn00f3aaf2019-10-24 11:58:06 +0100412 BOOST_CHECK(dynamicGuid == expectedDynamicValue);
413}
414
Jim Flynn8b200652019-10-24 18:07:44 +0100415BOOST_AUTO_TEST_CASE(GetTimelinePackerWriterFromProfilingService)
416{
Narumol Prangnawarat85ad78c2019-11-18 15:34:23 +0000417 armnn::IRuntime::CreationOptions::ExternalProfilingOptions options;
Jim Flynn8b200652019-10-24 18:07:44 +0100418 options.m_EnableProfiling = true;
419 ProfilingService& profilingService = ProfilingService::Instance();
420 profilingService.ResetExternalProfilingOptions(options, true);
421
422 std::unique_ptr<ISendTimelinePacket> writer = profilingService.GetSendTimelinePacket();
423 BOOST_CHECK(writer != nullptr);
424}
425
Jim Flynnab845752019-10-25 13:17:30 +0100426BOOST_AUTO_TEST_CASE(CheckStaticGuidsAndEvents)
427{
428 BOOST_CHECK("name" == LabelsAndEventClasses::NAME_LABEL);
429 BOOST_CHECK("type" == LabelsAndEventClasses::TYPE_LABEL);
430 BOOST_CHECK("index" == LabelsAndEventClasses::INDEX_LABEL);
431
432 std::hash<std::string> hasher;
433
434 uint64_t hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::NAME_LABEL));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000435 ProfilingStaticGuid expectedNameGuid(hash | MIN_STATIC_GUID);
Jim Flynnab845752019-10-25 13:17:30 +0100436 BOOST_CHECK(LabelsAndEventClasses::NAME_GUID == expectedNameGuid);
437
438 hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::TYPE_LABEL));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000439 ProfilingStaticGuid expectedTypeGuid(hash | MIN_STATIC_GUID);
Jim Flynnab845752019-10-25 13:17:30 +0100440 BOOST_CHECK(LabelsAndEventClasses::TYPE_GUID == expectedTypeGuid);
441
442 hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::INDEX_LABEL));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000443 ProfilingStaticGuid expectedIndexGuid(hash | MIN_STATIC_GUID);
Jim Flynnab845752019-10-25 13:17:30 +0100444 BOOST_CHECK(LabelsAndEventClasses::INDEX_GUID == expectedIndexGuid);
445
446 hash = static_cast<uint64_t>(hasher("ARMNN_PROFILING_SOL"));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000447 ProfilingStaticGuid expectedSol(hash | MIN_STATIC_GUID);
Jim Flynnab845752019-10-25 13:17:30 +0100448 BOOST_CHECK(LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS == expectedSol);
449
450 hash = static_cast<uint64_t>(hasher("ARMNN_PROFILING_EOL"));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000451 ProfilingStaticGuid expectedEol(hash | MIN_STATIC_GUID);
Jim Flynnab845752019-10-25 13:17:30 +0100452 BOOST_CHECK(LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS == expectedEol);
453}
454
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100455BOOST_AUTO_TEST_SUITE_END()