Package: src:linux Followup-For: Bug #860957 Dear Maintainer,
this patch adds support to ship the perf python bindings as a version dependent module (here, perf_4_19). By that, it can be imported using "import perf_4_19". A second patch in module linux-base provides a wrapper to load the perf module for the currently active kernel using "import perf". This is done similar to how the perf CLI wrapper works. For the sake of completeness, this wrapper is attached here as well. -- System Information: Debian Release: 10.7 APT prefers stable-updates APT policy: (500, 'stable-updates'), (500, 'stable') Architecture: amd64 (x86_64) Foreign Architectures: armhf, i386, arm64 Kernel: Linux 4.19.0-12-amd64 (SMP w/12 CPU cores) Kernel taint flags: TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE=en_US.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /usr/bin/dash Init: systemd (via /run/systemd/system) LSM: AppArmor: enabled
--- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf @@ -829,10 +829,10 @@ install-bin: install-tools install-tests install-traceevent-plugins -install: install-bin try-install-man - install-python_ext: - $(PYTHON_WORD) util/setup.py --quiet install --root='/$(DESTDIR_SQ)' + $(PYTHON_WORD) util/setup.py --quiet install --root='/$(DESTDIR_SQ)' --install-layout=deb; + +install: install-bin try-install-man install-python_ext # 'make install-doc' should call 'make -C Documentation install' $(INSTALL_DOC_TARGETS): --- a/debian/rules.d/tools/perf/Makefile +++ b/debian/rules.d/tools/perf/Makefile @@ -31,6 +31,9 @@ # Build with Python 3, not Python 2 MAKE_PERF += PYTHON=/usr/bin/python3 +# Pattern to match 4.19 and 4_19 in filenames +VERS_PATTERN := $(subst .,[._],$(VERSION)) + all: # perf changes some default directories depending on whether DESTDIR is # set. We must define it even when building to avoid a rebuild when we @@ -58,5 +61,6 @@ mv $(DESTDIR)/etc/bash_completion.d \ $(DESTDIR)/usr/share/bash-completion/completions rmdir --ignore-fail-on-non-empty $(DESTDIR)/etc + # Check for unversioned files that are likely to result in file conflicts - cd $(DESTDIR) && ! find \! -type d \! -path '*[_-]$(VERSION)*' | grep . + cd $(DESTDIR) && ! find \! -type d \! -path '*[_-]$(VERS_PATTERN)*' | grep . --- a/tools/perf/util/setup.py +++ b/tools/perf/util/setup.py @@ -51,14 +51,14 @@ # use full paths with source files ext_sources = list(map(lambda x: '%s/%s' % (src_perf, x) , ext_sources)) -perf = Extension('perf', +perf = Extension('perf_4_19', sources = ext_sources, include_dirs = ['util/include'], extra_compile_args = cflags, extra_objects = [libtraceevent, libapikfs], ) -setup(name='perf', +setup(name='perf_4_19', version='0.1', description='Interface with the Linux profiling infrastructure', author='Arnaldo Carvalho de Melo', --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -77,7 +77,7 @@ #if PY_MAJOR_VERSION < 3 PyMODINIT_FUNC initperf(void); #else -PyMODINIT_FUNC PyInit_perf(void); +PyMODINIT_FUNC PyInit_perf_4_19(void); #endif #define member_def(type, member, ptype, help) \ @@ -1270,7 +1270,7 @@ #if PY_MAJOR_VERSION < 3 PyMODINIT_FUNC initperf(void) #else -PyMODINIT_FUNC PyInit_perf(void) +PyMODINIT_FUNC PyInit_perf_4_19(void) #endif { PyObject *obj;
#!/usr/bin/python3 # Wrapper to load the kernel-specific version # of the python perf module using "import perf" import platform uname = platform.uname().release kvers = uname.split('.') if len(kvers) < 2: raise RuntimeError('Could not detect kernel version in: {}'.format(kvers)) try: perf = __import__('perf_{}_{}'.format(kvers[0], kvers[1])) # load symbols into parent namespace to provide it under perf # instead of perf.perf_<version> symbols = [symbol for symbol in perf.__dict__ if not symbol.startswith("_")] globals().update({symbol: getattr(perf, symbol) for symbol in symbols}) del perf del symbols except ModuleNotFoundError: raise ModuleNotFoundError('perf package not found. Install debian package linux-perf-{}.{}'.format(kvers[0],kvers[1])) del platform del uname del kvers