Skip to content

Commit e651563

Browse files
hoxyqmeta-codesync[bot]
authored andcommitted
Keep tracing time window on TraceRecordingState (facebook#54673)
Summary: Pull Request resolved: facebook#54673 # Changelog: [Internal] `HostTargetTraceRecording` will receive the tracing window size as a parameter and will propagate it to `TraceRecordingState`. This will make sure that all Tracing Agents actually aware of the window size. For example, once we add Frames to Host layer, it should use the same window size, as `PerformanceTracer`, which is initialized in `InstanceTracingAgent`. Reviewed By: sbuggay Differential Revision: D87782664 fbshipit-source-id: 58203065d68ac898adc785317ec2cb792efd13dc
1 parent d6ee54f commit e651563

File tree

5 files changed

+41
-20
lines changed

5 files changed

+41
-20
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ namespace facebook::react::jsinspector_modern {
1515
HostTargetTraceRecording::HostTargetTraceRecording(
1616
HostTarget& hostTarget,
1717
tracing::Mode tracingMode,
18-
std::set<tracing::Category> enabledCategories)
18+
std::set<tracing::Category> enabledCategories,
19+
std::optional<HighResDuration> windowSize)
1920
: hostTarget_(hostTarget),
2021
tracingMode_(tracingMode),
21-
enabledCategories_(std::move(enabledCategories)) {}
22+
enabledCategories_(std::move(enabledCategories)),
23+
windowSize_(windowSize) {}
2224

2325
void HostTargetTraceRecording::setTracedInstance(
2426
InstanceTarget* instanceTarget) {
@@ -35,10 +37,8 @@ void HostTargetTraceRecording::start() {
3537
"Tracing Agent for the HostTarget was already initialized.");
3638

3739
startTime_ = HighResTimeStamp::now();
38-
state_ = tracing::TraceRecordingState{
39-
.mode = tracingMode_,
40-
.enabledCategories = enabledCategories_,
41-
};
40+
state_ = tracing::TraceRecordingState(
41+
tracingMode_, enabledCategories_, windowSize_);
4242
hostTracingAgent_ = hostTarget_.createTracingAgent(*state_);
4343
}
4444

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <jsinspector-modern/tracing/HostTracingProfile.h>
1515
#include <jsinspector-modern/tracing/TraceRecordingState.h>
1616
#include <jsinspector-modern/tracing/TracingCategory.h>
17+
#include <react/timing/primitives.h>
1718

1819
#include <optional>
1920
#include <set>
@@ -31,10 +32,11 @@ namespace facebook::react::jsinspector_modern {
3132
*/
3233
class HostTargetTraceRecording {
3334
public:
34-
explicit HostTargetTraceRecording(
35+
HostTargetTraceRecording(
3536
HostTarget &hostTarget,
3637
tracing::Mode tracingMode,
37-
std::set<tracing::Category> enabledCategories);
38+
std::set<tracing::Category> enabledCategories,
39+
std::optional<HighResDuration> windowSize = std::nullopt);
3840

3941
inline bool isBackgroundInitiated() const
4042
{
@@ -97,6 +99,11 @@ class HostTargetTraceRecording {
9799
* The list of categories that are enabled for this recording.
98100
*/
99101
std::set<tracing::Category> enabledCategories_;
102+
103+
/**
104+
* The size of the time window for this recording.
105+
*/
106+
std::optional<HighResDuration> windowSize_;
100107
};
101108

102109
} // namespace facebook::react::jsinspector_modern

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

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

1111
namespace facebook::react::jsinspector_modern {
1212

13+
namespace {
14+
15+
// The size of the timeline for the trace recording that happened in the
16+
// background.
17+
constexpr HighResDuration kBackgroundTraceWindowSize =
18+
HighResDuration::fromMilliseconds(20000);
19+
20+
} // namespace
21+
1322
bool HostTargetController::startTracing(
1423
tracing::Mode tracingMode,
1524
std::set<tracing::Category> enabledCategories) {
@@ -39,11 +48,14 @@ bool HostTarget::startTracing(
3948
}
4049
}
4150

51+
auto timeWindow = tracingMode == tracing::Mode::Background
52+
? std::make_optional(kBackgroundTraceWindowSize)
53+
: std::nullopt;
4254
auto screenshotsCategoryEnabled =
4355
enabledCategories.contains(tracing::Category::Screenshot);
4456

4557
traceRecording_ = std::make_unique<HostTargetTraceRecording>(
46-
*this, tracingMode, std::move(enabledCategories));
58+
*this, tracingMode, std::move(enabledCategories), timeWindow);
4759
traceRecording_->setTracedInstance(currentInstance_.get());
4860
traceRecording_->start();
4961

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,6 @@
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-
2718
InstanceAgent::InstanceAgent(
2819
FrontendChannel frontendChannel,
2920
InstanceTarget& target,
@@ -171,8 +162,8 @@ void InstanceAgent::maybeSendPendingConsoleMessages() {
171162
InstanceTracingAgent::InstanceTracingAgent(tracing::TraceRecordingState& state)
172163
: tracing::TargetTracingAgent(state) {
173164
auto& performanceTracer = tracing::PerformanceTracer::getInstance();
174-
if (state.mode == tracing::Mode::Background) {
175-
performanceTracer.startTracing(kBackgroundTracePerformanceTracerWindowSize);
165+
if (state.windowSize) {
166+
performanceTracer.startTracing(*state.windowSize);
176167
} else {
177168
performanceTracer.startTracing();
178169
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ namespace facebook::react::jsinspector_modern::tracing {
2323
* Shared with Tracing Agents, which could use it to stash the corresponding target profiles during reloads.
2424
*/
2525
struct TraceRecordingState {
26+
TraceRecordingState(
27+
tracing::Mode tracingMode,
28+
std::set<tracing::Category> enabledCategories,
29+
std::optional<HighResDuration> windowSize = std::nullopt)
30+
: mode(tracingMode), enabledCategories(std::move(enabledCategories)), windowSize(windowSize)
31+
{
32+
}
33+
2634
// The mode of this Trace Recording.
2735
tracing::Mode mode;
2836

@@ -34,6 +42,9 @@ struct TraceRecordingState {
3442

3543
// The list of categories that are enabled for this recording.
3644
std::set<tracing::Category> enabledCategories;
45+
46+
// The size of the time window for this recording.
47+
std::optional<HighResDuration> windowSize;
3748
};
3849

3950
} // namespace facebook::react::jsinspector_modern::tracing

0 commit comments

Comments
 (0)