D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Process
/
Filename :
clock_gettime-c.ri
back
Copy
U:RDoc::AnyMethod[iI"clock_gettime:ETI"Process::clock_gettime;TT:publico:RDoc::Markup::Document:@parts[%o:RDoc::Markup::Paragraph; [I":Returns a clock time as determined by POSIX function ;TI"S{clock_gettime()}[https://man7.org/linux/man-pages/man3/clock_gettime.3.html]:;To:RDoc::Markup::BlankLine o:RDoc::Markup::Verbatim; [I"IProcess.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID) # => 198.650379677 ;T:@format0o; ; [I"IArgument +clock_id+ should be a symbol or a constant that specifies ;TI"-the clock whose time is to be returned; ;TI"see below.;T@o; ; [I"@Optional argument +unit+ should be a symbol that specifies ;TI"5the unit to be used in the returned clock time; ;TI"see below.;T@o; ; [I"<b>Argument +clock_id+</b>;T@o; ; [I"KArgument +clock_id+ specifies the clock whose time is to be returned; ;TI"Dit may be a constant such as <tt>Process::CLOCK_REALTIME</tt>, ;TI"5or a symbol shorthand such as +:CLOCK_REALTIME+.;T@o; ; [I"EThe supported clocks depend on the underlying operating system; ;TI"Jthis method supports the following clocks on the indicated platforms ;TI"@(raises Errno::EINVAL if called with an unsupported clock):;T@o:RDoc::Markup::List: @type:BULLET:@items[o:RDoc::Markup::ListItem:@label0; [o; ; [I"%+:CLOCK_BOOTTIME+: Linux 2.6.39.;To;;0; [o; ; [I"(+:CLOCK_BOOTTIME_ALARM+: Linux 3.0.;To;;0; [o; ; [I"s+:CLOCK_MONOTONIC+: SUSv3 to 4, Linux 2.5.63, FreeBSD 3.0, NetBSD 2.0, OpenBSD 3.4, macOS 10.12, Windows-2000.;To;;0; [o; ; [I"-+:CLOCK_MONOTONIC_COARSE+: Linux 2.6.32.;To;;0; [o; ; [I"*+:CLOCK_MONOTONIC_FAST+: FreeBSD 8.1.;To;;0; [o; ; [I"-+:CLOCK_MONOTONIC_PRECISE+: FreeBSD 8.1.;To;;0; [o; ; [I"7+:CLOCK_MONOTONIC_RAW+: Linux 2.6.28, macOS 10.12.;To;;0; [o; ; [I"0+:CLOCK_MONOTONIC_RAW_APPROX+: macOS 10.12.;To;;0; [o; ; [I"b+:CLOCK_PROCESS_CPUTIME_ID+: SUSv3 to 4, Linux 2.5.63, FreeBSD 9.3, OpenBSD 5.4, macOS 10.12.;To;;0; [o; ; [I"-+:CLOCK_PROF+: FreeBSD 3.0, OpenBSD 2.1.;To;;0; [o; ; [I"|+:CLOCK_REALTIME+: SUSv2 to 4, Linux 2.5.63, FreeBSD 3.0, NetBSD 2.0, OpenBSD 2.1, macOS 10.12, Windows-8/Server-2012. ;TI"4Time.now is recommended over +:CLOCK_REALTIME:.;To;;0; [o; ; [I"(+:CLOCK_REALTIME_ALARM+: Linux 3.0.;To;;0; [o; ; [I",+:CLOCK_REALTIME_COARSE+: Linux 2.6.32.;To;;0; [o; ; [I")+:CLOCK_REALTIME_FAST+: FreeBSD 8.1.;To;;0; [o; ; [I",+:CLOCK_REALTIME_PRECISE+: FreeBSD 8.1.;To;;0; [o; ; [I""+:CLOCK_SECOND+: FreeBSD 8.1.;To;;0; [o; ; [I"+:CLOCK_TAI+: Linux 3.10.;To;;0; [o; ; [I"a+:CLOCK_THREAD_CPUTIME_ID+: SUSv3 to 4, Linux 2.5.63, FreeBSD 7.1, OpenBSD 5.4, macOS 10.12.;To;;0; [o; ; [I"/+:CLOCK_UPTIME+: FreeBSD 7.0, OpenBSD 5.5.;To;;0; [o; ; [I"'+:CLOCK_UPTIME_FAST+: FreeBSD 8.1.;To;;0; [o; ; [I"*+:CLOCK_UPTIME_PRECISE+: FreeBSD 8.1.;To;;0; [o; ; [I"&+:CLOCK_UPTIME_RAW+: macOS 10.12.;To;;0; [o; ; [I"-+:CLOCK_UPTIME_RAW_APPROX+: macOS 10.12.;To;;0; [o; ; [I"0+:CLOCK_VIRTUAL+: FreeBSD 3.0, OpenBSD 2.1.;T@o; ; [ I"9Note that SUS stands for Single Unix Specification. ;TI"HSUS contains POSIX and clock_gettime is defined in the POSIX part. ;TI"4SUS defines +:CLOCK_REALTIME+ as mandatory but ;TI"6+:CLOCK_MONOTONIC+, +:CLOCK_PROCESS_CPUTIME_ID+, ;TI"1and +:CLOCK_THREAD_CPUTIME_ID+ are optional.;T@o; ; [I";Certain emulations are used when the given +clock_id+ ;TI"is not supported directly:;T@o;;;;[o;;0; [o; ; [I"&Emulations for +:CLOCK_REALTIME+:;T@o;;;;[o;;0; [o; ; [I"++:GETTIMEOFDAY_BASED_CLOCK_REALTIME+: ;TI">Use gettimeofday() defined by SUS (deprecated in SUSv4). ;TI"%The resolution is 1 microsecond.;To;;0; [o; ; [I"#+:TIME_BASED_CLOCK_REALTIME+: ;TI""Use time() defined by ISO C. ;TI" The resolution is 1 second.;T@o;;0; [o; ; [I"'Emulations for +:CLOCK_MONOTONIC+:;T@o;;;;[o;;0; [o; ; [I"2+:MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC+: ;TI"4Use mach_absolute_time(), available on Darwin. ;TI"%The resolution is CPU dependent.;To;;0; [o; ; [I"%+:TIMES_BASED_CLOCK_MONOTONIC+: ;TI"<Use the result value of times() defined by POSIX, thus:;To:RDoc::Markup::BlockQuote; [o; ; [I"MUpon successful completion, times() shall return the elapsed real time, ;TI":in clock ticks, since an arbitrary point in the past ;TI")(for example, system start-up time).;T@o; ; [I"RFor example, GNU/Linux returns a value based on jiffies and it is monotonic. ;TI"BHowever, 4.4BSD uses gettimeofday() and it is not monotonic. ;TI"7(FreeBSD uses +:CLOCK_MONOTONIC+ instead, though.);T@o; ; [ I"'The resolution is the clock tick. ;TI"A"getconf CLK_TCK" command shows the clock ticks per second. ;TI"K(The clock ticks-per-second is defined by HZ macro in older systems.) ;TI"7If it is 100 and clock_t is 32 bits integer type, ;TI"Ithe resolution is 10 millisecond and cannot represent over 497 days.;T@o;;0; [o; ; [I"0Emulations for +:CLOCK_PROCESS_CPUTIME_ID+:;T@o;;;;[o;;0; [o; ; [I"2+:GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID+: ;TI"%Use getrusage() defined by SUS. ;TI"Fgetrusage() is used with RUSAGE_SELF to obtain the time only for ;TI"Cthe calling process (excluding the time for child processes). ;TI"PThe result is addition of user time (ru_utime) and system time (ru_stime). ;TI"%The resolution is 1 microsecond.;To;;0; [o; ; [ I".+:TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID+: ;TI"#Use times() defined by POSIX. ;TI"RThe result is addition of user time (tms_utime) and system time (tms_stime). ;TI"Ttms_cutime and tms_cstime are ignored to exclude the time for child processes. ;TI"'The resolution is the clock tick. ;TI"A"getconf CLK_TCK" command shows the clock ticks per second. ;TI"K(The clock ticks per second is defined by HZ macro in older systems.) ;TI"4If it is 100, the resolution is 10 millisecond.;To;;0; [o; ; [I".+:CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID+: ;TI"#Use clock() defined by ISO C. ;TI"2The resolution is <tt>1/CLOCKS_PER_SEC</tt>. ;TI">+CLOCKS_PER_SEC+ is the C-level macro defined by time.h. ;TI".SUS defines +CLOCKS_PER_SEC+ as 1000000; ;TI".other systems may define it differently. ;TI"1If +CLOCKS_PER_SEC+ is 1000000 (as in SUS), ;TI"&the resolution is 1 microsecond. ;TI"JIf +CLOCKS_PER_SEC+ is 1000000 and clock_t is a 32-bit integer type, ;TI")it cannot represent over 72 minutes.;T@o; ; [I"<b>Argument +unit+</b>;T@o; ; [I"8Optional argument +unit+ (default +:float_second+) ;TI"/specifies the unit for the returned value.;T@o;;;;[o;;0; [o; ; [I"=+:float_microsecond+: Number of microseconds as a float.;To;;0; [o; ; [I"=+:float_millisecond+: Number of milliseconds as a float.;To;;0; [o; ; [I"3+:float_second+: Number of seconds as a float.;To;;0; [o; ; [I":+:microsecond+: Number of microseconds as an integer.;To;;0; [o; ; [I":+:millisecond+: Number of milliseconds as an integer.;To;;0; [o; ; [I"8+:nanosecond+: Number of nanoseconds as an integer.;To;;0; [o; ; [I"1+::second+: Number of seconds as an integer.;T@o; ; [I"Examples:;T@o;; [I"JProcess.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID, :float_microsecond) ;TI"# => 203605054.825 ;TI"JProcess.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID, :float_millisecond) ;TI"# => 203643.696848 ;TI"EProcess.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID, :float_second) ;TI"# => 203.762181929 ;TI"DProcess.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID, :microsecond) ;TI"# => 204123212 ;TI"DProcess.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID, :millisecond) ;TI"# => 204298 ;TI"CProcess.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID, :nanosecond) ;TI"# => 204602286036 ;TI"?Process.clock_gettime(:CLOCK_PROCESS_CPUTIME_ID, :second) ;TI"# => 204 ;T; 0o; ; [ I"PThe underlying function, clock_gettime(), returns a number of nanoseconds. ;TI"?Float object (IEEE 754 double) is not enough to represent ;TI"-the return value for +:CLOCK_REALTIME+. ;TI"QIf the exact nanoseconds value is required, use +:nanosecond+ as the +unit+.;T@o; ; [I"GThe origin (time zero) of the returned value is system-dependent, ;TI"4and may be, for example, system start up time, ;TI"+process start up time, the Epoch, etc.;T@o; ; [ I">The origin in +:CLOCK_REALTIME+ is defined as the Epoch: ;TI"'<tt>1970-01-01 00:00:00 UTC</tt>; ;TI"7some systems count leap seconds and others don't, ;TI"+so the result may vary across systems.;T: @fileI"process.c;T:0@omit_headings_from_table_of_contents_below0I"EProcess.clock_gettime(clock_id, unit = :float_second) -> number ;T0[ I"(*args);T@dFI"Process;TcRDoc::NormalModule00