PostgreSQL Source Code git master
Loading...
Searching...
No Matches
test_custom_fixed_stats.c File Reference
#include "postgres.h"
#include "access/htup_details.h"
#include "funcapi.h"
#include "pgstat.h"
#include "utils/builtins.h"
#include "utils/pgstat_internal.h"
#include "utils/timestamp.h"
Include dependency graph for test_custom_fixed_stats.c:

Go to the source code of this file.

Data Structures

struct  PgStat_StatCustomFixedEntry
 
struct  PgStatShared_CustomFixedEntry
 

Macros

#define PGSTAT_KIND_TEST_CUSTOM_FIXED_STATS   26
 
#define FIXED_COMP(fld)   stat_snap->fld -= reset.fld;
 

Typedefs

typedef struct PgStat_StatCustomFixedEntry PgStat_StatCustomFixedEntry
 
typedef struct PgStatShared_CustomFixedEntry PgStatShared_CustomFixedEntry
 

Functions

 PG_MODULE_MAGIC_EXT (.name="test_custom_fixed_stats",.version=PG_VERSION)
 
static void test_custom_stats_fixed_init_shmem_cb (void *stats)
 
static void test_custom_stats_fixed_reset_all_cb (TimestampTz ts)
 
static void test_custom_stats_fixed_snapshot_cb (void)
 
void _PG_init (void)
 
 PG_FUNCTION_INFO_V1 (test_custom_stats_fixed_update)
 
Datum test_custom_stats_fixed_update (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (test_custom_stats_fixed_reset)
 
Datum test_custom_stats_fixed_reset (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (test_custom_stats_fixed_report)
 
Datum test_custom_stats_fixed_report (PG_FUNCTION_ARGS)
 

Variables

static const PgStat_KindInfo custom_stats
 

Macro Definition Documentation

◆ FIXED_COMP

#define FIXED_COMP (   fld)    stat_snap->fld -= reset.fld;

◆ PGSTAT_KIND_TEST_CUSTOM_FIXED_STATS

#define PGSTAT_KIND_TEST_CUSTOM_FIXED_STATS   26

Definition at line 65 of file test_custom_fixed_stats.c.

Typedef Documentation

◆ PgStat_StatCustomFixedEntry

◆ PgStatShared_CustomFixedEntry

Function Documentation

◆ _PG_init()

void _PG_init ( void  )

Definition at line 73 of file test_custom_fixed_stats.c.

74{
75 /* Register custom statistics kind */
77}
void pgstat_register_kind(PgStat_Kind kind, const PgStat_KindInfo *kind_info)
Definition pgstat.c:1507
#define PGSTAT_KIND_TEST_CUSTOM_FIXED_STATS
static const PgStat_KindInfo custom_stats

References custom_stats, PGSTAT_KIND_TEST_CUSTOM_FIXED_STATS, and pgstat_register_kind().

◆ PG_FUNCTION_INFO_V1() [1/3]

PG_FUNCTION_INFO_V1 ( test_custom_stats_fixed_report  )

◆ PG_FUNCTION_INFO_V1() [2/3]

PG_FUNCTION_INFO_V1 ( test_custom_stats_fixed_reset  )

◆ PG_FUNCTION_INFO_V1() [3/3]

PG_FUNCTION_INFO_V1 ( test_custom_stats_fixed_update  )

◆ PG_MODULE_MAGIC_EXT()

PG_MODULE_MAGIC_EXT ( name = "test_custom_fixed_stats",
version = PG_VERSION 
)

◆ test_custom_stats_fixed_init_shmem_cb()

static void test_custom_stats_fixed_init_shmem_cb ( void stats)
static

Definition at line 84 of file test_custom_fixed_stats.c.

85{
88
90}
void LWLockInitialize(LWLock *lock, int tranche_id)
Definition lwlock.c:670
static int fb(int x)

References fb(), and LWLockInitialize().

◆ test_custom_stats_fixed_report()

Datum test_custom_stats_fixed_report ( PG_FUNCTION_ARGS  )

Definition at line 188 of file test_custom_fixed_stats.c.

189{
190 TupleDesc tupdesc;
191 Datum values[2] = {0};
192 bool nulls[2] = {false};
194
195 /* Take snapshot (applies reset offsets) */
198
199 /* Build return tuple */
200 tupdesc = CreateTemplateTupleDesc(2);
201 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "numcalls",
202 INT8OID, -1, 0);
203 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "stats_reset",
204 TIMESTAMPTZOID, -1, 0);
205 TupleDescFinalize(tupdesc);
206 BlessTupleDesc(tupdesc);
207
208 values[0] = Int64GetDatum(stats->numcalls);
209
210 /* Handle uninitialized timestamp (no reset yet) */
211 if (stats->stat_reset_timestamp == 0)
212 {
213 nulls[1] = true;
214 }
215 else
216 {
218 }
219
220 /* Return as tuple */
222}
int16 AttrNumber
Definition attnum.h:21
static Datum values[MAXATTR]
Definition bootstrap.c:190
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
#define PG_RETURN_DATUM(x)
Definition fmgr.h:354
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:1025
void pgstat_snapshot_fixed(PgStat_Kind kind)
Definition pgstat.c:1104
static void * pgstat_get_custom_snapshot_data(PgStat_Kind kind)
static Datum Int64GetDatum(int64 X)
Definition postgres.h:426
uint64_t Datum
Definition postgres.h:70
TupleDesc CreateTemplateTupleDesc(int natts)
Definition tupdesc.c:165
void TupleDescFinalize(TupleDesc tupdesc)
Definition tupdesc.c:511
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition tupdesc.c:909
static Datum TimestampTzGetDatum(TimestampTz X)
Definition timestamp.h:52

