ArmNN
 20.02
JsonPrinter Class Reference

#include <JsonPrinter.hpp>

Public Member Functions

void PrintJsonChildObject (const JsonChildObject &object, size_t &id)
 
void PrintHeader ()
 
void PrintArmNNHeader ()
 
void PrintFooter ()
 
void PrintSeparator ()
 
void PrintNewLine ()
 
void PrintLabel (const std::string &label, size_t id)
 
void PrintUnit (armnn::Measurement::Unit unit)
 
void PrintType (armnn::JsonObjectType type)
 
void PrintMeasurementsList (const std::vector< double > &measurementsVector)
 
 JsonPrinter (std::ostream &outputStream)
 

Detailed Description

Definition at line 78 of file JsonPrinter.hpp.

Constructor & Destructor Documentation

◆ JsonPrinter()

JsonPrinter ( std::ostream &  outputStream)
inline

Definition at line 93 of file JsonPrinter.hpp.

94  : m_OutputStream(outputStream), m_NumTabs(0)
95  {}

Member Function Documentation

◆ PrintArmNNHeader()

void PrintArmNNHeader ( )

Definition at line 63 of file JsonPrinter.cpp.

Referenced by Profiler::Print().

64 {
65  PrintTabs();
66  m_OutputStream << R"("ArmNN": {)" << std::endl;
67  IncrementNumberOfTabs();
68 }

◆ PrintFooter()

void PrintFooter ( )

Definition at line 163 of file JsonPrinter.cpp.

Referenced by Profiler::Print(), and JsonPrinter::PrintJsonChildObject().

164 {
165  DecrementNumberOfTabs();
166  PrintTabs();
167  m_OutputStream << "}";
168 }

◆ PrintHeader()

void PrintHeader ( )

Definition at line 57 of file JsonPrinter.cpp.

Referenced by Profiler::Print().

58 {
59  m_OutputStream << "{" << std::endl;
60  IncrementNumberOfTabs();
61 }

◆ PrintJsonChildObject()

void PrintJsonChildObject ( const JsonChildObject object,
size_t &  id 
)

Definition at line 15 of file JsonPrinter.cpp.

References armnn::Event, armnn::Measurement, JsonPrinter::PrintFooter(), JsonPrinter::PrintLabel(), JsonPrinter::PrintMeasurementsList(), JsonPrinter::PrintNewLine(), JsonPrinter::PrintSeparator(), JsonPrinter::PrintType(), and JsonPrinter::PrintUnit().

Referenced by Profiler::Print().

16 {
17  if (object.GetType() == JsonObjectType::Event)
18  {
19  // Increase the Id for new events. This ensures a new event has a unique ID and any measurements belonging
20  // to the event have the same id. This id is appended to the name during the call to PrintLabel() below.
21  id++;
22  }
23 
24  PrintLabel(object.m_Label, id);
25  PrintType(object.m_Type);
26 
27  if (!object.m_Measurements.empty() || !object.m_Children.empty())
28  {
30  PrintNewLine();
31  }
32 
33  if (object.GetType() == JsonObjectType::Measurement)
34  {
35  PrintMeasurementsList(object.m_Measurements);
37  PrintNewLine();
38  PrintUnit(object.m_Unit);
39  }
40  if (!object.m_Children.empty())
41  {
42  for (unsigned int childIndex = 0; childIndex < object.m_Children.size(); ++childIndex)
43  {
44  PrintJsonChildObject(object.m_Children[childIndex], id);
45  // Only print separator and new line if current child is not the last element.
46  if (&object.m_Children[childIndex] != &object.m_Children.back())
47  {
49  PrintNewLine();
50  }
51  }
52  }
53  PrintNewLine();
54  PrintFooter();
55 }
void PrintMeasurementsList(const std::vector< double > &measurementsVector)
void PrintType(armnn::JsonObjectType type)
Definition: JsonPrinter.cpp:92
void PrintJsonChildObject(const JsonChildObject &object, size_t &id)
Definition: JsonPrinter.cpp:15
void PrintLabel(const std::string &label, size_t id)
Definition: JsonPrinter.cpp:77
void PrintUnit(armnn::Measurement::Unit unit)
Definition: JsonPrinter.cpp:84

◆ PrintLabel()

void PrintLabel ( const std::string &  label,
size_t  id 
)

Definition at line 77 of file JsonPrinter.cpp.

Referenced by JsonPrinter::PrintJsonChildObject().

78 {
79  PrintTabs();
80  m_OutputStream << R"(")" << MakeKey(label, id) << R"(": {)" << std::endl;
81  IncrementNumberOfTabs();
82 }

◆ PrintMeasurementsList()

void PrintMeasurementsList ( const std::vector< double > &  measurementsVector)

Definition at line 119 of file JsonPrinter.cpp.

Referenced by JsonPrinter::PrintJsonChildObject().

120 {
121  if (measurementsVector.empty())
122  {
123  return;
124  }
125 
126  PrintTabs();
127  m_OutputStream << R"("raw": [)" << std::endl;
128  IncrementNumberOfTabs();
129  PrintTabs();
130  auto iter = measurementsVector.begin();
131  m_OutputStream << *iter;
132  for (iter = std::next(iter); iter != measurementsVector.end(); ++iter)
133  {
134  m_OutputStream << "," << std::endl;
135  PrintTabs();
136  m_OutputStream << *iter;
137  }
138  m_OutputStream << std::endl;
139  DecrementNumberOfTabs();
140  PrintTabs();
141  m_OutputStream << "]";
142 }

◆ PrintNewLine()

void PrintNewLine ( )

Definition at line 158 of file JsonPrinter.cpp.

Referenced by Profiler::Print(), and JsonPrinter::PrintJsonChildObject().

159 {
160  m_OutputStream << std::endl;
161 }

◆ PrintSeparator()

void PrintSeparator ( )

Definition at line 153 of file JsonPrinter.cpp.

Referenced by JsonPrinter::PrintJsonChildObject().

154 {
155  m_OutputStream << ",";
156 }

◆ PrintType()

void PrintType ( armnn::JsonObjectType  type)

Definition at line 92 of file JsonPrinter.cpp.

References armnn::Event, and armnn::Measurement.

Referenced by JsonPrinter::PrintJsonChildObject().

93 {
94  auto ToString = [](armnn::JsonObjectType type)
95  {
96  switch (type)
97  {
99  {
100  return "Measurement";
101  }
103  {
104  return "Event";
105  }
106  default:
107  {
108  return "Unknown";
109  }
110  }
111  };
112  PrintTabs();
113  m_OutputStream << R"("type": ")";
114  m_OutputStream << ToString(type);
115  m_OutputStream << R"(")";
116 }
JsonObjectType
Definition: JsonPrinter.hpp:18

◆ PrintUnit()

void PrintUnit ( armnn::Measurement::Unit  unit)

Definition at line 84 of file JsonPrinter.cpp.

References Measurement::ToString().

Referenced by JsonPrinter::PrintJsonChildObject().

85 {
86  PrintTabs();
87  m_OutputStream << R"("unit": ")";
88  m_OutputStream << armnn::Measurement::ToString(unit);
89  m_OutputStream << R"(")";
90 }
static const char * ToString(Unit unit)
Definition: Instrument.hpp:23

The documentation for this class was generated from the following files: