mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Track I/O timing for temporary file blocks in EXPLAIN (BUFFERS)
Previously, the output of EXPLAIN (BUFFERS) option showed only the I/O timing spent reading and writing shared and local buffers. This commit adds on top of that the I/O timing for temporary buffers in the output of EXPLAIN (for spilled external sorts, hashes, materialization. etc). This can be helpful for users in cases where the I/O related to temporary buffers is the bottleneck. Like its cousin, this information is available only when track_io_timing is enabled. Playing the patch, this is showing an extra overhead of up to 1% even when using gettimeofday() as implementation for interval timings, which is slightly within the usual range noise still that's measurable. Author: Masahiko Sawada Reviewed-by: Georgios Kokolatos, Melanie Plageman, Julien Rouhaud, Ranier Vilela Discussion: https://postgr.es/m/CAD21AoAJgotTeP83p6HiAGDhs_9Fw9pZ2J=_tYTsiO5Ob-V5GQ@mail.gmail.com
This commit is contained in:
@@ -3521,8 +3521,11 @@ show_buffer_usage(ExplainState *es, const BufferUsage *usage, bool planning)
|
||||
usage->temp_blks_written > 0);
|
||||
bool has_timing = (!INSTR_TIME_IS_ZERO(usage->blk_read_time) ||
|
||||
!INSTR_TIME_IS_ZERO(usage->blk_write_time));
|
||||
bool has_temp_timing = (!INSTR_TIME_IS_ZERO(usage->temp_blk_read_time) ||
|
||||
!INSTR_TIME_IS_ZERO(usage->temp_blk_write_time));
|
||||
bool show_planning = (planning && (has_shared ||
|
||||
has_local || has_temp || has_timing));
|
||||
has_local || has_temp || has_timing ||
|
||||
has_temp_timing));
|
||||
|
||||
if (show_planning)
|
||||
{
|
||||
@@ -3587,16 +3590,33 @@ show_buffer_usage(ExplainState *es, const BufferUsage *usage, bool planning)
|
||||
}
|
||||
|
||||
/* As above, show only positive counter values. */
|
||||
if (has_timing)
|
||||
if (has_timing || has_temp_timing)
|
||||
{
|
||||
ExplainIndentText(es);
|
||||
appendStringInfoString(es->str, "I/O Timings:");
|
||||
if (!INSTR_TIME_IS_ZERO(usage->blk_read_time))
|
||||
appendStringInfo(es->str, " read=%0.3f",
|
||||
INSTR_TIME_GET_MILLISEC(usage->blk_read_time));
|
||||
if (!INSTR_TIME_IS_ZERO(usage->blk_write_time))
|
||||
appendStringInfo(es->str, " write=%0.3f",
|
||||
INSTR_TIME_GET_MILLISEC(usage->blk_write_time));
|
||||
|
||||
if (has_timing)
|
||||
{
|
||||
appendStringInfoString(es->str, " shared/local");
|
||||
if (!INSTR_TIME_IS_ZERO(usage->blk_read_time))
|
||||
appendStringInfo(es->str, " read=%0.3f",
|
||||
INSTR_TIME_GET_MILLISEC(usage->blk_read_time));
|
||||
if (!INSTR_TIME_IS_ZERO(usage->blk_write_time))
|
||||
appendStringInfo(es->str, " write=%0.3f",
|
||||
INSTR_TIME_GET_MILLISEC(usage->blk_write_time));
|
||||
if (has_temp_timing)
|
||||
appendStringInfoChar(es->str, ',');
|
||||
}
|
||||
if (has_temp_timing)
|
||||
{
|
||||
appendStringInfoString(es->str, " temp");
|
||||
if (!INSTR_TIME_IS_ZERO(usage->temp_blk_read_time))
|
||||
appendStringInfo(es->str, " read=%0.3f",
|
||||
INSTR_TIME_GET_MILLISEC(usage->temp_blk_read_time));
|
||||
if (!INSTR_TIME_IS_ZERO(usage->temp_blk_write_time))
|
||||
appendStringInfo(es->str, " write=%0.3f",
|
||||
INSTR_TIME_GET_MILLISEC(usage->temp_blk_write_time));
|
||||
}
|
||||
appendStringInfoChar(es->str, '\n');
|
||||
}
|
||||
|
||||
@@ -3633,6 +3653,12 @@ show_buffer_usage(ExplainState *es, const BufferUsage *usage, bool planning)
|
||||
ExplainPropertyFloat("I/O Write Time", "ms",
|
||||
INSTR_TIME_GET_MILLISEC(usage->blk_write_time),
|
||||
3, es);
|
||||
ExplainPropertyFloat("Temp I/O Read Time", "ms",
|
||||
INSTR_TIME_GET_MILLISEC(usage->temp_blk_read_time),
|
||||
3, es);
|
||||
ExplainPropertyFloat("Temp I/O Write Time", "ms",
|
||||
INSTR_TIME_GET_MILLISEC(usage->temp_blk_write_time),
|
||||
3, es);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -237,6 +237,8 @@ BufferUsageAdd(BufferUsage *dst, const BufferUsage *add)
|
||||
dst->temp_blks_written += add->temp_blks_written;
|
||||
INSTR_TIME_ADD(dst->blk_read_time, add->blk_read_time);
|
||||
INSTR_TIME_ADD(dst->blk_write_time, add->blk_write_time);
|
||||
INSTR_TIME_ADD(dst->temp_blk_read_time, add->temp_blk_read_time);
|
||||
INSTR_TIME_ADD(dst->temp_blk_write_time, add->temp_blk_write_time);
|
||||
}
|
||||
|
||||
/* dst += add - sub */
|
||||
@@ -259,6 +261,10 @@ BufferUsageAccumDiff(BufferUsage *dst,
|
||||
add->blk_read_time, sub->blk_read_time);
|
||||
INSTR_TIME_ACCUM_DIFF(dst->blk_write_time,
|
||||
add->blk_write_time, sub->blk_write_time);
|
||||
INSTR_TIME_ACCUM_DIFF(dst->temp_blk_read_time,
|
||||
add->temp_blk_read_time, sub->temp_blk_read_time);
|
||||
INSTR_TIME_ACCUM_DIFF(dst->temp_blk_write_time,
|
||||
add->temp_blk_write_time, sub->temp_blk_write_time);
|
||||
}
|
||||
|
||||
/* helper functions for WAL usage accumulation */
|
||||
|
@@ -429,6 +429,8 @@ static void
|
||||
BufFileLoadBuffer(BufFile *file)
|
||||
{
|
||||
File thisfile;
|
||||
instr_time io_start;
|
||||
instr_time io_time;
|
||||
|
||||
/*
|
||||
* Advance to next component file if necessary and possible.
|
||||
@@ -440,10 +442,14 @@ BufFileLoadBuffer(BufFile *file)
|
||||
file->curOffset = 0L;
|
||||
}
|
||||
|
||||
thisfile = file->files[file->curFile];
|
||||
|
||||
if (track_io_timing)
|
||||
INSTR_TIME_SET_CURRENT(io_start);
|
||||
|
||||
/*
|
||||
* Read whatever we can get, up to a full bufferload.
|
||||
*/
|
||||
thisfile = file->files[file->curFile];
|
||||
file->nbytes = FileRead(thisfile,
|
||||
file->buffer.data,
|
||||
sizeof(file->buffer),
|
||||
@@ -458,6 +464,13 @@ BufFileLoadBuffer(BufFile *file)
|
||||
FilePathName(thisfile))));
|
||||
}
|
||||
|
||||
if (track_io_timing)
|
||||
{
|
||||
INSTR_TIME_SET_CURRENT(io_time);
|
||||
INSTR_TIME_SUBTRACT(io_time, io_start);
|
||||
INSTR_TIME_ADD(pgBufferUsage.temp_blk_read_time, io_time);
|
||||
}
|
||||
|
||||
/* we choose not to advance curOffset here */
|
||||
|
||||
if (file->nbytes > 0)
|
||||
@@ -485,6 +498,8 @@ BufFileDumpBuffer(BufFile *file)
|
||||
while (wpos < file->nbytes)
|
||||
{
|
||||
off_t availbytes;
|
||||
instr_time io_start;
|
||||
instr_time io_time;
|
||||
|
||||
/*
|
||||
* Advance to next component file if necessary and possible.
|
||||
@@ -507,6 +522,10 @@ BufFileDumpBuffer(BufFile *file)
|
||||
bytestowrite = (int) availbytes;
|
||||
|
||||
thisfile = file->files[file->curFile];
|
||||
|
||||
if (track_io_timing)
|
||||
INSTR_TIME_SET_CURRENT(io_start);
|
||||
|
||||
bytestowrite = FileWrite(thisfile,
|
||||
file->buffer.data + wpos,
|
||||
bytestowrite,
|
||||
@@ -517,6 +536,14 @@ BufFileDumpBuffer(BufFile *file)
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not write to file \"%s\": %m",
|
||||
FilePathName(thisfile))));
|
||||
|
||||
if (track_io_timing)
|
||||
{
|
||||
INSTR_TIME_SET_CURRENT(io_time);
|
||||
INSTR_TIME_SUBTRACT(io_time, io_start);
|
||||
INSTR_TIME_ADD(pgBufferUsage.temp_blk_write_time, io_time);
|
||||
}
|
||||
|
||||
file->curOffset += bytestowrite;
|
||||
wpos += bytestowrite;
|
||||
|
||||
|
Reference in New Issue
Block a user