| OLD | NEW |
| 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 "ResultsWriter.h" |
| 13 #include "Stats.h" | 13 #include "Stats.h" |
| 14 #include "Timer.h" | 14 #include "Timer.h" |
| 15 | 15 |
| 16 #include "SkCanvas.h" | 16 #include "SkCanvas.h" |
| 17 #include "SkCommandLineFlags.h" | 17 #include "SkCommonFlags.h" |
| 18 #include "SkForceLinking.h" | 18 #include "SkForceLinking.h" |
| 19 #include "SkGraphics.h" | 19 #include "SkGraphics.h" |
| 20 #include "SkString.h" | 20 #include "SkString.h" |
| 21 #include "SkSurface.h" | 21 #include "SkSurface.h" |
| 22 | 22 |
| 23 #if SK_SUPPORT_GPU | 23 #if SK_SUPPORT_GPU |
| 24 #include "gl/GrGLDefines.h" | 24 #include "gl/GrGLDefines.h" |
| 25 #include "GrContextFactory.h" | 25 #include "GrContextFactory.h" |
| 26 GrContextFactory gGrFactory; | 26 GrContextFactory gGrFactory; |
| 27 #endif | 27 #endif |
| 28 | 28 |
| 29 __SK_FORCE_IMAGE_DECODER_LINKING; | 29 __SK_FORCE_IMAGE_DECODER_LINKING; |
| 30 | 30 |
| 31 #if SK_DEBUG | 31 #if SK_DEBUG |
| 32 DEFINE_bool(runOnce, true, "Run each benchmark just once?"); | 32 DEFINE_bool(runOnce, true, "Run each benchmark just once?"); |
| 33 #else | 33 #else |
| 34 DEFINE_bool(runOnce, false, "Run each benchmark just once?"); | 34 DEFINE_bool(runOnce, false, "Run each benchmark just once?"); |
| 35 #endif | 35 #endif |
| 36 | 36 |
| 37 DEFINE_int32(samples, 10, "Number of samples to measure for each bench."); | 37 DEFINE_int32(samples, 10, "Number of samples to measure for each bench."); |
| 38 DEFINE_int32(overheadLoops, 100000, "Loops to estimate timer overhead."); | 38 DEFINE_int32(overheadLoops, 100000, "Loops to estimate timer overhead."); |
| 39 DEFINE_double(overheadGoal, 0.0001, | 39 DEFINE_double(overheadGoal, 0.0001, |
| 40 "Loop until timer overhead is at most this fraction of our measurm
ents."); | 40 "Loop until timer overhead is at most this fraction of our measurm
ents."); |
| 41 DEFINE_string(match, "", "The usual filters on file names of benchmarks to measu
re."); | |
| 42 DEFINE_bool2(quiet, q, false, "Print only bench name and minimum sample."); | |
| 43 DEFINE_bool2(verbose, v, false, "Print all samples."); | |
| 44 DEFINE_string(config, "nonrendering 8888 gpu", "Configs to measure. Options: " | |
| 45 "565 8888 gpu nonrendering debug nullgpu msaa4 msaa16 nvprmsaa4 nv
prmsaa16 angle"); | |
| 46 DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU."); | 41 DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU."); |
| 47 DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU allow
s to lag."); | 42 DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU allow
s to lag."); |
| 48 | 43 |
| 49 DEFINE_bool(cpu, true, "Master switch for CPU-bound work."); | |
| 50 DEFINE_bool(gpu, true, "Master switch for GPU-bound work."); | |
| 51 | |
| 52 DEFINE_string(outResultsFile, "", "If given, write results here as JSON."); | 44 DEFINE_string(outResultsFile, "", "If given, write results here as JSON."); |
| 53 DEFINE_bool(resetGpuContext, true, "Reset the GrContext before running each benc
h."); | |
| 54 DEFINE_int32(maxCalibrationAttempts, 3, | 45 DEFINE_int32(maxCalibrationAttempts, 3, |
| 55 "Try up to this many times to guess loops for a bench, or skip the
bench."); | 46 "Try up to this many times to guess loops for a bench, or skip the
bench."); |
| 56 DEFINE_int32(maxLoops, 1000000, "Never run a bench more times than this."); | 47 DEFINE_int32(maxLoops, 1000000, "Never run a bench more times than this."); |
| 57 DEFINE_string(key, "", "Space-separated key/value pairs to add to JSON."); | 48 DEFINE_string(key, "", "Space-separated key/value pairs to add to JSON."); |
| 58 DEFINE_string(gitHash, "", "Git hash to add to JSON."); | 49 DEFINE_string(gitHash, "", "Git hash to add to JSON."); |
| 59 | 50 |
| 60 | |
| 61 static SkString humanize(double ms) { | 51 static SkString humanize(double ms) { |
| 62 if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e3); | 52 if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e3); |
| 63 if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e6); | 53 if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e6); |
| 64 #ifdef SK_BUILD_FOR_WIN | 54 #ifdef SK_BUILD_FOR_WIN |
| 65 if (ms < 1) return SkStringPrintf("%.3gus", ms*1e3); | 55 if (ms < 1) return SkStringPrintf("%.3gus", ms*1e3); |
| 66 #else | 56 #else |
| 67 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e3); | 57 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e3); |
| 68 #endif | 58 #endif |
| 69 return SkStringPrintf("%.3gms", ms); | 59 return SkStringPrintf("%.3gms", ms); |
| 70 } | 60 } |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 log->configOption("GL_RENDERER", (const char*) version); | 281 log->configOption("GL_RENDERER", (const char*) version); |
| 292 | 282 |
| 293 SK_GL_RET(*ctx, version, GetString(GR_GL_VENDOR)); | 283 SK_GL_RET(*ctx, version, GetString(GR_GL_VENDOR)); |
| 294 log->configOption("GL_VENDOR", (const char*) version); | 284 log->configOption("GL_VENDOR", (const char*) version); |
| 295 | 285 |
| 296 SK_GL_RET(*ctx, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION)); | 286 SK_GL_RET(*ctx, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION)); |
| 297 log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version); | 287 log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version); |
| 298 } | 288 } |
| 299 #endif | 289 #endif |
| 300 | 290 |
| 301 int tool_main(int argc, char** argv); | 291 int nanobench_main(); |
| 302 int tool_main(int argc, char** argv) { | 292 int nanobench_main() { |
| 303 SetupCrashHandler(); | 293 SetupCrashHandler(); |
| 304 SkAutoGraphics ag; | 294 SkAutoGraphics ag; |
| 305 SkCommandLineFlags::Parse(argc, argv); | |
| 306 | 295 |
| 307 if (FLAGS_runOnce) { | 296 if (FLAGS_runOnce) { |
| 308 FLAGS_samples = 1; | 297 FLAGS_samples = 1; |
| 309 FLAGS_gpuFrameLag = 0; | 298 FLAGS_gpuFrameLag = 0; |
| 310 } | 299 } |
| 311 | 300 |
| 312 MultiResultsWriter log; | 301 MultiResultsWriter log; |
| 313 SkAutoTDelete<NanoJSONResultsWriter> json; | 302 SkAutoTDelete<NanoJSONResultsWriter> json; |
| 314 if (!FLAGS_outResultsFile.isEmpty()) { | 303 if (!FLAGS_outResultsFile.isEmpty()) { |
| 315 const char* gitHash = FLAGS_gitHash.isEmpty() ? "unknown-revision" : FLA
GS_gitHash[0]; | 304 const char* gitHash = FLAGS_gitHash.isEmpty() ? "unknown-revision" : FLA
GS_gitHash[0]; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 if (FLAGS_resetGpuContext) { | 411 if (FLAGS_resetGpuContext) { |
| 423 gGrFactory.destroyContexts(); | 412 gGrFactory.destroyContexts(); |
| 424 } | 413 } |
| 425 #endif | 414 #endif |
| 426 } | 415 } |
| 427 | 416 |
| 428 return 0; | 417 return 0; |
| 429 } | 418 } |
| 430 | 419 |
| 431 #if !defined SK_BUILD_FOR_IOS | 420 #if !defined SK_BUILD_FOR_IOS |
| 432 int main(int argc, char * const argv[]) { | 421 int main(int argc, char** argv) { |
| 433 return tool_main(argc, (char**) argv); | 422 SkCommandLineFlags::Parse(argc, argv); |
| 423 return nanobench_main(); |
| 434 } | 424 } |
| 435 #endif | 425 #endif |
| OLD | NEW |