ArmNN
 25.11
Loading...
Searching...
No Matches
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 {}

References JsonUtils::JsonUtils().

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 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 {
36 PrintSeparator();
37 PrintNewLine();
38 }
39 if (object.GetType() == JsonObjectType::Measurement)
40 {
41 PrintMeasurementsList(object.m_Measurements);
42 PrintSeparator();
43 PrintNewLine();
44 PrintUnit(object.m_Unit);
45 }
46 else if (object.GetType() == JsonObjectType::ExecObjectDesc)
47 {
48 // Add details opening
49 DecrementNumberOfTabs();
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();
67 IncrementNumberOfTabs();
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 {
77 PrintSeparator();
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(), PrintGuid(), PrintJsonChildObject(), PrintLabel(), PrintMeasurementsList(), JsonUtils::PrintNewLine(), JsonUtils::PrintSeparator(), JsonUtils::PrintTabs(), PrintType(), and PrintUnit().

Referenced by ProfilerImpl::Print(), and PrintJsonChildObject().

◆ 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;
100 IncrementNumberOfTabs();
101}

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

Referenced by 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;
156 IncrementNumberOfTabs();
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;
167 DecrementNumberOfTabs();
168 PrintTabs();
169 m_OutputStream << "]";
170}

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

Referenced by 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 {
117 case JsonObjectType::Measurement:
118 {
119 return "Measurement";
120 }
121 case JsonObjectType::Event:
122 {
123 return "Event";
124 }
125 case JsonObjectType::ExecObjectDesc:
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 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}
static const char * ToString(Unit unit)

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

Referenced by PrintJsonChildObject().


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