Skip to content

Commit 8698eca

Browse files
hoxyqfacebook-github-bot
authored andcommitted
Emit synthetic Trace Events for non-bridgeless to fix trace representation (facebook#49729)
Summary: Pull Request resolved: facebook#49729 # Changelog: [Internal] The only data source for non-bridgeless setup is JavaScript samples. Chrome DevTools frontend is built around an assumption that thread should have at least single timeline or user timing event to be represented on a timeline view. They do it for filtering out unnecessary workers threads and other. We will emit 2 synthetic Trace Events that should cover these requirements and recorded traces that contain only JavaScript samples should now be displayed correctly. This is where trace bounds are calculated - https://github.com/facebookexperimental/rn-chrome-devtools-frontend/blob/3adf51aa915c2deb26f5d373751a15b4d0c8f259/front_end/models/trace/handlers/MetaHandler.ts#L169-L173 Reviewed By: huntie Differential Revision: D70328681 fbshipit-source-id: 8eca0017d85de9ecbfb49074b439d5c4fee4aa56
1 parent 13177b3 commit 8698eca

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

packages/react-native/ReactCommon/jsinspector-modern/tracing/PerformanceTracer.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@ bool PerformanceTracer::stopTracing() {
6767
return false;
6868
}
6969

70+
// This is synthetic Trace Event, which should not be represented on a
71+
// timeline. CDT is not using Profile or ProfileChunk events for determining
72+
// trace timeline window, this is why trace that only contains JavaScript
73+
// samples will be displayed as empty. We use this event to avoid that.
74+
// This could happen for non-bridgeless apps, where Performance interface is
75+
// not supported and no spec-compliant Event Loop implementation.
76+
buffer_.push_back(TraceEvent{
77+
.name = "ReactNative-TracingStopped",
78+
.cat = "disabled-by-default-devtools.timeline",
79+
.ph = 'I',
80+
.ts = getUnixTimestampOfNow(),
81+
.pid = processId_,
82+
.tid = oscompat::getCurrentThreadId(),
83+
});
84+
7085
performanceMeasureCount_ = 0;
7186
profileCount_ = 0;
7287
tracing_ = false;
@@ -212,6 +227,20 @@ void PerformanceTracer::reportThread(uint64_t id, const std::string& name) {
212227
.tid = id,
213228
.args = folly::dynamic::object("name", name),
214229
});
230+
231+
// This is synthetic Trace Event, which should not be represented on a
232+
// timeline. CDT will filter out threads that only have JavaScript samples and
233+
// no timeline events or user timings. We use this event to avoid that.
234+
// This could happen for non-bridgeless apps, where Performance interface is
235+
// not supported and no spec-compliant Event Loop implementation.
236+
buffer_.push_back(TraceEvent{
237+
.name = "ReactNative-ThreadRegistered",
238+
.cat = "disabled-by-default-devtools.timeline",
239+
.ph = 'I',
240+
.ts = 0,
241+
.pid = processId_,
242+
.tid = id,
243+
});
215244
}
216245

217246
uint16_t PerformanceTracer::reportRuntimeProfile(

0 commit comments

Comments
 (0)