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