Changeset 5407cdc for libcfa/src/clock.hfa
- Timestamp:
- Apr 28, 2021, 4:56:50 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 8d66610
- Parents:
- feacef9 (diff), b7fd2db6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 edited
-
libcfa/src/clock.hfa (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/clock.hfa
rfeacef9 r5407cdc 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 : Sun Apr 18 08:12:16 2021 13 // Update Count : 28 14 14 // 15 15 … … 27 27 //######################### Clock ######################### 28 28 29 struct Clock { // private 30 Duration offset; // for virtual clock: contains offset from real-time 29 struct Clock { // virtual clock 30 // private 31 Duration offset; // offset from computer real-time 31 32 }; 32 33 33 34 static inline { 34 void reset Clock( Clock & clk, Duration adj ) with( clk ) {35 void reset( Clock & clk, Duration adj ) with( clk ) { // change offset 35 36 offset = adj + __timezone`s; // timezone (global) is (UTC - local time) in seconds 36 } // reset Clock37 } // reset 37 38 38 void ?{}( Clock & clk, Duration adj ) { resetClock( clk, adj ); } 39 void ?{}( Clock & clk ) { reset( clk, (Duration){ 0 } ); } // create no offset 40 void ?{}( Clock & clk, Duration adj ) { reset( clk, adj ); } // create with offset 39 41 40 Duration getResNsec() { 42 // System-wide clock that measures real, i.e., wall-clock) time. This clock is affected by discontinuous jumps in 43 // the system time. For example, manual changes of the clock, and incremental adjustments performed by adjtime(3) 44 // and NTP (daylight saving (Fall back). 45 Duration resolutionHi() { // clock resolution in nanoseconds (fine) 41 46 struct timespec res; 42 47 clock_getres( CLOCK_REALTIME, &res ); 43 48 return ((int64_t)res.tv_sec * TIMEGRAN + res.tv_nsec)`ns; 44 } // getRes49 } // resolutionHi 45 50 46 Duration getRes() {51 Duration resolution() { // clock resolution without nanoseconds (coarse) 47 52 struct timespec res; 48 53 clock_getres( CLOCK_REALTIME_COARSE, &res ); 49 54 return ((int64_t)res.tv_sec * TIMEGRAN + res.tv_nsec)`ns; 50 } // getRes55 } // resolution 51 56 52 Time getTimeNsec() { //with nanoseconds57 Time timeHiRes() { // real time with nanoseconds 53 58 timespec curr; 54 59 clock_gettime( CLOCK_REALTIME, &curr ); 55 60 return (Time){ curr }; 56 } // getTimeNsec61 } // timeHiRes 57 62 58 Time getTime() { //without nanoseconds63 Time time() { // real time without nanoseconds 59 64 timespec curr; 60 65 clock_gettime( CLOCK_REALTIME_COARSE, &curr ); 61 66 curr.tv_nsec = 0; 62 67 return (Time){ curr }; 63 } // getTime68 } // time 64 69 65 Time getTime( Clock & clk ) with( clk ) {66 return getTime() + offset;67 } // getTime70 Time time( Clock & clk ) with( clk ) { // real time for given clock 71 return time() + offset; 72 } // time 68 73 69 74 Time ?()( Clock & clk ) with( clk ) { // alternative syntax 70 return getTime() + offset;71 } // getTime75 return time() + offset; 76 } // ?() 72 77 73 timeval getTime( Clock & clk ) {78 timeval time( Clock & clk ) { // convert to C time format 74 79 return (timeval){ clk() }; 75 } // getTime80 } // time 76 81 77 tm getTime( Clock & clk ) with( clk ) {82 tm time( Clock & clk ) with( clk ) { 78 83 tm ret; 79 localtime_r( getTime( clk ).tv_sec, &ret );84 localtime_r( time( clk ).tv_sec, &ret ); 80 85 return ret; 81 } // getTime86 } // time 82 87 83 Time getCPUTime() { 88 // CFA processor CPU-time watch that ticks when the processor (kernel thread) is running. This watch is affected by 89 // discontinuous jumps when the OS is not running the kernal thread. A duration is returned because the value is 90 // relative and cannot be converted to real-time (wall-clock) time. 91 Duration processor() { // non-monotonic duration of kernel thread 84 92 timespec ts; 85 93 clock_gettime( CLOCK_THREAD_CPUTIME_ID, &ts ); 86 return (Time){ ts }; 87 } // getCPUTime 94 return (Duration){ ts }; 95 } // processor 96 97 // Program CPU-time watch measures CPU time consumed by all processors (kernel threads) in the UNIX process. This 98 // watch is affected by discontinuous jumps when the OS is not running the kernel threads. A duration is returned 99 // because the value is relative and cannot be converted to real-time (wall-clock) time. 100 Duration program() { // non-monotonic duration of program CPU 101 timespec ts; 102 clock_gettime( CLOCK_PROCESS_CPUTIME_ID, &ts ); 103 return (Duration){ ts }; 104 } // program 105 106 // Monotonic duration from machine boot and including system suspension. This watch is unaffected by discontinuous 107 // jumps resulting from manual changes of the clock, and incremental adjustments performed by adjtime(3) and NTP 108 // (Fall back). A duration is returned because the value is relative and cannot be converted to real-time 109 // (wall-clock) time. 110 Duration boot() { // monotonic duration since computer boot 111 timespec ts; 112 clock_gettime( CLOCK_BOOTTIME, &ts ); 113 return (Duration){ ts }; 114 } // boot 88 115 } // distribution 89 116
Note:
See TracChangeset
for help on using the changeset viewer.