Re: [PATCH v2 09/49] perf python: Add Intel PT call_return and itrace capability
From: Ian Rogers
Date: Tue Sep 22 2026 - 13:05:08 EST
On Tue, Sep 22, 2026 at 6:11 AM James Clark <james.clark@xxxxxxxxxx> wrote:
>
>
>
> On 21/09/2026 06:06, Ian Rogers wrote:
> > Add support for Intel PT call_return events and itrace options to the
> > perf Python extension so standalone Python scripts can decode and
> > inspect low-level instruction traces.
> >
> > Specifically:
> > - Add a call_return callback parameter and itrace option string to
> > perf.session, treating explicit None (Py_None) callbacks as omitted.
> > - Expose the perf.call_return object with db_id, parent_id, insn_count,
> > cyc_count, comm, pid, tid, call_time, return_time, branch_count,
> > call_ref, return_ref, flags, and call_path (resolved as a
> > perf.callchain ordered from outermost caller to callee).
> > - Export perf.CALL_RETURN_NO_CALL, perf.CALL_RETURN_NO_RETURN, and
> > perf.CALL_RETURN_NON_CALL flag constants.
> > - Expose session.e_machine and session.is_64_bit properties, preferring
> > recorded thread ELF machines (perf_session__e_machine) over perf_env
> > so pipe-mode traces do not prematurely cache host bitness.
> > - Support optional vmlinux, kallsyms, and symfs symbol configuration
> > parameters (and PERF_SYMBOL_VMLINUX, PERF_SYMBOL_KALLSYMS,
> > PERF_SYMBOL_SYMFS environment fallbacks) in perf.session, resetting
> > symbol_conf pointers and freeing vm_tm_corr_args, cpu_bitmap, and
> > ptime_range in
> > pyrf_session__delete().
> >
> > Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
> > ---
> > tools/perf/python/perf.pyi | 35 +++
> > tools/perf/util/python.c | 624 +++++++++++++++++++++++++++++++++++--
> > 2 files changed, 632 insertions(+), 27 deletions(-)
> >
> [...]
> > @@ -4161,23 +4585,40 @@ static PyObject *pyrf_session__new(PyTypeObject *type, PyObject *args, PyObject
> > {
> > struct pyrf_data *pdata;
> > PyObject *sample = NULL, *stat = NULL, *context_switch = NULL;
> > - static char * const kwlist[] = { "data", "sample", "stat", "context_switch", NULL };
> > + PyObject *call_return = NULL;
> > + char *itrace_str = NULL;
> > + char *vmlinux_str = NULL, *kallsyms_str = NULL, *symfs_str = NULL;
> > + static char * const kwlist[] = { "data", "sample", "stat", "context_switch",
>
> Hi Ian,
>
> This needs to be "static char *kwlist[]" to support older Python versions:
>
> Changed in version 3.13: The keywords parameter has now type char
> *const* in C and const char *const* in C++, instead of char**
Thanks! Fixing in v3.
Ian
> > + "call_return", "itrace", "vmlinux", "kallsyms",
> > + "symfs", NULL };
> > struct pyrf_session *psession;
> > struct perf_session *session;