mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Report JavaScript thread (#49395)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
72e745fc15
commit
bf6852db2e
@@ -154,6 +154,7 @@ void InstanceAgent::maybeSendPendingConsoleMessages() {
|
||||
|
||||
void InstanceAgent::startTracing() {
|
||||
if (runtimeAgent_) {
|
||||
runtimeAgent_->registerForTracing();
|
||||
runtimeAgent_->enableSamplingProfiler();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "SessionState.h"
|
||||
|
||||
#include <jsinspector-modern/InspectorInterfaces.h>
|
||||
#include <jsinspector-modern/InstanceTarget.h>
|
||||
#include <jsinspector-modern/RuntimeAgent.h>
|
||||
#include <jsinspector-modern/tracing/InstanceTracingProfile.h>
|
||||
|
||||
@@ -19,8 +20,6 @@
|
||||
|
||||
namespace facebook::react::jsinspector_modern {
|
||||
|
||||
class InstanceTarget;
|
||||
|
||||
/**
|
||||
* An Agent that handles requests from the Chrome DevTools Protocol for the
|
||||
* given InstanceTarget.
|
||||
|
||||
@@ -149,6 +149,10 @@ RuntimeAgent::~RuntimeAgent() {
|
||||
sessionState_.lastRuntimeAgentExportedState = getExportedState();
|
||||
}
|
||||
|
||||
void RuntimeAgent::registerForTracing() {
|
||||
targetController_.registerForTracing();
|
||||
}
|
||||
|
||||
void RuntimeAgent::enableSamplingProfiler() {
|
||||
targetController_.enableSamplingProfiler();
|
||||
}
|
||||
|
||||
@@ -83,6 +83,12 @@ class RuntimeAgent final {
|
||||
*/
|
||||
ExportedState getExportedState();
|
||||
|
||||
/**
|
||||
* Registers the corresponding RuntimeTarget for Tracing: might enable some
|
||||
* capabilities that will be later used in Tracing Profile.
|
||||
*/
|
||||
void registerForTracing();
|
||||
|
||||
/**
|
||||
* Start sampling profiler for the corresponding RuntimeTarget.
|
||||
*/
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "SessionState.h"
|
||||
|
||||
#include <jsinspector-modern/RuntimeTarget.h>
|
||||
#include <jsinspector-modern/tracing/PerformanceTracer.h>
|
||||
|
||||
using namespace facebook::jsi;
|
||||
|
||||
@@ -159,6 +160,10 @@ void RuntimeTargetController::notifyDebuggerSessionDestroyed() {
|
||||
target_.emitDebuggerSessionDestroyed();
|
||||
}
|
||||
|
||||
void RuntimeTargetController::registerForTracing() {
|
||||
target_.registerForTracing();
|
||||
}
|
||||
|
||||
void RuntimeTargetController::enableSamplingProfiler() {
|
||||
target_.enableSamplingProfiler();
|
||||
}
|
||||
@@ -172,6 +177,12 @@ RuntimeTargetController::collectSamplingProfile() {
|
||||
return target_.collectSamplingProfile();
|
||||
}
|
||||
|
||||
void RuntimeTarget::registerForTracing() {
|
||||
jsExecutor_([](auto& /*runtime*/) {
|
||||
PerformanceTracer::getInstance().reportJavaScriptThread();
|
||||
});
|
||||
}
|
||||
|
||||
void RuntimeTarget::enableSamplingProfiler() {
|
||||
delegate_.enableSamplingProfiler();
|
||||
}
|
||||
|
||||
@@ -134,6 +134,12 @@ class RuntimeTargetController {
|
||||
*/
|
||||
void notifyDebuggerSessionDestroyed();
|
||||
|
||||
/**
|
||||
* Registers the corresponding RuntimeTarget for Tracing: might enable some
|
||||
* capabilities that will be later used in Tracing Profile.
|
||||
*/
|
||||
void registerForTracing();
|
||||
|
||||
/**
|
||||
* Start sampling profiler for the corresponding RuntimeTarget.
|
||||
*/
|
||||
@@ -202,6 +208,12 @@ class JSINSPECTOR_EXPORT RuntimeTarget
|
||||
FrontendChannel channel,
|
||||
SessionState& sessionState);
|
||||
|
||||
/**
|
||||
* Registers this Runtime for Tracing: might enable some
|
||||
* capabilities that will be later used in Tracing Profile.
|
||||
*/
|
||||
void registerForTracing();
|
||||
|
||||
/**
|
||||
* Start sampling profiler for a particular JavaScript runtime.
|
||||
*/
|
||||
|
||||
@@ -188,6 +188,10 @@ void PerformanceTracer::reportProcess(uint64_t id, const std::string& name) {
|
||||
});
|
||||
}
|
||||
|
||||
void PerformanceTracer::reportJavaScriptThread() {
|
||||
reportThread(oscompat::getCurrentThreadId(), "JavaScript");
|
||||
}
|
||||
|
||||
void PerformanceTracer::reportThread(uint64_t id, const std::string& name) {
|
||||
if (!tracing_) {
|
||||
return;
|
||||
|
||||
@@ -88,6 +88,12 @@ class PerformanceTracer {
|
||||
*/
|
||||
void reportThread(uint64_t id, const std::string& name);
|
||||
|
||||
/**
|
||||
* Should only be called from the JavaScript thread, will buffer metadata
|
||||
* Trace Event.
|
||||
*/
|
||||
void reportJavaScriptThread();
|
||||
|
||||
private:
|
||||
PerformanceTracer();
|
||||
PerformanceTracer(const PerformanceTracer&) = delete;
|
||||
|
||||
Reference in New Issue
Block a user