GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — src: fix v8::CpuProfiler idle sampling by OleksandrChekhovskyi · Pull Request #2324 · nodejs/node

Conversation

@OleksandrChekhovskyi

@OleksandrChekhovskyi OleksandrChekhovskyi commented Aug 7, 2015

Copy link
Copy Markdown

Correctly mark idle wait as "(idle)" instead of "(program)", and take
samples during that time.

This makes profiling with node-inspector (via v8-profiler) actually useful.


Simple test program:

var http = require("http");

http.createServer(function(req, res) {
    res.end("Hello World\n");
}).listen(1337, "127.0.0.1");

console.log("node.js version: " + process.version);
console.log("Server running at http://127.0.0.1:1337/");

Testing was done by starting profiling, waiting few seconds, loading page once in the browser, waiting few more seconds and then stopping profiling.

What profiler showed before the fix (omg, several seconds of CPU time to handle one trivial request?):
io js-2 5 0

After the fix (now actually looks like reality):
io js-2 5 0-fixed

Please cherry-pick this fix to 2.x and 3.x - having working convenient profiling can be really useful.
The fix itself was in fact tested off 2.5.0, since v8-profiler package has not been updated yet for module ABI v45.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
thefourtheye
thefourtheye reviewed Aug 7, 2015
View reviewed changes
Comment thread src/node.cc

@thefourtheye thefourtheye Aug 7, 2015

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

What will happen in Windows?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@OleksandrChekhovskyi OleksandrChekhovskyi Aug 7, 2015

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Probably it will always collect samples during idle time (I have not tested Windows).
Note that the original code above was POSIX-only as well. It is moved here so that it can be conditional on the command line flag '--prof' (so only block SIGPROF if using v8.log-style profiling).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bnoordhuis

bnoordhuis commented Aug 7, 2015

Copy link
Copy Markdown
Member

Can you add a regression test? You can use test/addons/heap-profiler as a template.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@OleksandrChekhovskyi

OleksandrChekhovskyi commented Aug 7, 2015

Copy link
Copy Markdown
Author

What would you exactly test in such a test? The API 'worked', it just returned data that didn't match the reality. It's not obvious how to verify that.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bnoordhuis

bnoordhuis commented Aug 7, 2015

Copy link
Copy Markdown
Member

The v8::CpuProfile contains the raw timeline data, you can get it with v8::CpuProfile::GetSampleTimestamp(). I think that if the test calls setTimeout(function() {}, 100), it should see approximately 100 samples with your patch and zero or almost zero without.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mscdex mscdex added c++ Issues and PRs that require attention from people who are familiar with C++. v8 engine Issues and PRs related to the V8 dependency. labels Aug 7, 2015
@OleksandrChekhovskyi

OleksandrChekhovskyi commented Aug 7, 2015

Copy link
Copy Markdown
Author

Possible indeed. 'Approximately' and 'almost', however, make me nervous.
Are you sure it's worth the trouble?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bnoordhuis

bnoordhuis commented Aug 7, 2015

Copy link
Copy Markdown
Member

A test would be good if you don't want it to regress over time.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@OleksandrChekhovskyi

OleksandrChekhovskyi commented Aug 7, 2015

Copy link
Copy Markdown
Author

Ok, I'll try to make something on Monday.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@OleksandrChekhovskyi
OleksandrChekhovskyi force-pushed the master branch from 7973727 to a9729fd Compare August 10, 2015 11:13
@OleksandrChekhovskyi

OleksandrChekhovskyi commented Aug 10, 2015

Copy link
Copy Markdown
Author

The patch has been updated.
Now includes a test that verifies that samples collected with v8::CpuProfiler are evenly distributed.

In the future it might be possible to make it work with uneven samples. v8::CpuProfiler now reports sample timestamps, and they are supported by current Chrome DevTools, however it'll require updating v8-profiler and node-inspector, and that's much more work. Also since that would be a breaking behavior change, ideally it should only be enabled explicitly by the user.

So let's keep it simple for now, as it enables easy/convenient profiling immediately (assuming the patch is cherry-picked to stable branches).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bnoordhuis
bnoordhuis reviewed Aug 18, 2015
View reviewed changes
Comment thread test/addons/cpu-profiler/binding.cc Outdated

@bnoordhuis bnoordhuis Aug 18, 2015

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

