More benchmark tweaks
Bug: 187718492
Test: this
Change-Id: Ie0cad91e1c7d1a02704fc4b1007ba2c28cb2b3e7
diff --git a/libs/hwui/renderthread/CacheManager.cpp b/libs/hwui/renderthread/CacheManager.cpp
index 5047be9..46e8060 100644
--- a/libs/hwui/renderthread/CacheManager.cpp
+++ b/libs/hwui/renderthread/CacheManager.cpp
@@ -130,27 +130,43 @@
mGrContext->purgeResourcesNotUsedInMs(std::chrono::seconds(30));
}
+void CacheManager::getMemoryUsage(size_t* cpuUsage, size_t* gpuUsage) {
+ *cpuUsage = 0;
+ *gpuUsage = 0;
+ if (!mGrContext) {
+ return;
+ }
+
+ skiapipeline::SkiaMemoryTracer cpuTracer("category", true);
+ SkGraphics::DumpMemoryStatistics(&cpuTracer);
+ *cpuUsage += cpuTracer.total();
+
+ skiapipeline::SkiaMemoryTracer gpuTracer("category", true);
+ mGrContext->dumpMemoryStatistics(&gpuTracer);
+ *gpuUsage += gpuTracer.total();
+}
+
void CacheManager::dumpMemoryUsage(String8& log, const RenderState* renderState) {
if (!mGrContext) {
log.appendFormat("No valid cache instance.\n");
return;
}
- log.appendFormat("Font Cache (CPU):\n");
- log.appendFormat(" Size: %.2f kB \n", SkGraphics::GetFontCacheUsed() / 1024.0f);
- log.appendFormat(" Glyph Count: %d \n", SkGraphics::GetFontCacheCountUsed());
-
std::vector<skiapipeline::ResourcePair> cpuResourceMap = {
{"skia/sk_resource_cache/bitmap_", "Bitmaps"},
{"skia/sk_resource_cache/rrect-blur_", "Masks"},
{"skia/sk_resource_cache/rects-blur_", "Masks"},
{"skia/sk_resource_cache/tessellated", "Shadows"},
+ {"skia/sk_glyph_cache", "Glyph Cache"},
};
skiapipeline::SkiaMemoryTracer cpuTracer(cpuResourceMap, false);
SkGraphics::DumpMemoryStatistics(&cpuTracer);
if (cpuTracer.hasOutput()) {
log.appendFormat("CPU Caches:\n");
cpuTracer.logOutput(log);
+ log.appendFormat(" Glyph Count: %d \n", SkGraphics::GetFontCacheCountUsed());
+ log.appendFormat("Total CPU memory usage:\n");
+ cpuTracer.logTotals(log);
}
skiapipeline::SkiaMemoryTracer gpuTracer("category", true);
diff --git a/libs/hwui/renderthread/CacheManager.h b/libs/hwui/renderthread/CacheManager.h
index 0a6b8dc..713ea99 100644
--- a/libs/hwui/renderthread/CacheManager.h
+++ b/libs/hwui/renderthread/CacheManager.h
@@ -47,6 +47,7 @@
void trimMemory(TrimMemoryMode mode);
void trimStaleResources();
void dumpMemoryUsage(String8& log, const RenderState* renderState = nullptr);
+ void getMemoryUsage(size_t* cpuUsage, size_t* gpuUsage);
size_t getCacheSize() const { return mMaxResourceBytes; }
size_t getBackgroundCacheSize() const { return mBackgroundResourceBytes; }
diff --git a/libs/hwui/renderthread/RenderProxy.cpp b/libs/hwui/renderthread/RenderProxy.cpp
index ad325cf..95aa29d 100644
--- a/libs/hwui/renderthread/RenderProxy.cpp
+++ b/libs/hwui/renderthread/RenderProxy.cpp
@@ -195,6 +195,17 @@
}
}
+void RenderProxy::purgeCaches() {
+ if (RenderThread::hasInstance()) {
+ RenderThread& thread = RenderThread::getInstance();
+ thread.queue().post([&thread]() {
+ if (thread.getGrContext()) {
+ thread.cacheManager().trimMemory(CacheManager::TrimMemoryMode::Complete);
+ }
+ });
+ }
+}
+
void RenderProxy::overrideProperty(const char* name, const char* value) {
// expensive, but block here since name/value pointers owned by caller
RenderThread::getInstance().queue().runSync(
@@ -256,6 +267,13 @@
}
}
+void RenderProxy::getMemoryUsage(size_t* cpuUsage, size_t* gpuUsage) {
+ if (RenderThread::hasInstance()) {
+ auto& thread = RenderThread::getInstance();
+ thread.queue().runSync([&]() { thread.getMemoryUsage(cpuUsage, gpuUsage); });
+ }
+}
+
void RenderProxy::setProcessStatsBuffer(int fd) {
auto& rt = RenderThread::getInstance();
rt.queue().post([&rt, fd = dup(fd)]() {
diff --git a/libs/hwui/renderthread/RenderProxy.h b/libs/hwui/renderthread/RenderProxy.h
index 662b445..0681dc5 100644
--- a/libs/hwui/renderthread/RenderProxy.h
+++ b/libs/hwui/renderthread/RenderProxy.h
@@ -98,6 +98,7 @@
void destroyHardwareResources();
static void trimMemory(int level);
+ static void purgeCaches();
static void overrideProperty(const char* name, const char* value);
void fence();
@@ -110,6 +111,7 @@
void resetProfileInfo();
uint32_t frameTimePercentile(int p);
static void dumpGraphicsMemory(int fd, bool includeProfileData = true);
+ static void getMemoryUsage(size_t* cpuUsage, size_t* gpuUsage);
static void rotateProcessStatsBuffer();
static void setProcessStatsBuffer(int fd);
diff --git a/libs/hwui/renderthread/RenderThread.cpp b/libs/hwui/renderthread/RenderThread.cpp
index 308352d..0268bfd7 100644
--- a/libs/hwui/renderthread/RenderThread.cpp
+++ b/libs/hwui/renderthread/RenderThread.cpp
@@ -323,6 +323,10 @@
dprintf(fd, "\nPipeline=%s\n%s\n", pipelineToString(), cachesOutput.string());
}
+void RenderThread::getMemoryUsage(size_t* cpuUsage, size_t* gpuUsage) {
+ mCacheManager->getMemoryUsage(cpuUsage, gpuUsage);
+}
+
Readback& RenderThread::readback() {
if (!mReadback) {
mReadback = new Readback(*this);
diff --git a/libs/hwui/renderthread/RenderThread.h b/libs/hwui/renderthread/RenderThread.h
index afd5750..5021085 100644
--- a/libs/hwui/renderthread/RenderThread.h
+++ b/libs/hwui/renderthread/RenderThread.h
@@ -151,6 +151,7 @@
sk_sp<Bitmap> allocateHardwareBitmap(SkBitmap& skBitmap);
void dumpGraphicsMemory(int fd, bool includeProfileData);
+ void getMemoryUsage(size_t* cpuUsage, size_t* gpuUsage);
void requireGlContext();
void requireVkContext();