PostgreSQL Source Code git master
injection_stats_fixed.c File Reference
#include "postgres.h"
#include "fmgr.h"
#include "access/htup_details.h"
#include "common/hashfn.h"
#include "funcapi.h"
#include "injection_stats.h"
#include "pgstat.h"
#include "utils/builtins.h"
#include "utils/pgstat_internal.h"
Include dependency graph for injection_stats_fixed.c:

Go to the source code of this file.

Data Structures

struct  PgStat_StatInjFixedEntry
 
struct  PgStatShared_InjectionPointFixed
 

Macros

#define PGSTAT_KIND_INJECTION_FIXED   26
 
#define FIXED_COMP(fld)   stat_snap->fld -= reset.fld;
 

Typedefs

typedef struct PgStat_StatInjFixedEntry PgStat_StatInjFixedEntry
 
typedef struct PgStatShared_InjectionPointFixed PgStatShared_InjectionPointFixed
 

Functions

static void injection_stats_fixed_init_shmem_cb (void *stats)
 
static void injection_stats_fixed_reset_all_cb (TimestampTz ts)
 
static void injection_stats_fixed_snapshot_cb (void)
 
void pgstat_register_inj_fixed (void)
 
void pgstat_report_inj_fixed (uint32 numattach, uint32 numdetach, uint32 numrun, uint32 numcached, uint32 numloaded)
 
 PG_FUNCTION_INFO_V1 (injection_points_stats_fixed)
 
Datum injection_points_stats_fixed (PG_FUNCTION_ARGS)
 

Variables

static const PgStat_KindInfo injection_stats_fixed
 
static bool inj_fixed_loaded = false
 

Macro Definition Documentation

◆ FIXED_COMP

#define FIXED_COMP (   fld)    stat_snap->fld -= reset.fld;

◆ PGSTAT_KIND_INJECTION_FIXED

#define PGSTAT_KIND_INJECTION_FIXED   26

Definition at line 68 of file injection_stats_fixed.c.

Typedef Documentation

◆ PgStat_StatInjFixedEntry

◆ PgStatShared_InjectionPointFixed

Function Documentation

◆ injection_points_stats_fixed()

Datum injection_points_stats_fixed ( PG_FUNCTION_ARGS  )

Definition at line 174 of file injection_stats_fixed.c.

175{
176 TupleDesc tupdesc;
177 Datum values[5] = {0};
178 bool nulls[5] = {0};
180
183
186
187 /* Initialise attributes information in the tuple descriptor */
188 tupdesc = CreateTemplateTupleDesc(5);
189 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "numattach",
190 INT8OID, -1, 0);
191 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "numdetach",
192 INT8OID, -1, 0);
193 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "numrun",
194 INT8OID, -1, 0);
195 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "numcached",
196 INT8OID, -1, 0);
197 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "numloaded",
198 INT8OID, -1, 0);
199 BlessTupleDesc(tupdesc);
200
201 values[0] = Int64GetDatum(stats->numattach);
202 values[1] = Int64GetDatum(stats->numdetach);
203 values[2] = Int64GetDatum(stats->numrun);
204 values[3] = Int64GetDatum(stats->numcached);
205 values[4] = Int64GetDatum(stats->numloaded);
206 nulls[0] = false;
207 nulls[1] = false;
208 nulls[2] = false;
209 nulls[3] = false;
210 nulls[4] = false;
211
212 /* Returns the record as Datum */
214}
int16 AttrNumber
Definition: attnum.h:21
static Datum values[MAXATTR]
Definition: bootstrap.c:153
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2260
#define PG_RETURN_NULL()
Definition: fmgr.h:345
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
Definition: funcapi.h:230
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition: heaptuple.c:1117
bool inj_stats_enabled
static bool inj_fixed_loaded
#define PGSTAT_KIND_INJECTION_FIXED
void pgstat_snapshot_fixed(PgStat_Kind kind)
Definition: pgstat.c:1060
static void * pgstat_get_custom_snapshot_data(PgStat_Kind kind)
static Datum Int64GetDatum(int64 X)
Definition: postgres.h:403
uint64_t Datum
Definition: postgres.h:70
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:182
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:842

