blob: bc8e7b6ce8e81d7be7c33ab231f77dfcf03bceee [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//
Jim Flynn1fdeb992020-07-09 07:28:37 +01005#include "TimelineUtilityMethods.hpp"
Matteo Martincigh830101c2019-10-22 11:07:45 +01006
Nikhil Raj77fe76b2021-06-09 14:55:32 +01007#include <common/include/LabelsAndEventClasses.hpp>
8
Nikhil Raj7dcc6972021-04-30 15:44:24 +01009
Rob Hughes9542f902021-07-14 09:48:54 +010010#include <armnnUtils/Threads.hpp>
Nikhil Raj7dcc6972021-04-30 15:44:24 +010011
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000012namespace arm
Matteo Martincigh830101c2019-10-22 11:07:45 +010013{
14
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000015namespace pipe
Matteo Martincigh830101c2019-10-22 11:07:45 +010016{
17
Sadik Armagan3184c902020-03-18 10:57:30 +000018std::unique_ptr<TimelineUtilityMethods> TimelineUtilityMethods::GetTimelineUtils(ProfilingService& profilingService)
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +000019{
Keith Davis33ed2212020-03-30 10:43:41 +010020 if (profilingService.GetCurrentState() == ProfilingState::Active && profilingService.IsTimelineReportingEnabled())
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +000021 {
Sadik Armagan3184c902020-03-18 10:57:30 +000022 std::unique_ptr<ISendTimelinePacket> sendTimelinepacket = profilingService.GetSendTimelinePacket();
Sadik Armagan0a356672020-03-20 11:11:01 +000023 return std::make_unique<TimelineUtilityMethods>(sendTimelinepacket);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +000024 }
25 else
26 {
27 std::unique_ptr<TimelineUtilityMethods> empty;
28 return empty;
29 }
30}
31
32
Finn Williamscf2ad552020-03-20 15:10:59 +000033void TimelineUtilityMethods::SendWellKnownLabelsAndEventClasses(ISendTimelinePacket& timelinePacket)
Matteo Martincigh102cdbd2019-10-28 11:42:50 +000034{
35 // Send the "name" label, this call throws in case of error
Finn Williamscf2ad552020-03-20 15:10:59 +000036 timelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::NAME_GUID,
Jim Flynn1892d212020-05-26 21:10:49 +010037 LabelsAndEventClasses::NAME_LABEL);
Matteo Martincigh102cdbd2019-10-28 11:42:50 +000038
39 // Send the "type" label, this call throws in case of error
Finn Williamscf2ad552020-03-20 15:10:59 +000040 timelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::TYPE_GUID,
Jim Flynn1892d212020-05-26 21:10:49 +010041 LabelsAndEventClasses::TYPE_LABEL);
Matteo Martincigh102cdbd2019-10-28 11:42:50 +000042
43 // Send the "index" label, this call throws in case of error
Finn Williamscf2ad552020-03-20 15:10:59 +000044 timelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::INDEX_GUID,
Jim Flynn1892d212020-05-26 21:10:49 +010045 LabelsAndEventClasses::INDEX_LABEL);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +000046
47 // Send the "backendId" label, this call throws in case of error
Finn Williamscf2ad552020-03-20 15:10:59 +000048 timelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::BACKENDID_GUID,
Jim Flynn1892d212020-05-26 21:10:49 +010049 LabelsAndEventClasses::BACKENDID_LABEL);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +000050
Jim Flynn6398a982020-05-27 17:05:21 +010051 // Send the "child" label, this call throws in case of error
52 timelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::CHILD_GUID,
53 LabelsAndEventClasses::CHILD_LABEL);
54
55 // Send the "execution_of" label, this call throws in case of error
56 timelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::EXECUTION_OF_GUID,
57 LabelsAndEventClasses::EXECUTION_OF_LABEL);
58
Jim Flynnf7713212020-07-14 09:50:59 +010059 // Send the "process_id" label, this call throws in case of error
60 timelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::PROCESS_ID_GUID,
61 LabelsAndEventClasses::PROCESS_ID_LABEL);
62
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +000063 // Send the "layer" label, this call throws in case of error
Finn Williamscf2ad552020-03-20 15:10:59 +000064 timelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::LAYER_GUID,
Jim Flynn1892d212020-05-26 21:10:49 +010065 LabelsAndEventClasses::LAYER);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +000066
67 // Send the "workload" label, this call throws in case of error
Finn Williamscf2ad552020-03-20 15:10:59 +000068 timelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::WORKLOAD_GUID,
Jim Flynn1892d212020-05-26 21:10:49 +010069 LabelsAndEventClasses::WORKLOAD);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +000070
71 // Send the "network" label, this call throws in case of error
Finn Williamscf2ad552020-03-20 15:10:59 +000072 timelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::NETWORK_GUID,
Jim Flynn1892d212020-05-26 21:10:49 +010073 LabelsAndEventClasses::NETWORK);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +000074
75 // Send the "connection" label, this call throws in case of error
Finn Williamscf2ad552020-03-20 15:10:59 +000076 timelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::CONNECTION_GUID,
Jim Flynn1892d212020-05-26 21:10:49 +010077 LabelsAndEventClasses::CONNECTION);
Matteo Martincigh102cdbd2019-10-28 11:42:50 +000078
David Monahan6198fe02019-12-02 08:35:43 +000079 // Send the "inference" label, this call throws in case of error
Finn Williamscf2ad552020-03-20 15:10:59 +000080 timelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::INFERENCE_GUID,
Jim Flynn1892d212020-05-26 21:10:49 +010081 LabelsAndEventClasses::INFERENCE);
David Monahan6198fe02019-12-02 08:35:43 +000082
83 // Send the "workload_execution" label, this call throws in case of error
Finn Williamscf2ad552020-03-20 15:10:59 +000084 timelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID,
Jim Flynn1892d212020-05-26 21:10:49 +010085 LabelsAndEventClasses::WORKLOAD_EXECUTION);
David Monahan6198fe02019-12-02 08:35:43 +000086
Matteo Martincigh102cdbd2019-10-28 11:42:50 +000087 // Send the "start of life" event class, this call throws in case of error
Jim Flynn1892d212020-05-26 21:10:49 +010088 timelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS_NAME_GUID,
89 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS_NAME);
90 timelinePacket.SendTimelineEventClassBinaryPacket(LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
91 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS_NAME_GUID);
Matteo Martincigh102cdbd2019-10-28 11:42:50 +000092
93 // Send the "end of life" event class, this call throws in case of error
Jim Flynn1892d212020-05-26 21:10:49 +010094 timelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS_NAME_GUID,
95 LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS_NAME);
96 timelinePacket.SendTimelineEventClassBinaryPacket(LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
97 LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS_NAME_GUID);
Finn Williamscf2ad552020-03-20 15:10:59 +000098
99 timelinePacket.Commit();
Matteo Martincigh102cdbd2019-10-28 11:42:50 +0000100}
101
Narumol Prangnawaratd034e082019-10-30 12:48:31 +0000102ProfilingDynamicGuid TimelineUtilityMethods::CreateNamedTypedEntity(const std::string& name, const std::string& type)
103{
104 // Check that the entity name is valid
105 if (name.empty())
106 {
107 throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
108 }
109
110 // Check that the entity type is valid
111 if (type.empty())
112 {
113 throw InvalidArgumentException("Invalid entity type, the entity type cannot be empty");
114 }
115
116 // Generate dynamic GUID of the entity
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000117 ProfilingDynamicGuid entityGuid = ProfilingService::GetNextGuid();
Narumol Prangnawaratd034e082019-10-30 12:48:31 +0000118
Narumol Prangnawarat234d5252019-11-19 15:49:18 +0000119 CreateNamedTypedEntity(entityGuid, name, type);
120
121 return entityGuid;
122}
123
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000124void TimelineUtilityMethods::CreateNamedTypedEntity(ProfilingGuid entityGuid,
Narumol Prangnawarat234d5252019-11-19 15:49:18 +0000125 const std::string& name,
126 const std::string& type)
127{
128 // Check that the entity name is valid
129 if (name.empty())
130 {
131 throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
132 }
133
134 // Check that the entity type is valid
135 if (type.empty())
136 {
137 throw InvalidArgumentException("Invalid entity type, the entity type cannot be empty");
138 }
139
Narumol Prangnawaratd034e082019-10-30 12:48:31 +0000140 // Send Entity Binary Packet of the entity to the external profiling service
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000141 m_SendTimelinePacket->SendTimelineEntityBinaryPacket(entityGuid);
Narumol Prangnawaratd034e082019-10-30 12:48:31 +0000142
143 // Create name entity and send the relationship of the entity with the given name
144 NameEntity(entityGuid, name);
145
146 // Create type entity and send the relationship of the entity with the given type
147 TypeEntity(entityGuid, type);
Narumol Prangnawaratd034e082019-10-30 12:48:31 +0000148}
149
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000150void TimelineUtilityMethods::CreateNamedTypedEntity(ProfilingGuid entityGuid,
151 const std::string& name,
152 ProfilingStaticGuid typeGuid)
153{
154 // Check that the entity name is valid
155 if (name.empty())
156 {
157 throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
158 }
159
160 // Send Entity Binary Packet of the entity to the external profiling service
161 m_SendTimelinePacket->SendTimelineEntityBinaryPacket(entityGuid);
162
163 // Create name entity and send the relationship of the entity with the given name
164 NameEntity(entityGuid, name);
165
166 // Create type entity and send the relationship of the entity with the given type
167 MarkEntityWithType(entityGuid, typeGuid);
168}
169
Matteo Martincigh830101c2019-10-22 11:07:45 +0100170ProfilingStaticGuid TimelineUtilityMethods::DeclareLabel(const std::string& labelName)
171{
172 // Check that the label name is valid
173 if (labelName.empty())
174 {
175 // The label name is invalid
176 throw InvalidArgumentException("Invalid label name, the label name cannot be empty");
177 }
178
179 // Generate a static GUID for the given label name
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000180 ProfilingStaticGuid labelGuid = ProfilingService::GetStaticId(labelName);
Matteo Martincigh830101c2019-10-22 11:07:45 +0100181
182 // Send the new label to the external profiling service, this call throws in case of error
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000183 m_SendTimelinePacket->SendTimelineLabelBinaryPacket(labelGuid, labelName);
Matteo Martincigh830101c2019-10-22 11:07:45 +0100184
185 return labelGuid;
186}
187
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000188void TimelineUtilityMethods::MarkEntityWithLabel(ProfilingGuid entityGuid,
189 const std::string& labelName,
190 ProfilingStaticGuid labelTypeGuid)
Matteo Martincighc0401992019-10-28 15:24:34 +0000191{
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000192 // Check that the label name is valid
193 if (labelName.empty())
Matteo Martincighc0401992019-10-28 15:24:34 +0000194 {
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000195 // The label name is invalid
Matteo Martincighc0401992019-10-28 15:24:34 +0000196 throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
197 }
198
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000199 // Declare a label with the label's name, this call throws in case of error
200 ProfilingStaticGuid labelGuid = DeclareLabel(labelName);
Matteo Martincighc0401992019-10-28 15:24:34 +0000201
202 // Generate a GUID for the label relationship
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000203 ProfilingDynamicGuid relationshipGuid = ProfilingService::GetNextGuid();
Matteo Martincighc0401992019-10-28 15:24:34 +0000204
205 // Send the new label link to the external profiling service, this call throws in case of error
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000206 m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink,
207 relationshipGuid,
208 entityGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100209 labelGuid,
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000210 labelTypeGuid);
211}
212
213void TimelineUtilityMethods::MarkEntityWithType(ProfilingGuid entityGuid,
214 ProfilingStaticGuid typeNameGuid)
215{
216 // Generate a GUID for the label relationship
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000217 ProfilingDynamicGuid relationshipGuid = ProfilingService::GetNextGuid();
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000218
219 // Send the new label link to the external profiling service, this call throws in case of error
220 m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink,
221 relationshipGuid,
222 entityGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100223 typeNameGuid,
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000224 LabelsAndEventClasses::TYPE_GUID);
Matteo Martincighc0401992019-10-28 15:24:34 +0000225}
226
Narumol Prangnawaratd034e082019-10-30 12:48:31 +0000227void TimelineUtilityMethods::NameEntity(ProfilingGuid entityGuid, const std::string& name)
228{
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000229 MarkEntityWithLabel(entityGuid, name, LabelsAndEventClasses::NAME_GUID);
Narumol Prangnawaratd034e082019-10-30 12:48:31 +0000230}
231
232void TimelineUtilityMethods::TypeEntity(ProfilingGuid entityGuid, const std::string& type)
233{
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000234 MarkEntityWithLabel(entityGuid, type, LabelsAndEventClasses::TYPE_GUID);
Narumol Prangnawaratd034e082019-10-30 12:48:31 +0000235}
236
Narumol Prangnawarat94a30882019-10-30 12:48:31 +0000237ProfilingDynamicGuid TimelineUtilityMethods::CreateNamedTypedChildEntity(ProfilingGuid parentEntityGuid,
238 const std::string& entityName,
239 const std::string& entityType)
240{
241 // Check that the entity name is valid
242 if (entityName.empty())
243 {
244 // The entity name is invalid
245 throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
246 }
247
248 // Check that the entity type is valid
249 if (entityType.empty())
250 {
251 // The entity type is invalid
252 throw InvalidArgumentException("Invalid entity type, the entity type cannot be empty");
253 }
254
255 // Create a named type entity from the given name and type, this call throws in case of error
256 ProfilingDynamicGuid childEntityGuid = CreateNamedTypedEntity(entityName, entityType);
257
258 // Generate a GUID for the retention link relationship
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000259 ProfilingDynamicGuid retentionLinkGuid = ProfilingService::GetNextGuid();
Narumol Prangnawarat94a30882019-10-30 12:48:31 +0000260
261 // Send the new retention link to the external profiling service, this call throws in case of error
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000262 m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink,
263 retentionLinkGuid,
264 parentEntityGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100265 childEntityGuid,
266 LabelsAndEventClasses::EMPTY_GUID);
Narumol Prangnawarat94a30882019-10-30 12:48:31 +0000267
268 return childEntityGuid;
269}
270
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000271void TimelineUtilityMethods::CreateNamedTypedChildEntity(ProfilingGuid childEntityGuid,
Narumol Prangnawarat234d5252019-11-19 15:49:18 +0000272 ProfilingGuid parentEntityGuid,
273 const std::string& entityName,
274 const std::string& entityType)
275{
276 // Check that the entity name is valid
277 if (entityName.empty())
278 {
279 // The entity name is invalid
280 throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
281 }
282
283 // Check that the entity type is valid
284 if (entityType.empty())
285 {
286 // The entity type is invalid
287 throw InvalidArgumentException("Invalid entity type, the entity type cannot be empty");
288 }
289
290 // Create a named type entity from the given guid, name and type, this call throws in case of error
291 CreateNamedTypedEntity(childEntityGuid, entityName, entityType);
292
293 // Generate a GUID for the retention link relationship
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000294 ProfilingDynamicGuid retentionLinkGuid = ProfilingService::GetNextGuid();
Narumol Prangnawarat234d5252019-11-19 15:49:18 +0000295
296 // Send the new retention link to the external profiling service, this call throws in case of error
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000297 m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink,
298 retentionLinkGuid,
299 parentEntityGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100300 childEntityGuid,
Jim Flynn6398a982020-05-27 17:05:21 +0100301 LabelsAndEventClasses::CHILD_GUID);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000302}
303
304void TimelineUtilityMethods::CreateNamedTypedChildEntity(ProfilingGuid childEntityGuid,
305 ProfilingGuid parentEntityGuid,
306 const std::string& entityName,
307 ProfilingStaticGuid typeGuid)
308{
309 // Check that the entity name is valid
310 if (entityName.empty())
311 {
312 // The entity name is invalid
313 throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
314 }
315
316 // Create a named type entity from the given guid, name and type, this call throws in case of error
317 CreateNamedTypedEntity(childEntityGuid, entityName, typeGuid);
318
319 // Generate a GUID for the retention link relationship
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000320 ProfilingDynamicGuid retentionLinkGuid = ProfilingService::GetNextGuid();
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000321
322 // Send the new retention link to the external profiling service, this call throws in case of error
323 m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink,
324 retentionLinkGuid,
325 parentEntityGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100326 childEntityGuid,
Jim Flynn6398a982020-05-27 17:05:21 +0100327 LabelsAndEventClasses::CHILD_GUID);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000328}
329
330ProfilingDynamicGuid TimelineUtilityMethods::CreateRelationship(ProfilingRelationshipType relationshipType,
331 ProfilingGuid headGuid,
Jim Flynn6398a982020-05-27 17:05:21 +0100332 ProfilingGuid tailGuid,
333 ProfilingGuid relationshipCategory)
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000334{
335 // Generate a GUID for the relationship
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000336 ProfilingDynamicGuid relationshipGuid = ProfilingService::GetNextGuid();
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000337
338 // Send the new retention link to the external profiling service, this call throws in case of error
339 m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(relationshipType,
340 relationshipGuid,
341 headGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100342 tailGuid,
Jim Flynn6398a982020-05-27 17:05:21 +0100343 relationshipCategory);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000344 return relationshipGuid;
345}
346
347ProfilingDynamicGuid TimelineUtilityMethods::CreateConnectionRelationship(ProfilingRelationshipType relationshipType,
348 ProfilingGuid headGuid,
349 ProfilingGuid tailGuid)
350{
351 // Generate a GUID for the relationship
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000352 ProfilingDynamicGuid relationshipGuid = ProfilingService::GetNextGuid();
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000353
354 // Send the new retention link to the external profiling service, this call throws in case of error
355 m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(relationshipType,
356 relationshipGuid,
357 headGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100358 tailGuid,
Jim Flynn6398a982020-05-27 17:05:21 +0100359 LabelsAndEventClasses::CONNECTION_GUID);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000360 return relationshipGuid;
361}
362
363void TimelineUtilityMethods::CreateTypedEntity(ProfilingGuid entityGuid, ProfilingStaticGuid entityTypeGuid)
364{
365 // Send Entity Binary Packet of the entity to the external profiling service
366 m_SendTimelinePacket->SendTimelineEntityBinaryPacket(entityGuid);
367
368 // Create type entity and send the relationship of the entity with the given type
369 MarkEntityWithType(entityGuid, entityTypeGuid);
Narumol Prangnawarat234d5252019-11-19 15:49:18 +0000370}
371
Matteo Martincigh5dc816e2019-11-04 14:05:28 +0000372ProfilingDynamicGuid TimelineUtilityMethods::RecordEvent(ProfilingGuid entityGuid, ProfilingStaticGuid eventClassGuid)
373{
374 // Take a timestamp
375 uint64_t timestamp = GetTimestamp();
376
377 // Get the thread id
Jim Flynn1fdeb992020-07-09 07:28:37 +0100378 int threadId = armnnUtils::Threads::GetCurrentThreadId();
Matteo Martincigh5dc816e2019-11-04 14:05:28 +0000379
380 // Generate a GUID for the event
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000381 ProfilingDynamicGuid eventGuid = ProfilingService::GetNextGuid();
Matteo Martincigh5dc816e2019-11-04 14:05:28 +0000382
383 // Send the new timeline event to the external profiling service, this call throws in case of error
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000384 m_SendTimelinePacket->SendTimelineEventBinaryPacket(timestamp, threadId, eventGuid);
Matteo Martincigh5dc816e2019-11-04 14:05:28 +0000385
386 // Generate a GUID for the execution link
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000387 ProfilingDynamicGuid executionLinkId = ProfilingService::GetNextGuid();
Matteo Martincigh5dc816e2019-11-04 14:05:28 +0000388
389 // Send the new execution link to the external profiling service, this call throws in case of error
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000390 m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::ExecutionLink,
391 executionLinkId,
392 entityGuid,
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000393 eventGuid,
394 eventClassGuid);
Matteo Martincigh5dc816e2019-11-04 14:05:28 +0000395
396 return eventGuid;
397}
398
David Monahan6198fe02019-12-02 08:35:43 +0000399ProfilingDynamicGuid TimelineUtilityMethods::RecordWorkloadInferenceAndStartOfLifeEvent(ProfilingGuid workloadGuid,
400 ProfilingGuid inferenceGuid)
401{
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000402 ProfilingDynamicGuid workloadInferenceGuid = ProfilingService::GetNextGuid();
David Monahan6198fe02019-12-02 08:35:43 +0000403 CreateTypedEntity(workloadInferenceGuid, LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID);
Jim Flynn6398a982020-05-27 17:05:21 +0100404 CreateRelationship(ProfilingRelationshipType::RetentionLink,
405 inferenceGuid,
406 workloadInferenceGuid,
407 LabelsAndEventClasses::CHILD_GUID);
408 CreateRelationship(ProfilingRelationshipType::RetentionLink,
409 workloadGuid,
410 workloadInferenceGuid,
411 LabelsAndEventClasses::EXECUTION_OF_GUID);
David Monahan6198fe02019-12-02 08:35:43 +0000412 RecordEvent(workloadInferenceGuid, LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS);
413 return workloadInferenceGuid;
414}
415
416void TimelineUtilityMethods::RecordEndOfLifeEvent(ProfilingGuid entityGuid)
417{
418 RecordEvent(entityGuid, LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS);
419}
420
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000421} // namespace pipe
Matteo Martincigh830101c2019-10-22 11:07:45 +0100422
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000423} // namespace arm