SurfaceFlinger: Add ClientCache dumps
Can be useful in debugging buffer leaks.
Bug: 176691195
Test: Existing tests pass
Change-Id: I8b318f272a7da3dde76d9153b21ced94127f0d8b
diff --git a/services/surfaceflinger/ClientCache.cpp b/services/surfaceflinger/ClientCache.cpp
index a5be01c..2ae49fa 100644
--- a/services/surfaceflinger/ClientCache.cpp
+++ b/services/surfaceflinger/ClientCache.cpp
@@ -25,6 +25,8 @@
namespace android {
+using base::StringAppendF;
+
ANDROID_SINGLETON_STATIC_INSTANCE(ClientCache);
ClientCache::ClientCache() : mDeathRecipient(new CacheDeathRecipient) {}
@@ -203,4 +205,18 @@
ClientCache::getInstance().removeProcess(who);
}
+void ClientCache::dump(std::string& result) {
+ std::lock_guard lock(mMutex);
+ for (auto i : mBuffers) {
+ const sp<IBinder>& cacheOwner = i.second.first;
+ StringAppendF(&result," Cache owner: %p\n", cacheOwner.get());
+ auto &buffers = i.second.second;
+ for (auto& [id, clientCacheBuffer] : buffers) {
+ StringAppendF(&result, "\t ID: %d, Width/Height: %d,%d\n", (int)id,
+ (int)clientCacheBuffer.buffer->getWidth(),
+ (int)clientCacheBuffer.buffer->getHeight());
+ }
+ }
+}
+
}; // namespace android
diff --git a/services/surfaceflinger/ClientCache.h b/services/surfaceflinger/ClientCache.h
index d7af7c0..0d597c8 100644
--- a/services/surfaceflinger/ClientCache.h
+++ b/services/surfaceflinger/ClientCache.h
@@ -53,6 +53,8 @@
void unregisterErasedRecipient(const client_cache_t& cacheId,
const wp<ErasedRecipient>& recipient);
+ void dump(std::string& result);
+
private:
std::mutex mMutex;
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 77f4009..4f93b89 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -4849,6 +4849,8 @@
getRenderEngine().dump(result);
+ result.append("ClientCache state:\n");
+ ClientCache::getInstance().dump(result);
DebugEGLImageTracker::getInstance()->dump(result);
if (const auto display = getDefaultDisplayDeviceLocked()) {