PostgreSQL Source Code  git master
injection_stats_fixed.c File Reference
#include "postgres.h"
#include "fmgr.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   130
 
#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   130

Definition at line 66 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 168 of file injection_stats_fixed.c.

169 {
170  TupleDesc tupdesc;
171  Datum values[5] = {0};
172  bool nulls[5] = {0};
174 
176  PG_RETURN_NULL();
177 
180 
181  /* Initialise attributes information in the tuple descriptor */
182  tupdesc = CreateTemplateTupleDesc(5);
183  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "numattach",
184  INT8OID, -1, 0);
185  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "numdetach",
186  INT8OID, -1, 0);
187  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "numrun",
188  INT8OID, -1, 0);
189  TupleDescInitEntry(tupdesc, (AttrNumber) 4, "numcached",
190  INT8OID, -1, 0);
191  TupleDescInitEntry(tupdesc, (AttrNumber) 5, "numloaded",
192  INT8OID, -1, 0);
193  BlessTupleDesc(tupdesc);
194 
195  values[0] = Int64GetDatum(stats->numattach);
196  values[1] = Int64GetDatum(stats->numdetach);
197  values[2] = Int64GetDatum(stats->numrun);
198  values[3] = Int64GetDatum(stats->numcached);
199  values[4] = Int64GetDatum(stats->numloaded);
200  nulls[0] = false;
201  nulls[1] = false;
202  nulls[2] = false;
203  nulls[3] = false;
204  nulls[4] = false;
205 
206  /* Returns the record as Datum */
208 }
int16 AttrNumber
Definition: attnum.h:21
static Datum values[MAXATTR]
Definition: bootstrap.c:150
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2158
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1807
#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:1116
bool inj_stats_enabled
static bool inj_fixed_loaded
#define PGSTAT_KIND_INJECTION_FIXED
void pgstat_snapshot_fixed(PgStat_Kind kind)
Definition: pgstat.c:1054
static void * pgstat_get_custom_snapshot_data(PgStat_Kind kind)
uintptr_t Datum
Definition: postgres.h:64
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:67
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:651

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 72 of file injection_stats_fixed.c.

73 {
76 
78 }
void LWLockInitialize(LWLock *lock, int tranche_id)
Definition: lwlock.c:707
@ LWTRANCHE_PGSTATS_DATA
Definition: lwlock.h:205

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

◆ injection_stats_fixed_reset_all_cb()

static void injection_stats_fixed_reset_all_cb ( TimestampTz  ts)
static

Definition at line 81 of file injection_stats_fixed.c.

82 {
85 
86  LWLockAcquire(&stats_shmem->lock, LW_EXCLUSIVE);
88  &stats_shmem->stats,
89  sizeof(stats_shmem->stats),
90  &stats_shmem->changecount);
91  stats_shmem->stats.stat_reset_timestamp = ts;
92  LWLockRelease(&stats_shmem->lock);
93 }
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1168
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1781
@ LW_EXCLUSIVE
Definition: lwlock.h:114
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 96 of file injection_stats_fixed.c.

97 {
100  PgStat_StatInjFixedEntry *stat_snap =
102  PgStat_StatInjFixedEntry *reset_offset = &stats_shmem->reset_offset;
104 
106  &stats_shmem->stats,
107  sizeof(stats_shmem->stats),
108  &stats_shmem->changecount);
109 
110  LWLockAcquire(&stats_shmem->lock, LW_SHARED);
111  memcpy(&reset, reset_offset, sizeof(stats_shmem->stats));
112  LWLockRelease(&stats_shmem->lock);
113 
114  /* compensate by reset offsets */
115 #define FIXED_COMP(fld) stat_snap->fld -= reset.fld;
116  FIXED_COMP(numattach);
117  FIXED_COMP(numdetach);
118  FIXED_COMP(numrun);
119  FIXED_COMP(numcached);
120  FIXED_COMP(numloaded);
121 #undef FIXED_COMP
122 }
#define FIXED_COMP(fld)
@ LW_SHARED
Definition: lwlock.h:115
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 128 of file injection_stats_fixed.c.

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

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

145 {
147 
148  /* leave if disabled */
150  return;
151 
153 
155  stats_shmem->stats.numattach += numattach;
156  stats_shmem->stats.numdetach += numdetach;
157  stats_shmem->stats.numrun += numrun;
158  stats_shmem->stats.numcached += numcached;
159  stats_shmem->stats.numloaded += numloaded;
161 }
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, 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_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,
.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 50 of file injection_stats_fixed.c.

Referenced by pgstat_register_inj_fixed().