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

Go to the source code of this file.

Data Structures

struct  PgStat_StatInjEntry
 
struct  PgStatShared_InjectionPoint
 

Macros

#define PGSTAT_INJ_IDX(name)   hash_bytes_extended((const unsigned char *) name, strlen(name), 0)
 
#define PGSTAT_KIND_INJECTION   129
 

Typedefs

typedef struct PgStat_StatInjEntry PgStat_StatInjEntry
 
typedef struct PgStatShared_InjectionPoint PgStatShared_InjectionPoint
 

Functions

static bool injection_stats_flush_cb (PgStat_EntryRef *entry_ref, bool nowait)
 
static PgStat_StatInjEntrypgstat_fetch_stat_injentry (const char *name)
 
void pgstat_register_inj (void)
 
void pgstat_create_inj (const char *name)
 
void pgstat_drop_inj (const char *name)
 
void pgstat_report_inj (const char *name)
 
 PG_FUNCTION_INFO_V1 (injection_points_stats_numcalls)
 
Datum injection_points_stats_numcalls (PG_FUNCTION_ARGS)
 

Variables

static const PgStat_KindInfo injection_stats
 
static bool inj_stats_loaded = false
 

Macro Definition Documentation

◆ PGSTAT_INJ_IDX

#define PGSTAT_INJ_IDX (   name)    hash_bytes_extended((const unsigned char *) name, strlen(name), 0)

Definition at line 57 of file injection_stats.c.

◆ PGSTAT_KIND_INJECTION

#define PGSTAT_KIND_INJECTION   129

Definition at line 62 of file injection_stats.c.

Typedef Documentation

◆ PgStat_StatInjEntry

◆ PgStatShared_InjectionPoint

Function Documentation

◆ injection_points_stats_numcalls()

Datum injection_points_stats_numcalls ( PG_FUNCTION_ARGS  )

Definition at line 189 of file injection_stats.c.

190 {
193 
194  if (entry == NULL)
195  PG_RETURN_NULL();
196 
197  PG_RETURN_INT64(entry->numcalls);
198 }
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define PG_RETURN_INT64(x)
Definition: fmgr.h:368
#define PG_RETURN_NULL()
Definition: fmgr.h:345
static PgStat_StatInjEntry * pgstat_fetch_stat_injentry(const char *name)
PgStat_Counter numcalls
char * text_to_cstring(const text *t)
Definition: varlena.c:217
const char * name

References name, PgStat_StatInjEntry::numcalls, PG_GETARG_TEXT_PP, PG_RETURN_INT64, PG_RETURN_NULL, pgstat_fetch_stat_injentry(), and text_to_cstring().

◆ injection_stats_flush_cb()

static bool injection_stats_flush_cb ( PgStat_EntryRef entry_ref,
bool  nowait 
)
static

Definition at line 71 of file injection_stats.c.

72 {
73  PgStat_StatInjEntry *localent;
74  PgStatShared_InjectionPoint *shfuncent;
75 
76  localent = (PgStat_StatInjEntry *) entry_ref->pending;
77  shfuncent = (PgStatShared_InjectionPoint *) entry_ref->shared_stats;
78 
79  if (!pgstat_lock_entry(entry_ref, nowait))
80  return false;
81 
82  shfuncent->stats.numcalls += localent->numcalls;
83  return true;
84 }
bool pgstat_lock_entry(PgStat_EntryRef *entry_ref, bool nowait)
Definition: pgstat_shmem.c:647
PgStat_StatInjEntry stats
PgStatShared_Common * shared_stats

References PgStat_StatInjEntry::numcalls, PgStat_EntryRef::pending, pgstat_lock_entry(), PgStat_EntryRef::shared_stats, and PgStatShared_InjectionPoint::stats.

◆ PG_FUNCTION_INFO_V1()

PG_FUNCTION_INFO_V1 ( injection_points_stats_numcalls  )

◆ pgstat_create_inj()

void pgstat_create_inj ( const char *  name)

Definition at line 121 of file injection_stats.c.

122 {
123  PgStat_EntryRef *entry_ref;
124  PgStatShared_InjectionPoint *shstatent;
125 
126  /* leave if disabled */
128  return;
129 
131  PGSTAT_INJ_IDX(name), false);
132  shstatent = (PgStatShared_InjectionPoint *) entry_ref->shared_stats;
133 
134  /* initialize shared memory data */
135  memset(&shstatent->stats, 0, sizeof(shstatent->stats));
136  pgstat_unlock_entry(entry_ref);
137 }
bool inj_stats_enabled
static bool inj_stats_loaded
#define PGSTAT_INJ_IDX(name)
#define PGSTAT_KIND_INJECTION
void pgstat_unlock_entry(PgStat_EntryRef *entry_ref)
Definition: pgstat_shmem.c:675
PgStat_EntryRef * pgstat_get_entry_ref_locked(PgStat_Kind kind, Oid dboid, uint64 objid, bool nowait)
Definition: pgstat_shmem.c:684
#define InvalidOid
Definition: postgres_ext.h:36

