mirror of
https://github.com/postgres/postgres.git
synced 2025-10-16 17:07:43 +03: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:
@@ -99,6 +99,16 @@ RETURNS bigint
|
||||
AS 'MODULE_PATHNAME', 'injection_points_stats_numcalls'
|
||||
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()
|
||||
--
|
||||
|
@@ -40,6 +40,7 @@ static const PgStat_KindInfo injection_stats = {
|
||||
.name = "injection_points",
|
||||
.fixed_amount = false, /* Bounded by the number of points */
|
||||
.write_to_file = true,
|
||||
.track_entry_count = true,
|
||||
|
||||
/* Injection points are system-wide */
|
||||
.accessed_across_databases = true,
|
||||
@@ -196,6 +197,17 @@ injection_points_stats_numcalls(PG_FUNCTION_ARGS)
|
||||
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() */
|
||||
static bool
|
||||
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',
|
||||
"SELECT injection_points_stats_numcalls('stats-notice');");
|
||||
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',
|
||||
"SELECT * FROM injection_points_stats_fixed();");
|
||||
is($fixedstats, '1|0|2|0|0', 'fixed stats after some calls');
|
||||
@@ -55,6 +58,9 @@ $node->restart;
|
||||
$numcalls = $node->safe_psql('postgres',
|
||||
"SELECT injection_points_stats_numcalls('stats-notice');");
|
||||
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',
|
||||
"SELECT * FROM injection_points_stats_fixed();");
|
||||
is($fixedstats, '1|0|2|1|1', 'fixed stats after clean restart');
|
||||
@@ -65,6 +71,9 @@ $node->start;
|
||||
$numcalls = $node->safe_psql('postgres',
|
||||
"SELECT injection_points_stats_numcalls('stats-notice');");
|
||||
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',
|
||||
"SELECT * FROM injection_points_stats_fixed();");
|
||||
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',
|
||||
"SELECT injection_points_stats_numcalls('stats-notice');");
|
||||
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
|
||||
# should be able to come up.
|
||||
|
Reference in New Issue
Block a user