mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Create TracingMode (#53035)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/53035 # Changelog: [Internal] This adds an ability to distinguish different trace recordings, based on mode Reviewed By: sbuggay Differential Revision: D79557790 fbshipit-source-id: cbb216df86fa1a4692e1b82c8a14a6049b5c45ec
This commit is contained in:
committed by
Facebook GitHub Bot
parent
989579c533
commit
f66ef53962
@@ -18,6 +18,8 @@
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include <jsinspector-modern/tracing/TracingMode.h>
|
||||
|
||||
#ifndef JSINSPECTOR_EXPORT
|
||||
#ifdef _MSC_VER
|
||||
#ifdef CREATE_SHARED_LIBRARY
|
||||
@@ -171,9 +173,10 @@ class HostTargetController final {
|
||||
/**
|
||||
* Starts trace recording for this HostTarget.
|
||||
*
|
||||
* \param mode In which mode to start the trace recording.
|
||||
* \return false if already tracing, true otherwise.
|
||||
*/
|
||||
bool startTracing();
|
||||
bool startTracing(tracing::Mode mode);
|
||||
|
||||
/**
|
||||
* Stops previously started trace recording.
|
||||
@@ -264,9 +267,10 @@ class JSINSPECTOR_EXPORT HostTarget
|
||||
/**
|
||||
* Starts trace recording for this HostTarget.
|
||||
*
|
||||
* \param mode In which mode to start the trace recording.
|
||||
* \return false if already tracing, true otherwise.
|
||||
*/
|
||||
bool startTracing();
|
||||
bool startTracing(tracing::Mode mode);
|
||||
|
||||
/**
|
||||
* Stops previously started trace recording.
|
||||
|
||||
@@ -10,8 +10,10 @@
|
||||
|
||||
namespace facebook::react::jsinspector_modern {
|
||||
|
||||
HostTargetTraceRecording::HostTargetTraceRecording(HostTarget& hostTarget)
|
||||
: hostTarget_(hostTarget) {}
|
||||
HostTargetTraceRecording::HostTargetTraceRecording(
|
||||
tracing::Mode tracingMode,
|
||||
HostTarget& hostTarget)
|
||||
: tracingMode_(tracingMode), hostTarget_(hostTarget) {}
|
||||
|
||||
void HostTargetTraceRecording::setTracedInstance(
|
||||
InstanceTarget* instanceTarget) {
|
||||
|
||||
@@ -28,7 +28,17 @@ namespace facebook::react::jsinspector_modern {
|
||||
*/
|
||||
class HostTargetTraceRecording {
|
||||
public:
|
||||
explicit HostTargetTraceRecording(HostTarget& hostTarget);
|
||||
explicit HostTargetTraceRecording(
|
||||
tracing::Mode tracingMode,
|
||||
HostTarget& hostTarget);
|
||||
|
||||
inline bool isBackgroundInitiated() const {
|
||||
return tracingMode_ == tracing::Mode::Background;
|
||||
}
|
||||
|
||||
inline bool isUserInitiated() const {
|
||||
return tracingMode_ == tracing::Mode::CDP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the current traced Instance for this recording.
|
||||
@@ -50,6 +60,11 @@ class HostTargetTraceRecording {
|
||||
tracing::TraceRecordingState stop();
|
||||
|
||||
private:
|
||||
/**
|
||||
* The mode in which this trace recording was initialized.
|
||||
*/
|
||||
tracing::Mode tracingMode_;
|
||||
|
||||
/**
|
||||
* The Host for which this Trace Recording is going to happen.
|
||||
*/
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
|
||||
namespace facebook::react::jsinspector_modern {
|
||||
|
||||
bool HostTargetController::startTracing() {
|
||||
return target_.startTracing();
|
||||
bool HostTargetController::startTracing(tracing::Mode tracingMode) {
|
||||
return target_.startTracing(tracingMode);
|
||||
}
|
||||
|
||||
tracing::TraceRecordingState HostTargetController::stopTracing() {
|
||||
@@ -25,12 +25,13 @@ std::shared_ptr<HostTracingAgent> HostTarget::createTracingAgent(
|
||||
return agent;
|
||||
}
|
||||
|
||||
bool HostTarget::startTracing() {
|
||||
bool HostTarget::startTracing(tracing::Mode tracingMode) {
|
||||
if (traceRecording_ != nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
traceRecording_ = std::make_unique<HostTargetTraceRecording>(*this);
|
||||
traceRecording_ =
|
||||
std::make_unique<HostTargetTraceRecording>(tracingMode, *this);
|
||||
traceRecording_->setTracedInstance(currentInstance_.get());
|
||||
traceRecording_->start();
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <jsinspector-modern/tracing/RuntimeSamplingProfileTraceEventSerializer.h>
|
||||
#include <jsinspector-modern/tracing/TraceEventSerializer.h>
|
||||
#include <jsinspector-modern/tracing/TraceRecordingStateSerializer.h>
|
||||
#include <jsinspector-modern/tracing/TracingMode.h>
|
||||
|
||||
namespace facebook::react::jsinspector_modern {
|
||||
|
||||
@@ -63,7 +64,7 @@ bool TracingAgent::handleRequest(const cdp::PreparsedRequest& req) {
|
||||
}
|
||||
|
||||
bool didNotHaveAlreadyRunningRecording =
|
||||
hostTargetController_.startTracing();
|
||||
hostTargetController_.startTracing(tracing::Mode::CDP);
|
||||
if (!didNotHaveAlreadyRunningRecording) {
|
||||
frontendChannel_(cdp::jsonError(
|
||||
req.id,
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace facebook::react::jsinspector_modern::tracing {
|
||||
|
||||
enum class Mode {
|
||||
CDP, // Initiated by the user via Chrome DevTools Frontend.
|
||||
Background, // Initiated by the host, doesn't require active CDP session.
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user