Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2e35c67

Browse files
committed
injection_point: Add injection_points.stats
This GUC controls if cumulative statistics are enabled or not in themodule. Custom statistics require the module to be loaded withshared_preload_libraries, hence this GUC is made PGC_POSTMASTER. Bydefault, the stats are disabled. 001_stats.pl is updated to enable thestatistics, as it is the only area where these are required now.This will be used by an upcoming change for the injection point testadded by768a9fd where stats should not be used, as the test runs apoint callback in a critical section. And the module injection_pointswill need to be loaded with shared_preload_libraries there.Per discussion with Álvaro Herrera.Author: Michael PaquierDiscussion:https://postgr.es/m/ZsUnJUlSOBNAzwW1@paquier.xyz
1 parentb2b023a commit2e35c67

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
staticboolinjection_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+
boolinj_stats_enabled= false;
114+
105115
/* Shared memory init callbacks */
106116
staticshmem_request_hook_typeprev_shmem_request_hook=NULL;
107117
staticshmem_startup_hook_typeprev_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
returnNULL;
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(constchar*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
#ifndefINJECTION_STATS
1616
#defineINJECTION_STATS
1717

18+
/* GUC variable */
19+
externboolinj_stats_enabled;
20+
1821
/* injection_stats.c */
1922
externvoidpgstat_register_inj(void);
2023
externvoidpgstat_create_inj(constchar*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
boolnulls[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)

[8]ページ先頭

©2009-2025 Movatter.jp