//frameworks/native/services/surfaceflinger/BufferQueueLayer.cpp
sp<SurfaceFlinger>mFlinger;conststd::unique_ptr<FrameTracer>mFrameTracer;voidBufferQueueLayer::onLayerDisplayed(ftl::SharedFuture<FenceResult>futureFenceResult){constsp<Fence>releaseFence=futureFenceResult.get().value_or(Fence::NO_FENCE);mConsumer->setReleaseFence(releaseFence);// Prevent tracing the same release multiple times.
if(mPreviousFrameNumber!=mPreviousReleasedFrameNumber){mFlinger->mFrameTracer->traceFence(getSequence(),mPreviousBufferId,mPreviousFrameNumber,std::make_shared<FenceTime>(releaseFence),FrameTracer::FrameEvent::RELEASE_FENCE);mPreviousReleasedFrameNumber=mPreviousFrameNumber;}}
//frameworks/native/services/surfaceflinger/FrameTracer/FrameTracer.cpp
voidFrameTracer::traceFence(int32_tlayerId,uint64_tbufferID,uint64_tframeNumber,conststd::shared_ptr<FenceTime>&fence,FrameEvent::BufferEventTypetype,nsecs_tstartTime){FrameTracerDataSource::Trace([this,layerId,bufferID,frameNumber,&fence,type,startTime](FrameTracerDataSource::TraceContextctx){constnsecs_tsignalTime=fence->getSignalTime();if(signalTime!=Fence::SIGNAL_TIME_INVALID){std::lock_guard<std::mutex>lock(mTraceMutex);if(mTraceTracker.find(layerId)==mTraceTracker.end()){return;}// Handle any pending fences for this buffer.
tracePendingFencesLocked(ctx,layerId,bufferID);if(signalTime!=Fence::SIGNAL_TIME_PENDING){traceSpanLocked(ctx,layerId,bufferID,frameNumber,type,startTime,signalTime);}else{mTraceTracker[layerId].pendingFences[bufferID].push_back({.frameNumber=frameNumber,.type=type,.fence=fence,.startTime=startTime});}}});}