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

Side by Side Diff: bench/nanobench.cpp

Issue 390933002: nanobench: support --outResultsFile (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 5 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
« no previous file with comments | « no previous file | gyp/bench.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include <ctype.h> 8 #include <ctype.h>
9 9
10 #include "Benchmark.h" 10 #include "Benchmark.h"
11 #include "CrashHandler.h" 11 #include "CrashHandler.h"
12 #include "ResultsWriter.h"
12 #include "Stats.h" 13 #include "Stats.h"
13 #include "Timer.h" 14 #include "Timer.h"
14 15
15 #include "SkCanvas.h" 16 #include "SkCanvas.h"
16 #include "SkCommandLineFlags.h" 17 #include "SkCommandLineFlags.h"
17 #include "SkForceLinking.h" 18 #include "SkForceLinking.h"
18 #include "SkGraphics.h" 19 #include "SkGraphics.h"
19 #include "SkString.h" 20 #include "SkString.h"
20 #include "SkSurface.h" 21 #include "SkSurface.h"
21 22
(...skipping 12 matching lines...) Expand all
34 DEFINE_bool2(quiet, q, false, "Print only bench name and minimum sample."); 35 DEFINE_bool2(quiet, q, false, "Print only bench name and minimum sample.");
35 DEFINE_bool2(verbose, v, false, "Print all samples."); 36 DEFINE_bool2(verbose, v, false, "Print all samples.");
36 DEFINE_string(config, "nonrendering 8888 gpu", "Configs to measure. Options: " 37 DEFINE_string(config, "nonrendering 8888 gpu", "Configs to measure. Options: "
37 "565 8888 gpu nonrendering debug nullgpu msaa4 msaa16 nvprmsaa4 nv prmsaa16 angle"); 38 "565 8888 gpu nonrendering debug nullgpu msaa4 msaa16 nvprmsaa4 nv prmsaa16 angle");
38 DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU."); 39 DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU.");
39 DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU allow s to lag."); 40 DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU allow s to lag.");
40 41
41 DEFINE_bool(cpu, true, "Master switch for CPU-bound work."); 42 DEFINE_bool(cpu, true, "Master switch for CPU-bound work.");
42 DEFINE_bool(gpu, true, "Master switch for GPU-bound work."); 43 DEFINE_bool(gpu, true, "Master switch for GPU-bound work.");
43 44
45 DEFINE_string(outResultsFile, "", "If given, write results here as JSON.");
46
44 47
45 static SkString humanize(double ms) { 48 static SkString humanize(double ms) {
46 if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e3); 49 if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e3);
47 if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e6); 50 if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e6);
48 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e3); 51 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e3);
49 return SkStringPrintf("%.3gms", ms); 52 return SkStringPrintf("%.3gms", ms);
50 } 53 }
51 54
52 static double time(int loops, Benchmark* bench, SkCanvas* canvas, SkGLContextHel per* gl) { 55 static double time(int loops, Benchmark* bench, SkCanvas* canvas, SkGLContextHel per* gl) {
53 WallTimer timer; 56 WallTimer timer;
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 GPU_TARGET(nvprmsaa16, GrContextFactory::kNVPR_GLContextType, _8888, 16) 220 GPU_TARGET(nvprmsaa16, GrContextFactory::kNVPR_GLContextType, _8888, 16)
218 GPU_TARGET(debug, GrContextFactory::kDebug_GLContextType, _8888, 0) 221 GPU_TARGET(debug, GrContextFactory::kDebug_GLContextType, _8888, 0)
219 GPU_TARGET(nullgpu, GrContextFactory::kNull_GLContextType, _8888, 0) 222 GPU_TARGET(nullgpu, GrContextFactory::kNull_GLContextType, _8888, 0)
220 #if SK_ANGLE 223 #if SK_ANGLE
221 GPU_TARGET(angle, GrContextFactory::kANGLE_GLContextType, _8888, 0) 224 GPU_TARGET(angle, GrContextFactory::kANGLE_GLContextType, _8888, 0)
222 #endif 225 #endif
223 } 226 }
224 #endif 227 #endif
225 } 228 }
226 229
230 static void fill_static_options(ResultsWriter* log) {
231 #if defined(SK_BUILD_FOR_WIN32)
232 log->option("system", "WIN32");
233 #elif defined(SK_BUILD_FOR_MAC)
234 log->option("system", "MAC");
235 #elif defined(SK_BUILD_FOR_ANDROID)
236 log->option("system", "ANDROID");
237 #elif defined(SK_BUILD_FOR_UNIX)
238 log->option("system", "UNIX");
239 #else
240 log->option("system", "other");
241 #endif
242 #if defined(SK_DEBUG)
243 log->option("build", "DEBUG");
244 #else
245 log->option("build", "RELEASE");
246 #endif
247 }
248
227 int tool_main(int argc, char** argv); 249 int tool_main(int argc, char** argv);
228 int tool_main(int argc, char** argv) { 250 int tool_main(int argc, char** argv) {
229 SetupCrashHandler(); 251 SetupCrashHandler();
230 SkAutoGraphics ag; 252 SkAutoGraphics ag;
231 SkCommandLineFlags::Parse(argc, argv); 253 SkCommandLineFlags::Parse(argc, argv);
232 254
255 MultiResultsWriter log;
256 SkAutoTDelete<JSONResultsWriter> json;
257 if (!FLAGS_outResultsFile.isEmpty()) {
258 json.reset(SkNEW(JSONResultsWriter(FLAGS_outResultsFile[0])));
259 log.add(json.get());
260 }
261 CallEnd<MultiResultsWriter> ender(log);
262 fill_static_options(&log);
263
233 const double overhead = estimate_timer_overhead(); 264 const double overhead = estimate_timer_overhead();
234 SkAutoTMalloc<double> samples(FLAGS_samples); 265 SkAutoTMalloc<double> samples(FLAGS_samples);
235 266
236 if (FLAGS_verbose) { 267 if (FLAGS_verbose) {
237 // No header. 268 // No header.
238 } else if (FLAGS_quiet) { 269 } else if (FLAGS_quiet) {
239 SkDebugf("median\tbench\tconfig\n"); 270 SkDebugf("median\tbench\tconfig\n");
240 } else { 271 } else {
241 SkDebugf("loops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tconfig\tbench\ n"); 272 SkDebugf("loops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tconfig\tbench\ n");
242 } 273 }
243 274
244 for (const BenchRegistry* r = BenchRegistry::Head(); r != NULL; r = r->next( )) { 275 for (const BenchRegistry* r = BenchRegistry::Head(); r != NULL; r = r->next( )) {
245 SkAutoTDelete<Benchmark> bench(r->factory()(NULL)); 276 SkAutoTDelete<Benchmark> bench(r->factory()(NULL));
246 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getName())) { 277 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getName())) {
247 continue; 278 continue;
248 } 279 }
280 log.bench(bench->getName(), bench->getSize().fX, bench->getSize().fY);
249 281
250 SkTDArray<Target*> targets; 282 SkTDArray<Target*> targets;
251 create_targets(bench.get(), &targets); 283 create_targets(bench.get(), &targets);
252 284
253 bench->preDraw(); 285 bench->preDraw();
254 for (int j = 0; j < targets.count(); j++) { 286 for (int j = 0; j < targets.count(); j++) {
255 SkCanvas* canvas = targets[j]->surface.get() ? targets[j]->surface-> getCanvas() : NULL; 287 SkCanvas* canvas = targets[j]->surface.get() ? targets[j]->surface-> getCanvas() : NULL;
256 288
257 const int loops = 289 const int loops =
258 #if SK_SUPPORT_GPU 290 #if SK_SUPPORT_GPU
259 Benchmark::kGPU_Backend == targets[j]->backend 291 Benchmark::kGPU_Backend == targets[j]->backend
260 ? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get()) 292 ? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get())
261 : 293 :
262 #endif 294 #endif
263 cpu_bench( overhead, bench.get(), canvas, samples.get()); 295 cpu_bench( overhead, bench.get(), canvas, samples.get());
264 296
265 Stats stats(samples.get(), FLAGS_samples); 297 Stats stats(samples.get(), FLAGS_samples);
266 298
267 const char* config = targets[j]->config; 299 const char* config = targets[j]->config;
300
301 log.config(config);
302 log.timer("min_ms", stats.min);
303 log.timer("median_ms", stats.median);
304 log.timer("mean_ms", stats.mean);
305 log.timer("max_ms", stats.max);
306 log.timer("stddev_ms", sqrt(stats.var));
307
268 if (FLAGS_verbose) { 308 if (FLAGS_verbose) {
269 for (int i = 0; i < FLAGS_samples; i++) { 309 for (int i = 0; i < FLAGS_samples; i++) {
270 SkDebugf("%s ", humanize(samples[i]).c_str()); 310 SkDebugf("%s ", humanize(samples[i]).c_str());
271 } 311 }
272 SkDebugf("%s\n", bench->getName()); 312 SkDebugf("%s\n", bench->getName());
273 } else if (FLAGS_quiet) { 313 } else if (FLAGS_quiet) {
274 if (targets.count() == 1) { 314 if (targets.count() == 1) {
275 config = ""; // Only print the config if we run the same ben ch on more than one. 315 config = ""; // Only print the config if we run the same ben ch on more than one.
276 } 316 }
277 SkDebugf("%s\t%s\t%s\n", humanize(stats.median).c_str(), bench-> getName(), config); 317 SkDebugf("%s\t%s\t%s\n", humanize(stats.median).c_str(), bench-> getName(), config);
(...skipping 16 matching lines...) Expand all
294 } 334 }
295 335
296 return 0; 336 return 0;
297 } 337 }
298 338
299 #if !defined SK_BUILD_FOR_IOS 339 #if !defined SK_BUILD_FOR_IOS
300 int main(int argc, char * const argv[]) { 340 int main(int argc, char * const argv[]) {
301 return tool_main(argc, (char**) argv); 341 return tool_main(argc, (char**) argv);
302 } 342 }
303 #endif 343 #endif
OLDNEW
« no previous file with comments | « no previous file | gyp/bench.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698