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 212 of file pgstat_slru.c.

213{
215
216 /*
217 * The postmaster should never register any SLRU statistics counts; if it
218 * did, the counts would be duplicated into child processes via fork().
219 */
221
223
224 have_slrustats = true;
225 pgstat_report_fixed = true;
226
228}
#define Assert(condition)
Definition c.h:999
bool IsUnderPostmaster
Definition globals.c:122
bool IsPostmasterEnvironment
Definition globals.c:121
bool pgstat_report_fixed
Definition pgstat.c:219
#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:1104
PgStat_LocalState pgStatLocal
Definition pgstat.c:213
#define PGSTAT_KIND_SLRU
Definition pgstat_kind.h:40
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 Assert(name);
123 for (i = 0; i < SLRU_NUM_ELEMENTS; i++)
124 {
125 if (strcmp(slru_names[i], name) == 0)
126 return i;
127 }
128
129 /* return index of the last entry (which is the "other" one) */
130 return (SLRU_NUM_ELEMENTS - 1);
131}
int i
Definition isn.c:77
static const char *const slru_names[]
const char * name

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

Referenced by pgstat_reset_slru(), and shmem_slru_init().

◆ 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:1649
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 231 of file pgstat_slru.c.

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

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 140 of file pgstat_slru.c.

141{
143 int i;
144
145 if (!have_slrustats)
146 return false;
147
148 if (!nowait)
151 return true;
152
153 for (i = 0; i < SLRU_NUM_ELEMENTS; i++)
154 {
157
158#define SLRU_ACC(fld) sharedent->fld += pendingent->fld
159 SLRU_ACC(blocks_zeroed);
160 SLRU_ACC(blocks_hit);
161 SLRU_ACC(blocks_read);
163 SLRU_ACC(blocks_exists);
164 SLRU_ACC(flush);
165 SLRU_ACC(truncate);
166#undef SLRU_ACC
167 }
168
169 /* done, clear the pending entry */
171
173
174 have_slrustats = false;
175
176 return false;
177}
#define MemSet(start, val, len)
Definition c.h:1163
bool LWLockConditionalAcquire(LWLock *lock, LWLockMode mode)
Definition lwlock.c:1321
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 180 of file pgstat_slru.c.

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

References fb(), and LWLockInitialize().

◆ pgstat_slru_reset_all_cb()

void pgstat_slru_reset_all_cb ( TimestampTz  ts)

Definition at line 188 of file pgstat_slru.c.

189{
190 for (int i = 0; i < SLRU_NUM_ELEMENTS; i++)
192}

References i, pgstat_reset_slru_counter_internal(), and SLRU_NUM_ELEMENTS.

◆ pgstat_slru_snapshot_cb()

void pgstat_slru_snapshot_cb ( void  )

Definition at line 195 of file pgstat_slru.c.

196{
198
200
202 sizeof(stats_shmem->stats));
203
205}
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
@ LW_SHARED
Definition lwlock.h:105

References fb(), LW_SHARED, LWLockAcquire(), LWLockRelease(), memcpy(), pgStatLocal, PgStat_LocalState::shmem, PgStat_ShmemControl::slru, PgStat_Snapshot::slru, and PgStat_LocalState::snapshot.

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().