[PATCH v1 8/9] perf python: Initialize debug output on module load
From: Ian Rogers
Date: Mon Sep 28 2026 - 22:20:05 EST
Unlike the perf binary's main(), PyInit_perf() does not call
perf_debug_setup(). As a result, the first warning or error printed from
the perf Python C extension hits debug_file() with _debug_file == NULL
and emits 'debug_file not set' without a trailing newline before the
actual diagnostic message.
Call perf_debug_setup() in PyInit_perf() and add the missing trailing
newline to the fallback warning in debug_file().
Fixes: ec49230cf6dd ("perf debug: Expose debug file")
Assisted-by: Antigravity:gemini-3.1-pro
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/util/debug.c | 2 +-
tools/perf/util/python.c | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c
index 6b5ffe81f141..b7095519419e 100644
--- a/tools/perf/util/debug.c
+++ b/tools/perf/util/debug.c
@@ -55,7 +55,7 @@ FILE *debug_file(void)
{
if (!_debug_file) {
debug_set_file(stderr);
- pr_warning_once("debug_file not set");
+ pr_warning_once("%s not set\n", __func__);
}
return _debug_file;
}
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index 690a94fb4f62..95140dfaef9c 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -5157,6 +5157,7 @@ PyMODINIT_FUNC PyInit_perf(void)
/* The page_size is placed in util object. */
page_size = sysconf(_SC_PAGE_SIZE);
+ perf_debug_setup();
Py_INCREF(&pyrf_evlist__type);
PyModule_AddObject(module, "evlist", (PyObject *)&pyrf_evlist__type);
--
2.56.0.rc1.315.gc6ed9934b7-goog