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