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