Skip to content

Commit 2406672

Browse files
bpo-36044: Reduce number of unit tests run for PGO build (GH-14702)
Reduce the number of unit tests run for the PGO generation task. This speeds up the task by a factor of about 15x. Running the full unit test suite is slow. This change may result in a slightly less optimized build since not as many code branches will be executed. If you are willing to wait for the much slower build, the old behavior can be restored using './configure [..] PROFILE_TASK="-m test --pgo-extended"'. We make no guarantees as to which PGO task set produces a faster build. Users who care should run their own relevant benchmarks as results can depend on the environment, workload, and compiler tool chain. (cherry picked from commit 4e16a4a) Co-authored-by: Neil Schemenauer <[email protected]>
1 parent 5b39852 commit 2406672

File tree

7 files changed

+96
-4
lines changed

7 files changed

+96
-4
lines changed

Lib/test/libregrtest/cmdline.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,9 @@ def _create_parser():
264264
help='only write the name of test cases that will be run'
265265
' , don\'t execute them')
266266
group.add_argument('-P', '--pgo', dest='pgo', action='store_true',
267-
help='enable Profile Guided Optimization training')
267+
help='enable Profile Guided Optimization (PGO) training')
268+
group.add_argument('--pgo-extended', action='store_true',
269+
help='enable extended PGO training (slower training)')
268270
group.add_argument('--fail-env-changed', action='store_true',
269271
help='if a test file alters the environment, mark '
270272
'the test as failed')
@@ -344,6 +346,8 @@ def _parse_args(args, **kwargs):
344346
parser.error("-G/--failfast needs either -v or -W")
345347
if ns.pgo and (ns.verbose or ns.verbose2 or ns.verbose3):
346348
parser.error("--pgo/-v don't go together!")
349+
if ns.pgo_extended:
350+
ns.pgo = True # pgo_extended implies pgo
347351

348352
if ns.nowindows:
349353
print("Warning: the --nowindows (-n) option is deprecated. "

Lib/test/libregrtest/main.py

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
INTERRUPTED, CHILD_ERROR, TEST_DID_NOT_RUN,
1818
PROGRESS_MIN_TIME, format_test_result, is_failed)
1919
from test.libregrtest.setup import setup_tests
20+
from test.libregrtest.pgo import setup_pgo_tests
2021
from test.libregrtest.utils import removepy, count, format_duration, printlist
2122
from test import support
2223

@@ -214,6 +215,9 @@ def find_tests(self, tests):
214215

215216
removepy(self.tests)
216217

218+
# add default PGO tests if no tests are specified
219+
setup_pgo_tests(self.ns)
220+
217221
stdtests = STDTESTS[:]
218222
nottests = NOTTESTS.copy()
219223
if self.ns.exclude:

Lib/test/libregrtest/pgo.py

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Set of tests run by default if --pgo is specified. The tests below were
2+
# chosen based on the following criteria: either they exercise a commonly used
3+
# C extension module or type, or they run some relatively typical Python code.
4+
# Long running tests should be avoided because the PGO instrumented executable
5+
# runs slowly.
6+
PGO_TESTS = [
7+
'test_array',
8+
'test_base64',
9+
'test_binascii',
10+
'test_binop',
11+
'test_bisect',
12+
'test_bytes',
13+
'test_cmath',
14+
'test_codecs',
15+
'test_collections',
16+
'test_complex',
17+
'test_dataclasses',
18+
'test_datetime',
19+
'test_decimal',
20+
'test_difflib',
21+
'test_embed',
22+
'test_float',
23+
'test_fstring',
24+
'test_functools',
25+
'test_generators',
26+
'test_hashlib',
27+
'test_heapq',
28+
'test_int',
29+
'test_itertools',
30+
'test_json',
31+
'test_long',
32+
'test_math',
33+
'test_memoryview',
34+
'test_operator',
35+
'test_ordered_dict',
36+
'test_pickle',
37+
'test_pprint',
38+
'test_re',
39+
'test_set',
40+
'test_statistics',
41+
'test_struct',
42+
'test_tabnanny',
43+
'test_time',
44+
'test_unicode',
45+
'test_xml_etree',
46+
'test_xml_etree_c',
47+
]
48+
49+
def setup_pgo_tests(ns):
50+
if not ns.args and not ns.pgo_extended:
51+
# run default set of tests for PGO training
52+
ns.args = PGO_TESTS[:]

