From 00debea508caf36b1b58a364e6731480bce825bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Thu, 31 Jul 2025 14:29:24 -0700 Subject: [PATCH] Log synthetic events for trace start/end when the trace finishes (#52937) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/52937 Changelog: [internal] Minor refactor to log the synthetic events for trace start when the trace finishes. This is to simplify future work to implement a sliding window for trace events. Reviewed By: hoxyq Differential Revision: D79271692 fbshipit-source-id: 9e923ac36fff850a3aeede7304fb2d721bb9f16c --- .../tracing/PerformanceTracer.cpp | 13 ++++++++++++- .../jsinspector-modern/tracing/PerformanceTracer.h | 3 +++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/react-native/ReactCommon/jsinspector-modern/tracing/PerformanceTracer.cpp b/packages/react-native/ReactCommon/jsinspector-modern/tracing/PerformanceTracer.cpp index 6ff316aec34..424b9ad11b8 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/tracing/PerformanceTracer.cpp +++ b/packages/react-native/ReactCommon/jsinspector-modern/tracing/PerformanceTracer.cpp @@ -34,7 +34,7 @@ bool PerformanceTracer::startTracing() { } tracingAtomic_ = true; - + currentTraceStartTime_ = HighResTimeStamp::now(); return true; } @@ -60,6 +60,17 @@ std::optional> PerformanceTracer::stopTracing() { // samples will be displayed as empty. We use these events to avoid that. // This could happen for non-bridgeless apps, where Performance interface is // not supported and no spec-compliant Event Loop implementation. + + events.emplace_back(TraceEvent{ + .name = "TracingStartedInPage", + .cat = "disabled-by-default-devtools.timeline", + .ph = 'I', + .ts = currentTraceStartTime_, + .pid = processId_, + .tid = oscompat::getCurrentThreadId(), + .args = folly::dynamic::object("data", folly::dynamic::object()), + }); + events.emplace_back(TraceEvent{ .name = "ReactNative-TracingStopped", .cat = "disabled-by-default-devtools.timeline", diff --git a/packages/react-native/ReactCommon/jsinspector-modern/tracing/PerformanceTracer.h b/packages/react-native/ReactCommon/jsinspector-modern/tracing/PerformanceTracer.h index 533a6c388c9..7b83cff0a4e 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/tracing/PerformanceTracer.h +++ b/packages/react-native/ReactCommon/jsinspector-modern/tracing/PerformanceTracer.h @@ -149,7 +149,10 @@ class PerformanceTracer { */ uint32_t performanceMeasureCount_{0}; + HighResTimeStamp currentTraceStartTime_; + std::vector buffer_; + /** * Protects data members of this class for concurrent access, including * the tracingAtomic_, in order to eliminate potential "logic" races.