ArmNN
 20.05
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 
8 
9 namespace armnn
10 {
11 
12 namespace profiling
13 {
14 
16 {
17  if (profilingService.GetCurrentState() == ProfilingState::Active && profilingService.IsTimelineReportingEnabled())
18  {
19  std::unique_ptr<ISendTimelinePacket> sendTimelinepacket = profilingService.GetSendTimelinePacket();
20  return std::make_unique<TimelineUtilityMethods>(sendTimelinepacket);
21  }
22  else
23  {
24  std::unique_ptr<TimelineUtilityMethods> empty;
25  return empty;
26  }
27 }
28 
29 
31 {
32  // Send the "name" label, this call throws in case of error
35 
36  // Send the "type" label, this call throws in case of error
39 
40  // Send the "index" label, this call throws in case of error
43 
44  // Send the "backendId" label, this call throws in case of error
47 
48  // Send the "layer" label, this call throws in case of error
51 
52  // Send the "workload" label, this call throws in case of error
55 
56  // Send the "network" label, this call throws in case of error
59 
60  // Send the "connection" label, this call throws in case of error
63 
64  // Send the "inference" label, this call throws in case of error
67 
68  // Send the "workload_execution" label, this call throws in case of error
71 
72  // Send the "start of life" event class, this call throws in case of error
74 
75  // Send the "end of life" event class, this call throws in case of error
77 
78  timelinePacket.Commit();
79 }
80 
81 ProfilingDynamicGuid TimelineUtilityMethods::CreateNamedTypedEntity(const std::string& name, const std::string& type)
82 {
83  // Check that the entity name is valid
84  if (name.empty())
85  {
86  throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
87  }
88 
89  // Check that the entity type is valid
90  if (type.empty())
91  {
92  throw InvalidArgumentException("Invalid entity type, the entity type cannot be empty");
93  }
94 
95  // Generate dynamic GUID of the entity
97 
98  CreateNamedTypedEntity(entityGuid, name, type);
99 
100  return entityGuid;
101 }
102 
104  const std::string& name,
105  const std::string& type)
106 {
107  // Check that the entity name is valid
108  if (name.empty())
109  {
110  throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
111  }
112 
113  // Check that the entity type is valid
114  if (type.empty())
115  {
116  throw InvalidArgumentException("Invalid entity type, the entity type cannot be empty");
117  }
118 
119  // Send Entity Binary Packet of the entity to the external profiling service
120  m_SendTimelinePacket->SendTimelineEntityBinaryPacket(entityGuid);
121 
122  // Create name entity and send the relationship of the entity with the given name
123  NameEntity(entityGuid, name);
124 
125  // Create type entity and send the relationship of the entity with the given type
126  TypeEntity(entityGuid, type);
127 }
128 
130  const std::string& name,
131  ProfilingStaticGuid typeGuid)
132 {
133  // Check that the entity name is valid
134  if (name.empty())
135  {
136  throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
137  }
138 
139  // Send Entity Binary Packet of the entity to the external profiling service
140  m_SendTimelinePacket->SendTimelineEntityBinaryPacket(entityGuid);
141 
142  // Create name entity and send the relationship of the entity with the given name
143  NameEntity(entityGuid, name);
144 
145  // Create type entity and send the relationship of the entity with the given type
146  MarkEntityWithType(entityGuid, typeGuid);
147 }
148 
150 {
151  // Check that the label name is valid
152  if (labelName.empty())
153  {
154  // The label name is invalid
155  throw InvalidArgumentException("Invalid label name, the label name cannot be empty");
156  }
157 
158  // Generate a static GUID for the given label name
160 
161  // Send the new label to the external profiling service, this call throws in case of error
162  m_SendTimelinePacket->SendTimelineLabelBinaryPacket(labelGuid, labelName);
163 
164  return labelGuid;
165 }
166 
168  const std::string& labelName,
169  ProfilingStaticGuid labelTypeGuid)
170 {
171  // Check that the label name is valid
172  if (labelName.empty())
173  {
174  // The label name is invalid
175  throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
176  }
177 
178  // Declare a label with the label's name, this call throws in case of error
179  ProfilingStaticGuid labelGuid = DeclareLabel(labelName);
180 
181  // Generate a GUID for the label relationship
183 
184  // Send the new label link to the external profiling service, this call throws in case of error
185  m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink,
186  relationshipGuid,
187  entityGuid,
188  labelGuid);
189 
190  // Generate a GUID for the label relationship
192 
193  // Send the new label link to the external profiling service, this call throws in case of error
194  m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink,
195  relationshipLabelGuid,
196  relationshipGuid,
197  labelTypeGuid);
198 }
199 
201  ProfilingStaticGuid typeNameGuid)
202 {
203  // Generate a GUID for the label relationship
205 
206  // Send the new label link to the external profiling service, this call throws in case of error
207  m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink,
208  relationshipGuid,
209  entityGuid,
210  typeNameGuid);
211 
212  // Generate a GUID for the label relationship
214 
215  // Send the new label link to the external profiling service, this call throws in case of error
216  m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink,
217  relationshipLabelGuid,
218  relationshipGuid,
220 }
221 
222 void TimelineUtilityMethods::NameEntity(ProfilingGuid entityGuid, const std::string& name)
223 {
225 }
226 
227 void TimelineUtilityMethods::TypeEntity(ProfilingGuid entityGuid, const std::string& type)
228 {
230 }
231 
233  const std::string& entityName,
234  const std::string& entityType)
235 {
236  // Check that the entity name is valid
237  if (entityName.empty())
238  {
239  // The entity name is invalid
240  throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
241  }
242 
243  // Check that the entity type is valid
244  if (entityType.empty())
245  {
246  // The entity type is invalid
247  throw InvalidArgumentException("Invalid entity type, the entity type cannot be empty");
248  }
249 
250  // Create a named type entity from the given name and type, this call throws in case of error
251  ProfilingDynamicGuid childEntityGuid = CreateNamedTypedEntity(entityName, entityType);
252 
253  // Generate a GUID for the retention link relationship
255 
256  // Send the new retention link to the external profiling service, this call throws in case of error
257  m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink,
258  retentionLinkGuid,
259  parentEntityGuid,
260  childEntityGuid);
261 
262  return childEntityGuid;
263 }
264 
266  ProfilingGuid parentEntityGuid,
267  const std::string& entityName,
268  const std::string& entityType)
269 {
270  // Check that the entity name is valid
271  if (entityName.empty())
272  {
273  // The entity name is invalid
274  throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
275  }
276 
277  // Check that the entity type is valid
278  if (entityType.empty())
279  {
280  // The entity type is invalid
281  throw InvalidArgumentException("Invalid entity type, the entity type cannot be empty");
282  }
283 
284  // Create a named type entity from the given guid, name and type, this call throws in case of error
285  CreateNamedTypedEntity(childEntityGuid, entityName, entityType);
286 
287  // Generate a GUID for the retention link relationship
289 
290  // Send the new retention link to the external profiling service, this call throws in case of error
291  m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink,
292  retentionLinkGuid,
293  parentEntityGuid,
294  childEntityGuid);
295 }
296 
298  ProfilingGuid parentEntityGuid,
299  const std::string& entityName,
300  ProfilingStaticGuid typeGuid)
301 {
302  // Check that the entity name is valid
303  if (entityName.empty())
304  {
305  // The entity name is invalid
306  throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
307  }
308 
309  // Create a named type entity from the given guid, name and type, this call throws in case of error
310  CreateNamedTypedEntity(childEntityGuid, entityName, typeGuid);
311 
312  // Generate a GUID for the retention link relationship
314 
315  // Send the new retention link to the external profiling service, this call throws in case of error
316  m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink,
317  retentionLinkGuid,
318  parentEntityGuid,
319  childEntityGuid);
320 }
321 
323  ProfilingGuid headGuid,
324  ProfilingGuid tailGuid)
325 {
326  // Generate a GUID for the relationship
328 
329  // Send the new retention link to the external profiling service, this call throws in case of error
330  m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(relationshipType,
331  relationshipGuid,
332  headGuid,
333  tailGuid);
334  return relationshipGuid;
335 }
336 
338  ProfilingGuid headGuid,
339  ProfilingGuid tailGuid)
340 {
341  // Generate a GUID for the relationship
343 
344  // Send the new retention link to the external profiling service, this call throws in case of error
345  m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(relationshipType,
346  relationshipGuid,
347  headGuid,
348  tailGuid);
349 
351  return relationshipGuid;
352 }
353 
355 {
356  // Send Entity Binary Packet of the entity to the external profiling service
357  m_SendTimelinePacket->SendTimelineEntityBinaryPacket(entityGuid);
358 
359  // Create type entity and send the relationship of the entity with the given type
360  MarkEntityWithType(entityGuid, entityTypeGuid);
361 }
362 
364 {
365  // Take a timestamp
366  uint64_t timestamp = GetTimestamp();
367 
368  // Get the thread id
369  std::thread::id threadId = std::this_thread::get_id();
370 
371  // Generate a GUID for the event
373 
374  // Send the new timeline event to the external profiling service, this call throws in case of error
375  m_SendTimelinePacket->SendTimelineEventBinaryPacket(timestamp, threadId, eventGuid);
376 
377  // Generate a GUID for the execution link
379 
380  // Send the new execution link to the external profiling service, this call throws in case of error
381  m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::ExecutionLink,
382  executionLinkId,
383  entityGuid,
384  eventGuid);
385 
386  // Generate a GUID for the data relationship link
388 
389  // Send the new data relationship link to the external profiling service, this call throws in case of error
390  m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::DataLink,
391  eventClassLinkId,
392  eventGuid,
393  eventClassGuid);
394 
395  return eventGuid;
396 }
397 
399  ProfilingGuid inferenceGuid)
400 {
403  CreateRelationship(ProfilingRelationshipType::RetentionLink, inferenceGuid, workloadInferenceGuid);
404  CreateRelationship(ProfilingRelationshipType::RetentionLink, workloadGuid, workloadInferenceGuid);
406  return workloadInferenceGuid;
407 }
408 
410 {
412 }
413 
414 } // namespace profiling
415 
416 } // namespace armnn
static ARMNN_DLLEXPORT ProfilingStaticGuid INFERENCE_GUID
ProfilingDynamicGuid RecordWorkloadInferenceAndStartOfLifeEvent(ProfilingGuid workloadGuid, ProfilingGuid inferenceGuid)
static ARMNN_DLLEXPORT std::string WORKLOAD_EXECUTION
void RecordEndOfLifeEvent(ProfilingGuid entityGuid)
static ARMNN_DLLEXPORT std::string TYPE_LABEL
ProfilingState GetCurrentState() const
static std::unique_ptr< TimelineUtilityMethods > GetTimelineUtils(ProfilingService &profilingService)
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:296
virtual void SendTimelineLabelBinaryPacket(uint64_t profilingGuid, const std::string &label)=0
Create and write a TimelineLabelBinaryPacket from the parameters to the buffer.
static ARMNN_DLLEXPORT std::string NAME_LABEL
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 CreateNamedTypedEntity(const std::string &name, const std::string &type)
static ARMNN_DLLEXPORT ProfilingStaticGuid WORKLOAD_GUID
static ARMNN_DLLEXPORT ProfilingStaticGuid WORKLOAD_EXECUTION_GUID
virtual void Commit()=0
Commits the current buffer and reset the member variables.
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
static ProfilingStaticGuid GetStaticId(const std::string &str)
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
armnn::profiling::ProfilingService profilingService
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
virtual void SendTimelineEventClassBinaryPacket(uint64_t profilingGuid)=0
Create and write a TimelineEventClassBinaryPacket from the parameters to the buffer.
static ProfilingDynamicGuid GetNextGuid()
static void SendWellKnownLabelsAndEventClasses(ISendTimelinePacket &timelinePacket)
ProfilingDynamicGuid CreateRelationship(ProfilingRelationshipType relationshipType, ProfilingGuid headGuid, ProfilingGuid tailGuid)
static ARMNN_DLLEXPORT ProfilingStaticGuid BACKENDID_GUID
static ARMNN_DLLEXPORT std::string INFERENCE
void MarkEntityWithType(ProfilingGuid entityGuid, ProfilingStaticGuid typeNameGuid)
static ARMNN_DLLEXPORT std::string LAYER