PostgreSQL Source Code git master
Macros | Functions | Variables
pgstat_backend.c File Reference
#include "postgres.h"
#include "access/xlog.h"
#include "executor/instrument.h"
#include "storage/bufmgr.h"
#include "storage/proc.h"
#include "storage/procarray.h"
#include "utils/memutils.h"
#include "utils/pgstat_internal.h"
Include dependency graph for pgstat_backend.c:

Go to the source code of this file.

Macros

#define  WALSTAT_ACC(fld, var_to_add)    (bktype_shstats->fld += var_to_add.fld)
 

Functions

void  pgstat_count_backend_io_op_time (IOObject io_object, IOContext io_context, IOOp io_op, instr_time io_time)
 
void  pgstat_count_backend_io_op (IOObject io_object, IOContext io_context, IOOp io_op, uint32 cnt, uint64 bytes)
 
 
 
 
static bool  pgstat_backend_wal_have_pending (void)
 
 
bool  pgstat_flush_backend (bool nowait, bits32 flags)
 
bool  pgstat_backend_flush_cb (bool nowait)
 
 
 
 

Variables

 
static bool  backend_has_iostats = false
 
 

Macro Definition Documentation

WALSTAT_ACC

#define WALSTAT_ACC (   fld,
  var_to_add 
)     (bktype_shstats->fld += var_to_add.fld)

Function Documentation

pgstat_backend_flush_cb()

bool pgstat_backend_flush_cb ( bool  nowait )

Definition at line 313 of file pgstat_backend.c.

314{
316}
bool pgstat_flush_backend(bool nowait, bits32 flags)
#define PGSTAT_BACKEND_FLUSH_ALL

References PGSTAT_BACKEND_FLUSH_ALL, and pgstat_flush_backend().

pgstat_backend_reset_timestamp_cb()

void pgstat_backend_reset_timestamp_cb ( PgStatShared_Commonheader,
TimestampTz  ts 
)

Definition at line 400 of file pgstat_backend.c.

401{
402 ((PgStatShared_Backend *) header)->stats.stat_reset_timestamp = ts;
403}

pgstat_backend_wal_have_pending()

static bool pgstat_backend_wal_have_pending ( void  )
inlinestatic

Definition at line 216 of file pgstat_backend.c.

217{
219}
WalUsage pgWalUsage
Definition: instrument.c:22
static WalUsage prevBackendWalUsage
Definition: pgstat_backend.c:49
int64 wal_records
Definition: instrument.h:53

References pgWalUsage, prevBackendWalUsage, and WalUsage::wal_records.

Referenced by pgstat_flush_backend(), and pgstat_flush_backend_entry_wal().

pgstat_count_backend_io_op()

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

Definition at line 74 of file pgstat_backend.c.

