Compute Library
 22.11
JSONPrinter Class Reference

Implementation of a Printer that produces JSON output. More...

#include <JSONPrinter.h>

Collaboration diagram for JSONPrinter:
[legend]

Public Member Functions

void print_entry (const std::string &name, const std::string &value) override
 Print an entry consisting of a (name, value) pair. More...
 
void print_global_header () override
 Print global header. More...
 
void print_global_footer () override
 Print global footer. More...
 
void print_run_header () override
 Print header before running all tests. More...
 
void print_run_footer () override
 Print footer after running all tests. More...
 
void print_test_header (const TestInfo &info) override
 Print header before a test. More...
 
void print_test_footer () override
 Print footer after a test. More...
 
void print_errors_header () override
 Print header before errors. More...
 
void print_errors_footer () override
 Print footer after errors. More...
 
void print_error (const std::exception &error, bool expected) override
 Print test error. More...
 
void print_info (const std::string &info) override
 Print test log info. More...
 
void print_profiler_header (const std::string &header_data) override
 Print header data. More...
 
void print_measurements (const Profiler::MeasurementsMap &measurements) override
 Print measurements for a test. More...
 
void print_list_tests (const std::vector< TestInfo > &infos) override
 Print the list of all the tests. More...
 
- Public Member Functions inherited from Printer
 Printer ()=default
 Default constructor. More...
 
 Printer (std::ostream &stream)
 Construct printer with given output stream. More...
 
 Printer (const Printer &)=delete
 Prevent instances of this class from being copy constructed. More...
 
Printeroperator= (const Printer &)=delete
 Prevent instances of this class from being copied. More...
 
 Printer (Printer &&)=default
 Allow instances of this class to be move constructed. More...
 
Printeroperator= (Printer &&)=default
 Allow instances of this class to be moved. More...
 
virtual ~Printer ()=default
 Default destructor. More...
 
void print (const std::string &str)
 Print given string. More...
 
void set_stream (std::ostream &stream)
 Set the output stream. More...
 

Detailed Description

Implementation of a Printer that produces JSON output.

Definition at line 38 of file JSONPrinter.h.

Member Function Documentation

◆ print_entry()

void print_entry ( const std::string &  name,
const std::string &  value 
)
overridevirtual

Print an entry consisting of a (name, value) pair.

Parameters
[in]nameDescription of the value.
[in]valueValue.

Implements Printer.

Definition at line 74 of file JSONPrinter.cpp.

75 {
76  print_separator(_first_entry);
77 
78  *_stream << R"(")" << name << R"(" : ")" << value << R"(")";
79 }
const char * name

◆ print_error()

void print_error ( const std::exception &  error,
bool  expected 
)
overridevirtual

Print test error.

Parameters
[in]errorDescription of the error.
[in]expectedWhether the error was expected or not.

Implements Printer.

Definition at line 155 of file JSONPrinter.cpp.

156 {
157  if(expected)
158  {
159  _expected_errors.emplace_back(error.what());
160  }
161  else
162  {
163  _errors.emplace_back(error.what());
164  }
165 }

◆ print_errors_footer()

void print_errors_footer ( )
overridevirtual

Print footer after errors.

Implements Printer.

Definition at line 138 of file JSONPrinter.cpp.

139 {
140  print_separator(_first_test_entry);
141 
142  *_stream << R"("errors" : [)";
143  print_strings(_errors.begin(), _errors.end());
144  *_stream << "]";
145 
146  *_stream << R"(, "expected_errors" : [)";
147  print_strings(_expected_errors.begin(), _expected_errors.end());
148  *_stream << "]";
149 
150  *_stream << R"(, "infos" : [)";
151  print_strings(_infos.begin(), _infos.end());
152  *_stream << "]";
153 }

◆ print_errors_header()

void print_errors_header ( )
overridevirtual

Print header before errors.

Implements Printer.

Definition at line 131 of file JSONPrinter.cpp.

132 {
133  _errors.clear();
134  _expected_errors.clear();
135  _infos.clear();
136 }

◆ print_global_footer()

void print_global_footer ( )
overridevirtual

Print global footer.

Implements Printer.

Definition at line 86 of file JSONPrinter.cpp.

87 {
88  *_stream << "}\n";
89 }

◆ print_global_header()

void print_global_header ( )
overridevirtual

