ArmNN
 24.08
JsonPrinter.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include <string>
9 #include <map>
10 #include <set>
11 #include <sstream>
12 
13 #include <ProfilingGuid.hpp>
14 #include "Instrument.hpp"
15 #include "JsonUtils.hpp"
16 
17 namespace armnn
18 {
19 
20 enum class JsonObjectType
21 {
23  Event,
25 };
26 
28 {
29  // Object type changes according to the JsonObjectType specified in enum
30  JsonChildObject(const std::string& label)
31  : m_Label(label),
32  m_Unit(Measurement::Unit::TIME_MS),
35  m_DetailsOnly(false)
36  {}
37  JsonChildObject(const JsonChildObject&) = default;
38 
39  void AddMeasurement(const double measurement)
40  {
41  m_Measurements.push_back(measurement);
42  }
43 
44  void SetAndParseDetails(std::string layerDetailsStr)
45  {
46  std::stringstream layerDetails(layerDetailsStr);
47  std::string stringLine;
48  while (std::getline(layerDetails, stringLine, '\n'))
49  {
50  m_LayerDetailsList.push_back(stringLine);
51  }
52  }
53 
54  void SetGuid(arm::pipe::ProfilingGuid guid)
55  {
57  }
58 
59  void AddChild(const JsonChildObject& childObject)
60  {
61  m_Children.push_back(childObject);
62  }
63 
64  JsonChildObject& GetChild(const unsigned int index)
65  {
66  return m_Children[index];
67  }
68 
69  void SetUnit(const Measurement::Unit unit)
70  {
71  m_Unit = unit;
72  }
73 
74  size_t NumChildren() const
75  {
76  return m_Children.size();
77  }
78 
80  {
81  m_Type = type;
82  }
83 
85  {
86  return m_Type;
87  }
88 
90  {
91  m_DetailsOnly = true;
92  }
93 
94  bool IsDetailsOnlyEnabled() const
95  {
96  return m_DetailsOnly;
97  }
98 
99  ~JsonChildObject() = default;
100 
101  std::string m_Label;
105  std::vector<double> m_Measurements;
106  std::vector<std::string> m_LayerDetailsList;
107  std::vector<JsonChildObject> m_Children;
108 
109 private:
110  bool m_DetailsOnly;
111  JsonChildObject() = delete;
112 };
113 
114 class JsonPrinter : public JsonUtils
115 {
116 public:
117  void PrintJsonChildObject(const JsonChildObject& object, size_t& id);
118  void PrintLabel(const std::string& label, size_t id);
120  void PrintType(armnn::JsonObjectType type);
121  void PrintGuid(arm::pipe::ProfilingGuid guid);
122  void PrintMeasurementsList(const std::vector<double>& measurementsVector);
123 
124 public:
125  JsonPrinter(std::ostream& outputStream)
126  : JsonUtils(outputStream), m_OutputStream(outputStream)
127  {}
128 
129 private:
130  std::string MakeKey(const std::string& label, size_t id);
131 
132  std::ostream& m_OutputStream;
133 };
134 
135 } // namespace armnn
armnn::JsonPrinter::PrintLabel
void PrintLabel(const std::string &label, size_t id)
Definition: JsonPrinter.cpp:96
armnn::Optional< arm::pipe::ProfilingGuid >
armnn::JsonChildObject::JsonChildObject
JsonChildObject(const std::string &label)
Definition: JsonPrinter.hpp:30
armnn::JsonChildObject::AddChild
void AddChild(const JsonChildObject &childObject)
Definition: JsonPrinter.hpp:59
armnn::JsonChildObject::m_Type
JsonObjectType m_Type
Definition: JsonPrinter.hpp:103
armnn::JsonChildObject::m_Unit
Measurement::Unit m_Unit
Definition: JsonPrinter.hpp:102
JsonUtils.hpp
armnn::JsonObjectType::Measurement
@ Measurement
armnn::JsonChildObject::SetUnit
void SetUnit(const Measurement::Unit unit)
Definition: JsonPrinter.hpp:69
armnn::JsonChildObject::SetAndParseDetails
void SetAndParseDetails(std::string layerDetailsStr)
Definition: JsonPrinter.hpp:44
armnn::JsonChildObject::AddMeasurement
void AddMeasurement(const double measurement)
Definition: JsonPrinter.hpp:39
armnn::JsonObjectType
JsonObjectType
Definition: JsonPrinter.hpp:20
armnn::JsonChildObject::~JsonChildObject
~JsonChildObject()=default
armnn::EmptyOptional
EmptyOptional is used to initialize the Optional class in case we want to have default value for an O...
Definition: Optional.hpp:32
armnn::JsonChildObject::GetChild
JsonChildObject & GetChild(const unsigned int index)
Definition: JsonPrinter.hpp:64
armnn::Event
Event class records measurements reported by BeginEvent()/EndEvent() and returns measurements when Ev...
Definition: ProfilingEvent.hpp:27
Instrument.hpp
armnn::JsonPrinter::PrintType
void PrintType(armnn::JsonObjectType type)
Definition: JsonPrinter.cpp:111
armnn::JsonChildObject::SetType
void SetType(JsonObjectType type)
Definition: JsonPrinter.hpp:79
armnn::JsonPrinter::PrintGuid
void PrintGuid(arm::pipe::ProfilingGuid guid)
Definition: JsonPrinter.cpp:141
armnn::JsonChildObject::GetType
JsonObjectType GetType() const
Definition: JsonPrinter.hpp:84
armnn::Measurement
Definition: Instrument.hpp:14
armnn::JsonChildObject::m_Label
std::string m_Label
Definition: JsonPrinter.hpp:101
armnn::JsonChildObject::m_LayerDetailsList
std::vector< std::string > m_LayerDetailsList
Definition: JsonPrinter.hpp:106
armnn::JsonObjectType::ExecObjectDesc
@ ExecObjectDesc
armnn::JsonObjectType::Event
@ Event
armnn::JsonUtils
Definition: JsonUtils.hpp:16
armnn::JsonChildObject::SetGuid
void SetGuid(arm::pipe::ProfilingGuid guid)
Definition: JsonPrinter.hpp:54
armnn::JsonChildObject::m_Children
std::vector< JsonChildObject > m_Children
Definition: JsonPrinter.hpp:107
armnn::JsonChildObject::NumChildren
size_t NumChildren() const
Definition: JsonPrinter.hpp:74
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
armnn::JsonPrinter::PrintUnit
void PrintUnit(armnn::Measurement::Unit unit)
Definition: JsonPrinter.cpp:103
armnn::JsonPrinter
Definition: JsonPrinter.hpp:114
armnn::Measurement::Unit
Unit
Definition: Instrument.hpp:16
armnn::JsonChildObject::IsDetailsOnlyEnabled
bool IsDetailsOnlyEnabled() const
Definition: JsonPrinter.hpp:94
armnn::JsonPrinter::PrintJsonChildObject
void PrintJsonChildObject(const JsonChildObject &object, size_t &id)
Definition: JsonPrinter.cpp:15
armnn::JsonChildObject::EnableDetailsOnly
void EnableDetailsOnly()
Definition: JsonPrinter.hpp:89
armnn::JsonChildObject::m_Measurements
std::vector< double > m_Measurements
Definition: JsonPrinter.hpp:105
armnn::JsonChildObject::m_Guid
Optional< arm::pipe::ProfilingGuid > m_Guid
Definition: JsonPrinter.hpp:104
armnn::JsonPrinter::PrintMeasurementsList
void PrintMeasurementsList(const std::vector< double > &measurementsVector)
Definition: JsonPrinter.cpp:147
armnn::JsonPrinter::JsonPrinter
JsonPrinter(std::ostream &outputStream)
Definition: JsonPrinter.hpp:125
armnn::JsonChildObject
Definition: JsonPrinter.hpp:27