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

Side by Side Diff: bench/nanobench.cpp

Issue 438683002: nanobench: support GMs-as-benches (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: GM_ Created 6 years, 4 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 | « bench/GMBench.cpp ('k') | 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 "GMBench.h"
12 #include "ResultsWriter.h" 13 #include "ResultsWriter.h"
13 #include "Stats.h" 14 #include "Stats.h"
14 #include "Timer.h" 15 #include "Timer.h"
15 16
16 #include "SkCanvas.h" 17 #include "SkCanvas.h"
17 #include "SkCommonFlags.h" 18 #include "SkCommonFlags.h"
18 #include "SkForceLinking.h" 19 #include "SkForceLinking.h"
19 #include "SkGraphics.h" 20 #include "SkGraphics.h"
20 #include "SkString.h" 21 #include "SkString.h"
21 #include "SkSurface.h" 22 #include "SkSurface.h"
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 return sampleCnt <= ctx->getMaxSampleCount(); 233 return sampleCnt <= ctx->getMaxSampleCount();
233 } 234 }
234 return false; 235 return false;
235 } 236 }
236 #endif 237 #endif
237 238
238 #if SK_SUPPORT_GPU 239 #if SK_SUPPORT_GPU
239 #define kBogusGLContextType GrContextFactory::kNative_GLContextType 240 #define kBogusGLContextType GrContextFactory::kNative_GLContextType
240 #else 241 #else
241 #define kBogusGLContextType 0 242 #define kBogusGLContextType 0
242 #endif 243 #endif
243 244
244 // Append all configs that are enabled and supported. 245 // Append all configs that are enabled and supported.
245 static void create_configs(SkTDArray<Config>* configs) { 246 static void create_configs(SkTDArray<Config>* configs) {
246 #define CPU_CONFIG(name, backend, color, alpha) \ 247 #define CPU_CONFIG(name, backend, color, alpha) \
247 if (is_cpu_config_allowed(#name)) { \ 248 if (is_cpu_config_allowed(#name)) { \
248 Config config = { #name, Benchmark::backend, color, alpha, 0, kBogus GLContextType }; \ 249 Config config = { #name, Benchmark::backend, color, alpha, 0, kBogus GLContextType }; \
249 configs->push(config); \ 250 configs->push(config); \
250 } 251 }
251 252
252 if (FLAGS_cpu) { 253 if (FLAGS_cpu) {
253 CPU_CONFIG(nonrendering, kNonRendering_Backend, kUnknown_SkColorType, kU npremul_SkAlphaType) 254 CPU_CONFIG(nonrendering, kNonRendering_Backend, kUnknown_SkColorType, kU npremul_SkAlphaType)
254 CPU_CONFIG(8888, kRaster_Backend, kN32_SkColorType, kPremul_SkAlphaType) 255 CPU_CONFIG(8888, kRaster_Backend, kN32_SkColorType, kPremul_SkAlphaType)
255 CPU_CONFIG(565, kRaster_Backend, kRGB_565_SkColorType, kOpaque_SkAlphaTy pe) 256 CPU_CONFIG(565, kRaster_Backend, kRGB_565_SkColorType, kOpaque_SkAlphaTy pe)
256 } 257 }
257 258
258 #if SK_SUPPORT_GPU 259 #if SK_SUPPORT_GPU
259 #define GPU_CONFIG(name, ctxType, samples) \ 260 #define GPU_CONFIG(name, ctxType, samples) \
260 if (is_gpu_config_allowed(#name, GrContextFactory::ctxType, samples)) { \ 261 if (is_gpu_config_allowed(#name, GrContextFactory::ctxType, samples)) { \
261 Config config = { \ 262 Config config = { \
262 #name, \ 263 #name, \
263 Benchmark::kGPU_Backend, \ 264 Benchmark::kGPU_Backend, \
264 kN32_SkColorType, \ 265 kN32_SkColorType, \
265 kPremul_SkAlphaType, \ 266 kPremul_SkAlphaType, \
266 samples, \ 267 samples, \
267 GrContextFactory::ctxType }; \ 268 GrContextFactory::ctxType }; \
268 configs->push(config); \ 269 configs->push(config); \
269 } 270 }
270 271
271 if (FLAGS_gpu) { 272 if (FLAGS_gpu) {
272 GPU_CONFIG(gpu, kNative_GLContextType, 0) 273 GPU_CONFIG(gpu, kNative_GLContextType, 0)
273 GPU_CONFIG(msaa4, kNative_GLContextType, 4) 274 GPU_CONFIG(msaa4, kNative_GLContextType, 4)
274 GPU_CONFIG(msaa16, kNative_GLContextType, 16) 275 GPU_CONFIG(msaa16, kNative_GLContextType, 16)
275 GPU_CONFIG(nvprmsaa4, kNVPR_GLContextType, 4) 276 GPU_CONFIG(nvprmsaa4, kNVPR_GLContextType, 4)
276 GPU_CONFIG(nvprmsaa16, kNVPR_GLContextType, 16) 277 GPU_CONFIG(nvprmsaa16, kNVPR_GLContextType, 16)
277 GPU_CONFIG(debug, kDebug_GLContextType, 0) 278 GPU_CONFIG(debug, kDebug_GLContextType, 0)
278 GPU_CONFIG(nullgpu, kNull_GLContextType, 0) 279 GPU_CONFIG(nullgpu, kNull_GLContextType, 0)
279 } 280 }
280 #endif 281 #endif
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 return target; 313 return target;
313 } 314 }
314 315
315 // Creates targets for a benchmark and a set of configs. 316 // Creates targets for a benchmark and a set of configs.
316 static void create_targets(SkTDArray<Target*>* targets, Benchmark* b, 317 static void create_targets(SkTDArray<Target*>* targets, Benchmark* b,
317 const SkTDArray<Config>& configs) { 318 const SkTDArray<Config>& configs) {
318 for (int i = 0; i < configs.count(); ++i) { 319 for (int i = 0; i < configs.count(); ++i) {
319 if (Target* t = is_enabled(b, configs[i])) { 320 if (Target* t = is_enabled(b, configs[i])) {
320 targets->push(t); 321 targets->push(t);
321 } 322 }
322 323
323 } 324 }
324 } 325 }
325 326
326 static void fill_static_options(ResultsWriter* log) { 327 static void fill_static_options(ResultsWriter* log) {
327 #if defined(SK_BUILD_FOR_WIN32) 328 #if defined(SK_BUILD_FOR_WIN32)
328 log->option("system", "WIN32"); 329 log->option("system", "WIN32");
329 #elif defined(SK_BUILD_FOR_MAC) 330 #elif defined(SK_BUILD_FOR_MAC)
330 log->option("system", "MAC"); 331 log->option("system", "MAC");
331 #elif defined(SK_BUILD_FOR_ANDROID) 332 #elif defined(SK_BUILD_FOR_ANDROID)
332 log->option("system", "ANDROID"); 333 log->option("system", "ANDROID");
(...skipping 14 matching lines...) Expand all
347 log->configOption("GL_RENDERER", (const char*) version); 348 log->configOption("GL_RENDERER", (const char*) version);
348 349
349 SK_GL_RET(*ctx, version, GetString(GR_GL_VENDOR)); 350 SK_GL_RET(*ctx, version, GetString(GR_GL_VENDOR));
350 log->configOption("GL_VENDOR", (const char*) version); 351 log->configOption("GL_VENDOR", (const char*) version);
351 352
352 SK_GL_RET(*ctx, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION)); 353 SK_GL_RET(*ctx, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION));
353 log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version); 354 log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version);
354 } 355 }
355 #endif 356 #endif
356 357
358 class BenchmarkStream {
359 public:
360 BenchmarkStream() : fBenches(BenchRegistry::Head()) , fGMs(skiagm::GMRegistr y::Head()) {}
361
362 Benchmark* next(const char** sourceType) {
363 if (fBenches) {
364 Benchmark* bench = fBenches->factory()(NULL);
365 fBenches = fBenches->next();
366 *sourceType = "bench";
367 return bench;
368 }
369 while (fGMs) {
370 SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(NULL));
371 fGMs = fGMs->next();
372 if (gm->getFlags() & skiagm::GM::kAsBench_Flag) {
373 *sourceType = "gm";
374 return SkNEW_ARGS(GMBench, (gm.detach()));
375 }
376 }
377 return NULL;
378 }
379 private:
380 const BenchRegistry* fBenches;
381 const skiagm::GMRegistry* fGMs;
382 };
383
357 int nanobench_main(); 384 int nanobench_main();
358 int nanobench_main() { 385 int nanobench_main() {
359 SetupCrashHandler(); 386 SetupCrashHandler();
360 SkAutoGraphics ag; 387 SkAutoGraphics ag;
361 388
362 if (FLAGS_runOnce) { 389 if (FLAGS_runOnce) {
363 FLAGS_samples = 1; 390 FLAGS_samples = 1;
364 FLAGS_gpuFrameLag = 0; 391 FLAGS_gpuFrameLag = 0;
365 } 392 }
366 393
(...skipping 26 matching lines...) Expand all
393 // No header. 420 // No header.
394 } else if (FLAGS_quiet) { 421 } else if (FLAGS_quiet) {
395 SkDebugf("median\tbench\tconfig\n"); 422 SkDebugf("median\tbench\tconfig\n");
396 } else { 423 } else {
397 SkDebugf("loops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tconfig\tbench\ n"); 424 SkDebugf("loops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tconfig\tbench\ n");
398 } 425 }
399 426
400 SkTDArray<Config> configs; 427 SkTDArray<Config> configs;
401 create_configs(&configs); 428 create_configs(&configs);
402 429
403 for (const BenchRegistry* r = BenchRegistry::Head(); r != NULL; r = r->next( )) { 430 BenchmarkStream benches;
404 SkAutoTDelete<Benchmark> bench(r->factory()(NULL)); 431 const char* sourceType;
432 while (Benchmark* b = benches.next(&sourceType)) {
433 SkAutoTDelete<Benchmark> bench(b);
405 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getName())) { 434 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getName())) {
406 continue; 435 continue;
407 } 436 }
408 437
409 SkTDArray<Target*> targets; 438 SkTDArray<Target*> targets;
410 create_targets(&targets, bench.get(), configs); 439 create_targets(&targets, bench.get(), configs);
411 440
412 if (!targets.isEmpty()) { 441 if (!targets.isEmpty()) {
413 log.bench(bench->getName(), bench->getSize().fX, bench->getSize().fY ); 442 log.bench(bench->getName(), bench->getSize().fX, bench->getSize().fY );
414 bench->preDraw(); 443 bench->preDraw();
(...skipping 11 matching lines...) Expand all
426 cpu_bench( overhead, bench.get(), canvas, samples.get()); 455 cpu_bench( overhead, bench.get(), canvas, samples.get());
427 456
428 if (loops == 0) { 457 if (loops == 0) {
429 SkDebugf("Unable to time %s\t%s (overhead %s)\n", 458 SkDebugf("Unable to time %s\t%s (overhead %s)\n",
430 bench->getName(), config, HUMANIZE(overhead)); 459 bench->getName(), config, HUMANIZE(overhead));
431 continue; 460 continue;
432 } 461 }
433 462
434 Stats stats(samples.get(), FLAGS_samples); 463 Stats stats(samples.get(), FLAGS_samples);
435 log.config(config); 464 log.config(config);
465 log.configOption("source_type", sourceType);
436 #if SK_SUPPORT_GPU 466 #if SK_SUPPORT_GPU
437 if (Benchmark::kGPU_Backend == targets[j]->config.backend) { 467 if (Benchmark::kGPU_Backend == targets[j]->config.backend) {
438 fill_gpu_options(&log, targets[j]->gl); 468 fill_gpu_options(&log, targets[j]->gl);
439 } 469 }
440 #endif 470 #endif
441 log.timer("min_ms", stats.min); 471 log.timer("min_ms", stats.min);
442 log.timer("median_ms", stats.median); 472 log.timer("median_ms", stats.median);
443 log.timer("mean_ms", stats.mean); 473 log.timer("mean_ms", stats.mean);
444 log.timer("max_ms", stats.max); 474 log.timer("max_ms", stats.max);
445 log.timer("stddev_ms", sqrt(stats.var)); 475 log.timer("stddev_ms", sqrt(stats.var));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 518
489 return 0; 519 return 0;
490 } 520 }
491 521
492 #if !defined SK_BUILD_FOR_IOS 522 #if !defined SK_BUILD_FOR_IOS
493 int main(int argc, char** argv) { 523 int main(int argc, char** argv) {
494 SkCommandLineFlags::Parse(argc, argv); 524 SkCommandLineFlags::Parse(argc, argv);
495 return nanobench_main(); 525 return nanobench_main();
496 } 526 }
497 #endif 527 #endif
OLDNEW
« no previous file with comments | « bench/GMBench.cpp ('k') | gyp/bench.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698