<feed xmlns='http://www.w3.org/2005/Atom'>
<title>g/linux.git/tools/perf/util/python.c, branch master</title>
<subtitle>Unnamed repository; edit this file 'description' to name the repository.</subtitle>
<id>https://bastion.nosebs.vip/g/linux.git/atom/tools/perf/util/python.c?h=master</id>
<link rel='self' href='https://bastion.nosebs.vip/g/linux.git/atom/tools/perf/util/python.c?h=master'/>
<link rel='alternate' type='text/html' href='https://bastion.nosebs.vip/g/linux.git/'/>
<updated>2026-10-17T13:30:18Z</updated>
<entry>
<title>perf python: Free the parse error entries when parsing fails</title>
<updated>2026-10-17T13:30:18Z</updated>
<author>
<name>Arnaldo Carvalho de Melo</name>
<email>acme@redhat.com</email>
</author>
<published>2026-10-16T01:06:19Z</published>
<link rel='alternate' type='text/html' href='https://bastion.nosebs.vip/g/linux.git/commit/?id=39e0022c89abcdc1a811dfc0aeec2a2b9010b660'/>
<id>urn:sha1:39e0022c89abcdc1a811dfc0aeec2a2b9010b660</id>
<content type='text'>
pyrf__parse_events() prints the entries parse_events_error__print()
receives with the details of a failed parse, but returns without freeing
them, leaking whatever parse_events_error__handle() allocated, so call
parse_events_error__exit() on both paths, as the other parse_events()
callers do.

The perf test attr core PMU probe takes this failure path on machines
without a core PMU, where the leak then happens on every test run.

Fixes: f081defccd93 ("perf python: Add parse_events function")
Reported-by: Sashiko &lt;sashiko-bot@kernel.org&gt;
Closes: https://lore.kernel.org/r/sashiko-outbox-173525@kernel.org
Reviewed-by: Ian Rogers &lt;irogers@google.com&gt;
Tested-by: Ian Rogers &lt;irogers@google.com&gt;
Cc: stable@vger.kernel.org
Assisted-by: LLM
Signed-off-by: Arnaldo Carvalho de Melo &lt;acme@redhat.com&gt;
</content>
</entry>
<entry>
<title>perf python: Release the GIL while processing session events</title>
<updated>2026-10-03T09:10:26Z</updated>
<author>
<name>Ian Rogers</name>
<email>irogers@google.com</email>
</author>
<published>2026-10-02T18:26:14Z</published>
<link rel='alternate' type='text/html' href='https://bastion.nosebs.vip/g/linux.git/commit/?id=055c721d38a49ea37fe058f6259ed85bf89cdfec'/>
<id>urn:sha1:055c721d38a49ea37fe058f6259ed85bf89cdfec</id>
<content type='text'>
When a python session reads from a pipe, perf_session__new() and
perf_session__process_events() block waiting for data with the GIL held,
freezing any other python threads such as a TUI thread. Release the GIL
around both calls and acquire it with PyGILState_Ensure() in the tool and
call-return callbacks that invoke python.

Assisted-by: Antigravity:gemini-3.1-pro
Signed-off-by: Ian Rogers &lt;irogers@google.com&gt;
Signed-off-by: Arnaldo Carvalho de Melo &lt;acme@redhat.com&gt;
</content>
</entry>
<entry>
<title>perf python: Lazily resolve sample callchains</title>
<updated>2026-10-03T09:05:40Z</updated>
<author>
<name>Ian Rogers</name>
<email>irogers@google.com</email>
</author>
<published>2026-10-02T18:26:13Z</published>
<link rel='alternate' type='text/html' href='https://bastion.nosebs.vip/g/linux.git/commit/?id=09d0ea3517bb57b6fe315e2395a891d558fcdc42'/>
<id>urn:sha1:09d0ea3517bb57b6fe315e2395a891d558fcdc42</id>
<content type='text'>
Previously, pyrf_event__new() eagerly resolved the sample's address
location and callchain (including DWARF/FP unwinding and symbol lookup)
for every sample with a callchain, even when the Python callback never
accessed event.callchain (such as in ttimechart.py).

