xref: /aosp_15_r20/external/armnn/src/timelineDecoder/JSONTimelineDecoder.hpp (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
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 <armnnUtils/Filesystem.hpp>
11 
12 #include <map>
13 #include <vector>
14 
15 namespace armnn
16 {
17 namespace timelinedecoder
18 {
19 class JSONTimelineDecoder : public arm::pipe::ITimelineDecoder
20 {
21 public:
22     struct JSONEntity
23     {
24     public:
25         std::vector<uint64_t> connected_entities;
26         std::vector<uint64_t> childEntities;
27 
JSONEntityarmnn::timelinedecoder::JSONTimelineDecoder::JSONEntity28         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, std::ostream& os);
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 
65 private:
66     Model m_Model;
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 }
83