* [PATCH 1/5] perf python: Support inlined frames in callchains
2026-12-04 16:24 [PATCH 0/5] perf python: Honor more perf script options Jens Remus
@ 2026-12-04 16:24 ` 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
` (4 subsequent siblings)
5 siblings, 1 reply; 11+ messages in thread
From: Jens Remus @ 2026-12-04 16:24 UTC (permalink / raw)
To: Ian Rogers, Arnaldo Carvalho de Melo, Namhyung Kim,
Peter Zijlstra, Ingo Molnar
Cc: Jens Remus, Jan Polensky, Sumanth Korikkar, Heiko Carstens,
Vasily Gorbik, Alexander Gordeev, linux-perf-users, linux-kernel
The perf.session binding forces symbol_conf.inline_name to false, so
callchains never contain inlined frames, unlike perf script, which
resolves them by default and offers --no-inline to disable it.
Add an inline keyword argument to perf.session. When not given, it
defaults to the PERF_SYMBOL_INLINE environment variable, which perf
script sets from --inline/--no-inline when running a Python script,
like it already does for --vmlinux, --kallsyms, --symfs and --itrace.
Otherwise it defaults to false, as before.
Add the inlined flag to perf.callchain_node, so that scripts can tell
inlined frames from the frame of the function they are inlined into.
This enables perf script -s <script-file> using a Python script to
generate output identical to perf script.
Note that Python scripts run by perf script now resolve inlined frames
by default, as perf script does. Use --no-inline to disable it.
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
---
.../perf/Documentation/perf-script-python.txt | 9 +++--
tools/perf/builtin-script.c | 1 +
tools/perf/python/perf.pyi | 7 +++-
tools/perf/util/python.c | 38 +++++++++++++++++--
4 files changed, 46 insertions(+), 9 deletions(-)
diff --git a/tools/perf/Documentation/perf-script-python.txt b/tools/perf/Documentation/perf-script-python.txt
index cbf50b3e5f06..10b124267f89 100644
--- a/tools/perf/Documentation/perf-script-python.txt
+++ b/tools/perf/Documentation/perf-script-python.txt
@@ -19,9 +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`, and `--symfs`) 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` 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`.
Trace filtering command-line
options (`-C`, `-c`, `--pid`, `--tid`, `--time`, `--dlfilter`, `--dlarg`) passed
to `perf script` are not applied to standalone scripts.
@@ -118,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)`: 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.
+- `__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`.
- `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 b6691ebb1b4e..2ab6b17f638e 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -4537,6 +4537,7 @@ int cmd_script(int argc, const char **argv)
setenv("PERF_SYMBOL_SYMFS", symbol_conf.symfs, 1);
if (script_itrace_opts)
setenv("PERF_ITRACE", script_itrace_opts, 1);
+ setenv("PERF_SYMBOL_INLINE", symbol_conf.inline_name ? "1" : "0", 1);
execvp(__argv[0], (char **)__argv);
{
diff --git a/tools/perf/python/perf.pyi b/tools/perf/python/perf.pyi
index 087da00728fd..4fcbaf4694c9 100644
--- a/tools/perf/python/perf.pyi
+++ b/tools/perf/python/perf.pyi
@@ -353,6 +353,7 @@ class callchain_node:
symbol: str
dso: str
sym_offset: Optional[int]
+ inlined: bool
class callchain:
"""Sequence of callchain frames."""
@@ -487,7 +488,8 @@ class session:
itrace: Optional[str] = None,
vmlinux: Optional[str] = None,
kallsyms: Optional[str] = None,
- symfs: Optional[str] = None
+ symfs: Optional[str] = None,
+ inline: bool = ...
) -> None:
"""Initialize a perf session.
@@ -495,6 +497,9 @@ class session:
data: The perf data file to read.
sample: Callback for sample events.
stat: Callback for stat events.
+ inline: Resolve inlined functions in callchains. Defaults to the
+ PERF_SYMBOL_INLINE 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 60dbe2dad5eb..b5426dfaee01 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -994,11 +994,18 @@ static PyObject *pyrf_callchain_node__get_sym_offset(struct pyrf_callchain_node
return PyLong_FromUnsignedLongLong(addr - pnode->sym->start);
}
+static PyObject *pyrf_callchain_node__get_inlined(struct pyrf_callchain_node *pnode,
+ void *closure __maybe_unused)
+{
+ return PyBool_FromLong(pnode->sym && symbol__inlined(pnode->sym));
+}
+
static PyGetSetDef pyrf_callchain_node__getset[] = {
{ .name = "ip", .get = (getter)pyrf_callchain_node__get_ip, },
{ .name = "symbol", .get = (getter)pyrf_callchain_node__get_symbol, },
{ .name = "dso", .get = (getter)pyrf_callchain_node__get_dso, },
{ .name = "sym_offset", .get = (getter)pyrf_callchain_node__get_sym_offset, },
+ { .name = "inlined", .get = (getter)pyrf_callchain_node__get_inlined, },
{ .name = NULL, },
};
@@ -4241,6 +4248,7 @@ struct pyrf_session {
char *vmlinux_name;
char *kallsyms_name;
char *symfs;
+ bool inline_name;
};
struct pyrf_call_return {
@@ -4958,6 +4966,16 @@ static PyObject *pyrf_session__find_thread(struct pyrf_session *psession, PyObje
return result;
}
+/* Return @def when the environment variable is unset or empty. */
+static bool pyrf_getenv_bool(const char *name, bool def)
+{
+ const char *str = getenv(name);
+
+ if (!str || !str[0])
+ return def;
+ return strcmp(str, "0") != 0;
+}
+
static PyObject *pyrf_session__new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
struct pyrf_data *pdata;
@@ -4965,17 +4983,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;
static char *kwlist[] = { "data", "sample", "stat", "context_switch",
"call_return", "itrace", "vmlinux", "kallsyms",
- "symfs", NULL };
+ "symfs", "inline", NULL };
struct pyrf_session *psession;
struct perf_session *session;
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!|OOOOzzzz", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!|OOOOzzzzp", kwlist,
&pyrf_data__type, &pdata,
&sample, &stat, &context_switch,
&call_return, &itrace_str,
- &vmlinux_str, &kallsyms_str, &symfs_str))
+ &vmlinux_str, &kallsyms_str, &symfs_str,
+ &inline_arg))
return NULL;
psession = PyObject_New(struct pyrf_session, type);
@@ -4997,6 +5017,7 @@ static PyObject *pyrf_session__new(PyTypeObject *type, PyObject *args, PyObject
psession->vmlinux_name = NULL;
psession->kallsyms_name = NULL;
psession->symfs = NULL;
+ psession->inline_name = false;
psession->pdata = NULL;
memset(&psession->itrace_opts, 0, sizeof(psession->itrace_opts));
@@ -5108,6 +5129,14 @@ static PyObject *pyrf_session__new(PyTypeObject *type, PyObject *args, PyObject
}
}
+ /*
+ * The keyword arguments take precedence over the environment variables
+ * perf script sets from its command line options, which take
+ * precedence over the defaults.
+ */
+ psession->inline_name = inline_arg >= 0 ? inline_arg :
+ pyrf_getenv_bool("PERF_SYMBOL_INLINE", psession->inline_name);
+
if (pyrf_session__active) {
PyErr_SetString(PyExc_RuntimeError,
"Another perf.session is currently active");
@@ -5119,7 +5148,7 @@ static PyObject *pyrf_session__new(PyTypeObject *type, PyObject *args, PyObject
symbol_conf.symfs = psession->symfs ?: "";
symbol_conf.use_callchain = true;
symbol_conf.show_kernel_path = true;
- symbol_conf.inline_name = false;
+ symbol_conf.inline_name = psession->inline_name;
/* Reading the header of a pipe may block, let other python threads run. */
pyrf_session__active = psession;
@@ -5190,6 +5219,7 @@ static PyObject *pyrf_session__find_thread_events(struct pyrf_session *psession)
symbol_conf.vmlinux_name = psession->vmlinux_name;
symbol_conf.kallsyms_name = psession->kallsyms_name;
symbol_conf.symfs = psession->symfs ?: "";
+ symbol_conf.inline_name = psession->inline_name;
psession->callback_raised = false;
/* Callbacks that use python acquire the GIL, see pyrf_session_tool__sample(). */
--
2.53.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH 1/5] perf python: Support inlined frames in callchains
2026-12-04 16:24 ` [PATCH 1/5] perf python: Support inlined frames in callchains Jens Remus
@ 2026-12-04 16:46 ` sashiko-bot
0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-12-04 16:46 UTC (permalink / raw)
To: Jens Remus; +Cc: linux-perf-users
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] perf python: net_dropmonitor.py pairs inlined frame with
enclosing offset
- [Low] perf doc: perf-script-python.txt omits inlined callchain node
attribute
- [Low] perf python: pyrf_getenv_bool() checks only "0" instead of
perf_config_bool()
--
commit b323825e4c680032e02984aa9e4613ee4ca3e78e
Author: Jens Remus <jremus@linux.ibm.com>
perf python: Support inlined frames in callchains
This commit adds an inline keyword argument to perf.session (defaulting to
the PERF_SYMBOL_INLINE environment variable set by perf script) and exposes
an inlined attribute on perf.callchain_node.
> diff --git a/tools/perf/Documentation/perf-script-python.txt b/tools/perf/Documentation/perf-script-python.txt
> index cbf50b3e5f062..10b124267f89a 100644
> --- a/tools/perf/Documentation/perf-script-python.txt
> +++ b/tools/perf/Documentation/perf-script-python.txt
[ ... ]
> @@ -118,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)`: 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.
> +- `__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`.
[Severity: Low]
The Sample Object section later in this file still documents callchain as
a sequence of callchain nodes with only ip, symbol, and dso, omitting the
newly added inlined attribute (and the pre-existing sym_offset attribute).
Should that section be updated as well?
> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
> index b6691ebb1b4ef..2ab6b17f638e0 100644
> --- a/tools/perf/builtin-script.c
> +++ b/tools/perf/builtin-script.c
> @@ -4537,6 +4537,7 @@ int cmd_script(int argc, const char **argv)
> setenv("PERF_SYMBOL_SYMFS", symbol_conf.symfs, 1);
> if (script_itrace_opts)
> setenv("PERF_ITRACE", script_itrace_opts, 1);
> + setenv("PERF_SYMBOL_INLINE", symbol_conf.inline_name ? "1" : "0", 1);
[Severity: Medium]
Can exporting PERF_SYMBOL_INLINE=1 by default cause
tools/perf/python/net_dropmonitor.py to report an inlined function name
paired with the enclosing function's offset?
Because symbol_conf.inline_name defaults to true and callchains default to
callee order, sample.callchain now yields the innermost inlined frame
before the enclosing frame with the same ip. new_inline_sym() copies
base_sym->start, so sym_offset is still relative to the enclosing function.
tools/perf/python/net_dropmonitor.py:DropMonitor.process_event() {
...
if entry_ip == location and sym_name and sym_name != "[unknown]":
if sym_off is not None:
self.resolved_syms[location] = (sym_name, sym_off)
self.callchain_syms.pop(location, None)
else:
self.callchain_syms[location] = sym_name
break
...
}
DropMonitor.process_event() breaks on the first matching entry_ip without
checking entry.inlined, so an inlined frame at a drop location prints a
mismatched (inlined_name, enclosing_offset) pair. Skipping frames where
entry.inlined is true would preserve the enclosing symbol and offset.
[ ... ]
> diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
> index 60dbe2dad5eb8..b5426dfaee01f 100644
> --- a/tools/perf/util/python.c
> +++ b/tools/perf/util/python.c
[ ... ]
> @@ -4958,6 +4966,16 @@ static PyObject *pyrf_session__find_thread(struct pyrf_session *psession, PyObje
> return result;
> }
>
> +/* Return @def when the environment variable is unset or empty. */
> +static bool pyrf_getenv_bool(const char *name, bool def)
> +{
> + const char *str = getenv(name);
> +
> + if (!str || !str[0])
> + return def;
> + return strcmp(str, "0") != 0;
> +}
[Severity: Low]
Should pyrf_getenv_bool() use perf_config_bool() instead of only checking
for "0"?
With strcmp(str, "0") != 0, a user running a standalone script with
PERF_SYMBOL_INLINE=false (or "no"/"off") silently gets true, since the
documentation does not restrict the variable to 0/1.
python.c already includes config.h, so calling perf_config_bool(name, str)
after the empty-string check (matching perf_env_bool() in util/config.c)
would handle standard boolean values consistently.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204162426.4171717-7-jremus@linux.ibm.com?part=1
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 2/5] perf python: Export inlined symbol flag in DB export scripts
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:24 ` 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
` (3 subsequent siblings)
5 siblings, 1 reply; 11+ messages in thread
From: Jens Remus @ 2026-12-04 16:24 UTC (permalink / raw)
To: Ian Rogers, Arnaldo Carvalho de Melo, Namhyung Kim,
Peter Zijlstra, Ingo Molnar
Cc: Jens Remus, Jan Polensky, Sumanth Korikkar, Heiko Carstens,
Vasily Gorbik, Alexander Gordeev, linux-perf-users, linux-kernel
Add an inlined column to the symbols table of the SQLite and PostgreSQL
exports, populated from perf.callchain_node.inlined. An inlined frame
and a regular frame can share their name and DSO, so the flag is part
of the key that identifies a symbol.
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
---
tools/perf/python/export-to-postgresql.py | 32 +++++++++++++----------
tools/perf/python/export-to-sqlite.py | 18 +++++++------
2 files changed, 28 insertions(+), 22 deletions(-)
diff --git a/tools/perf/python/export-to-postgresql.py b/tools/perf/python/export-to-postgresql.py
index 9cac64dee361..4f303d239440 100755
--- a/tools/perf/python/export-to-postgresql.py
+++ b/tools/perf/python/export-to-postgresql.py
@@ -205,7 +205,7 @@ class PostgresExporter:
'branch_types': {},
'call_paths': {}
}
- self.symbol_rows: Dict[int, tuple[int, int, int, int, str]] = {}
+ self.symbol_rows: Dict[int, tuple[int, int, int, int, bool, str]] = {}
self.next_id = {
'machine': 1,
@@ -372,6 +372,7 @@ class PostgresExporter:
sym_start bigint,
sym_end bigint,
binding integer,
+ inlined boolean,
name varchar(2048))
""")
self.do_query("""
@@ -514,7 +515,7 @@ class PostgresExporter:
self.write_thread(0, 0, 0, -1, -1)
self.write_comm(0, "unknown", 0, 0, 0)
self.write_dso(0, 0, "unknown", "unknown", "")
- self.write_symbol(0, 0, 0, 0, 0, "unknown")
+ self.write_symbol(0, 0, 0, 0, 0, False, "unknown")
self.write_call_path(0, 0, 0, 0)
# Sentinel id = 0 rows in sample_table.bin and call_table.bin satisfy
# PostgreSQL FOREIGN KEY constraints (call_id/return_id -> samples.id
@@ -638,13 +639,15 @@ class PostgresExporter:
self.files['dso'].write(value)
def write_symbol(self, symbol_id: int, dso_id: int, sym_start: int,
- sym_end: int, binding: int, symbol_name: str) -> None:
+ sym_end: int, binding: int, inlined: bool,
+ symbol_name: str) -> None:
"""Write symbol to binary file."""
name_bytes = toserverstr(symbol_name)
n = len(name_bytes)
- fmt = "!hiqiqiQiQiii" + str(n) + "s"
- value = struct.pack(fmt, 6, 8, symbol_id, 8, dso_id, 8,
- sym_start, 8, sym_end, 4, binding, n, name_bytes)
+ fmt = "!hiqiqiQiQiiiBi" + str(n) + "s"
+ value = struct.pack(fmt, 7, 8, symbol_id, 8, dso_id, 8,
+ sym_start, 8, sym_end, 4, binding, 1, inlined,
+ n, name_bytes)
self.files['symbol'].write(value)
def write_call_path(self, cp_id: int, parent_id: int, symbol_id: int,
@@ -771,18 +774,18 @@ class PostgresExporter:
return dso_id
def get_symbol_id(self, dso_id: int, name: str, start: int,
- end: int) -> int:
+ end: int, inlined: bool = False) -> int:
"""Get or create symbol ID."""
- key = (dso_id, name)
+ key = (dso_id, name, inlined)
if key in self.caches['symbols']:
symbol_id, cached_start, cached_end = self.caches['symbols'][key]
if cached_start == 0 and cached_end == 0 and (start != 0 or end != 0):
self.caches['symbols'][key] = (symbol_id, start, end)
- self.symbol_rows[symbol_id] = (dso_id, start, end, 0, name)
+ self.symbol_rows[symbol_id] = (dso_id, start, end, 0, inlined, name)
return symbol_id
symbol_id = self.next_id['symbol']
self.caches['symbols'][key] = (symbol_id, start, end)
- self.symbol_rows[symbol_id] = (dso_id, start, end, 0, name)
+ self.symbol_rows[symbol_id] = (dso_id, start, end, 0, inlined, name)
self.next_id['symbol'] += 1
return symbol_id
@@ -887,7 +890,7 @@ class PostgresExporter:
dso_name = node.dso or "Unknown_dso"
symbol_name = node.symbol or "Unknown_symbol"
dso_id = self.get_dso_id(dso_name, dso_name, "", machine_id)
- symbol_id = self.get_symbol_id(dso_id, symbol_name, 0, 0)
+ symbol_id = self.get_symbol_id(dso_id, symbol_name, 0, 0, node.inlined)
parent_id = call_path_id
call_path_id = self.get_call_path_id(parent_id, symbol_id, node.ip)
return call_path_id, parent_id
@@ -963,7 +966,8 @@ class PostgresExporter:
or "Unknown_symbol")
node_dso_id = self.get_dso_id(dso_name, dso_name, "", machine_id)
- node_symbol_id = self.get_symbol_id(node_dso_id, symbol_name, 0, 0)
+ node_symbol_id = self.get_symbol_id(node_dso_id, symbol_name, 0, 0,
+ getattr(node, 'inlined', False))
parent_id = self.get_call_path_id(parent_id, node_symbol_id, node.ip)
call_path_id = parent_id
@@ -997,8 +1001,8 @@ class PostgresExporter:
def finalize(self) -> None:
"""Copy files to database and add keys/views."""
print("Copying to database...")
- for symbol_id, (dso_id, sym_start, sym_end, binding, name) in self.symbol_rows.items():
- self.write_symbol(symbol_id, dso_id, sym_start, sym_end, binding, name)
+ for symbol_id, (dso_id, sym_start, sym_end, binding, inlined, name) in self.symbol_rows.items():
+ self.write_symbol(symbol_id, dso_id, sym_start, sym_end, binding, inlined, name)
for name, f in self.files.items():
self.close_output_file(f)
diff --git a/tools/perf/python/export-to-sqlite.py b/tools/perf/python/export-to-sqlite.py
index 0a8087e51037..e582bb6004fd 100755
--- a/tools/perf/python/export-to-sqlite.py
+++ b/tools/perf/python/export-to-sqlite.py
@@ -168,6 +168,7 @@ class DatabaseExporter:
sym_start BIGINT,
sym_end BIGINT,
binding INTEGER,
+ inlined BOOLEAN,
name VARCHAR(2048))
""")
self.con.execute("""
@@ -460,7 +461,7 @@ class DatabaseExporter:
self.con.execute("INSERT OR IGNORE INTO comms VALUES (0, 'unknown', 0, 0, 0)")
self.con.execute("INSERT OR IGNORE INTO dsos VALUES (0, 0, 'unknown', 'unknown', '')")
self.con.execute("INSERT OR IGNORE INTO call_paths VALUES (0, 0, 0, 0)")
- self.con.execute("INSERT OR IGNORE INTO symbols VALUES (0, 0, 0, 0, 0, 'unknown')")
+ self.con.execute("INSERT OR IGNORE INTO symbols VALUES (0, 0, 0, 0, 0, 0, 'unknown')")
for b_type, b_name in BRANCH_TYPES:
self.con.execute("INSERT OR IGNORE INTO branch_types VALUES (?, ?)", (b_type, b_name))
self.caches['branch_types'][b_type] = b_name
@@ -470,7 +471,7 @@ class DatabaseExporter:
self.caches['threads'][(0, 0, 0)] = 0
self.caches['comms'][('unknown', 0)] = 0
self.caches['dsos'][(0, 'unknown', 'unknown', '')] = 0
- self.caches['symbols'][(0, 'unknown')] = (0, 0, 0)
+ self.caches['symbols'][(0, 'unknown', False)] = (0, 0, 0)
# Initialize comm_threads mapping
self.comm_threads_cache: set[tuple[int, int]] = set()
self.next_comm_thread_id = 1
@@ -570,9 +571,9 @@ class DatabaseExporter:
return dso_id
def get_symbol_id(self, dso_id: int, name: str, start: int,
- end: int) -> int:
+ end: int, inlined: bool = False) -> int:
"""Get or create symbol ID."""
- key = (dso_id, name)
+ key = (dso_id, name, inlined)
if key in self.caches['symbols']:
symbol_id, cached_start, cached_end = self.caches['symbols'][key]
if cached_start == 0 and cached_end == 0 and (start != 0 or end != 0):
@@ -581,8 +582,8 @@ class DatabaseExporter:
self.caches['symbols'][key] = (symbol_id, start, end)
return symbol_id
symbol_id = self.next_id['symbol']
- self._exec("INSERT INTO symbols VALUES (?, ?, ?, ?, ?, ?)",
- (symbol_id, dso_id, start, end, 0, name))
+ self._exec("INSERT INTO symbols VALUES (?, ?, ?, ?, ?, ?, ?)",
+ (symbol_id, dso_id, start, end, 0, inlined, name))
self.caches['symbols'][key] = (symbol_id, start, end)
self.next_id['symbol'] += 1
return symbol_id
@@ -643,7 +644,8 @@ class DatabaseExporter:
symbol_name = node.symbol or "Unknown_symbol"
node_dso_id = self.get_dso_id(dso_name, dso_name, "", machine_id)
- node_symbol_id = self.get_symbol_id(node_dso_id, symbol_name, 0, 0)
+ node_symbol_id = self.get_symbol_id(node_dso_id, symbol_name, 0, 0,
+ node.inlined)
parent_id = self.get_call_path_id(parent_id, node_symbol_id, node.ip)
call_path_id = parent_id
@@ -760,7 +762,7 @@ class DatabaseExporter:
dso_name = node.dso or "Unknown_dso"
symbol_name = node.symbol or "Unknown_symbol"
dso_id = self.get_dso_id(dso_name, dso_name, "", machine_id)
- symbol_id = self.get_symbol_id(dso_id, symbol_name, 0, 0)
+ symbol_id = self.get_symbol_id(dso_id, symbol_name, 0, 0, node.inlined)
parent_id = call_path_id
call_path_id = self.get_call_path_id(parent_id, symbol_id, node.ip)
return call_path_id, parent_id
--
2.53.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH 2/5] perf python: Export inlined symbol flag in DB export scripts
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
0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-12-04 16:59 UTC (permalink / raw)
To: Jens Remus; +Cc: linux-perf-users
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] perf python: symbols_view omits newly added inlined column
--
commit 94f2850728745d05c20b93e627431b793fdf46a6
Author: Jens Remus <jremus@linux.ibm.com>
perf python: Export inlined symbol flag in DB export scripts
This commit adds an inlined boolean column to the symbols table in
export-to-postgresql.py and export-to-sqlite.py, populated from
perf.callchain_node.inlined and included in the symbol deduplication key.
> diff --git a/tools/perf/python/export-to-postgresql.py b/tools/perf/python/export-to-postgresql.py
> index 9cac64dee3612..4f303d2394408 100755
> --- a/tools/perf/python/export-to-postgresql.py
> +++ b/tools/perf/python/export-to-postgresql.py
[ ... ]
> @@ -372,6 +372,7 @@ class PostgresExporter:
> sym_start bigint,
> sym_end bigint,
> binding integer,
> + inlined boolean,
> name varchar(2048))
> """)
> self.do_query("""
[Severity: Low]
Should symbols_view also include the new inlined column?
Both PostgresExporter.finalize() and DatabaseExporter.create_tables() in
tools/perf/python/export-to-sqlite.py project every other column of symbols
in symbols_view while omitting inlined. Because inlined and regular frames
sharing a name and DSO now get separate rows, they look identical in the view.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204162426.4171717-7-jremus@linux.ibm.com?part=2
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 3/5] perf python: Honor perf script --show-kernel-path
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:24 ` [PATCH 2/5] perf python: Export inlined symbol flag in DB export scripts Jens Remus
@ 2026-12-04 16:24 ` Jens Remus
2026-12-04 17:13 ` sashiko-bot
2026-12-04 16:24 ` [PATCH 4/5] perf python: Honor perf script --demangle and --demangle-kernel Jens Remus
` (2 subsequent siblings)
5 siblings, 1 reply; 11+ messages in thread
From: Jens Remus @ 2026-12-04 16:24 UTC (permalink / raw)
To: Ian Rogers, Arnaldo Carvalho de Melo, Namhyung Kim,
Peter Zijlstra, Ingo Molnar
Cc: Jens Remus, Jan Polensky, Sumanth Korikkar, Heiko Carstens,
Vasily Gorbik, Alexander Gordeev, linux-perf-users, linux-kernel
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
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH 3/5] perf python: Honor perf script --show-kernel-path
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
0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-12-04 17:13 UTC (permalink / raw)
To: Jens Remus; +Cc: linux-perf-users
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] perf python: pyrf_callchain_node__get_dso() reads global
show_kernel_path lazily
- [Low] perf python: default show_kernel_path=0 breaks gecko.py kmod
classification
--
commit 8453e475e7deb47d13e09c143ec3ea8957b9e428
Author: Jens Remus <jremus@linux.ibm.com>
perf python: Honor perf script --show-kernel-path
This patch adds a show_kernel_path keyword argument to perf.session,
defaulting to the PERF_SYMBOL_SHOW_KERNEL_PATH environment variable set
by perf script from --show-kernel-path, or true otherwise.
> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
> index 2ab6b17f638e0..ccf7e3fe89349 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);
> {
[Severity: Low]
Does exporting PERF_SYMBOL_SHOW_KERNEL_PATH=0 by default break kernel
module classification in tools/perf/python/gecko.py?
When perf script gecko runs without --show-kernel-path, gecko.py opens
perf.session without passing show_kernel_path, so
symbol_conf.show_kernel_path becomes false. For kernel modules,
pyrf_callchain_node__get_dso() then returns dso__name(dso) ([modname])
instead of dso__long_name(dso) (the .ko path):
tools/perf/python/gecko.py:Thread._intern_frame():
if (frame_str.find('kallsyms') != -1 or
frame_str.find('/vmlinux') != -1 or
frame_str.endswith('.ko)')):
category = self.kernel_category
Uncompressed kernel module callchain frames now format as
"symbol (in [modname])" rather than ending in ".ko)", so they fall
through to user_category instead of kernel_category in Firefox Profiler
output.
[ ... ]
> diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
> index b5426dfaee01f..18a8468c0eb28 100644
> --- a/tools/perf/util/python.c
> +++ b/tools/perf/util/python.c
[ ... ]
> @@ -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;
[Severity: Low]
Can overwriting the process-global symbol_conf.show_kernel_path
retroactively alter callchain_node.dso on retained objects from an
earlier session?
Unlike the other symbol_conf fields, symbol_conf.show_kernel_path is read
lazily in pyrf_callchain_node__get_dso() when Python accesses node.dso.
Because pyrf_event__copy() and pyrf_call_return__new() allow resolved
callchains to outlive a callback or process_events(), creating or
processing a second perf.session with a different show_kernel_path value
silently switches the DSO names reported by retained callchain_node
objects from the first session.
Capturing show_kernel_path on struct pyrf_callchain in
pyrf_sample_event__resolve_callchain() and pyrf_call_path__to_callchain()
and propagating it to struct pyrf_callchain_node would keep node.dso
bound to its originating session.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204162426.4171717-7-jremus@linux.ibm.com?part=3
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 4/5] perf python: Honor perf script --demangle and --demangle-kernel
2026-12-04 16:24 [PATCH 0/5] perf python: Honor more perf script options Jens Remus
` (2 preceding siblings ...)
2026-12-04 16:24 ` [PATCH 3/5] perf python: Honor perf script --show-kernel-path Jens Remus
@ 2026-12-04 16:24 ` Jens Remus
2026-12-04 16:24 ` [PATCH 5/5] perf python: Honor perf script --max-stack Jens Remus
2026-12-04 17:35 ` [PATCH 0/5] perf python: Honor more perf script options sashiko-bot
5 siblings, 0 replies; 11+ messages in thread
From: Jens Remus @ 2026-12-04 16:24 UTC (permalink / raw)
To: Ian Rogers, Arnaldo Carvalho de Melo, Namhyung Kim,
Peter Zijlstra, Ingo Molnar
Cc: Jens Remus, Jan Polensky, Sumanth Korikkar, Heiko Carstens,
Vasily Gorbik, Alexander Gordeev, linux-perf-users, linux-kernel
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
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 5/5] perf python: Honor perf script --max-stack
2026-12-04 16:24 [PATCH 0/5] perf python: Honor more perf script options Jens Remus
` (3 preceding siblings ...)
2026-12-04 16:24 ` [PATCH 4/5] perf python: Honor perf script --demangle and --demangle-kernel Jens Remus
@ 2026-12-04 16:24 ` 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
5 siblings, 1 reply; 11+ messages in thread
From: Jens Remus @ 2026-12-04 16:24 UTC (permalink / raw)
To: Ian Rogers, Arnaldo Carvalho de Melo, Namhyung Kim,
Peter Zijlstra, Ingo Molnar
Cc: Jens Remus, Jan Polensky, Sumanth Korikkar, Heiko Carstens,
Vasily Gorbik, Alexander Gordeev, linux-perf-users, linux-kernel
The perf.session binding resolves callchains with a fixed maximum depth
of PERF_MAX_STACK_DEPTH, ignoring the --max-stack option of perf script,
which is also raised to the callchain size of --itrace if larger.
Add a max_stack keyword argument to perf.session. When not given, it
defaults to the PERF_MAX_STACK environment variable, which perf script
sets from its effective maximum stack depth when running a Python
script. Otherwise it defaults to PERF_MAX_STACK_DEPTH, as before.
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
---
.../perf/Documentation/perf-script-python.txt | 11 ++--
tools/perf/builtin-script.c | 3 +
tools/perf/python/perf.pyi | 6 +-
tools/perf/util/python.c | 65 +++++++++++++++++--
4 files changed, 75 insertions(+), 10 deletions(-)
diff --git a/tools/perf/Documentation/perf-script-python.txt b/tools/perf/Documentation/perf-script-python.txt
index e2f05f5d526c..108deafeada3 100644
--- a/tools/perf/Documentation/perf-script-python.txt
+++ b/tools/perf/Documentation/perf-script-python.txt
@@ -20,10 +20,11 @@ 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`, `--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`.
+`--demangle`/`--no-demangle` and `--demangle-kernel`),
+`--max-stack` and `--itrace` options passed to `perf script`
+are forwarded via `PERF_SYMBOL_*`, `PERF_MAX_STACK` 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.
@@ -120,7 +121,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, 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`.
+- `__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, max_stack=127)`: 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. `max_stack` limits the number of resolved callchain entries. When run by `perf script`, the defaults of `inline`, `show_kernel_path`, `demangle`, `demangle_kernel` and `max_stack` are the values of `--inline`/`--no-inline`, `--show-kernel-path`, `--demangle`/`--no-demangle`, `--demangle-kernel` and `--max-stack`.
- `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 0936cf711e8c..c1e6ce1f0eaf 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -4435,6 +4435,7 @@ int cmd_script(int argc, const char **argv)
};
struct sigaction old_int, old_quit, old_term;
sigset_t block_mask, old_mask;
+ char max_stack_str[16];
if (is_python && is_legacy_python_script(script_name)) {
pr_err("Error: '%s' uses the removed legacy embedded Python scripting API.\n"
@@ -4543,6 +4544,8 @@ int cmd_script(int argc, const char **argv)
setenv("PERF_SYMBOL_DEMANGLE", symbol_conf.demangle ? "1" : "0", 1);
setenv("PERF_SYMBOL_DEMANGLE_KERNEL",
symbol_conf.demangle_kernel ? "1" : "0", 1);
+ snprintf(max_stack_str, sizeof(max_stack_str), "%u", scripting_max_stack);
+ setenv("PERF_MAX_STACK", max_stack_str, 1);
execvp(__argv[0], (char **)__argv);
{
diff --git a/tools/perf/python/perf.pyi b/tools/perf/python/perf.pyi
index c7f43deb84bf..d1604ab50092 100644
--- a/tools/perf/python/perf.pyi
+++ b/tools/perf/python/perf.pyi
@@ -492,7 +492,8 @@ class session:
inline: bool = ...,
show_kernel_path: bool = ...,
demangle: bool = ...,
- demangle_kernel: bool = ...
+ demangle_kernel: bool = ...,
+ max_stack: int = ...
) -> None:
"""Initialize a perf session.
@@ -513,6 +514,9 @@ class session:
demangle_kernel: Demangle kernel symbol names. Defaults to the
PERF_SYMBOL_DEMANGLE_KERNEL environment variable set by perf
script, otherwise False.
+ max_stack: Maximum number of callchain entries to resolve.
+ Defaults to the PERF_MAX_STACK environment variable set by
+ perf script, otherwise 127.
"""
...
e_machine: int
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index fe468a0f0aa4..7ddc127e3ef6 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -1088,6 +1088,12 @@ static PyTypeObject pyrf_callchain__type = {
.tp_as_sequence = &pyrf_callchain__sequence_methods,
};
+/*
+ * Maximum number of callchain entries to resolve, set from the active
+ * perf.session like the symbol_conf settings.
+ */
+static int pyrf_max_stack = PERF_MAX_STACK_DEPTH;
+
static int pyrf_sample_event__resolve_callchain(struct pyrf_event *pevent)
{
struct callchain_cursor *cursor;
@@ -1102,7 +1108,7 @@ static int pyrf_sample_event__resolve_callchain(struct pyrf_event *pevent)
cursor = get_tls_callchain_cursor();
if (thread__resolve_callchain(pevent->al.thread, cursor, pevent->sample,
- NULL, NULL, PERF_MAX_STACK_DEPTH) != 0)
+ NULL, NULL, pyrf_max_stack) != 0)
return 0;
callchain_cursor_commit(cursor);
@@ -4252,6 +4258,7 @@ struct pyrf_session {
bool show_kernel_path;
bool demangle;
bool demangle_kernel;
+ int max_stack;
};
struct pyrf_call_return {
@@ -4979,6 +4986,26 @@ static bool pyrf_getenv_bool(const char *name, bool def)
return strcmp(str, "0") != 0;
}
+/* Return @def when the environment variable is unset or empty. */
+static long pyrf_getenv_long(const char *name, long min, long max, long def)
+{
+ const char *str = getenv(name);
+ char *end;
+ long val;
+
+ if (str && str[0]) {
+ errno = 0;
+ val = strtol(str, &end, 10);
+ if (*end || errno || val < min || val > max) {
+ PyErr_Format(PyExc_ValueError, "invalid %s value: %s",
+ name, str);
+ return -1;
+ }
+ return val;
+ }
+ return def;
+}
+
static PyObject *pyrf_session__new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
struct pyrf_data *pdata;
@@ -4988,22 +5015,39 @@ static PyObject *pyrf_session__new(PyTypeObject *type, PyObject *args, PyObject
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;
+ PyObject *max_stack_obj = NULL;
+ long max_stack_arg = -1;
static char *kwlist[] = { "data", "sample", "stat", "context_switch",
"call_return", "itrace", "vmlinux", "kallsyms",
"symfs", "inline", "show_kernel_path",
- "demangle", "demangle_kernel", NULL };
+ "demangle", "demangle_kernel", "max_stack",
+ NULL };
struct pyrf_session *psession;
struct perf_session *session;
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!|OOOOzzzzpppp", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!|OOOOzzzzppppO", 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,
- &demangle_arg, &demangle_kernel_arg))
+ &demangle_arg, &demangle_kernel_arg,
+ &max_stack_obj))
return NULL;
+ if (max_stack_obj) {
+ max_stack_arg = PyLong_AsLong(max_stack_obj);
+
+ if (max_stack_arg == -1 && PyErr_Occurred())
+ return NULL;
+ if (max_stack_arg < 0 || max_stack_arg > INT_MAX) {
+ PyErr_Format(PyExc_ValueError,
+ "invalid max_stack value: %ld",
+ max_stack_arg);
+ return NULL;
+ }
+ }
+
psession = PyObject_New(struct pyrf_session, type);
if (!psession)
return NULL;
@@ -5027,6 +5071,7 @@ static PyObject *pyrf_session__new(PyTypeObject *type, PyObject *args, PyObject
psession->show_kernel_path = true;
psession->demangle = true;
psession->demangle_kernel = false;
+ psession->max_stack = PERF_MAX_STACK_DEPTH;
psession->pdata = NULL;
memset(&psession->itrace_opts, 0, sizeof(psession->itrace_opts));
@@ -5152,6 +5197,16 @@ static PyObject *pyrf_session__new(PyTypeObject *type, PyObject *args, PyObject
psession->demangle_kernel = demangle_kernel_arg >= 0 ? demangle_kernel_arg :
pyrf_getenv_bool("PERF_SYMBOL_DEMANGLE_KERNEL", psession->demangle_kernel);
+ if (max_stack_arg >= 0)
+ psession->max_stack = max_stack_arg;
+ else {
+ long val = pyrf_getenv_long("PERF_MAX_STACK", 0, INT_MAX, psession->max_stack);
+
+ if (val == -1 && PyErr_Occurred())
+ goto err_out;
+ psession->max_stack = val;
+ }
+
if (pyrf_session__active) {
PyErr_SetString(PyExc_RuntimeError,
"Another perf.session is currently active");
@@ -5166,6 +5221,7 @@ static PyObject *pyrf_session__new(PyTypeObject *type, PyObject *args, PyObject
symbol_conf.show_kernel_path = psession->show_kernel_path;
symbol_conf.demangle = psession->demangle;
symbol_conf.demangle_kernel = psession->demangle_kernel;
+ pyrf_max_stack = psession->max_stack;
/* Reading the header of a pipe may block, let other python threads run. */
pyrf_session__active = psession;
@@ -5240,6 +5296,7 @@ static PyObject *pyrf_session__find_thread_events(struct pyrf_session *psession)
symbol_conf.show_kernel_path = psession->show_kernel_path;
symbol_conf.demangle = psession->demangle;
symbol_conf.demangle_kernel = psession->demangle_kernel;
+ pyrf_max_stack = psession->max_stack;
psession->callback_raised = false;
/* Callbacks that use python acquire the GIL, see pyrf_session_tool__sample(). */
--
2.53.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH 5/5] perf python: Honor perf script --max-stack
2026-12-04 16:24 ` [PATCH 5/5] perf python: Honor perf script --max-stack Jens Remus
@ 2026-12-04 17:35 ` sashiko-bot
0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-12-04 17:35 UTC (permalink / raw)
To: Jens Remus; +Cc: linux-perf-users
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] perf python: pyrf_session__new() ignores itrace callchain_sz for
max_stack
--
commit a32cdfe5ec1c8800c1fb34b26309874d968719a6
Author: Jens Remus <jremus@linux.ibm.com>
perf python: Honor perf script --max-stack
This commit adds a max_stack keyword argument to perf.session and
forwards perf script's effective maximum stack depth via the
PERF_MAX_STACK environment variable.
> diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
> index fe468a0f0aa43..7ddc127e3ef68 100644
> --- a/tools/perf/util/python.c
> +++ b/tools/perf/util/python.c
[ ... ]
> @@ -5152,6 +5197,16 @@ static PyObject *pyrf_session__new(PyTypeObject *type, PyObject *args, PyObject
> psession->demangle_kernel = demangle_kernel_arg >= 0 ? demangle_kernel_arg :
> pyrf_getenv_bool("PERF_SYMBOL_DEMANGLE_KERNEL", psession->demangle_kernel);
>
> + if (max_stack_arg >= 0)
> + psession->max_stack = max_stack_arg;
> + else {
> + long val = pyrf_getenv_long("PERF_MAX_STACK", 0, INT_MAX, psession->max_stack);
> +
> + if (val == -1 && PyErr_Occurred())
> + goto err_out;
> + psession->max_stack = val;
> + }
[Severity: Low]
Should psession->max_stack also be raised to
psession->itrace_opts.callchain_sz when itrace callchain synthesis is
enabled?
Both cmd_script() and cmd_report() raise max_stack to
itrace_synth_opts.callchain_sz when callchain or add_callchain is set
and callchain_sz is larger.
When a script like export-to-sqlite.py passes itrace directly to
perf.session() (for example --itrace=g256) without max_stack,
psession->max_stack stays at 127 and synthesized callchains are
silently truncated above that depth.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204162426.4171717-7-jremus@linux.ibm.com?part=5
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 0/5] perf python: Honor more perf script options
2026-12-04 16:24 [PATCH 0/5] perf python: Honor more perf script options Jens Remus
` (4 preceding siblings ...)
2026-12-04 16:24 ` [PATCH 5/5] perf python: Honor perf script --max-stack Jens Remus
@ 2026-12-04 17:35 ` sashiko-bot
5 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-12-04 17:35 UTC (permalink / raw)
To: Jens Remus; +Cc: linux-perf-users
Sashiko has finished reviewing this 5-patch series:
- Patch 4: no issues found.
- Patch 1 ("perf python: Support inlined frames in callchains"): 3
potential issues (1 Medium, 2 Low)
- Patch 2 ("perf python: Export inlined symbol flag in DB export..."): 1
potential issue (1 Low)
- Patch 3 ("perf python: Honor perf script --show-kernel-path"): 2
potential issues (2 Low)
- Patch 5 ("perf python: Honor perf script --max-stack"): 1 potential
issue (1 Low)
Detailed reviews have been sent as separate replies to patches 1-3 and
5.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204162426.4171717-7-jremus@linux.ibm.com
^ permalink raw reply [flat|nested] 11+ messages in thread