PostgreSQL Source Code git master
Loading...
Searching...
No Matches
test_custom_var_stats.c File Reference
#include "postgres.h"
#include "access/htup_details.h"
#include "common/hashfn.h"
#include "funcapi.h"
#include "storage/dsm_registry.h"
#include "storage/fd.h"
#include "utils/builtins.h"
#include "utils/pgstat_internal.h"
Include dependency graph for test_custom_var_stats.c:

Go to the source code of this file.

Data Structures

struct  PgStat_StatCustomVarEntry
 
struct  PgStatShared_CustomVarEntry
 

Macros

#define write_chunk(fpout, ptr, len)   (fwrite(ptr, len, 1, fpout) == 1)
 
#define write_chunk_s(fpout, ptr)   write_chunk(fpout, ptr, sizeof(*ptr))
 
#define read_chunk(fpin, ptr, len)   (fread(ptr, 1, len, fpin) == (len))
 
#define read_chunk_s(fpin, ptr)   read_chunk(fpin, ptr, sizeof(*ptr))
 
#define TEST_CUSTOM_VAR_MAGIC_NUMBER   (0xBEEFBEEF)
 
#define PGSTAT_KIND_TEST_CUSTOM_VAR_STATS   25
 
#define TEST_CUSTOM_AUX_DATA_DESC   "pg_stat/test_custom_var_stats_desc.stats"
 
#define PGSTAT_CUSTOM_VAR_STATS_IDX(name)   hash_bytes_extended((const unsigned char *) name, strlen(name), 0)
 

Typedefs

typedef struct PgStat_StatCustomVarEntry PgStat_StatCustomVarEntry
 
typedef struct PgStatShared_CustomVarEntry PgStatShared_CustomVarEntry
 

Functions

 PG_MODULE_MAGIC_EXT (.name="test_custom_var_stats",.version=PG_VERSION)
 
static bool test_custom_stats_var_flush_pending_cb (PgStat_EntryRef *entry_ref, bool nowait)
 
static bool test_custom_stats_var_to_serialized_data (const PgStat_HashKey *key, const PgStatShared_Common *header, FILE *statfile)
 
static bool test_custom_stats_var_from_serialized_data (const PgStat_HashKey *key, PgStatShared_Common *header, FILE *statfile)
 
static void test_custom_stats_var_finish (PgStat_StatsFileOp status)
 
void _PG_init (void)
 
static PgStat_StatCustomVarEntrytest_custom_stats_var_fetch_entry (const char *stat_name)
 
 PG_FUNCTION_INFO_V1 (test_custom_stats_var_create)
 
Datum test_custom_stats_var_create (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (test_custom_stats_var_update)
 
Datum test_custom_stats_var_update (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (test_custom_stats_var_drop)
 
Datum test_custom_stats_var_drop (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (test_custom_stats_var_report)
 
Datum test_custom_stats_var_report (PG_FUNCTION_ARGS)
 

Variables

static FILEfd_description = NULL
 
static pgoff_t fd_description_offset = 0
 
static dsa_areacustom_stats_description_dsa = NULL
 
static const PgStat_KindInfo custom_stats
 

Macro Definition Documentation

◆ PGSTAT_CUSTOM_VAR_STATS_IDX

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

Definition at line 52 of file test_custom_var_stats.c.

◆ PGSTAT_KIND_TEST_CUSTOM_VAR_STATS

#define PGSTAT_KIND_TEST_CUSTOM_VAR_STATS   25

Definition at line 44 of file test_custom_var_stats.c.

◆ read_chunk

#define read_chunk (   fpin,
  ptr,
  len 
)    (fread(ptr, 1, len, fpin) == (len))

Definition at line 31 of file test_custom_var_stats.c.

◆ read_chunk_s

#define read_chunk_s (   fpin,
  ptr 
)    read_chunk(fpin, ptr, sizeof(*ptr))

Definition at line 32 of file test_custom_var_stats.c.

◆ TEST_CUSTOM_AUX_DATA_DESC

#define TEST_CUSTOM_AUX_DATA_DESC   "pg_stat/test_custom_var_stats_desc.stats"

Definition at line 47 of file test_custom_var_stats.c.

◆ TEST_CUSTOM_VAR_MAGIC_NUMBER

#define TEST_CUSTOM_VAR_MAGIC_NUMBER   (0xBEEFBEEF)

Definition at line 34 of file test_custom_var_stats.c.

◆ write_chunk

#define write_chunk (   fpout,
  ptr,
  len 
)    (fwrite(ptr, len, 1, fpout) == 1)

