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

Commit2793ace

Browse files
committed
injection_points: Add stats for point caching and loading
This adds two counters to the fixed-numbered stats of injection pointsto track the number of times injection points have been cached andloaded from the cache, as of the additions coming froma0a5869 and4b21100.These should have been part off68cd84, but I have lacked time andenergy back then, and it did not prevent the code to be a usefultemplate.While on it, this commit simplifies the description of a few tests whileadding coverage for the new stats data.Author: Yogesh SharmaDiscussion:https://postgr.es/m/3a6977f7-54ab-43ce-8806-11d5e15526a2@catprosystems.com
1 parentb10528e commit2793ace

File tree

5 files changed

+45
-13
lines changed

5 files changed

+45
-13
lines changed

‎src/test/modules/injection_points/injection_points--1.0.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ LANGUAGE C STRICT;
9191
-- Reports fixed-numbered statistics for injection points.
9292
CREATEFUNCTIONinjection_points_stats_fixed(OUT numattach int8,
9393
OUT numdetach int8,
94-
OUT numrun int8)
94+
OUT numrun int8,
95+
OUT numcached int8,
96+
OUT numloaded int8)
9597
RETURNS record
9698
AS'MODULE_PATHNAME','injection_points_stats_fixed'
9799
LANGUAGE C STRICT;

‎src/test/modules/injection_points/injection_points.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ injection_points_attach(PG_FUNCTION_ARGS)
297297
condition.pid=MyProcPid;
298298
}
299299

300-
pgstat_report_inj_fixed(1,0,0);
300+
pgstat_report_inj_fixed(1,0,0,0,0);
301301
InjectionPointAttach(name,"injection_points",function,&condition,
302302
sizeof(InjectionPointCondition));
303303

@@ -329,6 +329,7 @@ injection_points_load(PG_FUNCTION_ARGS)
329329
if (inj_state==NULL)
330330
injection_init_shmem();
331331

332+
pgstat_report_inj_fixed(0,0,0,0,1);
332333
INJECTION_POINT_LOAD(name);
333334

334335
PG_RETURN_VOID();
@@ -343,7 +344,7 @@ injection_points_run(PG_FUNCTION_ARGS)
343344
{
344345
char*name=text_to_cstring(PG_GETARG_TEXT_PP(0));
345346

346-
pgstat_report_inj_fixed(0,0,1);
347+
pgstat_report_inj_fixed(0,0,1,0,0);
347348
INJECTION_POINT(name);
348349

349350
PG_RETURN_VOID();
@@ -358,6 +359,7 @@ injection_points_cached(PG_FUNCTION_ARGS)
358359
{
359360
char*name=text_to_cstring(PG_GETARG_TEXT_PP(0));
360361

362+
pgstat_report_inj_fixed(0,0,0,1,0);
361363
INJECTION_POINT_CACHED(name);
362364

363365
PG_RETURN_VOID();
@@ -434,7 +436,7 @@ injection_points_detach(PG_FUNCTION_ARGS)
434436
{
435437
char*name=text_to_cstring(PG_GETARG_TEXT_PP(0));
436438

437-
pgstat_report_inj_fixed(0,1,0);
439+
pgstat_report_inj_fixed(0,1,0,0,0);
438440
if (!InjectionPointDetach(name))
439441
elog(ERROR,"could not detach injection point \"%s\"",name);
440442

‎src/test/modules/injection_points/injection_stats.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ extern void pgstat_report_inj(const char *name);
2525
externvoidpgstat_register_inj_fixed(void);
2626
externvoidpgstat_report_inj_fixed(uint32numattach,
2727
uint32numdetach,
28-
uint32numrun);
28+
uint32numrun,
29+
uint32numcached,
30+
uint32numloaded);
2931

3032
#endif

‎src/test/modules/injection_points/injection_stats_fixed.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ typedef struct PgStat_StatInjFixedEntry
2929
PgStat_Counternumattach;/* number of points attached */
3030
PgStat_Counternumdetach;/* number of points detached */
3131
PgStat_Counternumrun;/* number of points run */
32+
PgStat_Counternumcached;/* number of points cached */
33+
PgStat_Counternumloaded;/* number of points loaded */
3234
TimestampTzstat_reset_timestamp;
3335
}PgStat_StatInjFixedEntry;
3436

@@ -114,6 +116,8 @@ injection_stats_fixed_snapshot_cb(void)
114116
FIXED_COMP(numattach);
115117
FIXED_COMP(numdetach);
116118
FIXED_COMP(numrun);
119+
FIXED_COMP(numcached);
120+
FIXED_COMP(numloaded);
117121
#undef FIXED_COMP
118122
}
119123

