Skip to content

build: enable Perfetto by default - #65794

Open
aduh95 wants to merge 16 commits into
nodejs:mainfrom
aduh95:perfetto-sdk
Open

aduh95 wants to merge 16 commits into
nodejs:mainfrom
aduh95:perfetto-sdk

Conversation

@aduh95

@aduh95 aduh95 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

@aduh95 aduh95 added the semver-major PRs that contain breaking changes and should be released in the next major version. label Sep 4, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/actions

@nodejs-github-bot nodejs-github-bot added build Issues and PRs related to Node.js builds or CI infrastructure. meta Issues and PRs related to the general management of the project. needs-ci PRs that need a full CI run. labels Sep 4, 2026
@aduh95

This comment was marked as resolved.

@StefanStojanovic

Copy link
Copy Markdown
Contributor

@aduh95, I'll look into Windows failures.

@StefanStojanovic

StefanStojanovic commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

This is what got it to compile for me locally. In short, it was a configuration problem(s), so gyp changes resolved it all.

Details
From f31ec1fc602e9711756d9ca1d7ae386221e14662 Mon Sep 17 00:00:00 2001
From: StefanStojanovic <stefan.stojanovic@janeasystems.com>
Date: Wed, 9 Sep 2026 08:24:06 +0200
Subject: [PATCH] build,win: fix Perfetto

Signed-off-by: StefanStojanovic <stefan.stojanovic@janeasystems.com>
---
 deps/perfetto/perfetto.gyp | 8 ++++++++
 node.gypi                  | 5 +++++
 tools/v8_gypfiles/v8.gyp   | 6 +++++-
 3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/deps/perfetto/perfetto.gyp b/deps/perfetto/perfetto.gyp
index 083d0b386dd..697256401a3 100644
--- a/deps/perfetto/perfetto.gyp
+++ b/deps/perfetto/perfetto.gyp
@@ -18,6 +18,14 @@
       'sources': [
         '<@(perfetto_sdk_sources)',
       ],
+      'conditions': [
+        ['OS=="win"', {
+          'defines': [
+            'WIN32_LEAN_AND_MEAN',
+            'NOMINMAX',
+          ],
+        }],
+      ],
     },
   ]
 }
diff --git a/node.gypi b/node.gypi
index 104e884e661..1ca77fa3fee 100644
--- a/node.gypi
+++ b/node.gypi
@@ -93,6 +93,11 @@
     [ 'OS=="linux" and target_arch=="s390x"', {
       'cflags': [ '-march=z14' ],
     }],
+    [ 'v8_use_perfetto==1', {
+      'dependencies': [
+        'deps/perfetto/perfetto.gyp:perfetto_sdk',
+      ],
+    }],
     [ 'node_enable_d8=="true"', {
       'dependencies': [ 'tools/v8_gypfiles/d8.gyp:d8' ],
     }],
