| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #ifndef INSTR_TIME_H |
| #define INSTR_TIME_H |
|
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| typedef struct instr_time |
| { |
| int64 ticks; |
| } instr_time; |
|
|
|
|
| |
|
|
| #define NS_PER_S INT64CONST(1000000000) |
| #define NS_PER_MS INT64CONST(1000000) |
| #define NS_PER_US INT64CONST(1000) |
|
|
|
|
| #ifndef WIN32 |
|
|
|
|
| |
|
|
| #include <time.h> |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #if defined(__darwin__) && defined(CLOCK_MONOTONIC_RAW) |
| #define PG_INSTR_CLOCK CLOCK_MONOTONIC_RAW |
| #elif defined(CLOCK_MONOTONIC) |
| #define PG_INSTR_CLOCK CLOCK_MONOTONIC |
| #else |
| #define PG_INSTR_CLOCK CLOCK_REALTIME |
| #endif |
|
|
| |
| static inline instr_time |
| pg_clock_gettime_ns(void) |
| { |
| instr_time now; |
| struct timespec tmp; |
|
|
| clock_gettime(PG_INSTR_CLOCK, &tmp); |
| now.ticks = tmp.tv_sec * NS_PER_S + tmp.tv_nsec; |
|
|
| return now; |
| } |
|
|
| #define INSTR_TIME_SET_CURRENT(t) \ |
| ((t) = pg_clock_gettime_ns()) |
|
|
| #define INSTR_TIME_GET_NANOSEC(t) \ |
| ((int64) (t).ticks) |
|
|
|
|
| #else |
|
|
|
|
| |
|
|
| |
| static inline instr_time |
| pg_query_performance_counter(void) |
| { |
| instr_time now; |
| LARGE_INTEGER tmp; |
|
|
| QueryPerformanceCounter(&tmp); |
| now.ticks = tmp.QuadPart; |
|
|
| return now; |
| } |
|
|
| static inline double |
| GetTimerFrequency(void) |
| { |
| LARGE_INTEGER f; |
|
|
| QueryPerformanceFrequency(&f); |
| return (double) f.QuadPart; |
| } |
|
|
| #define INSTR_TIME_SET_CURRENT(t) \ |
| ((t) = pg_query_performance_counter()) |
|
|
| #define INSTR_TIME_GET_NANOSEC(t) \ |
| ((int64) ((t).ticks * ((double) NS_PER_S / GetTimerFrequency()))) |
|
|
| #endif |
|
|
|
|
| |
| |
| |
|
|
| #define INSTR_TIME_IS_ZERO(t) ((t).ticks == 0) |
|
|
|
|
| #define INSTR_TIME_SET_ZERO(t) ((t).ticks = 0) |
|
|
| #define INSTR_TIME_SET_CURRENT_LAZY(t) \ |
| (INSTR_TIME_IS_ZERO(t) ? INSTR_TIME_SET_CURRENT(t), true : false) |
|
|
|
|
| #define INSTR_TIME_ADD(x,y) \ |
| ((x).ticks += (y).ticks) |
|
|
| #define INSTR_TIME_SUBTRACT(x,y) \ |
| ((x).ticks -= (y).ticks) |
|
|
| #define INSTR_TIME_ACCUM_DIFF(x,y,z) \ |
| ((x).ticks += (y).ticks - (z).ticks) |
|
|
|
|
| #define INSTR_TIME_GET_DOUBLE(t) \ |
| ((double) INSTR_TIME_GET_NANOSEC(t) / NS_PER_S) |
|
|
| #define INSTR_TIME_GET_MILLISEC(t) \ |
| ((double) INSTR_TIME_GET_NANOSEC(t) / NS_PER_MS) |
|
|
| #define INSTR_TIME_GET_MICROSEC(t) \ |
| (INSTR_TIME_GET_NANOSEC(t) / NS_PER_US) |
|
|
| #endif |
|
|