ArmNN
 20.05
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);
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 == 100);
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, 92);
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  readableData,
66  offset);
67 
68  // Third dataset sent: TimelineRelationshipBinaryPacket
70  EmptyOptional(),
71  EmptyOptional(),
72  labelTypeGuid,
73  readableData,
74  offset);
75 
76  // Mark the buffer as read
77  mockBufferManager.MarkRead(readableBuffer);
78 }
79 
80 BOOST_AUTO_TEST_CASE(SendWellKnownLabelsAndEventClassesTest)
81 {
82  MockBufferManager mockBufferManager(1024);
84  SendTimelinePacket sendTimelinePacket(mockBufferManager);
85 
86  BOOST_CHECK_NO_THROW(TimelineUtilityMethods::SendWellKnownLabelsAndEventClasses(sendTimelinePacket));
87 
88  // Get the readable buffer
89  auto readableBuffer = mockBufferManager.GetReadableBuffer();
90  BOOST_CHECK(readableBuffer != nullptr);
91  unsigned int size = readableBuffer->GetSize();
92  BOOST_TEST(size == 300);
93  const unsigned char* readableData = readableBuffer->GetReadableData();
94  BOOST_CHECK(readableData != nullptr);
95 
96  // Utils
97  unsigned int offset = 0;
98 
99  // Verify Header
100  VerifyTimelineHeaderBinary(readableData, offset, 292);
101 
102  // First "well-known" label: NAME
105  readableData,
106  offset);
107 
108  // Second "well-known" label: TYPE
111  readableData,
112  offset);
113 
114  // Third "well-known" label: INDEX
117  readableData,
118  offset);
119 
120  // Forth "well-known" label: BACKENDID
123  readableData,
124  offset);
125 
126  // Well-known types
127  // Layer
130  readableData,
131  offset);
132 
133  // Workload
136  readableData,
137  offset);
138 
139  // Network
142  readableData,
143  offset);
144 
145  // Connection
148  readableData,
149  offset);
150 
151  // Inference
154  readableData,
155  offset);
156 
157  // Workload Execution
160  readableData,
161  offset);
162 
163  // First "well-known" event class: START OF LIFE
165  readableData,
166  offset);
167 
168  // Second "well-known" event class: END OF LIFE
170  readableData,
171  offset);
172 
173  // Mark the buffer as read
174  mockBufferManager.MarkRead(readableBuffer);
175 }
176 
177 BOOST_AUTO_TEST_CASE(CreateNamedTypedChildEntityTest)
178 {
179  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.
190  profilingService.NextGuid();
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);
280  std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager);
281  TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket);
282 
283  // Generate first guid to ensure that the named typed entity guid is not 0 on local single test.
284  profilingService.NextGuid();
285 
286  // Try declaring an invalid (empty) label
287  BOOST_CHECK_THROW(timelineUtilityMethods.DeclareLabel(""), InvalidArgumentException);
288 
289  // Try declaring an invalid (wrong SWTrace format) label
290  BOOST_CHECK_THROW(timelineUtilityMethods.DeclareLabel("inv@lid lab€l"), RuntimeException);
291 
292  // Declare a valid label
293  const std::string labelName = "valid label";
294  ProfilingGuid labelGuid = 0;
295  BOOST_CHECK_NO_THROW(labelGuid = timelineUtilityMethods.DeclareLabel(labelName));
296  BOOST_CHECK(labelGuid != ProfilingGuid(0));
297 
298  // Try adding the same label as before
299  ProfilingGuid newLabelGuid = 0;
300  BOOST_CHECK_NO_THROW(newLabelGuid = timelineUtilityMethods.DeclareLabel(labelName));
301  BOOST_CHECK(newLabelGuid != ProfilingGuid(0));
302  BOOST_CHECK(newLabelGuid == labelGuid);
303 }
304 
305 BOOST_AUTO_TEST_CASE(CreateNameTypeEntityInvalidTest)
306 {
307  MockBufferManager mockBufferManager(1024);
309  std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager);
310  TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket);
311 
312  // Invalid name
313  BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedEntity("", "Type"), InvalidArgumentException);
314 
315  // Invalid type
316  BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedEntity("Name", ""), InvalidArgumentException);
317 
318  ProfilingDynamicGuid guid = profilingService.NextGuid();
319 
320  // CreatedNamedTypedEntity with Guid - Invalid name
321  BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedEntity(guid, "", "Type"),
323 
324  // CreatedNamedTypedEntity with Guid - Invalid type
325  BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedEntity(guid, "Name", ""),
327 
328 }
329 
330 BOOST_AUTO_TEST_CASE(CreateNameTypeEntityTest)
331 {
332  MockBufferManager mockBufferManager(1024);
334  std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager);
335  TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket);
336 
337  const std::string entityName = "Entity0";
338  const std::string entityType = "Type0";
339 
340  // Generate first guid to ensure that the named typed entity guid is not 0 on local single test.
341  profilingService.NextGuid();
342 
343  ProfilingDynamicGuid guid = timelineUtilityMethods.CreateNamedTypedEntity(entityName, entityType);
344  BOOST_CHECK(guid != ProfilingGuid(0));
345 
346  // Commit all packets at once
347  timelineUtilityMethods.Commit();
348 
349  // Get the readable buffer
350  auto readableBuffer = mockBufferManager.GetReadableBuffer();
351  BOOST_CHECK(readableBuffer != nullptr);
352  unsigned int size = readableBuffer->GetSize();
353  BOOST_CHECK(size == 196);
354  const unsigned char* readableData = readableBuffer->GetReadableData();
355  BOOST_CHECK(readableData != nullptr);
356 
357  // Utils
358  unsigned int offset = 0;
359 
360  // Verify Header
361  VerifyTimelineHeaderBinary(readableData, offset, 188);
362 
363  // First dataset sent: TimelineEntityBinaryPacket
364  VerifyTimelineEntityBinaryPacketData(guid, readableData, offset);
365 
366  // Packets for Name Entity
367  // First dataset sent: TimelineLabelBinaryPacket
368  VerifyTimelineLabelBinaryPacketData(EmptyOptional(), entityName, readableData, offset);
369 
370  // Second dataset sent: TimelineRelationshipBinaryPacket
372  EmptyOptional(),
373  EmptyOptional(),
374  EmptyOptional(),
375  readableData,
376  offset);
377 
378  // Third dataset sent: TimelineRelationshipBinaryPacket
380  EmptyOptional(),
381  EmptyOptional(),
383  readableData,
384  offset);
385 
386  // Packets for Type Entity
387  // First dataset sent: TimelineLabelBinaryPacket
388  VerifyTimelineLabelBinaryPacketData(EmptyOptional(), entityType, readableData, offset);
389 
390  // Second dataset sent: TimelineRelationshipBinaryPacket
392  EmptyOptional(),
393  EmptyOptional(),
394  EmptyOptional(),
395  readableData,
396  offset);
397 
398  // Third dataset sent: TimelineRelationshipBinaryPacket
400  EmptyOptional(),
401  EmptyOptional(),
403  readableData,
404  offset);
405 
406  // Mark the buffer as read
407  mockBufferManager.MarkRead(readableBuffer);
408 }
409 
410 BOOST_AUTO_TEST_CASE(RecordEventTest)
411 {
412  MockBufferManager mockBufferManager(1024);
414  std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager);
415  TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket);
416  // Generate first guid to ensure that the named typed entity guid is not 0 on local single test.
417  profilingService.NextGuid();
418 
419  ProfilingGuid entityGuid(123);
420  ProfilingStaticGuid eventClassGuid(456);
421  ProfilingDynamicGuid eventGuid(0);
422  BOOST_CHECK_NO_THROW(eventGuid = timelineUtilityMethods.RecordEvent(entityGuid, eventClassGuid));
423  BOOST_CHECK(eventGuid != ProfilingGuid(0));
424 
425  // Commit all packets at once
426  timelineUtilityMethods.Commit();
427 
428  // Get the readable buffer
429  auto readableBuffer = mockBufferManager.GetReadableBuffer();
430  BOOST_CHECK(readableBuffer != nullptr);
431  unsigned int size = readableBuffer->GetSize();
432 
433  BOOST_CHECK(size == 92 + ThreadIdSize);
434 
435  const unsigned char* readableData = readableBuffer->GetReadableData();
436  BOOST_CHECK(readableData != nullptr);
437 
438  // Utils
439  unsigned int offset = 0;
440 
441  // Verify Header
442  VerifyTimelineHeaderBinary(readableData, offset, 84 + ThreadIdSize);
443 
444  // First dataset sent: TimelineEntityBinaryPacket
446 
447  // Second dataset sent: TimelineRelationshipBinaryPacket
449  EmptyOptional(),
450  entityGuid,
451  EmptyOptional(),
452  readableData,
453  offset);
454 
455  // Third dataset sent: TimelineRelationshipBinaryPacket
457  EmptyOptional(),
458  eventGuid,
459  eventClassGuid,
460  readableData,
461  offset);
462 
463  // Mark the buffer as read
464  mockBufferManager.MarkRead(readableBuffer);
465 }
466 
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
static ARMNN_DLLEXPORT ProfilingStaticGuid INFERENCE_GUID
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:296
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)
constexpr unsigned int ThreadIdSize
armnn::profiling::ProfilingService profilingService
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 void SendWellKnownLabelsAndEventClasses(ISendTimelinePacket &timelinePacket)
static ARMNN_DLLEXPORT ProfilingStaticGuid BACKENDID_GUID
static ARMNN_DLLEXPORT std::string INFERENCE
static ARMNN_DLLEXPORT std::string LAYER