| 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 "nanobench.h" | 10 #include "nanobench.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 } | 130 } |
| 131 void endTiming() override { | 131 void endTiming() override { |
| 132 if (this->gl) { | 132 if (this->gl) { |
| 133 SK_GL(*this->gl, Flush()); | 133 SK_GL(*this->gl, Flush()); |
| 134 this->gl->swapBuffers(); | 134 this->gl->swapBuffers(); |
| 135 } | 135 } |
| 136 } | 136 } |
| 137 void fence() override { | 137 void fence() override { |
| 138 SK_GL(*this->gl, Finish()); | 138 SK_GL(*this->gl, Finish()); |
| 139 } | 139 } |
| 140 | 140 |
| 141 bool needsFrameTiming() const override { return true; } | 141 bool needsFrameTiming() const override { return true; } |
| 142 bool init(SkImageInfo info, Benchmark* bench) override { | 142 bool init(SkImageInfo info, Benchmark* bench) override { |
| 143 uint32_t flags = this->config.useDFText ? SkSurfaceProps::kUseDistanceFi
eldFonts_Flag : 0; | 143 uint32_t flags = this->config.useDFText ? SkSurfaceProps::kUseDistanceFi
eldFonts_Flag : 0; |
| 144 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); | 144 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); |
| 145 this->surface.reset(SkSurface::NewRenderTarget(gGrFactory->get(this->con
fig.ctxType), | 145 this->surface.reset(SkSurface::NewRenderTarget(gGrFactory->get(this->con
fig.ctxType), |
| 146 SkSurface::kNo_Budgeted
, info, | 146 SkSurface::kNo_Budgeted
, info, |
| 147 this->config.samples, &
props)); | 147 this->config.samples, &
props)); |
| 148 this->gl = gGrFactory->getGLContext(this->config.ctxType); | 148 this->gl = gGrFactory->getGLContext(this->config.ctxType); |
| 149 if (!this->surface.get()) { | 149 if (!this->surface.get()) { |
| 150 return false; | 150 return false; |
| 151 } | 151 } |
| 152 return true; | 152 return true; |
| 153 } | 153 } |
| 154 void fillOptions(ResultsWriter* log) override { | 154 void fillOptions(ResultsWriter* log) override { |
| 155 const GrGLubyte* version; | 155 const GrGLubyte* version; |
| 156 SK_GL_RET(*this->gl, version, GetString(GR_GL_VERSION)); | 156 SK_GL_RET(*this->gl, version, GetString(GR_GL_VERSION)); |
| 157 log->configOption("GL_VERSION", (const char*)(version)); | 157 log->configOption("GL_VERSION", (const char*)(version)); |
| 158 | 158 |
| 159 SK_GL_RET(*this->gl, version, GetString(GR_GL_RENDERER)); | 159 SK_GL_RET(*this->gl, version, GetString(GR_GL_RENDERER)); |
| 160 log->configOption("GL_RENDERER", (const char*) version); | 160 log->configOption("GL_RENDERER", (const char*) version); |
| 161 | 161 |
| 162 SK_GL_RET(*this->gl, version, GetString(GR_GL_VENDOR)); | 162 SK_GL_RET(*this->gl, version, GetString(GR_GL_VENDOR)); |
| 163 log->configOption("GL_VENDOR", (const char*) version); | 163 log->configOption("GL_VENDOR", (const char*) version); |
| 164 | 164 |
| 165 SK_GL_RET(*this->gl, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION))
; | 165 SK_GL_RET(*this->gl, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION))
; |
| 166 log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version); | 166 log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version); |
| 167 } | 167 } |
| 168 }; | 168 }; |
| 169 | 169 |
| 170 #endif | 170 #endif |
| 171 | 171 |
| 172 static double time(int loops, Benchmark* bench, Target* target) { | 172 static double time(int loops, Benchmark* bench, Target* target) { |
| 173 SkCanvas* canvas = target->getCanvas(); | 173 SkCanvas* canvas = target->getCanvas(); |
| 174 if (canvas) { | 174 if (canvas) { |
| 175 canvas->clear(SK_ColorWHITE); | 175 canvas->clear(SK_ColorWHITE); |
| 176 } | 176 } |
| 177 WallTimer timer; | 177 WallTimer timer; |
| 178 timer.start(); | 178 timer.start(); |
| 179 canvas = target->beginTiming(canvas); | 179 canvas = target->beginTiming(canvas); |
| (...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 | 892 |
| 893 SkAutoTMalloc<double> samples(FLAGS_samples); | 893 SkAutoTMalloc<double> samples(FLAGS_samples); |
| 894 | 894 |
| 895 if (kAutoTuneLoops != FLAGS_loops) { | 895 if (kAutoTuneLoops != FLAGS_loops) { |
| 896 SkDebugf("Fixed number of loops; times would only be misleading so we wo
n't print them.\n"); | 896 SkDebugf("Fixed number of loops; times would only be misleading so we wo
n't print them.\n"); |
| 897 } else if (FLAGS_verbose) { | 897 } else if (FLAGS_verbose) { |
| 898 // No header. | 898 // No header. |
| 899 } else if (FLAGS_quiet) { | 899 } else if (FLAGS_quiet) { |
| 900 SkDebugf("median\tbench\tconfig\n"); | 900 SkDebugf("median\tbench\tconfig\n"); |
| 901 } else { | 901 } else { |
| 902 SkDebugf("maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\t%-*s\tconfig\tb
ench\n", | 902 SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\t%-*s\tconf
ig\tbench\n", |
| 903 FLAGS_samples, "samples"); | 903 FLAGS_samples, "samples"); |
| 904 } | 904 } |
| 905 | 905 |
| 906 SkTDArray<Config> configs; | 906 SkTDArray<Config> configs; |
| 907 create_configs(&configs); | 907 create_configs(&configs); |
| 908 | 908 |
| 909 int runs = 0; | 909 int runs = 0; |
| 910 BenchmarkStream benchStream; | 910 BenchmarkStream benchStream; |
| 911 while (Benchmark* b = benchStream.next()) { | 911 while (Benchmark* b = benchStream.next()) { |
| 912 SkAutoTDelete<Benchmark> bench(b); | 912 SkAutoTDelete<Benchmark> bench(b); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 956 targets[j]->fillOptions(log.get()); | 956 targets[j]->fillOptions(log.get()); |
| 957 log->metric("min_ms", stats.min); | 957 log->metric("min_ms", stats.min); |
| 958 if (runs++ % FLAGS_flushEvery == 0) { | 958 if (runs++ % FLAGS_flushEvery == 0) { |
| 959 log->flush(); | 959 log->flush(); |
| 960 } | 960 } |
| 961 | 961 |
| 962 if (kAutoTuneLoops != FLAGS_loops) { | 962 if (kAutoTuneLoops != FLAGS_loops) { |
| 963 if (targets.count() == 1) { | 963 if (targets.count() == 1) { |
| 964 config = ""; // Only print the config if we run the same ben
ch on more than one. | 964 config = ""; // Only print the config if we run the same ben
ch on more than one. |
| 965 } | 965 } |
| 966 SkDebugf("%4dM\t%s\t%s\n" | 966 SkDebugf("%4d/%-4dMB\t%s\t%s\n" |
| 967 , sk_tools::getBestResidentSetSizeMB() | 967 , sk_tools::getCurrResidentSetSizeMB() |
| 968 , sk_tools::getMaxResidentSetSizeMB() |
| 968 , bench->getUniqueName() | 969 , bench->getUniqueName() |
| 969 , config); | 970 , config); |
| 970 } else if (FLAGS_verbose) { | 971 } else if (FLAGS_verbose) { |
| 971 for (int i = 0; i < FLAGS_samples; i++) { | 972 for (int i = 0; i < FLAGS_samples; i++) { |
| 972 SkDebugf("%s ", HUMANIZE(samples[i])); | 973 SkDebugf("%s ", HUMANIZE(samples[i])); |
| 973 } | 974 } |
| 974 SkDebugf("%s\n", bench->getUniqueName()); | 975 SkDebugf("%s\n", bench->getUniqueName()); |
| 975 } else if (FLAGS_quiet) { | 976 } else if (FLAGS_quiet) { |
| 976 if (targets.count() == 1) { | 977 if (targets.count() == 1) { |
| 977 config = ""; // Only print the config if we run the same ben
ch on more than one. | 978 config = ""; // Only print the config if we run the same ben
ch on more than one. |
| 978 } | 979 } |
| 979 SkDebugf("%s\t%s\t%s\n", HUMANIZE(stats.median), bench->getUniqu
eName(), config); | 980 SkDebugf("%s\t%s\t%s\n", HUMANIZE(stats.median), bench->getUniqu
eName(), config); |
| 980 } else { | 981 } else { |
| 981 const double stddev_percent = 100 * sqrt(stats.var) / stats.mean
; | 982 const double stddev_percent = 100 * sqrt(stats.var) / stats.mean
; |
| 982 SkDebugf("%4dM\t%d\t%s\t%s\t%s\t%s\t%.0f%%\t%s\t%s\t%s\n" | 983 SkDebugf("%4d/%-4dMB\t%d\t%s\t%s\t%s\t%s\t%.0f%%\t%s\t%s\t%s\n" |
| 983 , sk_tools::getBestResidentSetSizeMB() | 984 , sk_tools::getCurrResidentSetSizeMB() |
| 985 , sk_tools::getMaxResidentSetSizeMB() |
| 984 , loops | 986 , loops |
| 985 , HUMANIZE(stats.min) | 987 , HUMANIZE(stats.min) |
| 986 , HUMANIZE(stats.median) | 988 , HUMANIZE(stats.median) |
| 987 , HUMANIZE(stats.mean) | 989 , HUMANIZE(stats.mean) |
| 988 , HUMANIZE(stats.max) | 990 , HUMANIZE(stats.max) |
| 989 , stddev_percent | 991 , stddev_percent |
| 990 , stats.plot.c_str() | 992 , stats.plot.c_str() |
| 991 , config | 993 , config |
| 992 , bench->getUniqueName() | 994 , bench->getUniqueName() |
| 993 ); | 995 ); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1024 | 1026 |
| 1025 return 0; | 1027 return 0; |
| 1026 } | 1028 } |
| 1027 | 1029 |
| 1028 #if !defined SK_BUILD_FOR_IOS | 1030 #if !defined SK_BUILD_FOR_IOS |
| 1029 int main(int argc, char** argv) { | 1031 int main(int argc, char** argv) { |
| 1030 SkCommandLineFlags::Parse(argc, argv); | 1032 SkCommandLineFlags::Parse(argc, argv); |
| 1031 return nanobench_main(); | 1033 return nanobench_main(); |
| 1032 } | 1034 } |
| 1033 #endif | 1035 #endif |
| OLD | NEW |