Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: implement --cpu-prof[-path] #27147

Closed
wants to merge 3 commits into from
Closed

Conversation

joyeecheung
Copy link
Member

This patch introduces a CLI flag --cpu-prof that starts the V8
CPU profiler on start up, and ends the profiler then writes the
CPU profile before the Node.js instance (on the main thread or
the worker thread) exits. By default the profile is written to
${cwd}/CPU.${yyyymmdd}.${hhmmss}.${pid}.${tid}.${seq}.cpuprofile.
The patch also introduces a --cpu-prof-path flag for the user
to specify the path the profile will be written to.

Fixes: #26878

Checklist
  • 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

This patch introduces a CLI flag --cpu-prof that starts the V8
CPU profiler on start up, and ends the profiler then writes the
CPU profile before the Node.js instance (on the main thread or
the worker thread) exits. By default the profile is written to
`${cwd}/CPU.${yyyymmdd}.${hhmmss}.${pid}.${tid}.${seq}.cpuprofile`.
The patch also introduces a --cpu-prof-path flag for the user
to specify the path the profile will be written to.

Fixes: nodejs#26878
@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot nodejs-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. labels Apr 9, 2019
@nodejs-github-bot

This comment has been minimized.

@mscdex
Copy link
Contributor

mscdex commented Apr 9, 2019

I don't see where the filename is being formatted as described (like it is for the coverage reports)?

@nodejs-github-bot

This comment has been minimized.

// TODO(joyeecheung): fallback to exec path / argv[0]
CHECK_EQ(err, 0);
CHECK_GT(size, 0);
DiagnosticFilename filename(env, "CPU", "cpuprofile");
Copy link
Member Author

@joyeecheung joyeecheung Apr 9, 2019

Choose a reason for hiding this comment

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

@mscdex This is where the file name is formatted.

Pending #27142 to be an exact match to the format described in the doc even for the first file generated.

@nodejs-github-bot

This comment has been minimized.

src/inspector_profiler.cc Show resolved Hide resolved
src/inspector_profiler.cc Outdated Show resolved Hide resolved
src/inspector_profiler.cc Outdated Show resolved Hide resolved
@joyeecheung joyeecheung added semver-minor PRs that contain new features and should be released in the next minor version. review wanted PRs that need reviews. labels Apr 10, 2019
@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

doc/api/cli.md Outdated Show resolved Hide resolved
@nodejs-github-bot
Copy link
Collaborator

@joyeecheung joyeecheung added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Apr 17, 2019
@joyeecheung
Copy link
Member Author

If there are no more questions I am going to land this on Friday.

@joyeecheung joyeecheung removed the review wanted PRs that need reviews. label Apr 19, 2019
@joyeecheung
Copy link
Member Author

Landed in e0e3084

@joyeecheung joyeecheung removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Apr 19, 2019
joyeecheung added a commit that referenced this pull request Apr 19, 2019
This patch introduces a CLI flag --cpu-prof that starts the V8
CPU profiler on start up, and ends the profiler then writes the
CPU profile before the Node.js instance (on the main thread or
the worker thread) exits. By default the profile is written to
`${cwd}/CPU.${yyyymmdd}.${hhmmss}.${pid}.${tid}.${seq}.cpuprofile`.
The patch also introduces a --cpu-prof-path flag for the user
to specify the path the profile will be written to.

Refs: #26878
PR-URL: #27147
Reviewed-By: Anna Henningsen <[email protected]>
@davidmarkclements
Copy link
Member

we've added support for this in 0x https://github.com/davidmarkclements/0x#--visualize-cpu-profile
🙌
flamegraph

Sign up for free to 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 / src Issues and PRs related to general changes in the lib or src directory. semver-minor PRs that contain new features and should be released in the next minor version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFC: add a flag similar to --prof, but based on v8 CPU profiler
7 participants