|
a |
|
b/src/chrono.h |
|
|
1 |
#ifndef _CHRONO_H_
|
|
|
2 |
#define _CHRONO_H_
|
|
|
3 |
|
|
|
4 |
/** Easy interface to measuring time intervals */
|
|
|
5 |
class Chrono {
|
|
|
6 |
public:
|
|
|
7 |
/** Initialize, setting the origin time */
|
|
|
8 |
Chrono();
|
|
|
9 |
|
|
|
10 |
/** Re-store current time and return mS since init or last call */
|
|
|
11 |
long restart();
|
|
|
12 |
/** Re-store current time and return uS since init or last call */
|
|
|
13 |
long urestart();
|
|
|
14 |
|
|
|
15 |
/** Snapshot current time to static storage */
|
|
|
16 |
static void refnow();
|
|
|
17 |
|
|
|
18 |
/** Return interval value in various units.
|
|
|
19 |
*
|
|
|
20 |
* Frozen means give time since the last refnow call (this is to
|
|
|
21 |
* allow for using one actual system call to get values from many
|
|
|
22 |
* chrono objects, like when examining timeouts in a queue
|
|
|
23 |
*/
|
|
|
24 |
long millis(bool frozen = false);
|
|
|
25 |
long micros(bool frozen = false);
|
|
|
26 |
float secs(bool frozen = false);
|
|
|
27 |
|
|
|
28 |
/** Return current orig */
|
|
|
29 |
long long amicros() const;
|
|
|
30 |
|
|
|
31 |
struct TimeSpec {
|
|
|
32 |
time_t tv_sec; /* Time in seconds */
|
|
|
33 |
long tv_nsec; /* And nanoseconds (< 10E9) */
|
|
|
34 |
};
|
|
|
35 |
|
|
|
36 |
private:
|
|
|
37 |
TimeSpec m_orig;
|
|
|
38 |
static TimeSpec o_now;
|
|
|
39 |
};
|
|
|
40 |
|
|
|
41 |
#endif /* _CHRONO_H_ */
|