1 // Copyright 2013 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.
5 #include "testing/perf/perf_test.h"
9 #include "base/logging.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/stringprintf.h"
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
,
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(),
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
,
41 printf("%s", ResultsToString(measurement
, modifier
, trace
, values
,
42 prefix
, suffix
, units
, important
).c_str());
50 void PrintResult(const std::string
& measurement
,
51 const std::string
& modifier
,
52 const std::string
& trace
,
54 const std::string
& units
,
56 PrintResultsImpl(measurement
,
59 base::UintToString(static_cast<unsigned int>(value
)),
66 void PrintResult(const std::string
& measurement
,
67 const std::string
& modifier
,
68 const std::string
& trace
,
70 const std::string
& units
,
72 PrintResultsImpl(measurement
,
75 base::DoubleToString(value
),
82 void AppendResult(std::string
& output
,
83 const std::string
& measurement
,
84 const std::string
& modifier
,
85 const std::string
& trace
,
87 const std::string
& units
,
89 output
+= ResultsToString(
93 base::UintToString(static_cast<unsigned int>(value
)),
100 void PrintResult(const std::string
& measurement
,
101 const std::string
& modifier
,
102 const std::string
& trace
,
103 const std::string
& value
,
104 const std::string
& units
,
106 PrintResultsImpl(measurement
,
116 void AppendResult(std::string
& output
,
117 const std::string
& measurement
,
118 const std::string
& modifier
,
119 const std::string
& trace
,
120 const std::string
& value
,
121 const std::string
& units
,
123 output
+= ResultsToString(measurement
,
133 void PrintResultMeanAndError(const std::string
& measurement
,
134 const std::string
& modifier
,
135 const std::string
& trace
,
136 const std::string
& mean_and_error
,
137 const std::string
& units
,
139 PrintResultsImpl(measurement
, modifier
, trace
, mean_and_error
,
140 "{", "}", units
, important
);
143 void AppendResultMeanAndError(std::string
& output
,
144 const std::string
& measurement
,
145 const std::string
& modifier
,
146 const std::string
& trace
,
147 const std::string
& mean_and_error
,
148 const std::string
& units
,
150 output
+= ResultsToString(measurement
, modifier
, trace
, mean_and_error
,
151 "{", "}", units
, important
);
154 void PrintResultList(const std::string
& measurement
,
155 const std::string
& modifier
,
156 const std::string
& trace
,
157 const std::string
& values
,
158 const std::string
& units
,
160 PrintResultsImpl(measurement
, modifier
, trace
, values
,
161 "[", "]", units
, important
);
164 void AppendResultList(std::string
& output
,
165 const std::string
& measurement
,
166 const std::string
& modifier
,
167 const std::string
& trace
,
168 const std::string
& values
,
169 const std::string
& units
,
171 output
+= ResultsToString(measurement
, modifier
, trace
, values
,
172 "[", "]", units
, important
);
175 void PrintSystemCommitCharge(const std::string
& test_name
,
178 PrintSystemCommitCharge(stdout
, test_name
, charge
, important
);
181 void PrintSystemCommitCharge(FILE* target
,
182 const std::string
& test_name
,
185 fprintf(target
, "%s", SystemCommitChargeToString(test_name
, charge
,
189 std::string
SystemCommitChargeToString(const std::string
& test_name
,
192 std::string
trace_name(test_name
);
204 } // namespace perf_test