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

core: implement resourceUsage() #1568

Closed
wants to merge 1 commit into from
Closed

core: implement resourceUsage() #1568

wants to merge 1 commit into from

Conversation

r-52
Copy link
Contributor

@r-52 r-52 commented Apr 30, 2015

libuv already provides the uv_getrusage function to get the
resource mesaures for the current process.
This changes implements the new process.resourceUsage() function
to make use of it.

An example output looks like:

{ userCpuTimeUsedSec: 0,
  userCpuTimeUsedMs: 159729,
  systemCpuTimeUsedSec: 0,
  systemCpuTimeUsedMs: 30597,
  maxResidentSetSize: 20426752,
  sharedMemSize: 0,
  integralUnsharedDataSize: 0,
  integralUnsharedStackSize: 0,
  pageReclaims: 3002,
  pageFaults: 2250,
  swaps: 0,
  blockInputOperations: 0,
  blockOutputOperations: 0,
  ipcMessagesSent: 55,
  ipcMessagesReceived: 54,
  signalsReceived: 0,
  voluntaryContextSwitches: 92,
  involuntaryContextSwitches: 374 }

Not supported fields on windows are zero.

resource_usage->Set(env->voluntary_context_switches(),
Number::New(env->isolate(), rusage.ru_nvcsw));
resource_usage->Set(env->involuntary_context_switches(),
Number::New(env->isolate(), rusage.ru_nivcsw));
Copy link
Member

Choose a reason for hiding this comment

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

The indentation of the second argument seems off by one space.

@bnoordhuis
Copy link
Member

LGTM with comments. Maybe this can get one more pair of eyeballs, @iojs/collaborators?


Returns the resource usage measures

Note: Not all resource usage measures are available on Windows. Fields
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you know exactly which fields aren't available on Windows? If so, you could call them out.

libuv already provides the `uv_getrusage` function to get the
resource mesaures for the current process.
This changes implements the new `process.resourceUsage()` function
to make use of it.

An example output looks like:

{ userCpuTimeUsedSec: 0,
  userCpuTimeUsedMs: 159729,
  systemCpuTimeUsedSec: 0,
  systemCpuTimeUsedMs: 30597,
  maxResidentSetSize: 20426752,
  sharedMemSize: 0,
  integralUnsharedDataSize: 0,
  integralUnsharedStackSize: 0,
  pageReclaims: 3002,
  pageFaults: 2250,
  swaps: 0,
  blockInputOperations: 0,
  blockOutputOperations: 0,
  ipcMessagesSent: 55,
  ipcMessagesReceived: 54,
  signalsReceived: 0,
  voluntaryContextSwitches: 92,
  involuntaryContextSwitches: 374 }

Not supported fields on windows are zero.
@r-52
Copy link
Contributor Author

r-52 commented Apr 30, 2015

@bnoordhuis @cjihrig thanks for your response! I removed the whitespace from the second argument.
The doc mentions now the fields, that are filled on windows.

@bnoordhuis
Copy link
Member

LGTM

A question for everyone: do we want to deviate from the UNIX rusage field names? I'd say 'yes' because the UNIX names are pretty cryptic and don't look like idiomatic JS identifiers.

@trevnorris
Copy link
Contributor

@bnoordhuis Using different names sounds appropriate.

@cjihrig
Copy link
Contributor

cjihrig commented Apr 30, 2015

+1 to more JS-like names.

@domenic
Copy link
Contributor

domenic commented May 1, 2015

Can we make the fields not-present on Windows instead? Would be a much better experience.

@trevnorris
Copy link
Contributor

Easy enough. We just need to identify the fields that don't exist on Windows, ifdef them out and update the docs. Anyone know which fields don't work in Windows?

@r-52
Copy link
Contributor Author

r-52 commented May 1, 2015

If the fields aren't present on Windows, would that make the behavior different to e.g os.loadavg? This function will return also zero filled fields on Windows.

@domenic
Copy link
Contributor

domenic commented May 1, 2015

Hmm, that is true. It would be more consistent with process.(get|set)e?(g|u)id, though. Maybe we should fix os.loadavg to not exist on Windows, like those functions do?

@rlidwka
Copy link
Contributor

rlidwka commented May 1, 2015

I'd prefer unix field names with ru_ prefix stripped. For example, isrss instead of integralUnsharedStackSize. Reasons are:

  1. They are shorter.
  2. They are more easily recognizable for people who worked with C.
  3. They are more likely to be the same for different programming languages (I don't know what e.g. perl and python do, but I'd bet they do not use JS identifiers).
  4. Documentation is readily available for them (manual pages + those cryptic nivcsw are google-able)

becauseLongCamelCasedIdentifiersAreUnreadable

If you still want to use those, maybe borrow some identifiers from here (just something I found searching for involuntaryContextSwitches):
http://www.thunderstone.com/site/vortexman/sysinfo.html

At least they are shorter.

@sam-github
Copy link
Contributor

If it uses js-style identifiers, please document the mapping to the underlying getrusage fields, so that its possible to find reference documentation. Should do the same either way for Windows, so its possible to look up more information for Windows, as well.

@r-52
Copy link
Contributor Author

r-52 commented May 1, 2015

@sam-github you mean something like a comment behind the example output:

....
maxResidentSetSize: 20426752, // maxrss
sharedMemSize: 0, // ixrss
integralUnsharedDataSize: 0, // idrss
...