References inj_stats_enabled, inj_stats_loaded, InvalidOid, name, pgstat_get_entry_ref_locked(), PGSTAT_INJ_IDX, PGSTAT_KIND_INJECTION, pgstat_unlock_entry(), PgStat_EntryRef::shared_stats, and PgStatShared_InjectionPoint::stats.

Referenced by injection_points_attach().

◆ pgstat_drop_inj()

void pgstat_drop_inj ( const char *  name)

Definition at line 143 of file injection_stats.c.

144 {
145  /* leave if disabled */
147  return;
148 
152 }
void pgstat_request_entry_refs_gc(void)
Definition: pgstat_shmem.c:700
bool pgstat_drop_entry(PgStat_Kind kind, Oid dboid, uint64 objid)
Definition: pgstat_shmem.c:946

References inj_stats_enabled, inj_stats_loaded, InvalidOid, name, pgstat_drop_entry(), PGSTAT_INJ_IDX, PGSTAT_KIND_INJECTION, and pgstat_request_entry_refs_gc().

Referenced by injection_points_cleanup(), and injection_points_detach().

◆ pgstat_fetch_stat_injentry()

static PgStat_StatInjEntry* pgstat_fetch_stat_injentry ( const char *  name)
static

Definition at line 91 of file injection_stats.c.

92 {
93  PgStat_StatInjEntry *entry = NULL;
94 
96  return NULL;
97 
98  /* Compile the lookup key as a hash of the point name */
100  InvalidOid,
102  return entry;
103 }
void * pgstat_fetch_entry(PgStat_Kind kind, Oid dboid, uint64 objid)
Definition: pgstat.c:939

References inj_stats_enabled, inj_stats_loaded, InvalidOid, name, pgstat_fetch_entry(), PGSTAT_INJ_IDX, and PGSTAT_KIND_INJECTION.

Referenced by injection_points_stats_numcalls().

◆ pgstat_register_inj()

void pgstat_register_inj ( void  )

Definition at line 109 of file injection_stats.c.

110 {
112 
113  /* mark stats as loaded */
114  inj_stats_loaded = true;
115 }
static const PgStat_KindInfo injection_stats
void pgstat_register_kind(PgStat_Kind kind, const PgStat_KindInfo *kind_info)
Definition: pgstat.c:1472

References inj_stats_loaded, injection_stats, PGSTAT_KIND_INJECTION, and pgstat_register_kind().

Referenced by _PG_init().

◆ pgstat_report_inj()

void pgstat_report_inj ( const char *  name)

Definition at line 161 of file injection_stats.c.

162 {
163  PgStat_EntryRef *entry_ref;
164  PgStatShared_InjectionPoint *shstatent;
165  PgStat_StatInjEntry *statent;
166 
167  /* leave if disabled */
169  return;
170 
172  PGSTAT_INJ_IDX(name), false);
173 
174  shstatent = (PgStatShared_InjectionPoint *) entry_ref->shared_stats;
175  statent = &shstatent->stats;
176 
177  /* Update the injection point statistics */
178  statent->numcalls++;
179 
180  pgstat_unlock_entry(entry_ref);
181 }

References inj_stats_enabled, inj_stats_loaded, InvalidOid, name, PgStat_StatInjEntry::numcalls, pgstat_get_entry_ref_locked(), PGSTAT_INJ_IDX, PGSTAT_KIND_INJECTION, pgstat_unlock_entry(), PgStat_EntryRef::shared_stats, and PgStatShared_InjectionPoint::stats.

Referenced by injection_error(), injection_notice(), and injection_wait().

Variable Documentation

◆ inj_stats_loaded

bool inj_stats_loaded = false
static

◆ injection_stats

const PgStat_KindInfo injection_stats
static
Initial value:
= {
.name = "injection_points",
.fixed_amount = false,
.write_to_file = true,
.accessed_across_databases = true,
.shared_size = sizeof(PgStatShared_InjectionPoint),
.shared_data_off = offsetof(PgStatShared_InjectionPoint, stats),
.shared_data_len = sizeof(((PgStatShared_InjectionPoint *) 0)->stats),
.pending_size = sizeof(PgStat_StatInjEntry),
.flush_pending_cb = injection_stats_flush_cb,
}
static bool injection_stats_flush_cb(PgStat_EntryRef *entry_ref, bool nowait)
struct PgStatShared_InjectionPoint PgStatShared_InjectionPoint

Definition at line 39 of file injection_stats.c.

Referenced by pgstat_register_inj().