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