ArmNN
 20.02
TimelineUtilityMethods.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2019 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
7 #include "ProfilingService.hpp"
9 
10 namespace armnn
11 {
12 
13 namespace profiling
14 {
15 
16 std::unique_ptr<TimelineUtilityMethods> TimelineUtilityMethods::GetTimelineUtils()
17 {
18  if (ProfilingService::Instance().IsEnabled())
19  {
20  std::unique_ptr<ISendTimelinePacket> sendTimelinepacket = ProfilingService::Instance().GetSendTimelinePacket();
21  return std::make_unique<TimelineUtilityMethods>(sendTimelinepacket);
22  }
23  else
24  {
25  std::unique_ptr<TimelineUtilityMethods> empty;
26  return empty;
27  }
28 }
29 
30 
32 {
33  // Send the "name" label, this call throws in case of error
34  m_SendTimelinePacket->SendTimelineLabelBinaryPacket(LabelsAndEventClasses::NAME_GUID,
36 
37  // Send the "type" label, this call throws in case of error
38  m_SendTimelinePacket->SendTimelineLabelBinaryPacket(LabelsAndEventClasses::TYPE_GUID,
40 
41  // Send the "index" label, this call throws in case of error
42  m_SendTimelinePacket->SendTimelineLabelBinaryPacket(LabelsAndEventClasses::INDEX_GUID,
44 
45  // Send the "backendId" label, this call throws in case of error
46  m_SendTimelinePacket->SendTimelineLabelBinaryPacket(LabelsAndEventClasses::BACKENDID_GUID,
48 
49  // Send the "layer" label, this call throws in case of error
50  m_SendTimelinePacket->SendTimelineLabelBinaryPacket(LabelsAndEventClasses::LAYER_GUID,
52 
53  // Send the "workload" label, this call throws in case of error
54  m_SendTimelinePacket->SendTimelineLabelBinaryPacket(LabelsAndEventClasses::WORKLOAD_GUID,
56 
57  // Send the "network" label, this call throws in case of error
58  m_SendTimelinePacket->SendTimelineLabelBinaryPacket(LabelsAndEventClasses::NETWORK_GUID,
60 
61  // Send the "connection" label, this call throws in case of error
62  m_SendTimelinePacket->SendTimelineLabelBinaryPacket(LabelsAndEventClasses::CONNECTION_GUID,
64 
65  // Send the "inference" label, this call throws in case of error
66  m_SendTimelinePacket->SendTimelineLabelBinaryPacket(LabelsAndEventClasses::INFERENCE_GUID,
68 
69  // Send the "workload_execution" label, this call throws in case of error
70  m_SendTimelinePacket->SendTimelineLabelBinaryPacket(LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID,
72 
73  // Send the "start of life" event class, this call throws in case of error
74  m_SendTimelinePacket->SendTimelineEventClassBinaryPacket(LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS);
75 
76  // Send the "end of life" event class, this call throws in case of error
77  m_SendTimelinePacket->SendTimelineEventClassBinaryPacket(LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS);
78 }
79 
80 ProfilingDynamicGuid TimelineUtilityMethods::CreateNamedTypedEntity(const std::string& name, const std::string& type)
81 {
82  // Check that the entity name is valid
83  if (name.empty())
84  {
85  throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
86  }
87 
88  // Check that the entity type is valid
89  if (type.empty())
90  {
91  throw InvalidArgumentException("Invalid entity type, the entity type cannot be empty");
92  }
93 
94  // Generate dynamic GUID of the entity
96 
97  CreateNamedTypedEntity(entityGuid, name, type);
98 
99  return entityGuid;
100 }
101 
103  const std::string& name,
104  const std::string& type)
105 {
106  // Check that the entity name is valid
107  if (name.empty())
108  {
109  throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
110  }
111 
112  // Check that the entity type is valid
113  if (type.empty())
114  {
115  throw InvalidArgumentException("Invalid entity type, the entity type cannot be empty");
116  }
117 
118  // Send Entity Binary Packet of the entity to the external profiling service
119  m_SendTimelinePacket->SendTimelineEntityBinaryPacket(entityGuid);
120 
121  // Create name entity and send the relationship of the entity with the given name
122  NameEntity(entityGuid, name);
123 
124  // Create type entity and send the relationship of the entity with the given type
125  TypeEntity(entityGuid, type);
126 }
127 
129  const std::string& name,
130  ProfilingStaticGuid typeGuid)
131 {
132  // Check that the entity name is valid
133  if (name.empty())
134  {
135  throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
136  }
137 
138  // Send Entity Binary Packet of the entity to the external profiling service
139  m_SendTimelinePacket->SendTimelineEntityBinaryPacket(entityGuid);
140 
141  // Create name entity and send the relationship of the entity with the given name
142  NameEntity(entityGuid, name);
143 
144  // Create type entity and send the relationship of the entity with the given type
145  MarkEntityWithType(entityGuid, typeGuid);
146 }
147 
149 {
150  // Check that the label name is valid
151  if (labelName.empty())
152  {
153  // The label name is invalid
154  throw InvalidArgumentException("Invalid label name, the label name cannot be empty");
155  }
156 
157  // Generate a static GUID for the given label name
159 
160  // Send the new label to the external profiling service, this call throws in case of error
161  m_SendTimelinePacket->SendTimelineLabelBinaryPacket(labelGuid, labelName);
162 
163  return labelGuid;
164 }
165 
167  const std::string& labelName,
168  ProfilingStaticGuid labelTypeGuid)
169 {
170  // Check that the label name is valid
171  if (labelName.empty())
172  {
173  // The label name is invalid
174  throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
175  }
176 
177  // Declare a label with the label's name, this call throws in case of error
178  ProfilingStaticGuid labelGuid = DeclareLabel(labelName);
179 
180  // Generate a GUID for the label relationship
182 
183  // Send the new label link to the external profiling service, this call throws in case of error
184  m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink,
185  relationshipGuid,
186  entityGuid,
187  labelGuid);
188 
189  // Generate a GUID for the label relationship
190  ProfilingDynamicGuid relationshipLabelGuid = ProfilingService::Instance().NextGuid();
191 
192  // Send the new label link to the external profiling service, this call throws in case of error
193  m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink,
194  relationshipLabelGuid,
195  relationshipGuid,
196  labelTypeGuid);
197 }
198 
200  ProfilingStaticGuid typeNameGuid)
201 {
202  // Generate a GUID for the label relationship
204 
205  // Send the new label link to the external profiling service, this call throws in case of error
206  m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink,
207  relationshipGuid,
208  entityGuid,
209  typeNameGuid);
210 
211  // Generate a GUID for the label relationship
212  ProfilingDynamicGuid relationshipLabelGuid = ProfilingService::Instance().NextGuid();
213 
214  // Send the new label link to the external profiling service, this call throws in case of error
215  m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink,
216  relationshipLabelGuid,
217  relationshipGuid,
219 }
220 
221 void TimelineUtilityMethods::NameEntity(ProfilingGuid entityGuid, const std::string& name)
222 {
224 }
225 
226 void TimelineUtilityMethods::TypeEntity(ProfilingGuid entityGuid, const std::string& type)
227 {
229 }
230 
232  const std::string& entityName,
233  const std::string& entityType)
234 {
235  // Check that the entity name is valid
236  if (entityName.empty())
237  {
238  // The entity name is invalid
239  throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
240  }
241 
242  // Check that the entity type is valid
243  if (entityType.empty())
244  {
245  // The entity type is invalid
246  throw InvalidArgumentException("Invalid entity type, the entity type cannot be empty");
247  }
248 
249  // Create a named type entity from the given name and type, this call throws in case of error
250  ProfilingDynamicGuid childEntityGuid = CreateNamedTypedEntity(entityName, entityType);
251 
252  // Generate a GUID for the retention link relationship
254 
255  // Send the new retention link to the external profiling service, this call throws in case of error
256  m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink,
257  retentionLinkGuid,
258  parentEntityGuid,
259  childEntityGuid);
260 
261  return childEntityGuid;
262 }
263 
265  ProfilingGuid parentEntityGuid,
266  const std::string& entityName,
267  const std::string& entityType)
268 {
269  // Check that the entity name is valid
270  if (entityName.empty())
271  {
272  // The entity name is invalid
273  throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
274  }
275 
276  // Check that the entity type is valid
277  if (entityType.empty())
278  {
279  // The entity type is invalid
280  throw InvalidArgumentException("Invalid entity type, the entity type cannot be empty");
281  }
282 
283  // Create a named type entity from the given guid, name and type, this call throws in case of error
284  CreateNamedTypedEntity(childEntityGuid, entityName, entityType);
285 
286  // Generate a GUID for the retention link relationship
288 
289  // Send the new retention link to the external profiling service, this call throws in case of error
290  m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink,
291  retentionLinkGuid,
292  parentEntityGuid,
293  childEntityGuid);
294 }
295 
297  ProfilingGuid parentEntityGuid,
298  const std::string& entityName,
299  ProfilingStaticGuid typeGuid)
300 {
301  // Check that the entity name is valid
302  if (entityName.empty())
303  {
304  // The entity name is invalid
305  throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
306  }
307 
308  // Create a named type entity from the given guid, name and type, this call throws in case of error
309  CreateNamedTypedEntity(childEntityGuid, entityName, typeGuid);
310 
311  // Generate a GUID for the retention link relationship
313 
314  // Send the new retention link to the external profiling service, this call throws in case of error
315  m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink,
316  retentionLinkGuid,
317  parentEntityGuid,
318  childEntityGuid);
319 }
320 
322  ProfilingGuid headGuid,
323  ProfilingGuid tailGuid)
324 {
325  // Generate a GUID for the relationship
327 
328  // Send the new retention link to the external profiling service, this call throws in case of error
329  m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(relationshipType,
330  relationshipGuid,
331  headGuid,
332  tailGuid);
333  return relationshipGuid;
334 }
335 
337  ProfilingGuid headGuid,
338  ProfilingGuid tailGuid)
339 {
340  // Generate a GUID for the relationship
342 
343  // Send the new retention link to the external profiling service, this call throws in case of error
344  m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(relationshipType,
345  relationshipGuid,
346  headGuid,
347  tailGuid);
348 
350  return relationshipGuid;
351 }
352 
354 {
355  // Send Entity Binary Packet of the entity to the external profiling service
356  m_SendTimelinePacket->SendTimelineEntityBinaryPacket(entityGuid);
357 
358  // Create type entity and send the relationship of the entity with the given type
359  MarkEntityWithType(entityGuid, entityTypeGuid);
360 }
361 
363 {
364  // Take a timestamp
365  uint64_t timestamp = GetTimestamp();
366 
367  // Get the thread id
368  std::thread::id threadId = std::this_thread::get_id();
369 
370  // Generate a GUID for the event
372 
373  // Send the new timeline event to the external profiling service, this call throws in case of error
374  m_SendTimelinePacket->SendTimelineEventBinaryPacket(timestamp, threadId, eventGuid);
375 
376  // Generate a GUID for the execution link
378 
379  // Send the new execution link to the external profiling service, this call throws in case of error
380  m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::ExecutionLink,
381  executionLinkId,
382  entityGuid,
383  eventGuid);
384 
385  // Generate a GUID for the data relationship link
387 
388  // Send the new data relationship link to the external profiling service, this call throws in case of error
389  m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::DataLink,
390  eventClassLinkId,
391  eventGuid,
392  eventClassGuid);
393 
394  return eventGuid;
395 }
396 
398  ProfilingGuid inferenceGuid)
399 {
400  ProfilingDynamicGuid workloadInferenceGuid = ProfilingService::Instance().NextGuid();
402  CreateRelationship(ProfilingRelationshipType::RetentionLink, inferenceGuid, workloadInferenceGuid);
403  CreateRelationship(ProfilingRelationshipType::RetentionLink, workloadGuid, workloadInferenceGuid);
405  return workloadInferenceGuid;
406 }
407 
409 {
411 }
412 
413 } // namespace profiling
414 
415 } // namespace armnn
static ARMNN_DLLEXPORT ProfilingStaticGuid INFERENCE_GUID
ProfilingDynamicGuid RecordWorkloadInferenceAndStartOfLifeEvent(ProfilingGuid workloadGuid, ProfilingGuid inferenceGuid)
static ProfilingService & Instance()
static ARMNN_DLLEXPORT std::string WORKLOAD_EXECUTION
void RecordEndOfLifeEvent(ProfilingGuid entityGuid)
static ARMNN_DLLEXPORT std::string TYPE_LABEL
ProfilingDynamicGuid CreateConnectionRelationship(ProfilingRelationshipType relationshipType, ProfilingGuid headGuid, ProfilingGuid tailGuid)
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
static std::unique_ptr< TimelineUtilityMethods > GetTimelineUtils()
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.
ProfilingDynamicGuid CreateNamedTypedEntity(const std::string &name, const std::string &type)
static ARMNN_DLLEXPORT ProfilingStaticGuid WORKLOAD_GUID
static ARMNN_DLLEXPORT ProfilingStaticGuid WORKLOAD_EXECUTION_GUID
static ARMNN_DLLEXPORT ProfilingStaticGuid ARMNN_PROFILING_EOL_EVENT_CLASS
ProfilingDynamicGuid CreateNamedTypedChildEntity(ProfilingGuid parentEntityGuid, const std::string &entityName, const std::string &entityType)
static ARMNN_DLLEXPORT ProfilingStaticGuid NAME_GUID
static ARMNN_DLLEXPORT ProfilingStaticGuid ARMNN_PROFILING_SOL_EVENT_CLASS
static ARMNN_DLLEXPORT std::string NETWORK
static ARMNN_DLLEXPORT ProfilingStaticGuid LAYER_GUID
void NameEntity(ProfilingGuid entityGuid, const std::string &name)
static ARMNN_DLLEXPORT std::string WORKLOAD
void CreateTypedEntity(ProfilingGuid entityGuid, ProfilingStaticGuid typeGuid)
std::unique_ptr< ISendTimelinePacket > GetSendTimelinePacket() const override
ProfilingDynamicGuid RecordEvent(ProfilingGuid entityGuid, ProfilingStaticGuid eventClassGuid)
static ARMNN_DLLEXPORT std::string INDEX_LABEL
void MarkEntityWithLabel(ProfilingGuid entityGuid, const std::string &labelName, ProfilingStaticGuid labelLinkGuid)
static ARMNN_DLLEXPORT ProfilingStaticGuid NETWORK_GUID
void TypeEntity(ProfilingGuid entityGuid, const std::string &type)
static ARMNN_DLLEXPORT std::string CONNECTION
static ARMNN_DLLEXPORT ProfilingStaticGuid INDEX_GUID
ProfilingStaticGuid DeclareLabel(const std::string &labelName)
static ARMNN_DLLEXPORT ProfilingStaticGuid TYPE_GUID
ProfilingDynamicGuid CreateRelationship(ProfilingRelationshipType relationshipType, ProfilingGuid headGuid, ProfilingGuid tailGuid)
static ARMNN_DLLEXPORT ProfilingStaticGuid BACKENDID_GUID
ProfilingStaticGuid GenerateStaticId(const std::string &str) override
Create a ProfilingStaticGuid based on a hash of the string.
static ARMNN_DLLEXPORT std::string INFERENCE
void MarkEntityWithType(ProfilingGuid entityGuid, ProfilingStaticGuid typeNameGuid)
static ARMNN_DLLEXPORT std::string LAYER