Definition at line 29 of file test_custom_var_stats.c.

◆ write_chunk_s

#define write_chunk_s (   fpout,
  ptr 
)    write_chunk(fpout, ptr, sizeof(*ptr))

Definition at line 30 of file test_custom_var_stats.c.

Typedef Documentation

◆ PgStat_StatCustomVarEntry

◆ PgStatShared_CustomVarEntry

Function Documentation

◆ _PG_init()

void _PG_init ( void  )

Definition at line 136 of file test_custom_var_stats.c.

137{
138 /* Register custom statistics kind */
140}
void pgstat_register_kind(PgStat_Kind kind, const PgStat_KindInfo *kind_info)
Definition pgstat.c:1522
static const PgStat_KindInfo custom_stats
#define PGSTAT_KIND_TEST_CUSTOM_VAR_STATS

References custom_stats, PGSTAT_KIND_TEST_CUSTOM_VAR_STATS, and pgstat_register_kind().

◆ PG_FUNCTION_INFO_V1() [1/4]

PG_FUNCTION_INFO_V1 ( test_custom_stats_var_create  )

◆ PG_FUNCTION_INFO_V1() [2/4]

PG_FUNCTION_INFO_V1 ( test_custom_stats_var_drop  )

◆ PG_FUNCTION_INFO_V1() [3/4]

PG_FUNCTION_INFO_V1 ( test_custom_stats_var_report  )

◆ PG_FUNCTION_INFO_V1() [4/4]

PG_FUNCTION_INFO_V1 ( test_custom_stats_var_update  )

◆ PG_MODULE_MAGIC_EXT()

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

◆ test_custom_stats_var_create()

Datum test_custom_stats_var_create ( PG_FUNCTION_ARGS  )

Definition at line 523 of file test_custom_var_stats.c.