Move callchain resolution to pyrf_sample_event__get_callchain() so that
callchains are only unwound and resolved when event.callchain is
accessed, reusing the sample's cached pevent-&gt;al via
pyrf_sample_event__resolve_al().

Because process_events() borrows the event and sample during the
callback, callchains are never copied in the common case. Only when a
callback retains a reference to the event beyond its return
(Py_REFCNT(pyevent) &gt; 1), the callchain was not already resolved during
the callback, and the callchain is synthesized or LBR-merged (not backed
by event_copy) does pyrf_event__copy() allocate a copy of
sample-&gt;callchain.

Assisted-by: Antigravity:gemini-3.1-pro
Signed-off-by: Ian Rogers &lt;irogers@google.com&gt;
Tested-by: Arnaldo Carvalho de Melo &lt;acme@redhat.com&gt;
Signed-off-by: Arnaldo Carvalho de Melo &lt;acme@redhat.com&gt;
</content>
</entry>
<entry>
<title>perf python: Lazily copy events and samples from process_events</title>
<updated>2026-10-03T09:00:32Z</updated>
<author>
<name>Ian Rogers</name>
<email>irogers@google.com</email>
</author>
<published>2026-10-02T18:26:12Z</published>
<link rel='alternate' type='text/html' href='https://bastion.nosebs.vip/g/linux.git/commit/?id=2c672ffdad4bc79e49c2187bcbe43a428a440889'/>
<id>urn:sha1:2c672ffdad4bc79e49c2187bcbe43a428a440889</id>
<content type='text'>
When perf.session.process_events() delivers an event to a Python
callback, pyrf_event__new() previously copied the raw perf_event into a
4,160-byte union perf_event embedded in struct pyrf_event and called
evsel__parse_sample() a second time to re-parse the sample against the
copied buffer.

In the common case, the Python callback inspects the event and returns
without storing a reference to it. Avoid the event memcpy, the duplicate
evsel__parse_sample() call, and the large PyObject allocation by:
1. Storing pointers to the underlying union perf_event and
   struct perf_sample in struct pyrf_event (using PyGetSetDef descriptors
   backed by PyMember_GetOne() to read fields through those pointers),
   shrinking struct pyrf_event so it fits in CPython's small-object
   allocator pool.
2. Borrowing the event and pre-parsed sample pointers from
   process_events() for the duration of the Python callback.
3. Checking Py_REFCNT(pyevent) &gt; 1 after the callback returns and only
   allocating event_copy and re-parsing into sample_storage when the
   Python callback retained a reference to the event object (or immediately
   in pyrf_evlist__read_on_cpu() where no pre-parsed sample is passed).

Assisted-by: Antigravity:gemini-3.1-pro
Signed-off-by: Ian Rogers &lt;irogers@google.com&gt;
Tested-by: Arnaldo Carvalho de Melo &lt;acme@redhat.com&gt;
Signed-off-by: Arnaldo Carvalho de Melo &lt;acme@redhat.com&gt;
</content>
</entry>
<entry>
<title>perf python: Quietly stop processing events when a callback raises</title>
<updated>2026-10-03T09:00:22Z</updated>
<author>
<name>Ian Rogers</name>
<email>irogers@google.com</email>
</author>
<published>2026-10-02T18:26:11Z</published>
<link rel='alternate' type='text/html' href='https://bastion.nosebs.vip/g/linux.git/commit/?id=d1ec67bdf540a56df22a52ef000e1347535dc1a1'/>
<id>urn:sha1:d1ec67bdf540a56df22a52ef000e1347535dc1a1</id>
<content type='text'>
When a session callback raises a python exception the callback returned
-1 causing reader__read_event() to print a "processing failed for event
of type: ..." error. This is redundant with the python exception that is
raised from process_events(), and corrupts the display of a TUI that
raises from a callback to deliberately stop processing, such as when
cancelling a background load.

