OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "BenchTimer.h" | 8 #include "BenchTimer.h" |
9 #include "SkBenchLogger.h" | 9 #include "SkBenchLogger.h" |
10 #include "SkBenchmark.h" | 10 #include "SkBenchmark.h" |
11 #include "SkBitmapDevice.h" | 11 #include "SkBitmapDevice.h" |
12 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
13 #include "SkColorPriv.h" | 13 #include "SkColorPriv.h" |
14 #include "SkCommandLineFlags.h" | 14 #include "SkCommandLineFlags.h" |
15 #include "SkDeferredCanvas.h" | 15 #include "SkDeferredCanvas.h" |
16 #include "SkGraphics.h" | 16 #include "SkGraphics.h" |
17 #include "SkImageEncoder.h" | 17 #include "SkImageEncoder.h" |
18 #include "SkOSFile.h" | 18 #include "SkOSFile.h" |
19 #include "SkPicture.h" | 19 #include "SkPicture.h" |
20 #include "SkStream.h" | |
20 #include "SkString.h" | 21 #include "SkString.h" |
21 | 22 |
22 #if SK_SUPPORT_GPU | 23 #if SK_SUPPORT_GPU |
23 #include "GrContext.h" | 24 #include "GrContext.h" |
24 #include "GrContextFactory.h" | 25 #include "GrContextFactory.h" |
25 #include "GrRenderTarget.h" | 26 #include "GrRenderTarget.h" |
26 #include "SkGpuDevice.h" | 27 #include "SkGpuDevice.h" |
27 #include "gl/GrGLDefines.h" | 28 #include "gl/GrGLDefines.h" |
28 #else | 29 #else |
29 class GrContext; | 30 class GrContext; |
30 #endif // SK_SUPPORT_GPU | 31 #endif // SK_SUPPORT_GPU |
31 | 32 |
33 #ifdef SK_BUILD_FOR_WIN | |
34 // json includes xlocale which generates warning 4530 because we're | |
35 // compiling without exceptions; | |
36 // see https://code.google.com/p/skia/issues/detail?id=1067 | |
37 #pragma warning(push) | |
38 #pragma warning(disable : 4530) | |
39 #endif | |
40 #include "json/value.h" | |
41 #ifdef SK_BUILD_FOR_WIN | |
42 #pragma warning(pop) | |
43 #endif | |
44 | |
32 #include <limits> | 45 #include <limits> |
33 | 46 |
34 enum BenchMode { | 47 enum BenchMode { |
35 kNormal_BenchMode, | 48 kNormal_BenchMode, |
36 kDeferred_BenchMode, | 49 kDeferred_BenchMode, |
37 kDeferredSilent_BenchMode, | 50 kDeferredSilent_BenchMode, |
38 kRecord_BenchMode, | 51 kRecord_BenchMode, |
39 kPictureRecord_BenchMode | 52 kPictureRecord_BenchMode |
40 }; | 53 }; |
41 const char* BenchMode_Name[] = { | 54 const char* BenchMode_Name[] = { |
42 "normal", "deferred", "deferredSilent", "record", "picturerecord" | 55 "normal", "deferred", "deferredSilent", "record", "picturerecord" |
43 }; | 56 }; |
44 | 57 |
45 static const char kDefaultsConfigStr[] = "defaults"; | 58 static const char kDefaultsConfigStr[] = "defaults"; |
46 | 59 |
47 /////////////////////////////////////////////////////////////////////////////// | 60 /////////////////////////////////////////////////////////////////////////////// |
48 | 61 |
49 static void erase(SkBitmap& bm) { | 62 static void erase(SkBitmap& bm) { |
50 if (bm.config() == SkBitmap::kA8_Config) { | 63 if (bm.config() == SkBitmap::kA8_Config) { |
51 bm.eraseColor(SK_ColorTRANSPARENT); | 64 bm.eraseColor(SK_ColorTRANSPARENT); |
52 } else { | 65 } else { |
53 bm.eraseColor(SK_ColorWHITE); | 66 bm.eraseColor(SK_ColorWHITE); |
54 } | 67 } |
55 } | 68 } |
56 | 69 |
70 // Base class for writing out the bench results. | |
djsollen
2013/11/25 15:35:46
can we move these 3 classes to their own header?
jcgregorio
2013/11/25 16:06:48
Done.
| |
71 // | |
72 // TODO(jcgregorio) Add info if tests fail to converge? | |
73 class ResultsWriter : SkNoncopyable { | |
74 public: | |
75 virtual ~ResultsWriter() {}; | |
76 | |
77 // Records one option set for this run. All options must be set before | |
78 // calling bench(). | |
79 virtual void option(const char name[], const char value[]) = 0; | |
80 | |
81 // Denotes the start of a specific benchmark. Once bench is called, | |
82 // then config and timer can be called multiple times to record runs. | |
83 virtual void bench(const char name[], int32_t x, int32_t y) = 0; | |
84 | |
85 // Records the specific configuration a bench is run under, such as "8888". | |
86 virtual void config(const char name[]) = 0; | |
87 | |
88 // Records a single test metric. | |
89 virtual void timer(const char name[], double ms) = 0; | |
90 | |
91 // Call when all results are finished. | |
92 virtual void end() = 0; | |
93 }; | |
94 | |
95 // This ResultsWriter handles writing out the human readable format of the | |
96 // bench results. | |
97 class LoggerResultsWriter : public ResultsWriter { | |
98 public: | |
99 explicit LoggerResultsWriter(SkBenchLogger& logger, const char* timeFormat) | |
100 : fLogger(logger) | |
101 , fTimeFormat(timeFormat) { | |
102 fLogger.logProgress("skia bench:"); | |
103 } | |
104 virtual void option(const char name[], const char value[]) { | |
105 fLogger.logProgress(SkStringPrintf(" %s=%s", name, value)); | |
106 } | |
107 virtual void bench(const char name[], int32_t x, int32_t y) { | |
108 fLogger.logProgress(SkStringPrintf( | |
109 "\nrunning bench [%3d %3d] %040s", x, y, name)); | |
110 } | |
111 virtual void config(const char name[]) { | |
112 fLogger.logProgress(SkStringPrintf(" %s:", name)); | |
113 } | |
114 virtual void timer(const char name[], double ms) { | |
115 fLogger.logProgress(SkStringPrintf(" %s = ", name)); | |
116 fLogger.logProgress(SkStringPrintf(fTimeFormat, ms)); | |
117 } | |
118 virtual void end() { | |
119 fLogger.logProgress("\n"); | |
120 } | |
121 private: | |
122 SkBenchLogger& fLogger; | |
123 const char* fTimeFormat; | |
124 }; | |
125 | |
126 // This ResultsWriter handles writing out the results in JSON. | |
127 // | |
128 // The output looks like: | |
129 // | |
130 // { | |
131 // "options" : { | |
132 // "alpha" : "0xFF", | |
133 // "scale" : "0", | |
134 // ... | |
135 // "system" : "UNIX" | |
136 // }, | |
137 // "results" : { | |
138 // "Xfermode_Luminosity_640_480" : { | |
139 // "565" : { | |
140 // "cmsecs" : 143.188128906250, | |
141 // "msecs" : 143.835957031250 | |
142 // }, | |
143 // ... | |
144 // | |
145 class JSONResultsWriter : public ResultsWriter { | |
146 public: | |
147 explicit JSONResultsWriter(const char filename[]) | |
148 : fFilename(filename) | |
149 , fRoot() | |
150 , fResults(fRoot["results"]) | |
151 , fBench(NULL) | |
152 , fConfig(NULL) { | |
153 } | |
154 virtual void option(const char name[], const char value[]) { | |
155 fRoot["options"][name] = value; | |
156 } | |
157 virtual void bench(const char name[], int32_t x, int32_t y) { | |
158 fBench = &fResults[SkStringPrintf( "%s_%d_%d", name, x, y).c_str()]; | |
159 } | |
160 virtual void config(const char name[]) { | |
161 SkASSERT(NULL != fBench); | |
162 fConfig = &(*fBench)[name]; | |
163 } | |
164 virtual void timer(const char name[], double ms) { | |
165 SkASSERT(NULL != fConfig); | |
166 (*fConfig)[name] = ms; | |
167 } | |
168 virtual void end() { | |
169 SkFILEWStream stream(fFilename.c_str()); | |
170 stream.writeText(fRoot.toStyledString().c_str()); | |
171 stream.flush(); | |
172 } | |
173 private: | |
174 SkString fFilename; | |
175 Json::Value fRoot; | |
176 Json::Value& fResults; | |
177 Json::Value* fBench; | |
178 Json::Value* fConfig; | |
179 }; | |
180 | |
181 // This ResultsWriter writes out to multiple ResultsWriters. | |
182 class MultiResultsWriter : public ResultsWriter { | |
183 public: | |
184 MultiResultsWriter() : writers() { | |
185 }; | |
186 void add(ResultsWriter* writer) { | |
187 writers.push_back(writer); | |
188 } | |
189 virtual void option(const char name[], const char value[]) { | |
190 for (int i = 0; i < writers.count(); ++i) { | |
191 writers[i]->option(name, value); | |
192 } | |
193 } | |
194 virtual void bench(const char name[], int32_t x, int32_t y) { | |
195 for (int i = 0; i < writers.count(); ++i) { | |
196 writers[i]->bench(name, x, y); | |
197 } | |
198 } | |
199 virtual void config(const char name[]) { | |
200 for (int i = 0; i < writers.count(); ++i) { | |
201 writers[i]->config(name); | |
202 } | |
203 } | |
204 virtual void timer(const char name[], double ms) { | |
205 for (int i = 0; i < writers.count(); ++i) { | |
206 writers[i]->timer(name, ms); | |
207 } | |
208 } | |
209 virtual void end() { | |
210 for (int i = 0; i < writers.count(); ++i) { | |
211 writers[i]->end(); | |
212 } | |
213 } | |
214 private: | |
215 SkTArray<ResultsWriter *> writers; | |
216 }; | |
217 | |
57 class Iter { | 218 class Iter { |
58 public: | 219 public: |
59 Iter() : fBench(BenchRegistry::Head()) {} | 220 Iter() : fBench(BenchRegistry::Head()) {} |
60 | 221 |
61 SkBenchmark* next() { | 222 SkBenchmark* next() { |
62 if (fBench) { | 223 if (fBench) { |
63 BenchRegistry::Factory f = fBench->factory(); | 224 BenchRegistry::Factory f = fBench->factory(); |
64 fBench = fBench->next(); | 225 fBench = fBench->next(); |
65 return f(); | 226 return f(); |
66 } | 227 } |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
268 DEFINE_string(config, kDefaultsConfigStr, | 429 DEFINE_string(config, kDefaultsConfigStr, |
269 "Run configs given. By default, runs the configs marked \"runByDe fault\" in gConfigs."); | 430 "Run configs given. By default, runs the configs marked \"runByDe fault\" in gConfigs."); |
270 DEFINE_string(logFile, "", "Also write stdout here."); | 431 DEFINE_string(logFile, "", "Also write stdout here."); |
271 DEFINE_int32(minMs, 20, "Shortest time we'll allow a benchmark to run."); | 432 DEFINE_int32(minMs, 20, "Shortest time we'll allow a benchmark to run."); |
272 DEFINE_int32(maxMs, 4000, "Longest time we'll allow a benchmark to run."); | 433 DEFINE_int32(maxMs, 4000, "Longest time we'll allow a benchmark to run."); |
273 DEFINE_double(error, 0.01, | 434 DEFINE_double(error, 0.01, |
274 "Ratio of subsequent bench measurements must drop within 1±error t o converge."); | 435 "Ratio of subsequent bench measurements must drop within 1±error t o converge."); |
275 DEFINE_string(timeFormat, "%9.2f", "Format to print results, in milliseconds per 1000 loops."); | 436 DEFINE_string(timeFormat, "%9.2f", "Format to print results, in milliseconds per 1000 loops."); |
276 DEFINE_bool2(verbose, v, false, "Print more."); | 437 DEFINE_bool2(verbose, v, false, "Print more."); |
277 DEFINE_string2(resourcePath, i, NULL, "directory for test resources."); | 438 DEFINE_string2(resourcePath, i, NULL, "directory for test resources."); |
439 DEFINE_string(outResultsFile, "", "If given, the results will be written to the file in JSON format."); | |
278 | 440 |
279 // Has this bench converged? First arguments are milliseconds / loop iteration, | 441 // Has this bench converged? First arguments are milliseconds / loop iteration, |
280 // last is overall runtime in milliseconds. | 442 // last is overall runtime in milliseconds. |
281 static bool HasConverged(double prevPerLoop, double currPerLoop, double currRaw) { | 443 static bool HasConverged(double prevPerLoop, double currPerLoop, double currRaw) { |
282 if (currRaw < FLAGS_minMs) { | 444 if (currRaw < FLAGS_minMs) { |
283 return false; | 445 return false; |
284 } | 446 } |
285 const double low = 1 - FLAGS_error, high = 1 + FLAGS_error; | 447 const double low = 1 - FLAGS_error, high = 1 + FLAGS_error; |
286 const double ratio = currPerLoop / prevPerLoop; | 448 const double ratio = currPerLoop / prevPerLoop; |
287 return low < ratio && ratio < high; | 449 return low < ratio && ratio < high; |
288 } | 450 } |
289 | 451 |
290 int tool_main(int argc, char** argv); | 452 int tool_main(int argc, char** argv); |
291 int tool_main(int argc, char** argv) { | 453 int tool_main(int argc, char** argv) { |
292 #if SK_ENABLE_INST_COUNT | 454 #if SK_ENABLE_INST_COUNT |
293 gPrintInstCount = true; | 455 gPrintInstCount = true; |
294 #endif | 456 #endif |
295 SkAutoGraphics ag; | 457 SkAutoGraphics ag; |
296 SkCommandLineFlags::Parse(argc, argv); | 458 SkCommandLineFlags::Parse(argc, argv); |
297 | 459 |
298 // First, parse some flags. | 460 // First, parse some flags. |
299 | |
300 SkBenchLogger logger; | 461 SkBenchLogger logger; |
301 if (FLAGS_logFile.count()) { | 462 if (FLAGS_logFile.count()) { |
302 logger.SetLogFile(FLAGS_logFile[0]); | 463 logger.SetLogFile(FLAGS_logFile[0]); |
303 } | 464 } |
304 | 465 |
466 LoggerResultsWriter logWriter(logger, FLAGS_timeFormat[0]); | |
467 MultiResultsWriter writer; | |
468 writer.add(&logWriter); | |
469 JSONResultsWriter* jsonWriter = NULL; | |
470 if (FLAGS_outResultsFile.count()) { | |
471 jsonWriter = SkNEW(JSONResultsWriter(FLAGS_outResultsFile[0])); | |
472 writer.add(jsonWriter); | |
473 } | |
474 | |
305 const uint8_t alpha = FLAGS_forceBlend ? 0x80 : 0xFF; | 475 const uint8_t alpha = FLAGS_forceBlend ? 0x80 : 0xFF; |
306 SkTriState::State dither = SkTriState::kDefault; | 476 SkTriState::State dither = SkTriState::kDefault; |
307 for (size_t i = 0; i < 3; i++) { | 477 for (size_t i = 0; i < 3; i++) { |
308 if (strcmp(SkTriState::Name[i], FLAGS_forceDither[0]) == 0) { | 478 if (strcmp(SkTriState::Name[i], FLAGS_forceDither[0]) == 0) { |
309 dither = static_cast<SkTriState::State>(i); | 479 dither = static_cast<SkTriState::State>(i); |
310 } | 480 } |
311 } | 481 } |
312 | 482 |
313 BenchMode benchMode = kNormal_BenchMode; | 483 BenchMode benchMode = kNormal_BenchMode; |
314 for (size_t i = 0; i < SK_ARRAY_COUNT(BenchMode_Name); i++) { | 484 for (size_t i = 0; i < SK_ARRAY_COUNT(BenchMode_Name); i++) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
377 } | 547 } |
378 } | 548 } |
379 } | 549 } |
380 #endif | 550 #endif |
381 | 551 |
382 // All flags should be parsed now. Report our settings. | 552 // All flags should be parsed now. Report our settings. |
383 if (kIsDebug) { | 553 if (kIsDebug) { |
384 logger.logError("bench was built in Debug mode, so we're going to hide t he times." | 554 logger.logError("bench was built in Debug mode, so we're going to hide t he times." |
385 " It's for your own good!\n"); | 555 " It's for your own good!\n"); |
386 } | 556 } |
387 SkString str("skia bench:"); | 557 writer.option("mode", FLAGS_mode[0]); |
388 str.appendf(" mode=%s", FLAGS_mode[0]); | 558 writer.option("alpha", SkStringPrintf("0x%02X", alpha).c_str()); |
389 str.appendf(" alpha=0x%02X antialias=%d filter=%d dither=%s", | 559 writer.option("antialias", SkStringPrintf("%d", FLAGS_forceAA).c_str()); |
390 alpha, FLAGS_forceAA, FLAGS_forceFilter, SkTriState::Name[dither ]); | 560 writer.option("filter", SkStringPrintf("%d", FLAGS_forceFilter).c_str()); |
391 str.appendf(" rotate=%d scale=%d clip=%d", FLAGS_rotate, FLAGS_scale, FLAGS_ clip); | 561 writer.option("dither", SkTriState::Name[dither]); |
562 | |
563 writer.option("rotate", SkStringPrintf("%d", FLAGS_rotate).c_str()); | |
564 writer.option("scale", SkStringPrintf("%d", FLAGS_scale).c_str()); | |
565 writer.option("clip", SkStringPrintf("%d", FLAGS_clip).c_str()); | |
392 | 566 |
393 #if defined(SK_SCALAR_IS_FIXED) | 567 #if defined(SK_SCALAR_IS_FIXED) |
394 str.append(" scalar=fixed"); | 568 writer.option("scalar", "fixed"); |
395 #else | 569 #else |
396 str.append(" scalar=float"); | 570 writer.option("scalar", "float"); |
397 #endif | 571 #endif |
398 | 572 |
399 #if defined(SK_BUILD_FOR_WIN32) | 573 #if defined(SK_BUILD_FOR_WIN32) |
400 str.append(" system=WIN32"); | 574 writer.option("system", "WIN32"); |
401 #elif defined(SK_BUILD_FOR_MAC) | 575 #elif defined(SK_BUILD_FOR_MAC) |
402 str.append(" system=MAC"); | 576 writer.option("system", "MAC"); |
403 #elif defined(SK_BUILD_FOR_ANDROID) | 577 #elif defined(SK_BUILD_FOR_ANDROID) |
404 str.append(" system=ANDROID"); | 578 writer.option("system", "ANDROID"); |
405 #elif defined(SK_BUILD_FOR_UNIX) | 579 #elif defined(SK_BUILD_FOR_UNIX) |
406 str.append(" system=UNIX"); | 580 writer.option("system", "UNIX"); |
407 #else | 581 #else |
408 str.append(" system=other"); | 582 writer.option("system", "other"); |
409 #endif | 583 #endif |
410 | 584 |
411 #if defined(SK_DEBUG) | 585 #if defined(SK_DEBUG) |
412 str.append(" DEBUG"); | 586 writer.option("build", "DEBUG"); |
587 #else | |
588 writer.option("build", "RELEASE"); | |
413 #endif | 589 #endif |
414 str.append("\n"); | |
415 logger.logProgress(str); | |
416 | |
417 | 590 |
418 // Set texture cache limits if non-default. | 591 // Set texture cache limits if non-default. |
419 for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); ++i) { | 592 for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); ++i) { |
420 #if SK_SUPPORT_GPU | 593 #if SK_SUPPORT_GPU |
421 const Config& config = gConfigs[i]; | 594 const Config& config = gConfigs[i]; |
422 if (SkBenchmark::kGPU_Backend != config.backend) { | 595 if (SkBenchmark::kGPU_Backend != config.backend) { |
423 continue; | 596 continue; |
424 } | 597 } |
425 GrContext* context = gContextFactory.get(config.contextType); | 598 GrContext* context = gContextFactory.get(config.contextType); |
426 if (NULL == context) { | 599 if (NULL == context) { |
427 continue; | 600 continue; |
428 } | 601 } |
429 | 602 |
430 size_t bytes; | 603 size_t bytes; |
431 int count; | 604 int count; |
432 context->getTextureCacheLimits(&count, &bytes); | 605 context->getTextureCacheLimits(&count, &bytes); |
433 if (-1 != FLAGS_gpuCacheBytes) { | 606 if (-1 != FLAGS_gpuCacheBytes) { |
434 bytes = static_cast<size_t>(FLAGS_gpuCacheBytes); | 607 bytes = static_cast<size_t>(FLAGS_gpuCacheBytes); |
435 } | 608 } |
436 if (-1 != FLAGS_gpuCacheCount) { | 609 if (-1 != FLAGS_gpuCacheCount) { |
437 count = FLAGS_gpuCacheCount; | 610 count = FLAGS_gpuCacheCount; |
438 } | 611 } |
439 context->setTextureCacheLimits(count, bytes); | 612 context->setTextureCacheLimits(count, bytes); |
440 #endif | 613 #endif |
441 } | 614 } |
442 | 615 |
443 // Find the longest name of the benches we're going to run to make the outpu t pretty. | |
444 Iter names; | |
445 SkBenchmark* bench; | |
446 size_t longestName = 0; | |
447 while ((bench = names.next()) != NULL) { | |
448 SkAutoTUnref<SkBenchmark> benchUnref(bench); | |
449 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getName())) { | |
450 continue; | |
451 } | |
452 const size_t length = strlen(bench->getName()); | |
453 longestName = length > longestName ? length : longestName; | |
454 } | |
455 | |
456 // Run each bench in each configuration it supports and we asked for. | 616 // Run each bench in each configuration it supports and we asked for. |
457 Iter iter; | 617 Iter iter; |
618 SkBenchmark* bench; | |
458 while ((bench = iter.next()) != NULL) { | 619 while ((bench = iter.next()) != NULL) { |
459 SkAutoTUnref<SkBenchmark> benchUnref(bench); | 620 SkAutoTUnref<SkBenchmark> benchUnref(bench); |
460 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getName())) { | 621 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getName())) { |
461 continue; | 622 continue; |
462 } | 623 } |
463 | 624 |
464 bench->setForceAlpha(alpha); | 625 bench->setForceAlpha(alpha); |
465 bench->setForceAA(FLAGS_forceAA); | 626 bench->setForceAA(FLAGS_forceAA); |
466 bench->setForceFilter(FLAGS_forceFilter); | 627 bench->setForceFilter(FLAGS_forceFilter); |
467 bench->setDither(dither); | 628 bench->setDither(dither); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
530 | 691 |
531 if (NULL != canvas) { | 692 if (NULL != canvas) { |
532 canvas->clear(SK_ColorWHITE); | 693 canvas->clear(SK_ColorWHITE); |
533 if (FLAGS_clip) { performClip(canvas, dim.fX, dim.fY); } | 694 if (FLAGS_clip) { performClip(canvas, dim.fX, dim.fY); } |
534 if (FLAGS_scale) { performScale(canvas, dim.fX, dim.fY); } | 695 if (FLAGS_scale) { performScale(canvas, dim.fX, dim.fY); } |
535 if (FLAGS_rotate) { performRotate(canvas, dim.fX, dim.fY); } | 696 if (FLAGS_rotate) { performRotate(canvas, dim.fX, dim.fY); } |
536 } | 697 } |
537 | 698 |
538 if (!loggedBenchName) { | 699 if (!loggedBenchName) { |
539 loggedBenchName = true; | 700 loggedBenchName = true; |
540 SkString str; | 701 writer.bench(bench->getName(), dim.fX, dim.fY); |
541 str.printf("running bench [%3d %3d] %*s ", | |
542 dim.fX, dim.fY, (int)longestName, bench->getName()); | |
543 logger.logProgress(str); | |
544 } | 702 } |
545 | 703 |
546 #if SK_SUPPORT_GPU | 704 #if SK_SUPPORT_GPU |
547 SkGLContextHelper* contextHelper = NULL; | 705 SkGLContextHelper* contextHelper = NULL; |
548 if (SkBenchmark::kGPU_Backend == config.backend) { | 706 if (SkBenchmark::kGPU_Backend == config.backend) { |
549 contextHelper = gContextFactory.getGLContext(config.contextType) ; | 707 contextHelper = gContextFactory.getGLContext(config.contextType) ; |
550 } | 708 } |
551 BenchTimer timer(contextHelper); | 709 BenchTimer timer(contextHelper); |
552 #else | 710 #else |
553 BenchTimer timer; | 711 BenchTimer timer; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
672 // Normalize to ms per 1000 iterations. | 830 // Normalize to ms per 1000 iterations. |
673 const double normalize = 1000.0 / loopsPerIter; | 831 const double normalize = 1000.0 / loopsPerIter; |
674 const struct { char shortName; const char* longName; double ms; } ti mes[] = { | 832 const struct { char shortName; const char* longName; double ms; } ti mes[] = { |
675 {'w', "msecs", normalize * timer.fWall}, | 833 {'w', "msecs", normalize * timer.fWall}, |
676 {'W', "Wmsecs", normalize * timer.fTruncatedWall}, | 834 {'W', "Wmsecs", normalize * timer.fTruncatedWall}, |
677 {'c', "cmsecs", normalize * timer.fCpu}, | 835 {'c', "cmsecs", normalize * timer.fCpu}, |
678 {'C', "Cmsecs", normalize * timer.fTruncatedCpu}, | 836 {'C', "Cmsecs", normalize * timer.fTruncatedCpu}, |
679 {'g', "gmsecs", normalize * timer.fGpu}, | 837 {'g', "gmsecs", normalize * timer.fGpu}, |
680 }; | 838 }; |
681 | 839 |
682 SkString result; | 840 writer.config(config.name); |
683 result.appendf(" %s:", config.name); | |
684 for (size_t i = 0; i < SK_ARRAY_COUNT(times); i++) { | 841 for (size_t i = 0; i < SK_ARRAY_COUNT(times); i++) { |
685 if (strchr(FLAGS_timers[0], times[i].shortName) && times[i].ms > 0) { | 842 if (strchr(FLAGS_timers[0], times[i].shortName) && times[i].ms > 0) { |
686 result.appendf(" %s = ", times[i].longName); | 843 writer.timer(times[i].longName, times[i].ms); |
687 result.appendf(FLAGS_timeFormat[0], times[i].ms); | |
688 } | 844 } |
689 } | 845 } |
690 logger.logProgress(result); | |
691 } | |
692 if (loggedBenchName) { | |
693 logger.logProgress("\n"); | |
694 } | 846 } |
695 } | 847 } |
848 writer.end(); | |
849 SkDELETE(jsonWriter); | |
696 #if SK_SUPPORT_GPU | 850 #if SK_SUPPORT_GPU |
697 gContextFactory.destroyContexts(); | 851 gContextFactory.destroyContexts(); |
698 #endif | 852 #endif |
699 return 0; | 853 return 0; |
700 } | 854 } |
701 | 855 |
702 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) | 856 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
703 int main(int argc, char * const argv[]) { | 857 int main(int argc, char * const argv[]) { |
704 return tool_main(argc, (char**) argv); | 858 return tool_main(argc, (char**) argv); |
705 } | 859 } |
706 #endif | 860 #endif |
OLD | NEW |