Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4a539a2

Browse files
committed
Expose BufferUsageAccumDiff().
Previously pg_stat_statements calculated the difference of buffer counters by its own code even while BufferUsageAccumDiff() had the same code. This commit expose BufferUsageAccumDiff() and makes pg_stat_statements use it for the calculation, in order to simply the code. This change also would be useful for the upcoming patch for the planning counters in pg_stat_statements because the patch will add one more code for the calculation of difference of buffer counters and that can easily be done by using BufferUsageAccumDiff(). Author: Julien Rouhaud Reviewed-by: Fujii Masao Discussion: https://postgr.es/m/bdfee4e0-a304-2498-8da5-3cb52c0a193e@oss.nttdata.com
1 parent b61d161 commit 4a539a2

File tree

3 files changed

+5
-27
lines changed

3 files changed

+5
-27
lines changed

contrib/pg_stat_statements/pg_stat_statements.c

+2-24
Original file line numberDiff line numberDiff line change
@@ -1016,30 +1016,8 @@ pgss_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
10161016
rows = (qc && qc->commandTag == CMDTAG_COPY) ? qc->nprocessed : 0;
10171017

10181018
/* calc differences of buffer counters. */
1019-
bufusage.shared_blks_hit =
1020-
pgBufferUsage.shared_blks_hit - bufusage_start.shared_blks_hit;
1021-
bufusage.shared_blks_read =
1022-
pgBufferUsage.shared_blks_read - bufusage_start.shared_blks_read;
1023-
bufusage.shared_blks_dirtied =
1024-
pgBufferUsage.shared_blks_dirtied - bufusage_start.shared_blks_dirtied;
1025-
bufusage.shared_blks_written =
1026-
pgBufferUsage.shared_blks_written - bufusage_start.shared_blks_written;
1027-
bufusage.local_blks_hit =
1028-
pgBufferUsage.local_blks_hit - bufusage_start.local_blks_hit;
1029-
bufusage.local_blks_read =
1030-
pgBufferUsage.local_blks_read - bufusage_start.local_blks_read;
1031-
bufusage.local_blks_dirtied =
1032-
pgBufferUsage.local_blks_dirtied - bufusage_start.local_blks_dirtied;
1033-
bufusage.local_blks_written =
1034-
pgBufferUsage.local_blks_written - bufusage_start.local_blks_written;
1035-
bufusage.temp_blks_read =
1036-
pgBufferUsage.temp_blks_read - bufusage_start.temp_blks_read;
1037-
bufusage.temp_blks_written =
1038-
pgBufferUsage.temp_blks_written - bufusage_start.temp_blks_written;
1039-
bufusage.blk_read_time = pgBufferUsage.blk_read_time;
1040-
INSTR_TIME_SUBTRACT(bufusage.blk_read_time, bufusage_start.blk_read_time);
1041-
bufusage.blk_write_time = pgBufferUsage.blk_write_time;
1042-
INSTR_TIME_SUBTRACT(bufusage.blk_write_time, bufusage_start.blk_write_time);
1019+
memset(&bufusage, 0, sizeof(BufferUsage));
1020+
BufferUsageAccumDiff(&bufusage, &pgBufferUsage, &bufusage_start);
10431021

10441022
pgss_store(queryString,
10451023
0, /* signal that it's a utility stmt */

src/backend/executor/instrument.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ BufferUsage pgBufferUsage;
2121
static BufferUsage save_pgBufferUsage;
2222

2323
static void BufferUsageAdd(BufferUsage *dst, const BufferUsage *add);
24-
static void BufferUsageAccumDiff(BufferUsage *dst,
25-
const BufferUsage *add, const BufferUsage *sub);
2624

2725

2826
/* Allocate new instrumentation structure(s) */
@@ -203,7 +201,7 @@ BufferUsageAdd(BufferUsage *dst, const BufferUsage *add)
203201
}
204202

205203
/* dst += add - sub */
206-
static void
204+
void
207205
BufferUsageAccumDiff(BufferUsage *dst,
208206
const BufferUsage *add,
209207
const BufferUsage *sub)

src/include/executor/instrument.h

+2
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,7 @@ extern void InstrAggNode(Instrumentation *dst, Instrumentation *add);
8181
extern void InstrStartParallelQuery(void);
8282
extern void InstrEndParallelQuery(BufferUsage *result);
8383
extern void InstrAccumParallelQuery(BufferUsage *result);
84+
extern void BufferUsageAccumDiff(BufferUsage *dst,
85+
const BufferUsage *add, const BufferUsage *sub);
8486

8587
#endif /* INSTRUMENT_H */

0 commit comments

Comments
 (0)