All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jens Remus <jremus@linux.ibm.com>
To: Ian Rogers <irogers@google.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>
Cc: Jens Remus <jremus@linux.ibm.com>,
	Jan Polensky <japo@linux.ibm.com>,
	Sumanth Korikkar <sumanthk@linux.ibm.com>,
	Heiko Carstens <hca@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 3/5] perf python: Honor perf script --show-kernel-path
Date: Fri,  4 Dec 2026 17:24:30 +0100	[thread overview]
Message-ID: <20261204162426.4171717-10-jremus@linux.ibm.com> (raw)
In-Reply-To: <20261204162426.4171717-7-jremus@linux.ibm.com>

The perf.session binding forces symbol_conf.show_kernel_path to true,
so callchain_node.dso reports the kernel DSO by its vmlinux path.  perf
script defaults to false and reports it as [kernel.kallsyms].

Add a show_kernel_path keyword argument to perf.session.  When not
given, it defaults to the PERF_SYMBOL_SHOW_KERNEL_PATH environment
variable, which perf script sets from --show-kernel-path when running a
Python script.  Otherwise it defaults to true, as before.

Note that Python scripts run by perf script now see the kernel DSO as
[kernel.kallsyms] by default, as perf script does.  Use
--show-kernel-path to get the previous behavior.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
---
 tools/perf/Documentation/perf-script-python.txt | 10 +++++-----
 tools/perf/builtin-script.c                     |  2 ++
 tools/perf/python/perf.pyi                      |  7 ++++++-
 tools/perf/util/python.c                        | 15 ++++++++++-----
 4 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/tools/perf/Documentation/perf-script-python.txt b/tools/perf/Documentation/perf-script-python.txt
index 10b124267f89..b4652a67b5bc 100644
--- a/tools/perf/Documentation/perf-script-python.txt
+++ b/tools/perf/Documentation/perf-script-python.txt
@@ -19,10 +19,10 @@ trace data recorded by `perf record`.
 With the removal of embedded Python interpreter from `perf`, scripts
 are now run as standalone Python programs that import the `perf`
 module to access trace data. Symbol configuration options (`--vmlinux`,
-`--kallsyms`, `--symfs` and `--inline`/`--no-inline`) and `--itrace` options
-passed to `perf script` are forwarded via `PERF_SYMBOL_*` and `PERF_ITRACE`
-environment variables to `perf.session`, and can also be passed directly to
-`perf.session`.
+`--kallsyms`, `--symfs`, `--inline`/`--no-inline` and `--show-kernel-path`)
+and `--itrace` options passed to `perf script` are forwarded via
+`PERF_SYMBOL_*` and `PERF_ITRACE` environment variables to `perf.session`,
+and can also be passed directly to `perf.session`.
 Trace filtering command-line
 options (`-C`, `-c`, `--pid`, `--tid`, `--time`, `--dlfilter`, `--dlarg`) passed
 to `perf script` are not applied to standalone scripts.
@@ -119,7 +119,7 @@ perf.session
 
 Manages a trace session.
 
-- `__init__(data, sample=None, stat=None, context_switch=None, call_return=None, itrace=None, vmlinux=None, kallsyms=None, symfs=None, inline=False)`: Creates a new session. `data` is a `perf.data` object. `sample` is a callback function called for each sample event. `vmlinux`, `kallsyms`, and `symfs` configure symbol resolution paths. `inline` resolves inlined functions in callchains, which are then flagged by `callchain_node.inlined`. When run by `perf script`, the default of `inline` is the value of `--inline`/`--no-inline`.
+- `__init__(data, sample=None, stat=None, context_switch=None, call_return=None, itrace=None, vmlinux=None, kallsyms=None, symfs=None, inline=False, show_kernel_path=True)`: Creates a new session. `data` is a `perf.data` object. `sample` is a callback function called for each sample event. `vmlinux`, `kallsyms`, and `symfs` configure symbol resolution paths. `inline` resolves inlined functions in callchains, which are then flagged by `callchain_node.inlined`. `show_kernel_path` reports the kernel DSO by its vmlinux path rather than `[kernel.kallsyms]`. When run by `perf script`, the defaults of `inline` and `show_kernel_path` are the values of `--inline`/`--no-inline` and `--show-kernel-path`.
 - `process_events()`: Reads the trace data and calls the sample callback for each event.
 - `find_thread(pid, tid=-1)`: Returns the thread associated with a PID/TID.
 - `e_machine`: ELF machine architecture ID (`EM_*`) of the session.
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 2ab6b17f638e..ccf7e3fe8934 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -4538,6 +4538,8 @@ int cmd_script(int argc, const char **argv)
 			if (script_itrace_opts)
 				setenv("PERF_ITRACE", script_itrace_opts, 1);
 			setenv("PERF_SYMBOL_INLINE", symbol_conf.inline_name ? "1" : "0", 1);
