Skip to content

Commit bf6852d

Browse files
hoxyqfacebook-github-bot
authored andcommitted
Report JavaScript thread (facebook#49395)
Summary: Pull Request resolved: facebook#49395 # Changelog: [Internal] Adding a new method to `RuntimeTarget` that will register it for Tracing. In our case, it will schedule a callback on JS executor that will register JavaScript thread with `PerformanceTracer`. Reviewed By: huntie Differential Revision: D69530984 fbshipit-source-id: 58cffe9e9c4482b494cfcfd3405f7bffa40cdc56
1 parent 72e745f commit bf6852d

File tree

8 files changed

+45
-2
lines changed

8 files changed

+45
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ void InstanceAgent::maybeSendPendingConsoleMessages() {
154154

155155
void InstanceAgent::startTracing() {
156156
if (runtimeAgent_) {
157+
runtimeAgent_->registerForTracing();
157158
runtimeAgent_->enableSamplingProfiler();
158159
}
159160
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@
1212
#include "SessionState.h"
1313

1414
#include <jsinspector-modern/InspectorInterfaces.h>
15+
#include <jsinspector-modern/InstanceTarget.h>
1516
#include <jsinspector-modern/RuntimeAgent.h>
1617
#include <jsinspector-modern/tracing/InstanceTracingProfile.h>
1718

1819
#include <functional>
1920

2021
namespace facebook::react::jsinspector_modern {
2122

22-
class InstanceTarget;
23-
2423
/**
2524
* An Agent that handles requests from the Chrome DevTools Protocol for the
2625
* given InstanceTarget.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ RuntimeAgent::~RuntimeAgent() {
149149
sessionState_.lastRuntimeAgentExportedState = getExportedState();
150150
}
151151

152+
void RuntimeAgent::registerForTracing() {
153+
targetController_.registerForTracing();
154+
}
155+
152156
void RuntimeAgent::enableSamplingProfiler() {
153157
targetController_.enableSamplingProfiler();
154158
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ class RuntimeAgent final {
8383
*/
8484
ExportedState getExportedState();
8585

86+
/**
87+
* Registers the corresponding RuntimeTarget for Tracing: might enable some
88+
* capabilities that will be later used in Tracing Profile.
89+
*/
90+
void registerForTracing();
91+
8692
/**
8793
* Start sampling profiler for the corresponding RuntimeTarget.
8894
*/

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "SessionState.h"
99

1010
#include <jsinspector-modern/RuntimeTarget.h>
11+
#include <jsinspector-modern/tracing/PerformanceTracer.h>
1112

1213
using namespace facebook::jsi;
1314

@@ -159,6 +160,10 @@ void RuntimeTargetController::notifyDebuggerSessionDestroyed() {
159160
target_.emitDebuggerSessionDestroyed();
160161
}
161162

163+
void RuntimeTargetController::registerForTracing() {
164+
target_.registerForTracing();
165+
}
166+
162167
void RuntimeTargetController::enableSamplingProfiler() {
163168
target_.enableSamplingProfiler();
164169
}
@@ -172,6 +177,12 @@ RuntimeTargetController::collectSamplingProfile() {
172177
return target_.collectSamplingProfile();
173178
}
174179

180+
void RuntimeTarget::registerForTracing() {
181+
jsExecutor_([](auto& /*runtime*/) {
182+
PerformanceTracer::getInstance().reportJavaScriptThread();
183+
});
184+
}
185+
175186
void RuntimeTarget::enableSamplingProfiler() {
176187
delegate_.enableSamplingProfiler();
177188
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ class RuntimeTargetController {
134134
*/
135135
void notifyDebuggerSessionDestroyed();
136136

137+
/**
138+
* Registers the corresponding RuntimeTarget for Tracing: might enable some
139+
* capabilities that will be later used in Tracing Profile.
140+
*/
141+
void registerForTracing();
142+
137143
/**
138144
* Start sampling profiler for the corresponding RuntimeTarget.
139145
*/
@@ -202,6 +208,12 @@ class JSINSPECTOR_EXPORT RuntimeTarget
202208
FrontendChannel channel,
203209
SessionState& sessionState);
204210

211+
/**
212+
* Registers this Runtime for Tracing: might enable some
213+
* capabilities that will be later used in Tracing Profile.
214+
*/
215+
void registerForTracing();
216+
205217
/**
206218
* Start sampling profiler for a particular JavaScript runtime.
207219
*/

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ void PerformanceTracer::reportProcess(uint64_t id, const std::string& name) {
188188
});
189189
}
190190

191+
void PerformanceTracer::reportJavaScriptThread() {
192+
reportThread(oscompat::getCurrentThreadId(), "JavaScript");
193+
}
194+
191195
void PerformanceTracer::reportThread(uint64_t id, const std::string& name) {
192196
if (!tracing_) {
193197
return;

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ class PerformanceTracer {
8888
*/
8989
void reportThread(uint64_t id, const std::string& name);
9090

91+
/**
92+
* Should only be called from the JavaScript thread, will buffer metadata
93+
* Trace Event.
94+
*/
95+
void reportJavaScriptThread();
96+
9197
private:
9298
PerformanceTracer();
9399
PerformanceTracer(const PerformanceTracer&) = delete;

0 commit comments

Comments
 (0)