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" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 } | 100 } |
101 if (loops > FLAGS_maxLoops) { | 101 if (loops > FLAGS_maxLoops) { |
102 SkDebugf("WARNING: clamping loops from %d to FLAGS_maxLoops, %d.\n", loo
ps, FLAGS_maxLoops); | 102 SkDebugf("WARNING: clamping loops from %d to FLAGS_maxLoops, %d.\n", loo
ps, FLAGS_maxLoops); |
103 return FLAGS_maxLoops; | 103 return FLAGS_maxLoops; |
104 } | 104 } |
105 return loops; | 105 return loops; |
106 } | 106 } |
107 | 107 |
108 static int cpu_bench(const double overhead, Benchmark* bench, SkCanvas* canvas,
double* samples) { | 108 static int cpu_bench(const double overhead, Benchmark* bench, SkCanvas* canvas,
double* samples) { |
109 // First figure out approximately how many loops of bench it takes to make o
verhead negligible. | 109 // First figure out approximately how many loops of bench it takes to make o
verhead negligible. |
110 double bench_plus_overhead; | 110 double bench_plus_overhead = 0.0; |
111 int round = 0; | 111 int round = 0; |
112 do { | 112 while (bench_plus_overhead < overhead) { |
113 bench_plus_overhead = time(1, bench, canvas, NULL); | 113 if (round++ == FLAGS_maxCalibrationAttempts) { |
114 if (++round == FLAGS_maxCalibrationAttempts) { | |
115 SkDebugf("WARNING: Can't estimate loops for %s (%s vs. %s); skipping
.\n", | 114 SkDebugf("WARNING: Can't estimate loops for %s (%s vs. %s); skipping
.\n", |
116 bench->getName(), HUMANIZE(bench_plus_overhead), HUMANIZE(o
verhead)); | 115 bench->getName(), HUMANIZE(bench_plus_overhead), HUMANIZE(o
verhead)); |
117 return 0; | 116 return 0; |
118 } | 117 } |
119 } while (bench_plus_overhead < overhead); | 118 bench_plus_overhead = time(1, bench, canvas, NULL); |
| 119 } |
120 | 120 |
121 // Later we'll just start and stop the timer once but loop N times. | 121 // Later we'll just start and stop the timer once but loop N times. |
122 // We'll pick N to make timer overhead negligible: | 122 // We'll pick N to make timer overhead negligible: |
123 // | 123 // |
124 // overhead | 124 // overhead |
125 // ------------------------- < FLAGS_overheadGoal | 125 // ------------------------- < FLAGS_overheadGoal |
126 // overhead + N * Bench Time | 126 // overhead + N * Bench Time |
127 // | 127 // |
128 // where bench_plus_overhead ≈ overhead + Bench Time. | 128 // where bench_plus_overhead ≈ overhead + Bench Time. |
129 // | 129 // |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 | 540 |
541 const int loops = | 541 const int loops = |
542 #if SK_SUPPORT_GPU | 542 #if SK_SUPPORT_GPU |
543 Benchmark::kGPU_Backend == targets[j]->config.backend | 543 Benchmark::kGPU_Backend == targets[j]->config.backend |
544 ? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get()) | 544 ? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get()) |
545 : | 545 : |
546 #endif | 546 #endif |
547 cpu_bench( overhead, bench.get(), canvas, samples.get()); | 547 cpu_bench( overhead, bench.get(), canvas, samples.get()); |
548 | 548 |
549 if (loops == 0) { | 549 if (loops == 0) { |
550 SkDebugf("Unable to time %s\t%s (overhead %s)\n", | 550 // Can't be timed. A warning note has already been printed. |
551 bench->getName(), config, HUMANIZE(overhead)); | |
552 continue; | 551 continue; |
553 } | 552 } |
554 | 553 |
555 Stats stats(samples.get(), FLAGS_samples); | 554 Stats stats(samples.get(), FLAGS_samples); |
556 log.config(config); | 555 log.config(config); |
557 benchStream.fillCurrentOptions(&log); | 556 benchStream.fillCurrentOptions(&log); |
558 #if SK_SUPPORT_GPU | 557 #if SK_SUPPORT_GPU |
559 if (Benchmark::kGPU_Backend == targets[j]->config.backend) { | 558 if (Benchmark::kGPU_Backend == targets[j]->config.backend) { |
560 fill_gpu_options(&log, targets[j]->gl); | 559 fill_gpu_options(&log, targets[j]->gl); |
561 } | 560 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 | 609 |
611 return 0; | 610 return 0; |
612 } | 611 } |
613 | 612 |
614 #if !defined SK_BUILD_FOR_IOS | 613 #if !defined SK_BUILD_FOR_IOS |
615 int main(int argc, char** argv) { | 614 int main(int argc, char** argv) { |
616 SkCommandLineFlags::Parse(argc, argv); | 615 SkCommandLineFlags::Parse(argc, argv); |
617 return nanobench_main(); | 616 return nanobench_main(); |
618 } | 617 } |
619 #endif | 618 #endif |
OLD | NEW |