Instead set session_done so that processing stops and return success,
the pending exception is then raised by process_events(). As a single
event may still cause further callbacks, for example multiple
call_return callbacks followed by a sample callback, skip calling python
while an exception is pending.

The session whose callback raised resets session_done after processing
so later sessions process all their events. As session_done is a global,
a session processed concurrently in another thread may be stopped early
too. Count the stop requests so that such a session raises an error
rather than silently dropping events.

Assisted-by: Antigravity:gemini-3.1-pro
Signed-off-by: Ian Rogers &lt;irogers@google.com&gt;
Signed-off-by: Arnaldo Carvalho de Melo &lt;acme@redhat.com&gt;
</content>
</entry>
<entry>
<title>perf python: Initialize debug output on module load</title>
<updated>2026-09-29T18:53:27Z</updated>
<author>
<name>Ian Rogers</name>
<email>irogers@google.com</email>
</author>
<published>2026-09-29T06:58:38Z</published>
<link rel='alternate' type='text/html' href='https://bastion.nosebs.vip/g/linux.git/commit/?id=3d13b3f1f3a7cd33d1847a4b87c3198089b6c4a7'/>
<id>urn:sha1:3d13b3f1f3a7cd33d1847a4b87c3198089b6c4a7</id>
<content type='text'>
Unlike the perf binary's main(), PyInit_perf() does not call
perf_debug_setup(). As a result, the first warning or error printed from
the perf Python C extension hits debug_file() with _debug_file == NULL
and emits 'debug_file not set' without a trailing newline before the
actual diagnostic message.

Call perf_debug_setup() in PyInit_perf() and add the missing trailing
newline to the fallback warning in debug_file().

Fixes: ec49230cf6dda704 ("perf debug: Expose debug file")
Assisted-by: Antigravity:gemini-3.1-pro
Signed-off-by: Ian Rogers &lt;irogers@google.com&gt;
Signed-off-by: Arnaldo Carvalho de Melo &lt;acme@redhat.com&gt;
</content>
</entry>
<entry>
<title>perf python: Add Intel PT call_return and itrace capability</title>
<updated>2026-09-26T18:49:27Z</updated>
<author>
<name>Ian Rogers</name>
<email>irogers@google.com</email>
</author>
<published>2026-09-26T06:19:36Z</published>
<link rel='alternate' type='text/html' href='https://bastion.nosebs.vip/g/linux.git/commit/?id=f66944587d18a84504d9c9782295944fbd29036f'/>
<id>urn:sha1:f66944587d18a84504d9c9782295944fbd29036f</id>
<content type='text'>
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, populating
  frame-&gt;map and frame-&gt;sym so call_path entries expose resolved symbol
  and DSO names).
- 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().

Assisted-by: Antigravity:gemini-3.1-pro
Signed-off-by: Ian Rogers &lt;irogers@google.com&gt;
Signed-off-by: Arnaldo Carvalho de Melo &lt;acme@redhat.com&gt;
</content>
</entry>
<entry>
<title>perf python: Expose addr location, transaction, and context_switch</title>
<updated>2026-09-26T18:49:27Z</updated>
<author>
<name>Ian Rogers</name>
<email>irogers@google.com</email>
</author>
<published>2026-09-26T06:19:35Z</published>
<link rel='alternate' type='text/html' href='https://bastion.nosebs.vip/g/linux.git/commit/?id=7a481f6c712a1505f67b97add508bb9d393c9d22'/>
<id>urn:sha1:7a481f6c712a1505f67b97add508bb9d393c9d22</id>
<content type='text'>
Expose destination address location components (addr_dso, addr_symbol,
addr_sym_offset), branch/transaction metrics (branch_type, in_tx,
flags, transaction), machine_pid, vcpu, sym_offset, and context_switch
callbacks directly to the Python extension.

Also include supporting fixes and infrastructure updates in
util/python.c and perf.pyi:
- Support fetching sym_offset on resolved sample symbols.
- Populate sample machine_pid and vcpu from evlist__id2sid() when
  perf_guest is enabled, and resolve samples against the matching guest
  or host machine.
