Changeset 4aa495f
- Timestamp:
- Apr 18, 2021, 8:21:14 AM (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:
- d2fadeb
- Parents:
- e54d0c3
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
example/io/batch-readv.c
re54d0c3 r4aa495f 66 66 } 67 67 68 uint64_t getTimeNsec() {68 uint64_t timeHiRes() { 69 69 timespec curr; 70 70 clock_gettime( CLOCK_REALTIME, &curr ); … … 163 163 164 164 printf("Running for %f second, reading %d bytes in batches of %d\n", duration, buflen, batch); 165 uint64_t start = getTimeNsec();166 uint64_t end = getTimeNsec();167 uint64_t prev = getTimeNsec();165 uint64_t start = timeHiRes(); 166 uint64_t end = timeHiRes(); 167 uint64_t prev = timeHiRes(); 168 168 for(;;) { 169 169 submit_and_drain(&iov, batch); 170 end = getTimeNsec();170 end = timeHiRes(); 171 171 uint64_t delta = end - start; 172 172 if( to_fseconds(end - prev) > 0.1 ) { -
libcfa/src/clock.hfa
re54d0c3 r4aa495f 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:25202113 // Update Count : 2 012 // 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 & 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 37 } // reset 37 38 38 void ?{}( Clock & clk ) { reset( clk, (Duration){ 0 } ); } 39 void ?{}( Clock & clk, Duration adj ) { reset( 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 40 41 41 42 // System-wide clock that measures real, i.e., wall-clock) time. This clock is affected by discontinuous jumps in 42 43 // the system time. For example, manual changes of the clock, and incremental adjustments performed by adjtime(3) 43 44 // and NTP (daylight saving (Fall back). 44 Duration resolution Nsec() {45 Duration resolutionHi() { // clock resolution in nanoseconds (fine) 45 46 struct timespec res; 46 47 clock_getres( CLOCK_REALTIME, &res ); 47 48 return ((int64_t)res.tv_sec * TIMEGRAN + res.tv_nsec)`ns; 48 } // resolution Nsec49 } // resolutionHi 49 50 50 Duration resolution() { 51 Duration resolution() { // clock resolution without nanoseconds (coarse) 51 52 struct timespec res; 52 53 clock_getres( CLOCK_REALTIME_COARSE, &res ); … … 54 55 } // resolution 55 56 56 Time time Nsec() { //with nanoseconds57 Time timeHiRes() { // real time with nanoseconds 57 58 timespec curr; 58 59 clock_gettime( CLOCK_REALTIME, &curr ); 59 60 return (Time){ curr }; 60 } // time Nsec61 } // timeHiRes 61 62 62 Time time() { // without nanoseconds63 Time time() { // real time without nanoseconds 63 64 timespec curr; 64 65 clock_gettime( CLOCK_REALTIME_COARSE, &curr ); … … 67 68 } // time 68 69 69 Time time( Clock & clk ) with( clk ) { 70 Time time( Clock & clk ) with( clk ) { // real time for given clock 70 71 return time() + offset; 71 72 } // time … … 75 76 } // ?() 76 77 77 timeval time( Clock & clk ) { 78 timeval time( Clock & clk ) { // convert to C time format 78 79 return (timeval){ clk() }; 79 80 } // time … … 88 89 // discontinuous jumps when the OS is not running the kernal thread. A duration is returned because the value is 89 90 // relative and cannot be converted to real-time (wall-clock) time. 90 Duration processor() { 91 Duration processor() { // non-monotonic duration of kernel thread 91 92 timespec ts; 92 93 clock_gettime( CLOCK_THREAD_CPUTIME_ID, &ts ); … … 97 98 // watch is affected by discontinuous jumps when the OS is not running the kernel threads. A duration is returned 98 99 // because the value is relative and cannot be converted to real-time (wall-clock) time. 99 Duration program() { 100 Duration program() { // non-monotonic duration of program CPU 100 101 timespec ts; 101 102 clock_gettime( CLOCK_PROCESS_CPUTIME_ID, &ts ); … … 103 104 } // program 104 105 105 // Monotonic stopwatch starting at machine boot and includes system suspension. This watch is unaffected by106 // discontinuous jumps resulting from manual changes of the clock, and incremental adjustments performed by107 // adjtime(3) and NTP (Fall back). A duration is returned because the value is relative and cannot be converted to108 // real-time(wall-clock) time.109 Duration boot() { 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 110 111 timespec ts; 111 112 clock_gettime( CLOCK_BOOTTIME, &ts ); -
tests/time.cfa
re54d0c3 r4aa495f 10 10 // Created On : Tue Mar 27 17:24:56 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jun 18 18:14:49 202013 // Update Count : 3 712 // Last Modified On : Fri Apr 16 14:59:53 2021 13 // Update Count : 38 14 14 // 15 15 … … 53 53 // | "Newfoundland" | getTime( Newfoundland ) 54 54 // | "local" | getTime() 55 // | "local nsec" | getTimeNsec()55 // | "local nsec" | timeHiRes() 56 56 // | "PST" | PST(); // getTime short form 57 57 // sout | nl;
Note: See TracChangeset
for help on using the changeset viewer.