public static IRubyObject times(ThreadContext context, IRubyObject recv, Block unusedBlock) {
return times(context.runtime);
}
public static IRubyObject times(Ruby runtime) {
Times tms = runtime.getPosix().times();
double utime = 0.0d, stime = 0.0d, cutime = 0.0d, cstime = 0.0d;
if (tms == null) {
ThreadMXBean bean = ManagementFactory.getThreadMXBean();
if(bean.isCurrentThreadCpuTimeSupported()) {
cutime = utime = bean.getCurrentThreadUserTime();
cstime = stime = bean.getCurrentThreadCpuTime() - bean.getCurrentThreadUserTime();
}
} else {
utime = (double)tms.utime();
stime = (double)tms.stime();
cutime = (double)tms.cutime();
cstime = (double)tms.cstime();
}
long hz = runtime.getPosix().sysconf(Sysconf._SC_CLK_TCK);
if (hz == -1) {
hz = 60; //https://github.com/ruby/ruby/blob/trunk/process.c#L6616