Subject: Re: [PATCH v9 00/23] perf python: Modernize and extend Python API (Phase 1)

From: Arnaldo Carvalho de Melo <[email-masked]>
Date: Mon, 25 May 2026 17:14:22 -0300

On Fri, May 22, 2026 at 03:04:11PM -0700, Ian Rogers wrote:
> The perf script command has long supported running Python and Perl scripts by
> embedding libpython and libperl. This approach has several drawbacks:
>  - overhead by creating Python dictionaries for every event (whether used or
>    not),
>  - complex build dependencies on specific Python/Perl versions,
>  - complications with threading due to perf being the interpreter,
>  - no clear way to run standalone scripts like ilist.py.
> 
> This series takes a different approach with some initial implementation posted
> as an RFC last October:
> https://lore.kernel.org/linux-perf-users/[email-masked]/
> with the motivation coming up on the mailing list earlier:
> https://lore.kernel.org/lkml/CAP-5=fWDqE8SYfOLZkg_0=[email-masked]/
> 
> The ultimate goal is to remove the embedded libpython and libperl support from
> perf entirely, expanding the existing perf Python module to provide full access
> to perf data files and events, allowing scripts to be run as standalone Python
> applications.
> 
> To make the review process more manageable, the original 58-patch series has
> been split. This v9 series represents "Phase 1: API & Infrastructure" (23 patches).
> It contains:
> 1. Missed explicit dependency cleanups and header sorting.
> 2. Crucial core safety infrastructure (reference counting for evlist/evsel)
>    to support safe lifecycle management in garbage-collected Python.
> 3. The core Python API extensions (session wrappers, perf_data wrappers,
>    sample accessors, stubs, and LiveSession helper).
> 
> The subsequent "Phase 2" series will contain the actual porting of all
> existing Python/Perl scripts to the new API (which yields up to 35x speedups
> as demonstrated previously) and the final removal of embedded interpreters.

I tried applying it now and got this:

Cover: ./v9_20260522_irogers_perf_python_modernize_and_extend_python_api_phase_1.cover
 Link: https://lore.kernel.org/r/[email-masked]
 Base: not specified
       git am ./v9_20260522_irogers_perf_python_modernize_and_extend_python_api_phase_1.mbx
⬢ [acme@toolbx perf-tools-next2]$        git am ./v9_20260522_irogers_perf_python_modernize_and_extend_python_api_phase_1.mbx
Applying: perf arch arm: Sort includes and add missed explicit dependencies
Applying: perf arch x86: Sort includes and add missed explicit dependencies
Applying: perf tests: Sort includes and add missed explicit dependencies
Applying: perf script: Sort includes and add missed explicit dependencies
Applying: perf util: Sort includes and add missed explicit dependencies
error: patch failed: tools/perf/util/evsel.c:11
error: tools/perf/util/evsel.c: patch does not apply
Patch failed at 0005 perf util: Sort includes and add missed explicit dependencies
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
⬢ [acme@toolbx perf-tools-next2]$ git am --abort
⬢ [acme@toolbx perf-tools-next2]$ git diff
⬢ [acme@toolbx perf-tools-next2]$

I agree with the intent and plan on reviewing and testing it.

- Arnaldo