@rlidwka thanks! I thought that the unix names are somehow cryptic. (In case of JS names: take messagesReceived instead of `ipcMessagesReceived``?)

@domenic it's not only ``os.loadavg()-os.cpus()` contains a `nice` field that's always filled with zero on Windows. The question is, should io.js as the runtime "hide" fields that aren't available on the current OS?

@domenic
Copy link
Contributor

domenic commented May 1, 2015

I guess I don't have strong enough feelings to override the precedent set for other os.* things. It seems nicer if they're absent but it's not like I have some program in mind that would benefit from the change.

@monsanto
Copy link
Contributor

monsanto commented May 1, 2015

I would prefer if functions that cannot be meaningfully used do not exist, as opposed to returning garbage.

@mscdex
Copy link
Contributor

mscdex commented May 1, 2015

+1 to keeping the properties on Windows and just setting them to 0. If nothing else it prevents the need to have to branch on process.platform or similar if you're doing running calculations on these fields.

@bnoordhuis
Copy link
Member

I agree with @mscdex.

@jbergstroem
Copy link
Member

how about returning -1 instead of 0? I agree that keeping properties is the way to go.

@r-52
Copy link
Contributor Author

r-52 commented May 2, 2015

@jbergstroem -1 could look like an error code or an error that happened. 0 has the advantage that you could e.g. perform calculations with them and you don't get a negative result for the values.

@silverwind silverwind added the process Issues and PRs related to the process subsystem. label May 4, 2015
@ghost
Copy link

ghost commented May 5, 2015

Copy libuv/libuv#342

@brendanashworth brendanashworth added the semver-minor PRs that contain new features and should be released in the next minor version. label May 13, 2015
@ronkorving
Copy link
Contributor

Agree with @jbergstroem that 0 is a mediocre "not supported" indicator. Why not undefined?
@romankl what good are the calculations on 0 possibly going to do?

@Fishrock123 Fishrock123 added the discuss Issues opened for discussions and feedbacks. label Jul 27, 2015
@trevnorris
Copy link
Contributor

@bnoordhuis think this is cool to land? seems it was on track before some last minute bikeshedding occurred. It LGTM.

@bnoordhuis
Copy link
Member

@@ -0,0 +1,23 @@
var assert = require('assert');
var common = require('../common');
Copy link
Member

Choose a reason for hiding this comment

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

The linter is probably going to complain that this should have 'use strict' at the top and that the imports should be const.

@rvagg
Copy link
Member

rvagg commented Aug 18, 2015

What are the fields that are not supported on Windows? If it's more than just a few of them then I'm -0 on this I think.

@brendanashworth brendanashworth removed the discuss Issues opened for discussions and feedbacks. label Aug 18, 2015
@ghost
Copy link

ghost commented Aug 18, 2015

@rvagg, over 50% fields are missing for windows in libuv, even though there is a Windows98-days helpers library (PDH) provided by win CRT till date for measuring low-level CPU related performance stats etc., which apparently emits all the information required to match Unix implementation (else how would game devs pull off so many projects on windows in the past and current century?). I have no dev experience with it therefore this request is blocking: libuv/libuv#342. Can anyone take a stab? Maybe guys from https://github.com/Microsoft/node get excited to chip in on this one; @jianchun.

@rvagg
Copy link
Member

rvagg commented Aug 18, 2015

over 50% fields are missing for windows

I'm not a fan then, it's going to look second-class, the os.loadavg() precedent is an unfortunate one here that I'm also not a fan of for similar reasons.

@nodejs/platform-windows opinions?

@seishun
Copy link
Contributor

seishun commented Aug 18, 2015

I agree, we shouldn't encourage people to write non-portable code.

@orangemocha
Copy link
Contributor

I have added libuv/libuv#342 to our queue of Windows fixes. Preferably, this PR would wait for that feature to be fully implemented in libuv on all platforms.

If this cannot wait, I would recommend specifying what is supported on which platform in the docs.

Since some of these fields might be platform-specific anyway, I think leaving them undefined where they are not implemented makes more sense than setting them to 0. It makes writing portable code easier.

@jasnell
Copy link
Member

jasnell commented Oct 22, 2015

@orangemocha @rvagg @bnoordhuis ... what do we want to do with this one? Still pending?

@bnoordhuis
Copy link
Member

@jasnell Still pending, I think. libuv/libuv#342 is still open. I don't expect anyone from the libuv team to work on that anytime soon though, it would have to come from outside.

@orangemocha
Copy link
Contributor

@jasnell still planning to work on libuv/libuv#342

@targos targos added the stalled Issues and PRs that are stalled. label Jan 31, 2016
@jasnell jasnell added the blocked PRs that are blocked by other issues or PRs. label Apr 21, 2016
@eljefedelrodeodeljefe
Copy link
Contributor

I could work on the windows part. I guess there won't be windows equivalents for the whole struct. So if we want to go further with it, we should be planning on windows specific docs.

@Fishrock123 Fishrock123 added the libuv Issues and PRs related to the libuv dependency or the uv binding. label May 3, 2016
@Trott
Copy link
Member

Trott commented Jan 18, 2017

libuv/libuv#342 is closed. Should we remove the blocked label from this?

@bnoordhuis bnoordhuis removed the blocked PRs that are blocked by other issues or PRs. label Jan 18, 2017
@bnoordhuis
Copy link
Member

Removed the label. The PR needs a rebase, though.

@Trott Trott mentioned this pull request Feb 22, 2017
4 tasks
@Trott
Copy link
Member

Trott commented Feb 22, 2017

Since the repo that this PR is against is now listed as unknown repository and the original author last commented here nearly 2 years ago, I took the liberty of rebasing, resolving conflicts, updating a few things to reflect the current code base, and opening a PR at #11490. I'm going to close this. Hopefully we can get the new PR landed or closed quickly.

@Trott Trott closed this Feb 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libuv Issues and PRs related to the libuv dependency or the uv binding. process Issues and PRs related to the process subsystem. semver-minor PRs that contain new features and should be released in the next minor version. stalled Issues and PRs that are stalled.
Projects
None yet
Development

Successfully merging this pull request may close these issues.