Flutter Engine
The Flutter Engine
GrResourceCacheBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2013 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.
6 */
7
8#include "bench/Benchmark.h"
9
17
18enum {
20};
21
23public:
24 BenchResource(GrGpu* gpu, std::string_view label)
25 : INHERITED(gpu, label) {
27 }
28
29 static void ComputeKey(int i, int keyData32Count, skgpu::UniqueKey* key) {
31 skgpu::UniqueKey::Builder builder(key, kDomain, keyData32Count);
32 for (int j = 0; j < keyData32Count; ++j) {
33 builder[j] = i + j;
34 }
35 }
36
37private:
38 size_t onGpuMemorySize() const override { return 100; }
39 void onSetLabel() override{}
40 const char* getResourceType() const override { return "bench"; }
41 using INHERITED = GrGpuResource;
42};
43
44static void populate_cache(GrGpu* gpu, int resourceCount, int keyData32Count) {
45 for (int i = 0; i < resourceCount; ++i) {
47 BenchResource::ComputeKey(i, keyData32Count, &key);
48 GrGpuResource* resource = new BenchResource(gpu, /*label=*/"BenchResource");
49 resource->resourcePriv().setUniqueKey(key);
50 resource->unref();
51 }
52}
53
55public:
56 GrResourceCacheBenchAdd(int keyData32Count)
57 : fFullName("grresourcecache_add")
58 , fKeyData32Count(keyData32Count) {
59 if (keyData32Count > 1) {
60 fFullName.appendf("_%d", fKeyData32Count);
61 }
62 }
63
64 bool isSuitableFor(Backend backend) override {
66 }
67protected:
68 const char* onGetName() override {
69 return fFullName.c_str();
70 }
71
72 void onDraw(int loops, SkCanvas* canvas) override {
74 if (nullptr == context) {
75 return;
76 }
77 // Set the cache budget to be very large so no purging occurs.
79
81
82 // Make sure the cache is empty.
83 cache->purgeUnlockedResources(GrPurgeResourceOptions::kAllResources);
84 SkASSERT(0 == cache->getResourceCount() && 0 == cache->getResourceBytes());
85
86 GrGpu* gpu = context->priv().getGpu();
87
88 for (int i = 0; i < loops; ++i) {
89 populate_cache(gpu, CACHE_SIZE_COUNT, fKeyData32Count);
90 SkASSERT(CACHE_SIZE_COUNT == cache->getResourceCount());
91 }
92 }
93
94private:
95 SkString fFullName;
96 int fKeyData32Count;
97 using INHERITED = Benchmark;
98};
99
101public:
102 GrResourceCacheBenchFind(int keyData32Count)
103 : fFullName("grresourcecache_find")
104 , fKeyData32Count(keyData32Count) {
105 if (keyData32Count > 1) {
106 fFullName.appendf("_%d", fKeyData32Count);
107 }
108 }
109
112 }
113protected:
114 const char* onGetName() override {
115 return fFullName.c_str();
116 }
117
118 void onDelayedSetup() override {
119 fContext = GrDirectContext::MakeMock(nullptr);
120 if (!fContext) {
121 return;
122 }
123 // Set the cache budget to be very large so no purging occurs.
124 fContext->setResourceCacheLimits(CACHE_SIZE_COUNT, 1 << 30);
125
127
128 // Make sure the cache is empty.
129 cache->purgeUnlockedResources(GrPurgeResourceOptions::kAllResources);
130 SkASSERT(0 == cache->getResourceCount() && 0 == cache->getResourceBytes());
131
132 GrGpu* gpu = fContext->priv().getGpu();
133
134 populate_cache(gpu, CACHE_SIZE_COUNT, fKeyData32Count);
135 }
136
137 void onDraw(int loops, SkCanvas* canvas) override {
138 if (!fContext) {
139 return;
140 }
142 SkASSERT(CACHE_SIZE_COUNT == cache->getResourceCount());
143 for (int i = 0; i < loops; ++i) {
144 for (int k = 0; k < CACHE_SIZE_COUNT; ++k) {
146 BenchResource::ComputeKey(k, fKeyData32Count, &key);
147 sk_sp<GrGpuResource> resource(cache->findAndRefUniqueResource(key));
149 }
150 }
151 }
152
153private:
154 sk_sp<GrDirectContext> fContext;
155 SkString fFullName;
156 int fKeyData32Count;
157 using INHERITED = Benchmark;
158};
159
160DEF_BENCH( return new GrResourceCacheBenchAdd(1); )
161#ifdef SK_RELEASE
162// Only on release because on debug the SkTDynamicHash validation is too slow.
163DEF_BENCH( return new GrResourceCacheBenchAdd(2); )
164DEF_BENCH( return new GrResourceCacheBenchAdd(3); )
165DEF_BENCH( return new GrResourceCacheBenchAdd(4); )
166DEF_BENCH( return new GrResourceCacheBenchAdd(5); )
167DEF_BENCH( return new GrResourceCacheBenchAdd(10); )
168DEF_BENCH( return new GrResourceCacheBenchAdd(25); )
169DEF_BENCH( return new GrResourceCacheBenchAdd(54); )
170DEF_BENCH( return new GrResourceCacheBenchAdd(55); )
171DEF_BENCH( return new GrResourceCacheBenchAdd(56); )
172#endif
173
174DEF_BENCH( return new GrResourceCacheBenchFind(1); )
175#ifdef SK_RELEASE
176DEF_BENCH( return new GrResourceCacheBenchFind(2); )
177DEF_BENCH( return new GrResourceCacheBenchFind(3); )
178DEF_BENCH( return new GrResourceCacheBenchFind(4); )
179DEF_BENCH( return new GrResourceCacheBenchFind(5); )
180DEF_BENCH( return new GrResourceCacheBenchFind(10); )
181DEF_BENCH( return new GrResourceCacheBenchFind(25); )
182DEF_BENCH( return new GrResourceCacheBenchFind(54); )
183DEF_BENCH( return new GrResourceCacheBenchFind(55); )
184DEF_BENCH( return new GrResourceCacheBenchFind(56); )
185#endif
#define DEF_BENCH(code)
Definition: Benchmark.h:20
const char * backend
static void populate_cache(GrGpu *gpu, int resourceCount, int keyData32Count)
@ CACHE_SIZE_COUNT
#define SkASSERT(cond)
Definition: SkAssert.h:116
static SkString resource(SkPDFResourceType type, int index)
BenchResource(GrGpu *gpu, std::string_view label)
static void ComputeKey(int i, int keyData32Count, skgpu::UniqueKey *key)
GrResourceCache * getResourceCache()
void setResourceCacheLimits(int maxResources, size_t maxResourceBytes)
static sk_sp< GrDirectContext > MakeMock(const GrMockOptions *, const GrContextOptions &)
GrDirectContextPriv priv()
GrGpuResource(GrGpu *, std::string_view label)
void registerWithCache(skgpu::Budgeted)
Definition: GrGpu.h:62
bool isSuitableFor(Backend backend) override
const char * onGetName() override
void onDraw(int loops, SkCanvas *canvas) override
GrResourceCacheBenchAdd(int keyData32Count)
const char * onGetName() override
GrResourceCacheBenchFind(int keyData32Count)
bool isSuitableFor(Backend backend) override
void onDraw(int loops, SkCanvas *canvas) override
const char * c_str() const
Definition: SkString.h:133
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:550
static Domain GenerateDomain()
Definition: ResourceKey.cpp:27
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By this is not enabled to reduce the overhead purge persistent cache
Definition: switches.h:191