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 | 542002c | 2017-07-26 16:03:58 +0100 | [diff] [blame] | 26 | #include "framework/Framework.h" |
| 27 | |
Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 28 | #include <algorithm> |
| 29 | |
| 30 | namespace arm_compute |
| 31 | { |
| 32 | namespace test |
| 33 | { |
| 34 | namespace framework |
| 35 | { |
| 36 | std::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 | |
| 46 | std::string PrettyPrinter::end_color() const |
| 47 | { |
| 48 | if(!_color_output) |
| 49 | { |
| 50 | return ""; |
| 51 | } |
| 52 | |
| 53 | return "\033[m"; |
| 54 | } |
| 55 | |
| 56 | void PrettyPrinter::set_color_output(bool color_output) |
| 57 | { |
| 58 | _color_output = color_output; |
| 59 | } |
| 60 | |
| 61 | void PrettyPrinter::print_entry(const std::string &name, const std::string &value) |
| 62 | { |
| 63 | *_stream << begin_color("4") << name << " = " << value << end_color() << "\n"; |
| 64 | } |
| 65 | |
| 66 | void PrettyPrinter::print_global_header() |
| 67 | { |
| 68 | } |
| 69 | |
| 70 | void PrettyPrinter::print_global_footer() |
| 71 | { |
| 72 | } |
| 73 | |
| 74 | void PrettyPrinter::print_run_header() |
| 75 | { |
| 76 | } |
| 77 | |
| 78 | void PrettyPrinter::print_run_footer() |
| 79 | { |
| 80 | } |
| 81 | |
Moritz Pflanzer | 542002c | 2017-07-26 16:03:58 +0100 | [diff] [blame] | 82 | void PrettyPrinter::print_test_header(const TestInfo &info) |
Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 83 | { |
Moritz Pflanzer | 542002c | 2017-07-26 16:03:58 +0100 | [diff] [blame] | 84 | *_stream << begin_color("2") << "Running [" << info.id << "] '" << info.name << "'" << end_color() << "\n"; |
Moritz Pflanzer | 80fffae | 2017-07-05 11:02:37 +0100 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | void PrettyPrinter::print_test_footer() |
| 88 | { |
| 89 | } |
| 90 | |
| 91 | void PrettyPrinter::print_measurements(const Profiler::MeasurementsMap &measurements) |
| 92 | { |
| 93 | for(const auto &instrument : measurements) |
| 94 | { |
| 95 | *_stream << begin_color("3") << " " << instrument.first << ":"; |
| 96 | |
| 97 | auto add_measurements = [](double a, const Instrument::Measurement & b) |
| 98 | { |
| 99 | return a + b.value; |
| 100 | }; |
| 101 | |
| 102 | auto cmp_measurements = [](const Instrument::Measurement & a, const Instrument::Measurement & b) |
| 103 | { |
| 104 | return a.value < b.value; |
| 105 | }; |
| 106 | |
| 107 | double sum_values = std::accumulate(instrument.second.begin(), instrument.second.end(), 0., add_measurements); |
| 108 | int num_values = instrument.second.size(); |
| 109 | const auto minmax_values = std::minmax_element(instrument.second.begin(), instrument.second.end(), cmp_measurements); |
| 110 | |
| 111 | if(num_values > 2) |
| 112 | { |
| 113 | sum_values -= minmax_values.first->value + minmax_values.second->value; |
| 114 | num_values -= 2; |
| 115 | } |
| 116 | |
| 117 | Instrument::Measurement avg{ sum_values / num_values, minmax_values.first->unit }; |
| 118 | |
| 119 | *_stream << " "; |
| 120 | *_stream << "AVG=" << avg << ", "; |
| 121 | *_stream << "MIN=" << *minmax_values.first << ", "; |
| 122 | *_stream << "MAX=" << *minmax_values.second << end_color() << "\n"; |
| 123 | } |
| 124 | } |
| 125 | } // namespace framework |
| 126 | } // namespace test |
| 127 | } // namespace arm_compute |