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 4/5] perf python: Honor perf script --demangle and --demangle-kernel
Date: Fri, 4 Dec 2026 17:24:31 +0100 [thread overview]
Message-ID: <20261204162426.4171717-11-jremus@linux.ibm.com> (raw)
In-Reply-To: <20261204162426.4171717-7-jremus@linux.ibm.com>
The perf.session binding always runs with the default symbol_conf
demangle settings, so --no-demangle and --demangle-kernel of perf
script have no effect on the symbol names of a Python script run by
perf script.
Add demangle and demangle_kernel keyword arguments to perf.session.
When not given, they default to the PERF_SYMBOL_DEMANGLE and
PERF_SYMBOL_DEMANGLE_KERNEL environment variables, which perf script
sets from --[no-]demangle and --[no-]demangle-kernel when running a
Python script. Otherwise they default to true and false, as before.
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
---
.../perf/Documentation/perf-script-python.txt | 5 +++--
tools/perf/builtin-script.c | 3 +++
tools/perf/python/perf.pyi | 10 ++++++++-
tools/perf/util/python.c | 21 ++++++++++++++++---
4 files changed, 33 insertions(+), 6 deletions(-)
diff --git a/tools/perf/Documentation/perf-script-python.txt b/tools/perf/Documentation/perf-script-python.txt
index b4652a67b5bc..e2f05f5d526c 100644
--- a/tools/perf/Documentation/perf-script-python.txt
+++ b/tools/perf/Documentation/perf-script-python.txt
@@ -19,7 +19,8 @@ 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`, `--inline`/`--no-inline` and `--show-kernel-path`)
+`--kallsyms`, `--symfs`, `--inline`/`--no-inline`, `--show-kernel-path`,
+`--demangle`/`--no-demangle` and `--demangle-kernel`)
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`.
@@ -119,7 +120,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, 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`.
+- `__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, demangle=True, demangle_kernel=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`. `show_kernel_path` reports the kernel DSO by its vmlinux path rather than `[kernel.kallsyms]`. `demangle` and `demangle_kernel` demangle user space and kernel symbol names. When run by `perf script`, the defaults of `inline`, `show_kernel_path`, `demangle` and `demangle_kernel` are the values of `--inline`/`--no-inline`, `--show-kernel-path`, `--demangle`/`--no-demangle` and `--demangle-kernel`.
- `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 ccf7e3fe8934..0936cf711e8c 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -4540,6 +4540,9 @@ int cmd_script(int argc, const char **argv)
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);
+ setenv("PERF_SYMBOL_DEMANGLE", symbol_conf.demangle ? "1" : "0", 1);
+ setenv("PERF_SYMBOL_DEMANGLE_KERNEL",
+ symbol_conf.demangle_kernel ? "1" : "0", 1);
execvp(__argv[0], (char **)__argv);
{
diff --git a/tools/perf/python/perf.pyi b/tools/perf/python/perf.pyi
index ce75f8999fa7..c7f43deb84bf 100644
--- a/tools/perf/python/perf.pyi
+++ b/tools/perf/python/perf.pyi
@@ -490,7 +490,9 @@ class session:
kallsyms: Optional[str] = None,
symfs: Optional[str] = None,
inline: bool = ...,
- show_kernel_path: bool = ...
+ show_kernel_path: bool = ...,
+ demangle: bool = ...,
+ demangle_kernel: bool = ...
) -> None:
"""Initialize a perf session.
@@ -505,6 +507,12 @@ class session:
than [kernel.kallsyms]. Defaults to the
PERF_SYMBOL_SHOW_KERNEL_PATH environment variable set by
perf script, otherwise True.
+ demangle: Demangle user space symbol names. Defaults to the
+ PERF_SYMBOL_DEMANGLE environment variable set by perf script,
+ otherwise True.
+ demangle_kernel: Demangle kernel symbol names. Defaults to the
+ PERF_SYMBOL_DEMANGLE_KERNEL environment variable set by perf
+ script, otherwise False.
"""
...
e_machine: int
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index 18a8468c0eb2..fe468a0f0aa4 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -4250,6 +4250,8 @@ struct pyrf_session {
char *symfs;
bool inline_name;
bool show_kernel_path;
+ bool demangle;
+ bool demangle_kernel;
};
struct pyrf_call_return {
@@ -4985,18 +4987,21 @@ static PyObject *pyrf_session__new(PyTypeObject *type, PyObject *args, PyObject
char *itrace_str = NULL;
char *vmlinux_str = NULL, *kallsyms_str = NULL, *symfs_str = NULL;
int inline_arg = -1, show_kernel_path_arg = -1;
+ int demangle_arg = -1, demangle_kernel_arg = -1;
static char *kwlist[] = { "data", "sample", "stat", "context_switch",
"call_return", "itrace", "vmlinux", "kallsyms",
- "symfs", "inline", "show_kernel_path", NULL };
+ "symfs", "inline", "show_kernel_path",
+ "demangle", "demangle_kernel", NULL };
struct pyrf_session *psession;
struct perf_session *session;
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!|OOOOzzzzpp", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!|OOOOzzzzpppp", kwlist,
&pyrf_data__type, &pdata,
&sample, &stat, &context_switch,
&call_return, &itrace_str,
&vmlinux_str, &kallsyms_str, &symfs_str,
- &inline_arg, &show_kernel_path_arg))
+ &inline_arg, &show_kernel_path_arg,
+ &demangle_arg, &demangle_kernel_arg))
return NULL;
psession = PyObject_New(struct pyrf_session, type);
@@ -5020,6 +5025,8 @@ static PyObject *pyrf_session__new(PyTypeObject *type, PyObject *args, PyObject
psession->symfs = NULL;
psession->inline_name = false;
psession->show_kernel_path = true;
+ psession->demangle = true;
+ psession->demangle_kernel = false;
psession->pdata = NULL;
memset(&psession->itrace_opts, 0, sizeof(psession->itrace_opts));
@@ -5140,6 +5147,10 @@ static PyObject *pyrf_session__new(PyTypeObject *type, PyObject *args, PyObject
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);
+ psession->demangle = demangle_arg >= 0 ? demangle_arg :
+ pyrf_getenv_bool("PERF_SYMBOL_DEMANGLE", psession->demangle);
+ psession->demangle_kernel = demangle_kernel_arg >= 0 ? demangle_kernel_arg :
+ pyrf_getenv_bool("PERF_SYMBOL_DEMANGLE_KERNEL", psession->demangle_kernel);
if (pyrf_session__active) {
PyErr_SetString(PyExc_RuntimeError,
@@ -5153,6 +5164,8 @@ static PyObject *pyrf_session__new(PyTypeObject *type, PyObject *args, PyObject
symbol_conf.use_callchain = true;
symbol_conf.inline_name = psession->inline_name;
symbol_conf.show_kernel_path = psession->show_kernel_path;
+ symbol_conf.demangle = psession->demangle;
+ symbol_conf.demangle_kernel = psession->demangle_kernel;
/* Reading the header of a pipe may block, let other python threads run. */
pyrf_session__active = psession;
@@ -5225,6 +5238,8 @@ static PyObject *pyrf_session__find_thread_events(struct pyrf_session *psession)
symbol_conf.symfs = psession->symfs ?: "";
symbol_conf.inline_name = psession->inline_name;
symbol_conf.show_kernel_path = psession->show_kernel_path;
+ symbol_conf.demangle = psession->demangle;
+ symbol_conf.demangle_kernel = psession->demangle_kernel;
psession->callback_raised = false;
/* Callbacks that use python acquire the GIL, see pyrf_session_tool__sample(). */
--
2.53.0
next prev 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 ` [PATCH 3/5] perf python: Honor perf script --show-kernel-path Jens Remus
2026-12-04 17:13 ` sashiko-bot
2026-12-04 16:24 ` Jens Remus [this message]
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-11-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox