Add traces of the size of HWUI shader cache in RAM

When HWUI needs to either load a shader from or store one to persistent
storage, this means a new shader is in its temporary (RAM) cache. Keep
track of the number and include it in perfetto traces.

As long as we're modifying ::store, make it override the version with
the newer signature, since the old one is deprecated.

Bug: 231194869
Bug: 225211273
Test: manual

Change-Id: I36b7e018291c50ed315f534f15946047ca001300
This commit is contained in:
Leon Scroggins III
2022-05-02 10:38:38 -04:00
parent 77644a2c31
commit 8cedb66717
3 changed files with 18 additions and 7 deletions

View File

@@ -136,6 +136,8 @@ sk_sp<SkData> ShaderCache::load(const SkData& key) {
free(valueBuffer);
return nullptr;
}
mNumShadersCachedInRam++;
ATRACE_FORMAT("HWUI RAM cache: %d shaders", mNumShadersCachedInRam);
return SkData::MakeFromMalloc(valueBuffer, valueSize);
}
@@ -182,9 +184,11 @@ void ShaderCache::saveToDiskLocked() {
mSavePending = false;
}
void ShaderCache::store(const SkData& key, const SkData& data) {
void ShaderCache::store(const SkData& key, const SkData& data, const SkString& /*description*/) {
ATRACE_NAME("ShaderCache::store");
std::lock_guard<std::mutex> lock(mMutex);
mNumShadersCachedInRam++;
ATRACE_FORMAT("HWUI RAM cache: %d shaders", mNumShadersCachedInRam);
if (!mInitialized) {
return;

View File

@@ -73,7 +73,7 @@ public:
* "store" attempts to insert a new key/value blob pair into the cache.
* This will be called by Skia after it compiled a new SKSL shader
*/
void store(const SkData& key, const SkData& data) override;
void store(const SkData& key, const SkData& data, const SkString& description) override;
/**
* "onVkFrameFlushed" tries to store Vulkan pipeline cache state.
@@ -210,6 +210,13 @@ private:
*/
static constexpr uint8_t sIDKey = 0;
/**
* Most of this class concerns persistent storage for shaders, but it's also
* interesting to keep track of how many shaders are stored in RAM. This
* class provides a convenient entry point for that.
*/
int mNumShadersCachedInRam = 0;
friend class ShaderCacheTestUtils; // used for unit testing
};

View File

@@ -140,9 +140,9 @@ TEST(ShaderCacheTest, testWriteAndRead) {
// write to the in-memory cache without storing on disk and verify we read the same values
sk_sp<SkData> inVS;
setShader(inVS, "sassas");
ShaderCache::get().store(GrProgramDescTest(100), *inVS.get());
ShaderCache::get().store(GrProgramDescTest(100), *inVS.get(), SkString());
setShader(inVS, "someVS");
ShaderCache::get().store(GrProgramDescTest(432), *inVS.get());
ShaderCache::get().store(GrProgramDescTest(432), *inVS.get(), SkString());
ASSERT_NE((outVS = ShaderCache::get().load(GrProgramDescTest(100))), sk_sp<SkData>());
ASSERT_TRUE(checkShader(outVS, "sassas"));
ASSERT_NE((outVS = ShaderCache::get().load(GrProgramDescTest(432))), sk_sp<SkData>());
@@ -166,7 +166,7 @@ TEST(ShaderCacheTest, testWriteAndRead) {
// change data, store to disk, read back again and verify data has been changed
setShader(inVS, "ewData1");
ShaderCache::get().store(GrProgramDescTest(432), *inVS.get());
ShaderCache::get().store(GrProgramDescTest(432), *inVS.get(), SkString());
ShaderCacheTestUtils::terminate(ShaderCache::get(), true);
ShaderCache::get().initShaderDiskCache();
ASSERT_NE((outVS2 = ShaderCache::get().load(GrProgramDescTest(432))), sk_sp<SkData>());
@@ -177,7 +177,7 @@ TEST(ShaderCacheTest, testWriteAndRead) {
std::vector<uint8_t> dataBuffer(dataSize);
genRandomData(dataBuffer);
setShader(inVS, dataBuffer);
ShaderCache::get().store(GrProgramDescTest(432), *inVS.get());
ShaderCache::get().store(GrProgramDescTest(432), *inVS.get(), SkString());
ShaderCacheTestUtils::terminate(ShaderCache::get(), true);
ShaderCache::get().initShaderDiskCache();
ASSERT_NE((outVS2 = ShaderCache::get().load(GrProgramDescTest(432))), sk_sp<SkData>());
@@ -225,7 +225,7 @@ TEST(ShaderCacheTest, testCacheValidation) {
setShader(data, dataBuffer);
blob = std::make_pair(key, data);
ShaderCache::get().store(*key.get(), *data.get());
ShaderCache::get().store(*key.get(), *data.get(), SkString());
}
ShaderCacheTestUtils::terminate(ShaderCache::get(), true);