PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 67 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 169 of file injection_stats_fixed.c.

170{
171 TupleDesc tupdesc;
172 Datum values[5] = {0};
173 bool nulls[5] = {0};
175
178
181
182 /* Initialise attributes information in the tuple descriptor */
183 tupdesc = CreateTemplateTupleDesc(5);
184 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "numattach",
185 INT8OID, -1, 0);
186 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "numdetach",
187 INT8OID, -1, 0);
188 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "numrun",
189 INT8OID, -1, 0);
190 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "numcached",
191 INT8OID, -1, 0);
192 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "numloaded",
193 INT8OID, -1, 0);
194 BlessTupleDesc(tupdesc);
195
196 values[0] = Int64GetDatum(stats->numattach);
197 values[1] = Int64GetDatum(stats->numdetach);
198 values[2] = Int64GetDatum(stats->numrun);
199 values[3] = Int64GetDatum(stats->numcached);
200 values[4] = Int64GetDatum(stats->numloaded);
201 nulls[0] = false;
202 nulls[1] = false;
203 nulls[2] = false;
204 nulls[3] = false;
205 nulls[4] = false;
206
207 /* Returns the record as Datum */
209}
int16 AttrNumber
Definition: attnum.h:21
static Datum values[MAXATTR]
Definition: bootstrap.c:151
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2260
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: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:1078
static void * pgstat_get_custom_snapshot_data(PgStat_Kind kind)
uintptr_t Datum
Definition: postgres.h:69
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:164
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:801

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

◆ injection_stats_fixed_reset_all_cb()

static void injection_stats_fixed_reset_all_cb ( TimestampTz  ts)
static

Definition at line 82 of file injection_stats_fixed.c.

83{
86
87 LWLockAcquire(&stats_shmem->lock, LW_EXCLUSIVE);
89 &stats_shmem->stats,
90 sizeof(stats_shmem->stats),
91 &stats_shmem->changecount);
92 stats_shmem->stats.stat_reset_timestamp = ts;
93 LWLockRelease(&stats_shmem->lock);
94}
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1180
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1900
@ 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 97 of file injection_stats_fixed.c.

98{
101 PgStat_StatInjFixedEntry *stat_snap =
103 PgStat_StatInjFixedEntry *reset_offset = &stats_shmem->reset_offset;
105
107 &stats_shmem->stats,
108 sizeof(stats_shmem->stats),
109 &stats_shmem->changecount);
110
111 LWLockAcquire(&stats_shmem->lock, LW_SHARED);
112 memcpy(&reset, reset_offset, sizeof(stats_shmem->stats));
113 LWLockRelease(&stats_shmem->lock);
114
115 /* compensate by reset offsets */
116#define FIXED_COMP(fld) stat_snap->fld -= reset.fld;
117 FIXED_COMP(numattach);
118 FIXED_COMP(numdetach);
119 FIXED_COMP(numrun);
120 FIXED_COMP(numcached);
121 FIXED_COMP(numloaded);
122#undef FIXED_COMP
123}
#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 129 of file injection_stats_fixed.c.

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

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 
)

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

Referenced by pgstat_register_inj_fixed().