From a7ba3cce6dbbde49efa5b20e2db5cd49c259d3ad Mon Sep 17 00:00:00 2001 From: Melanie Plageman Date: Tue, 21 Mar 2023 18:20:44 -0400 Subject: [PATCH v7 2/4] FlushRelationBuffers() counts temp relation IO timing Add pgstat_database and pgBufferUsage IO timing counting to FlushRelationBuffers() for writes of temporary relations. --- src/backend/storage/buffer/bufmgr.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 0a05577b68..dea2e8fe40 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -3591,6 +3591,8 @@ FlushRelationBuffers(Relation rel) { int i; BufferDesc *bufHdr; + instr_time io_start, + io_time; if (RelationUsesLocalBuffers(rel)) { @@ -3616,17 +3618,33 @@ FlushRelationBuffers(Relation rel) PageSetChecksumInplace(localpage, bufHdr->tag.blockNum); + if (track_io_timing) + INSTR_TIME_SET_CURRENT(io_start); + else + INSTR_TIME_SET_ZERO(io_start); + smgrwrite(RelationGetSmgr(rel), BufTagGetForkNum(&bufHdr->tag), bufHdr->tag.blockNum, localpage, false); + buf_state &= ~(BM_DIRTY | BM_JUST_DIRTIED); pg_atomic_unlocked_write_u32(&bufHdr->state, buf_state); pgstat_count_io_op(IOOBJECT_TEMP_RELATION, IOCONTEXT_NORMAL, IOOP_WRITE); + if (track_io_timing) + { + INSTR_TIME_SET_CURRENT(io_time); + INSTR_TIME_SUBTRACT(io_time, io_start); + pgstat_count_buffer_write_time(INSTR_TIME_GET_MICROSEC(io_time)); + INSTR_TIME_ADD(pgBufferUsage.blk_write_time, io_time); + } + + pgBufferUsage.local_blks_written++; + /* Pop the error context stack */ error_context_stack = errcallback.previous; } -- 2.37.2