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