ArmNN
 21.08
TimelineUtilityMethodsTests.cpp File Reference
#include "ProfilingMocks.hpp"
#include "ProfilingTestUtils.hpp"
#include <SendTimelinePacket.hpp>
#include <TimelineUtilityMethods.hpp>
#include <ProfilingService.hpp>
#include <common/include/LabelsAndEventClasses.hpp>
#include <memory>
#include <doctest/doctest.h>

Go to the source code of this file.

Functions

 TEST_SUITE ("TimelineUtilityMethodsTests")
 

Function Documentation

◆ TEST_SUITE()

TEST_SUITE ( "TimelineUtilityMethodsTests"  )

Definition at line 22 of file TimelineUtilityMethodsTests.cpp.

References MockBufferManager::GetReadableBuffer(), armnn::profiling::LabelLink, MockBufferManager::MarkRead(), ProfilingService::NextGuid(), TimelineUtilityMethods::SendWellKnownLabelsAndEventClasses(), VerifyTimelineHeaderBinary(), VerifyTimelineLabelBinaryPacketData(), and VerifyTimelineRelationshipBinaryPacketData().

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