ArmNN
 20.02
TimelineUtilityMethodsTests.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2019 Arm Ltd. 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  std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager);
27  TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket);
28 
29  // Generate first guid to ensure that the named typed entity guid is not 0 on local single test.
31 
32  ProfilingGuid entityGuid(123);
33  const std::string entityName = "some entity";
34  ProfilingStaticGuid labelTypeGuid(456);
35 
36  BOOST_CHECK_NO_THROW(timelineUtilityMethods.MarkEntityWithLabel(entityGuid, entityName, labelTypeGuid));
37 
38  // Commit all packets at once
39  timelineUtilityMethods.Commit();
40 
41  // Get the readable buffer
42  auto readableBuffer = mockBufferManager.GetReadableBuffer();
43  BOOST_CHECK(readableBuffer != nullptr);
44  unsigned int size = readableBuffer->GetSize();
45  BOOST_CHECK(size == 100);
46  const unsigned char* readableData = readableBuffer->GetReadableData();
47  BOOST_CHECK(readableData != nullptr);
48 
49  // Utils
50  unsigned int offset = 0;
51 
52  // Verify Header
53  VerifyTimelineHeaderBinary(readableData, offset, 92);
54 
55  // First dataset sent: TimelineLabelBinaryPacket
56  VerifyTimelineLabelBinaryPacketData(EmptyOptional(), entityName, readableData, offset);
57 
58  // Second dataset sent: TimelineRelationshipBinaryPacket
60  EmptyOptional(),
61  entityGuid,
62  EmptyOptional(),
63  readableData,
64  offset);
65 
66  // Third dataset sent: TimelineRelationshipBinaryPacket
68  EmptyOptional(),
69  EmptyOptional(),
70  labelTypeGuid,
71  readableData,
72  offset);
73 
74  // Mark the buffer as read
75  mockBufferManager.MarkRead(readableBuffer);
76 }
77 
78 BOOST_AUTO_TEST_CASE(SendWellKnownLabelsAndEventClassesTest)
79 {
80  MockBufferManager mockBufferManager(1024);
81  std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager);
82  TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket);
83 
84  BOOST_CHECK_NO_THROW(timelineUtilityMethods.SendWellKnownLabelsAndEventClasses());
85 
86  // Commit all packets at once
87  timelineUtilityMethods.Commit();
88 
89  // Get the readable buffer
90  auto readableBuffer = mockBufferManager.GetReadableBuffer();
91  BOOST_CHECK(readableBuffer != nullptr);
92  unsigned int size = readableBuffer->GetSize();
93  BOOST_TEST(size == 300);
94  const unsigned char* readableData = readableBuffer->GetReadableData();
95  BOOST_CHECK(readableData != nullptr);
96 
97  // Utils
98  unsigned int offset = 0;
99 
100  // Verify Header
101  VerifyTimelineHeaderBinary(readableData, offset, 292);
102 
103  // First "well-known" label: NAME
106  readableData,
107  offset);
108 
109  // Second "well-known" label: TYPE
112  readableData,
113  offset);
114 
115  // Third "well-known" label: INDEX
118  readableData,
119  offset);
120 
121  // Forth "well-known" label: BACKENDID
124  readableData,
125  offset);
126 
127  // Well-known types
128  // Layer
131  readableData,
132  offset);
133 
134  // Workload
137  readableData,
138  offset);
139 
140  // Network
143  readableData,
144  offset);
145 
146  // Connection
149  readableData,
150  offset);
151 
152  // Inference
155  readableData,
156  offset);
157 
158  // Workload Execution
161  readableData,
162  offset);
163 
164  // First "well-known" event class: START OF LIFE
166  readableData,
167  offset);
168 
169  // Second "well-known" event class: END OF LIFE
171  readableData,
172  offset);
173 
174  // Mark the buffer as read
175  mockBufferManager.MarkRead(readableBuffer);
176 }
177 
178 BOOST_AUTO_TEST_CASE(CreateNamedTypedChildEntityTest)
179 {
180  MockBufferManager mockBufferManager(1024);
181  std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager);
182  TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket);
183 
184  ProfilingDynamicGuid childEntityGuid(0);
185  ProfilingGuid parentEntityGuid(123);
186  const std::string entityName = "some entity";
187  const std::string entityType = "some type";
188 
189  // Generate first guid to ensure that the named typed entity guid is not 0 on local single test.
191 
192  BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedChildEntity(parentEntityGuid, "", entityType),
194  BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedChildEntity(parentEntityGuid, entityName, ""),
196  BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedChildEntity(
197  childEntityGuid, parentEntityGuid, "", entityType), InvalidArgumentException);
198  BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedChildEntity(
199  childEntityGuid, parentEntityGuid, entityName, ""), InvalidArgumentException);
200 
201  BOOST_CHECK_NO_THROW(childEntityGuid = timelineUtilityMethods.CreateNamedTypedChildEntity(parentEntityGuid,
202  entityName,
203  entityType));
204  BOOST_CHECK(childEntityGuid != ProfilingGuid(0));
205 
206  // Commit all packets at once
207  timelineUtilityMethods.Commit();
208 
209  // Get the readable buffer
210  auto readableBuffer = mockBufferManager.GetReadableBuffer();
211  BOOST_CHECK(readableBuffer != nullptr);
212  unsigned int size = readableBuffer->GetSize();
213  BOOST_CHECK(size == 236);
214  const unsigned char* readableData = readableBuffer->GetReadableData();
215  BOOST_CHECK(readableData != nullptr);
216 
217  // Utils
218  unsigned int offset = 0;
219 
220  // Verify Header
221  VerifyTimelineHeaderBinary(readableData, offset, 228);
222 
223  // First dataset sent: TimelineEntityBinaryPacket
224  VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
225 
226  // Second dataset sent: TimelineLabelBinaryPacket
227  VerifyTimelineLabelBinaryPacketData(EmptyOptional(), entityName, readableData, offset);
228 
229  // Third dataset sent: TimelineRelationshipBinaryPacket
231  EmptyOptional(),
232  EmptyOptional(),
233  EmptyOptional(),
234  readableData,
235  offset);
236 
237  // Fourth dataset sent: TimelineRelationshipBinaryPacket
239  EmptyOptional(),
240  EmptyOptional(),
242  readableData,
243  offset);
244 
245  // Fifth dataset sent: TimelineLabelBinaryPacket
246  VerifyTimelineLabelBinaryPacketData(EmptyOptional(), entityType, readableData, offset);
247 
248  // Sixth dataset sent: TimelineRelationshipBinaryPacket
250  EmptyOptional(),
251  EmptyOptional(),
252  EmptyOptional(),
253  readableData,
254  offset);
255 
256  // Seventh dataset sent: TimelineRelationshipBinaryPacket
258  EmptyOptional(),
259  EmptyOptional(),
261  readableData,
262  offset);
263 
264  // Eighth dataset sent: TimelineRelationshipBinaryPacket
266  EmptyOptional(),
267  parentEntityGuid,
268  EmptyOptional(),
269  readableData,
270  offset);
271 
272  // Mark the buffer as read
273  mockBufferManager.MarkRead(readableBuffer);
274 }
275 
276 BOOST_AUTO_TEST_CASE(DeclareLabelTest)
277 {
278  MockBufferManager mockBufferManager(1024);
279  std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager);
280  TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket);
281 
282  // Generate first guid to ensure that the named typed entity guid is not 0 on local single test.
284 
285  // Try declaring an invalid (empty) label
286  BOOST_CHECK_THROW(timelineUtilityMethods.DeclareLabel(""), InvalidArgumentException);
287 
288  // Try declaring an invalid (wrong SWTrace format) label
289  BOOST_CHECK_THROW(timelineUtilityMethods.DeclareLabel("inv@lid lab€l"), RuntimeException);
290 
291  // Declare a valid label
292  const std::string labelName = "valid label";
293  ProfilingGuid labelGuid = 0;
294  BOOST_CHECK_NO_THROW(labelGuid = timelineUtilityMethods.DeclareLabel(labelName));
295  BOOST_CHECK(labelGuid != ProfilingGuid(0));
296 
297  // Try adding the same label as before
298  ProfilingGuid newLabelGuid = 0;
299  BOOST_CHECK_NO_THROW(newLabelGuid = timelineUtilityMethods.DeclareLabel(labelName));
300  BOOST_CHECK(newLabelGuid != ProfilingGuid(0));
301  BOOST_CHECK(newLabelGuid == labelGuid);
302 }
303 
304 BOOST_AUTO_TEST_CASE(CreateNameTypeEntityInvalidTest)
305 {
306  MockBufferManager mockBufferManager(1024);
307  std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager);
308  TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket);
309 
310  // Invalid name
311  BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedEntity("", "Type"), InvalidArgumentException);
312 
313  // Invalid type
314  BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedEntity("Name", ""), InvalidArgumentException);
315 
317 
318  // CreatedNamedTypedEntity with Guid - Invalid name
319  BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedEntity(guid, "", "Type"),
321 
322  // CreatedNamedTypedEntity with Guid - Invalid type
323  BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedEntity(guid, "Name", ""),
325 
326 }
327 
328 BOOST_AUTO_TEST_CASE(CreateNameTypeEntityTest)
329 {
330  MockBufferManager mockBufferManager(1024);
331  std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager);
332  TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket);
333 
334  const std::string entityName = "Entity0";
335  const std::string entityType = "Type0";
336 
337  // Generate first guid to ensure that the named typed entity guid is not 0 on local single test.
339 
340  ProfilingDynamicGuid guid = timelineUtilityMethods.CreateNamedTypedEntity(entityName, entityType);
341  BOOST_CHECK(guid != ProfilingGuid(0));
342 
343  // Commit all packets at once
344  timelineUtilityMethods.Commit();
345 
346  // Get the readable buffer
347  auto readableBuffer = mockBufferManager.GetReadableBuffer();
348  BOOST_CHECK(readableBuffer != nullptr);
349  unsigned int size = readableBuffer->GetSize();
350  BOOST_CHECK(size == 196);
351  const unsigned char* readableData = readableBuffer->GetReadableData();
352  BOOST_CHECK(readableData != nullptr);
353 
354  // Utils
355  unsigned int offset = 0;
356 
357  // Verify Header
358  VerifyTimelineHeaderBinary(readableData, offset, 188);
359 
360  // First dataset sent: TimelineEntityBinaryPacket
361  VerifyTimelineEntityBinaryPacketData(guid, readableData, offset);
362 
363  // Packets for Name Entity
364  // First dataset sent: TimelineLabelBinaryPacket
365  VerifyTimelineLabelBinaryPacketData(EmptyOptional(), entityName, readableData, offset);
366 
367  // Second dataset sent: TimelineRelationshipBinaryPacket
369  EmptyOptional(),
370  EmptyOptional(),
371  EmptyOptional(),
372  readableData,
373  offset);
374 
375  // Third dataset sent: TimelineRelationshipBinaryPacket
377  EmptyOptional(),
378  EmptyOptional(),
380  readableData,
381  offset);
382 
383  // Packets for Type Entity
384  // First dataset sent: TimelineLabelBinaryPacket
385  VerifyTimelineLabelBinaryPacketData(EmptyOptional(), entityType, readableData, offset);
386 
387  // Second dataset sent: TimelineRelationshipBinaryPacket
389  EmptyOptional(),
390  EmptyOptional(),
391  EmptyOptional(),
392  readableData,
393  offset);
394 
395  // Third dataset sent: TimelineRelationshipBinaryPacket
397  EmptyOptional(),
398  EmptyOptional(),
400  readableData,
401  offset);
402 
403  // Mark the buffer as read
404  mockBufferManager.MarkRead(readableBuffer);
405 }
406 
407 BOOST_AUTO_TEST_CASE(RecordEventTest)
408 {
409  MockBufferManager mockBufferManager(1024);
410  std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager);
411  TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket);
412  // Generate first guid to ensure that the named typed entity guid is not 0 on local single test.
414 
415  ProfilingGuid entityGuid(123);
416  ProfilingStaticGuid eventClassGuid(456);
417  ProfilingDynamicGuid eventGuid(0);
418  BOOST_CHECK_NO_THROW(eventGuid = timelineUtilityMethods.RecordEvent(entityGuid, eventClassGuid));
419  BOOST_CHECK(eventGuid != ProfilingGuid(0));
420 
421  // Commit all packets at once
422  timelineUtilityMethods.Commit();
423 
424  // Get the readable buffer
425  auto readableBuffer = mockBufferManager.GetReadableBuffer();
426  BOOST_CHECK(readableBuffer != nullptr);
427  unsigned int size = readableBuffer->GetSize();
428  BOOST_CHECK(size == 100);
429  const unsigned char* readableData = readableBuffer->GetReadableData();
430  BOOST_CHECK(readableData != nullptr);
431 
432  // Utils
433  unsigned int offset = 0;
434 
435  // Verify Header
436  VerifyTimelineHeaderBinary(readableData, offset, 92);
437 
438  // First dataset sent: TimelineEntityBinaryPacket
440 
441  // Second dataset sent: TimelineRelationshipBinaryPacket
443  EmptyOptional(),
444  entityGuid,
445  EmptyOptional(),
446  readableData,
447  offset);
448 
449  // Third dataset sent: TimelineRelationshipBinaryPacket
451  EmptyOptional(),
452  eventGuid,
453  eventClassGuid,
454  readableData,
455  offset);
456 
457  // Mark the buffer as read
458  mockBufferManager.MarkRead(readableBuffer);
459 }
460 
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
static ARMNN_DLLEXPORT ProfilingStaticGuid INFERENCE_GUID
static ProfilingService & Instance()
static ARMNN_DLLEXPORT std::string WORKLOAD_EXECUTION
void VerifyTimelineEntityBinaryPacketData(Optional< ProfilingGuid > guid, const unsigned char *readableData, unsigned int &offset)
static ARMNN_DLLEXPORT std::string TYPE_LABEL
Strongly typed guids to distinguish between those generated at runtime, and those that are statically...
Definition: Types.hpp:294
static ARMNN_DLLEXPORT std::string NAME_LABEL
void VerifyTimelineLabelBinaryPacketData(Optional< ProfilingGuid > guid, const std::string &label, const unsigned char *readableData, unsigned int &offset)
Copyright (c) 2020 ARM Limited.
Head execution start depends on Tail execution completion.
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
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
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
static ARMNN_DLLEXPORT std::string WORKLOAD
IPacketBufferPtr GetReadableBuffer() override
static ARMNN_DLLEXPORT std::string INDEX_LABEL
BOOST_AUTO_TEST_CASE(CheckConvolution2dLayer)
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 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
void VerifyTimelineEventClassBinaryPacketData(ProfilingGuid guid, const unsigned char *readableData, unsigned int &offset)
void VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType relationshipType, Optional< ProfilingGuid > relationshipGuid, Optional< ProfilingGuid > headGuid, Optional< ProfilingGuid > tailGuid, const unsigned char *readableData, unsigned int &offset)
static ARMNN_DLLEXPORT ProfilingStaticGuid TYPE_GUID
void VerifyTimelineEventBinaryPacket(Optional< uint64_t > timestamp, Optional< std::thread::id > threadId, Optional< ProfilingGuid > eventGuid, const unsigned char *readableData, unsigned int &offset)
static ARMNN_DLLEXPORT ProfilingStaticGuid BACKENDID_GUID
static ARMNN_DLLEXPORT std::string INFERENCE
static ARMNN_DLLEXPORT std::string LAYER