524{
525 PgStat_EntryRef *entry_ref;
526 PgStatShared_CustomVarEntry *shared_entry;
530 bool found;
531
532 /* Validate name length first */
536 errmsg("custom statistic name \"%s\" is too long", stat_name),
537 errdetail("Name must be less than %d characters.", NAMEDATALEN)));
538
539 /* Initialize DSA and description provided */
541 custom_stats_description_dsa = GetNamedDSA("test_custom_stat_dsa", &found);
542
545 (errmsg("could not access DSA for custom statistics descriptions")));
546
547 /* Allocate space in DSA and copy description */
551 strlen(description) + 1);
552
553 /* Create or get existing entry */
556
557 if (!entry_ref)
559
560 shared_entry = (PgStatShared_CustomVarEntry *) entry_ref->shared_stats;
561
562 /* Zero-initialize statistics */
563 memset(&shared_entry->stats, 0, sizeof(shared_entry->stats));
564
565 /* Store description pointer */
566 shared_entry->description = dp;
567
568 pgstat_unlock_entry(entry_ref);
569
571}
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
void * dsa_get_address(dsa_area *area, dsa_pointer dp)
Definition dsa.c:954
uint64 dsa_pointer
Definition dsa.h:62
#define dsa_allocate(area, size)
Definition dsa.h:109
#define InvalidDsaPointer
Definition dsa.h:78
dsa_area * GetNamedDSA(const char *name, bool *found)
int errcode(int sqlerrcode)
Definition elog.c:875
int errdetail(const char *fmt,...) pg_attribute_printf(1
#define ERROR
Definition elog.h:40
#define ereport(elevel,...)
Definition elog.h:152
#define PG_RETURN_VOID()
Definition fmgr.h:350
#define PG_GETARG_TEXT_PP(n)
Definition fmgr.h:310
static char * errmsg
#define NAMEDATALEN
void pgstat_unlock_entry(PgStat_EntryRef *entry_ref)
PgStat_EntryRef * pgstat_get_entry_ref_locked(PgStat_Kind kind, Oid dboid, uint64 objid, bool nowait)
#define InvalidOid
static int fb(int x)
PgStat_StatCustomVarEntry stats
PgStatShared_Common * shared_stats
static dsa_area * custom_stats_description_dsa
#define PGSTAT_CUSTOM_VAR_STATS_IDX(name)
char * text_to_cstring(const text *t)
Definition varlena.c:217
const char * description

References custom_stats_description_dsa, description, PgStatShared_CustomVarEntry::description, dsa_allocate, dsa_get_address(), ereport, errcode(), errdetail(), errmsg, ERROR, fb(), GetNamedDSA(), InvalidDsaPointer, InvalidOid, memcpy(), NAMEDATALEN, PG_GETARG_TEXT_PP, PG_RETURN_VOID, PGSTAT_CUSTOM_VAR_STATS_IDX, pgstat_get_entry_ref_locked(), PGSTAT_KIND_TEST_CUSTOM_VAR_STATS, pgstat_unlock_entry(), PgStat_EntryRef::shared_stats, PgStatShared_CustomVarEntry::stats, and text_to_cstring().

◆ test_custom_stats_var_drop()

Datum test_custom_stats_var_drop ( PG_FUNCTION_ARGS  )

Definition at line 606 of file test_custom_var_stats.c.

607{
609
610 /* Drop entry and request GC if the entry could not be freed */
614
616}
void pgstat_request_entry_refs_gc(void)
bool pgstat_drop_entry(PgStat_Kind kind, Oid dboid, uint64 objid, bool missing_ok)

References fb(), InvalidOid, PG_GETARG_TEXT_PP, PG_RETURN_VOID, PGSTAT_CUSTOM_VAR_STATS_IDX, pgstat_drop_entry(), PGSTAT_KIND_TEST_CUSTOM_VAR_STATS, pgstat_request_entry_refs_gc(), and text_to_cstring().

◆ test_custom_stats_var_fetch_entry()

static PgStat_StatCustomVarEntry * test_custom_stats_var_fetch_entry ( const char stat_name)
static

Definition at line 500 of file test_custom_var_stats.c.

501{
502 /* Fetch entry by hashed name */
507 NULL);
508}
void * pgstat_fetch_entry(PgStat_Kind kind, Oid dboid, uint64 objid, bool *may_free)
Definition pgstat.c:962

References fb(), InvalidOid, PGSTAT_CUSTOM_VAR_STATS_IDX, pgstat_fetch_entry(), and PGSTAT_KIND_TEST_CUSTOM_VAR_STATS.

Referenced by test_custom_stats_var_report().

◆ test_custom_stats_var_finish()

static void test_custom_stats_var_finish ( PgStat_StatsFileOp  status)
static

Definition at line 418 of file test_custom_var_stats.c.

