From 6d173727e4d850523bfbb342f871743fb6eabae6 Mon Sep 17 00:00:00 2001 From: Chengzhong Wu Date: Sun, 2 Nov 2025 21:43:58 +0000 Subject: [PATCH] build: perfetto-sdk Signed-off-by: Chengzhong Wu PR-URL: https://github.com/nodejs/node/pull/64565 Refs: https://github.com/nodejs/diagnostics/issues/654 Reviewed-By: James M Snell Reviewed-By: Ryuhei Shima --- common.gypi | 2 +- configure.py | 7 +++++ node.gyp | 16 ++++++++++ tools/v8_gypfiles/features.gypi | 8 +++-- tools/v8_gypfiles/v8.gyp | 54 +++++++++++++++++++++++++++++++-- 5 files changed, 81 insertions(+), 6 deletions(-) diff --git a/common.gypi b/common.gypi index 0552460cb0b..e065e6e925f 100644 --- a/common.gypi +++ b/common.gypi @@ -87,7 +87,7 @@ 'v8_enable_external_code_space%': 0, 'v8_enable_sandbox%': 0, 'v8_enable_v8_checks%': 0, - 'v8_use_perfetto': 0, + 'v8_use_perfetto%': 0, 'tsan%': 0, ##### end V8 defaults ##### diff --git a/configure.py b/configure.py index 04ffff0db81..def52c6fb22 100755 --- a/configure.py +++ b/configure.py @@ -1123,6 +1123,12 @@ parser.add_argument('--without-inspector', default=None, help='disable the V8 inspector protocol') +parser.add_argument('--with-perfetto', + action='store_true', + dest='with_perfetto', + default=None, + help='enable perfetto support') + parser.add_argument('--shared', action='store_true', dest='shared', @@ -2223,6 +2229,7 @@ def configure_v8(o, configs): options.v8_disable_temporal_support = True o['variables']['v8_enable_temporal_support'] = 0 if options.v8_disable_temporal_support else 1 o['variables']['v8_trace_maps'] = 1 if options.trace_maps else 0 + o['variables']['v8_use_perfetto'] = 1 if options.with_perfetto else 0 o['variables']['node_use_v8_platform'] = b(not options.without_v8_platform) o['variables']['node_use_bundled_v8'] = b(not options.without_bundled_v8) o['variables']['force_dynamic_crt'] = 1 if options.shared else 0 diff --git a/node.gyp b/node.gyp index 368b621b123..2f52608e236 100644 --- a/node.gyp +++ b/node.gyp @@ -1462,6 +1462,14 @@ }, { 'sources!': [ '<@(node_cctest_quic_sources)' ], }], + [ 'v8_use_perfetto==1', { + 'defines': [ + 'PERFETTO_ENABLE_LEGACY_TRACE_EVENTS=1' + ], + 'dependencies': [ + 'deps/perfetto/perfetto.gyp:perfetto_sdk', + ], + }], ['v8_enable_inspector==1', { 'defines': [ 'HAVE_INSPECTOR=1', @@ -1783,6 +1791,14 @@ 'NODE_USE_NODE_CODE_CACHE=1', ], }], + [ 'v8_use_perfetto==1', { + 'defines': [ + 'PERFETTO_ENABLE_LEGACY_TRACE_EVENTS=1' + ], + 'dependencies': [ + 'deps/perfetto/perfetto.gyp:perfetto_sdk', + ], + }], ['v8_enable_inspector==1', { 'defines': [ 'HAVE_INSPECTOR=1', diff --git a/tools/v8_gypfiles/features.gypi b/tools/v8_gypfiles/features.gypi index 0208ce11983..a5227687d22 100644 --- a/tools/v8_gypfiles/features.gypi +++ b/tools/v8_gypfiles/features.gypi @@ -200,8 +200,7 @@ # Enable seeded array index hash. 'v8_enable_seeded_array_index_hash%': 1, - # Use Perfetto (https://perfetto.dev) as the default TracingController. Not - # currently implemented. + # Use Perfetto (https://perfetto.dev) as the default TracingController. 'v8_use_perfetto%': 0, # Enable map packing & unpacking (sets -dV8_MAP_PACKING). @@ -463,7 +462,10 @@ 'defines': ['ENABLE_VERIFY_CSA',], }], ['v8_use_perfetto==1', { - 'defines': ['V8_USE_PERFETTO',], + 'defines': [ + 'V8_USE_PERFETTO', + 'V8_USE_PERFETTO_SDK', + ], }], ['v8_enable_map_packing==1', { 'defines': ['V8_MAP_PACKING',], diff --git a/tools/v8_gypfiles/v8.gyp b/tools/v8_gypfiles/v8.gyp index 7953fa44b43..94a5435fca6 100644 --- a/tools/v8_gypfiles/v8.gyp +++ b/tools/v8_gypfiles/v8.gyp @@ -38,6 +38,7 @@ ], }], ], + 'perfetto_gyp_file': '../../deps/perfetto/perfetto.gyp', }, 'includes': ['toolchain.gypi', 'features.gypi'], 'target_defaults': { @@ -292,6 +293,13 @@ 'sources': [ '<(V8_ROOT)/src/init/setup-isolate-full.cc', ], + 'conditions': [ + ['v8_use_perfetto==1', { + 'dependencies': [ + '<(perfetto_gyp_file):perfetto_sdk', + ], + }], + ], }, # v8_init { 'target_name': 'v8_initializers', @@ -312,6 +320,11 @@ '