* process.c (rb_clock_gettime): CLOCK_PROCESS_CPUTIME_ID emulation
using getrusage is implemented. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42640 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
873dd9bc45
commit
167419848f
@ -1,3 +1,8 @@
|
|||||||
|
Wed Aug 21 19:17:46 2013 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* process.c (rb_clock_gettime): CLOCK_PROCESS_CPUTIME_ID emulation
|
||||||
|
using getrusage is implemented.
|
||||||
|
|
||||||
Wed Aug 21 17:34:27 2013 Tanaka Akira <akr@fsij.org>
|
Wed Aug 21 17:34:27 2013 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* gc.c (getrusage_time): Fallback clock_gettime to getrusage when
|
* gc.c (getrusage_time): Fallback clock_gettime to getrusage when
|
||||||
|
33
process.c
33
process.c
@ -6687,14 +6687,21 @@ rb_proc_times(VALUE obj)
|
|||||||
* For example, Process::CLOCK_REALTIME is defined as
|
* For example, Process::CLOCK_REALTIME is defined as
|
||||||
* +:POSIX_GETTIMEOFDAY_CLOCK_REALTIME+ when clock_gettime() is not available.
|
* +:POSIX_GETTIMEOFDAY_CLOCK_REALTIME+ when clock_gettime() is not available.
|
||||||
*
|
*
|
||||||
* Emulations for +:CLOCK_REALTIME+:
|
* Emulations for +CLOCK_REALTIME+:
|
||||||
* [:POSIX_GETTIMEOFDAY_CLOCK_REALTIME] Use gettimeofday(). The resolution is 1 micro second.
|
* [:POSIX_GETTIMEOFDAY_CLOCK_REALTIME] Use gettimeofday(). The resolution is 1 micro second.
|
||||||
* [:ISO_C_TIME_CLOCK_REALTIME] Use time(). The resolution is 1 second.
|
* [:ISO_C_TIME_CLOCK_REALTIME] Use time(). The resolution is 1 second.
|
||||||
*
|
*
|
||||||
* Emulations for +:CLOCK_MONOTONIC+:
|
* Emulations for +CLOCK_MONOTONIC+:
|
||||||
* [:MACH_ABSOLUTE_TIME_CLOCK_MONOTONIC] Use mach_absolute_time(), available on Darwin.
|
* [:MACH_ABSOLUTE_TIME_CLOCK_MONOTONIC] Use mach_absolute_time(), available on Darwin.
|
||||||
* The resolution is CPU dependent.
|
* The resolution is CPU dependent.
|
||||||
*
|
*
|
||||||
|
* Emulations for +CLOCK_PROCESS_CPUTIME_ID+:
|
||||||
|
* [:SUS_GETRUSAGE_SELF_USER_AND_SYSTEM_TIME_CLOCK_PROCESS_CPUTIME_ID]
|
||||||
|
* Use getrusage with RUSAGE_SELF.
|
||||||
|
* getrusage is defined by Single Unix Specification.
|
||||||
|
* The result is addition of ru_utime and ru_stime.
|
||||||
|
* The resolution is 1 micro second.
|
||||||
|
*
|
||||||
* If the given +clock_id+ is not supported, Errno::EINVAL is raised.
|
* If the given +clock_id+ is not supported, Errno::EINVAL is raised.
|
||||||
*
|
*
|
||||||
* +unit+ specifies a type of the return value.
|
* +unit+ specifies a type of the return value.
|
||||||
@ -6764,6 +6771,26 @@ rb_clock_gettime(int argc, VALUE *argv)
|
|||||||
goto success;
|
goto success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef RUSAGE_SELF
|
||||||
|
#define RUBY_SUS_GETRUSAGE_SELF_USER_AND_SYSTEM_TIME_CLOCK_PROCESS_CPUTIME_ID \
|
||||||
|
ID2SYM(rb_intern("SUS_GETRUSAGE_SELF_USER_AND_SYSTEM_TIME_CLOCK_PROCESS_CPUTIME_ID"))
|
||||||
|
if (clk_id == RUBY_SUS_GETRUSAGE_SELF_USER_AND_SYSTEM_TIME_CLOCK_PROCESS_CPUTIME_ID) {
|
||||||
|
struct rusage usage;
|
||||||
|
long usec;
|
||||||
|
ret = getrusage(RUSAGE_SELF, &usage);
|
||||||
|
if (ret != 0)
|
||||||
|
rb_sys_fail("getrusage");
|
||||||
|
ts.tv_sec = usage.ru_utime.tv_sec + usage.ru_stime.tv_sec;
|
||||||
|
usec = usage.ru_utime.tv_usec + usage.ru_stime.tv_usec;
|
||||||
|
if (1000000 <= usec) {
|
||||||
|
ts.tv_sec++;
|
||||||
|
usec -= 1000000;
|
||||||
|
}
|
||||||
|
ts.tv_nsec = usec * 1000;
|
||||||
|
goto success;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#define RUBY_MACH_ABSOLUTE_TIME_CLOCK_MONOTONIC ID2SYM(rb_intern("MACH_ABSOLUTE_TIME_CLOCK_MONOTONIC"))
|
#define RUBY_MACH_ABSOLUTE_TIME_CLOCK_MONOTONIC ID2SYM(rb_intern("MACH_ABSOLUTE_TIME_CLOCK_MONOTONIC"))
|
||||||
if (clk_id == RUBY_MACH_ABSOLUTE_TIME_CLOCK_MONOTONIC) {
|
if (clk_id == RUBY_MACH_ABSOLUTE_TIME_CLOCK_MONOTONIC) {
|
||||||
@ -7109,6 +7136,8 @@ Init_process(void)
|
|||||||
#endif
|
#endif
|
||||||
#ifdef CLOCK_PROCESS_CPUTIME_ID
|
#ifdef CLOCK_PROCESS_CPUTIME_ID
|
||||||
rb_define_const(rb_mProcess, "CLOCK_PROCESS_CPUTIME_ID", CLOCKID2NUM(CLOCK_PROCESS_CPUTIME_ID));
|
rb_define_const(rb_mProcess, "CLOCK_PROCESS_CPUTIME_ID", CLOCKID2NUM(CLOCK_PROCESS_CPUTIME_ID));
|
||||||
|
#elif defined(RUBY_SUS_GETRUSAGE_SELF_USER_AND_SYSTEM_TIME_CLOCK_PROCESS_CPUTIME_ID)
|
||||||
|
rb_define_const(rb_mProcess, "CLOCK_PROCESS_CPUTIME_ID", RUBY_SUS_GETRUSAGE_SELF_USER_AND_SYSTEM_TIME_CLOCK_PROCESS_CPUTIME_ID);
|
||||||
#endif
|
#endif
|
||||||
#ifdef CLOCK_THREAD_CPUTIME_ID
|
#ifdef CLOCK_THREAD_CPUTIME_ID
|
||||||
rb_define_const(rb_mProcess, "CLOCK_THREAD_CPUTIME_ID", CLOCKID2NUM(CLOCK_THREAD_CPUTIME_ID));
|
rb_define_const(rb_mProcess, "CLOCK_THREAD_CPUTIME_ID", CLOCKID2NUM(CLOCK_THREAD_CPUTIME_ID));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user