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

Is it possible to get cumulative process execution time (utime + stime)? #1061

Open
cederberg opened this issue Sep 9, 2023 · 3 comments
Open

Comments

@cederberg
Copy link

I cannot find any way to get the execution time for a process in the current API. Had a look in the source code, and it seems the corresponding values are actually fetched for some platforms, but ignored (or not made available).

As far as I know, the proper way to fetch these values are:

  • Linux — Returned by getrusage, but only for the currently running process. AFAIK, the only way to fetch the values for any process is to parse /proc/<pid>/stat, but I might be mistaken there.
  • Mac — Seems to already be fetched by proc_pidinfo into a libc::proc_taskinfo struct which is used to calculate the instant CPU usage.
  • Windows — Returned by GetProcessTimes in the lpKernelTime and lpUserTime fields.
  • FreeBSD — Couldn't find any obvious API, perhaps same story as for Linux?

It would be great if these values were also available, as they make it possible to detect excessive CPU usage "after the fact".

@GuillaumeGomez
Copy link
Owner

Is #1044 what you're looking for?

@cederberg
Copy link
Author

Interesting… I had missed this one. It is very similar, but I don’t think the API should return accumulated CPU use as a percentage. It is easy enough to calculate a percentage from CPU-seconds, but the inverse loses a lot of precision.

@GuillaumeGomez
Copy link
Owner

What do you think about this @bruceg? Is it possible for your feature to return both % and numbers?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants