Skip to content

Commit b9be67e

Browse files
hoxyqmeta-codesync[bot]
authored andcommitted
Use category to control JavaScript sampling profiler (#54381)
Summary: Pull Request resolved: #54381 # Changelog: [Internal] Now, instead of controlling the data sources based on tracing mode, we can control them based on enabled categories. `JavaScriptSampling` category is not enabled in JReactHostInspectorTarget, which allows the Host to control this. Reviewed By: huntie Differential Revision: D85996395 fbshipit-source-id: 4d3495ae0393854ecca1e24ab44546a65bc87733
1 parent 3841ef0 commit b9be67e

2 files changed

Lines changed: 62 additions & 2 deletions

File tree

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,14 @@ RuntimeTracingAgent::RuntimeTracingAgent(
152152
tracing::TraceRecordingState& state,
153153
RuntimeTargetController& targetController)
154154
: tracing::TargetTracingAgent(state), targetController_(targetController) {
155-
if (state.mode == tracing::Mode::CDP) {
155+
if (state.enabledCategories.contains(tracing::Category::JavaScriptSampling)) {
156156
targetController_.enableSamplingProfiler();
157157
}
158158
}
159159

160160
RuntimeTracingAgent::~RuntimeTracingAgent() {
161-
if (state_.mode == tracing::Mode::CDP) {
161+
if (state_.enabledCategories.contains(
162+
tracing::Category::JavaScriptSampling)) {
162163
targetController_.disableSamplingProfiler();
163164
auto profile = targetController_.collectSamplingProfile();
164165

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#include "TracingTest.h"
9+
#include "engines/JsiIntegrationTestHermesEngineAdapter.h"
10+
11+
#include <folly/executors/QueuedImmediateExecutor.h>
12+
#include <jsinspector-modern/InspectorFlags.h>
13+
#include <react/featureflags/ReactNativeFeatureFlags.h>
14+
#include <react/networking/NetworkReporter.h>
15+
16+
using namespace ::testing;
17+
18+
namespace facebook::react::jsinspector_modern {
19+
20+
class TracingTest : public TracingTestBase<
21+
JsiIntegrationTestHermesEngineAdapter,
22+
folly::QueuedImmediateExecutor> {
23+
protected:
24+
TracingTest() : TracingTestBase() {}
25+
26+
void SetUp() override {
27+
JsiIntegrationPortableTestBase::SetUp();
28+
connect();
29+
EXPECT_CALL(
30+
fromPage(),
31+
onMessage(
32+
JsonParsed(AllOf(AtJsonPtr("/method", "Debugger.scriptParsed")))))
33+
.Times(AnyNumber());
34+
}
35+
};
36+
37+
TEST_F(TracingTest, EnablesSamplingProfilerOnlyCategoryIsSpecified) {
38+
InSequence s;
39+
40+
startTracing({});
41+
auto allTraceEvents = endTracingAndCollectEvents();
42+
43+
EXPECT_THAT(
44+
allTraceEvents,
45+
Not(Contains(AllOf(
46+
AtJsonPtr("/name", "Profile"),
47+
AtJsonPtr("/cat", "disabled-by-default-v8.cpu_profiler")))));
48+
49+
startTracing({tracing::Category::JavaScriptSampling});
50+
allTraceEvents = endTracingAndCollectEvents();
51+
52+
EXPECT_THAT(
53+
allTraceEvents,
54+
Contains(AllOf(
55+
AtJsonPtr("/name", "Profile"),
56+
AtJsonPtr("/cat", "disabled-by-default-v8.cpu_profiler"))));
57+
}
58+
59+
} // namespace facebook::react::jsinspector_modern

0 commit comments

Comments
 (0)