76{
78 return;
79
80 Assert(pgstat_tracks_io_op(MyBackendType, io_object, io_context, io_op));
81
82 PendingBackendStats.pending_io.counts[io_object][io_context][io_op] += cnt;
83 PendingBackendStats.pending_io.bytes[io_object][io_context][io_op] += bytes;
84
87}
Assert(PointerIsAligned(start, uint64))
BackendType MyBackendType
Definition: miscinit.c:64
bool pgstat_report_fixed
Definition: pgstat.c:218
static PgStat_BackendPending PendingBackendStats
Definition: pgstat_backend.c:40
bool pgstat_tracks_backend_bktype(BackendType bktype)
static bool backend_has_iostats
Definition: pgstat_backend.c:41
bool pgstat_tracks_io_op(BackendType bktype, IOObject io_object, IOContext io_context, IOOp io_op)
Definition: pgstat_io.c:477
PgStat_PendingIO pending_io
Definition: pgstat.h:505
PgStat_Counter counts[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:333
uint64 bytes[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:332

References Assert(), backend_has_iostats, PgStat_PendingIO::bytes, PgStat_PendingIO::counts, MyBackendType, PgStat_BackendPending::pending_io, PendingBackendStats, pgstat_report_fixed, pgstat_tracks_backend_bktype(), and pgstat_tracks_io_op().

Referenced by pgstat_count_io_op().

pgstat_count_backend_io_op_time()

void pgstat_count_backend_io_op_time ( IOObject  io_object,
IOContext  io_context,
IOOp  io_op,
instr_time  io_time 
)

Definition at line 56 of file pgstat_backend.c.

58{
60
62 return;
63
64 Assert(pgstat_tracks_io_op(MyBackendType, io_object, io_context, io_op));
65
66 INSTR_TIME_ADD(PendingBackendStats.pending_io.pending_times[io_object][io_context][io_op],
67 io_time);
68
71}
bool track_io_timing
Definition: bufmgr.c:147
#define INSTR_TIME_ADD(x, y)
Definition: instr_time.h:178
instr_time pending_times[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:334
bool track_wal_io_timing
Definition: xlog.c:138

References Assert(), backend_has_iostats, INSTR_TIME_ADD, MyBackendType, PgStat_BackendPending::pending_io, PgStat_PendingIO::pending_times, PendingBackendStats, pgstat_report_fixed, pgstat_tracks_backend_bktype(), pgstat_tracks_io_op(), track_io_timing, and track_wal_io_timing.

Referenced by pgstat_count_io_op_time().

pgstat_create_backend()

void pgstat_create_backend ( ProcNumber  procnum )

Definition at line 322 of file pgstat_backend.c.

323{
324 PgStat_EntryRef *entry_ref;
325 PgStatShared_Backend *shstatent;
326
328 MyProcNumber, false);
329 shstatent = (PgStatShared_Backend *) entry_ref->shared_stats;
330
331 /*
332 * NB: need to accept that there might be stats from an older backend,
333 * e.g. if we previously used this proc number.
334 */
335 memset(&shstatent->stats, 0, sizeof(shstatent->stats));
336 pgstat_unlock_entry(entry_ref);
337
339 backend_has_iostats = false;
340
341 /*
342 * Initialize prevBackendWalUsage with pgWalUsage so that
343 * pgstat_backend_flush_cb() can calculate how much pgWalUsage counters
344 * are increased by subtracting prevBackendWalUsage from pgWalUsage.
345 */
347}
#define MemSet(start, val, len)
Definition: c.h:1019
ProcNumber MyProcNumber
Definition: globals.c:90
#define PGSTAT_KIND_BACKEND
Definition: pgstat_kind.h:32
void pgstat_unlock_entry(PgStat_EntryRef *entry_ref)
Definition: pgstat_shmem.c:720
PgStat_EntryRef * pgstat_get_entry_ref_locked(PgStat_Kind kind, Oid dboid, uint64 objid, bool nowait)
Definition: pgstat_shmem.c:729
#define InvalidOid
Definition: postgres_ext.h:37
PgStat_Backend stats
PgStatShared_Common * shared_stats

References backend_has_iostats, InvalidOid, MemSet, MyProcNumber, PendingBackendStats, pgstat_get_entry_ref_locked(), PGSTAT_KIND_BACKEND, pgstat_unlock_entry(), pgWalUsage, prevBackendWalUsage, PgStat_EntryRef::shared_stats, and PgStatShared_Backend::stats.

Referenced by pgstat_bestart_final().

pgstat_fetch_stat_backend()

PgStat_Backend * pgstat_fetch_stat_backend ( ProcNumber  procNumber )

Definition at line 93 of file pgstat_backend.c.

94{
95 PgStat_Backend *backend_entry;
96
98 InvalidOid, procNumber);
99
100 return backend_entry;
101}
void * pgstat_fetch_entry(PgStat_Kind kind, Oid dboid, uint64 objid)
Definition: pgstat.c:932

References InvalidOid, pgstat_fetch_entry(), and PGSTAT_KIND_BACKEND.

Referenced by pgstat_fetch_stat_backend_by_pid().

pgstat_fetch_stat_backend_by_pid()

PgStat_Backend * pgstat_fetch_stat_backend_by_pid ( int  pid,
BackendTypebktype 
)

Definition at line 111 of file pgstat_backend.c.

112{
113 PGPROC *proc;
114 PgBackendStatus *beentry;
115 ProcNumber procNumber;
116 PgStat_Backend *backend_stats;
117
118 proc = BackendPidGetProc(pid);
119 if (bktype)
120 *bktype = B_INVALID;
121
122 /* this could be an auxiliary process */
123 if (!proc)
124 proc = AuxiliaryPidGetProc(pid);
125
126 if (!proc)
127 return NULL;
128
129 procNumber = GetNumberFromPGProc(proc);
130
131 beentry = pgstat_get_beentry_by_proc_number(procNumber);
132 if (!beentry)
133 return NULL;
134
135 /* check if the backend type tracks statistics */
137 return NULL;
138
139 /* if PID does not match, leave */
140 if (beentry->st_procpid != pid)
141 return NULL;
142
143 if (bktype)
144 *bktype = beentry->st_backendType;
145
146 /*
147 * Retrieve the entry. Note that "beentry" may be freed depending on the
148 * value of stats_fetch_consistency, so do not access it from this point.
149 */
150 backend_stats = pgstat_fetch_stat_backend(procNumber);
151 if (!backend_stats)
152 {
153 if (bktype)
154 *bktype = B_INVALID;
155 return NULL;
156 }
157
158 return backend_stats;
159}
PgBackendStatus * pgstat_get_beentry_by_proc_number(ProcNumber procNumber)
@ B_INVALID
Definition: miscadmin.h:338
PgStat_Backend * pgstat_fetch_stat_backend(ProcNumber procNumber)
Definition: pgstat_backend.c:93
#define GetNumberFromPGProc(proc)
Definition: proc.h:441
PGPROC * BackendPidGetProc(int pid)
Definition: procarray.c:3158
int ProcNumber
Definition: procnumber.h:24
PGPROC * AuxiliaryPidGetProc(int pid)
Definition: proc.c:1091
Definition: proc.h:179
BackendType st_backendType

References AuxiliaryPidGetProc(), B_INVALID, BackendPidGetProc(), GetNumberFromPGProc, pgstat_fetch_stat_backend(), pgstat_get_beentry_by_proc_number(), pgstat_tracks_backend_bktype(), PgBackendStatus::st_backendType, and PgBackendStatus::st_procpid.

Referenced by pg_stat_get_backend_io(), and pg_stat_get_backend_wal().

pgstat_flush_backend()

bool pgstat_flush_backend ( bool  nowait,
bits32  flags 
)

Definition at line 270 of file pgstat_backend.c.

271{
272 PgStat_EntryRef *entry_ref;
273 bool has_pending_data = false;
274
276 return false;
277
278 /* Some IO data pending? */
280 has_pending_data = true;
281
282 /* Some WAL data pending? */
283 if ((flags & PGSTAT_BACKEND_FLUSH_WAL) &&
285 has_pending_data = true;
286
287 if (!has_pending_data)
288 return false;
289
291 MyProcNumber, nowait);
292 if (!entry_ref)
293 return true;
294
295 /* Flush requested statistics */
296 if (flags & PGSTAT_BACKEND_FLUSH_IO)
298
299 if (flags & PGSTAT_BACKEND_FLUSH_WAL)
301
302 pgstat_unlock_entry(entry_ref);
303
304 return false;
305}
static void pgstat_flush_backend_entry_wal(PgStat_EntryRef *entry_ref)
static void pgstat_flush_backend_entry_io(PgStat_EntryRef *entry_ref)
static bool pgstat_backend_wal_have_pending(void)
#define PGSTAT_BACKEND_FLUSH_IO
#define PGSTAT_BACKEND_FLUSH_WAL

References backend_has_iostats, InvalidOid, MyBackendType, MyProcNumber, PGSTAT_BACKEND_FLUSH_IO, PGSTAT_BACKEND_FLUSH_WAL, pgstat_backend_wal_have_pending(), pgstat_flush_backend_entry_io(), pgstat_flush_backend_entry_wal(), pgstat_get_entry_ref_locked(), PGSTAT_KIND_BACKEND, pgstat_tracks_backend_bktype(), and pgstat_unlock_entry().

Referenced by pgstat_backend_flush_cb(), pgstat_report_analyze(), pgstat_report_vacuum(), pgstat_report_wal(), WalSndLoop(), and WalSndWaitForWal().

pgstat_flush_backend_entry_io()

static void pgstat_flush_backend_entry_io ( PgStat_EntryRefentry_ref )
static

Definition at line 166 of file pgstat_backend.c.

167{
168 PgStatShared_Backend *shbackendent;
169 PgStat_BktypeIO *bktype_shstats;
170 PgStat_PendingIO pending_io;
171
172 /*
173 * This function can be called even if nothing at all has happened for IO
174 * statistics. In this case, avoid unnecessarily modifying the stats
175 * entry.
176 */
178 return;
179
180 shbackendent = (PgStatShared_Backend *) entry_ref->shared_stats;
181 bktype_shstats = &shbackendent->stats.io_stats;
182 pending_io = PendingBackendStats.pending_io;
183
184 for (int io_object = 0; io_object < IOOBJECT_NUM_TYPES; io_object++)
185 {
186 for (int io_context = 0; io_context < IOCONTEXT_NUM_TYPES; io_context++)
187 {
188 for (int io_op = 0; io_op < IOOP_NUM_TYPES; io_op++)
189 {
190 instr_time time;
191
192 bktype_shstats->counts[io_object][io_context][io_op] +=
193 pending_io.counts[io_object][io_context][io_op];
194 bktype_shstats->bytes[io_object][io_context][io_op] +=
195 pending_io.bytes[io_object][io_context][io_op];
196 time = pending_io.pending_times[io_object][io_context][io_op];
197
198 bktype_shstats->times[io_object][io_context][io_op] +=
200 }
201 }
202 }
203
204 /*
205 * Clear out the statistics buffer, so it can be re-used.
206 */
208
209 backend_has_iostats = false;
210}
for(;;)
#define INSTR_TIME_GET_MICROSEC(t)
Definition: instr_time.h:194
#define IOOP_NUM_TYPES
Definition: pgstat.h:317
#define IOCONTEXT_NUM_TYPES
Definition: pgstat.h:291
#define IOOBJECT_NUM_TYPES
Definition: pgstat.h:280
PgStat_BktypeIO io_stats
Definition: pgstat.h:492
PgStat_Counter times[IOOBJECT_NUM_TYPES][IOCONTEXT_NUM_TYPES][IOOP_NUM_TYPES]
Definition: pgstat.h:327
uint64 bytes[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:326

References backend_has_iostats, PgStat_BktypeIO::bytes, PgStat_PendingIO::bytes, PgStat_BktypeIO::counts, PgStat_PendingIO::counts, for(), INSTR_TIME_GET_MICROSEC, PgStat_Backend::io_stats, IOCONTEXT_NUM_TYPES, IOOBJECT_NUM_TYPES, IOOP_NUM_TYPES, MemSet, PgStat_BackendPending::pending_io, PgStat_PendingIO::pending_times, PendingBackendStats, PgStat_EntryRef::shared_stats, PgStatShared_Backend::stats, and PgStat_BktypeIO::times.

Referenced by pgstat_flush_backend().

pgstat_flush_backend_entry_wal()

static void pgstat_flush_backend_entry_wal ( PgStat_EntryRefentry_ref )
static

Definition at line 226 of file pgstat_backend.c.

227{
228 PgStatShared_Backend *shbackendent;
229 PgStat_WalCounters *bktype_shstats;
230 WalUsage wal_usage_diff = {0};
231
232 /*
233 * This function can be called even if nothing at all has happened for WAL
234 * statistics. In this case, avoid unnecessarily modifying the stats
235 * entry.
236 */
238 return;
239
240 shbackendent = (PgStatShared_Backend *) entry_ref->shared_stats;
241 bktype_shstats = &shbackendent->stats.wal_counters;
242
243 /*
244 * Calculate how much WAL usage counters were increased by subtracting the
245 * previous counters from the current ones.
246 */
248
249#define WALSTAT_ACC(fld, var_to_add) \
250 (bktype_shstats->fld += var_to_add.fld)
251 WALSTAT_ACC(wal_buffers_full, wal_usage_diff);
252 WALSTAT_ACC(wal_records, wal_usage_diff);
253 WALSTAT_ACC(wal_fpi, wal_usage_diff);
254 WALSTAT_ACC(wal_bytes, wal_usage_diff);
255#undef WALSTAT_ACC
256
257 /*
258 * Save the current counters for the subsequent calculation of WAL usage.
259 */
261}
void WalUsageAccumDiff(WalUsage *dst, const WalUsage *add, const WalUsage *sub)
Definition: instrument.c:287
#define WALSTAT_ACC(fld, var_to_add)
PgStat_WalCounters wal_counters
Definition: pgstat.h:493

References pgstat_backend_wal_have_pending(), pgWalUsage, prevBackendWalUsage, PgStat_EntryRef::shared_stats, PgStatShared_Backend::stats, PgStat_Backend::wal_counters, WALSTAT_ACC, and WalUsageAccumDiff().

Referenced by pgstat_flush_backend().

pgstat_tracks_backend_bktype()

bool pgstat_tracks_backend_bktype ( BackendType  bktype )

Definition at line 365 of file pgstat_backend.c.

366{
367 /*
368 * List every type so that new backend types trigger a warning about
369 * needing to adjust this switch.
370 */
371 switch (bktype)
372 {
373 case B_INVALID:
376 case B_ARCHIVER:
377 case B_LOGGER:
378 case B_BG_WRITER:
379 case B_CHECKPOINTER:
380 case B_IO_WORKER:
381 case B_STARTUP:
382 return false;
383
384 case B_AUTOVAC_WORKER:
385 case B_BACKEND:
386 case B_BG_WORKER:
389 case B_WAL_RECEIVER:
390 case B_WAL_SENDER:
391 case B_WAL_SUMMARIZER:
392 case B_WAL_WRITER:
393 return true;
394 }
395
396 return false;
397}
@ B_WAL_SUMMARIZER
Definition: miscadmin.h:366
@ B_WAL_WRITER
Definition: miscadmin.h:367
@ B_WAL_RECEIVER
Definition: miscadmin.h:365
@ B_CHECKPOINTER
Definition: miscadmin.h:362
@ B_WAL_SENDER
Definition: miscadmin.h:346
@ B_IO_WORKER
Definition: miscadmin.h:363
@ B_LOGGER
Definition: miscadmin.h:373
@ B_STARTUP
Definition: miscadmin.h:364
@ B_BG_WORKER
Definition: miscadmin.h:345
@ 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_IO_WORKER, 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_reset_backend_stats(), pgstat_bestart_final(), pgstat_count_backend_io_op(), pgstat_count_backend_io_op_time(), pgstat_fetch_stat_backend_by_pid(), and pgstat_flush_backend().

Variable Documentation

backend_has_iostats

bool backend_has_iostats = false
static

Definition at line 41 of file pgstat_backend.c.

Referenced by pgstat_count_backend_io_op(), pgstat_count_backend_io_op_time(), pgstat_create_backend(), pgstat_flush_backend(), and pgstat_flush_backend_entry_io().

PendingBackendStats

PgStat_BackendPending PendingBackendStats
static

Definition at line 40 of file pgstat_backend.c.

Referenced by pgstat_count_backend_io_op(), pgstat_count_backend_io_op_time(), pgstat_create_backend(), and pgstat_flush_backend_entry_io().

prevBackendWalUsage

WalUsage prevBackendWalUsage
static

Definition at line 49 of file pgstat_backend.c.

Referenced by pgstat_backend_wal_have_pending(), pgstat_create_backend(), and pgstat_flush_backend_entry_wal().

AltStyle によって変換されたページ (->オリジナル) /