stopwatch.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00040 #ifndef FX_TIMER_H
00041 #define FX_TIMER_H
00042
00043 #include "fastlib/base/common.h"
00044
00045 #include <sys/times.h>
00046
00047 EXTERN_C_BEGIN
00048
00050 typedef uint64 tsc_t;
00052 #define LTSC L64
00053
00054
00055
00056
00057 #if defined(__i386__)
00058
00059 #define RDTSC(tscv) __asm__ volatile (".byte 0x0f, 0x31" : "=A" (tscv))
00060 #define HAVE_RDTSC
00061 #endif
00062
00064 struct timestamp {
00066 tsc_t micros;
00067 #ifdef HAVE_RDTSC
00068
00069 tsc_t cycles;
00070 #endif
00071
00072 struct tms cpu;
00073 };
00074
00076 struct stopwatch {
00078 struct timestamp total;
00080 struct timestamp start;
00081 };
00082
00084 void timestamp_init(struct timestamp *snapshot);
00086 void timestamp_add(struct timestamp *dest, const struct timestamp *src);
00088 void timestamp_sub(struct timestamp *dest, const struct timestamp *src);
00094 void timestamp_now(struct timestamp *dest);
00100 void timestamp_now_rev(struct timestamp *dest);
00101
00103 void stopwatch_init(struct stopwatch *timer);
00105 void stopwatch_start(struct stopwatch *timer);
00107 void stopwatch_stop(struct stopwatch *timer, const struct timestamp *now);
00108
00110 #define STOPWATCH_ACTIVE(timer) ((timer)->start.micros != 0)
00111
00112 EXTERN_C_END
00113
00114 #endif