ArmNN
 21.02
TimelineUtilityMethodsTests.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "ProfilingMocks.hpp"
7 #include "ProfilingTestUtils.hpp"
8 
9 #include <SendTimelinePacket.hpp>
12 #include <ProfilingService.hpp>
13 
14 #include <memory>
15 
16 #include <boost/test/unit_test.hpp>
17 
18 using namespace armnn;
19 using namespace armnn::profiling;
20 
21 BOOST_AUTO_TEST_SUITE(TimelineUtilityMethodsTests)
22 
23 BOOST_AUTO_TEST_CASE(CreateTypedLabelTest)
24 {
25  MockBufferManager mockBufferManager(1024);
26  ProfilingService profilingService;
27 
28  std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager);
29  TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket);
30 
31  // Generate first guid to ensure that the named typed entity guid is not 0 on local single test.
32  profilingService.NextGuid();
33 
34  ProfilingGuid entityGuid(123);
35  const std::string entityName = "some entity";
36  ProfilingStaticGuid labelTypeGuid(456);
37 
38  BOOST_CHECK_NO_THROW(timelineUtilityMethods.MarkEntityWithLabel(entityGuid, entityName, labelTypeGuid));
39 
40  // Commit all packets at once
41  timelineUtilityMethods.Commit();
42 
43  // Get the readable buffer
44  auto readableBuffer = mockBufferManager.GetReadableBuffer();
45  BOOST_CHECK(readableBuffer != nullptr);
46  unsigned int size = readableBuffer->GetSize();
47  BOOST_CHECK(size == 76);
48  const unsigned char* readableData = readableBuffer->GetReadableData();
49  BOOST_CHECK(readableData != nullptr);
50 
51  // Utils
52  unsigned int offset = 0;
53 
54  // Verify Header
55  VerifyTimelineHeaderBinary(readableData, offset, 68);
56 
57  // First dataset sent: TimelineLabelBinaryPacket
58  VerifyTimelineLabelBinaryPacketData(EmptyOptional(), entityName, readableData, offset);
59 
60  // Second dataset sent: TimelineRelationshipBinaryPacket
62  EmptyOptional(),
63  entityGuid,
64  EmptyOptional(),
65  labelTypeGuid,
66  readableData,
67  offset);
68 
69  // Mark the buffer as read
70  mockBufferManager.MarkRead(readableBuffer);
71 }
72 
73 BOOST_AUTO_TEST_CASE(SendWellKnownLabelsAndEventClassesTest)
74 {
75  MockBufferManager mockBufferManager(1024);
76  ProfilingService profilingService;
77  SendTimelinePacket sendTimelinePacket(mockBufferManager);
78 
79  BOOST_CHECK_NO_THROW(TimelineUtilityMethods::SendWellKnownLabelsAndEventClasses(sendTimelinePacket));
80 
81  // Get the readable buffer
82  auto readableBuffer = mockBufferManager.GetReadableBuffer();
83  BOOST_CHECK(readableBuffer != nullptr);
84  unsigned int size = readableBuffer->GetSize();
85  BOOST_TEST(size == 460);
86  const unsigned char* readableData = readableBuffer->GetReadableData();
87  BOOST_CHECK(readableData != nullptr);
88 
89  // Utils
90  unsigned int offset = 0;
91 
92  // Verify Header
93  VerifyTimelineHeaderBinary(readableData, offset, 452);
94 
95  // First "well-known" label: NAME
98  readableData,
99  offset);
100 
101  // Second "well-known" label: TYPE
104  readableData,
105  offset);
106 
107  // Third "well-known" label: INDEX
110  readableData,
111  offset);
112 
113  // Forth "well-known" label: BACKENDID
116  readableData,
117  offset);
118 
119  // Fifth "well-known" label: CHILD
122  readableData,
123  offset);
124 
125  // Sixth "well-known" label: EXECUTION_OF
128  readableData,
129  offset);
130 
131  // Seventh "well-known" label: PROCESS_ID_LABEL
134  readableData,
135  offset);
136 
137  // Well-known types
138  // Layer
141  readableData,
142  offset);
143 
144  // Workload
147  readableData,
148  offset);
149 
150  // Network
153  readableData,
154  offset);
155 
156  // Connection
159  readableData,
160  offset);
161 
162  // Inference
165  readableData,
166  offset);
167 
168  // Workload Execution
171  readableData,
172  offset);
173 
174  // First "well-known" event class: START OF LIFE
177  readableData,
178  offset);
179 
182  readableData,
183  offset);
184 
185  // Second "well-known" event class: END OF LIFE
188  readableData,
189  offset);
190 
193  readableData,
194  offset);
195 
196  // Mark the buffer as read
197  mockBufferManager.MarkRead(readableBuffer);
198 }
199 
200 BOOST_AUTO_TEST_CASE(CreateNamedTypedChildEntityTest)
201 {
202  MockBufferManager mockBufferManager(1024);
203  ProfilingService profilingService;
204  std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager);
205  TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket);
206 
207  ProfilingDynamicGuid childEntityGuid(0);
208  ProfilingGuid parentEntityGuid(123);
209  const std::string entityName = "some entity";
210  const std::string entityType = "some type";
211 
212  // Generate first guid to ensure that the named typed entity guid is not 0 on local single test.
213  profilingService.NextGuid();
214 
215  BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedChildEntity(parentEntityGuid, "", entityType),
217  BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedChildEntity(parentEntityGuid, entityName, ""),
219  BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedChildEntity(
220  childEntityGuid, parentEntityGuid, "", entityType), InvalidArgumentException);
221  BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedChildEntity(
222  childEntityGuid, parentEntityGuid, entityName, ""), InvalidArgumentException);
223 
224  BOOST_CHECK_NO_THROW(childEntityGuid = timelineUtilityMethods.CreateNamedTypedChildEntity(parentEntityGuid,
225  entityName,
226  entityType));
227  BOOST_CHECK(childEntityGuid != ProfilingGuid(0));
228 
229  // Commit all packets at once
230  timelineUtilityMethods.Commit();
231 
232  // Get the readable buffer
233  auto readableBuffer = mockBufferManager.GetReadableBuffer();
234  BOOST_CHECK(readableBuffer != nullptr);
235  unsigned int size = readableBuffer->GetSize();
236  BOOST_CHECK(size == 196);
237  const unsigned char* readableData = readableBuffer->GetReadableData();
238  BOOST_CHECK(readableData != nullptr);
239 
240  // Utils
241  unsigned int offset = 0;
242 
243  // Verify Header
244  VerifyTimelineHeaderBinary(readableData, offset, 188);
245 
246  // First dataset sent: TimelineEntityBinaryPacket
247  VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
248 
249  // Second dataset sent: TimelineLabelBinaryPacket
250  VerifyTimelineLabelBinaryPacketData(EmptyOptional(), entityName, readableData, offset);
251 
252  // Third dataset sent: TimelineRelationshipBinaryPacket
254  EmptyOptional(),
255  EmptyOptional(),
256  EmptyOptional(),
258  readableData,
259  offset);
260 
261  // Fifth dataset sent: TimelineLabelBinaryPacket
262  VerifyTimelineLabelBinaryPacketData(EmptyOptional(), entityType, readableData, offset);
263 
264  // Sixth dataset sent: TimelineRelationshipBinaryPacket
266  EmptyOptional(),
267  EmptyOptional(),
268  EmptyOptional(),
270  readableData,
271  offset);
272 
273 
274  // Eighth dataset sent: TimelineRelationshipBinaryPacket
276  EmptyOptional(),
277  parentEntityGuid,
278  EmptyOptional(),
279  EmptyOptional(),
280  readableData,
281  offset);
282 
283  // Mark the buffer as read
284  mockBufferManager.MarkRead(readableBuffer);
285 }
286 
287 BOOST_AUTO_TEST_CASE(DeclareLabelTest)
288 {
289  MockBufferManager mockBufferManager(1024);
290  ProfilingService profilingService;
291  std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager);
292  TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket);
293 
294  // Generate first guid to ensure that the named typed entity guid is not 0 on local single test.
295  profilingService.NextGuid();
296 
297  // Try declaring an invalid (empty) label
298  BOOST_CHECK_THROW(timelineUtilityMethods.DeclareLabel(""), InvalidArgumentException);
299 
300  // Try declaring an invalid (wrong SWTrace format) label
301  BOOST_CHECK_THROW(timelineUtilityMethods.DeclareLabel("inv@lid lab€l"), RuntimeException);
302 
303  // Declare a valid label
304  const std::string labelName = "valid label";
305  ProfilingGuid labelGuid = 0;
306  BOOST_CHECK_NO_THROW(labelGuid = timelineUtilityMethods.DeclareLabel(labelName));
307  BOOST_CHECK(labelGuid != ProfilingGuid(0));
308 
309  // Try adding the same label as before
310  ProfilingGuid newLabelGuid = 0;
311  BOOST_CHECK_NO_THROW(newLabelGuid = timelineUtilityMethods.DeclareLabel(labelName));
312  BOOST_CHECK(newLabelGuid != ProfilingGuid(0));
313  BOOST_CHECK(newLabelGuid == labelGuid);
314 }
315 
316 BOOST_AUTO_TEST_CASE(CreateNameTypeEntityInvalidTest)
317 {
318  MockBufferManager mockBufferManager(1024);
319  ProfilingService profilingService;
320  std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager);
321  TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket);
322 
323  // Invalid name
324  BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedEntity("", "Type"), InvalidArgumentException);
325 
326  // Invalid type
327  BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedEntity("Name", ""), InvalidArgumentException);
328 
329  ProfilingDynamicGuid guid = profilingService.NextGuid();
330 
331  // CreatedNamedTypedEntity with Guid - Invalid name
332  BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedEntity(guid, "", "Type"),
334 
335  // CreatedNamedTypedEntity with Guid - Invalid type
336  BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedEntity(guid, "Name", ""),
338 
339 }
340 
341 BOOST_AUTO_TEST_CASE(CreateNameTypeEntityTest)
342 {
343  MockBufferManager mockBufferManager(1024);
344  ProfilingService profilingService;
345  std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager);
346  TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket);
347 
348  const std::string entityName = "Entity0";
349  const std::string entityType = "Type0";
350 
351  // Generate first guid to ensure that the named typed entity guid is not 0 on local single test.
352  profilingService.NextGuid();
353 
354  ProfilingDynamicGuid guid = timelineUtilityMethods.CreateNamedTypedEntity(entityName, entityType);
355  BOOST_CHECK(guid != ProfilingGuid(0));
356 
357  // Commit all packets at once
358  timelineUtilityMethods.Commit();
359 
360  // Get the readable buffer
361  auto readableBuffer = mockBufferManager.GetReadableBuffer();
362  BOOST_CHECK(readableBuffer != nullptr);
363  unsigned int size = readableBuffer->GetSize();
364  BOOST_CHECK(size == 148);
365  const unsigned char* readableData = readableBuffer->GetReadableData();
366  BOOST_CHECK(readableData != nullptr);
367 
368  // Utils
369  unsigned int offset = 0;
370 
371  // Verify Header
372  VerifyTimelineHeaderBinary(readableData, offset, 140);
373 
374  // First dataset sent: TimelineEntityBinaryPacket
375  VerifyTimelineEntityBinaryPacketData(guid, readableData, offset);
376 
377  // Packets for Name Entity
378  // First dataset sent: TimelineLabelBinaryPacket
379  VerifyTimelineLabelBinaryPacketData(EmptyOptional(), entityName, readableData, offset);
380 
381  // Second dataset sent: TimelineRelationshipBinaryPacket
383  EmptyOptional(),
384  EmptyOptional(),
385  EmptyOptional(),
387  readableData,
388  offset);
389 
390  // Packets for Type Entity
391  // First dataset sent: TimelineLabelBinaryPacket
392  VerifyTimelineLabelBinaryPacketData(EmptyOptional(), entityType, readableData, offset);
393 
394  // Second dataset sent: TimelineRelationshipBinaryPacket
396  EmptyOptional(),
397  EmptyOptional(),
398  EmptyOptional(),
400  readableData,
401  offset);
402 
403 
404  // Mark the buffer as read
405  mockBufferManager.MarkRead(readableBuffer);
406 }
407 
408 BOOST_AUTO_TEST_CASE(RecordEventTest)
409 {
410  MockBufferManager mockBufferManager(1024);
411  ProfilingService profilingService;
412  std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager);
413  TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket);
414  // Generate first guid to ensure that the named typed entity guid is not 0 on local single test.
415  profilingService.NextGuid();
416 
417  ProfilingGuid entityGuid(123);
418  ProfilingStaticGuid eventClassGuid(456);
419  ProfilingDynamicGuid eventGuid(0);
420  BOOST_CHECK_NO_THROW(eventGuid = timelineUtilityMethods.RecordEvent(entityGuid, eventClassGuid));
421  BOOST_CHECK(eventGuid != ProfilingGuid(0));
422 
423  // Commit all packets at once
424  timelineUtilityMethods.Commit();
425 
426  // Get the readable buffer
427  auto readableBuffer = mockBufferManager.GetReadableBuffer();
428  BOOST_CHECK(readableBuffer != nullptr);
429  unsigned int size = readableBuffer->GetSize();
430 
431  BOOST_CHECK(size == 68 + ThreadIdSize);
432 
433  const unsigned char* readableData = readableBuffer->GetReadableData();
434  BOOST_CHECK(readableData != nullptr);
435 
436  // Utils
437  unsigned int offset = 0;
438 
439  // Verify Header
440  VerifyTimelineHeaderBinary(readableData, offset, 60 + ThreadIdSize);
441 
442  // First dataset sent: TimelineEntityBinaryPacket
444 
445  // Second dataset sent: TimelineRelationshipBinaryPacket
447  EmptyOptional(),
448  entityGuid,
449  eventGuid,
450  eventClassGuid,
451  readableData,
452  offset);
453 
454  // Mark the buffer as read
455  mockBufferManager.MarkRead(readableBuffer);
456 }
457 
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
static ARMNN_DLLEXPORT ProfilingStaticGuid INFERENCE_GUID
void VerifyTimelineEventClassBinaryPacketData(ProfilingGuid guid, ProfilingGuid nameGuid, const unsigned char *readableData, unsigned int &offset)
static ARMNN_DLLEXPORT std::string WORKLOAD_EXECUTION
ProfilingGuid VerifyTimelineEntityBinaryPacketData(Optional< ProfilingGuid > guid, const unsigned char *readableData, unsigned int &offset)
static ARMNN_DLLEXPORT std::string TYPE_LABEL
static ARMNN_DLLEXPORT ProfilingStaticGuid ARMNN_PROFILING_SOL_EVENT_CLASS_NAME_GUID
Strongly typed guids to distinguish between those generated at runtime, and those that are statically...
Definition: Types.hpp:335
static ARMNN_DLLEXPORT std::string NAME_LABEL
Copyright (c) 2021 ARM Limited and Contributors.
static ARMNN_DLLEXPORT std::string BACKENDID_LABEL
static ARMNN_DLLEXPORT ProfilingStaticGuid CONNECTION_GUID
ProfilingDynamicGuid NextGuid() override
Return the next random Guid in the sequence.
static ARMNN_DLLEXPORT ProfilingStaticGuid WORKLOAD_GUID
static ARMNN_DLLEXPORT std::string EXECUTION_OF_LABEL
static ARMNN_DLLEXPORT ProfilingStaticGuid WORKLOAD_EXECUTION_GUID
static ARMNN_DLLEXPORT ProfilingStaticGuid ARMNN_PROFILING_EOL_EVENT_CLASS
static ARMNN_DLLEXPORT ProfilingStaticGuid NAME_GUID
static ARMNN_DLLEXPORT ProfilingStaticGuid ARMNN_PROFILING_SOL_EVENT_CLASS
static ARMNN_DLLEXPORT std::string NETWORK
void MarkRead(IPacketBufferPtr &packetBuffer) override
static ARMNN_DLLEXPORT ProfilingStaticGuid LAYER_GUID
void VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType relationshipType, Optional< ProfilingGuid > relationshipGuid, Optional< ProfilingGuid > headGuid, Optional< ProfilingGuid > tailGuid, Optional< ProfilingGuid > attributeGuid, const unsigned char *readableData, unsigned int &offset)
static ARMNN_DLLEXPORT ProfilingStaticGuid EXECUTION_OF_GUID
static ARMNN_DLLEXPORT ProfilingStaticGuid ARMNN_PROFILING_EOL_EVENT_CLASS_NAME_GUID
static ARMNN_DLLEXPORT std::string WORKLOAD
IPacketBufferPtr GetReadableBuffer() override
static ARMNN_DLLEXPORT std::string INDEX_LABEL
static ARMNN_DLLEXPORT std::string ARMNN_PROFILING_SOL_EVENT_CLASS_NAME
static ARMNN_DLLEXPORT std::string ARMNN_PROFILING_EOL_EVENT_CLASS_NAME
BOOST_AUTO_TEST_CASE(CheckConvolution2dLayer)
constexpr unsigned int ThreadIdSize
void VerifyTimelineHeaderBinary(const unsigned char *readableData, unsigned int &offset, uint32_t packetDataLength)
static ARMNN_DLLEXPORT ProfilingStaticGuid NETWORK_GUID
static ARMNN_DLLEXPORT std::string CONNECTION
BOOST_AUTO_TEST_SUITE_END()
static ARMNN_DLLEXPORT std::string PROCESS_ID_LABEL
static ARMNN_DLLEXPORT ProfilingStaticGuid INDEX_GUID
EmptyOptional is used to initialize the Optional class in case we want to have default value for an O...
Definition: Optional.hpp:32
static ARMNN_DLLEXPORT ProfilingStaticGuid TYPE_GUID
static ARMNN_DLLEXPORT std::string CHILD_LABEL
static void SendWellKnownLabelsAndEventClasses(ISendTimelinePacket &timelinePacket)
ProfilingGuid VerifyTimelineEventBinaryPacket(Optional< uint64_t > timestamp, Optional< int > threadId, Optional< ProfilingGuid > eventGuid, const unsigned char *readableData, unsigned int &offset)
ProfilingGuid VerifyTimelineLabelBinaryPacketData(Optional< ProfilingGuid > guid, const std::string &label, const unsigned char *readableData, unsigned int &offset)
static ARMNN_DLLEXPORT ProfilingStaticGuid PROCESS_ID_GUID
static ARMNN_DLLEXPORT ProfilingStaticGuid BACKENDID_GUID
static ARMNN_DLLEXPORT std::string INFERENCE
static ARMNN_DLLEXPORT ProfilingStaticGuid CHILD_GUID
static ARMNN_DLLEXPORT std::string LAYER