Skip to content

Commit d898f33

Browse files
committed
fixup! refactor: node tracing agent and track event registration
1 parent f35b26d commit d898f33

8 files changed

Lines changed: 32 additions & 35 deletions

File tree

‎patches/node/fix_use_embedder_perfetto_client_when_available.patch‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,36 @@ index ad3fe3e168882dcd8dce22cbaaeb81a626efb182..6ad1b95d5340c3f0f439388edde652d0
7373
tracing::EnvironmentArgs traced_value(args, exec_args);
7474
TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(TRACING_CATEGORY_NODE1(environment),
7575
"Environment",
76+
diff --git a/src/node.cc b/src/node.cc
77+
index dcb0ee4dece17406be5afc7313a35c921fd0d6ef..5f7103dffef71955f728256352105a5ac3761e88 100644
78+
--- a/src/node.cc
79+
+++ b/src/node.cc
80+
@@ -47,6 +47,10 @@
81+
#include "node_v8_platform-inl.h"
82+
#include "node_version.h"
83+
84+
+#if defined(V8_USE_PERFETTO)
85+
+#include "tracing/trace_event_perfetto.h"
86+
+#endif
87+
+
88+
#if HAVE_OPENSSL
89+
#include "ncrypto.h"
90+
#include "node_crypto.h"
91+
@@ -1136,6 +1140,14 @@ InitializeOncePerProcessInternal(const std::vector<std::string>& args,
92+
}
93+
}
94+
95+
+#if defined(V8_USE_PERFETTO)
96+
+ // Register Node's TrackEvent data source when tracing is provided by the
97+
+ // embedder. The standalone tracing agent initializes and registers it later.
98+
+ if (perfetto::Tracing::IsInitialized()) {
99+
+ tracing::RegisterPerfettoTrackEvent();
100+
+ }
101+
+#endif
102+
+
103+
if (!(flags & ProcessInitializationFlags::kNoUseLargePages) &&
104+
(per_process::cli_options->use_largepages == "on" ||
105+
per_process::cli_options->use_largepages == "silent")) {
76106
diff --git a/src/node_contextify.cc b/src/node_contextify.cc
77107
index 900bf7a3d67245dbbdbe9198671bc4de5093dd52..1c37d60329af852a53f352bfc8c53a37acf34ae1 100644
78108
--- a/src/node_contextify.cc

‎shell/app/node_main.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "shell/common/node_util.h"
3535
#include "shell/common/options_switches.h"
3636
#include "shell/common/platform_util.h"
37+
#include "third_party/electron_node/src/tracing/agent.h"
3738

3839
#if BUILDFLAG(IS_WIN)
3940
#include "chrome/child/v8_crashpad_support_win.h"
@@ -258,8 +259,7 @@ int NodeMain() {
258259
// idle in the kernel’s event provider .
259260
uv_loop_configure(loop, UV_METRICS_IDLE_TIME);
260261

261-
auto tracing_agent = NodeBindings::InitializeTracingAgent(
262-
/*use_standalone_perfetto_client=*/true);
262+
auto tracing_agent = node::tracing::Agent::CreateDefault();
263263
CHECK(tracing_agent);
264264

265265
// Initialize gin::IsolateHolder.

‎shell/browser/electron_browser_main_parts.cc‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,6 @@ void ElectronBrowserMainParts::PostEarlyInitialization() {
257257
}
258258
#endif
259259

260-
NodeBindings::InitializeTracingAgent(
261-
/*use_standalone_perfetto_client=*/false);
262-
263260
// The ProxyResolverV8 has setup a complete V8 environment, in order to
264261
// avoid conflicts we only initialize our V8 environment after that.
265262
js_env_ = std::make_unique<JavascriptEnvironment>(node_bindings_->uv_loop());

‎shell/common/node_bindings.cc‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
#include "third_party/electron_node/src/debug_utils.h"
5555
#include "third_party/electron_node/src/module_wrap.h"
5656
#include "third_party/electron_node/src/node_snapshot_builder.h"
57-
#include "third_party/electron_node/src/tracing/trace_event_perfetto.h"
5857
#include "v8/include/v8-statistics.h"
5958

6059
#if !IS_MAS_BUILD()
@@ -617,16 +616,6 @@ void NodeBindings::RegisterBuiltinBindings() {
617616
#undef V
618617
}
619618

620-
// static
621-
std::unique_ptr<node::tracing::Agent, node::tracing::Agent::Deleter>
622-
NodeBindings::InitializeTracingAgent(bool use_standalone_perfetto_client) {
623-
if (!use_standalone_perfetto_client) {
624-
node::tracing::RegisterPerfettoTrackEvent();
625-
return nullptr;
626-
}
627-
return node::tracing::Agent::CreateDefault();
628-
}
629-
630619
bool NodeBindings::IsInitialized() {
631620
return g_is_initialized;
632621
}

‎shell/common/node_bindings.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "gin/public/context_holder.h"
2020
#include "shell/common/gin_helper/gin_embedders.h"
2121
#include "shell/common/uv_includes.h"
22-
#include "third_party/electron_node/src/tracing/agent.h"
2322
#include "v8/include/v8-forward.h"
2423

2524
namespace base {
@@ -122,8 +121,6 @@ class NodeBindings {
122121
static std::unique_ptr<NodeBindings> Create(BrowserEnvironment browser_env,
123122
uv_loop_t* loop);
124123
static void RegisterBuiltinBindings();
125-
static std::unique_ptr<node::tracing::Agent, node::tracing::Agent::Deleter>
126-
InitializeTracingAgent(bool use_standalone_perfetto_client);
127124
static bool IsInitialized();
128125

129126
// Undo node::InitializeOncePerProcess() for this process. Must run before

‎shell/renderer/electron_renderer_client.cc‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,6 @@ void ElectronRendererClient::DidCreateScriptContext(
143143
electron_bindings_.get());
144144
NodeBindings* node_bindings = frame_env->node_bindings;
145145

146-
// Setup node tracing controller.
147-
static const node::tracing::Agent* const tracing_agent =
148-
NodeBindings::InitializeTracingAgent(
149-
/*use_standalone_perfetto_client=*/false)
150-
.release();
151-
CHECK_EQ(tracing_agent, nullptr);
152-
153146
// Setup node environment for each window.
154147
v8::Maybe<bool> initialized = node::InitializeContext(renderer_context);
155148
CHECK(!initialized.IsNothing() && initialized.FromJust());

‎shell/renderer/web_worker_observer.cc‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,6 @@ void WebWorkerObserver::InitializeNewEnvironment(
9595
// Start the embed thread.
9696
node_bindings_->PrepareEmbedThread();
9797

98-
// Setup node tracing controller.
99-
static const node::tracing::Agent* const tracing_agent =
100-
NodeBindings::InitializeTracingAgent(
101-
/*use_standalone_perfetto_client=*/false)
102-
.release();
103-
CHECK_EQ(tracing_agent, nullptr);
104-
10598
// The renderer main thread normally installed the process-wide builtin code
10699
// cache already (NodeBindings::Initialize); make sure before this thread's
107100
// per-context BuiltinLoader is constructed by InitializeContext. Idempotent.

‎shell/services/node/node_service.cc‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,6 @@ void NodeService::Initialize(
148148
}
149149
#endif
150150

151-
NodeBindings::InitializeTracingAgent(
152-
/*use_standalone_perfetto_client=*/false);
153151
js_env_.emplace(node_bindings_->uv_loop());
154152

155153
v8::Isolate* const isolate = js_env_->isolate();

0 commit comments

Comments
 (0)