Print global header.

Implements Printer.

Definition at line 81 of file JSONPrinter.cpp.

82 {
83  *_stream << "{";
84 }

◆ print_info()

void print_info ( const std::string &  info)
overridevirtual

Print test log info.

Parameters
[in]infoDescription of the log.

Implements Printer.

Definition at line 167 of file JSONPrinter.cpp.

168 {
169  _infos.push_back(info);
170 }
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)

◆ print_list_tests()

void print_list_tests ( const std::vector< TestInfo > &  infos)
overridevirtual

Print the list of all the tests.

Parameters
[in]infosList of tests to print

Implements Printer.

Definition at line 116 of file JSONPrinter.cpp.

References arm_compute::test::validation::info.

117 {
118  *_stream << R"(, "list_tests" : {)";
119  bool first = true;
120  for(auto const &info : infos)
121  {
122  if(!first)
123  {
124  *_stream << ",";
125  }
126  *_stream << R"(")" << info.id << R"(" : { "name": ")" << info.name << R"(", "mode": ")" << info.mode << R"(", "status" : ")" << info.status << R"(" })";
127  first = false;
128  }
129  *_stream << "}";
130 }
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)

◆ print_measurements()

void print_measurements ( const Profiler::MeasurementsMap measurements)
overridevirtual

Print measurements for a test.

Parameters
[in]measurementsMeasurements as collected by a Profiler.

Implements Printer.

Definition at line 181 of file JSONPrinter.cpp.

References arm_compute::test::join(), and caffe_mnist_image_extractor::str.

182 {
183  print_separator(_first_test_entry);
184  *_stream << R"("measurements" : {)";
185 
186  for(auto i_it = measurements.cbegin(), i_end = measurements.cend(); i_it != i_end;)
187  {
188  *_stream << R"(")" << i_it->first << R"(" : {)";
189 
190  auto measurement_to_string = [](const Measurement & measurement)
191  {
192  if(measurement.raw_data().size() == 1)
193  {
194  return measurement.raw_data().front();
195  }
196  else
197  {
198  std::stringstream str;
199  str << R"([")";
200  str << join(measurement.raw_data().begin(), measurement.raw_data().end(), R"(",")");
201  str << R"("])";
202  return str.str();
203  }
204  };
205  *_stream << R"("raw" : [)" << join(i_it->second.begin(), i_it->second.end(), ",", measurement_to_string) << "],";
206  *_stream << R"("unit" : ")" << i_it->second.begin()->unit() << R"(")";
207  *_stream << "}";
208 
209  if(++i_it != i_end)
210  {
211  *_stream << ",";
212  }
213  }
214 
215  *_stream << "}";
216 }
std::string join(T first, T last, const std::string &separator)
Helper function to concatenate multiple strings.
Definition: Utils.h:93

◆ print_profiler_header()

void print_profiler_header ( const std::string &  header_data)
overridevirtual

Print header data.

Parameters
[in]header_dataJSON formmated header data.

Implements Printer.

Definition at line 172 of file JSONPrinter.cpp.

173 {
174  if(header_data.size() > 0)
175  {
176  print_separator(_first_test_entry);
177  }
178  *_stream << header_data;
179 }

◆ print_run_footer()

void print_run_footer ( )
overridevirtual

Print footer after running all tests.

Implements Printer.

Definition at line 98 of file JSONPrinter.cpp.

99 {
100  *_stream << "}";
101 }

◆ print_run_header()

void print_run_header ( )
overridevirtual

Print header before running all tests.

Implements Printer.

Definition at line 91 of file JSONPrinter.cpp.

92 {
93  print_separator(_first_entry);
94 
95  *_stream << R"("tests" : {)";
96 }

◆ print_test_footer()

void print_test_footer ( )
overridevirtual

Print footer after a test.

Implements Printer.

Definition at line 111 of file JSONPrinter.cpp.

112 {
113  *_stream << "}";
114 }

◆ print_test_header()

void print_test_header ( const TestInfo info)
overridevirtual

Print header before a test.

Parameters
[in]infoTest info.

Implements Printer.

Definition at line 103 of file JSONPrinter.cpp.

References TestInfo::name.

104 {
105  print_separator(_first_test);
106 
107  _first_test_entry = true;
108  *_stream << R"(")" << info.name << R"(" : {)";
109 }
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)

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