blob: 631d96917a17a0703c5a658480b3b28f5ae81a4b [file] [log] [blame]
Moritz Pflanzer80fffae2017-07-05 11:02:37 +01001/*
2 * Copyright (c) 2017 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
Moritz Pflanzer542002c2017-07-26 16:03:58 +010026#include "framework/Framework.h"
27
Moritz Pflanzer80fffae2017-07-05 11:02:37 +010028#include <algorithm>
29
30namespace arm_compute
31{
32namespace test
33{
34namespace framework
35{
36std::string PrettyPrinter::begin_color(const std::string &color) const
37{
38 if(!_color_output)
39 {
40 return "";
41 }
42
43 return "\033[0;3" + color + "m";
44}
45
46std::string PrettyPrinter::end_color() const
47{
48 if(!_color_output)
49 {
50 return "";
51 }
52
53 return "\033[m";
54}
55
56void PrettyPrinter::set_color_output(bool color_output)
57{
58 _color_output = color_output;
59}
60
61void PrettyPrinter::print_entry(const std::string &name, const std::string &value)
62{
63 *_stream << begin_color("4") << name << " = " << value << end_color() << "\n";
64}
65
66void PrettyPrinter::print_global_header()
67{
68}
69
70void PrettyPrinter::print_global_footer()
71{
72}
73
74void PrettyPrinter::print_run_header()
75{
76}
77
78void PrettyPrinter::print_run_footer()
79{
80}
81
Moritz Pflanzer542002c2017-07-26 16:03:58 +010082void PrettyPrinter::print_test_header(const TestInfo &info)
Moritz Pflanzer80fffae2017-07-05 11:02:37 +010083{
Moritz Pflanzer542002c2017-07-26 16:03:58 +010084 *_stream << begin_color("2") << "Running [" << info.id << "] '" << info.name << "'" << end_color() << "\n";
Moritz Pflanzer80fffae2017-07-05 11:02:37 +010085}
86
87void PrettyPrinter::print_test_footer()
88{
89}
90
Moritz Pflanzer24a82462017-08-04 11:34:44 +010091void PrettyPrinter::print_errors_header()
92{
93}
94
95void PrettyPrinter::print_errors_footer()
96{
97}
98
99void PrettyPrinter::print_error(const std::exception &error)
100{
101 *_stream << begin_color("1") << error.what() << end_color() << "\n";
102}
103
Moritz Pflanzer80fffae2017-07-05 11:02:37 +0100104void PrettyPrinter::print_measurements(const Profiler::MeasurementsMap &measurements)
105{
106 for(const auto &instrument : measurements)
107 {
108 *_stream << begin_color("3") << " " << instrument.first << ":";
109
110 auto add_measurements = [](double a, const Instrument::Measurement & b)
111 {
112 return a + b.value;
113 };
114
115 auto cmp_measurements = [](const Instrument::Measurement & a, const Instrument::Measurement & b)
116 {
117 return a.value < b.value;
118 };
119
120 double sum_values = std::accumulate(instrument.second.begin(), instrument.second.end(), 0., add_measurements);
121 int num_values = instrument.second.size();
122 const auto minmax_values = std::minmax_element(instrument.second.begin(), instrument.second.end(), cmp_measurements);
123
124 if(num_values > 2)
125 {
126 sum_values -= minmax_values.first->value + minmax_values.second->value;
127 num_values -= 2;
128 }
129
130 Instrument::Measurement avg{ sum_values / num_values, minmax_values.first->unit };
131
132 *_stream << " ";
133 *_stream << "AVG=" << avg << ", ";
134 *_stream << "MIN=" << *minmax_values.first << ", ";
135 *_stream << "MAX=" << *minmax_values.second << end_color() << "\n";
136 }
137}
138} // namespace framework
139} // namespace test
140} // namespace arm_compute