mirror of
https://github.com/zebrajr/postgres.git
synced 2025-12-06 12:20:15 +01:00
injection_points: Enable entry count in its variable-sized stats
This serves as coverage for the tracking of entry count added by
7bd2975fa9 as built-in variable-sized stats kinds have no need for it,
at least not yet.
A new function, called injection_points_stats_count(), is added to the
module. It is able to return the number of entries. This has been
useful when doing some benchmarking to check the sanity of the counts.
Author: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://postgr.es/m/aMPKWR81KT5UXvEr@paquier.xyz
This commit is contained in:
parent
7bd2975fa9
commit
acf0960c23
|
|
@ -99,6 +99,16 @@ RETURNS bigint
|
||||||
AS 'MODULE_PATHNAME', 'injection_points_stats_numcalls'
|
AS 'MODULE_PATHNAME', 'injection_points_stats_numcalls'
|
||||||
LANGUAGE C STRICT;
|
LANGUAGE C STRICT;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- injection_points_stats_count()
|
||||||
|
--
|
||||||
|
-- Return the number of entries stored in the pgstats hash table.
|
||||||
|
--
|
||||||
|
CREATE FUNCTION injection_points_stats_count()
|
||||||
|
RETURNS bigint
|
||||||
|
AS 'MODULE_PATHNAME', 'injection_points_stats_count'
|
||||||
|
LANGUAGE C STRICT;
|
||||||
|
|
||||||
--
|
--
|
||||||
-- injection_points_stats_drop()
|
-- injection_points_stats_drop()
|
||||||
--
|
--
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ static const PgStat_KindInfo injection_stats = {
|
||||||
.name = "injection_points",
|
.name = "injection_points",
|
||||||
.fixed_amount = false, /* Bounded by the number of points */
|
.fixed_amount = false, /* Bounded by the number of points */
|
||||||
.write_to_file = true,
|
.write_to_file = true,
|
||||||
|
.track_entry_count = true,
|
||||||
|
|
||||||
/* Injection points are system-wide */
|
/* Injection points are system-wide */
|
||||||
.accessed_across_databases = true,
|
.accessed_across_databases = true,
|
||||||
|
|
@ -196,6 +197,17 @@ injection_points_stats_numcalls(PG_FUNCTION_ARGS)
|
||||||
PG_RETURN_INT64(entry->numcalls);
|
PG_RETURN_INT64(entry->numcalls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* SQL function returning the number of entries allocated for injection
|
||||||
|
* points in the shared hashtable of pgstats.
|
||||||
|
*/
|
||||||
|
PG_FUNCTION_INFO_V1(injection_points_stats_count);
|
||||||
|
Datum
|
||||||
|
injection_points_stats_count(PG_FUNCTION_ARGS)
|
||||||
|
{
|
||||||
|
PG_RETURN_INT64(pgstat_get_entry_count(PGSTAT_KIND_INJECTION));
|
||||||
|
}
|
||||||
|
|
||||||
/* Only used by injection_points_stats_drop() */
|
/* Only used by injection_points_stats_drop() */
|
||||||
static bool
|
static bool
|
||||||
match_inj_entries(PgStatShared_HashEntry *entry, Datum match_data)
|
match_inj_entries(PgStatShared_HashEntry *entry, Datum match_data)
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,9 @@ $node->safe_psql('postgres', "SELECT injection_points_run('stats-notice');");
|
||||||
my $numcalls = $node->safe_psql('postgres',
|
my $numcalls = $node->safe_psql('postgres',
|
||||||
"SELECT injection_points_stats_numcalls('stats-notice');");
|
"SELECT injection_points_stats_numcalls('stats-notice');");
|
||||||
is($numcalls, '2', 'number of stats calls');
|
is($numcalls, '2', 'number of stats calls');
|
||||||
|
my $entrycount =
|
||||||
|
$node->safe_psql('postgres', "SELECT injection_points_stats_count();");
|
||||||
|
is($entrycount, '1', 'number of entries');
|
||||||
my $fixedstats = $node->safe_psql('postgres',
|
my $fixedstats = $node->safe_psql('postgres',
|
||||||
"SELECT * FROM injection_points_stats_fixed();");
|
"SELECT * FROM injection_points_stats_fixed();");
|
||||||
is($fixedstats, '1|0|2|0|0', 'fixed stats after some calls');
|
is($fixedstats, '1|0|2|0|0', 'fixed stats after some calls');
|
||||||
|
|
@ -55,6 +58,9 @@ $node->restart;
|
||||||
$numcalls = $node->safe_psql('postgres',
|
$numcalls = $node->safe_psql('postgres',
|
||||||
"SELECT injection_points_stats_numcalls('stats-notice');");
|
"SELECT injection_points_stats_numcalls('stats-notice');");
|
||||||
is($numcalls, '3', 'number of stats after clean restart');
|
is($numcalls, '3', 'number of stats after clean restart');
|
||||||
|
$entrycount =
|
||||||
|
$node->safe_psql('postgres', "SELECT injection_points_stats_count();");
|
||||||
|
is($entrycount, '1', 'number of entries after clean restart');
|
||||||
$fixedstats = $node->safe_psql('postgres',
|
$fixedstats = $node->safe_psql('postgres',
|
||||||
"SELECT * FROM injection_points_stats_fixed();");
|
"SELECT * FROM injection_points_stats_fixed();");
|
||||||
is($fixedstats, '1|0|2|1|1', 'fixed stats after clean restart');
|
is($fixedstats, '1|0|2|1|1', 'fixed stats after clean restart');
|
||||||
|
|
@ -65,6 +71,9 @@ $node->start;
|
||||||
$numcalls = $node->safe_psql('postgres',
|
$numcalls = $node->safe_psql('postgres',
|
||||||
"SELECT injection_points_stats_numcalls('stats-notice');");
|
"SELECT injection_points_stats_numcalls('stats-notice');");
|
||||||
is($numcalls, '', 'number of stats after crash');
|
is($numcalls, '', 'number of stats after crash');
|
||||||
|
$entrycount =
|
||||||
|
$node->safe_psql('postgres', "SELECT injection_points_stats_count();");
|
||||||
|
is($entrycount, '0', 'number of entries after crash');
|
||||||
$fixedstats = $node->safe_psql('postgres',
|
$fixedstats = $node->safe_psql('postgres',
|
||||||
"SELECT * FROM injection_points_stats_fixed();");
|
"SELECT * FROM injection_points_stats_fixed();");
|
||||||
is($fixedstats, '0|0|0|0|0', 'fixed stats after crash');
|
is($fixedstats, '0|0|0|0|0', 'fixed stats after crash');
|
||||||
|
|
@ -81,6 +90,9 @@ $node->safe_psql('postgres', "SELECT injection_points_stats_drop();");
|
||||||
$numcalls = $node->safe_psql('postgres',
|
$numcalls = $node->safe_psql('postgres',
|
||||||
"SELECT injection_points_stats_numcalls('stats-notice');");
|
"SELECT injection_points_stats_numcalls('stats-notice');");
|
||||||
is($numcalls, '', 'no stats after drop via SQL function');
|
is($numcalls, '', 'no stats after drop via SQL function');
|
||||||
|
$entrycount =
|
||||||
|
$node->safe_psql('postgres', "SELECT injection_points_stats_count();");
|
||||||
|
is($entrycount, '0', 'number of entries after drop via SQL function');
|
||||||
|
|
||||||
# Stop the server, disable the module, then restart. The server
|
# Stop the server, disable the module, then restart. The server
|
||||||
# should be able to come up.
|
# should be able to come up.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user