summaryrefslogtreecommitdiff
path: root/src/backend/storage/buffer/bufmgr.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2012-03-27 14:52:37 -0400
committerRobert Haas <rhaas@postgresql.org>2012-03-27 14:55:02 -0400
commit40b9b957694cf7749c420c6c51a7e1d3c9b1fec1 (patch)
treeab94826c3e20f7fe0a63edb3370be8a8988fd31f /src/backend/storage/buffer/bufmgr.c
parent98316e211b60cb160247171e3557b40a247c4610 (diff)
New GUC, track_iotiming, to track I/O timings.
Currently, the only way to see the numbers this gathers is via EXPLAIN (ANALYZE, BUFFERS), but the plan is to add visibility through the stats collector and pg_stat_statements in subsequent patches. Ants Aasma, reviewed by Greg Smith, with some further changes by me.
Diffstat (limited to 'src/backend/storage/buffer/bufmgr.c')
-rw-r--r--src/backend/storage/buffer/bufmgr.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index 3924a51c0c6..4de6a7212cc 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -67,6 +67,7 @@
bool zero_damaged_pages = false;
int bgwriter_lru_maxpages = 100;
double bgwriter_lru_multiplier = 2.0;
+bool track_iotiming = false;
/*
* How many buffers PrefetchBuffer callers should try to stay ahead of their
@@ -437,8 +438,21 @@ ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
MemSet((char *) bufBlock, 0, BLCKSZ);
else
{
+ instr_time io_start,
+ io_time;
+
+ if (track_iotiming)
+ INSTR_TIME_SET_CURRENT(io_start);
+
smgrread(smgr, forkNum, blockNum, (char *) bufBlock);
+ if (track_iotiming)
+ {
+ INSTR_TIME_SET_CURRENT(io_time);
+ INSTR_TIME_SUBTRACT(io_time, io_start);
+ INSTR_TIME_ADD(pgBufferUsage.time_read, io_time);
+ }
+
/* check for garbage data */
if (!PageHeaderIsValid((PageHeader) bufBlock))
{
@@ -1874,6 +1888,7 @@ FlushBuffer(volatile BufferDesc *buf, SMgrRelation reln)
{
XLogRecPtr recptr;
ErrorContextCallback errcontext;
+ instr_time io_start, io_end;
/*
* Acquire the buffer's io_in_progress lock. If StartBufferIO returns
@@ -1921,12 +1936,21 @@ FlushBuffer(volatile BufferDesc *buf, SMgrRelation reln)
buf->flags &= ~BM_JUST_DIRTIED;
UnlockBufHdr(buf);
+ if (track_iotiming)
+ INSTR_TIME_SET_CURRENT(io_start);
+
smgrwrite(reln,
buf->tag.forkNum,
buf->tag.blockNum,
(char *) BufHdrGetBlock(buf),
false);
+ if (track_iotiming)
+ {
+ INSTR_TIME_SET_CURRENT(io_end);
+ INSTR_TIME_ACCUM_DIFF(pgBufferUsage.time_write, io_end, io_start);
+ }
+
pgBufferUsage.shared_blks_written++;
/*