Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 1 | // |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 2 | // Copyright © 2020 Arm Ltd and Contributors. All rights reserved. |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 8 | #include <common/include/ProfilingException.hpp> |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 9 | #include <server/include/timelineDecoder/ITimelineDecoder.hpp> |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 10 | |
| 11 | #include <map> |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 12 | #include <sstream> |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 13 | #include <vector> |
| 14 | |
| 15 | namespace armnn |
| 16 | { |
| 17 | |
| 18 | namespace profiling |
| 19 | { |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 20 | using LabelMap = std::map<uint64_t, arm::pipe::ITimelineDecoder::Label>; |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 21 | using Attribute = std::pair<std::string, std::string>; |
| 22 | using Attributes = std::map<std::string, Attribute>; |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 23 | class Entity; |
| 24 | class Connection |
| 25 | { |
| 26 | public: |
| 27 | Connection(uint64_t guid, Entity* head, Entity* tail) : |
| 28 | m_Guid(guid), m_HeadEntity(head), m_TailEntity(tail) |
| 29 | { |
| 30 | if (head == nullptr) |
| 31 | { |
| 32 | std::stringstream ss; |
| 33 | ss << "connection [" << guid << "] head cannot be null"; |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 34 | throw arm::pipe::ProfilingException(ss.str()); |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 35 | } |
| 36 | if (tail == nullptr) |
| 37 | { |
| 38 | std::stringstream ss; |
| 39 | ss << "connection [" << guid << "] tail cannot be null"; |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 40 | throw arm::pipe::ProfilingException(ss.str()); |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 41 | } |
| 42 | } |
| 43 | |
| 44 | uint64_t GetGuid() const {return m_Guid;} |
| 45 | const Entity* GetHead() const {return m_HeadEntity;} |
| 46 | const Entity* GetTail() const {return m_TailEntity;} |
| 47 | private: |
| 48 | uint64_t m_Guid; |
| 49 | Entity* m_HeadEntity; |
| 50 | Entity* m_TailEntity; |
| 51 | }; |
| 52 | class EventClassObj |
| 53 | { |
| 54 | public: |
| 55 | EventClassObj(uint64_t guid, const std::string& name) : m_Guid(guid), m_Name(name) {} |
| 56 | uint64_t GetGuid() const {return m_Guid;} |
| 57 | const std::string& GetName() const {return m_Name;} |
| 58 | private: |
| 59 | uint64_t m_Guid; |
| 60 | std::string m_Name; |
| 61 | }; |
| 62 | class EventObj |
| 63 | { |
| 64 | public: |
| 65 | EventObj(uint64_t guid, uint64_t timestamp, uint64_t threadId) : |
| 66 | m_Guid(guid), m_TimeStamp(timestamp), m_ThreadId(threadId) {} |
| 67 | uint64_t GetGuid() const {return m_Guid;} |
| 68 | uint64_t GetTimeStamp() const {return m_TimeStamp;} |
| 69 | uint64_t GetThreadId() const {return m_ThreadId;} |
| 70 | void SetEventClass(EventClassObj* evtClass) {m_EventClass = evtClass;} |
| 71 | std::string GetEventClass() |
| 72 | { |
| 73 | if (m_EventClass == nullptr) |
| 74 | { |
| 75 | return ""; |
| 76 | } |
| 77 | else |
| 78 | { |
| 79 | return m_EventClass->GetName(); |
| 80 | } |
| 81 | } |
| 82 | private: |
| 83 | uint64_t m_Guid; |
| 84 | uint64_t m_TimeStamp; |
| 85 | uint64_t m_ThreadId; |
| 86 | EventClassObj* m_EventClass; |
| 87 | }; |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 88 | class Entity |
| 89 | { |
| 90 | public: |
| 91 | Entity(uint64_t guid) : m_Guid(guid) {} |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 92 | uint64_t GetGuid() const {return m_Guid;} |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 93 | void AddChild(Entity* child) |
| 94 | { |
| 95 | if (child != nullptr) |
| 96 | { |
| 97 | m_Children.push_back(child); |
| 98 | } |
| 99 | } |
| 100 | void AddAttribute(const std::string& type, const std::string& value) |
| 101 | { |
| 102 | Attribute attr(type, value); |
| 103 | m_Attributes.emplace(type, attr); |
| 104 | } |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 105 | void AddConnection(const Connection& connection) |
| 106 | { |
| 107 | m_Connections.push_back(connection); |
| 108 | } |
| 109 | void AddExecution(Entity* execution) |
| 110 | { |
| 111 | if (execution != nullptr) |
| 112 | { |
| 113 | m_Executions.push_back(execution); |
| 114 | } |
| 115 | } |
| 116 | void AddEvent(EventObj* event) |
| 117 | { |
| 118 | if (event != nullptr) |
| 119 | { |
| 120 | m_Events.push_back(event); |
| 121 | } |
| 122 | } |
| 123 | const Attributes& GetAttributes() const {return m_Attributes;} |
| 124 | const std::vector<Entity*>& GetChildren() const {return m_Children;} |
| 125 | const std::vector<Connection>& GetConnections() const {return m_Connections;} |
| 126 | const std::vector<Entity*>& GetExecutions() const {return m_Executions;} |
| 127 | const std::vector<EventObj*>& GetEvents() const {return m_Events;} |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 128 | private: |
| 129 | uint64_t m_Guid; |
| 130 | Attributes m_Attributes; |
| 131 | std::vector<Entity*> m_Children; |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 132 | std::vector<Connection> m_Connections; |
| 133 | std::vector<Entity*> m_Executions; |
| 134 | std::vector<EventObj*> m_Events; |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 135 | }; |
| 136 | using Entities = std::map<uint64_t, Entity>; |
| 137 | struct ModelRelationship |
| 138 | { |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 139 | ModelRelationship(const arm::pipe::ITimelineDecoder::Relationship& relationship) : m_Relationship(relationship) {} |
| 140 | arm::pipe::ITimelineDecoder::Relationship m_Relationship; |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 141 | std::vector<Entity*> m_RelatedEntities; |
| 142 | }; |
| 143 | using Relationships = std::map<uint64_t, ModelRelationship>; |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 144 | using EventClasses = std::map<uint64_t, EventClassObj>; |
| 145 | using Events = std::map<uint64_t, EventObj>; |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 146 | class TimelineModel |
| 147 | { |
| 148 | public: |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 149 | void AddLabel(const arm::pipe::ITimelineDecoder::Label& label); |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 150 | std::string* FindLabel(uint64_t guid); |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 151 | void AddEntity(uint64_t guid); |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 152 | Entity* FindEntity(uint64_t id); |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 153 | void AddRelationship(const arm::pipe::ITimelineDecoder::Relationship& relationship); |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 154 | ModelRelationship* FindRelationship(uint64_t id); |
| 155 | const LabelMap& GetLabelMap() const {return m_LabelMap;} |
| 156 | const Entities& GetEntities() const {return m_Entities;} |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 157 | const std::vector<arm::pipe::ProfilingException>& GetErrors() const {return m_Errors;} |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 158 | bool IsInferenceGuid(uint64_t guid) const; |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 159 | void AddEventClass(const arm::pipe::ITimelineDecoder::EventClass& eventClass); |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 160 | const EventClasses& GetEventClasses() const {return m_EventClasses;} |
| 161 | EventClassObj* FindEventClass(uint64_t id); |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 162 | void AddEvent(const arm::pipe::ITimelineDecoder::Event& event); |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 163 | EventObj* FindEvent(uint64_t id); |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 164 | private: |
| 165 | LabelMap m_LabelMap; |
| 166 | Entities m_Entities; |
| 167 | Relationships m_Relationships; |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 168 | std::vector<arm::pipe::ProfilingException> m_Errors; |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 169 | std::vector<uint64_t> m_InferenceGuids; |
| 170 | EventClasses m_EventClasses; |
| 171 | Events m_Events; |
| 172 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 173 | void HandleLabelLink(const arm::pipe::ITimelineDecoder::Relationship& relationship); |
| 174 | void HandleConnection(const arm::pipe::ITimelineDecoder::Relationship& relationship); |
| 175 | void HandleChild(const arm::pipe::ITimelineDecoder::Relationship& relationship); |
| 176 | void HandleExecutionOf(const arm::pipe::ITimelineDecoder::Relationship& relationship); |
| 177 | void HandleExecutionLink(const arm::pipe::ITimelineDecoder::Relationship& relationship); |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 178 | }; |
| 179 | |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 180 | std::vector<std::string> GetModelDescription(const TimelineModel& model); |
| 181 | std::string GetEntityDescription(const Entity& entity); |
| 182 | std::string GetChildDescription(Entity* entity); |
| 183 | std::string GetConnectionDescription(const Connection& connection); |
| 184 | std::string GetExecutionDescription(Entity* execution); |
| 185 | std::string GetEventDescription(EventObj* event); |
| 186 | |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 187 | } // namespace profiling |
| 188 | |
| 189 | } // namespace armnn |