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

Commit cff69353 authored by Vishnu Nair's avatar Vishnu Nair Committed by Automerger Merge Worker
Browse files

Merge "[sf] add more debug logs to identify layer leaks" into udc-dev am: 92a3d2c3

parents b97e4845 92a3d2c3
Loading
Loading
Loading
Loading
+9 −2
Original line number Original line Diff line number Diff line
@@ -335,6 +335,7 @@ sp<IBinder> Layer::getHandle() {
        return nullptr;
        return nullptr;
    }
    }
    mGetHandleCalled = true;
    mGetHandleCalled = true;
    mHandleAlive = true;
    return sp<LayerHandle>::make(mFlinger, sp<Layer>::fromExisting(this));
    return sp<LayerHandle>::make(mFlinger, sp<Layer>::fromExisting(this));
}
}


@@ -1649,9 +1650,9 @@ void Layer::onDisconnect() {
    mFlinger->mFrameTracer->onDestroy(layerId);
    mFlinger->mFrameTracer->onDestroy(layerId);
}
}


size_t Layer::getChildrenCount() const {
size_t Layer::getDescendantCount() const {
    size_t count = 0;
    size_t count = 0;
    for (const sp<Layer>& child : mCurrentChildren) {
    for (const sp<Layer>& child : mDrawingChildren) {
        count += 1 + child->getChildrenCount();
        count += 1 + child->getChildrenCount();
    }
    }
    return count;
    return count;
@@ -1898,6 +1899,12 @@ void Layer::traverse(LayerVector::StateSet state, const LayerVector::Visitor& vi
    }
    }
}
}


void Layer::traverseChildren(const LayerVector::Visitor& visitor) {
    for (const sp<Layer>& child : mDrawingChildren) {
        visitor(child.get());
    }
}

