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

Commit b64a3b46 authored by Vishnu Nair's avatar Vishnu Nair
Browse files

SF: Pass timestamps into layer tracing

This will allow us to recreate layer traces that
reflect the same timeline as the transaction
trace.

Test: presubmit
Bug: 200284593

Change-Id: I693c514ae56ed2137ad53b007a6722ba9396ecde
parent 0fc7af50
Loading
Loading
Loading
Loading
+14 −7
Original line number Diff line number Diff line
@@ -2179,6 +2179,11 @@ bool SurfaceFlinger::commit(nsecs_t frameTime, int64_t vsyncId, nsecs_t expected
    updateCursorAsync();
    updateInputFlinger();

    if (mLayerTracingEnabled && !mLayerTracing.flagIsSet(LayerTracing::TRACE_COMPOSITION)) {
        // This will block and tracing should only be enabled for debugging.
        mLayerTracing.notify(mVisibleRegionsDirty, frameTime);
    }

    MAIN_THREAD_GUARD(persistDisplayBrightness(mustComposite));

    return mustComposite && CC_LIKELY(mBootStage != BootStage::BOOTLOADER);
@@ -2280,13 +2285,9 @@ void SurfaceFlinger::composite(nsecs_t frameTime) {
    modulateVsync(&VsyncModulator::onDisplayRefresh, usedGpuComposition);

    mLayersWithQueuedFrames.clear();
    if (mLayerTracingEnabled) {
    if (mLayerTracingEnabled && mLayerTracing.flagIsSet(LayerTracing::TRACE_COMPOSITION)) {
        // This will block and should only be used for debugging.
        if (mVisibleRegionsDirty) {
            mLayerTracing.notify("visibleRegionsDirty");
        } else if (mLayerTracing.flagIsSet(LayerTracing::TRACE_BUFFERS)) {
            mLayerTracing.notify("bufferLatched");
        }
        mLayerTracing.notify(mVisibleRegionsDirty, frameTime);
    }

    mVisibleRegionsWereDirtyThisFrame = mVisibleRegionsDirty; // Cache value for use in post-comp
@@ -5773,12 +5774,18 @@ status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* r
            }
            case 1025: { // Set layer tracing
                n = data.readInt32();
                int64_t fixedStartingTime = data.readInt64();
                bool tracingEnabledChanged;
                if (n) {
                    ALOGD("LayerTracing enabled");
                    tracingEnabledChanged = mLayerTracing.enable();
                    if (tracingEnabledChanged) {
                        mScheduler->schedule([&]() MAIN_THREAD { mLayerTracing.notify("start"); })
                        int64_t startingTime =
                                (fixedStartingTime) ? fixedStartingTime : systemTime();
                        mScheduler
                                ->schedule([&]() MAIN_THREAD {
                                    mLayerTracing.notify("start", startingTime);
                                })
                                .wait();
                    }
                } else {
+7 −3
Original line number Diff line number Diff line
@@ -98,16 +98,20 @@ void LayerTracing::dump(std::string& result) const {
    mBuffer->dump(result);
}

void LayerTracing::notify(const char* where) {
    ATRACE_CALL();
void LayerTracing::notify(bool visibleRegionDirty, int64_t time) {
    std::scoped_lock lock(mTraceLock);
    if (!mEnabled) {
        return;
    }

    if (!visibleRegionDirty && !flagIsSet(LayerTracing::TRACE_BUFFERS)) {
        return;
    }

    ATRACE_CALL();
    LayersTraceProto entry;
    entry.set_elapsed_realtime_nanos(elapsedRealtimeNano());
    entry.set_elapsed_realtime_nanos(time);
    const char* where = visibleRegionDirty ? "visibleRegionsDirty" : "bufferLatched";
    entry.set_where(where);
    LayersProto layers(mFlinger.dumpDrawingStateProto(mFlags));

+1 −1
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ public:
    bool isEnabled() const;
    status_t writeToFile();
    LayersTraceFileProto createTraceFileProto() const;
    void notify(const char* where);
    void notify(bool visibleRegionDirty, int64_t time);

    enum : uint32_t {
        TRACE_INPUT = 1 << 1,