19 #ifndef TBCI_STOPWATCH_H
20 #define TBCI_STOPWATCH_H
41 #ifdef HAVE_TBCICONFIG_H
42 # include "tbci/tbciconfig.h"
44 # include "tbci/config_manual.h"
57 #if defined (__linux__) && !defined(CLK_TCK)
58 # define CLK_TCK ((clock_t) sysconf (_SC_CLK_TCK))
65 # if defined(__WORDSIZE) && __WORDSIZE == 64
66 # define LONG_MIN (-9223372036854775807L - 1L)
68 # define LONG_MIN (-2147483647L - 1L)
74 #if defined(__linux__) && defined(BROKEN_HZ)
75 # include <asm/param.h>
76 # define CPS (CLOCKS_PER_SEC*HZ/CLK_TCK)
78 # define CPS CLOCKS_PER_SEC
139 const double t =
total;
204 #include <sys/times.h>
217 return (
double)(tims.tms_utime+tims.tms_cutime) *
secs_per_tick;
235 return (
double)(tims.tms_utime+tims.tms_cutime+tims.tms_stime+tims.tms_cstime)
252 #include <sys/time.h>
262 gettimeofday(&tv,
NULL);
263 return (
double)tv.tv_sec + (double)tv.tv_usec * 0.000001;
274 #include <sys/timeb.h>
283 return (
double)tb.time + (double)tb.millitm * 0.001;
298 return (
double) time(0);
const double secs_per_tick
Used in seconds() to convert internal time to s.
void start()
Starts the stopwatch.
double seconds() const
Return the current time, to be overriden in derived classes.
virtual double seconds() const
Return the current time, to be overriden in derived classes.
virtual double seconds() const
Return the current time, to be overriden in derived classes.
virtual double seconds() const
Return the current time, to be overriden in derived classes.
#define CLK_TCK
This whole CLOCKS_PER_SEC and CLK_TCK business is terribly FUCKED UP ! We need CLK_TCK, as it gives the REAL resolution, but somebody (POSIX?) decided it should not be there.
Stopwatch class using times() to measure userspace CPU time of ourselves and our children.
double adv_stopwatch()
Advance the stopwatch, return diff, handle single overflows.
double stop()
Stops the stopwatch and returns total time (since last reset)
base class for all the stop watches to minimize code duplication
double total
The total elapsed time since construction or reset.
double read_d()
Returns the time since last read/start without stopping the stopwatch (but resets the differential ti...
double read()
Returns the total time without stopping the stopwatch (but resets the differential timer) ...
const double overflow_secs
If we overflow once, we miss this many seconds; We assume that internally long ints are used...
double last_time
The last time we read/started/stopped the clock.
double reset()
Resets the stopwatch.
Stopwatch class using gettimeofday() / _ftime() / time() to measure elapsed (= wall clock) time...
double stop_d()
Stops the stopwatch and returns time since last start / read.
Stopwatch class using times() to measure userspace and system CPU time of ourselves and our children...
stopw_base(const double tick, const double over=-1.0)
c'tor
virtual ~stopw_base()
d'tor