All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Lalit Maganti" <lalitmaganti@gmail.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 3/4] perf python: Add perfetto script to open profiles in the Perfetto UI
Date: Sun, 15 Nov 2026 00:53:07 +0000	[thread overview]
Message-ID: <sashiko-outbox-215158@kernel.org> (raw)
In-Reply-To: <20261115003916.1873857-4-lalitmaganti@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] perf python: NO_ID sentinel mismatch in process_sample()
  causes ValueError
--

commit cffb2c3ec0bc0ef022e32f9177d74617f3f52e47
Author: Lalit Maganti <lalitmaganti@gmail.com>

perf python: Add perfetto script to open profiles in the Perfetto UI

This commit adds a Python script that converts samples in a perf.data file
to a Perfetto trace and serves it to the Perfetto UI, along with a shell
test for the conversion.

> diff --git a/tools/perf/python/perfetto.py b/tools/perf/python/perfetto.py
> new file mode 100755
> index 0000000000000..e168b146e5385
> --- /dev/null
> +++ b/tools/perf/python/perfetto.py
> @@ -0,0 +1,625 @@

[ ... ]

> +# perf reports these when the sample type lacks PERF_SAMPLE_CPU/TID/TIME.
> +NO_CPU = 0xffffffff
> +NO_ID = 0xffffffff
> +NO_TIME = 0xffffffffffffffff

[ ... ]

> +    def process_sample(self, sample: perf.sample_event) -> None:
> +        """Writes a perf sample as a StackSample packet."""
> +        if sample.sample_time == NO_TIME:
> +            self.nr_skipped += 1
> +            return
> +        self.nr_samples += 1
> +        event = str(sample.evsel)
> +        if event.startswith('evsel(') and event.endswith(')'):
> +            event = event[len('evsel('):-1]
> +        seq = self._sequence(event, sample.sample_time)
> +
> +        stack_sample = b''
> +        pid, tid = sample.sample_pid, sample.sample_tid
> +        if NO_ID not in (pid, tid):
> +            self._update_names(pid, tid)
> +            stack_sample += varint_field(StackSampleField.TASK_CONTEXT_IID, seq.task(pid, tid))

[Severity: Medium]
Does checking NO_ID (0xffffffff) against sample_pid and sample_tid miss
samples without a valid PID or TID and raise a ValueError in varint()?

Unlike sample_cpu (T_UINT), the C binding exposes sample_pid and
sample_tid as signed T_INT:

tools/perf/util/python.c:
	sample_member_def(sample_pid, pid, T_INT, "event pid"),			 \
	sample_member_def(sample_tid, tid, T_INT, "event tid"),			 \

When a sample is recorded without PERF_SAMPLE_TID or for a task with no
PID in the event namespace, sample_pid and sample_tid are -1 rather than
0xffffffff.  That passes the NO_ID check and reaches seq.task() ->
varint_field() -> varint(-1), where out.append(-1) raises ValueError and
aborts the trace conversion.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261115003916.1873857-1-lalitmaganti@gmail.com?part=3

  reply	other threads:[~2026-11-15  0:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-15  0:39 [PATCH 0/4] perf python: Add a script to open profiles in the Perfetto UI Lalit Maganti
2026-11-15  0:39 ` [PATCH 1/4] perf python: Add kernel attribute to callchain_node Lalit Maganti
2026-11-15  0:45   ` sashiko-bot
2026-11-15  0:39 ` [PATCH 2/4] perf python: Add clockid attribute to session Lalit Maganti
2026-11-15  0:44   ` sashiko-bot
2026-11-15  0:39 ` [PATCH 3/4] perf python: Add perfetto script to open profiles in the Perfetto UI Lalit Maganti
2026-11-15  0:53   ` sashiko-bot [this message]
2026-11-15  0:39 ` [PATCH 4/4] perf python: Compress the traces of the perfetto script Lalit Maganti
2026-11-15  0:45   ` 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-215158@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=lalitmaganti@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.