From 91d4332030b8112fb5d700dbe8860ecd5339c0a2 Mon Sep 17 00:00:00 2001 From: Devan Buggay Date: Mon, 3 Nov 2025 18:55:38 -0800 Subject: [PATCH] Expose frame events on PerformanceTracer (#54361) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/54361 Expose a couple frame related events on the PerformanceTracer and call setLayerTreeId when tracing starts (needed for DevTools to parse frames) Changelog: [Internal] Reviewed By: rubennorte Differential Revision: D85145809 fbshipit-source-id: 421ee5441041da64f486f5492fa6705b965751f9 --- .../tracing/PerformanceTracer.cpp | 35 +++++++++++++++++++ .../tracing/PerformanceTracer.h | 13 +++++++ 2 files changed, 48 insertions(+) diff --git a/packages/react-native/ReactCommon/jsinspector-modern/tracing/PerformanceTracer.cpp b/packages/react-native/ReactCommon/jsinspector-modern/tracing/PerformanceTracer.cpp index d2f04fca875..d596decb121 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/tracing/PerformanceTracer.cpp +++ b/packages/react-native/ReactCommon/jsinspector-modern/tracing/PerformanceTracer.cpp @@ -360,6 +360,41 @@ void PerformanceTracer::reportResourceFinish( }); } +void PerformanceTracer::setLayerTreeId(std::string frame, int layerTreeId) { + enqueueEvent( + PerformanceTracerSetLayerTreeIdEvent{ + .frame = std::move(frame), + .layerTreeId = layerTreeId, + .start = HighResTimeStamp::now(), + .threadId = getCurrentThreadId(), + }); +} + +void PerformanceTracer::reportFrameTiming( + int frameSeqId, + HighResTimeStamp start, + HighResTimeStamp end) { + ThreadId threadId = getCurrentThreadId(); + enqueueEvent( + PerformanceTracerFrameBeginDrawEvent{ + .frameSeqId = frameSeqId, + .start = start, + .threadId = threadId, + }); + enqueueEvent( + PerformanceTracerFrameCommitEvent{ + .frameSeqId = frameSeqId, + .start = start, + .threadId = threadId, + }); + enqueueEvent( + PerformanceTracerFrameDrawEvent{ + .frameSeqId = frameSeqId, + .start = end, + .threadId = threadId, + }); +} + /* static */ TraceEvent PerformanceTracer::constructRuntimeProfileTraceEvent( RuntimeProfileId profileId, ProcessId processId, diff --git a/packages/react-native/ReactCommon/jsinspector-modern/tracing/PerformanceTracer.h b/packages/react-native/ReactCommon/jsinspector-modern/tracing/PerformanceTracer.h index d60eb265d78..f763cc8597b 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/tracing/PerformanceTracer.h +++ b/packages/react-native/ReactCommon/jsinspector-modern/tracing/PerformanceTracer.h @@ -161,6 +161,19 @@ class PerformanceTracer { int encodedDataLength, int decodedBodyLength); + /** + * Sets the active layer tree ID in Chrome DevTools. This is needed in + * order for frames to be parsed. + * + * https://chromedevtools.github.io/devtools-protocol/tot/LayerTree/ + */ + void setLayerTreeId(std::string frame, int layerTreeId); + + /** + * Reports the required frame CDP events for a given native frame. + */ + void reportFrameTiming(int frameSeqId, HighResTimeStamp start, HighResTimeStamp end); + /** * Creates "Profile" Trace Event. *