perf build: Fix pylint build failures
v2 cover perf build: Fix pylint build failures
Recent changes to perf's Python module, including enabling pylint by default, exposed build failures in our CI. For example:
tests/shell/lib/perf_brstack_max.py:8:0: E0401: Unable to import 'perf' (import-error)
This series builds the perf Python extension before running pylint on its consumers without delaying C builds. It also prepends the output Python directory to PYTHONPATH for out-of-tree builds.
The series also mutes the optparse deprecation warning from older pylint versions. Python has reversed this deprecation, and newer pylint versions no longer report it.
A final patch renames an exception variable in the PostgreSQL exporter to fix pylint warning.
Tested on an x86 Intel Xeon(R) w7-3465X (28 cores, 56 threads), the average real build time over three runs was 20.104s for v1 and 18.998s for v2, about 1.1s (5.5%) faster.
---
Changes in v2:
- Run pylint after the Python extension without delaying C builds
(Sashiko).
- Fix the PostgreSQL warning.
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Leo Yan (4):
perf build: Build the Python extension before pylint consumers perf build: Add the output Python directory to pylint's PYTHONPATH perf test: Suppress optparse deprecation warning with older pylint perf python: Avoid shadowing exception name in PostgreSQL exporter
tools/perf/Build | 4 +++- tools/perf/Makefile.perf | 17 ++++++++++++++++- tools/perf/python/export-to-postgresql.py | 4 ++-- tools/perf/tests/Build | 4 +++- tools/perf/tests/shell/lib/attr.py | 3 ++- 5 files changed, 26 insertions(+), 6 deletions(-)
---
base-commit: 45d15e89a783a0a279b7a54f9018c230127380d7
change-id: 20260930-perf_fix_pylint_errors-3cef583b1e47
Best regards,
Signature · 1 line
Leo Yan <[email protected]>
PATCH v2 1/4 perf build: Build the Python extension before pylint consumers
Pylint checks for tests and standalone Python scripts can run before the perf Python extension is available. On a clean parallel build, an import error can stop make before the extension is built.
Run the script and test pylint checks in separate sub-makes after the language bindings are built. Keep their rules in the respective Build files so the perf and perf-test C sub-makes can compile concurrently with util and the Python extension. An isolated make perf does not need to build the extension just for these checks.
--- tools/perf/Build | 4 +++- tools/perf/Makefile.perf | 15 +++++++++++++++ tools/perf/tests/Build | 4 +++- 3 files changed, 21 insertions(+), 2 deletions(-)
tools/perf/Build +3 -1
@@ -102,4 +102,6 @@ $(OUTPUT)%.pylint_log: % $(call rule_mkdir) $(Q)$(call echo-cmd,test)$(PYLINT) "$<" > $@ || (cat $@ && rm $@ && false) -perf-y += $(PYLINT_TEST_LOGS) +.PHONY: pylint +pylint: $(addprefix $(OUTPUT),$(PYLINT_TEST_LOGS)) + @:
tools/perf/Makefile.perf +15 -0
@@ -578,6 +578,7 @@ strip: $(PROGRAMS) $(OUTPUT)perf $(STRIP) $(STRIP_OPTS) $(PROGRAMS) $(OUTPUT)perf PERF_IN := $(OUTPUT)perf-in.o + export NO_JEVENTS build := -f $(srctree)/tools/build/Makefile.build dir=. obj
@@ -633,6 +634,20 @@ $(SCRIPTS) : $(OUTPUT)% : %.sh $(OUTPUT)PERF-VERSION-FILE: .FORCE-PERF-VERSION-FILE $(Q)$(SHELL_PATH) util/PERF-VERSION-GEN $(OUTPUT) +ifdef PYLINT +# Run Python checks after the extension is ready, independently of C builds. +all: pylint-perf pylint-tests +.PHONY: pylint-perf pylint-tests + +pylint-perf pylint-tests: | $(LANG_BINDINGS) + +pylint-perf: + $(Q)$(MAKE) $(build)=perf pylint + +pylint-tests: + $(Q)$(MAKE) $(build)=perf-test dir=tests pylint +endif + # These can record PERF_VERSION perf.spec $(SCRIPTS) \ : $(OUTPUT)PERF-VERSION-FILE
tools/perf/tests/Build +3 -1
@@ -119,4 +119,6 @@ $(OUTPUT)%.pylint_log: % $(call rule_mkdir) $(Q)$(call echo-cmd,test)$(PYLINT) "$<" > $@ || (cat $@ && rm $@ && false) -perf-test-y += $(PYLINT_TEST_LOGS) +.PHONY: pylint +pylint: $(addprefix $(OUTPUT)tests/,$(PYLINT_TEST_LOGS)) + @:
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v2 1/4] perf build: Build the Python extension before pylint consumers
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 10 lines
Pylint checks for tests and standalone Python scripts can run before the perf Python extension is available. On a clean parallel build, an import error can stop make before the extension is built.
Run the script and test pylint checks in separate sub-makes after the language bindings are built. Keep their rules in the respective Build files so the perf and perf-test C sub-makes can compile concurrently with util and the Python extension. An isolated make perf does not need to build the extension just for these checks.
Quoted 4 lines
Fixes 8a54784e708b ("perf build: Add pylint build tests")Reported-by Aishwarya TCV <[email protected]>Assisted-by Codex:gpt-6Signed-off-by Leo Yan <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH v2 1/4] perf build: Build the Python extension before pylint consumers
In reply to Leo YanQuoted 11 lines · Leo Yan
Pylint checks for tests and standalone Python scripts can run before the perf Python extension is available. On a clean parallel build, an import error can stop make before the extension is built.
Run the script and test pylint checks in separate sub-makes after the language bindings are built. Keep their rules in the respective Build files so the perf and perf-test C sub-makes can compile concurrently with util and the Python extension. An isolated make perf does not need to build the extension just for these checks.
Quoted 4 lines
Fixes 8a54784e708b ("perf build: Add pylint build tests")Reported-by Aishwarya TCV <[email protected]>Assisted-by Codex:gpt-6Signed-off-by Leo Yan <[email protected]>
Thanks Leo! Should we do the same thing for mypy and shellcheck? This should help overall build performance.
Ian
Quoted 67 lines
--- tools/perf/Build | 4 +++- tools/perf/Makefile.perf | 15 +++++++++++++++ tools/perf/tests/Build | 4 +++- 3 files changed, 21 insertions(+), 2 deletions(-)tools/perf/Build +3
-1@@ -102,4 +102,6 @@ $(OUTPUT)%.pylint_log: % $(call rule_mkdir) $(Q)$(call echo-cmd,test)$(PYLINT) "$<" > $@ || (cat $@ && rm $@ && false) -perf-y += $(PYLINT_TEST_LOGS) +.PHONY: pylint +pylint: $(addprefix $(OUTPUT),$(PYLINT_TEST_LOGS)) + @:tools/perf/Makefile.perf +15
-0@@ -578,6 +578,7 @@ strip: $(PROGRAMS) $(OUTPUT)perf $(STRIP) $(STRIP_OPTS) $(PROGRAMS) $(OUTPUT)perf PERF_IN := $(OUTPUT)perf-in.o + export NO_JEVENTS build := -f $(srctree)/tools/build/Makefile.build dir=. obj@@ -633,6 +634,20 @@ $(SCRIPTS) : $(OUTPUT)% : %.sh $(OUTPUT)PERF-VERSION-FILE: .FORCE-PERF-VERSION-FILE $(Q)$(SHELL_PATH) util/PERF-VERSION-GEN $(OUTPUT) +ifdef PYLINT +# Run Python checks after the extension is ready, independently of C builds. +all: pylint-perf pylint-tests +.PHONY: pylint-perf pylint-tests + +pylint-perf pylint-tests: | $(LANG_BINDINGS) + +pylint-perf: + $(Q)$(MAKE) $(build)=perf pylint + +pylint-tests: + $(Q)$(MAKE) $(build)=perf-test dir=tests pylint +endif + # These can record PERF_VERSION perf.spec $(SCRIPTS) \ : $(OUTPUT)PERF-VERSION-FILEtools/perf/tests/Build +3
-2@@ -119,4 +119,6 @@ $(OUTPUT)%.pylint_log: % $(call rule_mkdir) $(Q)$(call echo-cmd,test)$(PYLINT) "$<" > $@ || (cat $@ && rm $@ && false) -perf-test-y += $(PYLINT_TEST_LOGS) +.PHONY: pylint +pylint: $(addprefix $(OUTPUT)tests/,$(PYLINT_TEST_LOGS)) + @: --2.34.1
PATCH v2 2/4 perf build: Add the output Python directory to pylint's PYTHONPATH
In reply to Leo YanPrepend the output Python directory to pylint's PYTHONPATH so builds using O= can also find the generated extension.
--- tools/perf/Makefile.perf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/Makefile.perf +1 -1
@@ -310,7 +310,7 @@ ifneq ($(force_fixdep),1) $(warning Warning: pylint version is older than 2.16.0, skipping pylint checks.) override PYLINT := else - override PYLINT := PYTHONPATH=$(srctree)/tools/perf/python:$(srctree)/tools/perf/pmu-events \ + override PYLINT := PYTHONPATH=$(abspath $(OUTPUT)python):$(srctree)/tools/perf/python:$(srctree)/tools/perf/pmu-events \ $(PYLINT) --disable=all --enable=E,W --disable=W0123,W0311,W0511,W0603,W0622,W0718 \ --ignored-modules=textual,setproctitle endif
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v2 2/4] perf build: Add the output Python directory to pylint's PYTHONPATH
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines
Prepend the output Python directory to pylint's PYTHONPATH so builds using O= can also find the generated extension.
Fixes 5fe83fb352c8 ("perf build: Make pylint build test opt-out (NO_PYLINT=1)")Reported-by Aishwarya TCV <[email protected]>Assisted-by Codex:gpt-6Signed-off-by Leo Yan <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH v2 2/4] perf build: Add the output Python directory to pylint's PYTHONPATH
In reply to Leo YanQuoted 8 lines · Leo Yan
Prepend the output Python directory to pylint's PYTHONPATH so builds using O= can also find the generated extension.
Fixes 5fe83fb352c8 ("perf build: Make pylint build test opt-out (NO_PYLINT=1)")Reported-by Aishwarya TCV <[email protected]>Assisted-by Codex:gpt-6Signed-off-by Leo Yan <[email protected]>
Thanks!
Ian
Quoted 21 lines
--- tools/perf/Makefile.perf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/perf/Makefile.perf +1
-2@@ -310,7 +310,7 @@ ifneq ($(force_fixdep),1) $(warning Warning: pylint version is older than 2.16.0, skipping pylint checks.) override PYLINT := else - override PYLINT := PYTHONPATH=$(srctree)/tools/perf/python:$(srctree)/tools/perf/pmu-events \ + override PYLINT := PYTHONPATH=$(abspath $(OUTPUT)python):$(srctree)/tools/perf/python:$(srctree)/tools/perf/pmu-events \ $(PYLINT) --disable=all --enable=E,W --disable=W0123,W0311,W0511,W0603,W0622,W0718 \ --ignored-modules=textual,setproctitle endif --2.34.1
PATCH v2 3/4 perf test: Suppress optparse deprecation warning with older pylint
In reply to Leo YanPython 3.13 reversed optparse's deprecation, and pylint 3.3.5 removed it from the deprecated-module list. Perf supports older pylint versions, so suppress the warning on this import and document the reason. Keep other deprecated-module diagnostics enabled.
--- tools/perf/tests/shell/lib/attr.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/tests/shell/lib/attr.py +2 -1
@@ -4,7 +4,8 @@ import configparser import os import sys import glob -import optparse +# Pylint before 3.3.5 still treats optparse as deprecated. +import optparse # pylint: disable=deprecated-module import platform import tempfile import logging
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v2 3/4] perf test: Suppress optparse deprecation warning with older pylint
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines
Python 3.13 reversed optparse's deprecation, and pylint 3.3.5 removed it from the deprecated-module list. Perf supports older pylint versions, so suppress the warning on this import and document the reason. Keep other deprecated-module diagnostics enabled.
Fixes 8a54784e708b ("perf build: Add pylint build tests")Reported-by Aishwarya TCV <[email protected]>Assisted-by Codex:gpt-6Signed-off-by Leo Yan <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Ian Rogers
reviewerRe: [PATCH v2 3/4] perf test: Suppress optparse deprecation warning with older pylint
In reply to Leo YanQuoted 21 lines · Leo Yan
Python 3.13 reversed optparse's deprecation, and pylint 3.3.5 removed it from the deprecated-module list. Perf supports older pylint versions, so suppress the warning on this import and document the reason. Keep other deprecated-module diagnostics enabled.
Fixes 8a54784e708b ("perf build: Add pylint build tests")Reported-by Aishwarya TCV <[email protected]>Assisted-by Codex:gpt-6Signed-off-by Leo Yan <[email protected]>--- tools/perf/tests/shell/lib/attr.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)tools/perf/tests/shell/lib/attr.py +0
-0
tools/perf/tests/shell/lib/attr.py import configparser · line 8
Quoted 6 lines
tools/perf/tests/shell/lib/attr.py +2
-1@@ -4,7 +4,8 @@ import configparser import os import sys import glob -import optparse +# Pylint before 3.3.5 still treats optparse as deprecated. +import optparse # pylint: disable=deprecated-module
Thanks Leo! Could we just update to argparse here?
```
diff --git a/tools/perf/tests/shell/lib/attr.py
b/tools/perf/tests/shell/lib/attr.py
index 7f3d5b64b00d..68f06df9565a 100644
--- a/tools/perf/tests/shell/lib/attr.py
+++ b/tools/perf/tests/shell/lib/attr.py
@@ -4,7 +4,7 @@ import configparser
import os
import sys
import glob
-import optparse
+import argparse
import platform
import tempfile
import logging
@@ -426,29 +426,20 @@ def setup_log(verbose):
ch.setFormatter(formatter)
log.addHandler(ch)
-USAGE = '''%s [OPTIONS]
- -d dir # tests dir
- -p path # perf binary
- -t test # single test
- -v # verbose level
-''' % sys.argv[0]
-
def main():
- parser = optparse.OptionParser(usage=USAGE)
-
- parser.add_option("-t", "--test",
- action="store", type="string", dest="test")
- parser.add_option("-d", "--test-dir",
- action="store", type="string", dest="test_dir")
- parser.add_option("-p", "--perf",
- action="store", type="string", dest="perf")
- parser.add_option("-v", "--verbose",
- default=0, action="count", dest="verbose")
-
- options, args = parser.parse_args()
- if args:
- parser.error('FAILED wrong arguments %s' % ' '.join(args))
- return -1
+ parser = argparse.ArgumentParser()
+
+ parser.add_argument("-t", "--test",
+ action="store", dest="test", help="single test")
+ parser.add_argument("-d", "--test-dir",
+ action="store", dest="test_dir", help="tests dir")
+ parser.add_argument("-p", "--perf",
+ action="store", dest="perf", help="perf binary")
+ parser.add_argument("-v", "--verbose",
+ default=0, action="count", dest="verbose",
+ help="verbose level")
+
+ options = parser.parse_args()
setup_log(options.verbose)
```Thanks,
Ian
Quoted 7 lines
tools/perf/tests/shell/lib/attr.py +0
-1import platform import tempfile import logging --2.34.1
Re: [PATCH v2 3/4] perf test: Suppress optparse deprecation warning with older pylint
On Wed, Sep 30, 2026 at 10:39:36AM -0700, Ian Rogers wrote:
[...]
Quoted 5 lines
tools/perf/tests/shell/lib/attr.py import configparser · line 8
Quoted 3 lines
tools/perf/tests/shell/lib/attr.py +2
-1-import optparse +# Pylint before 3.3.5 still treats optparse as deprecated. +import optparse # pylint: disable=deprecated-moduleThanks Leo! Could we just update to argparse here?
Thanks for suggestion. Please see the new patch:
PATCH v2 4/4 perf python: Avoid shadowing exception name in PostgreSQL exporter
In reply to Leo YanDuring the perf build, pylint reports:
************* Module export-to-postgresql
python/export-to-postgresql.py:319:8: W0621: Redefining name 'e' from outer scope (line 100) (redefined-outer-name)
Rename 'e' to 'db_error' to clear the warning.
--- tools/perf/python/export-to-postgresql.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/python/export-to-postgresql.py +2 -2
@@ -316,9 +316,9 @@ class PostgresExporter: # SQL identifiers are double-quoted; escape embedded double quotes by doubling them. db_name = self.dbname.replace('"', '""') self.do_query(f'CREATE DATABASE "{db_name}"') - except Exception as e: + except Exception as db_error: shutil.rmtree(self.output_dir_name, ignore_errors=True) - raise e + raise db_error self.disconnect() self.connect(self.dbname)
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v2 4/4] perf python: Avoid shadowing exception name in PostgreSQL exporter
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 10 lines
During the perf build, pylint reports:
************* Module export-to-postgresql
python/export-to-postgresql.py:319:8: W0621: Redefining name 'e' from outer scope (line 100) (redefined-outer-name)Rename 'e' to '
db_error' to clear the warning.Fixes b1f968c9656a ("perf python: Port export-to-postgresql to perf module")Assisted-by Codex:gpt-6Signed-off-by Leo Yan <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [PATCH v2 4/4] perf python: Avoid shadowing exception name in PostgreSQL exporter
In reply to Leo YanQuoted 11 lines · Leo Yan
During the perf build, pylint reports:
************* Module export-to-postgresql
python/export-to-postgresql.py:319:8: W0621: Redefining name 'e' from outer scope (line 100) (redefined-outer-name)Rename 'e' to '
db_error' to clear the warning.Fixes b1f968c9656a ("perf python: Port export-to-postgresql to perf module")Assisted-by Codex:gpt-6Signed-off-by Leo Yan <[email protected]>
Thanks!
Ian
Quoted 24 lines
--- tools/perf/python/export-to-postgresql.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/perf/python/export-to-postgresql.py +2
-3@@ -316,9 +316,9 @@ class PostgresExporter: # SQL identifiers are double-quoted; escape embedded double quotes by doubling them. db_name = self.dbname.replace('"', '""') self.do_query(f'CREATE DATABASE "{db_name}"') - except Exception as e: + except Exception as db_error: shutil.rmtree(self.output_dir_name, ignore_errors=True) - raise e + raise db_error self.disconnect() self.connect(self.dbname) --2.34.1
Quoted 8 lines · Leo Yan
Recent changes to perf's Python module, including enabling pylint by default, exposed build failures in our CI. For example:
tests/shell/lib/perf_brstack_max.py:8:0: E0401: Unable to import 'perf' (import-error)This series builds the perf Python extension before running pylint on its consumers without delaying C builds. It also prepends the output Python directory to PYTHONPATH for out-of-tree builds.
Thanks, applied patches 1-2 and 4, waiting for the suggestion from Ian to be considered for patch 3.
- Arnaldo