Makefile.pre.in

+4-3
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,10 @@ TCLTK_INCLUDES= @TCLTK_INCLUDES@
255255
TCLTK_LIBS= @TCLTK_LIBS@
256256

257257
# The task to run while instrumented when building the profile-opt target.
258-
# We exclude unittests with -x that take a rediculious amount of time to
259-
# run in the instrumented training build or do not provide much value.
260-
PROFILE_TASK=-m test.regrtest --pgo
258+
# To speed up profile generation, we don't run the full unit test suite
259+
# by default. The default is "-m test --pgo". To run more tests, use
260+
# PROFILE_TASK="-m test --pgo-extended"
261+
PROFILE_TASK= @PROFILE_TASK@
261262

262263
# report files for gcov / lcov coverage report
263264
COVERAGE_INFO= $(abs_builddir)/coverage.info
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Reduce the number of unit tests run for the PGO generation task. This
2+
speeds up the task by a factor of about 15x. Running the full unit test
3+
suite is slow. This change may result in a slightly less optimized build
4+
since not as many code branches will be executed. If you are willing to
5+
wait for the much slower build, the old behavior can be restored using
6+
'./configure [..] PROFILE_TASK="-m test --pgo-extended"'. We make no
7+
guarantees as to which PGO task set produces a faster build. Users who
8+
care should run their own relevant benchmarks as results can depend on
9+
the environment, workload, and compiler tool chain.

configure

+14
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,7 @@ target_vendor
686686
target_cpu
687687
target
688688
LLVM_AR
689+
PROFILE_TASK
689690
DEF_MAKE_RULE
690691
DEF_MAKE_ALL_RULE
691692
ABIFLAGS
@@ -856,6 +857,7 @@ LDFLAGS
856857
LIBS
857858
CPPFLAGS
858859
CPP
860+
PROFILE_TASK
859861
PKG_CONFIG
860862
PKG_CONFIG_PATH
861863
PKG_CONFIG_LIBDIR'
@@ -1559,6 +1561,8 @@ Some influential environment variables:
15591561
CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
15601562
you have headers in a nonstandard directory <include dir>
15611563
CPP C preprocessor
1564+
PROFILE_TASK
1565+
Python args for PGO generation task
15621566
PKG_CONFIG path to pkg-config utility
15631567
PKG_CONFIG_PATH
15641568
directories to add to pkg-config's search path
@@ -6426,6 +6430,16 @@ else
64266430
DEF_MAKE_RULE="all"
64276431
fi
64286432

6433+
6434+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking PROFILE_TASK" >&5
6435+
$as_echo_n "checking PROFILE_TASK... " >&6; }
6436+
if test -z "$PROFILE_TASK"
6437+
then
6438+
PROFILE_TASK='-m test --pgo'
6439+
fi
6440+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $PROFILE_TASK" >&5
6441+
$as_echo "$PROFILE_TASK" >&6; }
6442+
64296443
# Make llvm-relatec checks work on systems where llvm tools are not installed with their
64306444
# normal names in the default $PATH (ie: Ubuntu). They exist under the
64316445
# non-suffixed name in their versioned llvm directory.

configure.ac

+8
Original file line numberDiff line numberDiff line change
@@ -1293,6 +1293,14 @@ else
12931293
DEF_MAKE_RULE="all"
12941294
fi
12951295

1296+
AC_ARG_VAR(PROFILE_TASK, Python args for PGO generation task)
1297+
AC_MSG_CHECKING(PROFILE_TASK)
1298+
if test -z "$PROFILE_TASK"
1299+
then
1300+
PROFILE_TASK='-m test --pgo'
1301+
fi
1302+
AC_MSG_RESULT($PROFILE_TASK)
1303+
12961304
# Make llvm-relatec checks work on systems where llvm tools are not installed with their
12971305
# normal names in the default $PATH (ie: Ubuntu). They exist under the
12981306
# non-suffixed name in their versioned llvm directory.

0 commit comments

Comments
 (0)