python: support profile-optimized build
cover python: support profile-optimized build
This patchset makes it possible to enable profile-guided-optimization (PGO) for Python 2.7 - both native and target recipes.
Enabling PGO for python-native is simple, one patch, basically just changing the make target if PGO is enabled in build conf.
However, the target version requires a lot more convoluted approach because of the cross-build environment. Normally, (python-native in our case) PGO is done in one go by just running "make profile-opt". It first builds python binaries with profile instrumentation enabled. Then, a specific profile task, using that python, is run to get the profile data. Last, a complete re-build of python is done, feeding the compiler with the profile data obtained earlier. Unfortunately, in our cross-build environment this is not possible as the binaries are (cross-)built on the host machine but profiling needs to be done on the target architecture.
The approach used in this patchset splits the PGO build of target python into three steps:
1. build a target python binary with profile instrumentation enabled
2. build a special target image and run the profile task there, copying the profile data back to the build host
3. build an optimized target python binary, guided by the profile data
The first step is done by adding a new "python-profile-opt" recipe. It builds a special version of python that has the profile instrumentation enabled. The idea behind this is to keep "normal" python clean and isolated - not do any intermediate builds or contaminate python with pgo instrumentation.
The second step is implemented by adding a new image recipe. This is a minimal image that basically only contains the functionality for running the special profile-instrumented python and obtaining the profile data. It re-uses facilities from oeqa to communicate with the target instance over ssh. Also here, the idea behind a separate "profiling image" is to keep it isolated and not contaminate the main target build.
The third step is relatively straightforward, enabling the usage of profile data in do_compile in the python recipe.
Instructions for doing a PGO build for target python are:
1. enable profile-optimized build by specifying PYTHON_PROFILE_OPT = "1" in local.conf
2. get profile data by running
bitbake python-pgo-image -c profile
3. (re-)build your distro image
Benchmark results from my i7-3770K desktop machine show 8% to 20% improvement for python-native and 3.6% to 15% improvement for python (qemux86 target).
python-native:
pystone: 141883 -> 168168 pystones/s (+18%) pybench avg: 3367 -> 2795 ms (-20%) regrtest time: 270 -> 250 s (-8%)
python (target):
pystone: 2045 -> 2355 pystones/s (+15%) pybench avg: 181901 -> 175600 ms (-3.6%) regrtest time: 4210 -> 4050 s (-3.8%)
I've not done extensive testing to get statistically reliable results, but, the numbers above should give a useful enough ballpark figure.
New configuration variables, related to this patchset are:
PYTHON_PROFILE_OPT - set to "1" to enable PGO build of python PYTHON_PROFILE_TASK - profile task to run for python PYTHON_NATIVE_PROFILE_OPT - set to "1" to enable PGO build of python-native PYTHON_NATIVE_PROFILE_TASK - profile task to run for python-native
I have a corresponding patchset for Python3, too, and I will send that shortly.
The following changes since commit fc97963bc61bf16112859fe1d7e460a13d34baca:
oeqa/selftest/devtool: rewrite modify testcase (2017-01-19 22:45:46 +0000)
are available in the git repository at:
git://git.openembedded.org/openembedded-core-contrib marquiz/fixes-9338-py2
http://git.openembedded.org/openembedded-core-contrib/log/?h=marquiz/fixes-9338-py2
Markus Lehtonen (10):
python-native: support profile optimized build
python: add python-profile-opt recipe
python: remove path hack from setup.py
python-profile-opt: rename libpython
devtools/images: add python-pgo-image
python: make profile-optimized build possible
python-pgo-image: exclude tests from the default profile target
python: add python-tools subpackage
python-pgo-image: switch python default profile task to pybench
python-pgo-image: enable sstate for do_profile
meta/recipes-devtools/images/python-pgo-image.bb | 75 +++++++++++++++++ .../python/python-2.7-manifest.inc | 8 +- ...x-.so-loading-when-when-running-profile-t.patch | 26 ++++++ .../python/python-native_2.7.12.bb | 10 +++ .../python/python-profile-opt_2.7.12.bb | 13 +++ .../01-use-proper-tools-for-cross-build.patch | 10 --- ...rename-libpython-to-libpython-profile-opt.patch | 94 ++++++++++++++++++++++ meta/recipes-devtools/python/python_2.7.12.bb | 54 +++++++++++-- 8 files changed, 269 insertions(+), 21 deletions(-) create mode 100644 meta/recipes-devtools/images/python-pgo-image.bb create mode 100644 meta/recipes-devtools/python/python-native/Makefile-fix-.so-loading-when-when-running-profile-t.patch create mode 100644 meta/recipes-devtools/python/python-profile-opt_2.7.12.bb create mode 100644 meta/recipes-devtools/python/python/rename-libpython-to-libpython-profile-opt.patch
Signature · 1 line
2.10.2
RFC PATCH 1/10 python-native: support profile optimized build
Make it possible to build python-native with profile directed optimization enabled. The feature is enabled by setting PYTHON_NATIVE_PROFILE_OPT = "1" in local.conf.
The profile task to run may be specified with PYTHON_NATIVE_PROFILE_TASK variable in local.conf, e.g.PYTHON_NATIVE_PROFILE_TASK = "${S}/Tools/pybench/pybench.py -n 2 --with-gc --with-syscheck"
[YOCTO #9338]
--- ...x-.so-loading-when-when-running-profile-t.patch | 26 ++++++++++++++++++++++ .../python/python-native_2.7.12.bb | 10 +++++++++ 2 files changed, 36 insertions(+) create mode 100644 meta/recipes-devtools/python/python-native/Makefile-fix-.so-loading-when-when-running-profile-t.patch
meta/recipes-devtools/python/python-native/Makefile-fix-.so-loading-when-when-running-profile-t.patch new file +26 -0
@@ -0,0 +1,26 @@ +Makefile: fix .so loading when when running profile task + +Use correct search path when doing profiling for profile-optimized +build. This way we load the correct Python libraries, i.e. the ones from +our build directory, and not the ones from the host os. + +Upstream-Status: Pending + +Signed-off-by: Markus Lehtonen <[email protected]> + +diff --git a/Makefile.pre.in b/Makefile.pre.in +index 2affc41..4355e7f 100644 +--- a/Makefile.pre.in ++++ b/Makefile.pre.in +@@ -458,7 +458,7 @@ build_all_generate_profile: + + run_profile_task: + : # FIXME: can't run for a cross build +- $(LLVM_PROF_FILE) ./$(BUILDPYTHON) $(PROFILE_TASK) || true ++ $(LLVM_PROF_FILE) $(RUNSHARED) ./$(BUILDPYTHON) $(PROFILE_TASK) || true + + build_all_merge_profile: + $(LLVM_PROF_MERGER) +-- +2.6.6 +
meta/recipes-devtools/python/python-native_2.7.12.bb +10 -0
@@ -17,6 +17,7 @@ SRC_URI += "\ file://builddir.patch \ file://parallel-makeinst-create-bindir.patch \ file://revert_use_of_sysconfigdata.patch \ + file://Makefile-fix-.so-loading-when-when-running-profile-t.patch \ " S = "${WORKDIR}/Python-${PV}"
@@ -35,10 +36,19 @@ EXTRA_OEMAKE = '\ STAGING_INCDIR=${STAGING_INCDIR_NATIVE} \ ' +PYTHON_NATIVE_MAKE_TARGET ?= "${@'profile-opt' if d.getVar('PYTHON_NATIVE_PROFILE_OPT', True) == '1' else ''}" + do_configure_append() { autoreconf --verbose --install --force --exclude=autopoint ../Python-${PV}/Modules/_ctypes/libffi } +do_compile() { + if [ -n "${PYTHON_NATIVE_PROFILE_TASK}" ]; then + sed -i -e 's,^PROFILE_TASK=.*,PROFILE_TASK=${PYTHON_NATIVE_PROFILE_TASK},g' Makefile + fi + oe_runmake ${PYTHON_NATIVE_MAKE_TARGET} +} + do_install() { oe_runmake 'DESTDIR=${D}' install install -d ${D}${bindir}/${PN}
Signature · 1 line
2.10.2
RFC PATCH 2/10 python: add python-profile-opt recipe
In reply to Markus LehtonenThis patch adds a new recipe that builds a special version of python that produces profile data for profile guided optimization. It will install under /opt in order to prevent clash with the "normal" python. The new recipe directly includes the base python recipe so that they are build in as similar way as possible and this hopefully decreases the recipe maintenance burden, too.
Normally, python profile-guided-optimization is done simply by doing "make profile-opt" which first builds python with profile instrumentation enabled, then runs a profile task to get the profile data, and last, re-builds python with profile data guiding the optimization. However, in our cross-build environment this gets a lot trickier. We need to split out the steps as building is done on the build host but we need to run the second step (i.e. run the profile task) on the target hardware. This patch enables the first step, i.e. building python with profile instrumentation enabled
[YOCTO #9338]
--- .../python/python-profile-opt_2.7.12.bb | 17 ++++++++++++++ meta/recipes-devtools/python/python_2.7.12.bb | 26 +++++++++++++++------- 2 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 meta/recipes-devtools/python/python-profile-opt_2.7.12.bb
meta/recipes-devtools/python/python-profile-opt_2.7.12.bb new file +17 -0
@@ -0,0 +1,17 @@ +require python_${PV}.bb + +PROVIDES += "libpython2" +RPROVIDES_${PN}-core += "libpython2" + +# Use special prefix in order to prevent clash with normal python +STAGING_INCDIR_DEFAULT = "${STAGING_DIR_HOST}/usr/include" +STAGING_LIBDIR_DEFAULT = "${STAGING_DIR_HOST}/usr/${baselib}" +TARGET_CFLAGS += "-I${STAGING_INCDIR_DEFAULT}" +TARGET_CPPFLAGS += "-I${STAGING_INCDIR_DEFAULT}" +prefix = "/opt" +exec_prefix = "/opt" + +PYTHON_MAKE_TARGET = "build_all_generate_profile" + +# Force pkgdata not to clash with python recipe +PKG_libpython-profile-opt2 = "libpython-profile-opt2.7-1.0"
meta/recipes-devtools/python/python_2.7.12.bb +18 -8
@@ -37,6 +37,11 @@ CONFIGUREOPTS += " --with-system-ffi " EXTRA_OECONF += "ac_cv_file__dev_ptmx=yes ac_cv_file__dev_ptc=no" +# These are needed in order to build with modified prefix (python-prorile-opt +# recipe) +STAGING_INCDIR_DEFAULT ?= "${STAGING_INCDIR}" +STAGING_LIBDIR_DEFAULT ?= "${STAGING_LIBDIR}" + do_configure_append() { rm -f ${S}/Makefile.orig autoreconf -Wcross --verbose --install --force --exclude=autopoint ../Python-${PV}/Modules/_ctypes/libffi
@@ -45,12 +50,12 @@ do_configure_append() { do_compile() { # regenerate platform specific files, because they depend on system headers cd ${S}/Lib/plat-linux2 - include=${STAGING_INCDIR} ${STAGING_BINDIR_NATIVE}/python-native/python \ + include=${STAGING_INCDIR_DEFAULT} ${STAGING_BINDIR_NATIVE}/python-native/python \ ${S}/Tools/scripts/h2py.py -i '(u_long)' \ - ${STAGING_INCDIR}/dlfcn.h \ - ${STAGING_INCDIR}/linux/cdrom.h \ - ${STAGING_INCDIR}/netinet/in.h \ - ${STAGING_INCDIR}/sys/types.h + ${STAGING_INCDIR_DEFAULT}/dlfcn.h \ + ${STAGING_INCDIR_DEFAULT}/linux/cdrom.h \ + ${STAGING_INCDIR_DEFAULT}/netinet/in.h \ + ${STAGING_INCDIR_DEFAULT}/sys/types.h sed -e 's,${STAGING_DIR_HOST},,g' -i *.py cd -
@@ -60,7 +65,7 @@ do_compile() { if [ ! -f Makefile.orig ]; then install -m 0644 Makefile Makefile.orig fi - sed -i -e 's#^LDFLAGS=.*#LDFLAGS=${LDFLAGS} -L. -L${STAGING_LIBDIR}#g' \ + sed -i -e 's#^LDFLAGS=.*#LDFLAGS=${LDFLAGS} -L. -L${STAGING_LIBDIR_DEFAULT}#g' \ -e 's,libdir=${libdir},libdir=${STAGING_LIBDIR},g' \ -e 's,libexecdir=${libexecdir},libexecdir=${STAGING_DIR_HOST}${libexecdir},g' \ -e 's,^LIBDIR=.*,LIBDIR=${STAGING_LIBDIR},g' \
@@ -74,13 +79,17 @@ do_compile() { export CROSS_COMPILE="${TARGET_PREFIX}" export PYTHONBUILDDIR="${B}" + # This is only used in PGO profiling by python-profile-opt package + if [ "${PYTHON_MAKE_TARGET}" = "build_all_generate_profile" ]; then + export EXTRA_CFLAGS="-fprofile-dir=./python-pgo-profiles/" + fi oe_runmake HOSTPGEN=${STAGING_BINDIR_NATIVE}/python-native/pgen \ HOSTPYTHON=${STAGING_BINDIR_NATIVE}/python-native/python \ STAGING_LIBDIR=${STAGING_LIBDIR} \ STAGING_INCDIR=${STAGING_INCDIR} \ STAGING_BASELIBDIR=${STAGING_BASELIBDIR} \ - OPT="${CFLAGS}" + OPT="${CFLAGS}" ${PYTHON_MAKE_TARGET} } do_install() {
@@ -99,7 +108,8 @@ do_install() { STAGING_LIBDIR=${STAGING_LIBDIR} \ STAGING_INCDIR=${STAGING_INCDIR} \ STAGING_BASELIBDIR=${STAGING_BASELIBDIR} \ - DESTDIR=${D} LIBDIR=${libdir} + DESTDIR=${D} LIBDIR=${libdir} ${PYTHON_MAKE_TARGET} + oe_runmake HOSTPGEN=${STAGING_BINDIR_NATIVE}/python-native/pgen \ HOSTPYTHON=${STAGING_BINDIR_NATIVE}/python-native/python \
Signature · 1 line
2.10.2
RFC PATCH 3/10 python: remove path hack from setup.py
In reply to Markus LehtonenThere should be no need to hack the library and include dirs in setup.py. The script detects them from compiler output. We need to remove this is because python-profile-opt recipe is built with a non-standard prefix setting (i.e. /opt) and the hack breaks the discovery of system libraries and headers.
[YOCTO #9338]
--- .../python/python/01-use-proper-tools-for-cross-build.patch | 10 ---------- 1 file changed, 10 deletions(-)
meta/recipes-devtools/python/python/01-use-proper-tools-for-cross-build.patch +0 -10
@@ -85,13 +85,3 @@ Index: Python-2.7.12/setup.py assert not self.inplace basename, tail = os.path.splitext(ext_filename) newname = basename + "_failed" + tail -@@ -574,6 +575,9 @@ class PyBuildExt(build_ext): - - # XXX Omitted modules: gl, pure, dl, SGI-specific modules - -+ lib_dirs = [ os.getenv("STAGING_LIBDIR"), os.getenv("STAGING_BASELIBDIR") ] -+ inc_dirs = [ os.getenv("STAGING_INCDIR") ] -+ - # - # The following modules are all pretty straightforward, and compile - # on pretty much any POSIXish platform.
Signature · 1 line
2.10.2
RFC PATCH 4/10 python-profile-opt: rename libpython
In reply to Markus LehtonenThe python library needs to be renamed so that the automatic dependency generation/checking mechanism in bitbake does not get confused. Otherwise python-profile-opt will depend on libpython from the "normal" python package.
[YOCTO #9338]
--- .../python/python-profile-opt_2.7.12.bb | 6 +- ...rename-libpython-to-libpython-profile-opt.patch | 94 ++++++++++++++++++++++ 2 files changed, 95 insertions(+), 5 deletions(-) create mode 100644 meta/recipes-devtools/python/python/rename-libpython-to-libpython-profile-opt.patch
meta/recipes-devtools/python/python-profile-opt_2.7.12.bb +1 -5
@@ -1,7 +1,6 @@ require python_${PV}.bb -PROVIDES += "libpython2" -RPROVIDES_${PN}-core += "libpython2" +SRC_URI += "file://rename-libpython-to-libpython-profile-opt.patch" # Use special prefix in order to prevent clash with normal python STAGING_INCDIR_DEFAULT = "${STAGING_DIR_HOST}/usr/include"
@@ -12,6 +11,3 @@ prefix = "/opt" exec_prefix = "/opt" PYTHON_MAKE_TARGET = "build_all_generate_profile" - -# Force pkgdata not to clash with python recipe -PKG_libpython-profile-opt2 = "libpython-profile-opt2.7-1.0"
meta/recipes-devtools/python/python/rename-libpython-to-libpython-profile-opt.patch new file +94 -0
94 lines not on this page · raw message
Signature · 1 line
2.10.2
RFC PATCH 5/10 devtools/images: add python-pgo-image
In reply to Markus LehtonenThis is a special image for profiling Python in order to utilize profile-guided-optimization. Profile data can be obtained by by running bitbake python-pgo-image -c profile. It will be located in the directory pointed by ${PYTHON_PROFILE_DIR}. The profile task that is run can be altered by specifying ${PYTHON_PROFILE_TASK}.
[YOCTO #9338]
--- meta/recipes-devtools/images/python-pgo-image.bb | 55 ++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 meta/recipes-devtools/images/python-pgo-image.bb
meta/recipes-devtools/images/python-pgo-image.bb new file +55 -0
@@ -0,0 +1,55 @@ +SUMMARY = "Minimal image for doing Python profiling (for PGO)" + +IMAGE_FEATURES += "ssh-server-dropbear" +IMAGE_INSTALL = "packagegroup-core-boot python-profile-opt python-profile-opt-tests" + +LICENSE = "MIT" + +inherit core-image + +PYTHON_PROFILE_DIR ?= "${TMPDIR}/work-shared/${MACHINE}/python/pgo-data" +PYTHON_PROFILE_TASK ?= "-m test.regrtest --pgo -w -x test_asyncore test_gdb test_multiprocessing test_subprocess" + +# We need these because we're utilizing the runtime test helpers from oeqa +TEST_TARGET ?= "qemu" +TEST_QEMUBOOT_TIMEOUT ?= "1000" +TEST_LOG_DIR ?= "${WORKDIR}/qemulogs" + +python do_profile() { + from oeqa.targetcontrol import get_target_controller + from oe.utils import getstatusoutput + + target = get_target_controller(d) + target.deploy() + try: + # Boot target + bootparams = None + if d.getVar('VIRTUAL-RUNTIME_init_manager', True) == 'systemd': + bootparams = 'systemd.log_level=debug systemd.log_target=console' + target.start(extra_bootparams=bootparams) + + # Run profile task + profile_cmd = 'LD_LIBRARY_PATH=/opt/lib /opt/bin/python %s' % d.getVar("PYTHON_PROFILE_TASK", True) + ret, output = target.run(profile_cmd, timeout=7200) + if ret: + bb.fatal("Failed to run profile task on target: %s" % output) + ret, output = target.run('tar czf pgo-data.tgz -C /home/root/python-pgo-profiles/ .') + if ret: + bb.fatal("Failed to archive profile data on target: %s" % output) + + # Retrieve and unpack profile data + profile_dir = d.getVar("PYTHON_PROFILE_DIR", True) + target.copy_from('/home/root/pgo-data.tgz', profile_dir) + + profile_tarball = os.path.join(profile_dir, 'pgo-data.tgz') + ret, output = getstatusoutput('tar xf %s -C %s' % (profile_tarball, profile_dir)) + os.unlink(profile_tarball) + if ret: + bb.fatal("Failed to unpack python profile data: %s" % output) + finally: + target.stop() +} + +addtask profile after do_build +do_profile[depends] += "qemu-native:do_populate_sysroot qemu-helper-native:do_populate_sysroot" +do_profile[cleandirs] = "${PYTHON_PROFILE_DIR}"
Signature · 1 line
2.10.2
RFC PATCH 6/10 python: make profile-optimized build possible
In reply to Markus LehtonenThis patch makes it possible to build python with profile directed optimization. That is, feed python build process with profile data to guide optimization. This is the third (and the last) step in profile directed optimization for Python.
In order to do a profile-optimized build you need to set PYTHON_PROFILE_OPT = "1" in your local.conf. Be sure to get the profile data for python, preferably by running
"bitbake python-pgo-image -c profile".
[YOCTO #9338]
--- meta/recipes-devtools/python/python_2.7.12.bb | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)
meta/recipes-devtools/python/python_2.7.12.bb +24 -1
@@ -42,6 +42,17 @@ EXTRA_OECONF += "ac_cv_file__dev_ptmx=yes ac_cv_file__dev_ptc=no" STAGING_INCDIR_DEFAULT ?= "${STAGING_INCDIR}" STAGING_LIBDIR_DEFAULT ?= "${STAGING_LIBDIR}" +# Automatic profile guided optimization +PYTHON_MAKE_TARGET ?= "${@'build_all_use_profile' if d.getVar('PYTHON_PROFILE_OPT', True) == '1' else ''}" +PYTHON_PROFILE_DIR ?= "${@'${TMPDIR}/work-shared/${MACHINE}/python/pgo-data' if d.getVar('PYTHON_PROFILE_OPT', True) == '1' else ''}" +python () { + if (d.getVar('PYTHON_PROFILE_OPT', True) == '1' and + d.getVar('PYTHON_MAKE_TARGET', True) == 'build_all_use_profile'): + profile_dir = d.getVar('PYTHON_PROFILE_DIR', True) + bb.utils.mkdirhier(profile_dir) + d.setVarFlag('do_compile', 'file-checksums', '%s:True' % profile_dir) +} + do_configure_append() { rm -f ${S}/Makefile.orig autoreconf -Wcross --verbose --install --force --exclude=autopoint ../Python-${PV}/Modules/_ctypes/libffi
@@ -79,9 +90,15 @@ do_compile() { export CROSS_COMPILE="${TARGET_PREFIX}" export PYTHONBUILDDIR="${B}" - # This is only used in PGO profiling by python-profile-opt package if [ "${PYTHON_MAKE_TARGET}" = "build_all_generate_profile" ]; then + # This is only used in PGO profiling by python-profile-opt package export EXTRA_CFLAGS="-fprofile-dir=./python-pgo-profiles/" + else + if [ -n "${PYTHON_PROFILE_DIR}" ]; then + export EXTRA_CFLAGS="-fprofile-dir=${PYTHON_PROFILE_DIR}" + # Remove non-optimized build artefacts + oe_runmake clean + fi fi oe_runmake HOSTPGEN=${STAGING_BINDIR_NATIVE}/python-native/pgen \
@@ -99,6 +116,11 @@ do_install() { export CROSS_COMPILE="${TARGET_PREFIX}" export PYTHONBUILDDIR="${B}" + # This only has effect if we build with -fprofile-use, e.g. when make + # target is build_all_use_profile + if [ -n "${PYTHON_PROFILE_DIR}" ]; then + export EXTRA_CFLAGS="-fprofile-dir=${PYTHON_PROFILE_DIR}" + fi # After swizzling the makefile, we need to run the build again. # install can race with the build so we have to run this first, then install
@@ -146,6 +168,7 @@ py_package_preprocess () { python -m py_compile ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata.py } + require python-${PYTHON_MAJMIN}-manifest.inc # manual dependency additions
Signature · 1 line
2.10.2
RFC PATCH 7/10 python-pgo-image: exclude tests from the default profile target
In reply to Markus LehtonenExclue tests that are segfaulting or otherwise failing (on qemux86 target), and thus, causing the profile task to fail.
Also, disable tests that are taking very long to execute. In qemux86 target on my i7-3770K:
test_lib2to3: 1908.8s
test_io: 1278.4s
test_itertools: 436.4s
[YOCTO #9338]
--- meta/recipes-devtools/images/python-pgo-image.bb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
meta/recipes-devtools/images/python-pgo-image.bb +8 -1
@@ -8,7 +8,14 @@ LICENSE = "MIT" inherit core-image PYTHON_PROFILE_DIR ?= "${TMPDIR}/work-shared/${MACHINE}/python/pgo-data" -PYTHON_PROFILE_TASK ?= "-m test.regrtest --pgo -w -x test_asyncore test_gdb test_multiprocessing test_subprocess" +PYTHON_PROFILE_TASK_DEFAULT = "-m test.regrtest --pgo -w -x test_asyncore test_gdb test_multiprocessing test_subprocess" +# Exclude tests that are segfaulting on qemux86 target +PYTHON_PROFILE_TASK_DEFAULT += "test_bytes test_str test_string test_tuple test_unicode test_userstring test_xmlrpc" +# Exclude tests that are failing on qemux86 +PYTHON_PROFILE_TASK_DEFAULT += "test_StringIO test_builtin test_calendar test_cmath test_ctypes test_distutils test_exceptions test_getargs test_gzip test_json test_math test_shutil test_socket test_sqlite test_traceback test_warnings" +# Exclude tests that are taking very long on qemux86 +PYTHON_PROFILE_TASK_DEFAULT += "test_io test_lib2to3 test_itertools" +PYTHON_PROFILE_TASK ?= "${PYTHON_PROFILE_TASK_DEFAULT}" # We need these because we're utilizing the runtime test helpers from oeqa TEST_TARGET ?= "qemu"
Signature · 1 line
2.10.2
RFC PATCH 8/10 python: add python-tools subpackage
In reply to Markus LehtonenUseful in developing Python, e.g. in benchmarking.
[YOCTO #9338]
--- meta/recipes-devtools/python/python-2.7-manifest.inc | 8 +++++--- meta/recipes-devtools/python/python_2.7.12.bb | 5 +++++ 2 files changed, 10 insertions(+), 3 deletions(-)
meta/recipes-devtools/python/python-2.7-manifest.inc +5 -3
@@ -5,9 +5,9 @@ -PROVIDES+="${PN}-2to3 ${PN}-argparse ${PN}-audio ${PN}-bsddb ${PN}-codecs ${PN}-compile ${PN}-compiler ${PN}-compression ${PN}-contextlib ${PN}-core ${PN}-crypt ${PN}-ctypes ${PN}-curses ${PN}-datetime ${PN}-db ${PN}-debugger ${PN}-dev ${PN}-difflib ${PN}-distutils ${PN}-distutils-staticdev ${PN}-doctest ${PN}-email ${PN}-fcntl ${PN}-gdbm ${PN}-hotshot ${PN}-html ${PN}-idle ${PN}-image ${PN}-importlib ${PN}-io ${PN}-json ${PN}-lang ${PN}-logging ${PN}-mailbox ${PN}-math ${PN}-mime ${PN}-mmap ${PN}-multiprocessing ${PN}-netclient ${PN}-netserver ${PN}-numbers ${PN}-pickle ${PN}-pkgutil ${PN}-plistlib ${PN}-pprint ${PN}-profile ${PN}-pydoc ${PN}-re ${PN}-readline ${PN}-resource ${PN}-robotparser ${PN}-shell ${PN}-smtpd ${PN}-sqlite3 ${PN}-sqlite3-tests ${PN}-stringold ${PN}-subprocess ${PN}-syslog ${PN}-terminal ${PN}-tests ${PN}-textutils ${PN}-threading ${PN}-tkinter ${PN}-unittest ${PN}-unixadmin ${PN}-xml ${PN}-xmlrpc ${PN}-zlib " +PROVIDES+="${PN}-2to3 ${PN}-argparse ${PN}-audio ${PN}-bsddb ${PN}-codecs ${PN}-compile ${PN}-compiler ${PN}-compression ${PN}-contextlib ${PN}-core ${PN}-crypt ${PN}-ctypes ${PN}-curses ${PN}-datetime ${PN}-db ${PN}-debugger ${PN}-dev ${PN}-difflib ${PN}-distutils ${PN}-distutils-staticdev ${PN}-doctest ${PN}-email ${PN}-fcntl ${PN}-gdbm ${PN}-hotshot ${PN}-html ${PN}-idle ${PN}-image ${PN}-importlib ${PN}-io ${PN}-json ${PN}-lang ${PN}-logging ${PN}-mailbox ${PN}-math ${PN}-mime ${PN}-mmap ${PN}-multiprocessing ${PN}-netclient ${PN}-netserver ${PN}-numbers ${PN}-pickle ${PN}-pkgutil ${PN}-plistlib ${PN}-pprint ${PN}-profile ${PN}-pydoc ${PN}-re ${PN}-readline ${PN}-resource ${PN}-robotparser ${PN}-shell ${PN}-smtpd ${PN}-sqlite3 ${PN}-sqlite3-tests ${PN}-stringold ${PN}-subprocess ${PN}-syslog ${PN}-terminal ${PN}-tests ${PN}-textutils ${PN}-threading ${PN}-tkinter ${PN}-unittest ${PN}-unixadmin ${PN}-xml ${PN}-xmlrpc ${PN}-zlib ${PN}-tools" -PACKAGES="${PN}-dbg ${PN}-2to3 ${PN}-argparse ${PN}-audio ${PN}-bsddb ${PN}-codecs ${PN}-compile ${PN}-compiler ${PN}-compression ${PN}-contextlib ${PN}-core ${PN}-crypt ${PN}-ctypes ${PN}-curses ${PN}-datetime ${PN}-db ${PN}-debugger ${PN}-dev ${PN}-difflib ${PN}-distutils-staticdev ${PN}-distutils ${PN}-doctest ${PN}-email ${PN}-fcntl ${PN}-gdbm ${PN}-hotshot ${PN}-html ${PN}-idle ${PN}-image ${PN}-importlib ${PN}-io ${PN}-json ${PN}-lang ${PN}-logging ${PN}-mailbox ${PN}-math ${PN}-mime ${PN}-mmap ${PN}-multiprocessing ${PN}-netclient ${PN}-netserver ${PN}-numbers ${PN}-pickle ${PN}-pkgutil ${PN}-plistlib ${PN}-pprint ${PN}-profile ${PN}-pydoc ${PN}-re ${PN}-readline ${PN}-resource ${PN}-robotparser ${PN}-shell ${PN}-smtpd ${PN}-sqlite3 ${PN}-sqlite3-tests ${PN}-stringold ${PN}-subprocess ${PN}-syslog ${PN}-terminal ${PN}-tests ${PN}-textutils ${PN}-threading ${PN}-tkinter ${PN}-unittest ${PN}-unixadmin ${PN}-xml ${PN}-xmlrpc ${PN}-zlib ${PN}-modules" +PACKAGES="${PN}-dbg ${PN}-2to3 ${PN}-argparse ${PN}-audio ${PN}-bsddb ${PN}-codecs ${PN}-compile ${PN}-compiler ${PN}-compression ${PN}-contextlib ${PN}-core ${PN}-crypt ${PN}-ctypes ${PN}-curses ${PN}-datetime ${PN}-db ${PN}-debugger ${PN}-dev ${PN}-difflib ${PN}-distutils-staticdev ${PN}-distutils ${PN}-doctest ${PN}-email ${PN}-fcntl ${PN}-gdbm ${PN}-hotshot ${PN}-html ${PN}-idle ${PN}-image ${PN}-importlib ${PN}-io ${PN}-json ${PN}-lang ${PN}-logging ${PN}-mailbox ${PN}-math ${PN}-mime ${PN}-mmap ${PN}-multiprocessing ${PN}-netclient ${PN}-netserver ${PN}-numbers ${PN}-pickle ${PN}-pkgutil ${PN}-plistlib ${PN}-pprint ${PN}-profile ${PN}-pydoc ${PN}-re ${PN}-readline ${PN}-resource ${PN}-robotparser ${PN}-shell ${PN}-smtpd ${PN}-sqlite3 ${PN}-sqlite3-tests ${PN}-stringold ${PN}-subprocess ${PN}-syslog ${PN}-terminal ${PN}-tests ${PN}-textutils ${PN}-threading ${PN}-tkinter ${PN}-unittest ${PN}-unixadmin ${PN}-xml ${PN}-xmlrpc ${PN}-zlib ${PN}-modules ${PN}-tools" SUMMARY_${PN}-2to3="Python automated Python 2 to 3 code translator" RDEPENDS_${PN}-2to3="${PN}-core"
@@ -285,4 +285,6 @@ SUMMARY_${PN}-modules="All Python modules" RDEPENDS_${PN}-modules="${PN}-2to3 ${PN}-argparse ${PN}-audio ${PN}-bsddb ${PN}-codecs ${PN}-compile ${PN}-compiler ${PN}-compression ${PN}-contextlib ${PN}-core ${PN}-crypt ${PN}-ctypes ${PN}-curses ${PN}-datetime ${PN}-db ${PN}-debugger ${PN}-difflib ${PN}-distutils ${PN}-doctest ${PN}-email ${PN}-fcntl ${PN}-gdbm ${PN}-hotshot ${PN}-html ${PN}-idle ${PN}-image ${PN}-importlib ${PN}-io ${PN}-json ${PN}-lang ${PN}-logging ${PN}-mailbox ${PN}-math ${PN}-mime ${PN}-mmap ${PN}-multiprocessing ${PN}-netclient ${PN}-netserver ${PN}-numbers ${PN}-pickle ${PN}-pkgutil ${PN}-plistlib ${PN}-pprint ${PN}-profile ${PN}-pydoc ${PN}-re ${PN}-readline ${PN}-resource ${PN}-robotparser ${PN}-shell ${PN}-smtpd ${PN}-sqlite3 ${PN}-sqlite3-tests ${PN}-stringold ${PN}-subprocess ${PN}-syslog ${PN}-terminal ${PN}-tests ${PN}-textutils ${PN}-threading ${PN}-tkinter ${PN}-unittest ${PN}-unixadmin ${PN}-xml ${PN}-xmlrpc ${PN}-zlib " ALLOW_EMPTY_${PN}-modules = "1" - +SUMMARY_${PN}-tools="Useful scripts from Python" +RDEPENDS_${PN}-tools="${PN}-modules" +FILES_${PN}-tools="${docdir}/${PN}/Tools"
meta/recipes-devtools/python/python_2.7.12.bb +5 -0
@@ -148,6 +148,11 @@ do_install() { fi oe_multilib_header python${PYTHON_MAJMIN}/pyconfig.h + + # Install tools + install -d -m 755 ${D}/${docdir}/${PN} + cp -r ${S}/Tools ${D}/${docdir}/${PN}/ + find ${D}/${docdir}/${PN}/ -name Makefile -delete } do_install_append_class-nativesdk () {
Signature · 1 line
2.10.2
RFC PATCH 9/10 python-pgo-image: switch python default profile task to pybench
In reply to Markus LehtonenSwitch to pybench in order to reduce the time taken by profiling.
[YOCTO #9338]
--- meta/recipes-devtools/images/python-pgo-image.bb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
meta/recipes-devtools/images/python-pgo-image.bb +9 -7
@@ -1,7 +1,8 @@ SUMMARY = "Minimal image for doing Python profiling (for PGO)" IMAGE_FEATURES += "ssh-server-dropbear" -IMAGE_INSTALL = "packagegroup-core-boot python-profile-opt python-profile-opt-tests" +IMAGE_INSTALL = "packagegroup-core-boot" +IMAGE_INSTALL += "python-profile-opt python-profile-opt-tests python-profile-opt-tools" LICENSE = "MIT"
@@ -9,12 +10,13 @@ inherit core-image PYTHON_PROFILE_DIR ?= "${TMPDIR}/work-shared/${MACHINE}/python/pgo-data" PYTHON_PROFILE_TASK_DEFAULT = "-m test.regrtest --pgo -w -x test_asyncore test_gdb test_multiprocessing test_subprocess" -# Exclude tests that are segfaulting on qemux86 target -PYTHON_PROFILE_TASK_DEFAULT += "test_bytes test_str test_string test_tuple test_unicode test_userstring test_xmlrpc" -# Exclude tests that are failing on qemux86 -PYTHON_PROFILE_TASK_DEFAULT += "test_StringIO test_builtin test_calendar test_cmath test_ctypes test_distutils test_exceptions test_getargs test_gzip test_json test_math test_shutil test_socket test_sqlite test_traceback test_warnings" -# Exclude tests that are taking very long on qemux86 -PYTHON_PROFILE_TASK_DEFAULT += "test_io test_lib2to3 test_itertools" +## Exclude tests that are segfaulting on qemux86 target +#PYTHON_PROFILE_TASK_DEFAULT += "test_bytes test_str test_string test_tuple test_unicode test_userstring test_xmlrpc" +## Exclude tests that are failing on qemux86 +#PYTHON_PROFILE_TASK_DEFAULT += "test_StringIO test_builtin test_calendar test_cmath test_ctypes test_distutils test_exceptions test_getargs test_gzip test_json test_math test_shutil test_socket test_sqlite test_traceback test_warnings" +## Exclude tests that are taking very long on qemux86 +#PYTHON_PROFILE_TASK_DEFAULT += "test_io test_lib2to3 test_itertools" +PYTHON_PROFILE_TASK_DEFAULT = "/opt/share/doc/python-profile-opt/Tools/pybench/pybench.py -n 2 --with-gc --with-syscheck" PYTHON_PROFILE_TASK ?= "${PYTHON_PROFILE_TASK_DEFAULT}" # We need these because we're utilizing the runtime test helpers from oeqa
Signature · 1 line
2.10.2
RFC PATCH 10/10 python-pgo-image: enable sstate for do_profile
In reply to Markus LehtonenThere are caveats however, basically because of the circular dependency between python-pgo-image and python (python is a build dep of python-pgo-image, and at the same time, depends on the profile data generated by python-pgo-image). In practice the sstate data is only used when no profile data is yet present. Existing profile data (i.e. non-empty PYTHON_PROFILE_DIR) changes signature hash of python which, in turn, changes signature of python-pgo-image and causes a sstate signature mismatch and rebuild of python-pgo-image. Thus, in order to utilize sstate data the user should run "bitbake python-pgo-image -c clean" (or otherwise wipe pre-existing profile data) before running "bitbake python-pgo-image -c profile".
[YOCTO #9338]
--- meta/recipes-devtools/images/python-pgo-image.bb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
meta/recipes-devtools/images/python-pgo-image.bb +13 -2
@@ -9,6 +9,7 @@ LICENSE = "MIT" inherit core-image PYTHON_PROFILE_DIR ?= "${TMPDIR}/work-shared/${MACHINE}/python/pgo-data" +PROFILE_DATA_WORKDIR = "${WORKDIR}/profile-data" PYTHON_PROFILE_TASK_DEFAULT = "-m test.regrtest --pgo -w -x test_asyncore test_gdb test_multiprocessing test_subprocess" ## Exclude tests that are segfaulting on qemux86 target #PYTHON_PROFILE_TASK_DEFAULT += "test_bytes test_str test_string test_tuple test_unicode test_userstring test_xmlrpc"
@@ -47,7 +48,7 @@ python do_profile() { bb.fatal("Failed to archive profile data on target: %s" % output) # Retrieve and unpack profile data - profile_dir = d.getVar("PYTHON_PROFILE_DIR", True) + profile_dir = d.getVar("PROFILE_DATA_WORKDIR", True) target.copy_from('/home/root/pgo-data.tgz', profile_dir) profile_tarball = os.path.join(profile_dir, 'pgo-data.tgz')
@@ -61,4 +62,14 @@ python do_profile() { addtask profile after do_build do_profile[depends] += "qemu-native:do_populate_sysroot qemu-helper-native:do_populate_sysroot" -do_profile[cleandirs] = "${PYTHON_PROFILE_DIR}" +do_profile[cleandirs] = "${PROFILE_DATA_WORKDIR}" + + +python do_profile_setscene () { + sstate_setscene(d) +} + +SSTATETASKS += "do_profile" +do_profile[sstate-inputdirs] = "${PROFILE_DATA_WORKDIR}" +do_profile[sstate-outputdirs] = "${PYTHON_PROFILE_DIR}" +addtask do_profile_setscene
Signature · 1 line
2.10.2