Compute Library
 21.05
PrettyPrinter.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2019 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #include "PrettyPrinter.h"
25 
26 #include "../Framework.h"
27 #include "../instruments/InstrumentsStats.h"
28 #include "../instruments/Measurement.h"
29 
30 #include <algorithm>
31 
32 namespace arm_compute
33 {
34 namespace test
35 {
36 namespace framework
37 {
38 std::string PrettyPrinter::begin_color(const std::string &color) const
39 {
40  if(!_color_output)
41  {
42  return "";
43  }
44 
45  return "\033[0;3" + color + "m";
46 }
47 
48 std::string PrettyPrinter::end_color() const
49 {
50  if(!_color_output)
51  {
52  return "";
53  }
54 
55  return "\033[m";
56 }
57 
58 void PrettyPrinter::set_color_output(bool color_output)
59 {
60  _color_output = color_output;
61 }
62 
63 void PrettyPrinter::print_entry(const std::string &name, const std::string &value)
64 {
65  *_stream << begin_color("4") << name << " = " << value << end_color() << "\n";
66 }
67 
69 {
70 }
71 
73 {
74 }
75 
77 {
78 }
79 
81 {
82 }
83 
85 {
86  *_stream << begin_color("2") << "Running [" << info.id << "] '" << info.name << "'" << end_color() << "\n";
87 }
88 
90 {
91 }
92 
94 {
95 }
96 
98 {
99 }
100 
101 void PrettyPrinter::print_info(const std::string &info)
102 {
103  *_stream << begin_color("1") << "INFO: " << info << end_color() << "\n";
104 }
105 
106 void PrettyPrinter::print_error(const std::exception &error, bool expected)
107 {
108  std::string prefix = expected ? "EXPECTED ERROR: " : "ERROR: ";
109  *_stream << begin_color("1") << prefix << error.what() << end_color() << "\n";
110 }
111 
112 void PrettyPrinter::print_list_tests(const std::vector<TestInfo> &infos)
113 {
114  for(auto const &info : infos)
115  {
116  *_stream << "[" << info.id << ", " << info.mode << ", " << info.status << "] " << info.name << "\n";
117  }
118 }
120 {
121  for(const auto &instrument : measurements)
122  {
123  *_stream << begin_color("3") << " " << instrument.first << ":";
124 
125  InstrumentsStats stats(instrument.second);
126 
127  *_stream << " ";
128  *_stream << "AVG=" << stats.mean() << " " << stats.max().unit();
129  if(instrument.second.size() > 1)
130  {
131  *_stream << ", STDDEV=" << arithmetic_to_string(stats.relative_standard_deviation(), 2) << " %";
132  *_stream << ", MIN=" << stats.min();
133  *_stream << ", MAX=" << stats.max();
134  *_stream << ", MEDIAN=" << stats.median().value() << " " << stats.median().unit();
135  }
136  *_stream << end_color() << "\n";
137  }
138 }
139 } // namespace framework
140 } // namespace test
141 } // namespace arm_compute
void print_errors_footer() override
Print footer after errors.
void print_global_header() override
Print global header.
void print_list_tests(const std::vector< TestInfo > &infos) override
Print the list of all the tests.
void print_errors_header() override
Print header before errors.
const Measurement & min() const
The measurement with the minimum value.
Copyright (c) 2017-2021 Arm Limited.
const Measurement & median() const
The median measurement.
void print_global_footer() override
Print global footer.
const Measurement::Value & mean() const
The average of all the measurements.
Information about a test case.
Definition: Framework.h:78
std::map< std::string, std::vector< Measurement > > MeasurementsMap
Mapping from instrument ids to their measurements.
Definition: Profiler.h:49
Generate common statistics for a set of measurements.
const char * name
void print_error(const std::exception &error, bool expected) override
Print test error.
void print_run_header() override
Print header before running all tests.
void print_run_footer() override
Print footer after running all tests.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
void print_entry(const std::string &name, const std::string &value) override
Print an entry consisting of a (name, value) pair.
void print_test_footer() override
Print footer after a test.
double relative_standard_deviation() const
The relative standard deviation of the measurements.
void set_color_output(bool color_output)
Set if the output is colored.
const Value & value() const
Accessor for the stored value.
Definition: Measurement.h:301
void print_measurements(const Profiler::MeasurementsMap &measurements) override
Print measurements for a test.
const std::string & unit() const
Accessor for the unit of the measurement.
Definition: Measurement.h:283
std::string arithmetic_to_string(T val, int decimal_places=0)
Create a string with the arithmetic value in full precision.
Definition: Utils.h:164
void print_info(const std::string &info) override
Print test log info.
void print_test_header(const TestInfo &info) override
Print header before a test.
const Measurement & max() const
The measurement with the maximum value.