LayerVector Layer::makeChildrenTraversalList(LayerVector::StateSet stateSet,
LayerVector Layer::makeChildrenTraversalList(LayerVector::StateSet stateSet,
                                             const std::vector<Layer*>& layersInTree) {
                                             const std::vector<Layer*>& layersInTree) {
    LOG_ALWAYS_FATAL_IF(stateSet == LayerVector::StateSet::Invalid,
    LOG_ALWAYS_FATAL_IF(stateSet == LayerVector::StateSet::Invalid,
+6 −1
Original line number Original line Diff line number Diff line
@@ -700,6 +700,7 @@ public:
    void traverse(LayerVector::StateSet, const LayerVector::Visitor&);
    void traverse(LayerVector::StateSet, const LayerVector::Visitor&);
    void traverseInReverseZOrder(LayerVector::StateSet, const LayerVector::Visitor&);
    void traverseInReverseZOrder(LayerVector::StateSet, const LayerVector::Visitor&);
    void traverseInZOrder(LayerVector::StateSet, const LayerVector::Visitor&);
    void traverseInZOrder(LayerVector::StateSet, const LayerVector::Visitor&);
    void traverseChildren(const LayerVector::Visitor&);


    /**
    /**
     * Traverse only children in z order, ignoring relative layers that are not children of the
     * Traverse only children in z order, ignoring relative layers that are not children of the
@@ -707,7 +708,10 @@ public:
     */
     */
    void traverseChildrenInZOrder(LayerVector::StateSet, const LayerVector::Visitor&);
    void traverseChildrenInZOrder(LayerVector::StateSet, const LayerVector::Visitor&);


    size_t getChildrenCount() const;
    size_t getDescendantCount() const;
    size_t getChildrenCount() const { return mDrawingChildren.size(); }
    bool isHandleAlive() const { return mHandleAlive; }
    bool onHandleDestroyed() { return mHandleAlive = false; }


    // ONLY CALL THIS FROM THE LAYER DTOR!
    // ONLY CALL THIS FROM THE LAYER DTOR!
    // See b/141111965.  We need to add current children to offscreen layers in
    // See b/141111965.  We need to add current children to offscreen layers in
@@ -1192,6 +1196,7 @@ private:
    std::vector<std::pair<frontend::LayerHierarchy::TraversalPath, sp<LayerFE>>> mLayerFEs;
    std::vector<std::pair<frontend::LayerHierarchy::TraversalPath, sp<LayerFE>>> mLayerFEs;
    std::unique_ptr<frontend::LayerSnapshot> mSnapshot =
    std::unique_ptr<frontend::LayerSnapshot> mSnapshot =
            std::make_unique<frontend::LayerSnapshot>();
            std::make_unique<frontend::LayerSnapshot>();
    bool mHandleAlive = false;
};
};


std::ostream& operator<<(std::ostream& stream, const Layer::FrameRate& rate);
std::ostream& operator<<(std::ostream& stream, const Layer::FrameRate& rate);
+30 −1
Original line number Original line Diff line number Diff line
@@ -4096,6 +4096,32 @@ status_t SurfaceFlinger::addClientLayer(LayerCreationArgs& args, const sp<IBinde
        ALOGE("AddClientLayer failed, mNumLayers (%zu) >= MAX_LAYERS (%zu)", mNumLayers.load(),
        ALOGE("AddClientLayer failed, mNumLayers (%zu) >= MAX_LAYERS (%zu)", mNumLayers.load(),
              MAX_LAYERS);
              MAX_LAYERS);
        static_cast<void>(mScheduler->schedule([=] {
        static_cast<void>(mScheduler->schedule([=] {
            ALOGE("Dumping layer keeping > 20 children alive:");
            bool leakingParentLayerFound = false;
            mDrawingState.traverse([&](Layer* layer) {
                if (leakingParentLayerFound) {
                    return;
                }
                if (layer->getChildrenCount() > 20) {
                    leakingParentLayerFound = true;
                    sp<Layer> parent = sp<Layer>::fromExisting(layer);
                    while (parent) {
                        ALOGE("Parent Layer: %s handleIsAlive: %s", parent->getName().c_str(),
                              std::to_string(parent->isHandleAlive()).c_str());
                        parent = parent->getParent();
                    }
                    // Sample up to 100 layers
                    ALOGE("Dumping random sampling of child layers total(%zu): ",
                          layer->getChildrenCount());
                    int sampleSize = (layer->getChildrenCount() / 100) + 1;
                    layer->traverseChildren([&](Layer* layer) {
                        if (rand() % sampleSize == 0) {
                            ALOGE("Child Layer: %s", layer->getName().c_str());
                        }
                    });
                }
            });

            ALOGE("Dumping random sampling of on-screen layers: ");
            ALOGE("Dumping random sampling of on-screen layers: ");
            mDrawingState.traverse([&](Layer* layer) {
            mDrawingState.traverse([&](Layer* layer) {
                // Aim to dump about 200 layers to avoid totally trashing
                // Aim to dump about 200 layers to avoid totally trashing
@@ -4106,6 +4132,8 @@ status_t SurfaceFlinger::addClientLayer(LayerCreationArgs& args, const sp<IBinde
                    ALOGE("Layer: %s", layer->getName().c_str());
                    ALOGE("Layer: %s", layer->getName().c_str());
                }
                }
            });
            });
            ALOGE("Dumping random sampling of off-screen layers total(%zu): ",
                  mOffscreenLayers.size());
            for (Layer* offscreenLayer : mOffscreenLayers) {
            for (Layer* offscreenLayer : mOffscreenLayers) {
                if (rand() % 20 == 13) {
                if (rand() % 20 == 13) {
                    ALOGE("Offscreen-layer: %s", offscreenLayer->getName().c_str());
                    ALOGE("Offscreen-layer: %s", offscreenLayer->getName().c_str());
@@ -5302,6 +5330,7 @@ void SurfaceFlinger::onHandleDestroyed(BBinder* handle, sp<Layer>& layer, uint32


    Mutex::Autolock lock(mStateLock);
    Mutex::Autolock lock(mStateLock);
    markLayerPendingRemovalLocked(layer);
    markLayerPendingRemovalLocked(layer);
    layer->onHandleDestroyed();
    mBufferCountTracker.remove(handle);
    mBufferCountTracker.remove(handle);
    layer.clear();
    layer.clear();