PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pgstat_slru.c File Reference
#include "postgres.h"
#include "utils/pgstat_internal.h"
#include "utils/timestamp.h"
Include dependency graph for pgstat_slru.c:

Go to the source code of this file.

Macros

#define PGSTAT_COUNT_SLRU(stat)
 
#define SLRU_ACC(fld)   sharedent->fld += pendingent->fld
 

Functions

static PgStat_SLRUStatsget_slru_entry (int slru_idx)
 
static void pgstat_reset_slru_counter_internal (int index, TimestampTz ts)
 
void pgstat_reset_slru (const char *name)
 
PgStat_SLRUStatspgstat_fetch_slru (void)
 
const charpgstat_get_slru_name (int slru_idx)
 
int pgstat_get_slru_index (const char *name)
 
bool pgstat_slru_flush_cb (bool nowait)
 
void pgstat_slru_init_shmem_cb (void *stats)
 
void pgstat_slru_reset_all_cb (TimestampTz ts)
 
void pgstat_slru_snapshot_cb (void)
 

Variables

static PgStat_SLRUStats pending_SLRUStats [SLRU_NUM_ELEMENTS]
 
static bool have_slrustats = false
 

Macro Definition Documentation

◆ PGSTAT_COUNT_SLRU

#define PGSTAT_COUNT_SLRU (   stat)
Value:
{ \
get_slru_entry(slru_idx)->stat += 1; \
}
static int fb(int x)

Definition at line 58 of file pgstat_slru.c.

61{ \
62 get_slru_entry(slru_idx)->stat += 1; \
63}

◆ SLRU_ACC

#define SLRU_ACC (   fld)    sharedent->fld += pendingent->fld

Function Documentation

◆ get_slru_entry()

static PgStat_SLRUStats * get_slru_entry ( int  slru_idx)
inlinestatic

Definition at line 214 of file pgstat_slru.c.

215{
217
218 /*
219 * The postmaster should never register any SLRU statistics counts; if it
220 * did, the counts would be duplicated into child processes via fork().
221 */
223
225
226 have_slrustats = true;
227 pgstat_report_fixed = true;
228
230}
#define Assert(condition)
Definition c.h:873
bool IsUnderPostmaster
Definition globals.c:120
bool IsPostmasterEnvironment
Definition globals.c:119
bool pgstat_report_fixed
Definition pgstat.c:218
#define pgstat_assert_is_up()
#define SLRU_NUM_ELEMENTS
static bool have_slrustats
Definition pgstat_slru.c:35
static PgStat_SLRUStats pending_SLRUStats[SLRU_NUM_ELEMENTS]
Definition pgstat_slru.c:34

References Assert, fb(), have_slrustats, IsPostmasterEnvironment, IsUnderPostmaster, pending_SLRUStats, pgstat_assert_is_up, pgstat_report_fixed, and SLRU_NUM_ELEMENTS.

◆ pgstat_fetch_slru()

PgStat_SLRUStats * pgstat_fetch_slru ( void  )

Definition at line 91 of file pgstat_slru.c.

92{
94
96}
void pgstat_snapshot_fixed(PgStat_Kind kind)
Definition pgstat.c:1070
PgStat_LocalState pgStatLocal
Definition pgstat.c:212
#define PGSTAT_KIND_SLRU
Definition pgstat_kind.h:39
PgStat_Snapshot snapshot
PgStat_SLRUStats slru[SLRU_NUM_ELEMENTS]

References PGSTAT_KIND_SLRU, pgstat_snapshot_fixed(), pgStatLocal, PgStat_Snapshot::slru, and PgStat_LocalState::snapshot.

Referenced by pg_stat_get_slru().

◆ pgstat_get_slru_index()

int pgstat_get_slru_index ( const char name)

Definition at line 118 of file pgstat_slru.c.

119{
120 int i;
121
122 for (i = 0; i < SLRU_NUM_ELEMENTS; i++)
123 {
124 if (strcmp(slru_names[i], name) == 0)
125 return i;
126 }
127
128 /* return index of the last entry (which is the "other" one) */
129 return (SLRU_NUM_ELEMENTS - 1);
130}
int i
Definition isn.c:77
static const char *const slru_names[]
const char * name

References fb(), i, name, slru_names, and SLRU_NUM_ELEMENTS.

Referenced by pgstat_reset_slru(), and SimpleLruInit().

◆ pgstat_get_slru_name()

const char * pgstat_get_slru_name ( int  slru_idx)

