ArmNN  NotReleased
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 == 116);
46  const unsigned char* readableData = readableBuffer->GetReadableData();
47  BOOST_CHECK(readableData != nullptr);
48 
49  // Utils
50  unsigned int offset = 0;
51 
52  // First packet sent: TimelineLabelBinaryPacket
53  VerifyTimelineLabelBinaryPacket(EmptyOptional(), entityName, readableData, offset);
54 
55  // Second packet sent: TimelineRelationshipBinaryPacket
57  EmptyOptional(),
58  entityGuid,
59  EmptyOptional(),
60  readableData,
61  offset);
62 
63  // Third packet sent: TimelineRelationshipBinaryPacket
65  EmptyOptional(),
66  EmptyOptional(),
67  labelTypeGuid,
68  readableData,
69  offset);
70 
71  // Mark the buffer as read
72  mockBufferManager.MarkRead(readableBuffer);
73 }
74 
75 BOOST_AUTO_TEST_CASE(SendWellKnownLabelsAndEventClassesTest)
76 {
77  MockBufferManager mockBufferManager(1024);
78  std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager);
79  TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket);
80 
81  BOOST_CHECK_NO_THROW(timelineUtilityMethods.SendWellKnownLabelsAndEventClasses());
82 
83  // Commit all packets at once
84  timelineUtilityMethods.Commit();
85 
86  // Get the readable buffer
87  auto readableBuffer = mockBufferManager.GetReadableBuffer();
88  BOOST_CHECK(readableBuffer != nullptr);
89  unsigned int size = readableBuffer->GetSize();
90  BOOST_TEST(size == 388);
91  const unsigned char* readableData = readableBuffer->GetReadableData();
92  BOOST_CHECK(readableData != nullptr);
93 
94  // Utils
95  unsigned int offset = 0;
96 
97  // First "well-known" label: NAME
100  readableData,
101  offset);
102 
103  // Second "well-known" label: TYPE
106  readableData,
107  offset);
108 
109  // Third "well-known" label: INDEX
112  readableData,
113  offset);
114 
115  // Forth "well-known" label: BACKENDID
118  readableData,
119  offset);
120 
121  // Well-known types
122  // Layer
125  readableData,
126  offset);
127 
128  // Workload
131  readableData,
132  offset);
133 
134  // Network
137  readableData,
138  offset);
139 
140  // Connection
143  readableData,
144  offset);
145  // Inference
148  readableData,
149  offset);
150  // Workload Execution
153  readableData,
154  offset);
155 
156  // First "well-known" event class: START OF LIFE
158  readableData,
159  offset);
160 
161  // Second "well-known" event class: END OF LIFE
163  readableData,
164  offset);
165 
166  // Mark the buffer as read
167  mockBufferManager.MarkRead(readableBuffer);
168 }
169 
170 BOOST_AUTO_TEST_CASE(CreateNamedTypedChildEntityTest)
171 {
172  MockBufferManager mockBufferManager(1024);
173  std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager);
174  TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket);
175 
176  ProfilingDynamicGuid childEntityGuid(0);
177  ProfilingGuid parentEntityGuid(123);
178  const std::string entityName = "some entity";
179  const std::string entityType = "some type";
180 
181  // Generate first guid to ensure that the named typed entity guid is not 0 on local single test.
183 
184  BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedChildEntity(parentEntityGuid, "", entityType),
186  BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedChildEntity(parentEntityGuid, entityName, ""),
188  BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedChildEntity(
189  childEntityGuid, parentEntityGuid, "", entityType), InvalidArgumentException);
190  BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedChildEntity(
191  childEntityGuid, parentEntityGuid, entityName, ""), InvalidArgumentException);
192 
193  BOOST_CHECK_NO_THROW(childEntityGuid = timelineUtilityMethods.CreateNamedTypedChildEntity(parentEntityGuid,
194  entityName,
195  entityType));
196  BOOST_CHECK(childEntityGuid != ProfilingGuid(0));
197 
198  // Commit all packets at once
199  timelineUtilityMethods.Commit();
200 
201  // Get the readable buffer
202  auto readableBuffer = mockBufferManager.GetReadableBuffer();
203  BOOST_CHECK(readableBuffer != nullptr);
204  unsigned int size = readableBuffer->GetSize();
205  BOOST_CHECK(size == 292);
206  const unsigned char* readableData = readableBuffer->GetReadableData();
207  BOOST_CHECK(readableData != nullptr);
208 
209  // Utils
210  unsigned int offset = 0;
211 
212  // First packet sent: TimelineEntityBinaryPacket
213  VerifyTimelineEntityBinaryPacket(EmptyOptional(), readableData, offset);
214 
215  // Second packet sent: TimelineLabelBinaryPacket
216  VerifyTimelineLabelBinaryPacket(EmptyOptional(), entityName, readableData, offset);
217 
218  // Third packet sent: TimelineRelationshipBinaryPacket
220  EmptyOptional(),
221  EmptyOptional(),
222  EmptyOptional(),
223  readableData,
224  offset);
225 
226  // Fourth packet sent: TimelineRelationshipBinaryPacket
228  EmptyOptional(),
229  EmptyOptional(),
231  readableData,
232  offset);
233 
234  // Fifth packet sent: TimelineLabelBinaryPacket
235  VerifyTimelineLabelBinaryPacket(EmptyOptional(), entityType, readableData, offset);
236 
237  // Sixth packet sent: TimelineRelationshipBinaryPacket
239  EmptyOptional(),
240  EmptyOptional(),
241  EmptyOptional(),
242  readableData,
243  offset);
244 
245  // Seventh packet sent: TimelineRelationshipBinaryPacket
247  EmptyOptional(),
248  EmptyOptional(),
250  readableData,
251  offset);
252 
253  // Eighth packet sent: TimelineRelationshipBinaryPacket
255  EmptyOptional(),
256  parentEntityGuid,
257  EmptyOptional(),
258  readableData,
259  offset);
260 
261  // Mark the buffer as read
262  mockBufferManager.MarkRead(readableBuffer);
263 }
264 
265 BOOST_AUTO_TEST_CASE(DeclareLabelTest)
266 {
267  MockBufferManager mockBufferManager(1024);
268  std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager);
269  TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket);
270 
271  // Generate first guid to ensure that the named typed entity guid is not 0 on local single test.
273 
274  // Try declaring an invalid (empty) label
275  BOOST_CHECK_THROW(timelineUtilityMethods.DeclareLabel(""), InvalidArgumentException);
276 
277  // Try declaring an invalid (wrong SWTrace format) label
278  BOOST_CHECK_THROW(timelineUtilityMethods.DeclareLabel("inv@lid lab€l"), RuntimeException);
279 
280  // Declare a valid label
281  const std::string labelName = "valid label";
282  ProfilingGuid labelGuid = 0;
283  BOOST_CHECK_NO_THROW(labelGuid = timelineUtilityMethods.DeclareLabel(labelName));
284  BOOST_CHECK(labelGuid != ProfilingGuid(0));
285 
286  // Try adding the same label as before
287  ProfilingGuid newLabelGuid = 0;
288  BOOST_CHECK_NO_THROW(newLabelGuid = timelineUtilityMethods.DeclareLabel(labelName));
289  BOOST_CHECK(newLabelGuid != ProfilingGuid(0));
290  BOOST_CHECK(newLabelGuid == labelGuid);
291 }
292 
293 BOOST_AUTO_TEST_CASE(CreateNameTypeEntityInvalidTest)
294 {
295  MockBufferManager mockBufferManager(1024);
296  std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager);
297  TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket);
298 
299  // Invalid name
300  BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedEntity("", "Type"), InvalidArgumentException);
301 
302  // Invalid type
303  BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedEntity("Name", ""), InvalidArgumentException);
304 
306 
307  // CreatedNamedTypedEntity with Guid - Invalid name
308  BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedEntity(guid, "", "Type"),
310 
311  // CreatedNamedTypedEntity with Guid - Invalid type
312  BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedEntity(guid, "Name", ""),
314 
315 }
316 
317 BOOST_AUTO_TEST_CASE(CreateNameTypeEntityTest)
318 {
319  MockBufferManager mockBufferManager(1024);
320  std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager);
321  TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket);
322 
323  const std::string entityName = "Entity0";
324  const std::string entityType = "Type0";
325 
326  // Generate first guid to ensure that the named typed entity guid is not 0 on local single test.
328 
329  ProfilingDynamicGuid guid = timelineUtilityMethods.CreateNamedTypedEntity(entityName, entityType);
330  BOOST_CHECK(guid != ProfilingGuid(0));
331 
332  // Commit all packets at once
333  timelineUtilityMethods.Commit();
334 
335  // Get the readable buffer
336  auto readableBuffer = mockBufferManager.GetReadableBuffer();
337  BOOST_CHECK(readableBuffer != nullptr);
338  unsigned int size = readableBuffer->GetSize();
339  BOOST_CHECK(size == 244);
340  const unsigned char* readableData = readableBuffer->GetReadableData();
341  BOOST_CHECK(readableData != nullptr);
342 
343  // Utils
344  unsigned int offset = 0;
345 
346  // First packet sent: TimelineEntityBinaryPacket
347  VerifyTimelineEntityBinaryPacket(guid, readableData, offset);
348 
349  // Packets for Name Entity
350  // First packet sent: TimelineLabelBinaryPacket
351  VerifyTimelineLabelBinaryPacket(EmptyOptional(), entityName, readableData, offset);
352 
353  // Second packet sent: TimelineRelationshipBinaryPacket
355  EmptyOptional(),
356  EmptyOptional(),
357  EmptyOptional(),
358  readableData,
359  offset);
360 
361  // Third packet sent: TimelineRelationshipBinaryPacket
363  EmptyOptional(),
364  EmptyOptional(),
366  readableData,
367  offset);
368 
369  // Packets for Type Entity
370  // First packet sent: TimelineLabelBinaryPacket
371  VerifyTimelineLabelBinaryPacket(EmptyOptional(), entityType, readableData, offset);
372 
373  // Second packet sent: TimelineRelationshipBinaryPacket
375  EmptyOptional(),
376  EmptyOptional(),
377  EmptyOptional(),
378  readableData,
379  offset);
380 
381  // Third packet sent: TimelineRelationshipBinaryPacket
383  EmptyOptional(),
384  EmptyOptional(),
386  readableData,
387  offset);
388 
389  // Mark the buffer as read
390  mockBufferManager.MarkRead(readableBuffer);
391 }
392 
393 BOOST_AUTO_TEST_CASE(RecordEventTest)
394 {
395  MockBufferManager mockBufferManager(1024);
396  std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager);
397  TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket);
398  // Generate first guid to ensure that the named typed entity guid is not 0 on local single test.
400 
401  ProfilingGuid entityGuid(123);
402  ProfilingStaticGuid eventClassGuid(456);
403  ProfilingDynamicGuid eventGuid(0);
404  BOOST_CHECK_NO_THROW(eventGuid = timelineUtilityMethods.RecordEvent(entityGuid, eventClassGuid));
405  BOOST_CHECK(eventGuid != ProfilingGuid(0));
406 
407  // Commit all packets at once
408  timelineUtilityMethods.Commit();
409 
410  // Get the readable buffer
411  auto readableBuffer = mockBufferManager.GetReadableBuffer();
412  BOOST_CHECK(readableBuffer != nullptr);
413  unsigned int size = readableBuffer->GetSize();
414  BOOST_CHECK(size == 116);
415  const unsigned char* readableData = readableBuffer->GetReadableData();
416  BOOST_CHECK(readableData != nullptr);
417 
418  // Utils
419  unsigned int offset = 0;
420 
421  // First packet sent: TimelineEntityBinaryPacket
423 
424  // Second packet sent: TimelineRelationshipBinaryPacket
426  EmptyOptional(),
427  entityGuid,
428  EmptyOptional(),
429  readableData,
430  offset);
431 
432  // Third packet sent: TimelineRelationshipBinaryPacket
434  EmptyOptional(),
435  eventGuid,
436  eventClassGuid,
437  readableData,
438  offset);
439 
440  // Mark the buffer as read
441  mockBufferManager.MarkRead(readableBuffer);
442 }
443 
static ARMNN_DLLEXPORT ProfilingStaticGuid INDEX_GUID
static ARMNN_DLLEXPORT std::string INDEX_LABEL
static ARMNN_DLLEXPORT ProfilingStaticGuid WORKLOAD_GUID
static ARMNN_DLLEXPORT ProfilingStaticGuid WORKLOAD_EXECUTION_GUID
void VerifyTimelineLabelBinaryPacket(Optional< ProfilingGuid > guid, const std::string &label, const unsigned char *readableData, unsigned int &offset)
static ARMNN_DLLEXPORT ProfilingStaticGuid ARMNN_PROFILING_EOL_EVENT_CLASS
BOOST_AUTO_TEST_CASE(CheckConvolution2dLayer)
void VerifyTimelineEventClassBinaryPacket(ProfilingGuid guid, const unsigned char *readableData, unsigned int &offset)
static ARMNN_DLLEXPORT ProfilingStaticGuid CONNECTION_GUID
static ARMNN_DLLEXPORT std::string NAME_LABEL
ProfilingDynamicGuid NextGuid() override
Return the next random Guid in the sequence.
static ARMNN_DLLEXPORT std::string WORKLOAD_EXECUTION
void MarkRead(IPacketBufferPtr &packetBuffer) override
static ARMNN_DLLEXPORT ProfilingStaticGuid INFERENCE_GUID
static ARMNN_DLLEXPORT ProfilingStaticGuid TYPE_GUID
static ARMNN_DLLEXPORT std::string BACKENDID_LABEL
void VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType relationshipType, Optional< ProfilingGuid > relationshipGuid, Optional< ProfilingGuid > headGuid, Optional< ProfilingGuid > tailGuid, const unsigned char *readableData, unsigned int &offset)
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 ProfilingStaticGuid NETWORK_GUID
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
Head execution start depends on Tail execution completion.
static ARMNN_DLLEXPORT std::string CONNECTION
static ProfilingService & Instance()
static ARMNN_DLLEXPORT ProfilingStaticGuid LAYER_GUID
BOOST_AUTO_TEST_SUITE_END()
IPacketBufferPtr GetReadableBuffer() override
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
Strongly typed guids to distinguish between those generated at runtime, and those that are statically...
Definition: Types.hpp:291
static ARMNN_DLLEXPORT std::string WORKLOAD
static ARMNN_DLLEXPORT ProfilingStaticGuid ARMNN_PROFILING_SOL_EVENT_CLASS
static ARMNN_DLLEXPORT std::string TYPE_LABEL
static ARMNN_DLLEXPORT ProfilingStaticGuid NAME_GUID
static ARMNN_DLLEXPORT std::string LAYER
static ARMNN_DLLEXPORT std::string INFERENCE
static ARMNN_DLLEXPORT std::string NETWORK
void VerifyTimelineEntityBinaryPacket(Optional< ProfilingGuid > guid, const unsigned char *readableData, unsigned int &offset)