References BlessTupleDesc(), CreateTemplateTupleDesc(), heap_form_tuple(), HeapTupleGetDatum(), inj_fixed_loaded, inj_stats_enabled, Int64GetDatum(), PgStat_StatInjFixedEntry::numattach, PgStat_StatInjFixedEntry::numcached, PgStat_StatInjFixedEntry::numdetach, PgStat_StatInjFixedEntry::numloaded, PgStat_StatInjFixedEntry::numrun, PG_RETURN_DATUM, PG_RETURN_NULL, pgstat_get_custom_snapshot_data(), PGSTAT_KIND_INJECTION_FIXED, pgstat_snapshot_fixed(), TupleDescInitEntry(), and values.

◆ injection_stats_fixed_init_shmem_cb()

static void injection_stats_fixed_init_shmem_cb ( void *  stats)
static

Definition at line 74 of file injection_stats_fixed.c.

75{
78
79 LWLockInitialize(&stats_shmem->lock, LWTRANCHE_PGSTATS_DATA);
80}
void LWLockInitialize(LWLock *lock, int tranche_id)
Definition: lwlock.c:698

References PgStatShared_InjectionPointFixed::lock, and LWLockInitialize().

◆ injection_stats_fixed_reset_all_cb()

static void injection_stats_fixed_reset_all_cb ( TimestampTz  ts)
static

Definition at line 83 of file injection_stats_fixed.c.

84{
87
88 LWLockAcquire(&stats_shmem->lock, LW_EXCLUSIVE);
90 &stats_shmem->stats,
91 sizeof(stats_shmem->stats),
92 &stats_shmem->changecount);
93 stats_shmem->stats.stat_reset_timestamp = ts;
94 LWLockRelease(&stats_shmem->lock);
95}
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1174
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1894
@ LW_EXCLUSIVE
Definition: lwlock.h:112
static void * pgstat_get_custom_shmem_data(PgStat_Kind kind)
static void pgstat_copy_changecounted_stats(void *dst, void *src, size_t len, uint32 *cc)
PgStat_StatInjFixedEntry reset_offset

References PgStatShared_InjectionPointFixed::changecount, PgStatShared_InjectionPointFixed::lock, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), pgstat_copy_changecounted_stats(), pgstat_get_custom_shmem_data(), PGSTAT_KIND_INJECTION_FIXED, PgStatShared_InjectionPointFixed::reset_offset, PgStat_StatInjFixedEntry::stat_reset_timestamp, and PgStatShared_InjectionPointFixed::stats.

◆ injection_stats_fixed_snapshot_cb()

static void injection_stats_fixed_snapshot_cb ( void  )
static

Definition at line 98 of file injection_stats_fixed.c.

99{
102 PgStat_StatInjFixedEntry *stat_snap =
104 PgStat_StatInjFixedEntry *reset_offset = &stats_shmem->reset_offset;
106
108 &stats_shmem->stats,
109 sizeof(stats_shmem->stats),
110 &stats_shmem->changecount);
111
112 LWLockAcquire(&stats_shmem->lock, LW_SHARED);
113 memcpy(&reset, reset_offset, sizeof(stats_shmem->stats));
114 LWLockRelease(&stats_shmem->lock);
115
116 /* compensate by reset offsets */
117#define FIXED_COMP(fld) stat_snap->fld -= reset.fld;
118 FIXED_COMP(numattach);
119 FIXED_COMP(numdetach);
120 FIXED_COMP(numrun);
121 FIXED_COMP(numcached);
122 FIXED_COMP(numloaded);
123#undef FIXED_COMP
124}
#define FIXED_COMP(fld)
@ LW_SHARED
Definition: lwlock.h:113
void reset(void)
Definition: sql-declare.c:600

