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.

Data Structures

struct  PgStat_PendingIO
 

Typedefs

typedef struct PgStat_PendingIO PgStat_PendingIO
 

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)
 
void pgstat_count_io_op_n (IOObject io_object, IOContext io_context, IOOp io_op, uint32 cnt)
 
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)
 
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
 

Typedef Documentation

◆ PgStat_PendingIO

Function Documentation

◆ pgstat_bktype_io_stats_valid()

bool pgstat_bktype_io_stats_valid ( PgStat_BktypeIO backend_io,
BackendType  bktype 
)

Definition at line 46 of file pgstat_io.c.

48 {
49  for (int io_object = 0; io_object < IOOBJECT_NUM_TYPES; io_object++)
50  {
51  for (int io_context = 0; io_context < IOCONTEXT_NUM_TYPES; io_context++)
52  {
53  for (int io_op = 0; io_op < IOOP_NUM_TYPES; io_op++)
54  {
55  /* we do track it */
56  if (pgstat_tracks_io_op(bktype, io_object, io_context, io_op))
57  {
58  /* ensure that if IO times are non-zero, counts are > 0 */
59  if (backend_io->times[io_object][io_context][io_op] != 0 &&
60  backend_io->counts[io_object][io_context][io_op] <= 0)
61  return false;
62 
63  continue;
64  }
65 
66  /* we don't track it, and it is not 0 */
67  if (backend_io->counts[io_object][io_context][io_op] != 0)
68  return false;
69  }
70  }
71  }
72 
73  return true;
74 }
#define IOOP_NUM_TYPES
Definition: pgstat.h:342
#define IOCONTEXT_NUM_TYPES
Definition: pgstat.h:328
#define IOOBJECT_NUM_TYPES
Definition: pgstat.h:318
bool pgstat_tracks_io_op(BackendType bktype, IOObject io_object, IOContext io_context, IOOp io_op)
Definition: pgstat_io.c:454
PgStat_Counter times[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:347
PgStat_Counter counts[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:346

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_io(), and pgstat_io_flush_cb().

◆ pgstat_count_io_op()

void pgstat_count_io_op ( IOObject  io_object,
IOContext  io_context,
IOOp  io_op 
)

Definition at line 77 of file pgstat_io.c.

78 {
79  pgstat_count_io_op_n(io_object, io_context, io_op, 1);
80 }
void pgstat_count_io_op_n(IOObject io_object, IOContext io_context, IOOp io_op, uint32 cnt)
Definition: pgstat_io.c:83

References pgstat_count_io_op_n().

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

◆ pgstat_count_io_op_n()

void pgstat_count_io_op_n ( IOObject  io_object,
IOContext  io_context,
IOOp  io_op,
uint32  cnt 
)

Definition at line 83 of file pgstat_io.c.

84 {
85  Assert((unsigned int) io_object < IOOBJECT_NUM_TYPES);
86  Assert((unsigned int) io_context < IOCONTEXT_NUM_TYPES);
87  Assert((unsigned int) io_op < IOOP_NUM_TYPES);
88  Assert(pgstat_tracks_io_op(MyBackendType, io_object, io_context, io_op));
89 
90  PendingIOStats.counts[io_object][io_context][io_op] += cnt;
91 
92  have_iostats = true;
93 }
#define Assert(condition)
Definition: c.h:837
BackendType MyBackendType
Definition: miscinit.c:64
static PgStat_PendingIO PendingIOStats
Definition: pgstat_io.c:31
static bool have_iostats
Definition: pgstat_io.c:32
PgStat_Counter counts[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat_io.c:26

References Assert, PgStat_PendingIO::counts, have_iostats, IOCONTEXT_NUM_TYPES, IOOBJECT_NUM_TYPES, IOOP_NUM_TYPES, MyBackendType, PendingIOStats, and pgstat_tracks_io_op().

Referenced by pgstat_count_io_op(), and pgstat_count_io_op_time().

◆ 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 
)

Definition at line 122 of file pgstat_io.c.

124 {
125  if (track_io_timing)
126  {
127  instr_time io_time;
128 
129  INSTR_TIME_SET_CURRENT(io_time);
131 
132  if (io_op == IOOP_WRITE || io_op == IOOP_EXTEND)
133  {
135  if (io_object == IOOBJECT_RELATION)
137  else if (io_object == IOOBJECT_TEMP_RELATION)
139  }
140  else if (io_op == IOOP_READ)
141  {
143  if (io_object == IOOBJECT_RELATION)
145  else if (io_object == IOOBJECT_TEMP_RELATION)
147  }
148 
149  INSTR_TIME_ADD(PendingIOStats.pending_times[io_object][io_context][io_op],
150  io_time);
151  }
152 
153  pgstat_count_io_op_n(io_object, io_context, io_op, cnt);
154 }
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:591
@ IOOBJECT_RELATION
Definition: pgstat.h:314
@ IOOBJECT_TEMP_RELATION
Definition: pgstat.h:315
#define pgstat_count_buffer_write_time(n)
Definition: pgstat.h:593
@ IOOP_EXTEND
Definition: pgstat.h:333
@ IOOP_READ
Definition: pgstat.h:336
@ IOOP_WRITE
Definition: pgstat.h:338
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_io.c:27

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, PgStat_PendingIO::pending_times, PendingIOStats, pgBufferUsage, pgstat_count_buffer_read_time, pgstat_count_buffer_write_time, pgstat_count_io_op_n(), 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 157 of file pgstat_io.c.

158 {
160 
161  return &pgStatLocal.snapshot.io;
162 }
void pgstat_snapshot_fixed(PgStat_Kind kind)
Definition: pgstat.c:1068
PgStat_LocalState pgStatLocal
Definition: pgstat.c:212
#define PGSTAT_KIND_IO
Definition: pgstat.h:57
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 177 of file pgstat_io.c.

178 {
179  (void) pgstat_io_flush_cb(nowait);
180 }
bool pgstat_io_flush_cb(bool nowait)
Definition: pgstat_io.c:191

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 239 of file pgstat_io.c.

240 {
241  switch (io_context)
242  {
243  case IOCONTEXT_BULKREAD:
244  return "bulkread";
245  case IOCONTEXT_BULKWRITE:
246  return "bulkwrite";
247  case IOCONTEXT_NORMAL:
248  return "normal";
249  case IOCONTEXT_VACUUM:
250  return "vacuum";
251  }
252 
253  elog(ERROR, "unrecognized IOContext value: %d", io_context);
254  pg_unreachable();
255 }
#define pg_unreachable()
Definition: c.h:311
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225
@ IOCONTEXT_NORMAL
Definition: pgstat.h:324
@ IOCONTEXT_VACUUM
Definition: pgstat.h:325
@ IOCONTEXT_BULKREAD
Definition: pgstat.h:322
@ IOCONTEXT_BULKWRITE
Definition: pgstat.h:323

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

Referenced by pg_stat_get_io().

◆ pgstat_get_io_object_name()

const char* pgstat_get_io_object_name ( IOObject  io_object)

Definition at line 258 of file pgstat_io.c.

259 {
260  switch (io_object)
261  {
262  case IOOBJECT_RELATION:
263  return "relation";
265  return "temp relation";
266  }
267 
268  elog(ERROR, "unrecognized IOObject value: %d", io_object);
269  pg_unreachable();
270 }

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

Referenced by pg_stat_get_io().

◆ pgstat_io_flush_cb()

bool pgstat_io_flush_cb ( bool  nowait)

Definition at line 191 of file pgstat_io.c.

192 {
193  LWLock *bktype_lock;
194  PgStat_BktypeIO *bktype_shstats;
195 
196  if (!have_iostats)
197  return false;
198 
199  bktype_lock = &pgStatLocal.shmem->io.locks[MyBackendType];
200  bktype_shstats =
202 
203  if (!nowait)
204  LWLockAcquire(bktype_lock, LW_EXCLUSIVE);
205  else if (!LWLockConditionalAcquire(bktype_lock, LW_EXCLUSIVE))
206  return true;
207 
208  for (int io_object = 0; io_object < IOOBJECT_NUM_TYPES; io_object++)
209  {
210  for (int io_context = 0; io_context < IOCONTEXT_NUM_TYPES; io_context++)
211  {
212  for (int io_op = 0; io_op < IOOP_NUM_TYPES; io_op++)
213  {
214  instr_time time;
215 
216  bktype_shstats->counts[io_object][io_context][io_op] +=
217  PendingIOStats.counts[io_object][io_context][io_op];
218 
219  time = PendingIOStats.pending_times[io_object][io_context][io_op];
220 
221  bktype_shstats->times[io_object][io_context][io_op] +=
223  }
224  }
225  }
226 
228 
229  LWLockRelease(bktype_lock);
230 
231  memset(&PendingIOStats, 0, sizeof(PendingIOStats));
232 
233  have_iostats = false;
234 
235  return false;
236 }
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:46
Definition: lwlock.h:42
LWLock locks[BACKEND_NUM_TYPES]
PgStat_BktypeIO stats[BACKEND_NUM_TYPES]
Definition: pgstat.h:353
PgStat_ShmemControl * shmem
PgStatShared_IO io

References Assert, PgStat_PendingIO::counts, PgStat_BktypeIO::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 168 of file pgstat_io.c.

169 {
170  return have_iostats;
171 }

References have_iostats.

◆ pgstat_io_init_shmem_cb()

void pgstat_io_init_shmem_cb ( void *  stats)

Definition at line 273 of file pgstat_io.c.

274 {
275  PgStatShared_IO *stat_shmem = (PgStatShared_IO *) stats;
276 
277  for (int i = 0; i < BACKEND_NUM_TYPES; i++)
279 }
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:368

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 282 of file pgstat_io.c.

283 {
284  for (int i = 0; i < BACKEND_NUM_TYPES; i++)
285  {
286  LWLock *bktype_lock = &pgStatLocal.shmem->io.locks[i];
287  PgStat_BktypeIO *bktype_shstats = &pgStatLocal.shmem->io.stats.stats[i];
288 
289  LWLockAcquire(bktype_lock, LW_EXCLUSIVE);
290 
291  /*
292  * Use the lock in the first BackendType's PgStat_BktypeIO to protect
293  * the reset timestamp as well.
294  */
295  if (i == 0)
297 
298  memset(bktype_shstats, 0, sizeof(*bktype_shstats));
299  LWLockRelease(bktype_lock);
300  }
301 }
TimestampTz stat_reset_timestamp
Definition: pgstat.h:352

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 304 of file pgstat_io.c.

305 {
306  for (int i = 0; i < BACKEND_NUM_TYPES; i++)
307  {
308  LWLock *bktype_lock = &pgStatLocal.shmem->io.locks[i];
309  PgStat_BktypeIO *bktype_shstats = &pgStatLocal.shmem->io.stats.stats[i];
310  PgStat_BktypeIO *bktype_snap = &pgStatLocal.snapshot.io.stats[i];
311 
312  LWLockAcquire(bktype_lock, LW_SHARED);
313 
314  /*
315  * Use the lock in the first BackendType's PgStat_BktypeIO to protect
316  * the reset timestamp as well.
317  */
318  if (i == 0)
321 
322  /* using struct assignment due to better type safety */
323  *bktype_snap = *bktype_shstats;
324  LWLockRelease(bktype_lock);
325  }
326 }
@ 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 100 of file pgstat_io.c.

101 {
102  instr_time io_start;
103 
104  if (track_io_guc)
105  INSTR_TIME_SET_CURRENT(io_start);
106  else
107  {
108  /*
109  * There is no need to set io_start when an IO timing GUC is disabled,
110  * still initialize it to zero to avoid compiler warnings.
111  */
112  INSTR_TIME_SET_ZERO(io_start);
113  }
114 
115  return io_start;
116 }
#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 348 of file pgstat_io.c.

349 {
350  /*
351  * List every type so that new backend types trigger a warning about
352  * needing to adjust this switch.
353  */
354  switch (bktype)
355  {
356  case B_INVALID:
357  case B_DEAD_END_BACKEND:
358  case B_ARCHIVER:
359  case B_LOGGER:
360  case B_WAL_RECEIVER:
361  case B_WAL_WRITER:
362  case B_WAL_SUMMARIZER:
363  return false;
364 
365  case B_AUTOVAC_LAUNCHER:
366  case B_AUTOVAC_WORKER:
367  case B_BACKEND:
368  case B_BG_WORKER:
369  case B_BG_WRITER:
370  case B_CHECKPOINTER:
371  case B_SLOTSYNC_WORKER:
373  case B_STARTUP:
374  case B_WAL_SENDER:
375  return true;
376  }
377 
378  return false;
379 }
@ B_WAL_SUMMARIZER
Definition: miscadmin.h:358
@ B_WAL_WRITER
Definition: miscadmin.h:359
@ B_WAL_RECEIVER
Definition: miscadmin.h:357
@ B_CHECKPOINTER
Definition: miscadmin.h:355
@ B_WAL_SENDER
Definition: miscadmin.h:340
@ B_LOGGER
Definition: miscadmin.h:365
@ B_STARTUP
Definition: miscadmin.h:356
@ B_BG_WORKER
Definition: miscadmin.h:339
@ B_INVALID
Definition: miscadmin.h:332
@ B_STANDALONE_BACKEND
Definition: miscadmin.h:343
@ B_BG_WRITER
Definition: miscadmin.h:354
@ B_BACKEND
Definition: miscadmin.h:335
@ B_ARCHIVER
Definition: miscadmin.h:353
@ B_AUTOVAC_LAUNCHER
Definition: miscadmin.h:337
@ B_SLOTSYNC_WORKER
Definition: miscadmin.h:341
@ B_DEAD_END_BACKEND
Definition: miscadmin.h:336
@ B_AUTOVAC_WORKER
Definition: miscadmin.h:338

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 389 of file pgstat_io.c.

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

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_get_io(), 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 454 of file pgstat_io.c.

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

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_get_io(), pgstat_bktype_io_stats_valid(), and pgstat_count_io_op_n().

Variable Documentation

◆ have_iostats

bool have_iostats = false
static

Definition at line 32 of file pgstat_io.c.

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

◆ PendingIOStats

PgStat_PendingIO PendingIOStats
static

Definition at line 31 of file pgstat_io.c.

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