PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
pgstat_io.c File Reference
#include "postgres.h"
#include "executor/instrument.h"
#include "storage/bufmgr.h"
#include "utils/pgstat_internal.h"
Include dependency graph for pgstat_io.c:

Go to the source code of this file.

Functions

bool pgstat_bktype_io_stats_valid (PgStat_BktypeIO *backend_io, BackendType bktype)
 
void pgstat_count_io_op (IOObject io_object, IOContext io_context, IOOp io_op, uint32 cnt, uint64 bytes)
 
instr_time pgstat_prepare_io_time (bool track_io_guc)
 
void pgstat_count_io_op_time (IOObject io_object, IOContext io_context, IOOp io_op, instr_time start_time, uint32 cnt, uint64 bytes)
 
PgStat_IOpgstat_fetch_stat_io (void)
 
bool pgstat_io_have_pending_cb (void)
 
void pgstat_flush_io (bool nowait)
 
bool pgstat_io_flush_cb (bool nowait)
 
const char * pgstat_get_io_context_name (IOContext io_context)
 
const char * pgstat_get_io_object_name (IOObject io_object)
 
void pgstat_io_init_shmem_cb (void *stats)
 
void pgstat_io_reset_all_cb (TimestampTz ts)
 
void pgstat_io_snapshot_cb (void)
 
bool pgstat_tracks_io_bktype (BackendType bktype)
 
bool pgstat_tracks_io_object (BackendType bktype, IOObject io_object, IOContext io_context)
 
bool pgstat_tracks_io_op (BackendType bktype, IOObject io_object, IOContext io_context, IOOp io_op)
 

Variables

static PgStat_PendingIO PendingIOStats
 
static bool have_iostats = false
 

Function Documentation

◆ pgstat_bktype_io_stats_valid()

bool pgstat_bktype_io_stats_valid ( PgStat_BktypeIO backend_io,
BackendType  bktype 
)

Definition at line 37 of file pgstat_io.c.

