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

216{
218
219 /*
220 * The postmaster should never register any SLRU statistics counts; if it
221 * did, the counts would be duplicated into child processes via fork().
222 */
224
226
227 have_slrustats = true;
228 pgstat_report_fixed = true;
229
231}
#define Assert(condition)
Definition c.h:943
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:1639
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 234 of file pgstat_slru.c.

235{
237
239
240 memset(&stats_shmem->stats[index], 0, sizeof(PgStat_SLRUStats));
241 stats_shmem->stats[index].stat_reset_timestamp = ts;
242
244}
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: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 143 of file pgstat_slru.c.

144{
146 int i;
147
148 if (!have_slrustats)
149 return false;
150
151 if (!nowait)
154 return true;
155
156 for (i = 0; i < SLRU_NUM_ELEMENTS; i++)
157 {
160
161#define SLRU_ACC(fld) sharedent->fld += pendingent->fld
162 SLRU_ACC(blocks_zeroed);
163 SLRU_ACC(blocks_hit);
164 SLRU_ACC(blocks_read);
166 SLRU_ACC(blocks_exists);
167 SLRU_ACC(flush);
168 SLRU_ACC(truncate);
169#undef SLRU_ACC
170 }
171
172 /* done, clear the pending entry */
174
176
177 have_slrustats = false;
178
179 return false;
180}
#define MemSet(start, val, len)
Definition c.h:1107
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 183 of file pgstat_slru.c.

184{
186
188}
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 191 of file pgstat_slru.c.

192{
193 for (int i = 0; i < SLRU_NUM_ELEMENTS; i++)
195}

References i, pgstat_reset_slru_counter_internal(), and SLRU_NUM_ELEMENTS.

◆ pgstat_slru_snapshot_cb()

void pgstat_slru_snapshot_cb ( void  )

Definition at line 198 of file pgstat_slru.c.

199{
201
203
205 sizeof(stats_shmem->stats));
206
208}
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().