8 #include <client/src/ProfilingUtils.hpp>
14 namespace timelinedecoder
17 static const char *
const CONNECTION =
"connection";
18 static const char *
const BACKEND_ID =
"backendId";
19 static const char *
const NAME =
"name";
20 static const char *
const TYPE =
"type";
21 static const char *
const WORKLOAD =
"workload";
22 static const char *
const WORKLOAD_EXECUTION =
"workload_execution";
23 static const char *
const INFERENCE =
"inference";
24 static const char *
const LAYER =
"layer";
25 static const char *
const ENTITY =
"Entity";
26 static const char *
const EVENTCLASS =
"EventClass";
27 static const char *
const EVENT =
"Event";
33 this->m_Model.
jsonEntities.insert({entity.m_Guid, jsonEntity});
34 return TimelineStatus::TimelineStatus_Success;
41 this->m_Model.
eventClasses.insert({eventClass.m_Guid, eventClass});
42 this->m_Model.
jsonEntities.insert({eventClass.m_Guid, jsonEntity});
43 return TimelineStatus::TimelineStatus_Success;
50 this->m_Model.
events.insert({
event.m_Guid,
event});
52 return TimelineStatus::TimelineStatus_Success;
57 this->m_Model.
labels.insert({label.m_Guid, label});
58 return TimelineStatus::TimelineStatus_Success;
63 if (relationship.m_RelationshipType == ITimelineDecoder::RelationshipType::RetentionLink)
65 HandleRetentionLink(relationship);
67 else if (relationship.m_RelationshipType == ITimelineDecoder::RelationshipType::LabelLink)
69 HandleLabelLink(relationship);
71 else if (relationship.m_RelationshipType == ITimelineDecoder::RelationshipType::ExecutionLink)
73 HandleExecutionLink(relationship);
77 m_Model.
relationships.insert({relationship.m_Guid, relationship});
80 return TimelineStatus::TimelineStatus_Success;
84 void JSONTimelineDecoder::HandleExecutionLink(
const ITimelineDecoder::Relationship& relationship)
86 uint64_t tailGuid = relationship.m_TailGuid;
87 uint64_t headGuid = relationship.m_HeadGuid;
89 if (m_Model.
jsonEntities.count(relationship.m_HeadGuid) != 0)
91 JSONEntity& tailJSONEntity = m_Model.
jsonEntities.at(tailGuid);
92 JSONEntity& headJSONEntity = m_Model.
jsonEntities.at(headGuid);
93 tailJSONEntity.SetParent(headJSONEntity);
95 m_Model.
relationships.insert({relationship.m_Guid, relationship});
99 m_Model.
relationships.insert({relationship.m_Guid, relationship});
103 void JSONTimelineDecoder::HandleLabelLink(
const ITimelineDecoder::Relationship& relationship)
105 if (m_Model.
labels.count(relationship.m_TailGuid) != 0)
107 if (m_Model.
labels.at(relationship.m_TailGuid).m_Name == CONNECTION)
109 HandleConnectionLabel(relationship);
111 else if (m_Model.
labels.at(relationship.m_TailGuid).m_Name == BACKEND_ID)
113 HandleBackendIdLabel(relationship);
115 else if (m_Model.
labels.at(relationship.m_TailGuid).m_Name == NAME)
117 HandleNameLabel(relationship);
119 else if (m_Model.
labels.at(relationship.m_TailGuid).m_Name == TYPE)
121 HandleTypeLabel(relationship);
125 m_Model.
relationships.insert({relationship.m_Guid, relationship});
129 m_Model.
relationships.insert({relationship.m_Guid, relationship});
133 void JSONTimelineDecoder::HandleTypeLabel(
const ITimelineDecoder::Relationship& relationship)
135 if (m_Model.
relationships.count(relationship.m_HeadGuid) != 0)
137 Relationship labelRelation = m_Model.
relationships.at(relationship.m_HeadGuid);
138 if (m_Model.
jsonEntities.count(labelRelation.m_HeadGuid) != 0)
140 JSONEntity& headEntity = m_Model.
jsonEntities.at(labelRelation.m_HeadGuid);
141 std::string type = m_Model.
labels.at(labelRelation.m_TailGuid).m_Name;
142 headEntity.SetType(type);
147 m_Model.
relationships.insert({relationship.m_Guid, relationship});
151 void JSONTimelineDecoder::HandleNameLabel(
const ITimelineDecoder::Relationship& relationship)
153 if (m_Model.
relationships.count(relationship.m_HeadGuid) != 0)
155 Relationship labelRelation = m_Model.
relationships.at(relationship.m_HeadGuid);
156 JSONEntity& headEntity = m_Model.
jsonEntities.at(labelRelation.m_HeadGuid);
157 std::string name = m_Model.
labels.at(labelRelation.m_TailGuid).m_Name;
158 headEntity.SetName(name);
162 m_Model.
relationships.insert({relationship.m_Guid, relationship});
166 void JSONTimelineDecoder::HandleBackendIdLabel(
const ITimelineDecoder::Relationship& relationship)
168 if (m_Model.
relationships.count(relationship.m_HeadGuid) != 0)
170 Relationship labelRelation = m_Model.
relationships.at(relationship.m_HeadGuid);
171 JSONEntity& headEntity = m_Model.
jsonEntities.at(labelRelation.m_HeadGuid);
172 std::string backendName = m_Model.
labels.at(labelRelation.m_TailGuid).m_Name;
173 headEntity.extendedData.insert({BACKEND_ID, backendName});
177 m_Model.
relationships.insert({relationship.m_Guid, relationship});
181 void JSONTimelineDecoder::HandleConnectionLabel(
const ITimelineDecoder::Relationship& relationship)
183 if (m_Model.
relationships.count(relationship.m_HeadGuid) != 0)
185 Relationship retentionRelation = m_Model.
relationships.at(relationship.m_HeadGuid);
186 JSONEntity& headEntity = m_Model.
jsonEntities.at(retentionRelation.m_HeadGuid);
187 JSONEntity& tailEntity = m_Model.
jsonEntities.at(retentionRelation.m_TailGuid);
188 headEntity.AddConnection(headEntity, tailEntity);
192 m_Model.
relationships.insert({relationship.m_Guid, relationship});
196 void JSONTimelineDecoder::HandleRetentionLink(
const ITimelineDecoder::Relationship& relationship)
199 .count(relationship.m_HeadGuid) != 0)
201 JSONEntity& tailJSONEntity = m_Model.
jsonEntities.at(relationship.m_TailGuid);
202 JSONEntity& headJSONEntity = m_Model.
jsonEntities.at(relationship.m_HeadGuid);
203 tailJSONEntity.SetParent(headJSONEntity);
204 m_Model.
jsonEntities.insert({relationship.m_HeadGuid, headJSONEntity});
205 m_Model.
relationships.insert({relationship.m_Guid, relationship});
209 m_Model.
relationships.insert({relationship.m_Guid, relationship});
231 json.append(
"\tArmNN");
232 json.append(
": {\n");
246 std::string jsonEntityString;
249 return GetLayerJSONString(entity, counter, jsonEntityString);
251 else if (entity.
GetType() == WORKLOAD)
253 return GetWorkloadJSONString(entity, counter, jsonEntityString);
255 else if (entity.
GetType() == WORKLOAD_EXECUTION)
257 return GetWorkloadExecutionJSONString(entity, jsonEntityString);
259 else if (entity.
GetType() == INFERENCE)
261 return jsonEntityString;
270 return jsonEntityString;
275 std::string& jsonEntityString)
const
279 throw arm::pipe::ProfilingException(
280 "Workload Execution Entity Packet does not have the expected Event packets attached");
285 Event event1 = m_Model.
events.at(jsonEventOne.GetGuid());
286 Event event2 = m_Model.
events.at(jsonEventTwo.GetGuid());
288 uint64_t wall_clock_time = event2.m_TimeStamp - event1.m_TimeStamp;
289 jsonEntityString.append(
"\t\t\t");
290 jsonEntityString.append(
"raw : [");
291 jsonEntityString.append(std::to_string(wall_clock_time));
292 jsonEntityString.append(
"], \n");
293 jsonEntityString.append(
"\t\t\t");
294 jsonEntityString.append(
"unit : us,\n");
295 jsonEntityString.append(
"\t\t\t");
296 jsonEntityString.append(
"}\n");
298 return jsonEntityString;
301 std::string JSONTimelineDecoder::GetWorkloadJSONString(
const JSONTimelineDecoder::JSONEntity& entity,
int& counter,
302 std::string& jsonEntityString)
304 jsonEntityString.append(
"\t\t\t");
305 jsonEntityString.append(
"backendId :");
306 jsonEntityString.append(entity.extendedData.at(BACKEND_ID));
307 jsonEntityString.append(
",\n");
308 for (uint64_t child_entity_id : entity.childEntities)
310 JSONEntity &childEntity = m_Model.
jsonEntities.at(child_entity_id);
313 return jsonEntityString;
316 std::string JSONTimelineDecoder::GetLayerJSONString(JSONTimelineDecoder::JSONEntity& entity,
int& counter,
317 std::string& jsonEntityString)
319 jsonEntityString.append(
"\t\t");
320 jsonEntityString.append(entity.GetName());
321 jsonEntityString.append(
"_");
322 jsonEntityString.append(std::to_string(counter));
323 jsonEntityString.append(
": {\n");
324 jsonEntityString.append(
"\t\t\t");
325 jsonEntityString.append(
"type: Measurement,\n");
326 for (uint64_t child_entity_id : entity.childEntities)
328 JSONEntity& childEntity = m_Model.
jsonEntities.at(child_entity_id);
331 return jsonEntityString;
336 std::vector<uint64_t>::iterator it = std::find(headEntity.
childEntities.begin(),
354 this->name = entityName;
364 this->type = entityType;