Project

General

Profile

Actions

Feature #8809

closed

Process.clock_getres

Added by akr (Akira Tanaka) over 10 years ago. Updated about 4 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:56780]

Description

How about Process.clock_getres method?

POSIX defines clock_getres function to provide resolution information
of clocks.

I made a pacth to invoke clock_getres function.

Process.clock_getres(Process::CLOCK_MONOTONIC) #=> 1.0e-09
Process.clock_getres(Process::CLOCK_MONOTONIC_COARSE) #=> 0.00400025

The result means that the resolution of CLOCK_MONOTONIC is 1ns and
the resolution of CLOCK_MONOTONIC_COARSE is 4.00025ms.

Process.clock_getres has optional unit argument as Process.clock_gettime.

Process.clock_getres(Process::CLOCK_MONOTONIC, :nanosecond) #=> 1
Process.clock_getres(Process::CLOCK_MONOTONIC_COARSE, :nanosecond) #=> 4000250

It supports emulated clocks as well.

Process.clock_getres(:SUS_GETTIMEOFDAY_BASED_CLOCK_REALTIME) #=> 1.0000000000000002e-06
Process.clock_getres(:SUS_GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID) #=> 1.0000000000000002e-06

The unit argument can be :hertz, which means the reciprocal of the second.

Process.clock_getres(:SUS_GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID, :hertz) #=> 1000000.0

Note that
Process.clock_getres(:POSIX_TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID, :hertz) is the clock ticks per second (CLK_TCK) and
Process.clock_getres(:ISO_C_CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID, :hertz) is CLOCK_PER_SEC.
I wanted to access them easily to investigate emulated clock behaviors on
various OSes.

Any comments?


Files

clock_getres.patch (4.39 KB) clock_getres.patch akr (Akira Tanaka), 08/22/2013 11:33 PM
clock_getres-2.patch (6.06 KB) clock_getres-2.patch akr (Akira Tanaka), 08/24/2013 09:24 AM
clock_getres-3.patch (6 KB) clock_getres-3.patch akr (Akira Tanaka), 08/24/2013 10:41 AM

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #16740: Deprecating and removing the broken Process.clock_getresRejectedEregon (Benoit Daloze)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0