References PgStatShared_InjectionPointFixed::changecount, FIXED_COMP, PgStatShared_InjectionPointFixed::lock, LW_SHARED, LWLockAcquire(), LWLockRelease(), pgstat_copy_changecounted_stats(), pgstat_get_custom_shmem_data(), pgstat_get_custom_snapshot_data(), PGSTAT_KIND_INJECTION_FIXED, reset(), PgStatShared_InjectionPointFixed::reset_offset, and PgStatShared_InjectionPointFixed::stats.

◆ PG_FUNCTION_INFO_V1()

PG_FUNCTION_INFO_V1 ( injection_points_stats_fixed  )

◆ pgstat_register_inj_fixed()

void pgstat_register_inj_fixed ( void  )

Definition at line 130 of file injection_stats_fixed.c.

131{
133
134 /* mark stats as loaded */
135 inj_fixed_loaded = true;
136}
static const PgStat_KindInfo injection_stats_fixed
void pgstat_register_kind(PgStat_Kind kind, const PgStat_KindInfo *kind_info)
Definition: pgstat.c:1463

References inj_fixed_loaded, injection_stats_fixed, PGSTAT_KIND_INJECTION_FIXED, and pgstat_register_kind().

Referenced by _PG_init().

◆ pgstat_report_inj_fixed()

void pgstat_report_inj_fixed ( uint32  numattach,
uint32  numdetach,
uint32  numrun,
uint32  numcached,
uint32  numloaded 
)

Definition at line 142 of file injection_stats_fixed.c.

147{
149
150 /* leave if disabled */
152 return;
153
155
156 LWLockAcquire(&stats_shmem->lock, LW_EXCLUSIVE);
157
159 stats_shmem->stats.numattach += numattach;
160 stats_shmem->stats.numdetach += numdetach;
161 stats_shmem->stats.numrun += numrun;
162 stats_shmem->stats.numcached += numcached;
163 stats_shmem->stats.numloaded += numloaded;
165
166 LWLockRelease(&stats_shmem->lock);
167}
static void pgstat_end_changecount_write(uint32 *cc)
static void pgstat_begin_changecount_write(uint32 *cc)

References PgStatShared_InjectionPointFixed::changecount, inj_fixed_loaded, inj_stats_enabled, PgStatShared_InjectionPointFixed::lock, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), PgStat_StatInjFixedEntry::numattach, PgStat_StatInjFixedEntry::numcached, PgStat_StatInjFixedEntry::numdetach, PgStat_StatInjFixedEntry::numloaded, PgStat_StatInjFixedEntry::numrun, pgstat_begin_changecount_write(), pgstat_end_changecount_write(), pgstat_get_custom_shmem_data(), PGSTAT_KIND_INJECTION_FIXED, and PgStatShared_InjectionPointFixed::stats.

Referenced by injection_points_attach(), injection_points_attach_func(), injection_points_cached(), injection_points_detach(), injection_points_load(), and injection_points_run().

Variable Documentation

◆ inj_fixed_loaded

bool inj_fixed_loaded = false
static

◆ injection_stats_fixed

const PgStat_KindInfo injection_stats_fixed
static
Initial value:
= {
.name = "injection_points_fixed",
.fixed_amount = true,
.write_to_file = true,
.shared_size = sizeof(PgStat_StatInjFixedEntry),
.shared_data_off = offsetof(PgStatShared_InjectionPointFixed, stats),
.shared_data_len = sizeof(((PgStatShared_InjectionPointFixed *) 0)->stats),
}
struct PgStat_StatInjFixedEntry PgStat_StatInjFixedEntry
static void injection_stats_fixed_reset_all_cb(TimestampTz ts)
static void injection_stats_fixed_snapshot_cb(void)
static void injection_stats_fixed_init_shmem_cb(void *stats)

Definition at line 51 of file injection_stats_fixed.c.

Referenced by pgstat_register_inj_fixed().