1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-20 05:03:10 +03:00
Files
postgres/src/bin/pg_test_timing/t/001_basic.pl
Tom Lane 0b096e379e Change pg_test_timing to measure in nanoseconds not microseconds.
Most of our platforms have better-than-microsecond timing resolution,
so the original definition of this program is getting less and less
useful.  Make it report nanoseconds not microseconds.  Also, add a
second output table that reports the exact observed timing durations,
up to a limit of 1024 ns; and be sure to report the largest observed
duration.

The documentation for this program included a lot of system-specific
details that now seem largely obsolete.  Move all that text to the
PG wiki, where perhaps it will be easier to maintain and update.

Also, improve the TAP test so that it actually runs a short standard
run, allowing most of the code to be exercised; its coverage before
was abysmal.

Author: Hannu Krosing <hannuk@google.com>
Co-authored-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/be0339cc-1ae1-4892-9445-8e6d8995a44d@eisentraut.org
2025-07-08 11:23:15 -04:00

47 lines
1.3 KiB
Perl

# Copyright (c) 2021-2025, PostgreSQL Global Development Group
use strict;
use warnings FATAL => 'all';
use PostgreSQL::Test::Utils;
use Test::More;
#########################################
# Basic checks
program_help_ok('pg_test_timing');
program_version_ok('pg_test_timing');
program_options_handling_ok('pg_test_timing');
#########################################
# Test invalid option combinations
command_fails_like(
[ 'pg_test_timing', '--duration' => 'a' ],
qr/\Qpg_test_timing: invalid argument for option --duration\E/,
'pg_test_timing: invalid argument for option --duration');
command_fails_like(
[ 'pg_test_timing', '--duration' => '0' ],
qr/\Qpg_test_timing: --duration must be in range 1..4294967295\E/,
'pg_test_timing: --duration must be in range');
command_fails_like(
[ 'pg_test_timing', '--cutoff' => '101' ],
qr/\Qpg_test_timing: --cutoff must be in range 0..100\E/,
'pg_test_timing: --cutoff must be in range');
#########################################
# We obviously can't check for specific output, but we can
# do a simple run and make sure it produces something.
command_like(
[ 'pg_test_timing', '--duration' => '1' ],
qr/
\QTesting timing overhead for 1 second.\E.*
\QHistogram of timing durations:\E.*
\QObserved timing durations up to 99.9900%:\E
/sx,
'pg_test_timing: sanity check');
done_testing();