Skip to content

v8: add cpu profile APIs - #59429

Closed
theanarkh wants to merge 1 commit into
nodejs:mainfrom
theanarkh:add_cpu_profile_api
Closed

v8: add cpu profile APIs#59429
theanarkh wants to merge 1 commit into
nodejs:mainfrom
theanarkh:add_cpu_profile_api

Conversation

@theanarkh

Copy link
Copy Markdown
Contributor

Add CPU profile APIs.

  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@nodejs-github-botnodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Aug 10, 2025
Comment threadsrc/node_v8.cc Outdated
Comment threadsrc/node_v8.cc Outdated

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.

Suggested change
classJSONOutputStream : publicv8::OutputStream {
classJSONOutputStreamfinal: public v8::OutputStream {

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.

Btw – we may want to use HeapSnapshotStream here? I know it requires a bit more setup, but it integrates nicely with existing stream primitives in Node.js

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I think these are two issues in HeapSnapshotStream:

  1. We should not delete the snapshot(which is created in worker) in main thread.
  2. It will crash when the worker exits.
constworker=require('worker_threads');constw=newworker.Worker("setInterval(() => {}, 100)",{eval: true})w.on('online',async()=>{conststream=awaitw.getHeapSnapshot()stream.on('data',()=>{});// Crashw.terminate();});

Comment threadsrc/env.cc Outdated
Comment threadsrc/env.cc Outdated
Comment threadlib/v8.js Outdated
Comment threadlib/v8.js Outdated
Comment threadlib/v8.js Outdated
Comment threadsrc/node_v8.cc Outdated
Comment threadsrc/node_v8.cc Outdated
Comment threadsrc/node_v8.cc Outdated
Comment threadsrc/node_v8.cc Outdated
@addaleaxaddaleax added semver-minor PRs that contain new features and should be released in the next minor version. v8 module Issues and PRs related to the "v8" subsystem. labels Aug 11, 2025

@szegediszegedi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Advocating for using CpuProfiler::Start and thus eliminating the need for users to invent names for the profiler sessions in order to use the API.

Comment threadlib/v8.js Outdated
Comment threadlib/v8.js Outdated
Comment threadsrc/node_v8.cc Outdated
@theanarkh
theanarkhforce-pushed the add_cpu_profile_api branch 6 times, most recently from f4618c5 to e78d71aCompareSeptember 2, 2025 16:59
@theanarkh
theanarkh marked this pull request as ready for review September 2, 2025 17:01
@theanarkh
theanarkhforce-pushed the add_cpu_profile_api branch 2 times, most recently from 5037a4a to b3c64d0CompareSeptember 2, 2025 17:04
@codecov

codecovBot commented Sep 2, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.15385% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.95%. Comparing base (961554c) to head (1b66417).
⚠️ Report is 51 commits behind head on main.

Files with missing linesPatch %Lines
src/node_v8.cc77.41%2 Missing and 5 partials ⚠️
lib/v8.js94.11%2 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #59429 +/- ##
==========================================
+ Coverage 89.93% 89.95% +0.01% 
==========================================
Files 667 667 Lines 196775 196841 +66 Branches 38409 38422 +13 ==========================================
+ Hits 176977 177069 +92 + Misses 12247 12200 -47 - Partials 7551 7572 +21 
Files with missing linesCoverage Δ
src/node_v8.h40.00% <ø> (ø)
lib/v8.js99.02% <94.11%> (-0.35%)⬇️
src/node_v8.cc79.84% <77.41%> (-0.59%)⬇️

... and 51 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@theanarkhtheanarkh mentioned this pull request Sep 8, 2025
4 tasks
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++Issues and PRs that require attention from people who are familiar with C++.lib / srcIssues and PRs related to general changes in the lib or src directory.needs-ciPRs that need a full CI run.semver-minorPRs that contain new features and should be released in the next minor version.v8 moduleIssues and PRs related to the "v8" subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@theanarkh@szegedi@jasnell@addaleax@nodejs-github-bot