andrew@webrtc.org | 2009f6b | 2012-11-20 00:20:20 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | // A stripped-down version of Chromium's chrome/test/perf/perf_test.cc. |
| 12 | // ResultsToString(), PrintResult(size_t value) and AppendResult(size_t value) |
| 13 | // have been modified. The remainder are identical to the Chromium version. |
| 14 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "test/testsupport/perf_test.h" |
andrew@webrtc.org | 2009f6b | 2012-11-20 00:20:20 +0000 | [diff] [blame] | 16 | |
andrew@webrtc.org | 2009f6b | 2012-11-20 00:20:20 +0000 | [diff] [blame] | 17 | #include <sstream> |
pbos@webrtc.org | 34741c8 | 2013-05-27 08:02:22 +0000 | [diff] [blame] | 18 | #include <stdio.h> |
andrew@webrtc.org | 2009f6b | 2012-11-20 00:20:20 +0000 | [diff] [blame] | 19 | |
| 20 | namespace { |
| 21 | |
| 22 | std::string ResultsToString(const std::string& measurement, |
| 23 | const std::string& modifier, |
| 24 | const std::string& trace, |
| 25 | const std::string& values, |
| 26 | const std::string& prefix, |
| 27 | const std::string& suffix, |
| 28 | const std::string& units, |
| 29 | bool important) { |
| 30 | // <*>RESULT <graph_name>: <trace_name>= <value> <units> |
| 31 | // <*>RESULT <graph_name>: <trace_name>= {<mean>, <std deviation>} <units> |
| 32 | // <*>RESULT <graph_name>: <trace_name>= [<value>,value,value,...,] <units> |
| 33 | |
| 34 | // TODO(ajm): Use of a stream here may violate the style guide (depending on |
| 35 | // one's definition of "logging"). Consider adding StringPrintf-like |
| 36 | // functionality as in the original Chromium implementation. |
| 37 | std::ostringstream stream; |
| 38 | if (important) { |
| 39 | stream << "*"; |
| 40 | } |
| 41 | stream << "RESULT " << measurement << modifier << ": " << trace << "= " |
| 42 | << prefix << values << suffix << " " << units << std::endl; |
| 43 | return stream.str(); |
| 44 | } |
| 45 | |
| 46 | void PrintResultsImpl(const std::string& measurement, |
| 47 | const std::string& modifier, |
| 48 | const std::string& trace, |
| 49 | const std::string& values, |
| 50 | const std::string& prefix, |
| 51 | const std::string& suffix, |
| 52 | const std::string& units, |
| 53 | bool important) { |
| 54 | printf("%s", ResultsToString(measurement, modifier, trace, values, |
| 55 | prefix, suffix, units, important).c_str()); |
| 56 | } |
| 57 | |
| 58 | } // namespace |
| 59 | |
| 60 | namespace webrtc { |
| 61 | namespace test { |
| 62 | |
| 63 | void PrintResult(const std::string& measurement, |
| 64 | const std::string& modifier, |
| 65 | const std::string& trace, |
Edward Lemur | 6a82207 | 2017-11-22 19:17:50 +0100 | [diff] [blame] | 66 | const double value, |
andrew@webrtc.org | 2009f6b | 2012-11-20 00:20:20 +0000 | [diff] [blame] | 67 | const std::string& units, |
| 68 | bool important) { |
| 69 | std::ostringstream value_stream; |
| 70 | value_stream << value; |
| 71 | PrintResultsImpl(measurement, modifier, trace, value_stream.str(), "", "", |
| 72 | units, important); |
| 73 | } |
| 74 | |
andrew@webrtc.org | 2009f6b | 2012-11-20 00:20:20 +0000 | [diff] [blame] | 75 | void PrintResultMeanAndError(const std::string& measurement, |
| 76 | const std::string& modifier, |
| 77 | const std::string& trace, |
| 78 | const std::string& mean_and_error, |
| 79 | const std::string& units, |
| 80 | bool important) { |
| 81 | PrintResultsImpl(measurement, modifier, trace, mean_and_error, |
| 82 | "{", "}", units, important); |
| 83 | } |
| 84 | |
andrew@webrtc.org | 2009f6b | 2012-11-20 00:20:20 +0000 | [diff] [blame] | 85 | void PrintResultList(const std::string& measurement, |
| 86 | const std::string& modifier, |
| 87 | const std::string& trace, |
| 88 | const std::string& values, |
| 89 | const std::string& units, |
| 90 | bool important) { |
| 91 | PrintResultsImpl(measurement, modifier, trace, values, |
| 92 | "[", "]", units, important); |
| 93 | } |
| 94 | |
andrew@webrtc.org | 2009f6b | 2012-11-20 00:20:20 +0000 | [diff] [blame] | 95 | } // namespace test |
| 96 | } // namespace webrtc |