2 // Copyright © 2019 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
6 #include "TimelineUtilityMethods.hpp"
7 #include "ProfilingService.hpp"
8 #include "LabelsAndEventClasses.hpp"
16 void TimelineUtilityMethods::SendWellKnownLabelsAndEventClasses()
18 // Send the "name" label, this call throws in case of error
19 m_SendTimelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::NAME_GUID,
20 LabelsAndEventClasses::NAME_LABEL);
22 // Send the "type" label, this call throws in case of error
23 m_SendTimelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::TYPE_GUID,
24 LabelsAndEventClasses::TYPE_LABEL);
26 // Send the "index" label, this call throws in case of error
27 m_SendTimelinePacket.SendTimelineLabelBinaryPacket(LabelsAndEventClasses::INDEX_GUID,
28 LabelsAndEventClasses::INDEX_LABEL);
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);
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);
37 ProfilingDynamicGuid TimelineUtilityMethods::CreateNamedTypedEntity(const std::string& name, const std::string& type)
39 // Check that the entity name is valid
42 throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
45 // Check that the entity type is valid
48 throw InvalidArgumentException("Invalid entity type, the entity type cannot be empty");
51 // Generate dynamic GUID of the entity
52 ProfilingDynamicGuid entityGuid = ProfilingService::Instance().NextGuid();
54 // Send Entity Binary Packet of the entity to the external profiling service
55 m_SendTimelinePacket.SendTimelineEntityBinaryPacket(entityGuid);
57 // Create name entity and send the relationship of the entity with the given name
58 NameEntity(entityGuid, name);
60 // Create type entity and send the relationship of the entity with the given type
61 TypeEntity(entityGuid, type);
66 ProfilingStaticGuid TimelineUtilityMethods::DeclareLabel(const std::string& labelName)
68 // Check that the label name is valid
69 if (labelName.empty())
71 // The label name is invalid
72 throw InvalidArgumentException("Invalid label name, the label name cannot be empty");
75 // Generate a static GUID for the given label name
76 ProfilingStaticGuid labelGuid = ProfilingService::Instance().GenerateStaticId(labelName);
78 // Send the new label to the external profiling service, this call throws in case of error
79 m_SendTimelinePacket.SendTimelineLabelBinaryPacket(labelGuid, labelName);
84 void TimelineUtilityMethods::CreateTypedLabel(ProfilingGuid entityGuid,
85 const std::string& entityName,
86 ProfilingStaticGuid labelTypeGuid)
88 // Check that the entity name is valid
89 if (entityName.empty())
91 // The entity name is invalid
92 throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
95 // Declare a label with the entity's name, this call throws in case of error
96 ProfilingStaticGuid labelGuid = DeclareLabel(entityName);
98 // Generate a GUID for the label relationship
99 ProfilingDynamicGuid relationshipGuid = ProfilingService::Instance().NextGuid();
101 // Send the new label link to the external profiling service, this call throws in case of error
102 m_SendTimelinePacket.SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink,
107 // Generate a GUID for the label relationship
108 ProfilingDynamicGuid relationshipLabelGuid = ProfilingService::Instance().NextGuid();
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,
117 void TimelineUtilityMethods::NameEntity(ProfilingGuid entityGuid, const std::string& name)
119 CreateTypedLabel(entityGuid, name, LabelsAndEventClasses::NAME_GUID);
122 void TimelineUtilityMethods::TypeEntity(ProfilingGuid entityGuid, const std::string& type)
124 CreateTypedLabel(entityGuid, type, LabelsAndEventClasses::TYPE_GUID);
127 ProfilingDynamicGuid TimelineUtilityMethods::CreateNamedTypedChildEntity(ProfilingGuid parentEntityGuid,
128 const std::string& entityName,
129 const std::string& entityType)
131 // Check that the entity name is valid
132 if (entityName.empty())
134 // The entity name is invalid
135 throw InvalidArgumentException("Invalid entity name, the entity name cannot be empty");
138 // Check that the entity type is valid
139 if (entityType.empty())
141 // The entity type is invalid
142 throw InvalidArgumentException("Invalid entity type, the entity type cannot be empty");
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);
148 // Generate a GUID for the retention link relationship
149 ProfilingDynamicGuid retentionLinkGuid = ProfilingService::Instance().NextGuid();
151 // Send the new retention link to the external profiling service, this call throws in case of error
152 m_SendTimelinePacket.SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink,
157 return childEntityGuid;
160 } // namespace profiling