blob: c1ae610e49a88e8fdbeb2ae2612550b0a52a0d24 [file] [log] [blame]
Matteo Martincigh830101c2019-10-22 11:07:45 +01001//
2// Copyright © 2019 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "TimelineUtilityMethods.hpp"
7#include "ProfilingService.hpp"
Matteo Martincigh102cdbd2019-10-28 11:42:50 +00008#include "LabelsAndEventClasses.hpp"
Matteo Martincigh830101c2019-10-22 11:07:45 +01009
10namespace armnn
11{
12
13namespace profiling
14{
15
Matteo Martincigh102cdbd2019-10-28 11:42:50 +000016void TimelineUtilityMethods::SendWellKnownLabelsAndEventClasses()
17{
18 // Send the "name" label, this call throws in case of error
19 m_SendTimelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::NAME_GUID,
20 LabelsAndEventClasses::NAME_LABEL);
21
22 // Send the "type" label, this call throws in case of error
23 m_SendTimelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::TYPE_GUID,
24 LabelsAndEventClasses::TYPE_LABEL);
25
26 // Send the "index" label, this call throws in case of error
27 m_SendTimelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::INDEX_GUID,
28 LabelsAndEventClasses::INDEX_LABEL);
29
30 // Send the "start of life" event class, this call throws in case of error
31 m_SendTimelinePacket.SendTimelineEventClassBinaryPacket(LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS);
32
33 // Send the "end of life" event class, this call throws in case of error
34 m_SendTimelinePacket.SendTimelineEventClassBinaryPacket(LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS);
35}
36
Narumol Prangnawaratd034e082019-10-30 12:48:31 +000037ProfilingDynamicGuid TimelineUtilityMethods::CreateNamedTypedEntity(const std::string& name, const std::string& type)
38{
39 // Check that the entity name is valid
40 if (name.empty())
41 {
42 throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
43 }
44
45 // Check that the entity type is valid
46 if (type.empty())
47 {
48 throw InvalidArgumentException("Invalid entity type, the entity type cannot be empty");
49 }
50
51 // Generate dynamic GUID of the entity
52 ProfilingDynamicGuid entityGuid = ProfilingService::Instance().NextGuid();
53
Narumol Prangnawarat234d5252019-11-19 15:49:18 +000054 CreateNamedTypedEntity(entityGuid, name, type);
55
56 return entityGuid;
57}
58
59void TimelineUtilityMethods::CreateNamedTypedEntity(ProfilingDynamicGuid entityGuid,
60 const std::string& name,
61 const std::string& type)
62{
63 // Check that the entity name is valid
64 if (name.empty())
65 {
66 throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
67 }
68
69 // Check that the entity type is valid
70 if (type.empty())
71 {
72 throw InvalidArgumentException("Invalid entity type, the entity type cannot be empty");
73 }
74
Narumol Prangnawaratd034e082019-10-30 12:48:31 +000075 // Send Entity Binary Packet of the entity to the external profiling service
76 m_SendTimelinePacket.SendTimelineEntityBinaryPacket(entityGuid);
77
78 // Create name entity and send the relationship of the entity with the given name
79 NameEntity(entityGuid, name);
80
81 // Create type entity and send the relationship of the entity with the given type
82 TypeEntity(entityGuid, type);
Narumol Prangnawaratd034e082019-10-30 12:48:31 +000083}
84
Matteo Martincigh830101c2019-10-22 11:07:45 +010085ProfilingStaticGuid TimelineUtilityMethods::DeclareLabel(const std::string& labelName)
86{
87 // Check that the label name is valid
88 if (labelName.empty())
89 {
90 // The label name is invalid
91 throw InvalidArgumentException("Invalid label name, the label name cannot be empty");
92 }
93
94 // Generate a static GUID for the given label name
95 ProfilingStaticGuid labelGuid = ProfilingService::Instance().GenerateStaticId(labelName);
96
97 // Send the new label to the external profiling service, this call throws in case of error
98 m_SendTimelinePacket.SendTimelineLabelBinaryPacket(labelGuid, labelName);
99
100 return labelGuid;
101}
102
Matteo Martincighc0401992019-10-28 15:24:34 +0000103void TimelineUtilityMethods::CreateTypedLabel(ProfilingGuid entityGuid,
104 const std::string& entityName,
105 ProfilingStaticGuid labelTypeGuid)
106{
107 // Check that the entity name is valid
108 if (entityName.empty())
109 {
110 // The entity name is invalid
111 throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
112 }
113
114 // Declare a label with the entity's name, this call throws in case of error
Narumol Prangnawarat94a30882019-10-30 12:48:31 +0000115 ProfilingStaticGuid labelGuid = DeclareLabel(entityName);
Matteo Martincighc0401992019-10-28 15:24:34 +0000116
117 // Generate a GUID for the label relationship
Narumol Prangnawarat94a30882019-10-30 12:48:31 +0000118 ProfilingDynamicGuid relationshipGuid = ProfilingService::Instance().NextGuid();
Matteo Martincighc0401992019-10-28 15:24:34 +0000119
120 // Send the new label link to the external profiling service, this call throws in case of error
121 m_SendTimelinePacket.SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink,
122 relationshipGuid,
123 entityGuid,
124 labelGuid);
125
126 // Generate a GUID for the label relationship
Narumol Prangnawarat94a30882019-10-30 12:48:31 +0000127 ProfilingDynamicGuid relationshipLabelGuid = ProfilingService::Instance().NextGuid();
Matteo Martincighc0401992019-10-28 15:24:34 +0000128
129 // Send the new label link to the external profiling service, this call throws in case of error
130 m_SendTimelinePacket.SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink,
131 relationshipLabelGuid,
132 relationshipGuid,
133 labelTypeGuid);
134}
135
Narumol Prangnawaratd034e082019-10-30 12:48:31 +0000136void TimelineUtilityMethods::NameEntity(ProfilingGuid entityGuid, const std::string& name)
137{
138 CreateTypedLabel(entityGuid, name, LabelsAndEventClasses::NAME_GUID);
139}
140
141void TimelineUtilityMethods::TypeEntity(ProfilingGuid entityGuid, const std::string& type)
142{
143 CreateTypedLabel(entityGuid, type, LabelsAndEventClasses::TYPE_GUID);
144}
145
Narumol Prangnawarat94a30882019-10-30 12:48:31 +0000146ProfilingDynamicGuid TimelineUtilityMethods::CreateNamedTypedChildEntity(ProfilingGuid parentEntityGuid,
147 const std::string& entityName,
148 const std::string& entityType)
149{
150 // Check that the entity name is valid
151 if (entityName.empty())
152 {
153 // The entity name is invalid
154 throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
155 }
156
157 // Check that the entity type is valid
158 if (entityType.empty())
159 {
160 // The entity type is invalid
161 throw InvalidArgumentException("Invalid entity type, the entity type cannot be empty");
162 }
163
164 // Create a named type entity from the given name and type, this call throws in case of error
165 ProfilingDynamicGuid childEntityGuid = CreateNamedTypedEntity(entityName, entityType);
166
167 // Generate a GUID for the retention link relationship
168 ProfilingDynamicGuid retentionLinkGuid = ProfilingService::Instance().NextGuid();
169
170 // Send the new retention link to the external profiling service, this call throws in case of error
171 m_SendTimelinePacket.SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink,
172 retentionLinkGuid,
173 parentEntityGuid,
174 childEntityGuid);
175
176 return childEntityGuid;
177}
178
Narumol Prangnawarat234d5252019-11-19 15:49:18 +0000179void TimelineUtilityMethods::CreateNamedTypedChildEntity(ProfilingDynamicGuid childEntityGuid,
180 ProfilingGuid parentEntityGuid,
181 const std::string& entityName,
182 const std::string& entityType)
183{
184 // Check that the entity name is valid
185 if (entityName.empty())
186 {
187 // The entity name is invalid
188 throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
189 }
190
191 // Check that the entity type is valid
192 if (entityType.empty())
193 {
194 // The entity type is invalid
195 throw InvalidArgumentException("Invalid entity type, the entity type cannot be empty");
196 }
197
198 // Create a named type entity from the given guid, name and type, this call throws in case of error
199 CreateNamedTypedEntity(childEntityGuid, entityName, entityType);
200
201 // Generate a GUID for the retention link relationship
202 ProfilingDynamicGuid retentionLinkGuid = ProfilingService::Instance().NextGuid();
203
204 // Send the new retention link to the external profiling service, this call throws in case of error
205 m_SendTimelinePacket.SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink,
206 retentionLinkGuid,
207 parentEntityGuid,
208 childEntityGuid);
209}
210
Matteo Martincigh5dc816e2019-11-04 14:05:28 +0000211ProfilingDynamicGuid TimelineUtilityMethods::RecordEvent(ProfilingGuid entityGuid, ProfilingStaticGuid eventClassGuid)
212{
213 // Take a timestamp
214 uint64_t timestamp = GetTimestamp();
215
216 // Get the thread id
217 std::thread::id threadId = std::this_thread::get_id();
218
219 // Generate a GUID for the event
220 ProfilingDynamicGuid eventGuid = ProfilingService::Instance().NextGuid();
221
222 // Send the new timeline event to the external profiling service, this call throws in case of error
223 m_SendTimelinePacket.SendTimelineEventBinaryPacket(timestamp, threadId, eventGuid);
224
225 // Generate a GUID for the execution link
226 ProfilingDynamicGuid executionLinkId = ProfilingService::Instance().NextGuid();
227
228 // Send the new execution link to the external profiling service, this call throws in case of error
229 m_SendTimelinePacket.SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::ExecutionLink,
230 executionLinkId,
231 entityGuid,
232 eventGuid);
233
234 // Generate a GUID for the data relationship link
235 ProfilingDynamicGuid eventClassLinkId = ProfilingService::Instance().NextGuid();
236
237 // Send the new data relationship link to the external profiling service, this call throws in case of error
238 m_SendTimelinePacket.SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::DataLink,
239 eventClassLinkId,
240 entityGuid,
241 eventClassGuid);
242
243 return eventGuid;
244}
245
Matteo Martincigh830101c2019-10-22 11:07:45 +0100246} // namespace profiling
247
248} // namespace armnn