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
This commit is contained in:
Rubén Norte
2025-07-31 14:29:24 -07:00
committed by Facebook GitHub Bot
parent 9f6440d8c8
commit 00debea508
2 changed files with 15 additions and 1 deletions
@@ -34,7 +34,7 @@ bool PerformanceTracer::startTracing() {
}
tracingAtomic_ = true;
currentTraceStartTime_ = HighResTimeStamp::now();
return true;
}
@@ -60,6 +60,17 @@ std::optional<std::vector<TraceEvent>> 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",
@@ -149,7 +149,10 @@ class PerformanceTracer {
*/
uint32_t performanceMeasureCount_{0};
HighResTimeStamp currentTraceStartTime_;
std::vector<TraceEvent> buffer_;
/**
* Protects data members of this class for concurrent access, including
* the tracingAtomic_, in order to eliminate potential "logic" races.