39{
40 for (int io_object = 0; io_object < IOOBJECT_NUM_TYPES; io_object++)
41 {
42 for (int io_context = 0; io_context < IOCONTEXT_NUM_TYPES; io_context++)
43 {
44 for (int io_op = 0; io_op < IOOP_NUM_TYPES; io_op++)
45 {
46 /* we do track it */
47 if (pgstat_tracks_io_op(bktype, io_object, io_context, io_op))
48 {
49 /* ensure that if IO times are non-zero, counts are > 0 */
50 if (backend_io->times[io_object][io_context][io_op] != 0 &&
51 backend_io->counts[io_object][io_context][io_op] <= 0)
52 return false;
53
54 continue;
55 }
56
57 /* we don't track it, and it is not 0 */
58 if (backend_io->counts[io_object][io_context][io_op] != 0)
59 return false;
60 }
61 }
62 }
63
64 return true;
65}
#define IOOP_NUM_TYPES
Definition: pgstat.h:315
#define IOCONTEXT_NUM_TYPES
Definition: pgstat.h:289
#define IOOBJECT_NUM_TYPES
Definition: pgstat.h:279
bool pgstat_tracks_io_op(BackendType bktype, IOObject io_object, IOContext io_context, IOOp io_op)
Definition: pgstat_io.c:462
PgStat_Counter times[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:325
PgStat_Counter counts[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:324

References PgStat_BktypeIO::counts, IOCONTEXT_NUM_TYPES, IOOBJECT_NUM_TYPES, IOOP_NUM_TYPES, pgstat_tracks_io_op(), and PgStat_BktypeIO::times.

Referenced by pg_stat_get_backend_io(), pg_stat_get_io(), and pgstat_io_flush_cb().

◆ pgstat_count_io_op()

void pgstat_count_io_op ( IOObject  io_object,
IOContext  io_context,
IOOp  io_op,
uint32  cnt,
uint64  bytes 
)

Definition at line 68 of file pgstat_io.c.

70{
71 Assert((unsigned int) io_object < IOOBJECT_NUM_TYPES);
72 Assert((unsigned int) io_context < IOCONTEXT_NUM_TYPES);
73 Assert(pgstat_is_ioop_tracked_in_bytes(io_op) || bytes == 0);
74 Assert(pgstat_tracks_io_op(MyBackendType, io_object, io_context, io_op));
75
77 {
78 PgStat_BackendPending *entry_ref;
79
81 entry_ref->pending_io.counts[io_object][io_context][io_op] += cnt;
82 entry_ref->pending_io.bytes[io_object][io_context][io_op] += bytes;
83 }
84
85 PendingIOStats.counts[io_object][io_context][io_op] += cnt;
86 PendingIOStats.bytes[io_object][io_context][io_op] += bytes;
87
88 have_iostats = true;
89}
#define Assert(condition)
Definition: c.h:815
ProcNumber MyProcNumber
Definition: globals.c:89
BackendType MyBackendType
Definition: miscinit.c:64
#define pgstat_is_ioop_tracked_in_bytes(io_op)
Definition: pgstat.h:317
bool pgstat_tracks_backend_bktype(BackendType bktype)
PgStat_BackendPending * pgstat_prep_backend_pending(ProcNumber procnum)
static PgStat_PendingIO PendingIOStats
Definition: pgstat_io.c:23
static bool have_iostats
Definition: pgstat_io.c:24
PgStat_PendingIO pending_io
Definition: pgstat.h:356
PgStat_Counter counts[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:331
uint64 bytes[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:330

References Assert, PgStat_PendingIO::bytes, PgStat_PendingIO::counts, have_iostats, IOCONTEXT_NUM_TYPES, IOOBJECT_NUM_TYPES, MyBackendType, MyProcNumber, PgStat_BackendPending::pending_io, PendingIOStats, pgstat_is_ioop_tracked_in_bytes, pgstat_prep_backend_pending(), pgstat_tracks_backend_bktype(), and pgstat_tracks_io_op().

Referenced by GetLocalVictimBuffer(), GetVictimBuffer(), pgstat_count_io_op_time(), and PinBufferForBlock().

◆ pgstat_count_io_op_time()

void pgstat_count_io_op_time ( IOObject  io_object,
IOContext  io_context,
IOOp  io_op,
instr_time  start_time,
uint32  cnt,
uint64  bytes 
)

Definition at line 118 of file pgstat_io.c.

120{
121 if (track_io_timing)
122 {
123 instr_time io_time;
124
125 INSTR_TIME_SET_CURRENT(io_time);
127
128 if (io_op == IOOP_WRITE || io_op == IOOP_EXTEND)
129 {
131 if (io_object == IOOBJECT_RELATION)
133 else if (io_object == IOOBJECT_TEMP_RELATION)
135 }
136 else if (io_op == IOOP_READ)
137 {
139 if (io_object == IOOBJECT_RELATION)
141 else if (io_object == IOOBJECT_TEMP_RELATION)
143 }
144
145 INSTR_TIME_ADD(PendingIOStats.pending_times[io_object][io_context][io_op],
146 io_time);
147
149 {
150 PgStat_BackendPending *entry_ref;
151
153 INSTR_TIME_ADD(entry_ref->pending_io.pending_times[io_object][io_context][io_op],
154 io_time);
155 }
156 }
157
158 pgstat_count_io_op(io_object, io_context, io_op, cnt, bytes);
159}
bool track_io_timing
Definition: bufmgr.c:143
#define INSTR_TIME_SET_CURRENT(t)
Definition: instr_time.h:122
#define INSTR_TIME_ADD(x, y)
Definition: instr_time.h:178
#define INSTR_TIME_SUBTRACT(x, y)
Definition: instr_time.h:181
#define INSTR_TIME_GET_MICROSEC(t)
Definition: instr_time.h:194
BufferUsage pgBufferUsage
Definition: instrument.c:20
static time_t start_time
Definition: pg_ctl.c:95
#define pgstat_count_buffer_read_time(n)
Definition: pgstat.h:601
@ IOOBJECT_RELATION
Definition: pgstat.h:275
@ IOOBJECT_TEMP_RELATION
Definition: pgstat.h:276
#define pgstat_count_buffer_write_time(n)
Definition: pgstat.h:603
@ IOOP_EXTEND
Definition: pgstat.h:310
@ IOOP_READ
Definition: pgstat.h:311
@ IOOP_WRITE
Definition: pgstat.h:312
void pgstat_count_io_op(IOObject io_object, IOContext io_context, IOOp io_op, uint32 cnt, uint64 bytes)
Definition: pgstat_io.c:68
instr_time local_blk_read_time
Definition: instrument.h:38
instr_time shared_blk_read_time
Definition: instrument.h:36
instr_time shared_blk_write_time
Definition: instrument.h:37
instr_time local_blk_write_time
Definition: instrument.h:39
instr_time pending_times[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:332

References INSTR_TIME_ADD, INSTR_TIME_GET_MICROSEC, INSTR_TIME_SET_CURRENT, INSTR_TIME_SUBTRACT, IOOBJECT_RELATION, IOOBJECT_TEMP_RELATION, IOOP_EXTEND, IOOP_READ, IOOP_WRITE, BufferUsage::local_blk_read_time, BufferUsage::local_blk_write_time, MyBackendType, MyProcNumber, PgStat_BackendPending::pending_io, PgStat_PendingIO::pending_times, PendingIOStats, pgBufferUsage, pgstat_count_buffer_read_time, pgstat_count_buffer_write_time, pgstat_count_io_op(), pgstat_prep_backend_pending(), pgstat_tracks_backend_bktype(), BufferUsage::shared_blk_read_time, BufferUsage::shared_blk_write_time, start_time, and track_io_timing.

Referenced by ExtendBufferedRelLocal(), ExtendBufferedRelShared(), FlushBuffer(), FlushRelationBuffers(), GetLocalVictimBuffer(), IssuePendingWritebacks(), mdsyncfiletag(), register_dirty_segment(), and WaitReadBuffers().

◆ pgstat_fetch_stat_io()

PgStat_IO * pgstat_fetch_stat_io ( void  )

Definition at line 162 of file pgstat_io.c.

163{
165
166 return &pgStatLocal.snapshot.io;
167}
void pgstat_snapshot_fixed(PgStat_Kind kind)
Definition: pgstat.c:1089
PgStat_LocalState pgStatLocal
Definition: pgstat.c:213
#define PGSTAT_KIND_IO
Definition: pgstat_kind.h:38
PgStat_Snapshot snapshot

References PgStat_Snapshot::io, PGSTAT_KIND_IO, pgstat_snapshot_fixed(), pgStatLocal, and PgStat_LocalState::snapshot.

Referenced by pg_stat_get_io().

◆ pgstat_flush_io()

void pgstat_flush_io ( bool  nowait)

Definition at line 182 of file pgstat_io.c.

183{
184 (void) pgstat_io_flush_cb(nowait);
185}
bool pgstat_io_flush_cb(bool nowait)
Definition: pgstat_io.c:196

References pgstat_io_flush_cb().

Referenced by pgstat_report_analyze(), pgstat_report_bgwriter(), pgstat_report_checkpointer(), pgstat_report_vacuum(), and pgstat_report_wal().

◆ pgstat_get_io_context_name()

const char * pgstat_get_io_context_name ( IOContext  io_context)

Definition at line 247 of file pgstat_io.c.

248{
249 switch (io_context)
250 {
252 return "bulkread";
254 return "bulkwrite";
255 case IOCONTEXT_NORMAL:
256 return "normal";
257 case IOCONTEXT_VACUUM:
258 return "vacuum";
259 }
260
261 elog(ERROR, "unrecognized IOContext value: %d", io_context);
263}
#define pg_unreachable()
Definition: c.h:318
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225
@ IOCONTEXT_NORMAL
Definition: pgstat.h:285
@ IOCONTEXT_VACUUM
Definition: pgstat.h:286
@ IOCONTEXT_BULKREAD
Definition: pgstat.h:283
@ IOCONTEXT_BULKWRITE
Definition: pgstat.h:284

References elog, ERROR, IOCONTEXT_BULKREAD, IOCONTEXT_BULKWRITE, IOCONTEXT_NORMAL, IOCONTEXT_VACUUM, and pg_unreachable.

Referenced by pg_stat_io_build_tuples().

◆ pgstat_get_io_object_name()

const char * pgstat_get_io_object_name ( IOObject  io_object)

Definition at line 266 of file pgstat_io.c.

267{
268 switch (io_object)
269 {
271 return "relation";
273 return "temp relation";
274 }
275
276 elog(ERROR, "unrecognized IOObject value: %d", io_object);
278}

References elog, ERROR, IOOBJECT_RELATION, IOOBJECT_TEMP_RELATION, and pg_unreachable.

Referenced by pg_stat_io_build_tuples().

◆ pgstat_io_flush_cb()

bool pgstat_io_flush_cb ( bool  nowait)

Definition at line 196 of file pgstat_io.c.

197{
198 LWLock *bktype_lock;
199 PgStat_BktypeIO *bktype_shstats;
200
201 if (!have_iostats)
202 return false;
203
204 bktype_lock = &pgStatLocal.shmem->io.locks[MyBackendType];
205 bktype_shstats =
207
208 if (!nowait)
209 LWLockAcquire(bktype_lock, LW_EXCLUSIVE);
210 else if (!LWLockConditionalAcquire(bktype_lock, LW_EXCLUSIVE))
211 return true;
212
213 for (int io_object = 0; io_object < IOOBJECT_NUM_TYPES; io_object++)
214 {
215 for (int io_context = 0; io_context < IOCONTEXT_NUM_TYPES; io_context++)
216 {
217 for (int io_op = 0; io_op < IOOP_NUM_TYPES; io_op++)
218 {
219 instr_time time;
220
221 bktype_shstats->counts[io_object][io_context][io_op] +=
222 PendingIOStats.counts[io_object][io_context][io_op];
223
224 bktype_shstats->bytes[io_object][io_context][io_op] +=
225 PendingIOStats.bytes[io_object][io_context][io_op];
226
227 time = PendingIOStats.pending_times[io_object][io_context][io_op];
228
229 bktype_shstats->times[io_object][io_context][io_op] +=
231 }
232 }
233 }
234
236
237 LWLockRelease(bktype_lock);
238
239 memset(&PendingIOStats, 0, sizeof(PendingIOStats));
240
241 have_iostats = false;
242
243 return false;
244}
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1168
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1781
bool LWLockConditionalAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1339
@ LW_EXCLUSIVE
Definition: lwlock.h:114
bool pgstat_bktype_io_stats_valid(PgStat_BktypeIO *backend_io, BackendType bktype)
Definition: pgstat_io.c:37
Definition: lwlock.h:42
LWLock locks[BACKEND_NUM_TYPES]
uint64 bytes[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:323
PgStat_BktypeIO stats[BACKEND_NUM_TYPES]
Definition: pgstat.h:338
PgStat_ShmemControl * shmem
PgStatShared_IO io

References Assert, PgStat_BktypeIO::bytes, PgStat_PendingIO::bytes, PgStat_BktypeIO::counts, PgStat_PendingIO::counts, have_iostats, INSTR_TIME_GET_MICROSEC, PgStat_ShmemControl::io, IOCONTEXT_NUM_TYPES, IOOBJECT_NUM_TYPES, IOOP_NUM_TYPES, PgStatShared_IO::locks, LW_EXCLUSIVE, LWLockAcquire(), LWLockConditionalAcquire(), LWLockRelease(), MyBackendType, PgStat_PendingIO::pending_times, PendingIOStats, pgstat_bktype_io_stats_valid(), pgStatLocal, PgStat_LocalState::shmem, PgStat_IO::stats, PgStatShared_IO::stats, and PgStat_BktypeIO::times.

Referenced by pgstat_flush_io().

◆ pgstat_io_have_pending_cb()

bool pgstat_io_have_pending_cb ( void  )

Definition at line 173 of file pgstat_io.c.

174{
175 return have_iostats;
176}

References have_iostats.

◆ pgstat_io_init_shmem_cb()

void pgstat_io_init_shmem_cb ( void *  stats)

Definition at line 281 of file pgstat_io.c.

282{
283 PgStatShared_IO *stat_shmem = (PgStatShared_IO *) stats;
284
285 for (int i = 0; i < BACKEND_NUM_TYPES; i++)
287}
int i
Definition: isn.c:72
void LWLockInitialize(LWLock *lock, int tranche_id)
Definition: lwlock.c:707
@ LWTRANCHE_PGSTATS_DATA
Definition: lwlock.h:205
#define BACKEND_NUM_TYPES
Definition: miscadmin.h:375

References BACKEND_NUM_TYPES, i, PgStatShared_IO::locks, LWLockInitialize(), and LWTRANCHE_PGSTATS_DATA.

◆ pgstat_io_reset_all_cb()

void pgstat_io_reset_all_cb ( TimestampTz  ts)

Definition at line 290 of file pgstat_io.c.

291{
292 for (int i = 0; i < BACKEND_NUM_TYPES; i++)
293 {
294 LWLock *bktype_lock = &pgStatLocal.shmem->io.locks[i];
295 PgStat_BktypeIO *bktype_shstats = &pgStatLocal.shmem->io.stats.stats[i];
296
297 LWLockAcquire(bktype_lock, LW_EXCLUSIVE);
298
299 /*
300 * Use the lock in the first BackendType's PgStat_BktypeIO to protect
301 * the reset timestamp as well.
302 */
303 if (i == 0)
305
306 memset(bktype_shstats, 0, sizeof(*bktype_shstats));
307 LWLockRelease(bktype_lock);
308 }
309}
TimestampTz stat_reset_timestamp
Definition: pgstat.h:337

References BACKEND_NUM_TYPES, i, PgStat_ShmemControl::io, PgStatShared_IO::locks, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), pgStatLocal, PgStat_LocalState::shmem, PgStat_IO::stat_reset_timestamp, PgStat_IO::stats, and PgStatShared_IO::stats.

◆ pgstat_io_snapshot_cb()

void pgstat_io_snapshot_cb ( void  )

Definition at line 312 of file pgstat_io.c.

313{
314 for (int i = 0; i < BACKEND_NUM_TYPES; i++)
315 {
316 LWLock *bktype_lock = &pgStatLocal.shmem->io.locks[i];
317 PgStat_BktypeIO *bktype_shstats = &pgStatLocal.shmem->io.stats.stats[i];
318 PgStat_BktypeIO *bktype_snap = &pgStatLocal.snapshot.io.stats[i];
319
320 LWLockAcquire(bktype_lock, LW_SHARED);
321
322 /*
323 * Use the lock in the first BackendType's PgStat_BktypeIO to protect
324 * the reset timestamp as well.
325 */
326 if (i == 0)
329
330 /* using struct assignment due to better type safety */
331 *bktype_snap = *bktype_shstats;
332 LWLockRelease(bktype_lock);
333 }
334}
@ LW_SHARED
Definition: lwlock.h:115

References BACKEND_NUM_TYPES, i, PgStat_ShmemControl::io, PgStat_Snapshot::io, PgStatShared_IO::locks, LW_SHARED, LWLockAcquire(), LWLockRelease(), pgStatLocal, PgStat_LocalState::shmem, PgStat_LocalState::snapshot, PgStat_IO::stat_reset_timestamp, PgStat_IO::stats, and PgStatShared_IO::stats.

◆ pgstat_prepare_io_time()

instr_time pgstat_prepare_io_time ( bool  track_io_guc)

Definition at line 96 of file pgstat_io.c.

97{
98 instr_time io_start;
99
100 if (track_io_guc)
101 INSTR_TIME_SET_CURRENT(io_start);
102 else
103 {
104 /*
105 * There is no need to set io_start when an IO timing GUC is disabled,
106 * still initialize it to zero to avoid compiler warnings.
107 */
108 INSTR_TIME_SET_ZERO(io_start);
109 }
110
111 return io_start;
112}
#define INSTR_TIME_SET_ZERO(t)
Definition: instr_time.h:172

References INSTR_TIME_SET_CURRENT, and INSTR_TIME_SET_ZERO.

Referenced by ExtendBufferedRelLocal(), ExtendBufferedRelShared(), FlushBuffer(), FlushRelationBuffers(), GetLocalVictimBuffer(), IssuePendingWritebacks(), mdsyncfiletag(), register_dirty_segment(), and WaitReadBuffers().

◆ pgstat_tracks_io_bktype()

bool pgstat_tracks_io_bktype ( BackendType  bktype)

Definition at line 356 of file pgstat_io.c.

357{
358 /*
359 * List every type so that new backend types trigger a warning about
360 * needing to adjust this switch.
361 */
362 switch (bktype)
363 {
364 case B_INVALID:
366 case B_ARCHIVER:
367 case B_LOGGER:
368 case B_WAL_RECEIVER:
369 case B_WAL_WRITER:
370 case B_WAL_SUMMARIZER:
371 return false;
372
374 case B_AUTOVAC_WORKER:
375 case B_BACKEND:
376 case B_BG_WORKER:
377 case B_BG_WRITER:
378 case B_CHECKPOINTER:
381 case B_STARTUP:
382 case B_WAL_SENDER:
383 return true;
384 }
385
386 return false;
387}
@ B_WAL_SUMMARIZER
Definition: miscadmin.h:365
@ B_WAL_WRITER
Definition: miscadmin.h:366
@ B_WAL_RECEIVER
Definition: miscadmin.h:364
@ B_CHECKPOINTER
Definition: miscadmin.h:362
@ B_WAL_SENDER
Definition: miscadmin.h:346
@ B_LOGGER
Definition: miscadmin.h:372
@ B_STARTUP
Definition: miscadmin.h:363
@ B_BG_WORKER
Definition: miscadmin.h:345
@ B_INVALID
Definition: miscadmin.h:338
@ B_STANDALONE_BACKEND
Definition: miscadmin.h:349
@ B_BG_WRITER
Definition: miscadmin.h:361
@ B_BACKEND
Definition: miscadmin.h:341
@ B_ARCHIVER
Definition: miscadmin.h:360
@ B_AUTOVAC_LAUNCHER
Definition: miscadmin.h:343
@ B_SLOTSYNC_WORKER
Definition: miscadmin.h:347
@ B_DEAD_END_BACKEND
Definition: miscadmin.h:342
@ B_AUTOVAC_WORKER
Definition: miscadmin.h:344

References B_ARCHIVER, B_AUTOVAC_LAUNCHER, B_AUTOVAC_WORKER, B_BACKEND, B_BG_WORKER, B_BG_WRITER, B_CHECKPOINTER, B_DEAD_END_BACKEND, B_INVALID, B_LOGGER, B_SLOTSYNC_WORKER, B_STANDALONE_BACKEND, B_STARTUP, B_WAL_RECEIVER, B_WAL_SENDER, B_WAL_SUMMARIZER, and B_WAL_WRITER.

Referenced by pg_stat_get_io(), and pgstat_tracks_io_object().

◆ pgstat_tracks_io_object()

bool pgstat_tracks_io_object ( BackendType  bktype,
IOObject  io_object,
IOContext  io_context 
)

Definition at line 397 of file pgstat_io.c.

399{
400 bool no_temp_rel;
401
402 /*
403 * Some BackendTypes should never track IO statistics.
404 */
405 if (!pgstat_tracks_io_bktype(bktype))
406 return false;
407
408 /*
409 * Currently, IO on temporary relations can only occur in the
410 * IOCONTEXT_NORMAL IOContext.
411 */
412 if (io_context != IOCONTEXT_NORMAL &&
413 io_object == IOOBJECT_TEMP_RELATION)
414 return false;
415
416 /*
417 * In core Postgres, only regular backends and WAL Sender processes
418 * executing queries will use local buffers and operate on temporary
419 * relations. Parallel workers will not use local buffers (see
420 * InitLocalBuffers()); however, extensions leveraging background workers
421 * have no such limitation, so track IO on IOOBJECT_TEMP_RELATION for
422 * BackendType B_BG_WORKER.
423 */
424 no_temp_rel = bktype == B_AUTOVAC_LAUNCHER || bktype == B_BG_WRITER ||
425 bktype == B_CHECKPOINTER || bktype == B_AUTOVAC_WORKER ||
426 bktype == B_STANDALONE_BACKEND || bktype == B_STARTUP;
427
428 if (no_temp_rel && io_context == IOCONTEXT_NORMAL &&
429 io_object == IOOBJECT_TEMP_RELATION)
430 return false;
431
432 /*
433 * Some BackendTypes do not currently perform any IO in certain
434 * IOContexts, and, while it may not be inherently incorrect for them to
435 * do so, excluding those rows from the view makes the view easier to use.
436 */
437 if ((bktype == B_CHECKPOINTER || bktype == B_BG_WRITER) &&
438 (io_context == IOCONTEXT_BULKREAD ||
439 io_context == IOCONTEXT_BULKWRITE ||
440 io_context == IOCONTEXT_VACUUM))
441 return false;
442
443 if (bktype == B_AUTOVAC_LAUNCHER && io_context == IOCONTEXT_VACUUM)
444 return false;
445
446 if ((bktype == B_AUTOVAC_WORKER || bktype == B_AUTOVAC_LAUNCHER) &&
447 io_context == IOCONTEXT_BULKWRITE)
448 return false;
449
450 return true;
451}
bool pgstat_tracks_io_bktype(BackendType bktype)
Definition: pgstat_io.c:356

References B_AUTOVAC_LAUNCHER, B_AUTOVAC_WORKER, B_BG_WRITER, B_CHECKPOINTER, B_STANDALONE_BACKEND, B_STARTUP, IOCONTEXT_BULKREAD, IOCONTEXT_BULKWRITE, IOCONTEXT_NORMAL, IOCONTEXT_VACUUM, IOOBJECT_TEMP_RELATION, and pgstat_tracks_io_bktype().

Referenced by pg_stat_io_build_tuples(), and pgstat_tracks_io_op().

◆ pgstat_tracks_io_op()

bool pgstat_tracks_io_op ( BackendType  bktype,
IOObject  io_object,
IOContext  io_context,
IOOp  io_op 
)

Definition at line 462 of file pgstat_io.c.

464{
465 bool strategy_io_context;
466
467 /* if (io_context, io_object) will never collect stats, we're done */
468 if (!pgstat_tracks_io_object(bktype, io_object, io_context))
469 return false;
470
471 /*
472 * Some BackendTypes will not do certain IOOps.
473 */
474 if ((bktype == B_BG_WRITER || bktype == B_CHECKPOINTER) &&
475 (io_op == IOOP_READ || io_op == IOOP_EVICT || io_op == IOOP_HIT))
476 return false;
477
478 if ((bktype == B_AUTOVAC_LAUNCHER || bktype == B_BG_WRITER ||
479 bktype == B_CHECKPOINTER) && io_op == IOOP_EXTEND)
480 return false;
481
482 /*
483 * Temporary tables are not logged and thus do not require fsync'ing.
484 * Writeback is not requested for temporary tables.
485 */
486 if (io_object == IOOBJECT_TEMP_RELATION &&
487 (io_op == IOOP_FSYNC || io_op == IOOP_WRITEBACK))
488 return false;
489
490 /*
491 * Some IOOps are not valid in certain IOContexts and some IOOps are only
492 * valid in certain contexts.
493 */
494 if (io_context == IOCONTEXT_BULKREAD && io_op == IOOP_EXTEND)
495 return false;
496
497 strategy_io_context = io_context == IOCONTEXT_BULKREAD ||
498 io_context == IOCONTEXT_BULKWRITE || io_context == IOCONTEXT_VACUUM;
499
500 /*
501 * IOOP_REUSE is only relevant when a BufferAccessStrategy is in use.
502 */
503 if (!strategy_io_context && io_op == IOOP_REUSE)
504 return false;
505
506 /*
507 * IOOP_FSYNC IOOps done by a backend using a BufferAccessStrategy are
508 * counted in the IOCONTEXT_NORMAL IOContext. See comment in
509 * register_dirty_segment() for more details.
510 */
511 if (strategy_io_context && io_op == IOOP_FSYNC)
512 return false;
513
514
515 return true;
516}
@ IOOP_FSYNC
Definition: pgstat.h:304
@ IOOP_WRITEBACK
Definition: pgstat.h:307
@ IOOP_HIT
Definition: pgstat.h:305
@ IOOP_EVICT
Definition: pgstat.h:303
@ IOOP_REUSE
Definition: pgstat.h:306
bool pgstat_tracks_io_object(BackendType bktype, IOObject io_object, IOContext io_context)
Definition: pgstat_io.c:397

References B_AUTOVAC_LAUNCHER, B_BG_WRITER, B_CHECKPOINTER, IOCONTEXT_BULKREAD, IOCONTEXT_BULKWRITE, IOCONTEXT_VACUUM, IOOBJECT_TEMP_RELATION, IOOP_EVICT, IOOP_EXTEND, IOOP_FSYNC, IOOP_HIT, IOOP_READ, IOOP_REUSE, IOOP_WRITEBACK, and pgstat_tracks_io_object().

Referenced by pg_stat_io_build_tuples(), pgstat_bktype_io_stats_valid(), and pgstat_count_io_op().

Variable Documentation

◆ have_iostats

bool have_iostats = false
static

Definition at line 24 of file pgstat_io.c.

Referenced by pgstat_count_io_op(), pgstat_io_flush_cb(), and pgstat_io_have_pending_cb().

◆ PendingIOStats

PgStat_PendingIO PendingIOStats
static

Definition at line 23 of file pgstat_io.c.

Referenced by pgstat_count_io_op(), pgstat_count_io_op_time(), and pgstat_io_flush_cb().