Changeset 6645cda for libcfa/src
- Timestamp:
- Apr 14, 2021, 5:52:12 PM (3 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 9344f0e
- Parents:
- 89c2a77b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/clock.hfa
r89c2a77b r6645cda 10 10 // Created On : Thu Apr 12 14:36:06 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jan 6 12:49:58 202013 // Update Count : 912 // Last Modified On : Wed Apr 14 17:48:25 2021 13 // Update Count : 20 14 14 // 15 15 … … 32 32 33 33 static inline { 34 void reset Clock( Clock & clk, Duration adj ) with( clk ) {34 void reset( Clock & clk, Duration adj ) with( clk ) { 35 35 offset = adj + __timezone`s; // timezone (global) is (UTC - local time) in seconds 36 } // reset Clock36 } // reset 37 37 38 void ?{}( Clock & clk, Duration adj ) { resetClock( clk, adj ); } 38 void ?{}( Clock & clk ) { reset( clk, (Duration){ 0 } ); } 39 void ?{}( Clock & clk, Duration adj ) { reset( clk, adj ); } 39 40 40 Duration getResNsec() { 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() { 41 45 struct timespec res; 42 46 clock_getres( CLOCK_REALTIME, &res ); 43 47 return ((int64_t)res.tv_sec * TIMEGRAN + res.tv_nsec)`ns; 44 } // getRes48 } // resolutionNsec 45 49 46 Duration getRes() {50 Duration resolution() { 47 51 struct timespec res; 48 52 clock_getres( CLOCK_REALTIME_COARSE, &res ); 49 53 return ((int64_t)res.tv_sec * TIMEGRAN + res.tv_nsec)`ns; 50 } // getRes54 } // resolution 51 55 52 Time getTimeNsec() {// with nanoseconds56 Time timeNsec() { // with nanoseconds 53 57 timespec curr; 54 58 clock_gettime( CLOCK_REALTIME, &curr ); 55 59 return (Time){ curr }; 56 } // getTimeNsec60 } // timeNsec 57 61 58 Time getTime() {// without nanoseconds62 Time time() { // without nanoseconds 59 63 timespec curr; 60 64 clock_gettime( CLOCK_REALTIME_COARSE, &curr ); 61 65 curr.tv_nsec = 0; 62 66 return (Time){ curr }; 63 } // getTime67 } // time 64 68 65 Time getTime( Clock & clk ) with( clk ) {66 return getTime() + offset;67 } // getTime69 Time time( Clock & clk ) with( clk ) { 70 return time() + offset; 71 } // time 68 72 69 73 Time ?()( Clock & clk ) with( clk ) { // alternative syntax 70 return getTime() + offset;71 } // getTime74 return time() + offset; 75 } // ?() 72 76 73 timeval getTime( Clock & clk ) {77 timeval time( Clock & clk ) { 74 78 return (timeval){ clk() }; 75 } // getTime79 } // time 76 80 77 tm getTime( Clock & clk ) with( clk ) {81 tm time( Clock & clk ) with( clk ) { 78 82 tm ret; 79 localtime_r( getTime( clk ).tv_sec, &ret );83 localtime_r( time( clk ).tv_sec, &ret ); 80 84 return ret; 81 } // getTime85 } // time 82 86 83 Time getCPUTime() { 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() { 84 91 timespec ts; 85 92 clock_gettime( CLOCK_THREAD_CPUTIME_ID, &ts ); 86 return (Time){ ts }; 87 } // getCPUTime 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 88 114 } // distribution 89 115
Note: See TracChangeset
for help on using the changeset viewer.