1 // 2 // Copyright © 2020 Arm Ltd and Contributors. All rights reserved. 3 // SPDX-License-Identifier: MIT 4 // 5 6 #pragma once 7 8 #include <server/include/timelineDecoder/ITimelineDecoder.hpp> 9 10 #include <Filesystem.hpp> 11 #include <map> 12 #include <vector> 13 14 namespace armnn 15 { 16 namespace timelinedecoder 17 { 18 class JSONTimelineDecoder : public arm::pipe::ITimelineDecoder 19 { 20 public: 21 struct JSONEntity 22 { 23 public: 24 std::vector<uint64_t> connected_entities; 25 std::vector<uint64_t> childEntities; 26 JSONEntityarmnn::timelinedecoder::JSONTimelineDecoder::JSONEntity27 JSONEntity(uint64_t guid): m_Guid(guid){} 28 uint64_t GetGuid(); 29 std::string GetName(); 30 std::string GetType(); 31 void SetName(std::string entityName); 32 void SetType(std::string entityType); 33 void SetParent(JSONEntity& parent); 34 void AddConnection(JSONEntity& headEntity, JSONEntity& connectedEntity); 35 std::map<std::string, std::string> extendedData; 36 37 private: 38 uint64_t m_Guid; 39 std::string name; 40 std::string type; 41 }; 42 43 struct Model 44 { 45 std::map<uint64_t, JSONEntity> jsonEntities; 46 std::map<uint64_t, Relationship> relationships; 47 std::map<uint64_t, Label> labels; 48 std::map<uint64_t, Event> events; 49 std::map<uint64_t, EventClass> eventClasses; 50 }; 51 52 void PrintJSON(JSONEntity& entity, std::ostream& os); 53 std::string GetJSONString(JSONEntity& rootEntity); 54 std::string GetJSONEntityString(JSONEntity& entity, int& counter); 55 56 virtual TimelineStatus CreateEntity(const Entity&) override; 57 virtual TimelineStatus CreateEventClass(const EventClass&) override; 58 virtual TimelineStatus CreateEvent(const Event&) override; 59 virtual TimelineStatus CreateLabel(const Label&) override; 60 virtual TimelineStatus CreateRelationship(const Relationship&) override; 61 62 const Model& GetModel(); 63 64 private: 65 Model m_Model; 66 67 void HandleRetentionLink(const Relationship& relationship); 68 void HandleLabelLink(const Relationship& relationship); 69 void HandleExecutionLink(const Relationship& relationship); 70 void HandleConnectionLabel(const Relationship& relationship); 71 void HandleBackendIdLabel(const Relationship& relationship); 72 void HandleNameLabel(const Relationship& relationship); 73 void HandleTypeLabel(const Relationship& relationship); 74 75 std::string GetLayerJSONString(JSONEntity& entity, int& counter, std::string& jsonEntityString); 76 std::string GetWorkloadJSONString(const JSONEntity& entity, int& counter, std::string& jsonEntityString); 77 std::string GetWorkloadExecutionJSONString(const JSONEntity& entity, std::string& jsonEntityString) const; 78 }; 79 80 } 81 }