Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 | 8 |
| 9 #include <VisualBench/VisualBenchmarkStream.h> | 9 #include <VisualBench/VisualBenchmarkStream.h> |
| 10 #include "CpuWrappedBenchmark.h" | 10 #include "CpuWrappedBenchmark.h" |
| 11 #include "GMBench.h" | 11 #include "GMBench.h" |
| 12 #include "SkOSFile.h" | 12 #include "SkOSFile.h" |
| 13 #include "SkPath.h" | |
| 13 #include "SkPictureRecorder.h" | 14 #include "SkPictureRecorder.h" |
| 14 #include "SkStream.h" | 15 #include "SkStream.h" |
| 15 #include "VisualSKPBench.h" | 16 #include "VisualSKPBench.h" |
| 16 | 17 |
| 17 DEFINE_bool(cpu, false, "Run in CPU mode?"); | 18 DEFINE_bool(cpu, false, "Run in CPU mode?"); |
| 18 DEFINE_string2(match, m, nullptr, | 19 DEFINE_string2(match, m, nullptr, |
| 19 "[~][^]substring[$] [...] of bench name to run.\n" | 20 "[~][^]substring[$] [...] of bench name to run.\n" |
| 20 "Multiple matches may be separated by spaces.\n" | 21 "Multiple matches may be separated by spaces.\n" |
| 21 "~ causes a matching bench to always be skipped\n" | 22 "~ causes a matching bench to always be skipped\n" |
| 22 "^ requires the start of the bench to match\n" | 23 "^ requires the start of the bench to match\n" |
| 23 "$ requires the end of the bench to match\n" | 24 "$ requires the end of the bench to match\n" |
| 24 "^ and $ requires an exact match\n" | 25 "^ and $ requires an exact match\n" |
| 25 "If a bench does not match any list entry,\n" | 26 "If a bench does not match any list entry,\n" |
| 26 "it is skipped unless some list entry starts with ~"); | 27 "it is skipped unless some list entry starts with ~"); |
| 27 DEFINE_string(skps, "skps", "Directory to read skps from."); | 28 DEFINE_string(skps, "skps", "Directory to read skps from."); |
| 28 | 29 |
| 30 // We draw a big nonAA path to warmup the gpu / cpu | |
| 31 class WarmupBench : public Benchmark { | |
| 32 public: | |
| 33 WarmupBench() { | |
| 34 make_path(fPath); | |
| 35 } | |
| 36 private: | |
|
robertphillips
2015/10/05 13:05:01
MakePath ?
| |
| 37 static void make_path(SkPath& path) { | |
|
robertphillips
2015/10/05 13:05:01
Maybe have a MakeBigPath helper in sk_tools_utils
| |
| 38 #include "BigPathBench.inc" | |
| 39 } | |
| 40 const char* onGetName() override { return "warmupbench"; } | |
| 41 void onDraw(int loops, SkCanvas* canvas) override { | |
| 42 SkPaint paint; | |
| 43 paint.setStyle(SkPaint::kStroke_Style); | |
| 44 paint.setStrokeWidth(2); | |
| 45 for (int i = 0; i < loops; i++) { | |
| 46 canvas->drawPath(fPath, paint); | |
| 47 } | |
| 48 } | |
| 49 SkPath fPath; | |
| 50 }; | |
| 51 | |
| 29 VisualBenchmarkStream::VisualBenchmarkStream() | 52 VisualBenchmarkStream::VisualBenchmarkStream() |
| 30 : fBenches(BenchRegistry::Head()) | 53 : fBenches(BenchRegistry::Head()) |
| 31 , fGMs(skiagm::GMRegistry::Head()) | 54 , fGMs(skiagm::GMRegistry::Head()) |
| 32 , fSourceType(nullptr) | 55 , fSourceType(nullptr) |
| 33 , fBenchType(nullptr) | 56 , fBenchType(nullptr) |
| 34 , fCurrentSKP(0) { | 57 , fCurrentSKP(0) |
| 58 , fIsWarmedUp(false) { | |
| 35 for (int i = 0; i < FLAGS_skps.count(); i++) { | 59 for (int i = 0; i < FLAGS_skps.count(); i++) { |
| 36 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { | 60 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { |
| 37 fSKPs.push_back() = FLAGS_skps[i]; | 61 fSKPs.push_back() = FLAGS_skps[i]; |
| 38 } else { | 62 } else { |
| 39 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); | 63 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); |
| 40 SkString path; | 64 SkString path; |
| 41 while (it.next(&path)) { | 65 while (it.next(&path)) { |
| 42 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str()); | 66 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str()); |
| 43 } | 67 } |
| 44 } | 68 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 60 | 84 |
| 61 pic->reset(SkPicture::CreateFromStream(stream.get())); | 85 pic->reset(SkPicture::CreateFromStream(stream.get())); |
| 62 if (pic->get() == nullptr) { | 86 if (pic->get() == nullptr) { |
| 63 SkDebugf("Could not read %s as an SkPicture.\n", path); | 87 SkDebugf("Could not read %s as an SkPicture.\n", path); |
| 64 return false; | 88 return false; |
| 65 } | 89 } |
| 66 return true; | 90 return true; |
| 67 } | 91 } |
| 68 | 92 |
| 69 Benchmark* VisualBenchmarkStream::next() { | 93 Benchmark* VisualBenchmarkStream::next() { |
| 94 if (!fIsWarmedUp) { | |
| 95 fIsWarmedUp = true; | |
| 96 return new WarmupBench; | |
| 97 } | |
| 98 | |
| 70 Benchmark* bench; | 99 Benchmark* bench; |
| 100 | |
| 71 // skips non matching benches | 101 // skips non matching benches |
| 72 while ((bench = this->innerNext()) && | 102 while ((bench = this->innerNext()) && |
| 73 (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName()) || | 103 (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName()) || |
| 74 !bench->isSuitableFor(Benchmark::kGPU_Backend))) { | 104 !bench->isSuitableFor(Benchmark::kGPU_Backend))) { |
| 75 bench->unref(); | 105 bench->unref(); |
| 76 } | 106 } |
| 77 if (FLAGS_cpu) { | 107 if (FLAGS_cpu) { |
| 78 return new CpuWrappedBenchmark(bench); | 108 return new CpuWrappedBenchmark(bench); |
| 79 } | 109 } |
| 80 return bench; | 110 return bench; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 111 } | 141 } |
| 112 | 142 |
| 113 SkString name = SkOSPath::Basename(path.c_str()); | 143 SkString name = SkOSPath::Basename(path.c_str()); |
| 114 fSourceType = "skp"; | 144 fSourceType = "skp"; |
| 115 fBenchType = "playback"; | 145 fBenchType = "playback"; |
| 116 return new VisualSKPBench(name.c_str(), pic.get()); | 146 return new VisualSKPBench(name.c_str(), pic.get()); |
| 117 } | 147 } |
| 118 | 148 |
| 119 return nullptr; | 149 return nullptr; |
| 120 } | 150 } |
| OLD | NEW |