Skip to content

Commit 4e38d71

Browse files
authored
bpo-28643: Record profile-opt build progress with stamp files (#4223)
* bpo-28643: Record profile-opt build progress with stamp files The profile-opt makefile target is expensive to build. Since the makefile does not contain complete dependency information for this target, much extra work can get done if the build is interrupted and re-started. Even running "make" a second time will result in a huge amount of redundant work. As a minimal fix (rather than removing recursive "make" and adding a proper dependency graph), split the profile-opt target into parts: - ensure tree is clean (profile-clean-stamp) - build with profile generation enabled (profile-gen-stamp) - run task to generate profile information (profile-run-stamp) - build optimized Python using above information (profile-opt) We use "stamp" files to record completion of the steps. Running "make clean" will not remove the profile-run-stamp file. Other minor changes: - remove the "build_all_use_profile" target. I don't expect callers of the makefile to use this target so that should be safe. - remove execution of "profile-removal" at end of "profile-opt". I don't see any reason to not to keep the profile information, given the cost to generate it. Removing the "profile-run-stamp" file will force re-generation of it.
1 parent 0d2c645 commit 4e38d71

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

Makefile.pre.in

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -442,25 +442,37 @@ DTRACE_DEPS = \
442442
all: @DEF_MAKE_ALL_RULE@
443443
build_all: $(BUILDPYTHON) oldsharedmods sharedmods gdbhooks Programs/_testembed python-config
444444

445-
# Compile a binary with profile guided optimization.
446-
profile-opt:
445+
# Profile generation build must start from a clean tree.
446+
profile-clean-stamp:
447+
$(MAKE) clean profile-removal
448+
touch $@
449+
450+
# Compile with profile generation enabled.
451+
profile-gen-stamp: profile-clean-stamp
447452
@if [ $(LLVM_PROF_ERR) = yes ]; then \
448453
echo "Error: Cannot perform PGO build because llvm-profdata was not found in PATH" ;\
449454
echo "Please add it to PATH and run ./configure again" ;\
450455
exit 1;\
451456
fi
452457
@echo "Building with support for profile generation:"
453-
$(MAKE) clean
454-
$(MAKE) profile-removal
455458
$(MAKE) build_all_generate_profile
456-
$(MAKE) profile-removal
459+
touch $@
460+
461+
# Run task with profile generation build to create profile information.
462+
profile-run-stamp:
457463
@echo "Running code to generate profile data (this can take a while):"
464+
# First, we need to create a clean build with profile generation
465+
# enabled.
466+
$(MAKE) profile-gen-stamp
467+
# Next, run the profile task to generate the profile information.
458468
$(MAKE) run_profile_task
459469
$(MAKE) build_all_merge_profile
460-
@echo "Rebuilding with profile guided optimizations:"
470+
# Remove profile generation binary since we are done with it.
461471
$(MAKE) clean
462-
$(MAKE) build_all_use_profile
463-
$(MAKE) profile-removal
472+
# This is an expensive target to build and it does not have proper
473+
# makefile dependancy information. So, we create a "stamp" file
474+
# to record its completion and avoid re-running it.
475+
touch $@
464476

465477
build_all_generate_profile:
466478
$(MAKE) @DEF_MAKE_RULE@ CFLAGS_NODIST="$(CFLAGS) $(PGO_PROF_GEN_FLAG)" LDFLAGS="$(LDFLAGS) $(PGO_PROF_GEN_FLAG)" LIBS="$(LIBS)"
@@ -472,7 +484,11 @@ run_profile_task:
472484
build_all_merge_profile:
473485
$(LLVM_PROF_MERGER)
474486

475-
build_all_use_profile:
487+
# Compile Python binary with profile guided optimization.
488+
# To force re-running of the profile task, remove the profile-run-stamp file.
489+
profile-opt: profile-run-stamp
490+
@echo "Rebuilding with profile guided optimizations:"
491+
-rm -f profile-clean-stamp
476492
$(MAKE) @DEF_MAKE_RULE@ CFLAGS_NODIST="$(CFLAGS) $(PGO_PROF_USE_FLAG)" LDFLAGS="$(LDFLAGS)"
477493

478494
# Compile and run with gcov
@@ -1621,13 +1637,15 @@ clean: pycremoval
16211637
-rm -f Programs/_testembed Programs/_freeze_importlib
16221638
-find build -type f -a ! -name '*.gc??' -exec rm -f {} ';'
16231639
-rm -f Include/pydtrace_probes.h
1640+
-rm -f profile-gen-stamp
16241641

16251642
profile-removal:
16261643
find . -name '*.gc??' -exec rm -f {} ';'
16271644
find . -name '*.profclang?' -exec rm -f {} ';'
16281645
find . -name '*.dyn' -exec rm -f {} ';'
16291646
rm -f $(COVERAGE_INFO)
16301647
rm -rf $(COVERAGE_REPORT)
1648+
rm -f profile-run-stamp
16311649

16321650
clobber: clean profile-removal
16331651
-rm -f $(BUILDPYTHON) $(PGEN) $(LIBRARY) $(LDLIBRARY) $(DLLLIBRARY) \
@@ -1636,6 +1654,7 @@ clobber: clean profile-removal
16361654
-rm -rf build platform
16371655
-rm -rf $(PYTHONFRAMEWORKDIR)
16381656
-rm -f python-config.py python-config
1657+
-rm -f profile-gen-stamp profile-clean-stamp
16391658

16401659
# Make things extra clean, before making a distribution:
16411660
# remove all generated files, even Makefile[.pre]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Record profile-opt build progress with stamp files.

0 commit comments

Comments
 (0)