PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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)
 
static bool match_inj_entries (PgStatShared_HashEntry *entry, Datum match_data)
 
 PG_FUNCTION_INFO_V1 (injection_points_stats_drop)
 
Datum injection_points_stats_drop (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_drop()

Datum injection_points_stats_drop ( PG_FUNCTION_ARGS  )

Definition at line 213 of file injection_stats.c.

214{
216
218}
#define PG_RETURN_VOID()
Definition: fmgr.h:349
static bool match_inj_entries(PgStatShared_HashEntry *entry, Datum match_data)
void pgstat_drop_matching_entries(bool(*do_drop)(PgStatShared_HashEntry *, Datum), Datum match_data)

References match_inj_entries(), PG_RETURN_VOID, and pgstat_drop_matching_entries().

◆ injection_points_stats_numcalls()

Datum injection_points_stats_numcalls ( PG_FUNCTION_ARGS  )

Definition at line 190 of file injection_stats.c.

191{
194
195 if (entry == NULL)
197
199}
#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:225
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;
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
84 pgstat_unlock_entry(entry_ref);
85
86 return true;
87}
void pgstat_unlock_entry(PgStat_EntryRef *entry_ref)
Definition: pgstat_shmem.c:684
bool pgstat_lock_entry(PgStat_EntryRef *entry_ref, bool nowait)
Definition: pgstat_shmem.c:654
PgStat_StatInjEntry stats
PgStatShared_Common * shared_stats

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

◆ match_inj_entries()

static bool match_inj_entries ( PgStatShared_HashEntry entry,
Datum  match_data 
)
static

Definition at line 203 of file injection_stats.c.

204{
205 return entry->key.kind == PGSTAT_KIND_INJECTION;
206}
#define PGSTAT_KIND_INJECTION
PgStat_Kind kind

References PgStatShared_HashEntry::key, PgStat_HashKey::kind, and PGSTAT_KIND_INJECTION.

Referenced by injection_points_stats_drop().

◆ PG_FUNCTION_INFO_V1() [1/2]

PG_FUNCTION_INFO_V1 ( injection_points_stats_drop  )

◆ PG_FUNCTION_INFO_V1() [2/2]

PG_FUNCTION_INFO_V1 ( injection_points_stats_numcalls  )

◆ pgstat_create_inj()

void pgstat_create_inj ( const char *  name)

Definition at line 124 of file injection_stats.c.

125{
126 PgStat_EntryRef *entry_ref;
128
129 /* leave if disabled */
131 return;
132
134 PGSTAT_INJ_IDX(name), NULL);
135
136 shstatent = (PgStatShared_InjectionPoint *) entry_ref->shared_stats;
137
138 /* initialize shared memory data */
139 memset(&shstatent->stats, 0, sizeof(shstatent->stats));
140}
bool inj_stats_enabled
static bool inj_stats_loaded
#define PGSTAT_INJ_IDX(name)
PgStat_EntryRef * pgstat_prep_pending_entry(PgStat_Kind kind, Oid dboid, uint64 objid, bool *created_entry)
Definition: pgstat.c:1280
#define InvalidOid
Definition: postgres_ext.h:35

References inj_stats_enabled, inj_stats_loaded, InvalidOid, name, PGSTAT_INJ_IDX, PGSTAT_KIND_INJECTION, pgstat_prep_pending_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 146 of file injection_stats.c.

147{
148 /* leave if disabled */
150 return;
151
155}
void pgstat_request_entry_refs_gc(void)
Definition: pgstat_shmem.c:709
bool pgstat_drop_entry(PgStat_Kind kind, Oid dboid, uint64 objid)
Definition: pgstat_shmem.c:962

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

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

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

113{
115
116 /* mark stats as loaded */
117 inj_stats_loaded = true;
118}
static const PgStat_KindInfo injection_stats
void pgstat_register_kind(PgStat_Kind kind, const PgStat_KindInfo *kind_info)
Definition: pgstat.c:1478

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

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

References inj_stats_enabled, inj_stats_loaded, InvalidOid, name, PgStat_StatInjEntry::numcalls, PGSTAT_INJ_IDX, PGSTAT_KIND_INJECTION, pgstat_prep_pending_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().