Skip to content

Commit 593bdc6

Browse files
hoxyqfacebook-github-bot
authored andcommitted
Keep tracingMode on TraceRecordingState (#53077)
Summary: Pull Request resolved: #53077 # Changelog: [Internal] Stores the tracing::Mode on a TraceRecordingState and updates the logic for: - InstanceTracingAgent to enable PerformanceTracer with a specified window size - RuntimeTracingAgent to only enable sampling profiler for CDP-initiated sessions Reviewed By: sbuggay Differential Revision: D79670864 fbshipit-source-id: 2c4eacb29666b59acbc508848a0a3d859f21a403
1 parent b358404 commit 593bdc6

4 files changed

Lines changed: 31 additions & 6 deletions

File tree

packages/react-native/ReactCommon/jsinspector-modern/HostTargetTraceRecording.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ void HostTargetTraceRecording::start() {
2929
hostTracingAgent_ == nullptr &&
3030
"Tracing Agent for the HostTarget was already initialized.");
3131

32-
state_ = tracing::TraceRecordingState{.startTime = HighResTimeStamp::now()};
32+
state_ = tracing::TraceRecordingState{
33+
.mode = tracingMode_,
34+
.startTime = HighResTimeStamp::now(),
35+
};
3336
hostTracingAgent_ = hostTarget_.createTracingAgent(*state_);
3437
}
3538

packages/react-native/ReactCommon/jsinspector-modern/InstanceAgent.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@
1515

1616
namespace facebook::react::jsinspector_modern {
1717

18+
namespace {
19+
20+
// The size of the timeline for the trace recording that happened in the
21+
// background.
22+
constexpr HighResDuration kBackgroundTracePerformanceTracerWindowSize =
23+
HighResDuration::fromMilliseconds(20000);
24+
25+
} // namespace
26+
1827
InstanceAgent::InstanceAgent(
1928
FrontendChannel frontendChannel,
2029
InstanceTarget& target,
@@ -160,7 +169,12 @@ void InstanceAgent::maybeSendPendingConsoleMessages() {
160169

161170
InstanceTracingAgent::InstanceTracingAgent(tracing::TraceRecordingState& state)
162171
: tracing::TargetTracingAgent(state) {
163-
tracing::PerformanceTracer::getInstance().startTracing();
172+
auto& performanceTracer = tracing::PerformanceTracer::getInstance();
173+
if (state.mode == tracing::Mode::Background) {
174+
performanceTracer.startTracing(kBackgroundTracePerformanceTracerWindowSize);
175+
} else {
176+
performanceTracer.startTracing();
177+
}
164178
}
165179

166180
InstanceTracingAgent::~InstanceTracingAgent() {

packages/react-native/ReactCommon/jsinspector-modern/RuntimeAgent.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,18 @@ RuntimeTracingAgent::RuntimeTracingAgent(
134134
tracing::TraceRecordingState& state,
135135
RuntimeTargetController& targetController)
136136
: tracing::TargetTracingAgent(state), targetController_(targetController) {
137-
targetController_.enableSamplingProfiler();
137+
if (state.mode == tracing::Mode::CDP) {
138+
targetController_.enableSamplingProfiler();
139+
}
138140
}
139141

140142
RuntimeTracingAgent::~RuntimeTracingAgent() {
141-
targetController_.disableSamplingProfiler();
142-
auto profile = targetController_.collectSamplingProfile();
143+
if (state_.mode == tracing::Mode::CDP) {
144+
targetController_.disableSamplingProfiler();
145+
auto profile = targetController_.collectSamplingProfile();
143146

144-
state_.runtimeSamplingProfiles.emplace_back(std::move(profile));
147+
state_.runtimeSamplingProfiles.emplace_back(std::move(profile));
148+
}
145149
}
146150

147151
} // namespace facebook::react::jsinspector_modern

packages/react-native/ReactCommon/jsinspector-modern/tracing/TraceRecordingState.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "InstanceTracingProfile.h"
1111
#include "RuntimeSamplingProfile.h"
12+
#include "TracingMode.h"
1213

1314
#include <oscompat/OSCompat.h>
1415
#include <react/timing/primitives.h>
@@ -18,6 +19,9 @@
1819
namespace facebook::react::jsinspector_modern::tracing {
1920

2021
struct TraceRecordingState {
22+
// The mode of this Trace Recording.
23+
tracing::Mode mode;
24+
2125
// The ID of the OS-level process that this Trace Recording is associated
2226
// with.
2327
ProcessId processId = oscompat::getCurrentProcessId();

0 commit comments

Comments
 (0)