diff options
author | Thomas Munro | 2021-03-10 03:09:50 +0000 |
---|---|---|
committer | Thomas Munro | 2021-03-10 04:44:04 +0000 |
commit | 547f04e7348b6ed992bd4a197d39661fe7c25097 (patch) | |
tree | ffb02da6d78cc3aeee3df4f132de1688baa05e68 /src/include/portability | |
parent | b1d6a8f86813772b9198367a34c8ff8bff7fef9e (diff) |
pgbench: Improve time logic.
Instead of instr_time (struct timespec) and the INSTR_XXX macros,
introduce pg_time_usec_t and use integer arithmetic. Don't include the
connection time in TPS unless using -C mode, but report it separately.
Author: Fabien COELHO <[email protected]>
Reviewed-by: Kyotaro Horiguchi <[email protected]>
Reviewed-by: Hayato Kuroda <[email protected]>
Discussion: https://postgr.es/m/20200227180100.zyvjwzcpiokfsqm2%40alap3.anarazel.de
Diffstat (limited to 'src/include/portability')
-rw-r--r-- | src/include/portability/instr_time.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/include/portability/instr_time.h b/src/include/portability/instr_time.h index 39a4f0600e2..faf806a4410 100644 --- a/src/include/portability/instr_time.h +++ b/src/include/portability/instr_time.h @@ -253,4 +253,32 @@ GetTimerFrequency(void) #define INSTR_TIME_SET_CURRENT_LAZY(t) \ (INSTR_TIME_IS_ZERO(t) ? INSTR_TIME_SET_CURRENT(t), true : false) +/* + * Simpler convenient interface + * + * The instr_time type is expensive when dealing with time arithmetic. + * Define a type to hold microseconds on top of this, suitable for + * benchmarking performance measures, eg in "pgbench". + * + * Type int64 is good enough for about 584500 years. + */ +typedef int64 pg_time_usec_t; + +static inline pg_time_usec_t +pg_time_now(void) +{ + instr_time now; + + INSTR_TIME_SET_CURRENT(now); + return (pg_time_usec_t) INSTR_TIME_GET_MICROSEC(now); +} + +static inline void +pg_time_now_lazy(pg_time_usec_t *now) +{ + if ((*now) == 0) + (*now) = pg_time_now(); +} + +#define PG_TIME_GET_DOUBLE(t) (0.000001 * (t)) #endif /* INSTR_TIME_H */ |