Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 1 | /* |
| 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 Pflanzer | 09e4f98 | 2017-08-30 12:47:06 +0100 | [diff] [blame] | 26 | #include "../Framework.h" |
| 27 | #include "../instruments/Measurement.h" |
Moritz Pflanzer | 542002c | 2017-07-26 16:03:58 +0100 | [diff] [blame] | 28 | |
Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 29 | #include <algorithm> |
| 30 | |
| 31 | namespace arm_compute |
| 32 | { |
| 33 | namespace test |
| 34 | { |
| 35 | namespace framework |
| 36 | { |
| 37 | std::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 | |
| 47 | std::string PrettyPrinter::end_color() const |
| 48 | { |
| 49 | if(!_color_output) |
| 50 | { |
| 51 | return ""; |
| 52 | } |
| 53 | |
| 54 | return "\033[m"; |
| 55 | } |
| 56 | |
| 57 | void PrettyPrinter::set_color_output(bool color_output) |
| 58 | { |
| 59 | _color_output = color_output; |
| 60 | } |
| 61 | |
| 62 | void PrettyPrinter::print_entry(const std::string &name, const std::string &value) |
| 63 | { |
| 64 | *_stream << begin_color("4") << name << " = " << value << end_color() << "\n"; |
| 65 | } |
| 66 | |
| 67 | void PrettyPrinter::print_global_header() |
| 68 | { |
| 69 | } |
| 70 | |
| 71 | void PrettyPrinter::print_global_footer() |
| 72 | { |
| 73 | } |
| 74 | |
| 75 | void PrettyPrinter::print_run_header() |
| 76 | { |
| 77 | } |
| 78 | |
| 79 | void PrettyPrinter::print_run_footer() |
| 80 | { |
| 81 | } |
| 82 | |
Moritz Pflanzer | 542002c | 2017-07-26 16:03:58 +0100 | [diff] [blame] | 83 | void PrettyPrinter::print_test_header(const TestInfo &info) |
Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 84 | { |
Moritz Pflanzer | 542002c | 2017-07-26 16:03:58 +0100 | [diff] [blame] | 85 | *_stream << begin_color("2") << "Running [" << info.id << "] '" << info.name << "'" << end_color() << "\n"; |
Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | void PrettyPrinter::print_test_footer() |
| 89 | { |
| 90 | } |
| 91 | |
Moritz Pflanzer | 24a8246 | 2017-08-04 11:34:44 +0100 | [diff] [blame] | 92 | void PrettyPrinter::print_errors_header() |
| 93 | { |
| 94 | } |
| 95 | |
| 96 | void PrettyPrinter::print_errors_footer() |
| 97 | { |
| 98 | } |
| 99 | |
steniu01 | 172c58d | 2017-08-31 13:49:08 +0100 | [diff] [blame] | 100 | void PrettyPrinter::print_info(const std::string &info) |
| 101 | { |
| 102 | *_stream << begin_color("1") << "INFO: " << info << end_color() << "\n"; |
| 103 | } |
| 104 | |
Moritz Pflanzer | 5b61fd3 | 2017-09-12 15:51:33 +0100 | [diff] [blame^] | 105 | void PrettyPrinter::print_error(const std::exception &error, bool expected) |
Moritz Pflanzer | 24a8246 | 2017-08-04 11:34:44 +0100 | [diff] [blame] | 106 | { |
Moritz Pflanzer | 5b61fd3 | 2017-09-12 15:51:33 +0100 | [diff] [blame^] | 107 | std::string prefix = expected ? "EXPECTED ERROR: " : "ERROR: "; |
| 108 | *_stream << begin_color("1") << prefix << error.what() << end_color() << "\n"; |
Moritz Pflanzer | 24a8246 | 2017-08-04 11:34:44 +0100 | [diff] [blame] | 109 | } |
| 110 | |
Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 111 | void PrettyPrinter::print_measurements(const Profiler::MeasurementsMap &measurements) |
| 112 | { |
| 113 | for(const auto &instrument : measurements) |
| 114 | { |
| 115 | *_stream << begin_color("3") << " " << instrument.first << ":"; |
| 116 | |
Moritz Pflanzer | 09e4f98 | 2017-08-30 12:47:06 +0100 | [diff] [blame] | 117 | auto add_measurements = [](double a, const Measurement & b) |
Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 118 | { |
| 119 | return a + b.value; |
| 120 | }; |
| 121 | |
Moritz Pflanzer | 09e4f98 | 2017-08-30 12:47:06 +0100 | [diff] [blame] | 122 | auto cmp_measurements = [](const Measurement & a, const Measurement & b) |
Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 123 | { |
| 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 Pflanzer | 09e4f98 | 2017-08-30 12:47:06 +0100 | [diff] [blame] | 137 | Measurement avg{ sum_values / num_values, minmax_values.first->unit }; |
Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 138 | |
| 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 |