There are a bunch of style errors in this file but once #2427 lands, make cpplint should tell you about them.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@OleksandrChekhovskyi
OleksandrChekhovskyi force-pushed the master branch from a9729fd to 4b690ce Compare August 19, 2015 07:45
@OleksandrChekhovskyi

OleksandrChekhovskyi commented Aug 19, 2015

Copy link
Copy Markdown
Author

Style errors have been fixed, unconditional idle notifier undone, commit message updated.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bnoordhuis

bnoordhuis commented Aug 20, 2015

Copy link
Copy Markdown
Member

LGTM and thanks. Linking to #2428 because I'd like to see that land first.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bnoordhuis

bnoordhuis commented Aug 25, 2015

Copy link
Copy Markdown
Member

CI: https://jenkins-iojs.nodesource.com/job/node-test-pull-request/152/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@OleksandrChekhovskyi

OleksandrChekhovskyi commented Aug 25, 2015

Copy link
Copy Markdown
Author

It looks like the build failed because it failed to fetch the source code from git.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bnoordhuis

bnoordhuis commented Aug 25, 2015

Copy link
Copy Markdown
Member

GH is pretty flaky today. Second try: https://jenkins-iojs.nodesource.com/job/node-test-pull-request/154/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bnoordhuis

bnoordhuis commented Aug 25, 2015

Copy link
Copy Markdown
Member

The freebsd101-64 failure is #2464 but I see the test from this PR failing on the fedora22 buildbot: https://jenkins-iojs.nodesource.com/job/node-test-commit-linux/272/nodes=fedora22/console (grep for 'not ok'.)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@OleksandrChekhovskyi

OleksandrChekhovskyi commented Aug 25, 2015

Copy link
Copy Markdown
Author

Not sure why would it fail. This might just mean that testing timing-related stuff in a unit test is not a good idea.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bnoordhuis

bnoordhuis commented Aug 25, 2015

Copy link
Copy Markdown
Member

V8 has CPU profiler tests that run on a wide range of platforms so it must be possible to write something that isn't timing sensitive.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@OleksandrChekhovskyi
OleksandrChekhovskyi force-pushed the master branch from 4b690ce to 214ca22 Compare August 28, 2015 09:13
Oleksandr Chekhovskyi
src: fix v8::CpuProfiler idle sampling
9ba84d8
Ensure that samples are evenly distributed, which is required for v8::CpuProfiler
users to work correctly (v8-profiler / node-inspector).
@OleksandrChekhovskyi
OleksandrChekhovskyi force-pushed the master branch from 214ca22 to 9ba84d8 Compare August 28, 2015 09:15
@OleksandrChekhovskyi

OleksandrChekhovskyi commented Aug 28, 2015

Copy link
Copy Markdown
Author

I couldn't think of any reliable way to validate this in a unit test, so I have dropped the test in the updated patch.

It needs to check either number of samples, timings between samples, or presence of samples within certain intervals, and neither of these are reliable.

I have checked V8 CPU profiler tests and those only check for specifics only if samples have been manually recorded by the code in the test.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@OleksandrChekhovskyi

OleksandrChekhovskyi commented Sep 1, 2015

Copy link
Copy Markdown
Author

