ArmNN
 24.08
JsonPrinter Class Reference

#include <JsonPrinter.hpp>

Inheritance diagram for JsonPrinter:
[legend]
Collaboration diagram for JsonPrinter:
[legend]

Public Member Functions

void PrintJsonChildObject (const JsonChildObject &object, size_t &id)
 
void PrintLabel (const std::string &label, size_t id)
 
void PrintUnit (armnn::Measurement::Unit unit)
 
void PrintType (armnn::JsonObjectType type)
 
void PrintGuid (arm::pipe::ProfilingGuid guid)
 
void PrintMeasurementsList (const std::vector< double > &measurementsVector)
 
 JsonPrinter (std::ostream &outputStream)
 
- Public Member Functions inherited from JsonUtils
 JsonUtils (std::ostream &outputStream)
 
void PrintTabs ()
 
void DecrementNumberOfTabs ()
 
void IncrementNumberOfTabs ()
 
void PrintNewLine ()
 
void PrintFooter ()
 
void PrintHeader ()
 
void PrintArmNNHeader ()
 
void PrintSeparator ()
 

Detailed Description

Definition at line 114 of file JsonPrinter.hpp.

Constructor & Destructor Documentation

◆ JsonPrinter()

JsonPrinter ( std::ostream &  outputStream)
inline

Definition at line 125 of file JsonPrinter.hpp.

126  : JsonUtils(outputStream), m_OutputStream(outputStream)
127  {}

Member Function Documentation

◆ PrintGuid()

void PrintGuid ( arm::pipe::ProfilingGuid  guid)

Definition at line 141 of file JsonPrinter.cpp.

142 {
143  PrintTabs();
144  m_OutputStream << std::quoted("GUID") << ": " << std::quoted(std::to_string(guid)) << "," << std::endl;
145 }

References JsonUtils::PrintTabs().

Referenced by JsonPrinter::PrintJsonChildObject().

◆ PrintJsonChildObject()

void PrintJsonChildObject ( const JsonChildObject object,
size_t &  id 
)

Definition at line 15 of file JsonPrinter.cpp.

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  if (object.GetType() != JsonObjectType::ExecObjectDesc)
25  {
26  PrintLabel(object.m_Label, id);
27  if (object.m_Guid.has_value())
28  {
29  PrintGuid(object.m_Guid.value());
30  }
31  PrintType(object.m_Type);
32  }
33 
34  if (!object.m_Measurements.empty() || !object.m_Children.empty())
35  {
37  PrintNewLine();
38  }
39  if (object.GetType() == JsonObjectType::Measurement)
40  {
41  PrintMeasurementsList(object.m_Measurements);
43  PrintNewLine();
44  PrintUnit(object.m_Unit);
45  }
46  else if (object.GetType() == JsonObjectType::ExecObjectDesc)
47  {
48  // Add details opening
50  PrintTabs();
51  m_OutputStream << std::quoted("Graph") << ":[";
52  PrintNewLine();
53 
54  // Fill details body
55  for (std::string stringLine : object.m_LayerDetailsList)
56  {
57  PrintTabs();
58  m_OutputStream << stringLine;
59  PrintNewLine();
60  }
61 
62  // Close out details
63  PrintTabs();
64  object.IsDetailsOnlyEnabled() ? m_OutputStream << "]" : m_OutputStream << "],";
65 
66  PrintNewLine();
68  }
69  if (!object.m_Children.empty())
70  {
71  for (unsigned int childIndex = 0; childIndex < object.m_Children.size(); ++childIndex)
72  {
73  PrintJsonChildObject(object.m_Children[childIndex], id);
74  // Only print separator and new line if current child is not the last element.
75  if (&object.m_Children[childIndex] != &object.m_Children.back())
76  {
78  PrintNewLine();
79  }
80  }
81  }
82  if (object.GetType() != JsonObjectType::ExecObjectDesc)
83  {
84  PrintNewLine();
85  PrintFooter();
86  }
87 }

References JsonUtils::DecrementNumberOfTabs(), armnn::Event, armnn::ExecObjectDesc, JsonUtils::IncrementNumberOfTabs(), armnn::Measurement, JsonUtils::PrintFooter(), JsonPrinter::PrintGuid(), JsonPrinter::PrintLabel(), JsonPrinter::PrintMeasurementsList(), JsonUtils::PrintNewLine(), JsonUtils::PrintSeparator(), JsonUtils::PrintTabs(), JsonPrinter::PrintType(), and JsonPrinter::PrintUnit().

Referenced by ProfilerImpl::Print().

◆ PrintLabel()

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

Definition at line 96 of file JsonPrinter.cpp.