- Expose next_prev_pid and next_prev_tid on switch_event only for
  PERF_RECORD_SWITCH_CPU_WIDE records (returning None otherwise).
- Wire up tracing_data in pyrf_session__new() and update perf.pyi type
  stubs (including srccode() and insn() return types).

Assisted-by: Antigravity:gemini-3.1-pro
Signed-off-by: Ian Rogers &lt;irogers@google.com&gt;
Signed-off-by: Arnaldo Carvalho de Melo &lt;acme@redhat.com&gt;
</content>
</entry>
<entry>
<title>perf python: Update callchain stubs and session thread lookup</title>
<updated>2026-09-26T18:49:27Z</updated>
<author>
<name>Ian Rogers</name>
<email>irogers@google.com</email>
</author>
<published>2026-09-26T06:19:29Z</published>
<link rel='alternate' type='text/html' href='https://bastion.nosebs.vip/g/linux.git/commit/?id=514ecdfd0073686e2a61681fe6f9e08870d9a89a'/>
<id>urn:sha1:514ecdfd0073686e2a61681fe6f9e08870d9a89a</id>
<content type='text'>
Update pyrf_session__find_thread() in util/python.c to accept an
optional tid parameter (defaulting to pid) and return None instead of
raising TypeError when a thread is not found in the session machines.

Update perf.pyi to match:
- Set session.find_thread() signature to (pid: int, tid: int = -1) -&gt;
  Optional[thread].
- Update callchain_node.symbol and callchain_node.dso to str (the C
  getters return "[unknown]" fallback strings rather than None) and add
  __iter__() to callchain.

Also update treport.py to handle Optional[thread] returned by
session.find_thread().

Assisted-by: Antigravity:gemini-3.1-pro
Signed-off-by: Ian Rogers &lt;irogers@google.com&gt;
Signed-off-by: Arnaldo Carvalho de Melo &lt;acme@redhat.com&gt;
</content>
</entry>
<entry>
<title>perf python: Update syscall helpers and expose arch_strerrno</title>
<updated>2026-09-26T18:49:27Z</updated>
<author>
<name>Ian Rogers</name>
<email>irogers@google.com</email>
</author>
<published>2026-09-26T06:19:28Z</published>
<link rel='alternate' type='text/html' href='https://bastion.nosebs.vip/g/linux.git/commit/?id=c4925cc8b8b1647b3cf9a9d8e84ac4c9f1e962c5'/>
<id>urn:sha1:c4925cc8b8b1647b3cf9a9d8e84ac4c9f1e962c5</id>
<content type='text'>
Update the PyArg_ParseTupleAndKeywords format string for
pyrf__syscall_name() and pyrf__syscall_id() from "i|$i" to "i|i" (and
"s|$i" to "s|i"), allowing elf_machine to be passed as an optional
positional argument as well as a keyword argument. Update syscall_id()
and syscall_name() in perf.pyi to match, and set the return type of
syscall_name() to Optional[str] as unknown syscall numbers return None.

Also expose perf_env__arch_strerrno() as perf.arch_strerrno(err,
elf_machine=None) so standalone Python scripts can resolve
architecture-specific errno names directly from the auto-generated
trace beauty tables instead of maintaining duplicate errno dictionaries
in Python. Tighten the macro pattern in arch_errno_names.sh to
E[A-Z0-9]+ so compiler -D flags containing underscores (such as LLVM's
-DEXPERIMENTAL_KEY_INSTRUCTIONS=1) do not shadow EPERM (1), and add
EM_SPARC32PLUS alongside EM_SPARC and EM_SPARCV9.

Assisted-by: Antigravity:gemini-3.1-pro
Signed-off-by: Ian Rogers &lt;irogers@google.com&gt;
Signed-off-by: Arnaldo Carvalho de Melo &lt;acme@redhat.com&gt;
</content>
</entry>
</feed>
