• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include <common/include/ProfilingException.hpp>
9 #include <server/include/timelineDecoder/ITimelineDecoder.hpp>
10 
11 #include <map>
12 #include <sstream>
13 #include <vector>
14 
15 namespace arm
16 {
17 
18 namespace pipe
19 {
20 using LabelMap = std::map<uint64_t, arm::pipe::ITimelineDecoder::Label>;
21 using Attribute = std::pair<std::string, std::string>;
22 using Attributes = std::map<std::string, Attribute>;
23 class Entity;
24 class Connection
25 {
26 public:
Connection(uint64_t guid,Entity * head,Entity * tail)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";
34             throw arm::pipe::ProfilingException(ss.str());
35         }
36         if (tail == nullptr)
37         {
38             std::stringstream ss;
39             ss << "connection [" << guid << "] tail cannot be null";
40             throw arm::pipe::ProfilingException(ss.str());
41         }
42     }
43 
GetGuid() const44     uint64_t GetGuid() const {return m_Guid;}
GetHead() const45     const Entity* GetHead() const {return m_HeadEntity;}
GetTail() const46     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:
EventClassObj(uint64_t guid,const std::string & name)55     EventClassObj(uint64_t guid, const std::string& name) : m_Guid(guid), m_Name(name) {}
GetGuid() const56     uint64_t GetGuid() const {return m_Guid;}
GetName() const57     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:
EventObj(uint64_t guid,uint64_t timestamp,uint64_t threadId)65     EventObj(uint64_t guid, uint64_t timestamp, uint64_t threadId) :
66         m_Guid(guid), m_TimeStamp(timestamp), m_ThreadId(threadId) {}
GetGuid() const67     uint64_t GetGuid() const {return m_Guid;}
GetTimeStamp() const68     uint64_t GetTimeStamp() const {return m_TimeStamp;}
GetThreadId() const69     uint64_t GetThreadId() const {return m_ThreadId;}
SetEventClass(EventClassObj * evtClass)70     void SetEventClass(EventClassObj* evtClass) {m_EventClass = evtClass;}
GetEventClass()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 };
88 class Entity
89 {
90 public:
Entity(uint64_t guid)91     Entity(uint64_t guid) : m_Guid(guid) {}
GetGuid() const92     uint64_t GetGuid() const {return m_Guid;}
AddChild(Entity * child)93     void AddChild(Entity* child)
94     {
95         if (child != nullptr)
96         {
97             m_Children.push_back(child);
98         }
99     }
AddAttribute(const std::string & type,const std::string & value)100     void AddAttribute(const std::string& type, const std::string& value)
101     {
102         Attribute attr(type, value);
103         m_Attributes.emplace(type, attr);
104     }
AddConnection(const Connection & connection)105     void AddConnection(const Connection& connection)
106     {
107         m_Connections.push_back(connection);
108     }
AddExecution(Entity * execution)109     void AddExecution(Entity* execution)
110     {
111         if (execution != nullptr)
112         {
113             m_Executions.push_back(execution);
114         }
115     }
AddEvent(EventObj * event)116     void AddEvent(EventObj* event)
117     {
118         if (event != nullptr)
119         {
120             m_Events.push_back(event);
121         }
122     }
GetAttributes() const123     const Attributes& GetAttributes() const {return m_Attributes;}
GetChildren() const124     const std::vector<Entity*>& GetChildren() const {return m_Children;}
GetConnections() const125     const std::vector<Connection>& GetConnections() const {return m_Connections;}
GetExecutions() const126     const std::vector<Entity*>& GetExecutions() const {return m_Executions;}
GetEvents() const127     const std::vector<EventObj*>& GetEvents() const {return m_Events;}
128 private:
129     uint64_t m_Guid;
130     Attributes m_Attributes;
131     std::vector<Entity*> m_Children;
132     std::vector<Connection> m_Connections;
133     std::vector<Entity*> m_Executions;
134     std::vector<EventObj*> m_Events;
135 };
136 using Entities = std::map<uint64_t, Entity>;
137 struct ModelRelationship
138 {
ModelRelationshiparm::pipe::ModelRelationship139     ModelRelationship(const arm::pipe::ITimelineDecoder::Relationship& relationship) : m_Relationship(relationship) {}
140     arm::pipe::ITimelineDecoder::Relationship m_Relationship;
141     std::vector<Entity*> m_RelatedEntities;
142 };
143 using Relationships = std::map<uint64_t, ModelRelationship>;
144 using EventClasses = std::map<uint64_t, EventClassObj>;
145 using Events = std::map<uint64_t, EventObj>;
146 class TimelineModel
147 {
148 public:
149     void AddLabel(const arm::pipe::ITimelineDecoder::Label& label);
150     std::string* FindLabel(uint64_t guid);
151     void AddEntity(uint64_t guid);
152     Entity* FindEntity(uint64_t id);
153     void AddRelationship(const arm::pipe::ITimelineDecoder::Relationship& relationship);
154     ModelRelationship* FindRelationship(uint64_t id);
GetLabelMap() const155     const LabelMap& GetLabelMap() const {return m_LabelMap;}
GetEntities() const156     const Entities& GetEntities() const {return m_Entities;}
GetErrors() const157     const std::vector<arm::pipe::ProfilingException>& GetErrors() const {return m_Errors;}
158     bool IsInferenceGuid(uint64_t guid) const;
159     void AddEventClass(const arm::pipe::ITimelineDecoder::EventClass& eventClass);
GetEventClasses() const160     const EventClasses& GetEventClasses() const {return m_EventClasses;}
161     EventClassObj* FindEventClass(uint64_t id);
162     void AddEvent(const arm::pipe::ITimelineDecoder::Event& event);
163     EventObj* FindEvent(uint64_t id);
164 private:
165     LabelMap m_LabelMap;
166     Entities m_Entities;
167     Relationships m_Relationships;
168     std::vector<arm::pipe::ProfilingException> m_Errors;
169     std::vector<uint64_t> m_InferenceGuids;
170     EventClasses m_EventClasses;
171     Events m_Events;
172 
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);
178 };
179 
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 
187 } // namespace pipe
188 
189 } // namespace arm