Changes in libcfa/src/clock.hfa [6645cda:4834563]
- File:
-
- 1 edited
-
libcfa/src/clock.hfa (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/clock.hfa
r6645cda r4834563 10 10 // Created On : Thu Apr 12 14:36:06 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Apr 14 17:48:25 202113 // Update Count : 2012 // Last Modified On : Mon Jan 6 12:49:58 2020 13 // Update Count : 9 14 14 // 15 15 … … 32 32 33 33 static inline { 34 void reset ( Clock & clk, Duration adj ) with( clk ) {34 void resetClock( Clock & clk, Duration adj ) with( clk ) { 35 35 offset = adj + __timezone`s; // timezone (global) is (UTC - local time) in seconds 36 } // reset 36 } // resetClock 37 37 38 void ?{}( Clock & clk ) { reset( clk, (Duration){ 0 } ); } 39 void ?{}( Clock & clk, Duration adj ) { reset( clk, adj ); } 38 void ?{}( Clock & clk, Duration adj ) { resetClock( clk, adj ); } 40 39 41 // System-wide clock that measures real, i.e., wall-clock) time. This clock is affected by discontinuous jumps in 42 // the system time. For example, manual changes of the clock, and incremental adjustments performed by adjtime(3) 43 // and NTP (daylight saving (Fall back). 44 Duration resolutionNsec() { 40 Duration getResNsec() { 45 41 struct timespec res; 46 42 clock_getres( CLOCK_REALTIME, &res ); 47 43 return ((int64_t)res.tv_sec * TIMEGRAN + res.tv_nsec)`ns; 48 } // resolutionNsec44 } // getRes 49 45 50 Duration resolution() {46 Duration getRes() { 51 47 struct timespec res; 52 48 clock_getres( CLOCK_REALTIME_COARSE, &res ); 53 49 return ((int64_t)res.tv_sec * TIMEGRAN + res.tv_nsec)`ns; 54 } // resolution50 } // getRes 55 51 56 Time timeNsec() {// with nanoseconds52 Time getTimeNsec() { // with nanoseconds 57 53 timespec curr; 58 54 clock_gettime( CLOCK_REALTIME, &curr ); 59 55 return (Time){ curr }; 60 } // timeNsec56 } // getTimeNsec 61 57 62 Time time() {// without nanoseconds58 Time getTime() { // without nanoseconds 63 59 timespec curr; 64 60 clock_gettime( CLOCK_REALTIME_COARSE, &curr ); 65 61 curr.tv_nsec = 0; 66 62 return (Time){ curr }; 67 } // time63 } // getTime 68 64 69 Time time( Clock & clk ) with( clk ) {70 return time() + offset;71 } // time65 Time getTime( Clock & clk ) with( clk ) { 66 return getTime() + offset; 67 } // getTime 72 68 73 69 Time ?()( Clock & clk ) with( clk ) { // alternative syntax 74 return time() + offset;75 } // ?()70 return getTime() + offset; 71 } // getTime 76 72 77 timeval time( Clock & clk ) {73 timeval getTime( Clock & clk ) { 78 74 return (timeval){ clk() }; 79 } // time75 } // getTime 80 76 81 tm time( Clock & clk ) with( clk ) {77 tm getTime( Clock & clk ) with( clk ) { 82 78 tm ret; 83 localtime_r( time( clk ).tv_sec, &ret );79 localtime_r( getTime( clk ).tv_sec, &ret ); 84 80 return ret; 85 } // time81 } // getTime 86 82 87 // CFA processor CPU-time watch that ticks when the processor (kernel thread) is running. This watch is affected by 88 // discontinuous jumps when the OS is not running the kernal thread. A duration is returned because the value is 89 // relative and cannot be converted to real-time (wall-clock) time. 90 Duration processor() { 83 Time getCPUTime() { 91 84 timespec ts; 92 85 clock_gettime( CLOCK_THREAD_CPUTIME_ID, &ts ); 93 return (Duration){ ts }; 94 } // processor 95 96 // Program CPU-time watch measures CPU time consumed by all processors (kernel threads) in the UNIX process. This 97 // watch is affected by discontinuous jumps when the OS is not running the kernel threads. A duration is returned 98 // because the value is relative and cannot be converted to real-time (wall-clock) time. 99 Duration program() { 100 timespec ts; 101 clock_gettime( CLOCK_PROCESS_CPUTIME_ID, &ts ); 102 return (Duration){ ts }; 103 } // program 104 105 // Monotonic stopwatch starting at machine boot and includes system suspension. This watch is unaffected by 106 // discontinuous jumps resulting from manual changes of the clock, and incremental adjustments performed by 107 // adjtime(3) and NTP (Fall back). A duration is returned because the value is relative and cannot be converted to 108 // real-time (wall-clock) time. 109 Duration boot() { 110 timespec ts; 111 clock_gettime( CLOCK_BOOTTIME, &ts ); 112 return (Duration){ ts }; 113 } // boot 86 return (Time){ ts }; 87 } // getCPUTime 114 88 } // distribution 115 89
Note:
See TracChangeset
for help on using the changeset viewer.