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

Commit d136af5b authored by Vishnu Nair's avatar Vishnu Nair Committed by Android (Google) Code Review
Browse files

Merge "[sf] write transaction trace to disk on error" into udc-qpr-dev

parents 23fcab4c d1f74983
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@
#include "LayerLog.h"
#include "LayerSnapshotBuilder.h"
#include "TimeStats/TimeStats.h"
#include "Tracing/TransactionTracing.h"

namespace android::surfaceflinger::frontend {

@@ -435,13 +436,13 @@ void LayerSnapshotBuilder::updateSnapshots(const Args& args) {
        // multiple children.
        LayerHierarchy::ScopedAddToTraversalPath addChildToPath(root, args.root.getLayer()->id,
                                                                LayerHierarchy::Variant::Attached);
        updateSnapshotsInHierarchy(args, args.root, root, mRootSnapshot);
        updateSnapshotsInHierarchy(args, args.root, root, mRootSnapshot, /*depth=*/0);
    } else {
        for (auto& [childHierarchy, variant] : args.root.mChildren) {
            LayerHierarchy::ScopedAddToTraversalPath addChildToPath(root,
                                                                    childHierarchy->getLayer()->id,
                                                                    variant);
            updateSnapshotsInHierarchy(args, *childHierarchy, root, mRootSnapshot);
            updateSnapshotsInHierarchy(args, *childHierarchy, root, mRootSnapshot, /*depth=*/0);
        }
    }

@@ -494,7 +495,15 @@ void LayerSnapshotBuilder::update(const Args& args) {

const LayerSnapshot& LayerSnapshotBuilder::updateSnapshotsInHierarchy(
        const Args& args, const LayerHierarchy& hierarchy,
        LayerHierarchy::TraversalPath& traversalPath, const LayerSnapshot& parentSnapshot) {
        LayerHierarchy::TraversalPath& traversalPath, const LayerSnapshot& parentSnapshot,
        int depth) {
    if (depth > 50) {
        TransactionTraceWriter::getInstance().invoke("layer_builder_stack_overflow_",
                                                     /*overwrite=*/false);
        LOG_ALWAYS_FATAL("Cycle detected in LayerSnapshotBuilder. See "
                         "builder_stack_overflow_transactions.winscope");
    }

    const RequestedLayerState* layer = hierarchy.getLayer();
    LayerSnapshot* snapshot = getSnapshot(traversalPath);
    const bool newSnapshot = snapshot == nullptr;
@@ -517,7 +526,8 @@ const LayerSnapshot& LayerSnapshotBuilder::updateSnapshotsInHierarchy(
                                                                childHierarchy->getLayer()->id,
                                                                variant);
        const LayerSnapshot& childSnapshot =
                updateSnapshotsInHierarchy(args, *childHierarchy, traversalPath, *snapshot);
                updateSnapshotsInHierarchy(args, *childHierarchy, traversalPath, *snapshot,
                                           depth + 1);
        updateChildState(*snapshot, childSnapshot, args);
    }

+1 −1
Original line number Diff line number Diff line
@@ -96,7 +96,7 @@ private:

    const LayerSnapshot& updateSnapshotsInHierarchy(const Args&, const LayerHierarchy& hierarchy,
                                                    LayerHierarchy::TraversalPath& traversalPath,
                                                    const LayerSnapshot& parentSnapshot);
                                                    const LayerSnapshot& parentSnapshot, int depth);
    void updateSnapshot(LayerSnapshot&, const Args&, const RequestedLayerState&,
                        const LayerSnapshot& parentSnapshot, const LayerHierarchy::TraversalPath&);
    static void updateRelativeState(LayerSnapshot& snapshot, const LayerSnapshot& parentSnapshot,
+24 −4
Original line number Diff line number Diff line
@@ -131,6 +131,7 @@ void RequestedLayerState::merge(const ResolvedComposerState& resolvedComposerSta
    const uint32_t oldFlags = flags;
    const half oldAlpha = color.a;
    const bool hadBuffer = externalTexture != nullptr;
    uint64_t oldFramenumber = hadBuffer ? bufferData->frameNumber : 0;
    const bool hadSideStream = sidebandStream != nullptr;
    const layer_state_t& clientState = resolvedComposerState.state;
    const bool hadBlur = hasBlur();
@@ -147,12 +148,9 @@ void RequestedLayerState::merge(const ResolvedComposerState& resolvedComposerSta
            changes |= RequestedLayerState::Changes::Geometry;
        }
    }

    if (clientState.what & layer_state_t::eBufferChanged) {
        externalTexture = resolvedComposerState.externalTexture;
        barrierProducerId = std::max(bufferData->producerId, barrierProducerId);
        barrierFrameNumber = std::max(bufferData->frameNumber, barrierFrameNumber);
        // TODO(b/277265947) log and flush transaction trace when we detect out of order updates

        const bool hasBuffer = externalTexture != nullptr;
        if (hasBuffer || hasBuffer != hadBuffer) {
            changes |= RequestedLayerState::Changes::Buffer;
@@ -163,6 +161,28 @@ void RequestedLayerState::merge(const ResolvedComposerState& resolvedComposerSta
                    RequestedLayerState::Changes::VisibleRegion |
                    RequestedLayerState::Changes::Visibility | RequestedLayerState::Changes::Input;
        }

        if (hasBuffer) {
            const bool frameNumberChanged =
                    bufferData->flags.test(BufferData::BufferDataChange::frameNumberChanged);
            const uint64_t frameNumber =
                    frameNumberChanged ? bufferData->frameNumber : oldFramenumber + 1;
            bufferData->frameNumber = frameNumber;

            if ((barrierProducerId > bufferData->producerId) ||
                ((barrierProducerId == bufferData->producerId) &&
                 (barrierFrameNumber > bufferData->frameNumber))) {
                ALOGE("Out of order buffers detected for %s producedId=%d frameNumber=%" PRIu64
                      " -> producedId=%d frameNumber=%" PRIu64,
                      getDebugString().c_str(), bufferData->producerId, bufferData->frameNumber,
                      bufferData->producerId, frameNumber);
                TransactionTraceWriter::getInstance().invoke("out_of_order_buffers_",
                                                             /*overwrite=*/false);
            }

            barrierProducerId = std::max(bufferData->producerId, barrierProducerId);
            barrierFrameNumber = std::max(bufferData->frameNumber, barrierFrameNumber);
        }
    }

    if (clientState.what & layer_state_t::eSidebandStreamChanged) {
+10 −1
Original line number Diff line number Diff line
@@ -3125,6 +3125,16 @@ bool Layer::setBuffer(std::shared_ptr<renderengine::ExternalTexture>& buffer,
        return true;
    }

    if ((mDrawingState.producerId > bufferData.producerId) ||
        ((mDrawingState.producerId == bufferData.producerId) &&
         (mDrawingState.frameNumber > frameNumber))) {
        ALOGE("Out of order buffers detected for %s producedId=%d frameNumber=%" PRIu64
              " -> producedId=%d frameNumber=%" PRIu64,
              getDebugName(), mDrawingState.producerId, mDrawingState.frameNumber,
              bufferData.producerId, frameNumber);
        TransactionTraceWriter::getInstance().invoke("out_of_order_buffers_", /*overwrite=*/false);
    }

    mDrawingState.producerId = bufferData.producerId;
    mDrawingState.barrierProducerId =
            std::max(mDrawingState.producerId, mDrawingState.barrierProducerId);
@@ -3132,7 +3142,6 @@ bool Layer::setBuffer(std::shared_ptr<renderengine::ExternalTexture>& buffer,
    mDrawingState.barrierFrameNumber =
            std::max(mDrawingState.frameNumber, mDrawingState.barrierFrameNumber);

    // TODO(b/277265947) log and flush transaction trace when we detect out of order updates
    mDrawingState.releaseBufferListener = bufferData.releaseBufferListener;
    mDrawingState.buffer = std::move(buffer);
    mDrawingState.acquireFence = bufferData.flags.test(BufferData::BufferDataChange::fenceChanged)
+24 −1
Original line number Diff line number Diff line
@@ -909,6 +909,29 @@ void SurfaceFlinger::init() FTL_FAKE_GUARD(kMainThreadContext) {
        ALOGE("Run StartPropertySetThread failed!");
    }

    if (mTransactionTracing) {
        TransactionTraceWriter::getInstance().setWriterFunction([&](const std::string& prefix,
                                                                    bool overwrite) {
            auto writeFn = [&]() {
                const std::string filename =
                        TransactionTracing::DIR_NAME + prefix + TransactionTracing::FILE_NAME;
                if (overwrite) {
                    std::ifstream file(filename);
                    if (file.is_open()) {
                        return;
                    }
                }
                mTransactionTracing->flush();
                mTransactionTracing->writeToFile(filename);
            };
            if (std::this_thread::get_id() == mMainThreadId) {
                writeFn();
            } else {
                mScheduler->schedule(writeFn).get();
            }
        });
    }

    ALOGV("Done initializing");
}

@@ -6728,7 +6751,7 @@ status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* r
                        mTransactionTracing->setBufferSize(
                                TransactionTracing::ACTIVE_TRACING_BUFFER_SIZE);
                    } else {
                        mTransactionTracing->writeToFile();
                        TransactionTraceWriter::getInstance().invoke("", /* overwrite= */ true);
                        mTransactionTracing->setBufferSize(
                                TransactionTracing::CONTINUOUS_TRACING_BUFFER_SIZE);
                    }
Loading