References BlessTupleDesc(), CreateTemplateTupleDesc(), fb(), heap_form_tuple(), HeapTupleGetDatum(), Int64GetDatum(), PgStat_StatCustomFixedEntry::numcalls, PG_RETURN_DATUM, pgstat_get_custom_snapshot_data(), PGSTAT_KIND_TEST_CUSTOM_FIXED_STATS, pgstat_snapshot_fixed(), PgStat_StatCustomFixedEntry::stat_reset_timestamp, TimestampTzGetDatum(), TupleDescFinalize(), TupleDescInitEntry(), and values.

◆ test_custom_stats_fixed_reset()

Datum test_custom_stats_fixed_reset ( PG_FUNCTION_ARGS  )

Definition at line 175 of file test_custom_fixed_stats.c.

176{
178
180}
#define PG_RETURN_VOID()
Definition fmgr.h:350
void pgstat_reset_of_kind(PgStat_Kind kind)
Definition pgstat.c:904

References PG_RETURN_VOID, PGSTAT_KIND_TEST_CUSTOM_FIXED_STATS, and pgstat_reset_of_kind().

◆ test_custom_stats_fixed_reset_all_cb()

static void test_custom_stats_fixed_reset_all_cb ( TimestampTz  ts)
static

Definition at line 97 of file test_custom_fixed_stats.c.

98{
101
102 /* see explanation above PgStatShared_Archiver for the reset protocol */
105 &stats_shmem->stats,
106 sizeof(stats_shmem->stats),
107 &stats_shmem->changecount);
108 stats_shmem->stats.stat_reset_timestamp = ts;
110}
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition lwlock.c:1150
void LWLockRelease(LWLock *lock)
Definition lwlock.c:1767
@ LW_EXCLUSIVE
Definition lwlock.h:104
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)

References fb(), LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), pgstat_copy_changecounted_stats(), pgstat_get_custom_shmem_data(), and PGSTAT_KIND_TEST_CUSTOM_FIXED_STATS.

◆ test_custom_stats_fixed_snapshot_cb()

static void test_custom_stats_fixed_snapshot_cb ( void  )
static

Definition at line 117 of file test_custom_fixed_stats.c.

118{
123 PgStat_StatCustomFixedEntry *reset_offset = &stats_shmem->reset_offset;
125
127 &stats_shmem->stats,
128 sizeof(stats_shmem->stats),
129 &stats_shmem->changecount);
130
132 memcpy(&reset, reset_offset, sizeof(stats_shmem->stats));
134
135 /* Apply reset offsets */
136#define FIXED_COMP(fld) stat_snap->fld -= reset.fld;
137 FIXED_COMP(numcalls);
138#undef FIXED_COMP
139}
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
@ LW_SHARED
Definition lwlock.h:105
void reset(void)
#define FIXED_COMP(fld)

References fb(), FIXED_COMP, LW_SHARED, LWLockAcquire(), LWLockRelease(), memcpy(), pgstat_copy_changecounted_stats(), pgstat_get_custom_shmem_data(), pgstat_get_custom_snapshot_data(), PGSTAT_KIND_TEST_CUSTOM_FIXED_STATS, and reset().

◆ test_custom_stats_fixed_update()

Variable Documentation

◆ custom_stats

const PgStat_KindInfo custom_stats
static
Initial value:
= {
.name = "test_custom_fixed_stats",
.fixed_amount = true,
.write_to_file = true,
.shared_size = sizeof(PgStatShared_CustomFixedEntry),
.shared_data_off = offsetof(PgStatShared_CustomFixedEntry, stats),
.shared_data_len = sizeof(((PgStatShared_CustomFixedEntry *) 0)->stats),
}
static void test_custom_stats_fixed_init_shmem_cb(void *stats)
static void test_custom_stats_fixed_snapshot_cb(void)
static void test_custom_stats_fixed_reset_all_cb(TimestampTz ts)

Definition at line 48 of file test_custom_fixed_stats.c.

48 {
49 .name = "test_custom_fixed_stats",
50 .fixed_amount = true, /* exactly one entry */
51 .write_to_file = true, /* persist to stats file */
52
53 .shared_size = sizeof(PgStatShared_CustomFixedEntry),
54 .shared_data_off = offsetof(PgStatShared_CustomFixedEntry, stats),
55 .shared_data_len = sizeof(((PgStatShared_CustomFixedEntry *) 0)->stats),
56
60};

Referenced by _PG_init().