Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 26b98f42 authored by Robert Carr's avatar Robert Carr
Browse files

SurfaceFlinger: Dump on layer leaks

Every so often some process will leak layer references and
SurfaceFlinger will eventually crash (or refusing to create
new layers because of the max layer count). We never have
enough info to trace these down, and it becomes a horrible
game of chasing repro steps. While we currently have no
complaints about anything like this in T, a recent
12L bug serves as a timely reminder that we should get
this logging in BEFORE the next issue occurs, rather
than after.

Bug: 227286456
Test: Existing tests pass
Change-Id: I2c8b834c93a27204225b482fea1e54837204c9cf
parent d7814346
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -3603,6 +3603,23 @@ status_t SurfaceFlinger::addClientLayer(const sp<Client>& client, const sp<IBind
    if (mNumLayers >= ISurfaceComposer::MAX_LAYERS) {
        ALOGE("AddClientLayer failed, mNumLayers (%zu) >= MAX_LAYERS (%zu)", mNumLayers.load(),
              ISurfaceComposer::MAX_LAYERS);
        static_cast<void>(mScheduler->schedule([=] {
            ALOGE("Dumping random sampling of on-screen layers: ");
            mDrawingState.traverse([&](Layer *layer) {
                // Aim to dump about 200 layers to avoid totally trashing
                // logcat. On the other hand, if there really are 4096 layers
                // something has gone totally wrong its probably the most
                // useful information in logcat.
                if (rand() % 20 == 13) {
                    ALOGE("Layer: %s", layer->getName().c_str());
                }
            });
            for (Layer* offscreenLayer : mOffscreenLayers) {
                if (rand() % 20 == 13) {
                    ALOGE("Offscreen-layer: %s", offscreenLayer->getName().c_str());
                }
            }
        }));
        return NO_MEMORY;
    }