Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 1 | /* |
Anthony Barbier | c9afce5 | 2018-01-26 16:07:50 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 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 Pflanzer | 09e4f98 | 2017-08-30 12:47:06 +0100 | [diff] [blame] | 26 | #include "../Framework.h" |
Anthony Barbier | c9afce5 | 2018-01-26 16:07:50 +0000 | [diff] [blame] | 27 | #include "../instruments/InstrumentsStats.h" |
Moritz Pflanzer | 09e4f98 | 2017-08-30 12:47:06 +0100 | [diff] [blame] | 28 | #include "../instruments/Measurement.h" |
Moritz Pflanzer | 542002c | 2017-07-26 16:03:58 +0100 | [diff] [blame] | 29 | |
Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 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 | |
| 68 | void PrettyPrinter::print_global_header() |
| 69 | { |
| 70 | } |
| 71 | |
| 72 | void PrettyPrinter::print_global_footer() |
| 73 | { |
| 74 | } |
| 75 | |
| 76 | void PrettyPrinter::print_run_header() |
| 77 | { |
| 78 | } |
| 79 | |
| 80 | void PrettyPrinter::print_run_footer() |
| 81 | { |
| 82 | } |
| 83 | |
Moritz Pflanzer | 542002c | 2017-07-26 16:03:58 +0100 | [diff] [blame] | 84 | void PrettyPrinter::print_test_header(const TestInfo &info) |
Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 85 | { |
Moritz Pflanzer | 542002c | 2017-07-26 16:03:58 +0100 | [diff] [blame] | 86 | *_stream << begin_color("2") << "Running [" << info.id << "] '" << info.name << "'" << end_color() << "\n"; |
Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | void PrettyPrinter::print_test_footer() |
| 90 | { |
| 91 | } |
| 92 | |
Moritz Pflanzer | 24a8246 | 2017-08-04 11:34:44 +0100 | [diff] [blame] | 93 | void PrettyPrinter::print_errors_header() |
| 94 | { |
| 95 | } |
| 96 | |
| 97 | void PrettyPrinter::print_errors_footer() |
| 98 | { |
| 99 | } |
| 100 | |
steniu01 | 172c58d | 2017-08-31 13:49:08 +0100 | [diff] [blame] | 101 | void PrettyPrinter::print_info(const std::string &info) |
| 102 | { |
| 103 | *_stream << begin_color("1") << "INFO: " << info << end_color() << "\n"; |
| 104 | } |
| 105 | |
Moritz Pflanzer | 5b61fd3 | 2017-09-12 15:51:33 +0100 | [diff] [blame] | 106 | void PrettyPrinter::print_error(const std::exception &error, bool expected) |
Moritz Pflanzer | 24a8246 | 2017-08-04 11:34:44 +0100 | [diff] [blame] | 107 | { |
Moritz Pflanzer | 5b61fd3 | 2017-09-12 15:51:33 +0100 | [diff] [blame] | 108 | std::string prefix = expected ? "EXPECTED ERROR: " : "ERROR: "; |
| 109 | *_stream << begin_color("1") << prefix << error.what() << end_color() << "\n"; |
Moritz Pflanzer | 24a8246 | 2017-08-04 11:34:44 +0100 | [diff] [blame] | 110 | } |
| 111 | |
Anthony Barbier | dbfb31c | 2017-11-24 11:24:45 +0000 | [diff] [blame] | 112 | void 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 Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 119 | void PrettyPrinter::print_measurements(const Profiler::MeasurementsMap &measurements) |
| 120 | { |
| 121 | for(const auto &instrument : measurements) |
| 122 | { |
| 123 | *_stream << begin_color("3") << " " << instrument.first << ":"; |
| 124 | |
Anthony Barbier | c9afce5 | 2018-01-26 16:07:50 +0000 | [diff] [blame] | 125 | InstrumentsStats stats(instrument.second); |
Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 126 | |
Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 127 | *_stream << " "; |
Anthony Barbier | c9afce5 | 2018-01-26 16:07:50 +0000 | [diff] [blame] | 128 | *_stream << "AVG=" << stats.mean() << " " << stats.max().unit(); |
| 129 | if(instrument.second.size() > 1) |
Anthony Barbier | ab14c15 | 2017-11-09 10:29:59 +0000 | [diff] [blame] | 130 | { |
Anthony Barbier | c9afce5 | 2018-01-26 16:07:50 +0000 | [diff] [blame] | 131 | *_stream << ", STDDEV=" << arithmetic_to_string(stats.relative_standard_deviation(), 2) << " %"; |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame^] | 132 | *_stream << ", MIN=" << stats.min(); |
| 133 | *_stream << ", MAX=" << stats.max(); |
Anthony Barbier | c9afce5 | 2018-01-26 16:07:50 +0000 | [diff] [blame] | 134 | *_stream << ", MEDIAN=" << stats.median().value() << " " << stats.median().unit(); |
Anthony Barbier | ab14c15 | 2017-11-09 10:29:59 +0000 | [diff] [blame] | 135 | } |
| 136 | *_stream << end_color() << "\n"; |
Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 137 | } |
| 138 | } |
| 139 | } // namespace framework |
| 140 | } // namespace test |
| 141 | } // namespace arm_compute |