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 56 of file injection_stats.c.

◆ PGSTAT_KIND_INJECTION

#define PGSTAT_KIND_INJECTION   129

Definition at line 61 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 188 of file injection_stats.c.

189 {
192 
193  if (entry == NULL)
194  PG_RETURN_NULL();
195 
196  PG_RETURN_INT64(entry->numcalls);
197 }
#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 70 of file injection_stats.c.

71 {
72  PgStat_StatInjEntry *localent;
73  PgStatShared_InjectionPoint *shfuncent;
74 
75  localent = (PgStat_StatInjEntry *) entry_ref->pending;
76  shfuncent = (PgStatShared_InjectionPoint *) entry_ref->shared_stats;
77 
78  if (!pgstat_lock_entry(entry_ref, nowait))
79  return false;
80 
81  shfuncent->stats.numcalls += localent->numcalls;
82  return true;
83 }
bool pgstat_lock_entry(PgStat_EntryRef *entry_ref, bool nowait)
Definition: pgstat_shmem.c:610
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 120 of file injection_stats.c.

121 {
122  PgStat_EntryRef *entry_ref;
123  PgStatShared_InjectionPoint *shstatent;
124 
125  /* leave if disabled */
127  return;
128 
130  PGSTAT_INJ_IDX(name), false);
131  shstatent = (PgStatShared_InjectionPoint *) entry_ref->shared_stats;
132 
133  /* initialize shared memory data */
134  memset(&shstatent->stats, 0, sizeof(shstatent->stats));
135  pgstat_unlock_entry(entry_ref);
136 }
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:638
PgStat_EntryRef * pgstat_get_entry_ref_locked(PgStat_Kind kind, Oid dboid, uint64 objid, bool nowait)
Definition: pgstat_shmem.c:647
#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 142 of file injection_stats.c.

143 {
144  /* leave if disabled */
146  return;
147 
151 }
void pgstat_request_entry_refs_gc(void)
Definition: pgstat_shmem.c:663
bool pgstat_drop_entry(PgStat_Kind kind, Oid dboid, uint64 objid)
Definition: pgstat_shmem.c:909

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 90 of file injection_stats.c.

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

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 108 of file injection_stats.c.

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

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 160 of file injection_stats.c.

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

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

◆ injection_stats

const PgStat_KindInfo injection_stats
static
Initial value:
= {
.name = "injection_points",
.fixed_amount = false,
.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().