Skip to content

Commit 72d71e0

Browse files
committed
Add per-test-script runtime display to pg_regress.
It seems useful to have this information available, so that it's easier to tell when a test script is taking a disproportionate amount of time. Discussion: https://postgr.es/m/[email protected]
1 parent cb90de1 commit 72d71e0

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

src/test/regress/pg_regress.c

+24-5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "getopt_long.h"
3737
#include "libpq/pqcomm.h" /* needed for UNIXSOCK_PATH() */
3838
#include "pg_config_paths.h"
39+
#include "portability/instr_time.h"
3940

4041
/* for resultmap we need a list of pairs of strings */
4142
typedef struct _resultmap
@@ -1473,14 +1474,15 @@ results_differ(const char *testname, const char *resultsfile, const char *defaul
14731474

14741475
/*
14751476
* Wait for specified subprocesses to finish, and return their exit
1476-
* statuses into statuses[]
1477+
* statuses into statuses[] and stop times into stoptimes[]
14771478
*
14781479
* If names isn't NULL, print each subprocess's name as it finishes
14791480
*
14801481
* Note: it's OK to scribble on the pids array, but not on the names array
14811482
*/
14821483
static void
1483-
wait_for_tests(PID_TYPE * pids, int *statuses, char **names, int num_tests)
1484+
wait_for_tests(PID_TYPE * pids, int *statuses, instr_time *stoptimes,
1485+
char **names, int num_tests)
14841486
{
14851487
int tests_left;
14861488
int i;
@@ -1533,6 +1535,7 @@ wait_for_tests(PID_TYPE * pids, int *statuses, char **names, int num_tests)
15331535
#endif
15341536
pids[i] = INVALID_PID;
15351537
statuses[i] = (int) exit_status;
1538+
INSTR_TIME_SET_CURRENT(stoptimes[i]);
15361539
if (names)
15371540
status(" %s", names[i]);
15381541
tests_left--;
@@ -1582,6 +1585,8 @@ run_schedule(const char *schedule, test_function tfunc)
15821585
_stringlist *expectfiles[MAX_PARALLEL_TESTS];
15831586
_stringlist *tags[MAX_PARALLEL_TESTS];
15841587
PID_TYPE pids[MAX_PARALLEL_TESTS];
1588+
instr_time starttimes[MAX_PARALLEL_TESTS];
1589+
instr_time stoptimes[MAX_PARALLEL_TESTS];
15851590
int statuses[MAX_PARALLEL_TESTS];
15861591
_stringlist *ignorelist = NULL;
15871592
char scbuf[1024];
@@ -1687,7 +1692,8 @@ run_schedule(const char *schedule, test_function tfunc)
16871692
{
16881693
status(_("test %-28s ... "), tests[0]);
16891694
pids[0] = (tfunc) (tests[0], &resultfiles[0], &expectfiles[0], &tags[0]);
1690-
wait_for_tests(pids, statuses, NULL, 1);
1695+
INSTR_TIME_SET_CURRENT(starttimes[0]);
1696+
wait_for_tests(pids, statuses, stoptimes, NULL, 1);
16911697
/* status line is finished below */
16921698
}
16931699
else if (max_concurrent_tests > 0 && max_concurrent_tests < num_tests)
@@ -1707,12 +1713,15 @@ run_schedule(const char *schedule, test_function tfunc)
17071713
if (i - oldest >= max_connections)
17081714
{
17091715
wait_for_tests(pids + oldest, statuses + oldest,
1716+
stoptimes + oldest,
17101717
tests + oldest, i - oldest);
17111718
oldest = i;
17121719
}
17131720
pids[i] = (tfunc) (tests[i], &resultfiles[i], &expectfiles[i], &tags[i]);
1721+
INSTR_TIME_SET_CURRENT(starttimes[i]);
17141722
}
17151723
wait_for_tests(pids + oldest, statuses + oldest,
1724+
stoptimes + oldest,
17161725
tests + oldest, i - oldest);
17171726
status_end();
17181727
}
@@ -1722,8 +1731,9 @@ run_schedule(const char *schedule, test_function tfunc)
17221731
for (i = 0; i < num_tests; i++)
17231732
{
17241733
pids[i] = (tfunc) (tests[i], &resultfiles[i], &expectfiles[i], &tags[i]);
1734+
INSTR_TIME_SET_CURRENT(starttimes[i]);
17251735
}
1726-
wait_for_tests(pids, statuses, tests, num_tests);
1736+
wait_for_tests(pids, statuses, stoptimes, tests, num_tests);
17271737
status_end();
17281738
}
17291739

@@ -1793,6 +1803,9 @@ run_schedule(const char *schedule, test_function tfunc)
17931803
if (statuses[i] != 0)
17941804
log_child_failure(statuses[i]);
17951805

1806+
INSTR_TIME_SUBTRACT(stoptimes[i], starttimes[i]);
1807+
status(_(" (%.0f ms)"), INSTR_TIME_GET_MILLISEC(stoptimes[i]));
1808+
17961809
status_end();
17971810
}
17981811

@@ -1818,6 +1831,8 @@ static void
18181831
run_single_test(const char *test, test_function tfunc)
18191832
{
18201833
PID_TYPE pid;
1834+
instr_time starttime;
1835+
instr_time stoptime;
18211836
int exit_status;
18221837
_stringlist *resultfiles = NULL;
18231838
_stringlist *expectfiles = NULL;
@@ -1829,7 +1844,8 @@ run_single_test(const char *test, test_function tfunc)
18291844

18301845
status(_("test %-28s ... "), test);
18311846
pid = (tfunc) (test, &resultfiles, &expectfiles, &tags);
1832-
wait_for_tests(&pid, &exit_status, NULL, 1);
1847+
INSTR_TIME_SET_CURRENT(starttime);
1848+
wait_for_tests(&pid, &exit_status, &stoptime, NULL, 1);
18331849

18341850
/*
18351851
* Advance over all three lists simultaneously.
@@ -1867,6 +1883,9 @@ run_single_test(const char *test, test_function tfunc)
18671883
if (exit_status != 0)
18681884
log_child_failure(exit_status);
18691885

1886+
INSTR_TIME_SUBTRACT(stoptime, starttime);
1887+
status(_(" (%.0f ms)"), INSTR_TIME_GET_MILLISEC(stoptime));
1888+
18701889
status_end();
18711890
}
18721891

0 commit comments

Comments
 (0)