Definition at line 104 of file pgstat_slru.c.

105{
107 return NULL;
108
109 return slru_names[slru_idx];
110}

References fb(), slru_names, and SLRU_NUM_ELEMENTS.

Referenced by pg_stat_get_slru().

◆ pgstat_reset_slru()

void pgstat_reset_slru ( const char name)

Definition at line 45 of file pgstat_slru.c.

46{
48
49 Assert(name != NULL);
50
52}
TimestampTz GetCurrentTimestamp(void)
Definition timestamp.c:1645
int64 TimestampTz
Definition timestamp.h:39
int pgstat_get_slru_index(const char *name)
static void pgstat_reset_slru_counter_internal(int index, TimestampTz ts)

References Assert, fb(), GetCurrentTimestamp(), name, pgstat_get_slru_index(), and pgstat_reset_slru_counter_internal().

Referenced by pg_stat_reset_slru().

◆ pgstat_reset_slru_counter_internal()

static void pgstat_reset_slru_counter_internal ( int  index,
TimestampTz  ts 
)
static

Definition at line 233 of file pgstat_slru.c.

234{
236
238
239 memset(&stats_shmem->stats[index], 0, sizeof(PgStat_SLRUStats));
240 stats_shmem->stats[index].stat_reset_timestamp = ts;
241
243}
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition lwlock.c:1176
void LWLockRelease(LWLock *lock)
Definition lwlock.c:1793
@ LW_EXCLUSIVE
Definition lwlock.h:112
PgStat_ShmemControl * shmem
PgStatShared_SLRU slru
Definition type.h:96

References fb(), LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), pgStatLocal, PgStat_LocalState::shmem, and PgStat_ShmemControl::slru.

Referenced by pgstat_reset_slru(), and pgstat_slru_reset_all_cb().

◆ pgstat_slru_flush_cb()

bool pgstat_slru_flush_cb ( bool  nowait)

Definition at line 142 of file pgstat_slru.c.

143{
145 int i;
146
147 if (!have_slrustats)
148 return false;
149
150 if (!nowait)
153 return true;
154
155 for (i = 0; i < SLRU_NUM_ELEMENTS; i++)
156 {
159
160#define SLRU_ACC(fld) sharedent->fld += pendingent->fld
161 SLRU_ACC(blocks_zeroed);
162 SLRU_ACC(blocks_hit);
163 SLRU_ACC(blocks_read);
165 SLRU_ACC(blocks_exists);
166 SLRU_ACC(flush);
167 SLRU_ACC(truncate);
168#undef SLRU_ACC
169 }
170
171 /* done, clear the pending entry */
173
175
176 have_slrustats = false;
177
178 return false;
179}
#define MemSet(start, val, len)
Definition c.h:1013
bool LWLockConditionalAcquire(LWLock *lock, LWLockMode mode)
Definition lwlock.c:1347
static int64 blocks_written
#define SLRU_ACC(fld)

References blocks_written, fb(), have_slrustats, i, LW_EXCLUSIVE, LWLockAcquire(), LWLockConditionalAcquire(), LWLockRelease(), MemSet, pending_SLRUStats, pgStatLocal, PgStat_LocalState::shmem, PgStat_ShmemControl::slru, SLRU_ACC, and SLRU_NUM_ELEMENTS.

◆ pgstat_slru_init_shmem_cb()

void pgstat_slru_init_shmem_cb ( void stats)

Definition at line 182 of file pgstat_slru.c.

183{
185
187}
void LWLockInitialize(LWLock *lock, int tranche_id)
Definition lwlock.c:698

References fb(), and LWLockInitialize().

◆ pgstat_slru_reset_all_cb()

void pgstat_slru_reset_all_cb ( TimestampTz  ts)

Definition at line 190 of file pgstat_slru.c.

191{
192 for (int i = 0; i < SLRU_NUM_ELEMENTS; i++)
194}

References i, pgstat_reset_slru_counter_internal(), and SLRU_NUM_ELEMENTS.

◆ pgstat_slru_snapshot_cb()

Variable Documentation

◆ have_slrustats

bool have_slrustats = false
static

Definition at line 35 of file pgstat_slru.c.

Referenced by get_slru_entry(), and pgstat_slru_flush_cb().

◆ pending_SLRUStats

PgStat_SLRUStats pending_SLRUStats[SLRU_NUM_ELEMENTS]
static

Definition at line 34 of file pgstat_slru.c.

Referenced by get_slru_entry(), and pgstat_slru_flush_cb().