Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jens Remus" <jremus@linux.ibm.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 1/5] perf python: Support inlined frames in callchains
Date: Fri, 04 Dec 2026 16:46:52 +0000	[thread overview]
Message-ID: <sashiko-outbox-250215@kernel.org> (raw)
In-Reply-To: <20261204162426.4171717-8-jremus@linux.ibm.com>

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

  reply	other threads:[~2026-12-04 16:46 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 [this message]
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 ` [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=sashiko-outbox-250215@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=jremus@linux.ibm.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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