This GUC controls if cumulative statistics are enabled or not in the
module. Custom statistics require the module to be loaded with
shared_preload_libraries, hence this GUC is made PGC_POSTMASTER. By
default, the stats are disabled. 001_stats.pl is updated to enable the
statistics, as it is the only area where these are required now.
This will be used by an upcoming change for the injection point test
added by
768a9fd5535f where stats should not be used, as the test runs a
point callback in a critical section. And the module injection_points
will need to be loaded with shared_preload_libraries there.
Per discussion with Álvaro Herrera.
Author: Michael Paquier
Discussion: https://postgr.es/m/
[email protected]
#include "storage/lwlock.h"
#include "storage/shmem.h"
#include "utils/builtins.h"
+#include "utils/guc.h"
#include "utils/injection_point.h"
#include "utils/memutils.h"
#include "utils/wait_event.h"
/* track if injection points attached in this process are linked to it */
static bool injection_point_local = false;
+/*
+ * GUC variable
+ *
+ * This GUC is useful to control if statistics should be enabled or not
+ * during a test with injection points, like for example if a test relies
+ * on a callback run in a critical section where no allocation should happen.
+ */
+bool inj_stats_enabled = false;
+
/* Shared memory init callbacks */
static shmem_request_hook_type prev_shmem_request_hook = NULL;
static shmem_startup_hook_type prev_shmem_startup_hook = NULL;
if (!process_shared_preload_libraries_in_progress)
return;
+ DefineCustomBoolVariable("injection_points.stats",
+ "Enables statistics for injection points.",
+ NULL,
+ &inj_stats_enabled,
+ false,
+ PGC_POSTMASTER,
+ 0,
+ NULL,
+ NULL,
+ NULL);
+
+ MarkGUCPrefixReserved("injection_points");
+
/* Shared memory initialization */
prev_shmem_request_hook = shmem_request_hook;
shmem_request_hook = injection_shmem_request;
{
PgStat_StatInjEntry *entry = NULL;
- if (!inj_stats_loaded)
+ if (!inj_stats_loaded || !inj_stats_enabled)
return NULL;
/* Compile the lookup key as a hash of the point name */
PgStatShared_InjectionPoint *shstatent;
/* leave if disabled */
- if (!inj_stats_loaded)
+ if (!inj_stats_loaded || !inj_stats_enabled)
return;
entry_ref = pgstat_get_entry_ref_locked(PGSTAT_KIND_INJECTION, InvalidOid,
pgstat_drop_inj(const char *name)
{
/* leave if disabled */
- if (!inj_stats_loaded)
+ if (!inj_stats_loaded || !inj_stats_enabled)
return;
if (!pgstat_drop_entry(PGSTAT_KIND_INJECTION, InvalidOid,
PgStat_StatInjEntry *statent;
/* leave if disabled */
- if (!inj_stats_loaded)
+ if (!inj_stats_loaded || !inj_stats_enabled)
return;
entry_ref = pgstat_get_entry_ref_locked(PGSTAT_KIND_INJECTION, InvalidOid,
#ifndef INJECTION_STATS
#define INJECTION_STATS
+/* GUC variable */
+extern bool inj_stats_enabled;
+
/* injection_stats.c */
extern void pgstat_register_inj(void);
extern void pgstat_create_inj(const char *name);
PgStatShared_InjectionPointFixed *stats_shmem;
/* leave if disabled */
- if (!inj_fixed_loaded)
+ if (!inj_fixed_loaded || !inj_stats_enabled)
return;
stats_shmem = pgstat_get_custom_shmem_data(PGSTAT_KIND_INJECTION_FIXED);
bool nulls[5] = {0};
PgStat_StatInjFixedEntry *stats;
- if (!inj_fixed_loaded)
+ if (!inj_fixed_loaded || !inj_stats_enabled)
PG_RETURN_NULL();
pgstat_snapshot_fixed(PGSTAT_KIND_INJECTION_FIXED);
# Node initialization
my $node = PostgreSQL::Test::Cluster->new('master');
$node->init;
-$node->append_conf('postgresql.conf',
- "shared_preload_libraries = 'injection_points'");
+$node->append_conf(
+ 'postgresql.conf', qq(
+shared_preload_libraries = 'injection_points'
+injection_points.stats = true
+));
$node->start;
$node->safe_psql('postgres', 'CREATE EXTENSION injection_points;');