Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(853)

Side by Side Diff: testing/perf/perf_test.cc

Issue 23509002: Factor out a perf test result printer method. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix mac compile Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « testing/perf/perf_test.h ('k') | testing/perf/perf_test.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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(static_cast<unsigned int>(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(
74 measurement,
75 modifier,
76 trace,
77 base::UintToString(static_cast<unsigned int>(value)),
78 std::string(),
79 std::string(),
80 units,
81 important);
82 }
83
84 void PrintResult(const std::string& measurement,
85 const std::string& modifier,
86 const std::string& trace,
87 const std::string& value,
88 const std::string& units,
89 bool important) {
90 PrintResultsImpl(measurement,
91 modifier,
92 trace,
93 value,
94 std::string(),
95 std::string(),
96 units,
97 important);
98 }
99
100 void AppendResult(std::string& output,
101 const std::string& measurement,
102 const std::string& modifier,
103 const std::string& trace,
104 const std::string& value,
105 const std::string& units,
106 bool important) {
107 output += ResultsToString(measurement,
108 modifier,
109 trace,
110 value,
111 std::string(),
112 std::string(),
113 units,
114 important);
115 }
116
117 void PrintResultMeanAndError(const std::string& measurement,
118 const std::string& modifier,
119 const std::string& trace,
120 const std::string& mean_and_error,
121 const std::string& units,
122 bool important) {
123 PrintResultsImpl(measurement, modifier, trace, mean_and_error,
124 "{", "}", units, important);
125 }
126
127 void AppendResultMeanAndError(std::string& output,
128 const std::string& measurement,
129 const std::string& modifier,
130 const std::string& trace,
131 const std::string& mean_and_error,
132 const std::string& units,
133 bool important) {
134 output += ResultsToString(measurement, modifier, trace, mean_and_error,
135 "{", "}", units, important);
136 }
137
138 void PrintResultList(const std::string& measurement,
139 const std::string& modifier,
140 const std::string& trace,
141 const std::string& values,
142 const std::string& units,
143 bool important) {
144 PrintResultsImpl(measurement, modifier, trace, values,
145 "[", "]", units, important);
146 }
147
148 void AppendResultList(std::string& output,
149 const std::string& measurement,
150 const std::string& modifier,
151 const std::string& trace,
152 const std::string& values,
153 const std::string& units,
154 bool important) {
155 output += ResultsToString(measurement, modifier, trace, values,
156 "[", "]", units, important);
157 }
158
159 void PrintSystemCommitCharge(const std::string& test_name,
160 size_t charge,
161 bool important) {
162 PrintSystemCommitCharge(stdout, test_name, charge, important);
163 }
164
165 void PrintSystemCommitCharge(FILE* target,
166 const std::string& test_name,
167 size_t charge,
168 bool important) {
169 fprintf(target, "%s", SystemCommitChargeToString(test_name, charge,
170 important).c_str());
171 }
172
173 std::string SystemCommitChargeToString(const std::string& test_name,
174 size_t charge,
175 bool important) {
176 std::string trace_name(test_name);
177 std::string output;
178 AppendResult(output,
179 "commit_charge",
180 std::string(),
181 "cc" + trace_name,
182 charge,
183 "kb",
184 important);
185 return output;
186 }
187
188 } // namespace perf_test
OLDNEW
« no previous file with comments | « testing/perf/perf_test.h ('k') | testing/perf/perf_test.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698