blob: c4e085587e4b352e3f9763e4c0302071948965bd [file] [log] [blame]
Éanna Ó Catháin0de47122020-04-01 15:40:12 +01001//
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>
Éanna Ó Catháin49c52a12020-04-27 12:54:11 +010012#include <boost/filesystem/path.hpp>
13#include <boost/filesystem.hpp>
Éanna Ó Catháin0de47122020-04-01 15:40:12 +010014
15namespace armnn
16{
17namespace timelinedecoder
18{
19class JSONTimelineDecoder : public ITimelineDecoder
20{
21public:
22 struct JSONEntity
23 {
24 public:
25 std::vector<uint64_t> connected_entities;
26 std::vector<uint64_t> childEntities;
27
28 JSONEntity(uint64_t guid): m_Guid(guid){}
29 uint64_t GetGuid();
30 std::string GetName();
31 std::string GetType();
32 void SetName(std::string entityName);
33 void SetType(std::string entityType);
34 void SetParent(JSONEntity& parent);
35 void AddConnection(JSONEntity& headEntity, JSONEntity& connectedEntity);
36 std::map<std::string, std::string> extendedData;
37
38 private:
39 uint64_t m_Guid;
40 std::string name;
41 std::string type;
42 };
43
44 struct Model
45 {
46 std::map<uint64_t, JSONEntity> jsonEntities;
47 std::map<uint64_t, Relationship> relationships;
48 std::map<uint64_t, Label> labels;
49 std::map<uint64_t, Event> events;
50 std::map<uint64_t, EventClass> eventClasses;
51 };
52
53 void PrintJSON(JSONEntity& entity);
54 std::string GetJSONString(JSONEntity& rootEntity);
55 std::string GetJSONEntityString(JSONEntity& entity, int& counter);
56
57 virtual TimelineStatus CreateEntity(const Entity&) override;
58 virtual TimelineStatus CreateEventClass(const EventClass&) override;
59 virtual TimelineStatus CreateEvent(const Event&) override;
60 virtual TimelineStatus CreateLabel(const Label&) override;
61 virtual TimelineStatus CreateRelationship(const Relationship&) override;
62
63 const Model& GetModel();
64 void SetOutgoingCaptureFile(const std::string& basicString);
65
66private:
67 Model m_Model;
Éanna Ó Catháin49c52a12020-04-27 12:54:11 +010068 boost::filesystem::path fileDir = boost::filesystem::temp_directory_path();
69 boost::filesystem::path p{fileDir / boost::filesystem::unique_path("output.json")};
70
71 std::string outputJSONFile = p.string();
Éanna Ó Catháin0de47122020-04-01 15:40:12 +010072
73 void HandleRetentionLink(const Relationship& relationship);
74 void HandleLabelLink(const Relationship& relationship);
75 void HandleExecutionLink(const Relationship& relationship);
76 void HandleConnectionLabel(const Relationship& relationship);
77 void HandleBackendIdLabel(const Relationship& relationship);
78 void HandleNameLabel(const Relationship& relationship);
79 void HandleTypeLabel(const Relationship& relationship);
80
81 std::string GetLayerJSONString(JSONEntity& entity, int& counter, std::string& jsonEntityString);
82 std::string GetWorkloadJSONString(const JSONEntity& entity, int& counter, std::string& jsonEntityString);
83 std::string GetWorkloadExecutionJSONString(const JSONEntity& entity, std::string& jsonEntityString) const;
84};
85
86}
87}