Project

General

Profile

Actions

Feature #8809

closed

Process.clock_getres

Added by akr (Akira Tanaka) over 11 years ago. Updated over 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

Updated by david_macmahon (David MacMahon) over 11 years ago

On Aug 22, 2013, at 7:33 AM, akr (Akira Tanaka) wrote:

I made a pacth to invoke clock_getres function.

Thanks for making a patch! It makes the discussion much less abstract (more real?). I think I will try to follow your example in the future.

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.

Did you consider having these methods return Rational rather than Float?

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

How would you feel about supporting :ns and :hz as equivalents for :nanosecond and :hertz?

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.

Those are some long symbols! Are these intended only for experimental/investigative use?

Any comments?

I appreciate having access to POSIX functionality, so I'm all for this idea!

Thanks,
Dave

Updated by akr (Akira Tanaka) over 11 years ago

2013/8/23 David MacMahon :

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.

Did you consider having these methods return Rational rather than Float?

Process.clock_getres can return rational if it supports
:rational_second as a unit.

The current default of unit is :float_second and
I think float is good enough.

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

How would you feel about supporting :ns and :hz as equivalents for :nanosecond and :hertz?

It is difficult to support :microsecond in that style
because the SI prefix, Greek m, is not representable in ASCII.

Someone may argue :hz should be :Hz.

I feel :float_s is bit curious.

So it is difficult to adopt :ns style as canonical style of unit.

I think several aliases are possible but
I'd like to concentrate to main feature.
The discussion for what aliases should be added or not can be diverge.

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.

Those are some long symbols! Are these intended only for experimental/investigative use?

I choose the long symbols that is longer than Process::CLOCK_PROCESS_CPUTIME_ID.
Basically users should use Process::CLOCK_PROCESS_CPUTIME_ID if no reason.

Tanaka Akira

Updated by david_macmahon (David MacMahon) over 11 years ago

On Aug 22, 2013, at 3:37 PM, Tanaka Akira wrote:

Process.clock_getres can return rational if it supports
:rational_second as a unit.

The current default of unit is :float_second and
I think float is good enough.

Agreed. Plus, if someone really wants, they can request nanosecond precision, which is all that clock_getres supports (at least on Linux).

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

How would you feel about supporting :ns and :hz as equivalents for :nanosecond and :hertz?

It is difficult to support :microsecond in that style
because the SI prefix, Greek m, is not representable in ASCII.

I know it's not SI, but I often use ASCII "u" for Greek m ("µ"), so :microsecond would be aliased by :us.

Someone may argue :hz should be :Hz.

No doubt! :-)

I feel :float_s is bit curious.

How about separating the type and the resolution into two different parameters?

 Process.clock_getres(Process::CLOCK_MONOTONIC, :float, :second)

...or...

 Process.clock_getres(Process::CLOCK_MONOTONIC, Float, :second)

So it is difficult to adopt :ns style as canonical style of unit.

I think several aliases are possible but
I'd like to concentrate to main feature.
The discussion for what aliases should be added or not can be diverge.

Agreed. I think the main feature is great!

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.

Those are some long symbols! Are these intended only for experimental/investigative use?

I choose the long symbols that is longer than Process::CLOCK_PROCESS_CPUTIME_ID.
Basically users should use Process::CLOCK_PROCESS_CPUTIME_ID if no reason.

Sounds good.

Dave

Updated by akr (Akira Tanaka) over 11 years ago

david_macmahon (David MacMahon) wrote:

I know it's not SI, but I often use ASCII "u" for Greek m ("µ"), so :microsecond would be aliased by :us.

It may be possible.

I found ISO 2955.
ISO 2955: Information processing - Representation units in Systems with limited Character sets

I feel :float_s is bit curious.

How about separating the type and the resolution into two different parameters?

 Process.clock_getres(Process::CLOCK_MONOTONIC, :float, :second)

...or...

 Process.clock_getres(Process::CLOCK_MONOTONIC, Float, :second)

I think most useful combinations are follows.

  • float second
  • integer nanosecond (clock_gettime/clock_getres native format)

The current design makes us possible to specify
former as no unit argument and
later as :nanosecond.

Your design force us longer description for integer nanosecond.

Updated by akr (Akira Tanaka) over 11 years ago

I updated the patch again.

Actions #7

Updated by akr (Akira Tanaka) over 11 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r42744.
Akira, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • process.c (rb_clock_getres): New method.
    (timetick2dblnum_reciprocal): New function.

  • configure.in: Check clock_getres.

[ruby-core:56780] [Feature #8809] accepted at
DevelopersMeeting20130831Japan
https://bugs.ruby-lang.org/projects/ruby/wiki/DevelopersMeeting20130831Japan

Actions #8

Updated by Eregon (Benoit Daloze) over 4 years ago

  • Related to Bug #16740: Deprecating and removing the broken Process.clock_getres added

Updated by Eregon (Benoit Daloze) over 4 years ago

In #16740 I propose to remove this API because it almost always returns incorrect and useless values.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0