joshualitt | 189aef7 | 2015-09-08 07:08:11 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
joshualitt | 189aef7 | 2015-09-08 07:08:11 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include "VisualLightweightBenchModule.h" |
| 9 | |
| 10 | #include "ProcStats.h" |
| 11 | #include "SkApplication.h" |
| 12 | #include "SkCanvas.h" |
| 13 | #include "SkCommandLineFlags.h" |
| 14 | #include "SkForceLinking.h" |
| 15 | #include "SkGraphics.h" |
| 16 | #include "SkGr.h" |
| 17 | #include "SkImageDecoder.h" |
| 18 | #include "SkOSFile.h" |
| 19 | #include "SkStream.h" |
| 20 | #include "Stats.h" |
| 21 | #include "gl/GrGLInterface.h" |
| 22 | |
| 23 | __SK_FORCE_IMAGE_DECODER_LINKING; |
| 24 | |
| 25 | // Between samples we reset context |
| 26 | // Between frames we swap buffers |
joshualitt | 189aef7 | 2015-09-08 07:08:11 -0700 | [diff] [blame] | 27 | DEFINE_bool2(verbose, v, false, "enable verbose output from the test driver."); |
joshualitt | 189aef7 | 2015-09-08 07:08:11 -0700 | [diff] [blame] | 28 | DEFINE_string(outResultsFile, "", "If given, write results here as JSON."); |
mtklein | ca6f43b | 2015-09-15 13:29:20 -0700 | [diff] [blame] | 29 | DEFINE_string(key, "", |
| 30 | "Space-separated key/value pairs to add to JSON identifying this builder."); |
joshualitt | 189aef7 | 2015-09-08 07:08:11 -0700 | [diff] [blame] | 31 | DEFINE_string(properties, "", |
| 32 | "Space-separated key/value pairs to add to JSON identifying this run."); |
joshualitt | 98d2e2f | 2015-10-05 07:23:30 -0700 | [diff] [blame] | 33 | DEFINE_int32(samples, 10, "Number of times to time each skp."); |
joshualitt | 189aef7 | 2015-09-08 07:08:11 -0700 | [diff] [blame] | 34 | |
| 35 | static SkString humanize(double ms) { |
| 36 | if (FLAGS_verbose) { |
| 37 | return SkStringPrintf("%llu", (uint64_t)(ms*1e6)); |
| 38 | } |
| 39 | return HumanizeMs(ms); |
| 40 | } |
| 41 | |
| 42 | #define HUMANIZE(time) humanize(time).c_str() |
| 43 | |
| 44 | VisualLightweightBenchModule::VisualLightweightBenchModule(VisualBench* owner) |
cdalton | 266e202 | 2015-11-13 08:28:49 -0800 | [diff] [blame] | 45 | : INHERITED(owner) |
joshualitt | d0f0bce | 2015-10-14 07:49:28 -0700 | [diff] [blame] | 46 | , fCurrentSample(0) |
joshualitt | 189aef7 | 2015-09-08 07:08:11 -0700 | [diff] [blame] | 47 | , fResults(new ResultsWriter) { |
joshualitt | 189aef7 | 2015-09-08 07:08:11 -0700 | [diff] [blame] | 48 | // Print header |
cdalton | baf8fcb | 2015-11-24 09:20:24 -0800 | [diff] [blame] | 49 | SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\t%-*s\tconfig\tbench\n", |
| 50 | FLAGS_samples, "samples"); |
joshualitt | 189aef7 | 2015-09-08 07:08:11 -0700 | [diff] [blame] | 51 | |
| 52 | // setup json logging if required |
| 53 | if (!FLAGS_outResultsFile.isEmpty()) { |
| 54 | fResults.reset(new NanoJSONResultsWriter(FLAGS_outResultsFile[0])); |
| 55 | } |
| 56 | |
mtklein | ca6f43b | 2015-09-15 13:29:20 -0700 | [diff] [blame] | 57 | if (1 == FLAGS_key.count() % 2) { |
| 58 | SkDebugf("ERROR: --key must be passed with an even number of arguments.\n"); |
| 59 | } else { |
| 60 | for (int i = 1; i < FLAGS_key.count(); i += 2) { |
| 61 | fResults->key(FLAGS_key[i - 1], FLAGS_key[i]); |
| 62 | } |
| 63 | } |
| 64 | |
joshualitt | 189aef7 | 2015-09-08 07:08:11 -0700 | [diff] [blame] | 65 | if (1 == FLAGS_properties.count() % 2) { |
| 66 | SkDebugf("ERROR: --properties must be passed with an even number of arguments.\n"); |
| 67 | } else { |
| 68 | for (int i = 1; i < FLAGS_properties.count(); i += 2) { |
| 69 | fResults->property(FLAGS_properties[i - 1], FLAGS_properties[i]); |
| 70 | } |
| 71 | } |
joshualitt | d0f0bce | 2015-10-14 07:49:28 -0700 | [diff] [blame] | 72 | |
| 73 | // seed an initial record |
| 74 | fRecords.push_back(); |
joshualitt | 189aef7 | 2015-09-08 07:08:11 -0700 | [diff] [blame] | 75 | } |
| 76 | |
joshualitt | d0f0bce | 2015-10-14 07:49:28 -0700 | [diff] [blame] | 77 | void VisualLightweightBenchModule::renderFrame(SkCanvas* canvas, Benchmark* benchmark, int loops) { |
| 78 | benchmark->draw(loops, canvas); |
joshualitt | 189aef7 | 2015-09-08 07:08:11 -0700 | [diff] [blame] | 79 | canvas->flush(); |
joshualitt | 189aef7 | 2015-09-08 07:08:11 -0700 | [diff] [blame] | 80 | } |
| 81 | |
joshualitt | d0f0bce | 2015-10-14 07:49:28 -0700 | [diff] [blame] | 82 | void VisualLightweightBenchModule::printStats(Benchmark* benchmark, int loops) { |
joshualitt | 189aef7 | 2015-09-08 07:08:11 -0700 | [diff] [blame] | 83 | const SkTArray<double>& measurements = fRecords.back().fMeasurements; |
joshualitt | d0f0bce | 2015-10-14 07:49:28 -0700 | [diff] [blame] | 84 | const char* shortName = benchmark->getUniqueName(); |
joshualitt | 189aef7 | 2015-09-08 07:08:11 -0700 | [diff] [blame] | 85 | |
| 86 | // update log |
| 87 | // Note: We currently log only the minimum. It would be interesting to log more information |
| 88 | SkString configName; |
cdalton | baf8fcb | 2015-11-24 09:20:24 -0800 | [diff] [blame] | 89 | if (FLAGS_cpu) { |
| 90 | configName.append("cpu"); |
| 91 | } else if (FLAGS_nvpr) { |
| 92 | if (FLAGS_offscreen) { |
| 93 | configName.appendf("nvpr_%d", FLAGS_msaa); |
| 94 | } else { |
| 95 | configName.appendf("nvpr_msaa_%d", FLAGS_msaa); |
| 96 | } |
| 97 | } else if (FLAGS_msaa > 0) { |
| 98 | if (FLAGS_offscreen) { |
| 99 | configName.appendf("offscreen_msaa_%d", FLAGS_msaa); |
| 100 | } else { |
| 101 | configName.appendf("msaa_%d", FLAGS_msaa); |
| 102 | } |
joshualitt | 189aef7 | 2015-09-08 07:08:11 -0700 | [diff] [blame] | 103 | } else { |
cdalton | baf8fcb | 2015-11-24 09:20:24 -0800 | [diff] [blame] | 104 | if (FLAGS_offscreen) { |
| 105 | configName.append("offscreen"); |
| 106 | } else { |
| 107 | configName.append("gpu"); |
| 108 | } |
joshualitt | 189aef7 | 2015-09-08 07:08:11 -0700 | [diff] [blame] | 109 | } |
joshualitt | d0f0bce | 2015-10-14 07:49:28 -0700 | [diff] [blame] | 110 | // Log bench name |
| 111 | fResults->bench(shortName, benchmark->getSize().fX, benchmark->getSize().fY); |
| 112 | |
joshualitt | 189aef7 | 2015-09-08 07:08:11 -0700 | [diff] [blame] | 113 | fResults->config(configName.c_str()); |
joshualitt | 7d4b458 | 2015-09-24 08:08:23 -0700 | [diff] [blame] | 114 | fResults->configOption("name", shortName); |
joshualitt | 189aef7 | 2015-09-08 07:08:11 -0700 | [diff] [blame] | 115 | SkASSERT(measurements.count()); |
| 116 | Stats stats(measurements); |
joshualitt | 7d4b458 | 2015-09-24 08:08:23 -0700 | [diff] [blame] | 117 | fResults->metric("min_ms", stats.min); |
joshualitt | 189aef7 | 2015-09-08 07:08:11 -0700 | [diff] [blame] | 118 | |
| 119 | // Print output |
| 120 | if (FLAGS_verbose) { |
| 121 | for (int i = 0; i < measurements.count(); i++) { |
| 122 | SkDebugf("%s ", HUMANIZE(measurements[i])); |
| 123 | } |
| 124 | SkDebugf("%s\n", shortName); |
| 125 | } else { |
| 126 | const double stdDevPercent = 100 * sqrt(stats.var) / stats.mean; |
cdalton | baf8fcb | 2015-11-24 09:20:24 -0800 | [diff] [blame] | 127 | SkDebugf("%4d/%-4dMB\t%d\t%s\t%s\t%s\t%s\t%.0f%%\t%s\t%s\t%s\n", |
joshualitt | 189aef7 | 2015-09-08 07:08:11 -0700 | [diff] [blame] | 128 | sk_tools::getCurrResidentSetSizeMB(), |
| 129 | sk_tools::getMaxResidentSetSizeMB(), |
joshualitt | d0f0bce | 2015-10-14 07:49:28 -0700 | [diff] [blame] | 130 | loops, |
joshualitt | 189aef7 | 2015-09-08 07:08:11 -0700 | [diff] [blame] | 131 | HUMANIZE(stats.min), |
| 132 | HUMANIZE(stats.median), |
| 133 | HUMANIZE(stats.mean), |
| 134 | HUMANIZE(stats.max), |
| 135 | stdDevPercent, |
joshualitt | 7d4b458 | 2015-09-24 08:08:23 -0700 | [diff] [blame] | 136 | stats.plot.c_str(), |
cdalton | baf8fcb | 2015-11-24 09:20:24 -0800 | [diff] [blame] | 137 | configName.c_str(), |
joshualitt | 189aef7 | 2015-09-08 07:08:11 -0700 | [diff] [blame] | 138 | shortName); |
| 139 | } |
| 140 | } |
| 141 | |
joshualitt | d0f0bce | 2015-10-14 07:49:28 -0700 | [diff] [blame] | 142 | bool VisualLightweightBenchModule::timingFinished(Benchmark* benchmark, int loops, |
| 143 | double measurement) { |
| 144 | fRecords.back().fMeasurements.push_back(measurement); |
| 145 | if (++fCurrentSample > FLAGS_samples) { |
| 146 | this->printStats(benchmark, loops); |
| 147 | fRecords.push_back(); |
| 148 | fCurrentSample = 0; |
joshualitt | 189aef7 | 2015-09-08 07:08:11 -0700 | [diff] [blame] | 149 | return true; |
| 150 | } |
joshualitt | d0f0bce | 2015-10-14 07:49:28 -0700 | [diff] [blame] | 151 | return false; |
joshualitt | 189aef7 | 2015-09-08 07:08:11 -0700 | [diff] [blame] | 152 | } |
jvanverth | f5d1b2d | 2015-09-15 07:40:56 -0700 | [diff] [blame] | 153 | |
| 154 | bool VisualLightweightBenchModule::onHandleChar(SkUnichar c) { |
| 155 | return true; |
| 156 | } |