97 {
98  PrintTabs();
99  m_OutputStream << R"(")" << MakeKey(label, id) << R"(": {)" << std::endl;
101 }

References JsonUtils::IncrementNumberOfTabs(), and JsonUtils::PrintTabs().

Referenced by JsonPrinter::PrintJsonChildObject().

◆ PrintMeasurementsList()

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

Definition at line 147 of file JsonPrinter.cpp.

148 {
149  if (measurementsVector.empty())
150  {
151  return;
152  }
153 
154  PrintTabs();
155  m_OutputStream << R"("raw": [)" << std::endl;
157  PrintTabs();
158  auto iter = measurementsVector.begin();
159  m_OutputStream << *iter;
160  for (iter = std::next(iter); iter != measurementsVector.end(); ++iter)
161  {
162  m_OutputStream << "," << std::endl;
163  PrintTabs();
164  m_OutputStream << *iter;
165  }
166  m_OutputStream << std::endl;
168  PrintTabs();
169  m_OutputStream << "]";
170 }

References JsonUtils::DecrementNumberOfTabs(), JsonUtils::IncrementNumberOfTabs(), and JsonUtils::PrintTabs().

Referenced by JsonPrinter::PrintJsonChildObject().

◆ PrintType()

void PrintType ( armnn::JsonObjectType  type)

Definition at line 111 of file JsonPrinter.cpp.

112 {
113  auto ToString = [](armnn::JsonObjectType type)
114  {
115  switch (type)
116  {
118  {
119  return "Measurement";
120  }
122  {
123  return "Event";
124  }
126  {
127  return "Operator Description";
128  }
129  default:
130  {
131  return "Unknown";
132  }
133  }
134  };
135  PrintTabs();
136  m_OutputStream << R"("type": ")";
137  m_OutputStream << ToString(type);
138  m_OutputStream << R"(")";
139 }

References armnn::Event, armnn::ExecObjectDesc, armnn::Measurement, and JsonUtils::PrintTabs().

Referenced by JsonPrinter::PrintJsonChildObject().

◆ PrintUnit()

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

Definition at line 103 of file JsonPrinter.cpp.

104 {
105  PrintTabs();
106  m_OutputStream << R"("unit": ")";
107  m_OutputStream << armnn::Measurement::ToString(unit);
108  m_OutputStream << R"(")";
109 }

References JsonUtils::PrintTabs(), and Measurement::ToString().

Referenced by JsonPrinter::PrintJsonChildObject().


The documentation for this class was generated from the following files:
armnn::JsonPrinter::PrintLabel
void PrintLabel(const std::string &label, size_t id)
Definition: JsonPrinter.cpp:96
armnn::JsonUtils::PrintNewLine
void PrintNewLine()
Definition: JsonUtils.hpp:46
armnn::JsonObjectType::Measurement
@ Measurement
armnn::JsonUtils::IncrementNumberOfTabs
void IncrementNumberOfTabs()
Definition: JsonUtils.hpp:41
armnn::JsonObjectType
JsonObjectType
Definition: JsonPrinter.hpp:20
armnn::JsonUtils::DecrementNumberOfTabs
void DecrementNumberOfTabs()
Definition: JsonUtils.hpp:32
armnn::JsonPrinter::PrintType
void PrintType(armnn::JsonObjectType type)
Definition: JsonPrinter.cpp:111
armnn::JsonPrinter::PrintGuid
void PrintGuid(arm::pipe::ProfilingGuid guid)
Definition: JsonPrinter.cpp:141
armnn::Measurement::ToString
static const char * ToString(Unit unit)
Definition: Instrument.hpp:23
armnn::JsonObjectType::ExecObjectDesc
@ ExecObjectDesc
armnn::JsonObjectType::Event
@ Event
armnn::JsonPrinter::PrintUnit
void PrintUnit(armnn::Measurement::Unit unit)
Definition: JsonPrinter.cpp:103
armnn::JsonUtils::PrintFooter
void PrintFooter()
Definition: JsonUtils.hpp:51
armnn::JsonUtils::PrintSeparator
void PrintSeparator()
Definition: JsonUtils.hpp:70
armnn::JsonUtils::JsonUtils
JsonUtils(std::ostream &outputStream)
Definition: JsonUtils.hpp:19
armnn::JsonPrinter::PrintJsonChildObject
void PrintJsonChildObject(const JsonChildObject &object, size_t &id)
Definition: JsonPrinter.cpp:15
armnn::JsonPrinter::PrintMeasurementsList
void PrintMeasurementsList(const std::vector< double > &measurementsVector)
Definition: JsonPrinter.cpp:147
armnn::JsonUtils::PrintTabs
void PrintTabs()
Definition: JsonUtils.hpp:23