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 | |
bsalomon
2013/11/22 20:36:30
We have this same #ifdef stuff in several places,
jcgregorio
2013/11/25 14:39:16
Sure, how about include/utils/SkJSONCPP.h?
bsalomon
2013/11/25 15:28:33
SGTM
jcgregorio
2013/11/25 16:06:47
Done.
| |
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. | |
71 // | |
72 // TODO(jcgregorio) Add info if tests fail to converge? | |
73 class ResultsWriter : SkNoncopyable { | |
74 public: | |
75 virtual ~ResultsWriter() {}; | |
76 virtual void option(const char name[], const char value[]) = 0; | |
77 virtual void bench(const char name[], int32_t x, int32_t y) = 0; | |
bsalomon
2013/11/22 20:36:30
maybe some short comments about how the caller use
jcgregorio
2013/11/25 14:39:16
Done. Also, when writing the comments I realized I
| |
78 virtual void endBench() = 0; | |
79 virtual void config(const char name[]) = 0; | |
80 virtual void timer(const char name[], double ms) = 0; | |
81 virtual void end() = 0; | |
82 }; | |
83 | |
84 // This ResultsWriter handles writing out the human readable format of the | |
85 // bench results. | |
86 class LoggerResultsWriter : public ResultsWriter { | |
bsalomon
2013/11/22 20:36:30
I don't know much about the logger but I'm wonderi
jcgregorio
2013/11/25 14:39:16
The current logger also takes care of logging erro
bsalomon
2013/11/25 15:28:33
I don't know. I'm not really familiar with this. I
jcgregorio
2013/11/25 16:06:47
OK, ignoring for now.
| |
87 public: | |
88 explicit LoggerResultsWriter(SkBenchLogger& logger, const char* timeFormat) | |
89 : fLogger(logger) | |
90 , fTimeFormat(timeFormat) | |
91 , fFinishedOptions(false) { | |
92 fLogger.logProgress("skia bench:"); | |
93 } | |
94 virtual void option(const char name[], const char value[]) { | |
95 fLogger.logProgress(SkStringPrintf(" %s=%s", name, value)); | |
96 } | |
97 virtual void bench(const char name[], int32_t x, int32_t y) { | |
98 if (!fFinishedOptions) { | |
99 fLogger.logProgress("\n"); | |
100 fFinishedOptions = true; | |
101 } | |
102 fLogger.logProgress(SkStringPrintf( | |
103 "running bench [%3d %3d] %040s", x, y, name)); | |
104 } | |
105 virtual void endBench() { | |
106 fLogger.logProgress("\n"); | |
107 } | |
108 virtual void config(const char name[]) { | |
109 fLogger.logProgress(SkStringPrintf(" %s:", name)); | |
110 } | |
111 virtual void timer(const char name[], double ms) { | |
112 fLogger.logProgress(SkStringPrintf(" %s = ", name)); | |
113 fLogger.logProgress(SkStringPrintf(fTimeFormat, ms)); | |
114 } | |
115 virtual void end() { | |
116 fLogger.logProgress("\n"); | |
117 } | |
118 private: | |
119 SkBenchLogger& fLogger; | |
120 const char* fTimeFormat; | |
121 bool fFinishedOptions; | |
122 }; | |
123 | |
124 // This ResultsWriter handles writing out the results in JSON. | |
125 // | |
126 // The output looks like: | |
127 // | |
128 // { | |
129 // "options" : { | |
130 // "alpha" : "0xFF", | |
131 // "scale" : "0", | |
132 // ... | |
133 // "system" : "UNIX" | |
134 // }, | |
135 // "results" : { | |
136 // "Xfermode_Luminosity_640_480" : { | |
137 // "565" : { | |
138 // "cmsecs" : 143.188128906250, | |
139 // "msecs" : 143.835957031250 | |
140 // }, | |
141 // ... | |
142 // | |
143 class JSONResultsWriter : public ResultsWriter { | |
144 public: | |
145 explicit JSONResultsWriter(const char filename[]) | |
146 : fFilename(filename) | |
147 , fRoot() | |
148 , fResults(fRoot["results"]) | |
149 , fBench(NULL) | |
150 , fConfig(NULL) { | |
151 } | |
152 virtual void option(const char name[], const char value[]) { | |
153 fRoot["options"][name] = value; | |
154 } | |
155 virtual void bench(const char name[], int32_t x, int32_t y) { | |
156 fBench = &fResults[SkStringPrintf( "%s_%d_%d", name, x, y).c_str()]; | |
157 } | |
158 virtual void endBench() { | |
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() { | |
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 endBench() { | |
200 for (int i = 0; i < writers.count(); ++i) { | |
201 writers[i]->endBench(); | |
202 } | |
203 } | |
204 virtual void config(const char name[]) { | |
205 for (int i = 0; i < writers.count(); ++i) { | |
206 writers[i]->config(name); | |
207 } | |
208 } | |
209 virtual void timer(const char name[], double ms) { | |
210 for (int i = 0; i < writers.count(); ++i) { | |
211 writers[i]->timer(name, ms); | |
212 } | |
213 } | |
214 virtual void end() { | |
215 for (int i = 0; i < writers.count(); ++i) { | |
216 writers[i]->end(); | |
217 } | |
218 } | |
219 private: | |
220 SkTArray<ResultsWriter *> writers; | |
221 }; | |
222 | |
57 class Iter { | 223 class Iter { |
58 public: | 224 public: |
59 Iter() : fBench(BenchRegistry::Head()) {} | 225 Iter() : fBench(BenchRegistry::Head()) {} |
60 | 226 |
61 SkBenchmark* next() { | 227 SkBenchmark* next() { |
62 if (fBench) { | 228 if (fBench) { |
63 BenchRegistry::Factory f = fBench->factory(); | 229 BenchRegistry::Factory f = fBench->factory(); |
64 fBench = fBench->next(); | 230 fBench = fBench->next(); |
65 return f(); | 231 return f(); |
66 } | 232 } |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
268 DEFINE_string(config, kDefaultsConfigStr, | 434 DEFINE_string(config, kDefaultsConfigStr, |
269 "Run configs given. By default, runs the configs marked \"runByDe fault\" in gConfigs."); | 435 "Run configs given. By default, runs the configs marked \"runByDe fault\" in gConfigs."); |
270 DEFINE_string(logFile, "", "Also write stdout here."); | 436 DEFINE_string(logFile, "", "Also write stdout here."); |
271 DEFINE_int32(minMs, 20, "Shortest time we'll allow a benchmark to run."); | 437 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."); | 438 DEFINE_int32(maxMs, 4000, "Longest time we'll allow a benchmark to run."); |
273 DEFINE_double(error, 0.01, | 439 DEFINE_double(error, 0.01, |
274 "Ratio of subsequent bench measurements must drop within 1±error t o converge."); | 440 "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."); | 441 DEFINE_string(timeFormat, "%9.2f", "Format to print results, in milliseconds per 1000 loops."); |
276 DEFINE_bool2(verbose, v, false, "Print more."); | 442 DEFINE_bool2(verbose, v, false, "Print more."); |
277 DEFINE_string2(resourcePath, i, NULL, "directory for test resources."); | 443 DEFINE_string2(resourcePath, i, NULL, "directory for test resources."); |
444 DEFINE_string(outResultsFile, "", "If given, the results will be written to the file in JSON format."); | |
278 | 445 |
279 // Has this bench converged? First arguments are milliseconds / loop iteration, | 446 // Has this bench converged? First arguments are milliseconds / loop iteration, |
280 // last is overall runtime in milliseconds. | 447 // last is overall runtime in milliseconds. |
281 static bool HasConverged(double prevPerLoop, double currPerLoop, double currRaw) { | 448 static bool HasConverged(double prevPerLoop, double currPerLoop, double currRaw) { |
282 if (currRaw < FLAGS_minMs) { | 449 if (currRaw < FLAGS_minMs) { |
283 return false; | 450 return false; |
284 } | 451 } |
285 const double low = 1 - FLAGS_error, high = 1 + FLAGS_error; | 452 const double low = 1 - FLAGS_error, high = 1 + FLAGS_error; |
286 const double ratio = currPerLoop / prevPerLoop; | 453 const double ratio = currPerLoop / prevPerLoop; |
287 return low < ratio && ratio < high; | 454 return low < ratio && ratio < high; |
288 } | 455 } |
289 | 456 |
290 int tool_main(int argc, char** argv); | 457 int tool_main(int argc, char** argv); |
291 int tool_main(int argc, char** argv) { | 458 int tool_main(int argc, char** argv) { |
292 #if SK_ENABLE_INST_COUNT | 459 #if SK_ENABLE_INST_COUNT |
293 gPrintInstCount = true; | 460 gPrintInstCount = true; |
294 #endif | 461 #endif |
295 SkAutoGraphics ag; | 462 SkAutoGraphics ag; |
296 SkCommandLineFlags::Parse(argc, argv); | 463 SkCommandLineFlags::Parse(argc, argv); |
297 | 464 |
298 // First, parse some flags. | 465 // First, parse some flags. |
299 | |
300 SkBenchLogger logger; | 466 SkBenchLogger logger; |
301 if (FLAGS_logFile.count()) { | 467 if (FLAGS_logFile.count()) { |
302 logger.SetLogFile(FLAGS_logFile[0]); | 468 logger.SetLogFile(FLAGS_logFile[0]); |
303 } | 469 } |
304 | 470 |
471 LoggerResultsWriter logWriter(logger, FLAGS_timeFormat[0]); | |
472 MultiResultsWriter writer; | |
473 writer.add(&logWriter); | |
474 JSONResultsWriter* jsonWriter = NULL; | |
475 if (FLAGS_outResultsFile.count()) { | |
476 jsonWriter = SkNEW(JSONResultsWriter(FLAGS_outResultsFile[0])); | |
477 writer.add(jsonWriter); | |
478 } | |
479 | |
305 const uint8_t alpha = FLAGS_forceBlend ? 0x80 : 0xFF; | 480 const uint8_t alpha = FLAGS_forceBlend ? 0x80 : 0xFF; |
306 SkTriState::State dither = SkTriState::kDefault; | 481 SkTriState::State dither = SkTriState::kDefault; |
307 for (size_t i = 0; i < 3; i++) { | 482 for (size_t i = 0; i < 3; i++) { |
308 if (strcmp(SkTriState::Name[i], FLAGS_forceDither[0]) == 0) { | 483 if (strcmp(SkTriState::Name[i], FLAGS_forceDither[0]) == 0) { |
309 dither = static_cast<SkTriState::State>(i); | 484 dither = static_cast<SkTriState::State>(i); |
310 } | 485 } |
311 } | 486 } |
312 | 487 |
313 BenchMode benchMode = kNormal_BenchMode; | 488 BenchMode benchMode = kNormal_BenchMode; |
314 for (size_t i = 0; i < SK_ARRAY_COUNT(BenchMode_Name); i++) { | 489 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 } | 552 } |
378 } | 553 } |
379 } | 554 } |
380 #endif | 555 #endif |
381 | 556 |
382 // All flags should be parsed now. Report our settings. | 557 // All flags should be parsed now. Report our settings. |
383 if (kIsDebug) { | 558 if (kIsDebug) { |
384 logger.logError("bench was built in Debug mode, so we're going to hide t he times." | 559 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"); | 560 " It's for your own good!\n"); |
386 } | 561 } |
387 SkString str("skia bench:"); | 562 writer.option("mode", FLAGS_mode[0]); |
388 str.appendf(" mode=%s", FLAGS_mode[0]); | 563 writer.option("alpha", SkStringPrintf("0x%02X", alpha).c_str()); |
389 str.appendf(" alpha=0x%02X antialias=%d filter=%d dither=%s", | 564 writer.option("antialias", SkStringPrintf("%d", FLAGS_forceAA).c_str()); |
390 alpha, FLAGS_forceAA, FLAGS_forceFilter, SkTriState::Name[dither ]); | 565 writer.option("filter", SkStringPrintf("%d", FLAGS_forceFilter).c_str()); |
391 str.appendf(" rotate=%d scale=%d clip=%d", FLAGS_rotate, FLAGS_scale, FLAGS_ clip); | 566 writer.option("dither", SkTriState::Name[dither]); |
567 | |
568 writer.option("rotate", SkStringPrintf("%d", FLAGS_rotate).c_str()); | |
569 writer.option("scale", SkStringPrintf("%d", FLAGS_scale).c_str()); | |
570 writer.option("clip", SkStringPrintf("%d", FLAGS_clip).c_str()); | |
392 | 571 |
393 #if defined(SK_SCALAR_IS_FIXED) | 572 #if defined(SK_SCALAR_IS_FIXED) |
394 str.append(" scalar=fixed"); | 573 writer.option("scalar", "fixed"); |
395 #else | 574 #else |
396 str.append(" scalar=float"); | 575 writer.option("scalar", "float"); |
397 #endif | 576 #endif |
398 | 577 |
399 #if defined(SK_BUILD_FOR_WIN32) | 578 #if defined(SK_BUILD_FOR_WIN32) |
400 str.append(" system=WIN32"); | 579 writer.option("system", "WIN32"); |
401 #elif defined(SK_BUILD_FOR_MAC) | 580 #elif defined(SK_BUILD_FOR_MAC) |
402 str.append(" system=MAC"); | 581 writer.option("system", "MAC"); |
403 #elif defined(SK_BUILD_FOR_ANDROID) | 582 #elif defined(SK_BUILD_FOR_ANDROID) |
404 str.append(" system=ANDROID"); | 583 writer.option("system", "ANDROID"); |
405 #elif defined(SK_BUILD_FOR_UNIX) | 584 #elif defined(SK_BUILD_FOR_UNIX) |
406 str.append(" system=UNIX"); | 585 writer.option("system", "UNIX"); |
407 #else | 586 #else |
408 str.append(" system=other"); | 587 writer.option("system", "other"); |
409 #endif | 588 #endif |
410 | 589 |
411 #if defined(SK_DEBUG) | 590 #if defined(SK_DEBUG) |
412 str.append(" DEBUG"); | 591 writer.option("build", "DEBUG"); |
592 #else | |
593 writer.option("build", "RELEASE"); | |
413 #endif | 594 #endif |
414 str.append("\n"); | |
415 logger.logProgress(str); | |
416 | |
417 | 595 |
418 // Set texture cache limits if non-default. | 596 // Set texture cache limits if non-default. |
419 for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); ++i) { | 597 for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); ++i) { |
420 #if SK_SUPPORT_GPU | 598 #if SK_SUPPORT_GPU |
421 const Config& config = gConfigs[i]; | 599 const Config& config = gConfigs[i]; |
422 if (SkBenchmark::kGPU_Backend != config.backend) { | 600 if (SkBenchmark::kGPU_Backend != config.backend) { |
423 continue; | 601 continue; |
424 } | 602 } |
425 GrContext* context = gContextFactory.get(config.contextType); | 603 GrContext* context = gContextFactory.get(config.contextType); |
426 if (NULL == context) { | 604 if (NULL == context) { |
427 continue; | 605 continue; |
428 } | 606 } |
429 | 607 |
430 size_t bytes; | 608 size_t bytes; |
431 int count; | 609 int count; |
432 context->getTextureCacheLimits(&count, &bytes); | 610 context->getTextureCacheLimits(&count, &bytes); |
433 if (-1 != FLAGS_gpuCacheBytes) { | 611 if (-1 != FLAGS_gpuCacheBytes) { |
434 bytes = static_cast<size_t>(FLAGS_gpuCacheBytes); | 612 bytes = static_cast<size_t>(FLAGS_gpuCacheBytes); |
435 } | 613 } |
436 if (-1 != FLAGS_gpuCacheCount) { | 614 if (-1 != FLAGS_gpuCacheCount) { |
437 count = FLAGS_gpuCacheCount; | 615 count = FLAGS_gpuCacheCount; |
438 } | 616 } |
439 context->setTextureCacheLimits(count, bytes); | 617 context->setTextureCacheLimits(count, bytes); |
440 #endif | 618 #endif |
441 } | 619 } |
442 | 620 |
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. | 621 // Run each bench in each configuration it supports and we asked for. |
457 Iter iter; | 622 Iter iter; |
623 SkBenchmark* bench; | |
458 while ((bench = iter.next()) != NULL) { | 624 while ((bench = iter.next()) != NULL) { |
459 SkAutoTUnref<SkBenchmark> benchUnref(bench); | 625 SkAutoTUnref<SkBenchmark> benchUnref(bench); |
460 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getName())) { | 626 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getName())) { |
461 continue; | 627 continue; |
462 } | 628 } |
463 | 629 |
464 bench->setForceAlpha(alpha); | 630 bench->setForceAlpha(alpha); |
465 bench->setForceAA(FLAGS_forceAA); | 631 bench->setForceAA(FLAGS_forceAA); |
466 bench->setForceFilter(FLAGS_forceFilter); | 632 bench->setForceFilter(FLAGS_forceFilter); |
467 bench->setDither(dither); | 633 bench->setDither(dither); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
530 | 696 |
531 if (NULL != canvas) { | 697 if (NULL != canvas) { |
532 canvas->clear(SK_ColorWHITE); | 698 canvas->clear(SK_ColorWHITE); |
533 if (FLAGS_clip) { performClip(canvas, dim.fX, dim.fY); } | 699 if (FLAGS_clip) { performClip(canvas, dim.fX, dim.fY); } |
534 if (FLAGS_scale) { performScale(canvas, dim.fX, dim.fY); } | 700 if (FLAGS_scale) { performScale(canvas, dim.fX, dim.fY); } |
535 if (FLAGS_rotate) { performRotate(canvas, dim.fX, dim.fY); } | 701 if (FLAGS_rotate) { performRotate(canvas, dim.fX, dim.fY); } |
536 } | 702 } |
537 | 703 |
538 if (!loggedBenchName) { | 704 if (!loggedBenchName) { |
539 loggedBenchName = true; | 705 loggedBenchName = true; |
540 SkString str; | 706 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 } | 707 } |
545 | 708 |
546 #if SK_SUPPORT_GPU | 709 #if SK_SUPPORT_GPU |
547 SkGLContextHelper* contextHelper = NULL; | 710 SkGLContextHelper* contextHelper = NULL; |
548 if (SkBenchmark::kGPU_Backend == config.backend) { | 711 if (SkBenchmark::kGPU_Backend == config.backend) { |
549 contextHelper = gContextFactory.getGLContext(config.contextType) ; | 712 contextHelper = gContextFactory.getGLContext(config.contextType) ; |
550 } | 713 } |
551 BenchTimer timer(contextHelper); | 714 BenchTimer timer(contextHelper); |
552 #else | 715 #else |
553 BenchTimer timer; | 716 BenchTimer timer; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
672 // Normalize to ms per 1000 iterations. | 835 // Normalize to ms per 1000 iterations. |
673 const double normalize = 1000.0 / loopsPerIter; | 836 const double normalize = 1000.0 / loopsPerIter; |
674 const struct { char shortName; const char* longName; double ms; } ti mes[] = { | 837 const struct { char shortName; const char* longName; double ms; } ti mes[] = { |
675 {'w', "msecs", normalize * timer.fWall}, | 838 {'w', "msecs", normalize * timer.fWall}, |
676 {'W', "Wmsecs", normalize * timer.fTruncatedWall}, | 839 {'W', "Wmsecs", normalize * timer.fTruncatedWall}, |
677 {'c', "cmsecs", normalize * timer.fCpu}, | 840 {'c', "cmsecs", normalize * timer.fCpu}, |
678 {'C', "Cmsecs", normalize * timer.fTruncatedCpu}, | 841 {'C', "Cmsecs", normalize * timer.fTruncatedCpu}, |
679 {'g', "gmsecs", normalize * timer.fGpu}, | 842 {'g', "gmsecs", normalize * timer.fGpu}, |
680 }; | 843 }; |
681 | 844 |
682 SkString result; | 845 writer.config(config.name); |
683 result.appendf(" %s:", config.name); | |
684 for (size_t i = 0; i < SK_ARRAY_COUNT(times); i++) { | 846 for (size_t i = 0; i < SK_ARRAY_COUNT(times); i++) { |
685 if (strchr(FLAGS_timers[0], times[i].shortName) && times[i].ms > 0) { | 847 if (strchr(FLAGS_timers[0], times[i].shortName) && times[i].ms > 0) { |
686 result.appendf(" %s = ", times[i].longName); | 848 writer.timer(times[i].longName, times[i].ms); |
687 result.appendf(FLAGS_timeFormat[0], times[i].ms); | |
688 } | 849 } |
689 } | 850 } |
690 logger.logProgress(result); | |
691 } | 851 } |
692 if (loggedBenchName) { | 852 if (loggedBenchName) { |
693 logger.logProgress("\n"); | 853 writer.endBench(); |
694 } | 854 } |
695 } | 855 } |
856 writer.end(); | |
857 if (NULL != jsonWriter) { | |
858 SkDELETE(jsonWriter); | |
bsalomon
2013/11/22 20:36:30
I don't think you need the NULL check.
jcgregorio
2013/11/25 14:39:16
Done.
| |
859 } | |
696 #if SK_SUPPORT_GPU | 860 #if SK_SUPPORT_GPU |
697 gContextFactory.destroyContexts(); | 861 gContextFactory.destroyContexts(); |
698 #endif | 862 #endif |
699 return 0; | 863 return 0; |
700 } | 864 } |
701 | 865 |
702 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) | 866 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
703 int main(int argc, char * const argv[]) { | 867 int main(int argc, char * const argv[]) { |
704 return tool_main(argc, (char**) argv); | 868 return tool_main(argc, (char**) argv); |
705 } | 869 } |
706 #endif | 870 #endif |
OLD | NEW |