diff --git a/tools/v8_gypfiles/v8.gyp b/tools/v8_gypfiles/v8.gyp
index a976148ddab..2b1ee51c8f1 100644
--- a/tools/v8_gypfiles/v8.gyp
+++ b/tools/v8_gypfiles/v8.gyp
@@ -1758,7 +1758,11 @@
         }],
         ['v8_use_perfetto==1', {
           'sources!': [
-            '<!@pymod_do_main(GN-scraper "<(V8_ROOT)/BUILD.gn"  "\\"v8_libplatform.*?v8_use_perfetto.*?sources \\-= ")',
+            '<(V8_ROOT)/src/libplatform/tracing/trace-buffer.cc',
+            '<(V8_ROOT)/src/libplatform/tracing/trace-buffer.h',
+            '<(V8_ROOT)/src/libplatform/tracing/trace-writer.cc',
+            '<(V8_ROOT)/src/libplatform/tracing/trace-writer.h',
+            '<(V8_ROOT)/src/tracing/trace-event-no-perfetto.h',
           ],
           'sources': [
             '<!@pymod_do_main(GN-scraper "<(V8_ROOT)/BUILD.gn"  "\\"v8_libplatform.*?v8_use_perfetto.*?sources \\+= ")',
-- 
2.45.2.windows.1

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@aduh95

aduh95 commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

@nodejs/platform-aix Build failure: ../deps/perfetto/sdk/perfetto.h:1035:5: error: function-like macro 'PERFETTO_BUILDFLAG_DEFINE_PERFETTO_OS_APPLE' is not defined

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@richardlau

Copy link
Copy Markdown
Member

@nodejs/platform-aix Build failure: ../deps/perfetto/sdk/perfetto.h:1035:5: error: function-like macro 'PERFETTO_BUILDFLAG_DEFINE_PERFETTO_OS_APPLE' is not defined

I think the actual error is this:
e.g. https://ci.nodejs.org/job/node-test-commit-aix/65261/nodes=aix72-power9/console

01:02:46 In file included from ../deps/perfetto/sdk/perfetto.cc:21:
01:02:46 ../deps/perfetto/sdk/perfetto.h:295:2: error: OS not supported (see build_config.h)
01:02:46   295 | #error OS not supported (see build_config.h)
01:02:46       |  ^

Same failure is seen on SmartOS.

@jasnell

jasnell commented Sep 10, 2026

Copy link
Copy Markdown
Member

doh!

@aduh95

aduh95 commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

How should we proceed? Force --without-perfetto for those platforms or wait until support is added upstream? @nodejs/platform-aix @nodejs/platform-smartos

@jasnell

jasnell commented Sep 10, 2026

Copy link
Copy Markdown
Member

good question. I think as long as the observable behavior with trace events is still the same either way, forcing --without-perfetto on those platforms is likely ok. We'd need to avoid a case where tracing output is broken on just those. If we still consider this experimental, then it should be fine omitting the unsupported platforms, however.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@aduh95 aduh95 added the tsc-agenda Issues and PRs to discuss during Technical Steering Committee meetings. label Sep 15, 2026
@aduh95

aduh95 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

Adding to the TSC agenda to make sure 53d853b has consensus (the alternative would be to block Perfetto enabling until support for all platforms is added upstream)

@saitanallensantiago26-beep

This comment was marked as off-topic.

1 similar comment
@saitanallensantiago26-beep

This comment was marked as off-topic.

@legendecas legendecas added the trace_events Issues and PRs related to trace events from V8, Node.js core, and user code. label Sep 15, 2026
@legendecas

legendecas commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

A long time solution would be to build from source (or use the one from the OS package manager if it exists) the trace_processor on our CI machines I reckon.

The reason that we built with perfetto sdk only was that the full perfetto library has a lot of dependencies (specifically in trace_processor). The Node.js runtime only needs the data producer part (i.e. perfetto_sdk).

If we could setup an independent build (outside of the node.js core build), I think it is acceptable to take in all of perfetto dependencies. But I'd prefer not to include them in ./deps.

@aduh95

aduh95 commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

For reference, I tried cross compiling trace_processor_shell for Linux s390x, but it looks like it's not supported:

FAILED: [code=1] obj/src/trace_processor/core/dataframe/dataframe.typed_cursor.o 
s390x-unknown-linux-musl-c++ -MMD -MF obj/src/trace_processor/core/dataframe/dataframe.typed_cursor.o.d -DNDEBUG -DPERFETTO_IMPLEMENTATION -DRE2_USE_ABSL -I../.. -I../../src/profiling/memory/include -I../../include -Igen/build_config -Igen -fstrict-aliasing -Wformat -g -fPIC -fstack-protector-strong -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -Wall -Wextra -Wpedantic -fvisibility=hidden -O3 -fdata-sections -ffunction-sections -pthread -DNOMINMAX -I/nix/store/nb28sjwi88z3nwngslfdv1wx67jp70pq-abseil-cpp-static-s390x-unknown-linux-musl-20260817.0-dev/include -I/nix/store/0raa09r7jl567y4xxmb88kqf6wvv3bab-re2-static-s390x-unknown-linux-musl-2025-11-05-dev/include -Wno-redundant-move -Wno-use-after-free -Wno-maybe-uninitialized -Wno-infinite-recursion -Wno-nonnull -fno-exceptions -fno-rtti -std=c++17    -std=c++20  -c ../../src/trace_processor/core/dataframe/typed_cursor.cc -o obj/src/trace_processor/core/dataframe/dataframe.typed_cursor.o
In file included from ../../include/perfetto/base/logging.h:24,
                 from ../../src/trace_processor/core/dataframe/typed_cursor.h:27,
                 from ../../src/trace_processor/core/dataframe/typed_cursor.cc:17:
../../src/trace_processor/core/util/bit_vector.h: In static member function 'static perfetto::trace_processor::core::BitVector perfetto::trace_processor::core::BitVector::CreateFromBitmap(const uint8_t*, uint64_t)':
../../include/perfetto/base/compiler.h:127:53: error: static assertion failed
  127 | #define PERFETTO_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
      |                                     ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
../../src/trace_processor/core/util/bit_vector.h:90:19: note: in expansion of macro 'PERFETTO_IS_LITTLE_ENDIAN'
   90 |     static_assert(PERFETTO_IS_LITTLE_ENDIAN());
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~~
  • the comparison reduces to '(4321 == 1234)'
  • in expansion of macro 'PERFETTO_IS_LITTLE_ENDIAN'
       90 |     static_assert(PERFETTO_IS_LITTLE_ENDIAN());
          |                   ^~~~~~~~~~~~~~~~~~~~~~~~~
ninja: build stopped: subcommand failed.
error: Cannot build '/nix/store/nx64bq0vlqyd0by858f9k91i444j8092-perfetto-static-s390x-unknown-linux-musl-59.1.drv'.

Cross-compiling for ppc64le works at least, that could be an option.

@miladfarca

Copy link
Copy Markdown
Contributor

I tried cross compiling trace_processor_shell for Linux s390x

As mentioned in this comment only the emitter/tracer was patched on big-endian, we are not currently planning to fix the processor as it's not needed for emitting traces on Node.js or V8.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@aduh95

aduh95 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor Author

I'm testing cross-compiling on GHA, store the result on Cachix, and have Jenkins download it from there; I've opened google/perfetto#8256 to get s390x support upstream, we should likely wait for that to land before progressing (looks like even our CI is not happy with it, so I guess it will require more work).

Never attempts to download it:

  • node-test-linux-linked-withoutssl

Fails to download:

  • node-test-linux-linked-openssl30 (CERTIFICATE_VERIFY_FAILED)
  • node-test-linux-linked-openssl35 (CERTIFICATE_VERIFY_FAILED)

Download but fails to run:

  • node-test-linux-ubuntu2404-x64 (SIGILL)
  • macosx-15-x64 (SIGSEGV)
  • node-test-linux-alpine-latest-x64 (ENOENT)
  • node-test-linux-alpine-last-latest-x64 (ENOENT)
  • all the s390x and ppc64le platforms (SIGSEGV)

Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

sashwinbalaji pushed a commit to google/perfetto that referenced this pull request Oct 26, 2026
In nodejs/node#65794, we're trying to test our
Perfetto integration on several platforms, one of which is s390x
(support was added by #7449) but
the cross-compilation fails when it reaches little-endian assertions.

I've tasked an LLM-agent to make a patch, and here's what it came up
with. I've validated that I was able to cross-compile for s390x.
@miladfarca

miladfarca commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

I need to clear a few questions/assumptions about this PR, specially around big-endian support:

Node.js itself only uses the tracer/emitter correct? It doesn't use the perfetto analyzer.
The only reason the analyzer is being pulled in here is to convert the new perfetto output back to json so current Node.js tests can still run?

I'm also assuming the prebuilt analyzer is being downloaded for x64 and arm64 and compiled for ppc64 and s390x?

I have compiled V8 on s390x native which includes this BE patch with v8_use_perfetto and v8_use_perfetto_json_export set to true and there is one test failing:

out/s390x.release/v8_unittests --random-seed=742941924 --nohard-abort --gtest_filter=PlatformTracingTest.JsonIntegrationTest --gtest_random_seed=742941924 --gtest_print_time=0
...
#
# Fatal error
# Check failed: "\"1\":1e+100" == all_args[i++].
#
#

Meaning the patch is not complete and the analyzer (aka. trace_processor_shell) is still broken on big-endian, it only compiles. This test is only enabled with v8_use_perfetto_json_export set to true and wasn't compiling before the above BE patch, now it does compile but it's failing, meaning json_export function is still broken.

Having said all that, my question is, isn't it better to fix/rewrite the Node.js tests to use the perfetto output directly instead of relying on the analyzer to do the json conversions? This way we avoid dragging this (partially broken) tool in Node.js just for doing a conversion.

@legendecas

legendecas commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Node.js itself only uses the tracer/emitter correct? It doesn't use the perfetto analyzer.
The only reason the analyzer is being pulled in here is to convert the new perfetto output back to json so current Node.js tests can still run?

Yes, Node.js core only uses emitter/producer.

The perfetto trace_processor_shell is only for running tests, converting the binary perfetto output to json.

isn't it better to fix/rewrite the Node.js tests to use the perfetto output directly instead of relying on the analyzer to do the json conversions?

Producing perfetto json output would require a bigger runtime dependencie, like libjsoncpp, protobuf etc, essentially building the analyzer into the runtime. I would prefer not introducing these analyzer dependencies for the core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocked PRs that are blocked by other issues or PRs. build Issues and PRs related to Node.js builds or CI infrastructure. meta Issues and PRs related to the general management of the project. needs-ci PRs that need a full CI run. semver-major PRs that contain breaking changes and should be released in the next major version. trace_events Issues and PRs related to trace events from V8, Node.js core, and user code.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants