| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "GrContextFactory.h" | 8 #include "GrContextFactory.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkOSFile.h" | 10 #include "SkOSFile.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 DEFINE_int32(duration, 5000, "number of milliseconds to run the benchmark"); | 36 DEFINE_int32(duration, 5000, "number of milliseconds to run the benchmark"); |
| 37 DEFINE_int32(sampleMs, 50, "minimum duration of a sample"); | 37 DEFINE_int32(sampleMs, 50, "minimum duration of a sample"); |
| 38 DEFINE_bool(fps, false, "use fps instead of ms"); | 38 DEFINE_bool(fps, false, "use fps instead of ms"); |
| 39 DEFINE_string(skp, "", "path to a single .skp file to benchmark"); | 39 DEFINE_string(skp, "", "path to a single .skp file to benchmark"); |
| 40 DEFINE_string(png, "", "if set, save a .png proof to disk at this file location"
); | 40 DEFINE_string(png, "", "if set, save a .png proof to disk at this file location"
); |
| 41 DEFINE_int32(verbosity, 4, "level of verbosity (0=none to 5=debug)"); | 41 DEFINE_int32(verbosity, 4, "level of verbosity (0=none to 5=debug)"); |
| 42 DEFINE_bool(suppressHeader, false, "don't print a header row before the results"
); | 42 DEFINE_bool(suppressHeader, false, "don't print a header row before the results"
); |
| 43 | 43 |
| 44 static const char* header = | 44 static const char* header = |
| 45 " median accum max min stddev metric samples sample_ms
config bench"; | 45 " accum median max min stddev samples sample_ms metric
config bench"; |
| 46 | 46 |
| 47 static const char* resultFormat = | 47 static const char* resultFormat = |
| 48 "%8.4g %8.4g %8.4g %8.4g %6.3g%% %-6s %7li %9i %-9s %s"; | 48 "%8.4g %8.4g %8.4g %8.4g %6.3g%% %7li %9i %-6s %-9s %s"; |
| 49 | 49 |
| 50 struct Sample { | 50 struct Sample { |
| 51 using clock = std::chrono::high_resolution_clock; | 51 using clock = std::chrono::high_resolution_clock; |
| 52 | 52 |
| 53 Sample() : fFrames(0), fDuration(0) {} | 53 Sample() : fFrames(0), fDuration(0) {} |
| 54 double seconds() const { return std::chrono::duration<double>(fDuration).cou
nt(); } | 54 double seconds() const { return std::chrono::duration<double>(fDuration).cou
nt(); } |
| 55 double ms() const { return std::chrono::duration<double, std::milli>(fDurati
on).count(); } | 55 double ms() const { return std::chrono::duration<double, std::milli>(fDurati
on).count(); } |
| 56 double value() const { return FLAGS_fps ? fFrames / this->seconds() : this->
ms() / fFrames; } | 56 double value() const { return FLAGS_fps ? fFrames / this->seconds() : this->
ms() / fFrames; } |
| 57 static const char* metric() { return FLAGS_fps ? "fps" : "ms"; } | 57 static const char* metric() { return FLAGS_fps ? "fps" : "ms"; } |
| 58 | 58 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 126 |
| 127 Sample accum = Sample(); | 127 Sample accum = Sample(); |
| 128 std::vector<double> values; | 128 std::vector<double> values; |
| 129 values.reserve(samples.size()); | 129 values.reserve(samples.size()); |
| 130 for (const Sample& sample : samples) { | 130 for (const Sample& sample : samples) { |
| 131 accum.fFrames += sample.fFrames; | 131 accum.fFrames += sample.fFrames; |
| 132 accum.fDuration += sample.fDuration; | 132 accum.fDuration += sample.fDuration; |
| 133 values.push_back(sample.value()); | 133 values.push_back(sample.value()); |
| 134 } | 134 } |
| 135 std::sort(values.begin(), values.end()); | 135 std::sort(values.begin(), values.end()); |
| 136 const double medianValue = values[values.size() / 2]; | 136 |
| 137 const double accumValue = accum.value(); | 137 const double accumValue = accum.value(); |
| 138 | |
| 139 double variance = 0; | 138 double variance = 0; |
| 140 for (double value : values) { | 139 for (double value : values) { |
| 141 const double delta = value - accumValue; | 140 const double delta = value - accumValue; |
| 142 variance += delta * delta; | 141 variance += delta * delta; |
| 143 } | 142 } |
| 144 variance /= values.size(); | 143 variance /= values.size(); |
| 145 // Technically, this is the relative standard deviation. | 144 // Technically, this is the relative standard deviation. |
| 146 const double stddev = 100/*%*/ * sqrt(variance) / accumValue; | 145 const double stddev = 100/*%*/ * sqrt(variance) / accumValue; |
| 147 | 146 |
| 148 printf(resultFormat, medianValue, accumValue, values.back(), values.front(),
stddev, | 147 printf(resultFormat, accumValue, values[values.size() / 2], values.back(), v
alues.front(), |
| 149 Sample::metric(), values.size(), FLAGS_sampleMs, config, bench); | 148 stddev, values.size(), FLAGS_sampleMs, Sample::metric(), config, benc
h); |
| 150 printf("\n"); | 149 printf("\n"); |
| 151 fflush(stdout); | 150 fflush(stdout); |
| 152 } | 151 } |
| 153 | 152 |
| 154 int main(int argc, char** argv) { | 153 int main(int argc, char** argv) { |
| 155 SkCommandLineFlags::SetUsage("Use skpbench.py instead. " | 154 SkCommandLineFlags::SetUsage("Use skpbench.py instead. " |
| 156 "You usually don't want to use this program dir
ectly."); | 155 "You usually don't want to use this program dir
ectly."); |
| 157 SkCommandLineFlags::Parse(argc, argv); | 156 SkCommandLineFlags::Parse(argc, argv); |
| 158 | 157 |
| 159 if (!FLAGS_suppressHeader) { | 158 if (!FLAGS_suppressHeader) { |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 fFenceSync->deleteFence(fFence); | 315 fFenceSync->deleteFence(fFence); |
| 317 this->updateFence(); | 316 this->updateFence(); |
| 318 } | 317 } |
| 319 | 318 |
| 320 void GpuSync::updateFence() { | 319 void GpuSync::updateFence() { |
| 321 fFence = fFenceSync->insertFence(); | 320 fFence = fFenceSync->insertFence(); |
| 322 if (kInvalidPlatformGpuFence == fFence) { | 321 if (kInvalidPlatformGpuFence == fFence) { |
| 323 exitf(ExitErr::kUnavailable, "failed to insert fence"); | 322 exitf(ExitErr::kUnavailable, "failed to insert fence"); |
| 324 } | 323 } |
| 325 } | 324 } |
| OLD | NEW |