OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "testing/perf/perf_test.h" |
| 6 |
| 7 #include <stdio.h> |
| 8 |
| 9 #include "base/logging.h" |
| 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/stringprintf.h" |
| 12 |
| 13 namespace { |
| 14 |
| 15 std::string ResultsToString(const std::string& measurement, |
| 16 const std::string& modifier, |
| 17 const std::string& trace, |
| 18 const std::string& values, |
| 19 const std::string& prefix, |
| 20 const std::string& suffix, |
| 21 const std::string& units, |
| 22 bool important) { |
| 23 // <*>RESULT <graph_name>: <trace_name>= <value> <units> |
| 24 // <*>RESULT <graph_name>: <trace_name>= {<mean>, <std deviation>} <units> |
| 25 // <*>RESULT <graph_name>: <trace_name>= [<value>,value,value,...,] <units> |
| 26 return base::StringPrintf("%sRESULT %s%s: %s= %s%s%s %s\n", |
| 27 important ? "*" : "", measurement.c_str(), modifier.c_str(), |
| 28 trace.c_str(), prefix.c_str(), values.c_str(), suffix.c_str(), |
| 29 units.c_str()); |
| 30 } |
| 31 |
| 32 void PrintResultsImpl(const std::string& measurement, |
| 33 const std::string& modifier, |
| 34 const std::string& trace, |
| 35 const std::string& values, |
| 36 const std::string& prefix, |
| 37 const std::string& suffix, |
| 38 const std::string& units, |
| 39 bool important) { |
| 40 fflush(stdout); |
| 41 printf("%s", ResultsToString(measurement, modifier, trace, values, |
| 42 prefix, suffix, units, important).c_str()); |
| 43 fflush(stdout); |
| 44 } |
| 45 |
| 46 } // namespace |
| 47 |
| 48 namespace perf_test { |
| 49 |
| 50 void PrintResult(const std::string& measurement, |
| 51 const std::string& modifier, |
| 52 const std::string& trace, |
| 53 size_t value, |
| 54 const std::string& units, |
| 55 bool important) { |
| 56 PrintResultsImpl(measurement, |
| 57 modifier, |
| 58 trace, |
| 59 base::UintToString(value), |
| 60 std::string(), |
| 61 std::string(), |
| 62 units, |
| 63 important); |
| 64 } |
| 65 |
| 66 void AppendResult(std::string& output, |
| 67 const std::string& measurement, |
| 68 const std::string& modifier, |
| 69 const std::string& trace, |
| 70 size_t value, |
| 71 const std::string& units, |
| 72 bool important) { |
| 73 output += ResultsToString(measurement, |
| 74 modifier, |
| 75 trace, |
| 76 base::UintToString(value), |
| 77 std::string(), |
| 78 std::string(), |
| 79 units, |
| 80 important); |
| 81 } |
| 82 |
| 83 void PrintResult(const std::string& measurement, |
| 84 const std::string& modifier, |
| 85 const std::string& trace, |
| 86 const std::string& value, |
| 87 const std::string& units, |
| 88 bool important) { |
| 89 PrintResultsImpl(measurement, |
| 90 modifier, |
| 91 trace, |
| 92 value, |
| 93 std::string(), |
| 94 std::string(), |
| 95 units, |
| 96 important); |
| 97 } |
| 98 |
| 99 void AppendResult(std::string& output, |
| 100 const std::string& measurement, |
| 101 const std::string& modifier, |
| 102 const std::string& trace, |
| 103 const std::string& value, |
| 104 const std::string& units, |
| 105 bool important) { |
| 106 output += ResultsToString(measurement, |
| 107 modifier, |
| 108 trace, |
| 109 value, |
| 110 std::string(), |
| 111 std::string(), |
| 112 units, |
| 113 important); |
| 114 } |
| 115 |
| 116 void PrintResultMeanAndError(const std::string& measurement, |
| 117 const std::string& modifier, |
| 118 const std::string& trace, |
| 119 const std::string& mean_and_error, |
| 120 const std::string& units, |
| 121 bool important) { |
| 122 PrintResultsImpl(measurement, modifier, trace, mean_and_error, |
| 123 "{", "}", units, important); |
| 124 } |
| 125 |
| 126 void AppendResultMeanAndError(std::string& output, |
| 127 const std::string& measurement, |
| 128 const std::string& modifier, |
| 129 const std::string& trace, |
| 130 const std::string& mean_and_error, |
| 131 const std::string& units, |
| 132 bool important) { |
| 133 output += ResultsToString(measurement, modifier, trace, mean_and_error, |
| 134 "{", "}", units, important); |
| 135 } |
| 136 |
| 137 void PrintResultList(const std::string& measurement, |
| 138 const std::string& modifier, |
| 139 const std::string& trace, |
| 140 const std::string& values, |
| 141 const std::string& units, |
| 142 bool important) { |
| 143 PrintResultsImpl(measurement, modifier, trace, values, |
| 144 "[", "]", units, important); |
| 145 } |
| 146 |
| 147 void AppendResultList(std::string& output, |
| 148 const std::string& measurement, |
| 149 const std::string& modifier, |
| 150 const std::string& trace, |
| 151 const std::string& values, |
| 152 const std::string& units, |
| 153 bool important) { |
| 154 output += ResultsToString(measurement, modifier, trace, values, |
| 155 "[", "]", units, important); |
| 156 } |
| 157 |
| 158 void PrintSystemCommitCharge(const std::string& test_name, |
| 159 size_t charge, |
| 160 bool important) { |
| 161 PrintSystemCommitCharge(stdout, test_name, charge, important); |
| 162 } |
| 163 |
| 164 void PrintSystemCommitCharge(FILE* target, |
| 165 const std::string& test_name, |
| 166 size_t charge, |
| 167 bool important) { |
| 168 fprintf(target, "%s", SystemCommitChargeToString(test_name, charge, |
| 169 important).c_str()); |
| 170 } |
| 171 |
| 172 std::string SystemCommitChargeToString(const std::string& test_name, |
| 173 size_t charge, |
| 174 bool important) { |
| 175 std::string trace_name(test_name); |
| 176 std::string output; |
| 177 AppendResult(output, |
| 178 "commit_charge", |
| 179 std::string(), |
| 180 "cc" + trace_name, |
| 181 charge, |
| 182 "kb", |
| 183 important); |
| 184 return output; |
| 185 } |
| 186 |
| 187 } // namespace perf_test |
OLD | NEW |