blob: 318195109cf8441af7ed88e3b588d9147b971334 [file] [log] [blame]
Moritz Pflanzer80fffae2017-07-05 11:02:37 +01001/*
Anthony Barbierc9afce52018-01-26 16:07:50 +00002 * Copyright (c) 2017-2018 ARM Limited.
Moritz Pflanzer80fffae2017-07-05 11:02:37 +01003 *
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
Moritz Pflanzer09e4f982017-08-30 12:47:06 +010026#include "../Framework.h"
Anthony Barbierc9afce52018-01-26 16:07:50 +000027#include "../instruments/InstrumentsStats.h"
Moritz Pflanzer09e4f982017-08-30 12:47:06 +010028#include "../instruments/Measurement.h"
Moritz Pflanzer542002c2017-07-26 16:03:58 +010029
Moritz Pflanzer80fffae2017-07-05 11:02:37 +010030#include <algorithm>
31
32namespace arm_compute
33{
34namespace test
35{
36namespace framework
37{
38std::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
48std::string PrettyPrinter::end_color() const
49{
50 if(!_color_output)
51 {
52 return "";
53 }
54
55 return "\033[m";
56}
57
58void PrettyPrinter::set_color_output(bool color_output)
59{
60 _color_output = color_output;
61}
62
63void PrettyPrinter::print_entry(const std::string &name, const std::string &value)
64{
65 *_stream << begin_color("4") << name << " = " << value << end_color() << "\n";
66}
67
68void PrettyPrinter::print_global_header()
69{
70}
71
72void PrettyPrinter::print_global_footer()
73{
74}
75
76void PrettyPrinter::print_run_header()
77{
78}
79
80void PrettyPrinter::print_run_footer()
81{
82}
83
Moritz Pflanzer542002c2017-07-26 16:03:58 +010084void PrettyPrinter::print_test_header(const TestInfo &info)
Moritz Pflanzer80fffae2017-07-05 11:02:37 +010085{
Moritz Pflanzer542002c2017-07-26 16:03:58 +010086 *_stream << begin_color("2") << "Running [" << info.id << "] '" << info.name << "'" << end_color() << "\n";
Moritz Pflanzer80fffae2017-07-05 11:02:37 +010087}
88
89void PrettyPrinter::print_test_footer()
90{
91}
92
Moritz Pflanzer24a82462017-08-04 11:34:44 +010093void PrettyPrinter::print_errors_header()
94{
95}
96
97void PrettyPrinter::print_errors_footer()
98{
99}
100
steniu01172c58d2017-08-31 13:49:08 +0100101void PrettyPrinter::print_info(const std::string &info)
102{
103 *_stream << begin_color("1") << "INFO: " << info << end_color() << "\n";
104}
105
Moritz Pflanzer5b61fd32017-09-12 15:51:33 +0100106void PrettyPrinter::print_error(const std::exception &error, bool expected)
Moritz Pflanzer24a82462017-08-04 11:34:44 +0100107{
Moritz Pflanzer5b61fd32017-09-12 15:51:33 +0100108 std::string prefix = expected ? "EXPECTED ERROR: " : "ERROR: ";
109 *_stream << begin_color("1") << prefix << error.what() << end_color() << "\n";
Moritz Pflanzer24a82462017-08-04 11:34:44 +0100110}
111
Anthony Barbierdbfb31c2017-11-24 11:24:45 +0000112void PrettyPrinter::print_list_tests(const std::vector<TestInfo> &infos)
113{
114 for(auto info : infos)
115 {
116 *_stream << "[" << info.id << ", " << info.mode << ", " << info.status << "] " << info.name << "\n";
117 }
118}
Moritz Pflanzer80fffae2017-07-05 11:02:37 +0100119void PrettyPrinter::print_measurements(const Profiler::MeasurementsMap &measurements)
120{
121 for(const auto &instrument : measurements)
122 {
123 *_stream << begin_color("3") << " " << instrument.first << ":";
124
Anthony Barbierc9afce52018-01-26 16:07:50 +0000125 InstrumentsStats stats(instrument.second);
Moritz Pflanzer80fffae2017-07-05 11:02:37 +0100126
Moritz Pflanzer80fffae2017-07-05 11:02:37 +0100127 *_stream << " ";
Anthony Barbierc9afce52018-01-26 16:07:50 +0000128 *_stream << "AVG=" << stats.mean() << " " << stats.max().unit();
129 if(instrument.second.size() > 1)
Anthony Barbierab14c152017-11-09 10:29:59 +0000130 {
Anthony Barbierc9afce52018-01-26 16:07:50 +0000131 *_stream << ", STDDEV=" << arithmetic_to_string(stats.relative_standard_deviation(), 2) << " %";
Georgios Pinitas5c2fb3f2018-05-01 15:26:20 +0100132 *_stream << ", MIN=" << stats.min();
133 *_stream << ", MAX=" << stats.max();
Anthony Barbierc9afce52018-01-26 16:07:50 +0000134 *_stream << ", MEDIAN=" << stats.median().value() << " " << stats.median().unit();
Anthony Barbierab14c152017-11-09 10:29:59 +0000135 }
136 *_stream << end_color() << "\n";
Moritz Pflanzer80fffae2017-07-05 11:02:37 +0100137 }
138}
139} // namespace framework
140} // namespace test
141} // namespace arm_compute