blob: e72894a6ab7a05073ffeb743c1f3a8f30bae5e04 [file] [log] [blame]
Matteo Martincigh830101c2019-10-22 11:07:45 +01001//
Jim Flynn6398a982020-05-27 17:05:21 +01002// Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
Matteo Martincigh830101c2019-10-22 11:07:45 +01003// SPDX-License-Identifier: MIT
4//
Matteo Martincigh102cdbd2019-10-28 11:42:50 +00005#include "LabelsAndEventClasses.hpp"
Jim Flynn1fdeb992020-07-09 07:28:37 +01006#include <Threads.hpp>
7#include "TimelineUtilityMethods.hpp"
Matteo Martincigh830101c2019-10-22 11:07:45 +01008
9namespace armnn
10{
11
12namespace profiling
13{
14
Sadik Armagan3184c902020-03-18 10:57:30 +000015std::unique_ptr<TimelineUtilityMethods> TimelineUtilityMethods::GetTimelineUtils(ProfilingService& profilingService)
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +000016{
Keith Davis33ed2212020-03-30 10:43:41 +010017 if (profilingService.GetCurrentState() == ProfilingState::Active && profilingService.IsTimelineReportingEnabled())
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +000018 {
Sadik Armagan3184c902020-03-18 10:57:30 +000019 std::unique_ptr<ISendTimelinePacket> sendTimelinepacket = profilingService.GetSendTimelinePacket();
Sadik Armagan0a356672020-03-20 11:11:01 +000020 return std::make_unique<TimelineUtilityMethods>(sendTimelinepacket);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +000021 }
22 else
23 {
24 std::unique_ptr<TimelineUtilityMethods> empty;
25 return empty;
26 }
27}
28
29
Finn Williamscf2ad552020-03-20 15:10:59 +000030void TimelineUtilityMethods::SendWellKnownLabelsAndEventClasses(ISendTimelinePacket& timelinePacket)
Matteo Martincigh102cdbd2019-10-28 11:42:50 +000031{
32 // Send the "name" label, this call throws in case of error
Finn Williamscf2ad552020-03-20 15:10:59 +000033 timelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::NAME_GUID,
Jim Flynn1892d212020-05-26 21:10:49 +010034 LabelsAndEventClasses::NAME_LABEL);
Matteo Martincigh102cdbd2019-10-28 11:42:50 +000035
36 // Send the "type" label, this call throws in case of error
Finn Williamscf2ad552020-03-20 15:10:59 +000037 timelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::TYPE_GUID,
Jim Flynn1892d212020-05-26 21:10:49 +010038 LabelsAndEventClasses::TYPE_LABEL);
Matteo Martincigh102cdbd2019-10-28 11:42:50 +000039
40 // Send the "index" label, this call throws in case of error
Finn Williamscf2ad552020-03-20 15:10:59 +000041 timelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::INDEX_GUID,
Jim Flynn1892d212020-05-26 21:10:49 +010042 LabelsAndEventClasses::INDEX_LABEL);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +000043
44 // Send the "backendId" label, this call throws in case of error
Finn Williamscf2ad552020-03-20 15:10:59 +000045 timelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::BACKENDID_GUID,
Jim Flynn1892d212020-05-26 21:10:49 +010046 LabelsAndEventClasses::BACKENDID_LABEL);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +000047
Jim Flynn6398a982020-05-27 17:05:21 +010048 // Send the "child" label, this call throws in case of error
49 timelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::CHILD_GUID,
50 LabelsAndEventClasses::CHILD_LABEL);
51
52 // Send the "execution_of" label, this call throws in case of error
53 timelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::EXECUTION_OF_GUID,
54 LabelsAndEventClasses::EXECUTION_OF_LABEL);
55
Jim Flynnf7713212020-07-14 09:50:59 +010056 // Send the "process_id" label, this call throws in case of error
57 timelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::PROCESS_ID_GUID,
58 LabelsAndEventClasses::PROCESS_ID_LABEL);
59
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +000060 // Send the "layer" label, this call throws in case of error
Finn Williamscf2ad552020-03-20 15:10:59 +000061 timelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::LAYER_GUID,
Jim Flynn1892d212020-05-26 21:10:49 +010062 LabelsAndEventClasses::LAYER);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +000063
64 // Send the "workload" label, this call throws in case of error
Finn Williamscf2ad552020-03-20 15:10:59 +000065 timelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::WORKLOAD_GUID,
Jim Flynn1892d212020-05-26 21:10:49 +010066 LabelsAndEventClasses::WORKLOAD);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +000067
68 // Send the "network" label, this call throws in case of error
Finn Williamscf2ad552020-03-20 15:10:59 +000069 timelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::NETWORK_GUID,
Jim Flynn1892d212020-05-26 21:10:49 +010070 LabelsAndEventClasses::NETWORK);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +000071
72 // Send the "connection" label, this call throws in case of error
Finn Williamscf2ad552020-03-20 15:10:59 +000073 timelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::CONNECTION_GUID,
Jim Flynn1892d212020-05-26 21:10:49 +010074 LabelsAndEventClasses::CONNECTION);
Matteo Martincigh102cdbd2019-10-28 11:42:50 +000075
David Monahan6198fe02019-12-02 08:35:43 +000076 // Send the "inference" label, this call throws in case of error
Finn Williamscf2ad552020-03-20 15:10:59 +000077 timelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::INFERENCE_GUID,
Jim Flynn1892d212020-05-26 21:10:49 +010078 LabelsAndEventClasses::INFERENCE);
David Monahan6198fe02019-12-02 08:35:43 +000079
80 // Send the "workload_execution" label, this call throws in case of error
Finn Williamscf2ad552020-03-20 15:10:59 +000081 timelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID,
Jim Flynn1892d212020-05-26 21:10:49 +010082 LabelsAndEventClasses::WORKLOAD_EXECUTION);
David Monahan6198fe02019-12-02 08:35:43 +000083
Matteo Martincigh102cdbd2019-10-28 11:42:50 +000084 // Send the "start of life" event class, this call throws in case of error
Jim Flynn1892d212020-05-26 21:10:49 +010085 timelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS_NAME_GUID,
86 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS_NAME);
87 timelinePacket.SendTimelineEventClassBinaryPacket(LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
88 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS_NAME_GUID);
Matteo Martincigh102cdbd2019-10-28 11:42:50 +000089
90 // Send the "end of life" event class, this call throws in case of error
Jim Flynn1892d212020-05-26 21:10:49 +010091 timelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS_NAME_GUID,
92 LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS_NAME);
93 timelinePacket.SendTimelineEventClassBinaryPacket(LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
94 LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS_NAME_GUID);
Finn Williamscf2ad552020-03-20 15:10:59 +000095
96 timelinePacket.Commit();
Matteo Martincigh102cdbd2019-10-28 11:42:50 +000097}
98
Narumol Prangnawaratd034e082019-10-30 12:48:31 +000099ProfilingDynamicGuid TimelineUtilityMethods::CreateNamedTypedEntity(const std::string& name, const std::string& type)
100{
101 // Check that the entity name is valid
102 if (name.empty())
103 {
104 throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
105 }
106
107 // Check that the entity type is valid
108 if (type.empty())
109 {
110 throw InvalidArgumentException("Invalid entity type, the entity type cannot be empty");
111 }
112
113 // Generate dynamic GUID of the entity
Sadik Armagan0a356672020-03-20 11:11:01 +0000114 ProfilingDynamicGuid entityGuid = profiling::ProfilingService::GetNextGuid();
Narumol Prangnawaratd034e082019-10-30 12:48:31 +0000115
Narumol Prangnawarat234d5252019-11-19 15:49:18 +0000116 CreateNamedTypedEntity(entityGuid, name, type);
117
118 return entityGuid;
119}
120
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000121void TimelineUtilityMethods::CreateNamedTypedEntity(ProfilingGuid entityGuid,
Narumol Prangnawarat234d5252019-11-19 15:49:18 +0000122 const std::string& name,
123 const std::string& type)
124{
125 // Check that the entity name is valid
126 if (name.empty())
127 {
128 throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
129 }
130
131 // Check that the entity type is valid
132 if (type.empty())
133 {
134 throw InvalidArgumentException("Invalid entity type, the entity type cannot be empty");
135 }
136
Narumol Prangnawaratd034e082019-10-30 12:48:31 +0000137 // Send Entity Binary Packet of the entity to the external profiling service
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000138 m_SendTimelinePacket->SendTimelineEntityBinaryPacket(entityGuid);
Narumol Prangnawaratd034e082019-10-30 12:48:31 +0000139
140 // Create name entity and send the relationship of the entity with the given name
141 NameEntity(entityGuid, name);
142
143 // Create type entity and send the relationship of the entity with the given type
144 TypeEntity(entityGuid, type);
Narumol Prangnawaratd034e082019-10-30 12:48:31 +0000145}
146
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000147void TimelineUtilityMethods::CreateNamedTypedEntity(ProfilingGuid entityGuid,
148 const std::string& name,
149 ProfilingStaticGuid typeGuid)
150{
151 // Check that the entity name is valid
152 if (name.empty())
153 {
154 throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
155 }
156
157 // Send Entity Binary Packet of the entity to the external profiling service
158 m_SendTimelinePacket->SendTimelineEntityBinaryPacket(entityGuid);
159
160 // Create name entity and send the relationship of the entity with the given name
161 NameEntity(entityGuid, name);
162
163 // Create type entity and send the relationship of the entity with the given type
164 MarkEntityWithType(entityGuid, typeGuid);
165}
166
Matteo Martincigh830101c2019-10-22 11:07:45 +0100167ProfilingStaticGuid TimelineUtilityMethods::DeclareLabel(const std::string& labelName)
168{
169 // Check that the label name is valid
170 if (labelName.empty())
171 {
172 // The label name is invalid
173 throw InvalidArgumentException("Invalid label name, the label name cannot be empty");
174 }
175
176 // Generate a static GUID for the given label name
Sadik Armagan0a356672020-03-20 11:11:01 +0000177 ProfilingStaticGuid labelGuid = profiling::ProfilingService::GetStaticId(labelName);
Matteo Martincigh830101c2019-10-22 11:07:45 +0100178
179 // Send the new label to the external profiling service, this call throws in case of error
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000180 m_SendTimelinePacket->SendTimelineLabelBinaryPacket(labelGuid, labelName);
Matteo Martincigh830101c2019-10-22 11:07:45 +0100181
182 return labelGuid;
183}
184
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000185void TimelineUtilityMethods::MarkEntityWithLabel(ProfilingGuid entityGuid,
186 const std::string& labelName,
187 ProfilingStaticGuid labelTypeGuid)
Matteo Martincighc0401992019-10-28 15:24:34 +0000188{
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000189 // Check that the label name is valid
190 if (labelName.empty())
Matteo Martincighc0401992019-10-28 15:24:34 +0000191 {
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000192 // The label name is invalid
Matteo Martincighc0401992019-10-28 15:24:34 +0000193 throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
194 }
195
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000196 // Declare a label with the label's name, this call throws in case of error
197 ProfilingStaticGuid labelGuid = DeclareLabel(labelName);
Matteo Martincighc0401992019-10-28 15:24:34 +0000198
199 // Generate a GUID for the label relationship
Sadik Armagan0a356672020-03-20 11:11:01 +0000200 ProfilingDynamicGuid relationshipGuid = profiling::ProfilingService::GetNextGuid();
Matteo Martincighc0401992019-10-28 15:24:34 +0000201
202 // Send the new label link to the external profiling service, this call throws in case of error
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000203 m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink,
204 relationshipGuid,
205 entityGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100206 labelGuid,
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000207 labelTypeGuid);
208}
209
210void TimelineUtilityMethods::MarkEntityWithType(ProfilingGuid entityGuid,
211 ProfilingStaticGuid typeNameGuid)
212{
213 // Generate a GUID for the label relationship
Sadik Armagan0a356672020-03-20 11:11:01 +0000214 ProfilingDynamicGuid relationshipGuid = profiling::ProfilingService::GetNextGuid();
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000215
216 // Send the new label link to the external profiling service, this call throws in case of error
217 m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink,
218 relationshipGuid,
219 entityGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100220 typeNameGuid,
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000221 LabelsAndEventClasses::TYPE_GUID);
Matteo Martincighc0401992019-10-28 15:24:34 +0000222}
223
Narumol Prangnawaratd034e082019-10-30 12:48:31 +0000224void TimelineUtilityMethods::NameEntity(ProfilingGuid entityGuid, const std::string& name)
225{
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000226 MarkEntityWithLabel(entityGuid, name, LabelsAndEventClasses::NAME_GUID);
Narumol Prangnawaratd034e082019-10-30 12:48:31 +0000227}
228
229void TimelineUtilityMethods::TypeEntity(ProfilingGuid entityGuid, const std::string& type)
230{
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000231 MarkEntityWithLabel(entityGuid, type, LabelsAndEventClasses::TYPE_GUID);
Narumol Prangnawaratd034e082019-10-30 12:48:31 +0000232}
233
Narumol Prangnawarat94a30882019-10-30 12:48:31 +0000234ProfilingDynamicGuid TimelineUtilityMethods::CreateNamedTypedChildEntity(ProfilingGuid parentEntityGuid,
235 const std::string& entityName,
236 const std::string& entityType)
237{
238 // Check that the entity name is valid
239 if (entityName.empty())
240 {
241 // The entity name is invalid
242 throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
243 }
244
245 // Check that the entity type is valid
246 if (entityType.empty())
247 {
248 // The entity type is invalid
249 throw InvalidArgumentException("Invalid entity type, the entity type cannot be empty");
250 }
251
252 // Create a named type entity from the given name and type, this call throws in case of error
253 ProfilingDynamicGuid childEntityGuid = CreateNamedTypedEntity(entityName, entityType);
254
255 // Generate a GUID for the retention link relationship
Sadik Armagan0a356672020-03-20 11:11:01 +0000256 ProfilingDynamicGuid retentionLinkGuid = profiling::ProfilingService::GetNextGuid();
Narumol Prangnawarat94a30882019-10-30 12:48:31 +0000257
258 // Send the new retention link to the external profiling service, this call throws in case of error
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000259 m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink,
260 retentionLinkGuid,
261 parentEntityGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100262 childEntityGuid,
263 LabelsAndEventClasses::EMPTY_GUID);
Narumol Prangnawarat94a30882019-10-30 12:48:31 +0000264
265 return childEntityGuid;
266}
267
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000268void TimelineUtilityMethods::CreateNamedTypedChildEntity(ProfilingGuid childEntityGuid,
Narumol Prangnawarat234d5252019-11-19 15:49:18 +0000269 ProfilingGuid parentEntityGuid,
270 const std::string& entityName,
271 const std::string& entityType)
272{
273 // Check that the entity name is valid
274 if (entityName.empty())
275 {
276 // The entity name is invalid
277 throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
278 }
279
280 // Check that the entity type is valid
281 if (entityType.empty())
282 {
283 // The entity type is invalid
284 throw InvalidArgumentException("Invalid entity type, the entity type cannot be empty");
285 }
286
287 // Create a named type entity from the given guid, name and type, this call throws in case of error
288 CreateNamedTypedEntity(childEntityGuid, entityName, entityType);
289
290 // Generate a GUID for the retention link relationship
Sadik Armagan0a356672020-03-20 11:11:01 +0000291 ProfilingDynamicGuid retentionLinkGuid = profiling::ProfilingService::GetNextGuid();
Narumol Prangnawarat234d5252019-11-19 15:49:18 +0000292
293 // Send the new retention link to the external profiling service, this call throws in case of error
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000294 m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink,
295 retentionLinkGuid,
296 parentEntityGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100297 childEntityGuid,
Jim Flynn6398a982020-05-27 17:05:21 +0100298 LabelsAndEventClasses::CHILD_GUID);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000299}
300
301void TimelineUtilityMethods::CreateNamedTypedChildEntity(ProfilingGuid childEntityGuid,
302 ProfilingGuid parentEntityGuid,
303 const std::string& entityName,
304 ProfilingStaticGuid typeGuid)
305{
306 // Check that the entity name is valid
307 if (entityName.empty())
308 {
309 // The entity name is invalid
310 throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
311 }
312
313 // Create a named type entity from the given guid, name and type, this call throws in case of error
314 CreateNamedTypedEntity(childEntityGuid, entityName, typeGuid);
315
316 // Generate a GUID for the retention link relationship
Sadik Armagan0a356672020-03-20 11:11:01 +0000317 ProfilingDynamicGuid retentionLinkGuid = profiling::ProfilingService::GetNextGuid();
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000318
319 // Send the new retention link to the external profiling service, this call throws in case of error
320 m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink,
321 retentionLinkGuid,
322 parentEntityGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100323 childEntityGuid,
Jim Flynn6398a982020-05-27 17:05:21 +0100324 LabelsAndEventClasses::CHILD_GUID);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000325}
326
327ProfilingDynamicGuid TimelineUtilityMethods::CreateRelationship(ProfilingRelationshipType relationshipType,
328 ProfilingGuid headGuid,
Jim Flynn6398a982020-05-27 17:05:21 +0100329 ProfilingGuid tailGuid,
330 ProfilingGuid relationshipCategory)
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000331{
332 // Generate a GUID for the relationship
Sadik Armagan0a356672020-03-20 11:11:01 +0000333 ProfilingDynamicGuid relationshipGuid = profiling::ProfilingService::GetNextGuid();
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000334
335 // Send the new retention link to the external profiling service, this call throws in case of error
336 m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(relationshipType,
337 relationshipGuid,
338 headGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100339 tailGuid,
Jim Flynn6398a982020-05-27 17:05:21 +0100340 relationshipCategory);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000341 return relationshipGuid;
342}
343
344ProfilingDynamicGuid TimelineUtilityMethods::CreateConnectionRelationship(ProfilingRelationshipType relationshipType,
345 ProfilingGuid headGuid,
346 ProfilingGuid tailGuid)
347{
348 // Generate a GUID for the relationship
Sadik Armagan0a356672020-03-20 11:11:01 +0000349 ProfilingDynamicGuid relationshipGuid = profiling::ProfilingService::GetNextGuid();
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000350
351 // Send the new retention link to the external profiling service, this call throws in case of error
352 m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(relationshipType,
353 relationshipGuid,
354 headGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100355 tailGuid,
Jim Flynn6398a982020-05-27 17:05:21 +0100356 LabelsAndEventClasses::CONNECTION_GUID);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000357 return relationshipGuid;
358}
359
360void TimelineUtilityMethods::CreateTypedEntity(ProfilingGuid entityGuid, ProfilingStaticGuid entityTypeGuid)
361{
362 // Send Entity Binary Packet of the entity to the external profiling service
363 m_SendTimelinePacket->SendTimelineEntityBinaryPacket(entityGuid);
364
365 // Create type entity and send the relationship of the entity with the given type
366 MarkEntityWithType(entityGuid, entityTypeGuid);
Narumol Prangnawarat234d5252019-11-19 15:49:18 +0000367}
368
Matteo Martincigh5dc816e2019-11-04 14:05:28 +0000369ProfilingDynamicGuid TimelineUtilityMethods::RecordEvent(ProfilingGuid entityGuid, ProfilingStaticGuid eventClassGuid)
370{
371 // Take a timestamp
372 uint64_t timestamp = GetTimestamp();
373
374 // Get the thread id
Jim Flynn1fdeb992020-07-09 07:28:37 +0100375 int threadId = armnnUtils::Threads::GetCurrentThreadId();
Matteo Martincigh5dc816e2019-11-04 14:05:28 +0000376
377 // Generate a GUID for the event
Sadik Armagan0a356672020-03-20 11:11:01 +0000378 ProfilingDynamicGuid eventGuid = profiling::ProfilingService::GetNextGuid();
Matteo Martincigh5dc816e2019-11-04 14:05:28 +0000379
380 // Send the new timeline event to the external profiling service, this call throws in case of error
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000381 m_SendTimelinePacket->SendTimelineEventBinaryPacket(timestamp, threadId, eventGuid);
Matteo Martincigh5dc816e2019-11-04 14:05:28 +0000382
383 // Generate a GUID for the execution link
Sadik Armagan0a356672020-03-20 11:11:01 +0000384 ProfilingDynamicGuid executionLinkId = profiling::ProfilingService::GetNextGuid();
Matteo Martincigh5dc816e2019-11-04 14:05:28 +0000385
386 // Send the new execution link to the external profiling service, this call throws in case of error
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000387 m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::ExecutionLink,
388 executionLinkId,
389 entityGuid,
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000390 eventGuid,
391 eventClassGuid);
Matteo Martincigh5dc816e2019-11-04 14:05:28 +0000392
393 return eventGuid;
394}
395
David Monahan6198fe02019-12-02 08:35:43 +0000396ProfilingDynamicGuid TimelineUtilityMethods::RecordWorkloadInferenceAndStartOfLifeEvent(ProfilingGuid workloadGuid,
397 ProfilingGuid inferenceGuid)
398{
Sadik Armagan0a356672020-03-20 11:11:01 +0000399 ProfilingDynamicGuid workloadInferenceGuid = profiling::ProfilingService::GetNextGuid();
David Monahan6198fe02019-12-02 08:35:43 +0000400 CreateTypedEntity(workloadInferenceGuid, LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID);
Jim Flynn6398a982020-05-27 17:05:21 +0100401 CreateRelationship(ProfilingRelationshipType::RetentionLink,
402 inferenceGuid,
403 workloadInferenceGuid,
404 LabelsAndEventClasses::CHILD_GUID);
405 CreateRelationship(ProfilingRelationshipType::RetentionLink,
406 workloadGuid,
407 workloadInferenceGuid,
408 LabelsAndEventClasses::EXECUTION_OF_GUID);
David Monahan6198fe02019-12-02 08:35:43 +0000409 RecordEvent(workloadInferenceGuid, LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS);
410 return workloadInferenceGuid;
411}
412
413void TimelineUtilityMethods::RecordEndOfLifeEvent(ProfilingGuid entityGuid)
414{
415 RecordEvent(entityGuid, LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS);
416}
417
Matteo Martincigh830101c2019-10-22 11:07:45 +0100418} // namespace profiling
419
420} // namespace armnn