Changes to v8-profiler have been upstreamed now (node-inspector/v8-profiler#73), so now only this patch is missing from the 'working profiler' picture.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rvagg
rvagg force-pushed the master branch from 11c25c2 to ba02bd0 Compare September 6, 2015 11:55
@bnoordhuis bnoordhuis mentioned this pull request Sep 12, 2015
src: reduce cpu profiler overhead nodejs/node-v0.x-archive#8791
Closed
bnoordhuis pushed a commit that referenced this pull request Sep 12, 2015
Oleksandr Chekhovskyi @bnoordhuis
src: fix v8::CpuProfiler idle sampling
8e14135
Ensure that samples are evenly distributed, which is required for
v8::CpuProfiler users to work correctly (v8-profiler / node-inspector).

PR-URL: #2324
Reviewed-By: Ben Noordhuis <[email protected]>
@bnoordhuis

bnoordhuis commented Sep 12, 2015

Copy link
Copy Markdown
Member

Thanks Oleksandr, landed in 8e14135.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bnoordhuis bnoordhuis closed this Sep 12, 2015
@Fishrock123 Fishrock123 mentioned this pull request Sep 13, 2015
Release proposal: v4.1.0 #2844
Closed
3 of 7 tasks
Fishrock123 pushed a commit that referenced this pull request Sep 15, 2015
Oleksandr Chekhovskyi @Fishrock123
src: fix v8::CpuProfiler idle sampling
b0df227
Ensure that samples are evenly distributed, which is required for
v8::CpuProfiler users to work correctly (v8-profiler / node-inspector).

PR-URL: #2324
Reviewed-By: Ben Noordhuis <[email protected]>
@rvagg rvagg mentioned this pull request Sep 15, 2015
Release proposal: v3.3.1 #2698
Merged
Fishrock123 added a commit to Fishrock123/node that referenced this pull request Sep 17, 2015
@Fishrock123
2015-09-17, Version 4.1.0 (Stable) Release
b4ec2c2
Notable changes:

* buffer:
  - Buffers are now created in JavaScript, rather than C++. This increases the speed of buffer creation (Trevor Norris) nodejs#2866.
  - `Buffer#slice()` now uses `Uint8Array#subarray()` internally, increasing `slice()` performance (Karl Skomski) nodejs#2777.
* fs:
  - `fs.utimes()` now properly converts numeric strings, `NaN`, and `Infinity` (Yazhong Liu) nodejs#2387.
  - `fs.WriteStream` now implements `_writev`, allowing for super-fast bulk writes (Ron Korving) nodejs#2167.
* http: Fixed an issue with certain `write()` sizes causing errors when using `http.request()` (Fedor Indutny) nodejs#2824.
* npm: Upgrade to version 2.14.3, see https://github.com/npm/npm/releases/tag/v2.14.3 for more details (Kat Marchán) nodejs#2822.
* src: V8 cpu profiling no longer erroneously shows idle time (Oleksandr Chekhovskyi) nodejs#2324.
* v8: Lateral upgrade to 4.5.103.33 from 4.5.103.30, contains minor fixes (Ali Ijaz Sheikh) nodejs#2870.
  - This fixes a previously known bug where some computed object shorthand properties did not work correctly (nodejs#2507).

Refs: nodejs#2844
PR-URL: nodejs#2889
Fishrock123 added a commit that referenced this pull request Sep 17, 2015
@Fishrock123 @rvagg
2015-09-17, Version 4.1.0 (Stable) Release
e4f2952
Notable changes:

* buffer:
  - Buffers are now created in JavaScript, rather than C++. This increases the speed of buffer creation (Trevor Norris) #2866.
  - `Buffer#slice()` now uses `Uint8Array#subarray()` internally, increasing `slice()` performance (Karl Skomski) #2777.
* fs:
  - `fs.utimes()` now properly converts numeric strings, `NaN`, and `Infinity` (Yazhong Liu) #2387.
  - `fs.WriteStream` now implements `_writev`, allowing for super-fast bulk writes (Ron Korving) #2167.
* http: Fixed an issue with certain `write()` sizes causing errors when using `http.request()` (Fedor Indutny) #2824.
* npm: Upgrade to version 2.14.3, see https://github.com/npm/npm/releases/tag/v2.14.3 for more details (Kat Marchán) #2822.
* src: V8 cpu profiling no longer erroneously shows idle time (Oleksandr Chekhovskyi) #2324.
* v8: Lateral upgrade to 4.5.103.33 from 4.5.103.30, contains minor fixes (Ali Ijaz Sheikh) #2870.
  - This fixes a previously known bug where some computed object shorthand properties did not work correctly (#2507).

Refs: #2844
PR-URL: #2889
@rvagg rvagg mentioned this pull request Sep 22, 2015
Release proposal: v4.1.1 #2995
Merged
@Hackatosh Hackatosh mentioned this pull request Oct 29, 2026
src: keep idle time when poll is interrupted libuv/libuv#5325
Open
@Hackatosh Hackatosh mentioned this pull request Nov 16, 2026
Using Datadog PProf mess up Event Loop Utilization metrics / Event Loop Idle Time metrics DataDog/pprof-nodejs#433
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. v8 engine Issues and PRs related to the V8 dependency.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@OleksandrChekhovskyi @bnoordhuis @thefourtheye @mscdex
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.