Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2e35c67

Browse files
committed
injection_point: Add injection_points.stats
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 768a9fd 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/ZsUnJUlSOBNAzwW1@paquier.xyz
1 parent b2b023a commit 2e35c67

File tree

5 files changed

+37
-8
lines changed

5 files changed

+37
-8
lines changed

src/test/modules/injection_points/injection_points.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "storage/lwlock.h"
2929
#include "storage/shmem.h"
3030
#include "utils/builtins.h"
31+
#include "utils/guc.h"
3132
#include "utils/injection_point.h"
3233
#include "utils/memutils.h"
3334
#include "utils/wait_event.h"
@@ -102,6 +103,15 @@ extern PGDLLEXPORT void injection_wait(const char *name,
102103
/* track if injection points attached in this process are linked to it */
103104
static bool injection_point_local = false;
104105

106+
/*
107+
* GUC variable
108+
*
109+
* This GUC is useful to control if statistics should be enabled or not
110+
* during a test with injection points, like for example if a test relies
111+
* on a callback run in a critical section where no allocation should happen.
112+
*/
113+
bool inj_stats_enabled = false;
114+
105115
/* Shared memory init callbacks */
106116
static shmem_request_hook_type prev_shmem_request_hook = NULL;
107117
static shmem_startup_hook_type prev_shmem_startup_hook = NULL;
@@ -513,6 +523,19 @@ _PG_init(void)
513523
if (!process_shared_preload_libraries_in_progress)
514524
return;
515525

526+
DefineCustomBoolVariable("injection_points.stats",
527+
"Enables statistics for injection points.",
528+
NULL,
529+
&inj_stats_enabled,
530+
false,
531+
PGC_POSTMASTER,
532+
0,
533+
NULL,
534+
NULL,
535+
NULL);
536+
537+
MarkGUCPrefixReserved("injection_points");
538+
516539
/* Shared memory initialization */
517540
prev_shmem_request_hook = shmem_request_hook;
518541
shmem_request_hook = injection_shmem_request;

src/test/modules/injection_points/injection_stats.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pgstat_fetch_stat_injentry(const char *name)
9191
{
9292
PgStat_StatInjEntry *entry = NULL;
9393

94-
if (!inj_stats_loaded)
94+
if (!inj_stats_loaded || !inj_stats_enabled)
9595
return NULL;
9696

9797
/* Compile the lookup key as a hash of the point name */
@@ -123,7 +123,7 @@ pgstat_create_inj(const char *name)
123123
PgStatShared_InjectionPoint *shstatent;
124124

125125
/* leave if disabled */
126-
if (!inj_stats_loaded)
126+
if (!inj_stats_loaded || !inj_stats_enabled)
127127
return;
128128

129129
entry_ref = pgstat_get_entry_ref_locked(PGSTAT_KIND_INJECTION, InvalidOid,
@@ -142,7 +142,7 @@ void
142142
pgstat_drop_inj(const char *name)
143143
{
144144
/* leave if disabled */
145-
if (!inj_stats_loaded)
145+
if (!inj_stats_loaded || !inj_stats_enabled)
146146
return;
147147

148148
if (!pgstat_drop_entry(PGSTAT_KIND_INJECTION, InvalidOid,
@@ -164,7 +164,7 @@ pgstat_report_inj(const char *name)
164164
PgStat_StatInjEntry *statent;
165165

166166
/* leave if disabled */
167-
if (!inj_stats_loaded)
167+
if (!inj_stats_loaded || !inj_stats_enabled)
168168
return;
169169

170170
entry_ref = pgstat_get_entry_ref_locked(PGSTAT_KIND_INJECTION, InvalidOid,

src/test/modules/injection_points/injection_stats.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#ifndef INJECTION_STATS
1616
#define INJECTION_STATS
1717

18+
/* GUC variable */
19+
extern bool inj_stats_enabled;
20+
1821
/* injection_stats.c */
1922
extern void pgstat_register_inj(void);
2023
extern void pgstat_create_inj(const char *name);

src/test/modules/injection_points/injection_stats_fixed.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pgstat_report_inj_fixed(uint32 numattach,
146146
PgStatShared_InjectionPointFixed *stats_shmem;
147147

148148
/* leave if disabled */
149-
if (!inj_fixed_loaded)
149+
if (!inj_fixed_loaded || !inj_stats_enabled)
150150
return;
151151

152152
stats_shmem = pgstat_get_custom_shmem_data(PGSTAT_KIND_INJECTION_FIXED);
@@ -172,7 +172,7 @@ injection_points_stats_fixed(PG_FUNCTION_ARGS)
172172
bool nulls[5] = {0};
173173
PgStat_StatInjFixedEntry *stats;
174174

175-
if (!inj_fixed_loaded)
175+
if (!inj_fixed_loaded || !inj_stats_enabled)
176176
PG_RETURN_NULL();
177177

178178
pgstat_snapshot_fixed(PGSTAT_KIND_INJECTION_FIXED);

src/test/modules/injection_points/t/001_stats.pl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@
2020
# Node initialization
2121
my $node = PostgreSQL::Test::Cluster->new('master');
2222
$node->init;
23-
$node->append_conf('postgresql.conf',
24-
"shared_preload_libraries = 'injection_points'");
23+
$node->append_conf(
24+
'postgresql.conf', qq(
25+
shared_preload_libraries = 'injection_points'
26+
injection_points.stats = true
27+
));
2528
$node->start;
2629
$node->safe_psql('postgres', 'CREATE EXTENSION injection_points;');
2730

0 commit comments

Comments
 (0)