@@ -135,7 +139,9 @@ pgstat_register_inj_fixed(void)
135139
void
136140
pgstat_report_inj_fixed(uint32numattach,
137141
uint32numdetach,
138-
uint32numrun)
142+
uint32numrun,
143+
uint32numcached,
144+
uint32numloaded)
139145
{
140146
PgStatShared_InjectionPointFixed*stats_shmem;
141147

@@ -149,6 +155,8 @@ pgstat_report_inj_fixed(uint32 numattach,
149155
stats_shmem->stats.numattach+=numattach;
150156
stats_shmem->stats.numdetach+=numdetach;
151157
stats_shmem->stats.numrun+=numrun;
158+
stats_shmem->stats.numcached+=numcached;
159+
stats_shmem->stats.numloaded+=numloaded;
152160
pgstat_end_changecount_write(&stats_shmem->changecount);
153161
}
154162

@@ -160,8 +168,8 @@ Datum
160168
injection_points_stats_fixed(PG_FUNCTION_ARGS)
161169
{
162170
TupleDesctupdesc;
163-
Datumvalues[3]= {0};
164-
boolnulls[3]= {0};
171+
Datumvalues[5]= {0};
172+
boolnulls[5]= {0};
165173
PgStat_StatInjFixedEntry*stats;
166174

167175
if (!inj_fixed_loaded)
@@ -171,21 +179,29 @@ injection_points_stats_fixed(PG_FUNCTION_ARGS)
171179
stats=pgstat_get_custom_snapshot_data(PGSTAT_KIND_INJECTION_FIXED);
172180

173181
/* Initialise attributes information in the tuple descriptor */
174-
tupdesc=CreateTemplateTupleDesc(3);
182+
tupdesc=CreateTemplateTupleDesc(5);
175183
TupleDescInitEntry(tupdesc, (AttrNumber)1,"numattach",
176184
INT8OID,-1,0);
177185
TupleDescInitEntry(tupdesc, (AttrNumber)2,"numdetach",
178186
INT8OID,-1,0);
179187
TupleDescInitEntry(tupdesc, (AttrNumber)3,"numrun",
180188
INT8OID,-1,0);
189+
TupleDescInitEntry(tupdesc, (AttrNumber)4,"numcached",
190+
INT8OID,-1,0);
191+
TupleDescInitEntry(tupdesc, (AttrNumber)5,"numloaded",
192+
INT8OID,-1,0);
181193
BlessTupleDesc(tupdesc);
182194

183195
values[0]=Int64GetDatum(stats->numattach);
184196
values[1]=Int64GetDatum(stats->numdetach);
185197
values[2]=Int64GetDatum(stats->numrun);
198+
values[3]=Int64GetDatum(stats->numcached);
199+
values[4]=Int64GetDatum(stats->numloaded);
186200
nulls[0]= false;
187201
nulls[1]= false;
188202
nulls[2]= false;
203+
nulls[3]= false;
204+
nulls[4]= false;
189205

190206
/* Returns the record as Datum */
191207
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc,values,nulls)));

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,26 @@
3535
is($numcalls,'2','number of stats calls');
3636
my$fixedstats =$node->safe_psql('postgres',
3737
"SELECT * FROM injection_points_stats_fixed();");
38-
is($fixedstats,'1|0|2','number of fixed stats');
38+
is($fixedstats,'1|0|2|0|0','fixed stats after some calls');
39+
40+
# Loading and caching.
41+
$node->safe_psql(
42+
'postgres',"
43+
SELECT injection_points_load('stats-notice');
44+
SELECT injection_points_cached('stats-notice');
45+
");
46+
$fixedstats =$node->safe_psql('postgres',
47+
"SELECT * FROM injection_points_stats_fixed();");
48+
is($fixedstats,'1|0|2|1|1','fixed stats after loading and caching');
3949

4050
# Restart the node cleanly, stats should still be around.
4151
$node->restart;
4252
$numcalls =$node->safe_psql('postgres',
4353
"SELECT injection_points_stats_numcalls('stats-notice');");
44-
is($numcalls,'2','number of stats after clean restart');
54+
is($numcalls,'3','number of stats after clean restart');
4555
$fixedstats =$node->safe_psql('postgres',
4656
"SELECT * FROM injection_points_stats_fixed();");
47-
is($fixedstats,'1|0|2','number offixed stats after clean restart');
57+
is($fixedstats,'1|0|2|1|1','fixed stats after clean restart');
4858

4959
# On crash the stats are gone.
5060
$node->stop('immediate');
@@ -54,6 +64,6 @@
5464
is($numcalls,'','number of stats after crash');
5565
$fixedstats =$node->safe_psql('postgres',
5666
"SELECT * FROM injection_points_stats_fixed();");
57-
is($fixedstats,'0|0|0','number offixed stats after crash');
67+
is($fixedstats,'0|0|0|0|0','fixed stats after crash');
5868

5969
done_testing();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp