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

Go to the source code of this file.

Macros

#define BGWRITER_ACC(fld)   stats_shmem->stats.fld += PendingBgWriterStats.fld
 
#define BGWRITER_COMP(fld)   pgStatLocal.snapshot.bgwriter.fld -= reset.fld;
 

Functions

void pgstat_report_bgwriter (void)
 
PgStat_BgWriterStatspgstat_fetch_stat_bgwriter (void)
 
void pgstat_bgwriter_init_shmem_cb (void *stats)
 
void pgstat_bgwriter_reset_all_cb (TimestampTz ts)
 
void pgstat_bgwriter_snapshot_cb (void)
 

Variables

PgStat_BgWriterStats PendingBgWriterStats = {0}
 

Macro Definition Documentation

◆ BGWRITER_ACC

#define BGWRITER_ACC (   fld)    stats_shmem->stats.fld += PendingBgWriterStats.fld

◆ BGWRITER_COMP

#define BGWRITER_COMP (   fld)    pgStatLocal.snapshot.bgwriter.fld -= reset.fld;

Function Documentation

◆ pgstat_bgwriter_init_shmem_cb()

void pgstat_bgwriter_init_shmem_cb ( void *  stats)

Definition at line 80 of file pgstat_bgwriter.c.

81 {
82  PgStatShared_BgWriter *stats_shmem = (PgStatShared_BgWriter *) stats;
83 
85 }
void LWLockInitialize(LWLock *lock, int tranche_id)
Definition: lwlock.c:707
@ LWTRANCHE_PGSTATS_DATA
Definition: lwlock.h:205

References PgStatShared_BgWriter::lock, LWLockInitialize(), and LWTRANCHE_PGSTATS_DATA.

◆ pgstat_bgwriter_reset_all_cb()

void pgstat_bgwriter_reset_all_cb ( TimestampTz  ts)

Definition at line 88 of file pgstat_bgwriter.c.

89 {
91 
92  /* see explanation above PgStatShared_BgWriter for the reset protocol */
93  LWLockAcquire(&stats_shmem->lock, LW_EXCLUSIVE);
95  &stats_shmem->stats,
96  sizeof(stats_shmem->stats),
97  &stats_shmem->changecount);
98  stats_shmem->stats.stat_reset_timestamp = ts;
99  LWLockRelease(&stats_shmem->lock);
100 }
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1168
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1781
@ LW_EXCLUSIVE
Definition: lwlock.h:114
PgStat_LocalState pgStatLocal
Definition: pgstat.c:212
static void pgstat_copy_changecounted_stats(void *dst, void *src, size_t len, uint32 *cc)
PgStat_BgWriterStats reset_offset
PgStat_BgWriterStats stats
TimestampTz stat_reset_timestamp
Definition: pgstat.h:290
PgStat_ShmemControl * shmem
PgStatShared_BgWriter bgwriter

References PgStat_ShmemControl::bgwriter, PgStatShared_BgWriter::changecount, PgStatShared_BgWriter::lock, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), pgstat_copy_changecounted_stats(), pgStatLocal, PgStatShared_BgWriter::reset_offset, PgStat_LocalState::shmem, PgStat_BgWriterStats::stat_reset_timestamp, and PgStatShared_BgWriter::stats.

◆ pgstat_bgwriter_snapshot_cb()

void pgstat_bgwriter_snapshot_cb ( void  )

Definition at line 103 of file pgstat_bgwriter.c.

104 {
106  PgStat_BgWriterStats *reset_offset = &stats_shmem->reset_offset;
108 
110  &stats_shmem->stats,
111  sizeof(stats_shmem->stats),
112  &stats_shmem->changecount);
113 
114  LWLockAcquire(&stats_shmem->lock, LW_SHARED);
115  memcpy(&reset, reset_offset, sizeof(stats_shmem->stats));
116  LWLockRelease(&stats_shmem->lock);
117 
118  /* compensate by reset offsets */
119 #define BGWRITER_COMP(fld) pgStatLocal.snapshot.bgwriter.fld -= reset.fld;
120  BGWRITER_COMP(buf_written_clean);
121  BGWRITER_COMP(maxwritten_clean);
122  BGWRITER_COMP(buf_alloc);
123 #undef BGWRITER_COMP
124 }
@ LW_SHARED
Definition: lwlock.h:115
#define BGWRITER_COMP(fld)
void reset(void)
Definition: sql-declare.c:600
PgStat_Snapshot snapshot
PgStat_BgWriterStats bgwriter

References PgStat_ShmemControl::bgwriter, PgStat_Snapshot::bgwriter, BGWRITER_COMP, PgStatShared_BgWriter::changecount, PgStatShared_BgWriter::lock, LW_SHARED, LWLockAcquire(), LWLockRelease(), pgstat_copy_changecounted_stats(), pgStatLocal, reset(), PgStatShared_BgWriter::reset_offset, PgStat_LocalState::shmem, PgStat_LocalState::snapshot, and PgStatShared_BgWriter::stats.

◆ pgstat_fetch_stat_bgwriter()

◆ pgstat_report_bgwriter()

void pgstat_report_bgwriter ( void  )

Definition at line 31 of file pgstat_bgwriter.c.

32 {
34 
37 
38  /*
39  * This function can be called even if nothing at all has happened. In
40  * this case, avoid unnecessarily modifying the stats entry.
41  */
43  sizeof(struct PgStat_BgWriterStats)))
44  return;
45 
47 
48 #define BGWRITER_ACC(fld) stats_shmem->stats.fld += PendingBgWriterStats.fld
49  BGWRITER_ACC(buf_written_clean);
50  BGWRITER_ACC(maxwritten_clean);
51  BGWRITER_ACC(buf_alloc);
52 #undef BGWRITER_ACC
53 
55 
56  /*
57  * Clear out the statistics buffer, so it can be re-used.
58  */
60 
61  /*
62  * Report IO statistics
63  */
64  pgstat_flush_io(false);
65 }
#define Assert(condition)
Definition: c.h:837
#define MemSet(start, val, len)
Definition: c.h:999
static bool pg_memory_is_all_zeros(const void *ptr, size_t len)
Definition: memutils.h:219
#define BGWRITER_ACC(fld)
PgStat_BgWriterStats PendingBgWriterStats
static void pgstat_end_changecount_write(uint32 *cc)
#define pgstat_assert_is_up()
static void pgstat_begin_changecount_write(uint32 *cc)
void pgstat_flush_io(bool nowait)
Definition: pgstat_io.c:177

References Assert, PgStat_ShmemControl::bgwriter, BGWRITER_ACC, PgStatShared_BgWriter::changecount, PgStat_ShmemControl::is_shutdown, MemSet, PendingBgWriterStats, pg_memory_is_all_zeros(), pgstat_assert_is_up, pgstat_begin_changecount_write(), pgstat_end_changecount_write(), pgstat_flush_io(), pgStatLocal, and PgStat_LocalState::shmem.

Referenced by BackgroundWriterMain().

Variable Documentation

◆ PendingBgWriterStats

PgStat_BgWriterStats PendingBgWriterStats = {0}

Definition at line 24 of file pgstat_bgwriter.c.

Referenced by BgBufferSync(), and pgstat_report_bgwriter().