77 #define NS_PER_S INT64CONST(1000000000)
78 #define NS_PER_MS INT64CONST(1000000)
79 #define NS_PER_US INT64CONST(1000)
101 #if defined(__darwin__) && defined(CLOCK_MONOTONIC_RAW)
102 #define PG_INSTR_CLOCK CLOCK_MONOTONIC_RAW
103 #elif defined(CLOCK_MONOTONIC)
104 #define PG_INSTR_CLOCK CLOCK_MONOTONIC
106 #define PG_INSTR_CLOCK CLOCK_REALTIME
122 #define INSTR_TIME_SET_CURRENT(t) \
123 ((t) = pg_clock_gettime_ns())
125 #define INSTR_TIME_GET_NANOSEC(t) \
136 pg_query_performance_counter(
void)
141 QueryPerformanceCounter(&tmp);
142 now.ticks = tmp.QuadPart;
148 GetTimerFrequency(
void)
152 QueryPerformanceFrequency(&f);
153 return (
double) f.QuadPart;
156 #define INSTR_TIME_SET_CURRENT(t) \
157 ((t) = pg_query_performance_counter())
159 #define INSTR_TIME_GET_NANOSEC(t) \
160 ((int64) ((t).ticks * ((double) NS_PER_S / GetTimerFrequency())))
169 #define INSTR_TIME_IS_ZERO(t) ((t).ticks == 0)
172 #define INSTR_TIME_SET_ZERO(t) ((t).ticks = 0)
174 #define INSTR_TIME_SET_CURRENT_LAZY(t) \
175 (INSTR_TIME_IS_ZERO(t) ? INSTR_TIME_SET_CURRENT(t), true : false)
178 #define INSTR_TIME_ADD(x,y) \
179 ((x).ticks += (y).ticks)
181 #define INSTR_TIME_SUBTRACT(x,y) \
182 ((x).ticks -= (y).ticks)
184 #define INSTR_TIME_ACCUM_DIFF(x,y,z) \
185 ((x).ticks += (y).ticks - (z).ticks)
188 #define INSTR_TIME_GET_DOUBLE(t) \
189 ((double) INSTR_TIME_GET_NANOSEC(t) / NS_PER_S)
191 #define INSTR_TIME_GET_MILLISEC(t) \
192 ((double) INSTR_TIME_GET_NANOSEC(t) / NS_PER_MS)
194 #define INSTR_TIME_GET_MICROSEC(t) \
195 (INSTR_TIME_GET_NANOSEC(t) / NS_PER_US)
Datum now(PG_FUNCTION_ARGS)
struct instr_time instr_time
static instr_time pg_clock_gettime_ns(void)