419{
420 switch (status)
421 {
422 case STATS_WRITE:
423 if (!fd_description)
424 return;
425
427
428 /* Check for write errors and cleanup if necessary */
430 {
431 ereport(LOG,
433 errmsg("could not write to file \"%s\": %m",
437 }
438 else if (FreeFile(fd_description) < 0)
439 {
440 ereport(LOG,
442 errmsg("could not close file \"%s\": %m",
445 }
446 break;
447
448 case STATS_READ:
449 if (fd_description)
451
452 /* Remove the file after reading */
453 elog(DEBUG2, "removing file \"%s\"", TEST_CUSTOM_AUX_DATA_DESC);
455 break;
456
457 case STATS_DISCARD:
458 {
459 int ret;
460
461 /* Attempt to remove the file */
463 if (ret != 0)
464 {
465 if (errno == ENOENT)
466 elog(LOG,
467 "didn't need to unlink file \"%s\" - didn't exist",
469 else
470 ereport(LOG,
472 errmsg("could not unlink file \"%s\": %m",
474 }
475 else
476 {
477 ereport(LOG,
478 (errmsg_internal("unlinked file \"%s\"",
480 }
481 }
482 break;
483 }
484
486}
int errcode_for_file_access(void)
Definition elog.c:898
#define LOG
Definition elog.h:32
int int errmsg_internal(const char *fmt,...) pg_attribute_printf(1
#define DEBUG2
Definition elog.h:30
#define elog(elevel,...)
Definition elog.h:228
int FreeFile(FILE *file)
Definition fd.c:2827
@ STATS_WRITE
@ STATS_READ
@ STATS_DISCARD
static pgoff_t fd_description_offset
#define TEST_CUSTOM_AUX_DATA_DESC
static FILE * fd_description

References DEBUG2, elog, ereport, errcode_for_file_access(), errmsg, errmsg_internal(), fb(), fd_description, fd_description_offset, FreeFile(), LOG, STATS_DISCARD, STATS_READ, STATS_WRITE, and TEST_CUSTOM_AUX_DATA_DESC.

◆ test_custom_stats_var_flush_pending_cb()

static bool test_custom_stats_var_flush_pending_cb ( PgStat_EntryRef entry_ref,
bool  nowait 
)
static

Definition at line 157 of file test_custom_var_stats.c.

158{
160 PgStatShared_CustomVarEntry *shared_entry;
161
163 shared_entry = (PgStatShared_CustomVarEntry *) entry_ref->shared_stats;
164
165 if (!pgstat_lock_entry(entry_ref, nowait))
166 return false;
167
168 /* Add pending counts to shared totals */
169 shared_entry->stats.numcalls += pending_entry->numcalls;
170
171 pgstat_unlock_entry(entry_ref);
172
173 return true;
174}
bool pgstat_lock_entry(PgStat_EntryRef *entry_ref, bool nowait)

References fb(), PgStat_StatCustomVarEntry::numcalls, PgStat_EntryRef::pending, pgstat_lock_entry(), pgstat_unlock_entry(), PgStat_EntryRef::shared_stats, and PgStatShared_CustomVarEntry::stats.

◆ test_custom_stats_var_from_serialized_data()

static bool test_custom_stats_var_from_serialized_data ( const PgStat_HashKey key,
PgStatShared_Common header,
FILE statfile 
)
static

Definition at line 289 of file test_custom_var_stats.c.

292{
295 size_t len;
296 pgoff_t offset;
297 char *buffer;
298 bool found;
301
302 /* Check the magic number first, in the main file. */
304 {
305 elog(WARNING, "failed to read magic number from statistics file");
306 return false;
307 }
308
310 {
311 elog(WARNING, "found magic number %u from statistics file, should be %u",
313 return false;
314 }
315
316 /*
317 * Read the offset from the main stats file, to be able to read the
318 * auxiliary data from the secondary statistics file.
319 */
320 if (!read_chunk_s(statfile, &offset))
321 {
322 elog(WARNING, "failed to read metadata offset from statistics file");
323 return false;
324 }
325
326 /* Open statistics file for reading if not already open */
327 if (!fd_description)
328 {
330 if (fd_description == NULL)
331 {
332 if (errno != ENOENT)
333 ereport(LOG,
335 errmsg("could not open statistics file \"%s\" for reading: %m",
338 return false;
339 }
340 }
341
342 /* Read data from the secondary statistics file, at the specified offset */
343 if (fseeko(fd_description, offset, SEEK_SET) != 0)
344 {
345 elog(WARNING, "could not seek in file \"%s\": %m",
347 return false;
348 }
349
350 /* Read the hash key from the secondary statistics file */
352 {
353 elog(WARNING, "failed to read hash key from file");
354 return false;
355 }
356
357 /* Check key consistency */
358 if (file_key.kind != key->kind ||
359 file_key.dboid != key->dboid ||
360 file_key.objid != key->objid)
361 {
362 elog(WARNING, "found entry key %u/%u/%" PRIu64 " not matching with %u/%u/%" PRIu64,
363 file_key.kind, file_key.dboid, file_key.objid,
364 key->kind, key->dboid, key->objid);
365 return false;
366 }
367
368 entry = (PgStatShared_CustomVarEntry *) header;
369
370 /* Read the description length and its data */
372 {
373 elog(WARNING, "failed to read metadata length from statistics file");
374 return false;
375 }
376
377 /* Handle empty descriptions */
378 if (len == 0)
379 {
381 return true;
382 }
383
384 /* Initialize DSA if needed */
386 custom_stats_description_dsa = GetNamedDSA("test_custom_stat_dsa", &found);
387
389 {
390 elog(WARNING, "could not access DSA for custom statistics descriptions");
391 return false;
392 }
393
394 buffer = palloc(len);
395 if (!read_chunk(fd_description, buffer, len))
396 {
397 pfree(buffer);
398 elog(WARNING, "failed to read description from file");
399 return false;
400 }
401
402 /* Allocate space in DSA and copy the description */
405 entry->description = dp;
406 pfree(buffer);
407
408 return true;
409}
#define PG_BINARY_R
Definition c.h:1433
uint32_t uint32
Definition c.h:683
#define WARNING
Definition elog.h:37
FILE * AllocateFile(const char *name, const char *mode)
Definition fd.c:2628
void pfree(void *pointer)
Definition mcxt.c:1619
void * palloc(Size size)
Definition mcxt.c:1390
const void size_t len
void pgstat_reset_of_kind(PgStat_Kind kind)
Definition pgstat.c:904
off_t pgoff_t
Definition port.h:422
#define read_chunk(fpin, ptr, len)
#define read_chunk_s(fpin, ptr)
#define TEST_CUSTOM_VAR_MAGIC_NUMBER
#define fseeko(stream, offset, origin)
Definition win32_port.h:206

References AllocateFile(), custom_stats_description_dsa, PgStatShared_CustomVarEntry::description, dsa_allocate, dsa_get_address(), elog, ereport, errcode_for_file_access(), errmsg, fb(), fd_description, fseeko, GetNamedDSA(), InvalidDsaPointer, len, LOG, memcpy(), palloc(), pfree(), PG_BINARY_R, PGSTAT_KIND_TEST_CUSTOM_VAR_STATS, pgstat_reset_of_kind(), read_chunk, read_chunk_s, TEST_CUSTOM_AUX_DATA_DESC, TEST_CUSTOM_VAR_MAGIC_NUMBER, and WARNING.

◆ test_custom_stats_var_report()

Datum test_custom_stats_var_report ( PG_FUNCTION_ARGS  )

Definition at line 627 of file test_custom_var_stats.c.

628{
630 char *stat_name;
632
633 if (SRF_IS_FIRSTCALL())
634 {
635 TupleDesc tupdesc;
636 MemoryContext oldcontext;
637
638 /* Initialize SRF context */
640 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
641
642 /* Get composite return type */
643 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
644 elog(ERROR, "test_custom_stats_var_report: return type is not composite");
645
646 funcctx->tuple_desc = BlessTupleDesc(tupdesc);
647 funcctx->max_calls = 1; /* single row result */
648
649 MemoryContextSwitchTo(oldcontext);
650 }
651
653
654 if (funcctx->call_cntr < funcctx->max_calls)
655 {
656 Datum values[3];
657 bool nulls[3] = {false, false, false};
658 HeapTuple tuple;
659 PgStat_EntryRef *entry_ref;
660 PgStatShared_CustomVarEntry *shared_entry;
661 char *description = NULL;
662 bool found;
663
666
667 /* Return row only if entry exists */
668 if (stat_entry)
669 {
670 /* Get entry ref to access shared entry */
673
674 if (entry_ref)
675 {
676 shared_entry = (PgStatShared_CustomVarEntry *) entry_ref->shared_stats;
677
678 /* Get description from DSA if available */
679 if (DsaPointerIsValid(shared_entry->description))
680 {
682 custom_stats_description_dsa = GetNamedDSA("test_custom_stat_dsa", &found);
683
686 }
687 }
688
690 values[1] = Int64GetDatum(stat_entry->numcalls);
691
692 if (description)
694 else
695 nulls[2] = true;
696
697 tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
699 }
700 }
701
703}
static Datum values[MAXATTR]
Definition bootstrap.c:190
#define DsaPointerIsValid(x)
Definition dsa.h:106
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition funcapi.c:276
#define SRF_IS_FIRSTCALL()
Definition funcapi.h:304
#define SRF_PERCALL_SETUP()
Definition funcapi.h:308
@ TYPEFUNC_COMPOSITE
Definition funcapi.h:149
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition funcapi.h:310
#define SRF_FIRSTCALL_INIT()
Definition funcapi.h:306
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
Definition funcapi.h:230
#define SRF_RETURN_DONE(_funcctx)
Definition funcapi.h:328
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition heaptuple.c:1025
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:138
PgStat_EntryRef * pgstat_get_entry_ref(PgStat_Kind kind, Oid dboid, uint64 objid, bool create, bool *created_entry)
static Datum Int64GetDatum(int64 X)
Definition postgres.h:426
uint64_t Datum
Definition postgres.h:70
#define PointerGetDatum(X)
Definition postgres.h:354
static PgStat_StatCustomVarEntry * test_custom_stats_var_fetch_entry(const char *stat_name)
text * cstring_to_text(const char *s)
Definition varlena.c:184

References BlessTupleDesc(), cstring_to_text(), custom_stats_description_dsa, description, PgStatShared_CustomVarEntry::description, dsa_get_address(), DsaPointerIsValid, elog, ERROR, fb(), get_call_result_type(), GetNamedDSA(), heap_form_tuple(), HeapTupleGetDatum(), Int64GetDatum(), InvalidOid, MemoryContextSwitchTo(), PG_GETARG_TEXT_PP, PGSTAT_CUSTOM_VAR_STATS_IDX, pgstat_get_entry_ref(), PGSTAT_KIND_TEST_CUSTOM_VAR_STATS, PointerGetDatum, PgStat_EntryRef::shared_stats, SRF_FIRSTCALL_INIT, SRF_IS_FIRSTCALL, SRF_PERCALL_SETUP, SRF_RETURN_DONE, SRF_RETURN_NEXT, test_custom_stats_var_fetch_entry(), text_to_cstring(), TYPEFUNC_COMPOSITE, and values.

◆ test_custom_stats_var_to_serialized_data()

static bool test_custom_stats_var_to_serialized_data ( const PgStat_HashKey key,
const PgStatShared_Common header,
FILE statfile 
)
static

Definition at line 197 of file test_custom_var_stats.c.

200{
201 char *description;
202 size_t len;
203 const PgStatShared_CustomVarEntry *entry = (const PgStatShared_CustomVarEntry *) header;
204 bool found;
206
207 /*
208 * First mark the main file with a magic number, keeping a trace that some
209 * auxiliary data will exist in the secondary statistics file.
210 */
212 return false;
213
214 /* Open statistics file for writing. */
215 if (!fd_description)
216 {
218 if (fd_description == NULL)
219 {
220 ereport(LOG,
222 errmsg("could not open statistics file \"%s\" for writing: %m",
224 return false;
225 }
226
227 /* Initialize offset for secondary statistics file. */
229 }
230
231 /* Write offset to the main data file */
233 return false;
234
235 /*
236 * First write the entry key to the secondary statistics file. This will
237 * be cross-checked with the key read from main stats file at loading
238 * time.
239 */
241 return false;
243
245 custom_stats_description_dsa = GetNamedDSA("test_custom_stat_dsa", &found);
246
247 /* Handle entries without descriptions */
249 {
250 /* length to description file */
251 len = 0;
253 return false;
254 fd_description_offset += sizeof(size_t);
255 return true;
256 }
257
258 /*
259 * Retrieve description from DSA, then write the length followed by the
260 * description.
261 */
263 entry->description);
264 len = strlen(description) + 1;
266 return false;
268 return false;
269
270 /*
271 * Update offset for next entry, counting for the length (size_t) of the
272 * description and the description contents.
273 */
274 fd_description_offset += len + sizeof(size_t);
275 return true;
276}
#define PG_BINARY_W
Definition c.h:1434
#define write_chunk(fpout, ptr, len)
#define write_chunk_s(fpout, ptr)

References AllocateFile(), custom_stats_description_dsa, description, PgStatShared_CustomVarEntry::description, dsa_get_address(), DsaPointerIsValid, ereport, errcode_for_file_access(), errmsg, fb(), fd_description, fd_description_offset, GetNamedDSA(), len, LOG, PG_BINARY_W, TEST_CUSTOM_AUX_DATA_DESC, TEST_CUSTOM_VAR_MAGIC_NUMBER, write_chunk, and write_chunk_s.

◆ test_custom_stats_var_update()

Datum test_custom_stats_var_update ( PG_FUNCTION_ARGS  )

Definition at line 582 of file test_custom_var_stats.c.

583{
585 PgStat_EntryRef *entry_ref;
587
588 /* Get pending entry in local memory */
591
593 pending_entry->numcalls++;
594
596}
PgStat_EntryRef * pgstat_prep_pending_entry(PgStat_Kind kind, Oid dboid, uint64 objid, bool *created_entry)
Definition pgstat.c:1309

References fb(), InvalidOid, PgStat_EntryRef::pending, PG_GETARG_TEXT_PP, PG_RETURN_VOID, PGSTAT_CUSTOM_VAR_STATS_IDX, PGSTAT_KIND_TEST_CUSTOM_VAR_STATS, pgstat_prep_pending_entry(), and text_to_cstring().

Variable Documentation

◆ custom_stats

const PgStat_KindInfo custom_stats
static
Initial value:
= {
.name = "test_custom_var_stats",
.fixed_amount = false,
.write_to_file = true,
.track_entry_count = true,
.accessed_across_databases = true,
.shared_size = sizeof(PgStatShared_CustomVarEntry),
.shared_data_off = offsetof(PgStatShared_CustomVarEntry, stats),
.shared_data_len = sizeof(((PgStatShared_CustomVarEntry *) 0)->stats),
.pending_size = sizeof(PgStat_StatCustomVarEntry),
}
static void test_custom_stats_var_finish(PgStat_StatsFileOp status)
static bool test_custom_stats_var_to_serialized_data(const PgStat_HashKey *key, const PgStatShared_Common *header, FILE *statfile)
static bool test_custom_stats_var_flush_pending_cb(PgStat_EntryRef *entry_ref, bool nowait)
static bool test_custom_stats_var_from_serialized_data(const PgStat_HashKey *key, PgStatShared_Common *header, FILE *statfile)

Definition at line 114 of file test_custom_var_stats.c.

114 {
115 .name = "test_custom_var_stats",
116 .fixed_amount = false, /* variable number of entries */
117 .write_to_file = true, /* persist across restarts */
118 .track_entry_count = true, /* count active entries */
119 .accessed_across_databases = true, /* global statistics */
120 .shared_size = sizeof(PgStatShared_CustomVarEntry),
121 .shared_data_off = offsetof(PgStatShared_CustomVarEntry, stats),
122 .shared_data_len = sizeof(((PgStatShared_CustomVarEntry *) 0)->stats),
123 .pending_size = sizeof(PgStat_StatCustomVarEntry),
124 .flush_pending_cb = test_custom_stats_var_flush_pending_cb,
125 .to_serialized_data = test_custom_stats_var_to_serialized_data,
126 .from_serialized_data = test_custom_stats_var_from_serialized_data,
128};

Referenced by _PG_init().

◆ custom_stats_description_dsa

◆ fd_description

◆ fd_description_offset

pgoff_t fd_description_offset = 0
static