blob: 65668697f74a87b7d79ed3974491b0f63c0501a9 [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
54 // Send Entity Binary Packet of the entity to the external profiling service
55 m_SendTimelinePacket.SendTimelineEntityBinaryPacket(entityGuid);
56
57 // Create name entity and send the relationship of the entity with the given name
58 NameEntity(entityGuid, name);
59
60 // Create type entity and send the relationship of the entity with the given type
61 TypeEntity(entityGuid, type);
62
63 return entityGuid;
64}
65
Matteo Martincigh830101c2019-10-22 11:07:45 +010066ProfilingStaticGuid TimelineUtilityMethods::DeclareLabel(const std::string& labelName)
67{
68 // Check that the label name is valid
69 if (labelName.empty())
70 {
71 // The label name is invalid
72 throw InvalidArgumentException("Invalid label name, the label name cannot be empty");
73 }
74
75 // Generate a static GUID for the given label name
76 ProfilingStaticGuid labelGuid = ProfilingService::Instance().GenerateStaticId(labelName);
77
78 // Send the new label to the external profiling service, this call throws in case of error
79 m_SendTimelinePacket.SendTimelineLabelBinaryPacket(labelGuid, labelName);
80
81 return labelGuid;
82}
83
Matteo Martincighc0401992019-10-28 15:24:34 +000084void TimelineUtilityMethods::CreateTypedLabel(ProfilingGuid entityGuid,
85 const std::string& entityName,
86 ProfilingStaticGuid labelTypeGuid)
87{
88 // Check that the entity name is valid
89 if (entityName.empty())
90 {
91 // The entity name is invalid
92 throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
93 }
94
95 // Declare a label with the entity's name, this call throws in case of error
Narumol Prangnawarat94a30882019-10-30 12:48:31 +000096 ProfilingStaticGuid labelGuid = DeclareLabel(entityName);
Matteo Martincighc0401992019-10-28 15:24:34 +000097
98 // Generate a GUID for the label relationship
Narumol Prangnawarat94a30882019-10-30 12:48:31 +000099 ProfilingDynamicGuid relationshipGuid = ProfilingService::Instance().NextGuid();
Matteo Martincighc0401992019-10-28 15:24:34 +0000100
101 // Send the new label link to the external profiling service, this call throws in case of error
102 m_SendTimelinePacket.SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink,
103 relationshipGuid,
104 entityGuid,
105 labelGuid);
106
107 // Generate a GUID for the label relationship
Narumol Prangnawarat94a30882019-10-30 12:48:31 +0000108 ProfilingDynamicGuid relationshipLabelGuid = ProfilingService::Instance().NextGuid();
Matteo Martincighc0401992019-10-28 15:24:34 +0000109
110 // Send the new label link to the external profiling service, this call throws in case of error
111 m_SendTimelinePacket.SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink,
112 relationshipLabelGuid,
113 relationshipGuid,
114 labelTypeGuid);
115}
116
Narumol Prangnawaratd034e082019-10-30 12:48:31 +0000117void TimelineUtilityMethods::NameEntity(ProfilingGuid entityGuid, const std::string& name)
118{
119 CreateTypedLabel(entityGuid, name, LabelsAndEventClasses::NAME_GUID);
120}
121
122void TimelineUtilityMethods::TypeEntity(ProfilingGuid entityGuid, const std::string& type)
123{
124 CreateTypedLabel(entityGuid, type, LabelsAndEventClasses::TYPE_GUID);
125}
126
Narumol Prangnawarat94a30882019-10-30 12:48:31 +0000127ProfilingDynamicGuid TimelineUtilityMethods::CreateNamedTypedChildEntity(ProfilingGuid parentEntityGuid,
128 const std::string& entityName,
129 const std::string& entityType)
130{
131 // Check that the entity name is valid
132 if (entityName.empty())
133 {
134 // The entity name is invalid
135 throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
136 }
137
138 // Check that the entity type is valid
139 if (entityType.empty())
140 {
141 // The entity type is invalid
142 throw InvalidArgumentException("Invalid entity type, the entity type cannot be empty");
143 }
144
145 // Create a named type entity from the given name and type, this call throws in case of error
146 ProfilingDynamicGuid childEntityGuid = CreateNamedTypedEntity(entityName, entityType);
147
148 // Generate a GUID for the retention link relationship
149 ProfilingDynamicGuid retentionLinkGuid = ProfilingService::Instance().NextGuid();
150
151 // Send the new retention link to the external profiling service, this call throws in case of error
152 m_SendTimelinePacket.SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink,
153 retentionLinkGuid,
154 parentEntityGuid,
155 childEntityGuid);
156
157 return childEntityGuid;
158}
159
Matteo Martincigh830101c2019-10-22 11:07:45 +0100160} // namespace profiling
161
162} // namespace armnn