From 4b9ac96fbf66222ae5fca60e5eed02209b42d1c8 Mon Sep 17 00:00:00 2001 From: "imai.yoshikazu" Date: Wed, 15 Jan 2020 12:42:58 +0000 Subject: [PATCH v4 2/2] [POC] Change measuring method of wait event time from INSTR_TIME to rdtsc. This patch changes measuring method of wait event time from INSTR_TIME (which uses gettimeofday or clock_gettime) to rdtsc. This might reduce the overhead of measuring overhead. Any supports like changing clock cycle to actual time or error handling are not currently implemented. --- src/include/pgstat.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/include/pgstat.h b/src/include/pgstat.h index f90bb44..58fa1f7 100644 --- a/src/include/pgstat.h +++ b/src/include/pgstat.h @@ -432,7 +432,7 @@ typedef struct PgStat_WaitAccumEntry { uint32 wait_event_info; PgStat_Counter calls; - instr_time times; + uint64 times; } PgStat_WaitAccumEntry; /* ---------- @@ -1269,7 +1269,7 @@ typedef struct PgStat_FunctionCallUsage } PgStat_FunctionCallUsage; extern WAHash *wa_hash; -extern instr_time waitStart; +extern uint64 waitStart; /* ---------- * GUC parameters @@ -1392,7 +1392,7 @@ pgstat_report_waitaccum_start() if (pgstat_track_wait_timing) { - INSTR_TIME_SET_CURRENT(waitStart); + waitStart = rdtsc(); } } @@ -1400,15 +1400,15 @@ static inline void pgstat_report_waitaccum_end(uint32 wait_event_info) { PgStat_WaitAccumEntry *entry; - instr_time diff; + uint64 diff = 0; if (wa_hash == NULL) return; if (pgstat_track_wait_timing) { - INSTR_TIME_SET_CURRENT(diff); - INSTR_TIME_SUBTRACT(diff, waitStart); + diff = rdtsc(); + diff -= waitStart; } entry = pgstat_get_wa_entry(wa_hash, wait_event_info); @@ -1423,7 +1423,7 @@ pgstat_report_waitaccum_end(uint32 wait_event_info) entry->calls++; if (pgstat_track_wait_timing) { - INSTR_TIME_ADD(entry->times, diff); + entry->times += diff; } } -- 1.8.3.1