From 35c77c59d2e4aec95d6c1489b052d4456855f72f Mon Sep 17 00:00:00 2001 From: Takashi Menjo Date: Wed, 19 May 2021 11:57:49 +0900 Subject: [PATCH 08/13] WAL statistics in cases of wal_pmem_map=true --- src/backend/access/transam/xlogpmem.c | 47 +++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/backend/access/transam/xlogpmem.c b/src/backend/access/transam/xlogpmem.c index 8bd990f1cd0..d91fb2175b7 100644 --- a/src/backend/access/transam/xlogpmem.c +++ b/src/backend/access/transam/xlogpmem.c @@ -195,6 +195,7 @@ void PmemXLogFlush(XLogRecPtr start, XLogRecPtr end) { Size off; + instr_time start_time; Assert(wal_pmem_map); Assert(start < end); @@ -203,22 +204,68 @@ PmemXLogFlush(XLogRecPtr start, XLogRecPtr end) Assert(XLByteInPrevSeg(end, mappedSegNo, wal_segment_size)); off = XLogSegmentOffset(start, wal_segment_size); + + /* Measure I/O timing to write WAL data */ + if (track_wal_io_timing) + INSTR_TIME_SET_CURRENT(start_time); + + pgstat_report_wait_start(WAIT_EVENT_WAL_WRITE); pmem_flush(mappedPages + off, end - start); + pgstat_report_wait_end(); + + /* + * Increment the I/O timing and the number of times WAL data + * were written out to disk. + */ + if (track_wal_io_timing) + { + instr_time duration; + + INSTR_TIME_SET_CURRENT(duration); + INSTR_TIME_SUBTRACT(duration, start_time); + WalStats.m_wal_write_time += INSTR_TIME_GET_MICROSEC(duration); + } + + WalStats.m_wal_write++; } /* * Wait for cache-flush to finish. + * + * See also issue_xlog_fsync in xlog.c. */ void PmemXLogSync(void) { + instr_time start; + Assert(wal_pmem_map); /* Fast return */ if (!enableFsync) return; + /* Measure I/O timing to sync the WAL file */ + if (track_wal_io_timing) + INSTR_TIME_SET_CURRENT(start); + + pgstat_report_wait_start(WAIT_EVENT_WAL_SYNC); pmem_drain(); + pgstat_report_wait_end(); + + /* + * Increment the I/O timing and the number of times WAL files were synced. + */ + if (track_wal_io_timing) + { + instr_time duration; + + INSTR_TIME_SET_CURRENT(duration); + INSTR_TIME_SUBTRACT(duration, start); + WalStats.m_wal_sync_time += INSTR_TIME_GET_MICROSEC(duration); + } + + WalStats.m_wal_sync++; } /* -- 2.17.1