diff options
author | Robert Haas <rhaas@postgresql.org> | 2012-02-22 20:33:05 -0500 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2012-02-22 20:33:05 -0500 |
commit | 2254367435fcc4a31cc3b6d8324e33c5c30f265a (patch) | |
tree | 484dc972b60dd19f03cf15c30869a1566c576848 /src | |
parent | f74f9a277c37b42c570ce01019f815abbec58ba0 (diff) | |
download | postgresql-2254367435fcc4a31cc3b6d8324e33c5c30f265a.tar.gz postgresql-2254367435fcc4a31cc3b6d8324e33c5c30f265a.zip |
Make EXPLAIN (BUFFERS) track blocks dirtied, as well as those written.
Also expose the new counters through pg_stat_statements.
Patch by me. Review by Fujii Masao and Greg Smith.
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/commands/explain.c | 16 | ||||
-rw-r--r-- | src/backend/executor/instrument.c | 2 | ||||
-rw-r--r-- | src/backend/storage/buffer/bufmgr.c | 1 | ||||
-rw-r--r-- | src/backend/storage/buffer/localbuf.c | 4 | ||||
-rw-r--r-- | src/include/executor/instrument.h | 2 |
5 files changed, 22 insertions, 3 deletions
diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c index a1692f82ae8..93b1f34ca0c 100644 --- a/src/backend/commands/explain.c +++ b/src/backend/commands/explain.c @@ -1183,12 +1183,14 @@ ExplainNode(PlanState *planstate, List *ancestors, { bool has_shared = (usage->shared_blks_hit > 0 || usage->shared_blks_read > 0 || - usage->shared_blks_written); + usage->shared_blks_dirtied > 0 || + usage->shared_blks_written > 0); bool has_local = (usage->local_blks_hit > 0 || usage->local_blks_read > 0 || - usage->local_blks_written); + usage->local_blks_dirtied > 0 || + usage->local_blks_written > 0); bool has_temp = (usage->temp_blks_read > 0 || - usage->temp_blks_written); + usage->temp_blks_written > 0); /* Show only positive counter values. */ if (has_shared || has_local || has_temp) @@ -1205,6 +1207,9 @@ ExplainNode(PlanState *planstate, List *ancestors, if (usage->shared_blks_read > 0) appendStringInfo(es->str, " read=%ld", usage->shared_blks_read); + if (usage->shared_blks_dirtied > 0) + appendStringInfo(es->str, " dirtied=%ld", + usage->shared_blks_dirtied); if (usage->shared_blks_written > 0) appendStringInfo(es->str, " written=%ld", usage->shared_blks_written); @@ -1220,6 +1225,9 @@ ExplainNode(PlanState *planstate, List *ancestors, if (usage->local_blks_read > 0) appendStringInfo(es->str, " read=%ld", usage->local_blks_read); + if (usage->local_blks_dirtied > 0) + appendStringInfo(es->str, " dirtied=%ld", + usage->local_blks_dirtied); if (usage->local_blks_written > 0) appendStringInfo(es->str, " written=%ld", usage->local_blks_written); @@ -1243,9 +1251,11 @@ ExplainNode(PlanState *planstate, List *ancestors, { ExplainPropertyLong("Shared Hit Blocks", usage->shared_blks_hit, es); ExplainPropertyLong("Shared Read Blocks", usage->shared_blks_read, es); + ExplainPropertyLong("Shared Dirtied Blocks", usage->shared_blks_dirtied, es); ExplainPropertyLong("Shared Written Blocks", usage->shared_blks_written, es); ExplainPropertyLong("Local Hit Blocks", usage->local_blks_hit, es); ExplainPropertyLong("Local Read Blocks", usage->local_blks_read, es); + ExplainPropertyLong("Local Dirtied Blocks", usage->local_blks_dirtied, es); ExplainPropertyLong("Local Written Blocks", usage->local_blks_written, es); ExplainPropertyLong("Temp Read Blocks", usage->temp_blks_read, es); ExplainPropertyLong("Temp Written Blocks", usage->temp_blks_written, es); diff --git a/src/backend/executor/instrument.c b/src/backend/executor/instrument.c index 2c749b13cd8..6e9f450d688 100644 --- a/src/backend/executor/instrument.c +++ b/src/backend/executor/instrument.c @@ -137,9 +137,11 @@ BufferUsageAccumDiff(BufferUsage *dst, { dst->shared_blks_hit += add->shared_blks_hit - sub->shared_blks_hit; dst->shared_blks_read += add->shared_blks_read - sub->shared_blks_read; + dst->shared_blks_dirtied += add->shared_blks_dirtied - sub->shared_blks_dirtied; dst->shared_blks_written += add->shared_blks_written - sub->shared_blks_written; dst->local_blks_hit += add->local_blks_hit - sub->local_blks_hit; dst->local_blks_read += add->local_blks_read - sub->local_blks_read; + dst->local_blks_dirtied += add->local_blks_dirtied - sub->local_blks_dirtied; dst->local_blks_written += add->local_blks_written - sub->local_blks_written; dst->temp_blks_read += add->temp_blks_read - sub->temp_blks_read; dst->temp_blks_written += add->temp_blks_written - sub->temp_blks_written; diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 1adb6d360dd..3924a51c0c6 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -988,6 +988,7 @@ MarkBufferDirty(Buffer buffer) if (dirtied) { VacuumPageDirty++; + pgBufferUsage.shared_blks_dirtied++; if (VacuumCostActive) VacuumCostBalance += VacuumCostPageDirty; if (ProcGlobal->bgwriterLatch) diff --git a/src/backend/storage/buffer/localbuf.c b/src/backend/storage/buffer/localbuf.c index 096d36a233b..63c14f7300c 100644 --- a/src/backend/storage/buffer/localbuf.c +++ b/src/backend/storage/buffer/localbuf.c @@ -276,6 +276,10 @@ MarkLocalBufferDirty(Buffer buffer) Assert(LocalRefCount[bufid] > 0); bufHdr = &LocalBufferDescriptors[bufid]; + + if (!(bufHdr->flags & BM_DIRTY)) + pgBufferUsage.local_blks_dirtied++; + bufHdr->flags |= BM_DIRTY; } diff --git a/src/include/executor/instrument.h b/src/include/executor/instrument.h index 084302e4e7e..066f684f330 100644 --- a/src/include/executor/instrument.h +++ b/src/include/executor/instrument.h @@ -20,9 +20,11 @@ typedef struct BufferUsage { long shared_blks_hit; /* # of shared buffer hits */ long shared_blks_read; /* # of shared disk blocks read */ + long shared_blks_dirtied; /* # of shared blocks dirtied */ long shared_blks_written; /* # of shared disk blocks written */ long local_blks_hit; /* # of local buffer hits */ long local_blks_read; /* # of local disk blocks read */ + long local_blks_dirtied; /* # of shared blocks dirtied */ long local_blks_written; /* # of local disk blocks written */ long temp_blks_read; /* # of temp blocks read */ long temp_blks_written; /* # of temp blocks written */ |