-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
initial stab at process.cpuUsage() #5565
Conversation
Local<ArrayBuffer> ab = args[0].As<Uint32Array>()->Buffer(); | ||
uint32_t* fields = static_cast<uint32_t*>(ab->GetContents().Data()); | ||
|
||
// results passed as split values, reassembed in JS |
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.
s/reassembed/reassembled/
Should get at least a minimal test that confirms the object returned by |
absolutely @Trott Figured I'd do the minimal work to see if there's even interest in this, if the approach is generally correct, etc. The most basic test is to ensure that subsequent values are monotonically increasing, or the same. Would be nice to have one that slept for a 100 ms or so, and then made sure the old / new values were within some range of reasonable-ness, but I fear could easily become flaky. I will also peek at libuv's tests for this. BTW, purty sure this my first Node.js PR! |
I really like the idea, but should we be adding this onto |
Maybe put it to |
The |
// to access ru_utime (user CPU time used) and ru_stime (system CPU time used), | ||
// which are uv_timeval_t structs (long tv_sec, long tv_usec) as tuples | ||
// similar to process.hrtime() values. Only it's seconds/microseconds instead | ||
// of hrtime()'s seconds/nanoseconds. |
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.
To avoid confusion in user land (ie: to maintain a level of consistency), would it make sense to turn them into nanoseconds?
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.
Have to admit, I'm a bit torn on this:
- on one hand,
rusage()
returns seconds / microseconds, and so I'd kinda like to match that - on the other hand,
process.hrtime()
returns [seconds, nanoseconds], so would be nice to be consistent
I'm kinda leaning towards your suggestion, returning [seconds, nanoseconds], especially since folks may be using both hrtime()
and cpuUsage()
together, to get a "cpu usage %" type value.
If we want to do that, then I think we'd just doc that the resolution is currently at the microsecond level, but the value returned is nanoseconds.
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.
If we align more with hrtime()
, perhaps it also makes sense to provide a "diff" function, like hrtime()
, where if you pass a previous result of cpuUsage()
into the function, it will return a "diff" of the times, instead of the current time. For one of the primary use cases I'm considering, I'd be wanting a diff anyway, so this cuts down a little bit on the amount of code I'd be writing.
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.
That's interesting. Would love to see some feedback from others on this.
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.
generally +1. I'd favor nanoseconds for consistency also. Also +1 on the diffing. Would be nicely consistent to vanilla js also.
Just a quick thought: Maybe it's worth taking this even further, whether let p = process.cpuUsage(); p.diff(); p.diff()
might be a thing.
Needs some form of test case but generally LGTM |
@pmuellr Could you go over the checklist in the OP? Thanks! :D |
@Fishrock123 sure; let me refresh the code given the changes mentioned here (still in |
PR-URL: nodejs#5628 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rod Vagg <rod@vagg.org> Reviewed-By: James M Snell <jasnell@gmail.com>
Avoid putting github templates in the source tarballs. PR-URL: nodejs#5612 Reviewed-By: Rod Vagg <rod@vagg.org> Reviewed-By: Rich Trott <rtrott@gmail.com>
PR-URL: nodejs#5622 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
Fixes: nodejs#5322 PR-URL: nodejs#5641 Reviewed-By: Robert Lindstädt <robert.lindstaedt@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Roman Reiss <me@silverwind.io>
Instead of leaking the arguments object by passing it as an argument to a function, copy it's contents to a new array, then pass the array. This allows V8 to optimize the function that contains this code, improving performance. PR-URL: nodejs#4361 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
We recently sandboxed the release CI jobs to their own Jenkins instance This commit updates the links found in `doc/releases.md` to point people in the right direction. PR-URL: nodejs#5632 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Johan Bergström <bugs@bergstroem.nu> Reviewed-By: James M Snell <jasnell@gmail.com>
Invoke MSBuild specifying the target platform as generated by Gyp. Reviewed-By: James M Snell <jasnell@gmail.com> PR-URL: nodejs#5627
PR-URL: nodejs#5662 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
PR-URL: nodejs#5665 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com>
Add benjamingr to collaborator list. Related nodejs#5064 PR-URL: nodejs#5664 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com>
PR-URL: nodejs#5666 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Glen Keane <glenkeane.94@gmail.com>
PR-URL: nodejs#5668 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com>
PR-URL: nodejs#5663 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Jeremy Whitlock <jwhitlock@apache.org>
PR-URL: nodejs#5667 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit adds tests for several known issues. Refs: nodejs#1901 Refs: nodejs#728 Refs: nodejs#4778 Refs: nodejs#947 Refs: nodejs#2734 PR-URL: nodejs#5653 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Reintroduces an intentional typo in a process doc example. Fixes: nodejs#5644 PR-URL: nodejs#5654 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
decipher.setAuthPadding canged to decipher.setAutoPadding PR-URL: nodejs#6041 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Roman Klauke <romaaan.git@gmail.com>
This allows third-party tools to check whether or not a handle that can be unreferenced is unreferenced at a particular time. Notably, this should be helpful for inspection via AsyncWrap. Also, this is useful even to node's internals, particularly timers. Refs: nodejs#5828 Refs: nodejs#5827 PR-URL: nodejs#5834 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
PR-URL: nodejs#6076 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Roman Klauke <romaaan.git@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
* due to: openssl bump in 1f43478 PR-URL: nodejs#6065 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
As requested in nodejs#5221 Original commit message: fix debug command processor wrt restart frame. R=jkummerow@chromium.org BUG=v8:4757 LOG=N Review URL: https://codereview.chromium.org/1700693002 Cr-Commit-Position: refs/heads/master@{nodejs#33983} PR-URL: nodejs#6086 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
* use common.mustCall() to verify all tests have run * eliminate unneeded removeTestFile() * eliminate unneeded var leaking into global scope * var -> const * remove instance of let PR-URL: nodejs#6050 Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: nodejs#6108 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
ParseArrayIndex() was requesting a Uint32Value(), but assigning it to an in32_t. This caused slight differences in error message reported in edge cases of argument parsing. Fixed by getting the IntegerValue() before checking if the value is < 0. Added test of API that was affected. PR-URL: nodejs#6084 Reviewed-By: James M Snell <jasnell@gmail.com>
Adds a new topic that provides an overview of the event loop, timers, and `process.nextTick()` that is based upon a NodeSource "Need to Node" presentation hosted by @trevnorris: Event Scheduling and the Node.js Event Loop (https://nodesource.com/resources). PR-URL: nodejs#4936 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Calvin W. Metcalf <calvin.metcalf@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
There is some unnecessary logic in repl.js. Remove it. PR-URL: nodejs#6071 Reviewed-By: James M Snell <jasnell@gmail.com>
A win32-only test was verifying that path.win32._makeLong('C:') would return the current working directory. This would only work if current working directory was also on the C: device. Fix is to grab the device letter for current working directory, and pass that to _makeLong(). PR-URL: nodejs#6067 Reviewed-By: Trott - Rich Trott <rtrott@gmail.com> Reviewed-By: Joao Reis <reis@janeasystems.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Rewriting npm shebang in install.py violates user expectations among other things. The shebang in npm.js is kept as #!/usr/bin/env node. Fixes: nodejs#6095 PR-URL: nodejs#6098 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Fixes: nodejs#6080 PR-URL: nodejs#6124 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: James M Snell <jasnell@gmail.com>
The only test with modifications is `test-stdin-child-proc` that was passing when it should not because the exit code of the child process was not being checked. PR-URL: nodejs#6087 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Johan Bergström <bugs@bergstroem.nu> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Claudio Rodriguez <cjrodr@yahoo.com>
This change was to add upon the algorithm description of path.format by adding examples for unix systems that clarified behavior in various scenarios. PR-URL: nodejs#5838 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Roman Klauke <romaaan.git@gmail.com>
Adds additional `targetStart`, `targetEnd`, `sourceStart, and `sourceEnd` arguments to `Buffer.prototype.compare` to allow comparison of sub-ranges of two Buffers without requiring Buffer.prototype.slice() Fixes: nodejs#521 PR-URL: nodejs#5880 Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Introduced in commit 7d8882b, "handle_wrap: expose an `isRefed()` check to JS". PR-URL: nodejs#6129 Reviewed-By: Evan Lucas <evanlucas@me.com>
Fixes an issue that prevented scrolling from going past large code blocks on iOS devices. Also fixes a few minor styling issues that came up in the discussion. Fixes: nodejs#5861 PR-URL: nodejs#5878 Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Robert Lindstädt <robert.lindstaedt@gmail.com>
Doc tool produces incomplete json when it meets unordered lists that directly following a heading. Add a default case to processList function to handle the lists. PR-URL: nodejs#5966 Fixes: nodejs#1545 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Robert Lindstädt <robert.lindstaedt@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
Current tools/doc/json.js only supports one bracket style for optional params methodName(param0[,param1],param2). Add support to other styles such as methodName(param0,[param1,]param2) or methodName(param0[,param1,param2]) or methodName(param0[,param1[,param2]]). PR-URL: nodejs#5977 Fixes: nodejs#5976 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Robert Lindstädt <robert.lindstaedt@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
This commit refines the documentation around child.kill(), where kill attempts against shells will lead to unexpected results. Namely, on linux the child process of a child process will not terminate, when its parent gets terminated. This is different across the the platforms. PR-URL: nodejs#2098 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Closes: nodejs#2098
PR-URL: nodejs#6132 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: thefourtheye <thechargingvolcano@gmail.com>
PR-URL: nodejs#6132 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: thefourtheye <thechargingvolcano@gmail.com>
Clarify caveats on `maxBuffer` with regards to Unicode output. Refs: nodejs#1901 PR-URL: nodejs#6030 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Currently we include instructions on how to check the sha of a downloaded tar-ball, but do not include instruction on how to get the `SHA256.txt` file. This has led to confusion with people thinking that the SHA256.txt is included in that tarball. This commit includes instructions on how to use curl to download the `SHA256.txt` prior to the instructions on how to verify the sha. Refs: nodejs/help#113 Refs: nodejs/help#137 PR-URL: nodejs#6120 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2aa26df
to
19c6a84
Compare
My git foo is weak. The rebases I've done on my clone/fork look ok, but in the PR, they're pulling in stuff from the old branch I started on (some 5.x branch, which was incorrect, shouda been master from the start). So, giving up on this branch / PR. I've got a clean branch / PR here as a replacement: #6157 |
Pull Request check-list
Please make sure to review and check all of these items:
make -j8 test
(UNIX) orvcbuild test nosign
(Windows) pass withthis change (including linting)?
test (or a benchmark) included?
existing APIs, or introduces new ones)?
NOTE: these things are not required to open a PR and can be done
afterwards / while the PR is open.
Affected core subsystem(s)
process
Description of change
Adds the function
cpuUsage()
to the globalprocess
object. Proposed doc is in the PR, and immediate below:process.cpuUsage()
Returns the user and system cpu time usage of the current process, in an object with properties
user
andsystem
, whose values are arrays of integers as[seconds, microseconds]
tuples. These values measure time spent in user and system code respectively, and may end up being greater than actual elapsed time if multiple cpu cores are performing work for this process.