+			setenv("PERF_SYMBOL_SHOW_KERNEL_PATH",
+			       symbol_conf.show_kernel_path ? "1" : "0", 1);
 
 			execvp(__argv[0], (char **)__argv);
 			{
diff --git a/tools/perf/python/perf.pyi b/tools/perf/python/perf.pyi
index 4fcbaf4694c9..ce75f8999fa7 100644
--- a/tools/perf/python/perf.pyi
+++ b/tools/perf/python/perf.pyi
@@ -489,7 +489,8 @@ class session:
         vmlinux: Optional[str] = None,
         kallsyms: Optional[str] = None,
         symfs: Optional[str] = None,
-        inline: bool = ...
+        inline: bool = ...,
+        show_kernel_path: bool = ...
     ) -> None:
         """Initialize a perf session.
 
@@ -500,6 +501,10 @@ class session:
             inline: Resolve inlined functions in callchains. Defaults to the
                 PERF_SYMBOL_INLINE environment variable set by perf script,
                 otherwise False.
+            show_kernel_path: Report the kernel DSO by its vmlinux path rather
+                than [kernel.kallsyms]. Defaults to the
+                PERF_SYMBOL_SHOW_KERNEL_PATH environment variable set by
+                perf script, otherwise True.
         """
         ...
     e_machine: int
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index b5426dfaee01..18a8468c0eb2 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -4249,6 +4249,7 @@ struct pyrf_session {
 	char *kallsyms_name;
 	char *symfs;
 	bool inline_name;
+	bool show_kernel_path;
 };
 
 struct pyrf_call_return {
@@ -4983,19 +4984,19 @@ static PyObject *pyrf_session__new(PyTypeObject *type, PyObject *args, PyObject
 	PyObject *call_return = NULL;
 	char *itrace_str = NULL;
 	char *vmlinux_str = NULL, *kallsyms_str = NULL, *symfs_str = NULL;
-	int inline_arg = -1;
+	int inline_arg = -1, show_kernel_path_arg = -1;
 	static char *kwlist[] = { "data", "sample", "stat", "context_switch",
 				  "call_return", "itrace", "vmlinux", "kallsyms",
-				  "symfs", "inline", NULL };
+				  "symfs", "inline", "show_kernel_path", NULL };
 	struct pyrf_session *psession;
 	struct perf_session *session;
 
-	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!|OOOOzzzzp", kwlist,
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!|OOOOzzzzpp", kwlist,
 					 &pyrf_data__type, &pdata,
 					 &sample, &stat, &context_switch,
 					 &call_return, &itrace_str,
 					 &vmlinux_str, &kallsyms_str, &symfs_str,
-					 &inline_arg))
+					 &inline_arg, &show_kernel_path_arg))
 		return NULL;
 
 	psession = PyObject_New(struct pyrf_session, type);
@@ -5018,6 +5019,7 @@ static PyObject *pyrf_session__new(PyTypeObject *type, PyObject *args, PyObject
 	psession->kallsyms_name = NULL;
 	psession->symfs = NULL;
 	psession->inline_name = false;
+	psession->show_kernel_path = true;
 	psession->pdata = NULL;
 	memset(&psession->itrace_opts, 0, sizeof(psession->itrace_opts));
 
@@ -5136,6 +5138,8 @@ static PyObject *pyrf_session__new(PyTypeObject *type, PyObject *args, PyObject
 	 */
 	psession->inline_name = inline_arg >= 0 ? inline_arg :
 		pyrf_getenv_bool("PERF_SYMBOL_INLINE", psession->inline_name);
+	psession->show_kernel_path = show_kernel_path_arg >= 0 ? show_kernel_path_arg :
+		pyrf_getenv_bool("PERF_SYMBOL_SHOW_KERNEL_PATH", psession->show_kernel_path);
 
 	if (pyrf_session__active) {
 		PyErr_SetString(PyExc_RuntimeError,
@@ -5147,8 +5151,8 @@ static PyObject *pyrf_session__new(PyTypeObject *type, PyObject *args, PyObject
 	symbol_conf.kallsyms_name = psession->kallsyms_name;
 	symbol_conf.symfs = psession->symfs ?: "";
 	symbol_conf.use_callchain = true;
-	symbol_conf.show_kernel_path = true;
 	symbol_conf.inline_name = psession->inline_name;
+	symbol_conf.show_kernel_path = psession->show_kernel_path;
 
 	/* Reading the header of a pipe may block, let other python threads run. */
 	pyrf_session__active = psession;
@@ -5220,6 +5224,7 @@ static PyObject *pyrf_session__find_thread_events(struct pyrf_session *psession)
 	symbol_conf.kallsyms_name = psession->kallsyms_name;
 	symbol_conf.symfs = psession->symfs ?: "";
 	symbol_conf.inline_name = psession->inline_name;
+	symbol_conf.show_kernel_path = psession->show_kernel_path;
 
 	psession->callback_raised = false;
 	/* Callbacks that use python acquire the GIL, see pyrf_session_tool__sample(). */
-- 
2.53.0


  parent reply	other threads:[~2026-12-04 16:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 16:24 [PATCH 0/5] perf python: Honor more perf script options Jens Remus
2026-12-04 16:24 ` [PATCH 1/5] perf python: Support inlined frames in callchains Jens Remus
2026-12-04 16:46   ` sashiko-bot
2026-12-04 16:24 ` [PATCH 2/5] perf python: Export inlined symbol flag in DB export scripts Jens Remus
2026-12-04 16:59   ` sashiko-bot
2026-12-04 16:24 ` Jens Remus [this message]
2026-12-04 17:13   ` [PATCH 3/5] perf python: Honor perf script --show-kernel-path sashiko-bot
2026-12-04 16:24 ` [PATCH 4/5] perf python: Honor perf script --demangle and --demangle-kernel Jens Remus
2026-12-04 16:24 ` [PATCH 5/5] perf python: Honor perf script --max-stack Jens Remus
2026-12-04 17:35   ` sashiko-bot
2026-12-04 17:35 ` [PATCH 0/5] perf python: Honor more perf script options sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204162426.4171717-10-jremus@linux.ibm.com \
    --to=jremus@linux.ibm.com \
    --cc=acme@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=irogers@google.com \
    --cc=japo@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=sumanthk@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.