Skip to content

diagnostics_channel: add USDT probes - #62118

Draft
bengl wants to merge 3 commits into
nodejs:mainfrom
bengl:bengl/usdt-dc
Draft

diagnostics_channel: add USDT probes#62118
bengl wants to merge 3 commits into
nodejs:mainfrom
bengl:bengl/usdt-dc

Conversation

@bengl

@bengl bengl commented Mar 5, 2026

Copy link
Copy Markdown
Member

Adds USDT probes that are fired for every diagnostics_channel publish.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/gyp

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. labels Mar 5, 2026
Comment thread doc/api/diagnostics_channel.md Outdated

#### Platform support

At `./configure` time, Node.js checks for a working `dtrace` tool and

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have removed dtrace support long time ago. Wouldn't it require us to include a new suite for testing it on that environment?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what our build setup looks like now, but yes, everything that was required for the previous incarnation of probes in Node.js would likely be required again with this PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we tested the dtrace stuff previously. I think when it was removed it had be broken for a while (or maybe that was one of the other non-tested removed features).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a possible path forward here where headers are pre-generated and added to git (much like we do for other cases of generated headers, in dependencies for example), and then a userland, self-contained test (at least on linux) checks for the placement and activation of the probe.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I've made some changes (many months later..)

Linux is now default-on with no dtrace build dependency. src/node_provider_linux.h is committed.
It can be regenerated via tools/usdt/generate_headers.py and a --check drift job runs in CI against it.
Default ./configure enables USDT whenever <sys/sdt.h> is present (systemtap-sdt-dev / systemtap-sdt-devel is the only build requirement on Linux).

macOS is opt-in via ./configure --with-dtrace (which at build-time calls dtrace -h -xnolibs).
--without-dtrace still disables everything.

New test-usdt CI job in test-linux.yml:

  • default: end-to-end bpftrace test as root (verifies the probe fires with the channel name) plus the committed-header drift check
  • --without-dtrace: pins the no-op tier

Bench (aarch64 VM, benchmark/diagnostics_channel/publish.js, subscribers=1, avg of 2): default ~282M ops/s vs --without-dtrace ~314M ops/s — ~10% on this microbench.

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

This pull request has been marked as stale due to 90 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.

@github-actions github-actions Bot added the stale Issues and PRs marked stale due to inactivity and scheduled for automatic closure. label Aug 3, 2026
bengl added a commit to bengl/node that referenced this pull request Sep 9, 2026
Implements the approach from the nodejs#62118 review discussion to remove
the build-time 'dtrace' dependency on Linux:

* Commit the SystemTap-generated probe header
  (src/node_provider_linux.h, regenerate with
  tools/usdt/generate_headers.py).  USDT support is now on by
  default on Linux whenever <sys/sdt.h> is available
  (systemtap-sdt-dev on Debian/Ubuntu, systemtap-sdt-devel on
  Fedora/RHEL) and never needs a 'dtrace' tool at build time.  A
  committed-header drift check runs in CI.
* Make native DTrace opt-in on macOS via the new
  ./configure --with-dtrace; FreeBSD/illumos remain unsupported
  pending a 'dtrace -G' link step.  --without-dtrace still disables
  probes everywhere.  The always-on <sys/sdt.h> fallback tier is
  gone.
* Add a path-gated test-usdt job to the Linux CI workflow with a
  default leg that runs the end-to-end bpftrace probe test as
  root, and a --without-dtrace leg that pins the no-op tier.

The generated header is excluded from cpplint like
src/node_root_certs.h.
Adds USDT probes that are fired for every diagnostics_channel publish.

Signed-off-by: Bryan English <bryan@bryanenglish.com>
Implements the approach from the nodejs#62118 review discussion to remove
the build-time 'dtrace' dependency on Linux:

* Commit the SystemTap-generated probe header
  (src/node_provider_linux.h, regenerate with
  tools/usdt/generate_headers.py).  USDT support is now on by
  default on Linux whenever <sys/sdt.h> is available
  (systemtap-sdt-dev on Debian/Ubuntu, systemtap-sdt-devel on
  Fedora/RHEL) and never needs a 'dtrace' tool at build time.  A
  committed-header drift check runs in CI.
* Make native DTrace opt-in on macOS via the new
  ./configure --with-dtrace; FreeBSD/illumos remain unsupported
  pending a 'dtrace -G' link step.  --without-dtrace still disables
  probes everywhere.  The always-on <sys/sdt.h> fallback tier is
  gone.
* Add a path-gated test-usdt job to the Linux CI workflow with a
  default leg that runs the end-to-end bpftrace probe test as
  root, and a --without-dtrace leg that pins the no-op tier.

The generated header is excluded from cpplint like
src/node_root_certs.h.

Signed-off-by: Bryan English <bryan@bryanenglish.com>
The publish() hot path captured the probe semaphore Uint16Array
view at module load.  This module is baked into the startup
snapshot, and the view's native backing store cannot be serialized:
the captured view is detached when the snapshot is deserialized, so
publish() never called emitPublishProbe() in snapshot builds and
the dc__publish probe never fired for JavaScript publishes even
with a tracer attached.  Caught by the new bpftrace CI job.

Resolve the view lazily from the binding (once per process; 'null'
marks a USDT-less build) and add positive-path coverage to
test-diagnostics-channel-usdt.js: force the semaphore and verify
that publish() calls emitPublishProbe() for string-named channels,
never for symbol-named ones, and not when the semaphore is 0.

Signed-off-by: Bryan English <bryan@bryanenglish.com>
@github-actions github-actions Bot removed the stale Issues and PRs marked stale due to inactivity and scheduled for automatic closure. label Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants