Crystal: [RFC] Process.times on Windows

Created on 19 Apr 2020  路  5Comments  路  Source: crystal-lang/crystal

Process.times is not implemented on Windows now. This is a proposal how to implement it.

CPU usage consumed by a process can be got by GetProcessTimes. It is easy to fill Process::Tms#utime and #stime. Just calling GetProcessTimes(GetCurrentProcess(), ....). I want to hear opinions about #cutime and #cstime.

The #cutime and #cstime values come from getrusage() with RUSAGE_CHILDREN on Unix. They include the resources used by not only direct children but also further descendants on Linux. POSIX just says "children of the current process" and doesn't notice whether they include the resources used by further descendants or not. The manpage of FreeBSD and macOS is same with that of POSIX. Does the word "children" in English include descendants in this context?

By the way I came up with two options.

  1. Doesn't support #cutime and #cstime. They are zeros always.
  2. Support resources about direct children, not including further descendants.
    Call GetProcessTimes just before [this line] and add up to a class variable of Crystal::System::Process.

I prefer the former because most users, I guess, won't care about #cutime and #cstime.
In addition the latter is similar to but not same with that on Linux.

windows

Most helpful comment

Let's do the same as Ruby and Python.

All 5 comments

... most users, I guess, won't care about #cutime and #cstime.

Total CPU time printed by BenchMark is sum of utime, stime, cutime and cstime. Is it worth to support cutime and cstime of direct children?

Maybe none of this is worth supporting.

Maybe none of this is worth supporting.

Does it mean "both cutime and cstime are not worth to supporting"? I'm not a native English speaker.

Both ruby and python set zeros to cutime and cstime on Windows. I'm leaning toward to same behaviour with ruby and python.

Let's do the same as Ruby and Python.

Oh wow, I had no idea that Python supported this!

Was this page helpful?
0 / 5 - 0 ratings