blob: 5eec72a2fe8454c119bed0c9f5cd5657dba3405d [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 Pflanzer09e4f982017-08-30 12:47:06 +010026#include "../Framework.h"
27#include "../instruments/Measurement.h"
Moritz Pflanzer542002c2017-07-26 16:03:58 +010028
Moritz Pflanzer80fffae2017-07-05 11:02:37 +010029#include <algorithm>
30
31namespace arm_compute
32{
33namespace test
34{
35namespace framework
36{
37std::string PrettyPrinter::begin_color(const std::string &color) const
38{
39 if(!_color_output)
40 {
41 return "";
42 }
43
44 return "\033[0;3" + color + "m";
45}
46
47std::string PrettyPrinter::end_color() const
48{
49 if(!_color_output)
50 {
51 return "";
52 }
53
54 return "\033[m";
55}
56
57void PrettyPrinter::set_color_output(bool color_output)
58{
59 _color_output = color_output;
60}
61
62void PrettyPrinter::print_entry(const std::string &name, const std::string &value)
63{
64 *_stream << begin_color("4") << name << " = " << value << end_color() << "\n";
65}
66
67void PrettyPrinter::print_global_header()
68{
69}
70
71void PrettyPrinter::print_global_footer()
72{
73}
74
75void PrettyPrinter::print_run_header()
76{
77}
78
79void PrettyPrinter::print_run_footer()
80{
81}
82
Moritz Pflanzer542002c2017-07-26 16:03:58 +010083void PrettyPrinter::print_test_header(const TestInfo &info)
Moritz Pflanzer80fffae2017-07-05 11:02:37 +010084{
Moritz Pflanzer542002c2017-07-26 16:03:58 +010085 *_stream << begin_color("2") << "Running [" << info.id << "] '" << info.name << "'" << end_color() << "\n";
Moritz Pflanzer80fffae2017-07-05 11:02:37 +010086}
87
88void PrettyPrinter::print_test_footer()
89{
90}
91
Moritz Pflanzer24a82462017-08-04 11:34:44 +010092void PrettyPrinter::print_errors_header()
93{
94}
95
96void PrettyPrinter::print_errors_footer()
97{
98}
99
steniu01172c58d2017-08-31 13:49:08 +0100100void PrettyPrinter::print_info(const std::string &info)
101{
102 *_stream << begin_color("1") << "INFO: " << info << end_color() << "\n";
103}
104
Moritz Pflanzer5b61fd32017-09-12 15:51:33 +0100105void PrettyPrinter::print_error(const std::exception &error, bool expected)
Moritz Pflanzer24a82462017-08-04 11:34:44 +0100106{
Moritz Pflanzer5b61fd32017-09-12 15:51:33 +0100107 std::string prefix = expected ? "EXPECTED ERROR: " : "ERROR: ";
108 *_stream << begin_color("1") << prefix << error.what() << end_color() << "\n";
Moritz Pflanzer24a82462017-08-04 11:34:44 +0100109}
110
Moritz Pflanzer80fffae2017-07-05 11:02:37 +0100111void PrettyPrinter::print_measurements(const Profiler::MeasurementsMap &measurements)
112{
113 for(const auto &instrument : measurements)
114 {
115 *_stream << begin_color("3") << " " << instrument.first << ":";
116
Moritz Pflanzer09e4f982017-08-30 12:47:06 +0100117 auto add_measurements = [](double a, const Measurement & b)
Moritz Pflanzer80fffae2017-07-05 11:02:37 +0100118 {
119 return a + b.value;
120 };
121
Moritz Pflanzer09e4f982017-08-30 12:47:06 +0100122 auto cmp_measurements = [](const Measurement & a, const Measurement & b)
Moritz Pflanzer80fffae2017-07-05 11:02:37 +0100123 {
124 return a.value < b.value;
125 };
126
127 double sum_values = std::accumulate(instrument.second.begin(), instrument.second.end(), 0., add_measurements);
128 int num_values = instrument.second.size();
129 const auto minmax_values = std::minmax_element(instrument.second.begin(), instrument.second.end(), cmp_measurements);
130
131 if(num_values > 2)
132 {
133 sum_values -= minmax_values.first->value + minmax_values.second->value;
134 num_values -= 2;
135 }
136
Moritz Pflanzer09e4f982017-08-30 12:47:06 +0100137 Measurement avg{ sum_values / num_values, minmax_values.first->unit };
Moritz Pflanzer80fffae2017-07-05 11:02:37 +0100138
139 *_stream << " ";
140 *_stream << "AVG=" << avg << ", ";
141 *_stream << "MIN=" << *minmax_values.first << ", ";
142 *_stream << "MAX=" << *minmax_values.second << end_color() << "\n";
143 }
144}
145} // namespace framework
146} // namespace test
147} // namespace arm_compute