Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v2 1/2] perf python: New treport script
Date: Sat, 08 Aug 2026 07:13:03 +0000	[thread overview]
Message-ID: <20260808071303.A489E1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260808065743.2328212-2-irogers@google.com>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] The script uses multiple undefined attributes and methods from the `perf` Python module, guaranteeing an immediate crash.
- [Low] Unconditional import of the third-party `textual` package will cause a raw `ModuleNotFoundError` stack trace if it is not installed.
- [Low] Extracting the event name via hardcoded string slicing on the string representation of an object is extremely brittle.
- [Low] The commit message demonstrates usage with a path that does not match the actual location of the script.
--

--- Patch [1]: [PATCH v2 1/2] perf python: New treport script ---
commit c8886e7317972e7aa7d9b4370a2487dc827a9013
Author: Alice Rogers <alice.mei.rogers@gmail.com>

perf python: New treport script

This commit introduces a new textual-based application, treport.py, which
displays the results of perf sample processing in an interactive tree format.

> With perf script treport:
> 
> $ perf record -e cycles:u -g perf test -w brstack
> [ perf record: Woken up 1 times to write data ]
> [ perf record: Captured and wrote 0.008 MB perf.data (57 samples) ]
> $ perf script tools/perf/scripts/python/treport.py

[Severity: Low]
This isn't a bug, but the commit message demonstrates usage with
tools/perf/scripts/python/treport.py, while the patch creates the file
at tools/perf/python/treport.py. Could this cause confusion for users
trying to copy and paste the command?

> diff --git a/tools/perf/python/treport.py b/tools/perf/python/treport.py
> new file mode 100755
> index 0000000000000..528a640e4d356
> --- /dev/null
> +++ b/tools/perf/python/treport.py
> @@ -0,0 +1,207 @@
> +#!/usr/bin/env python3
> +# SPDX-License-Identifier: MIT
> +"""treport.py - perf report like tool written using textual."""
> +from typing import Dict, Optional
> +import argparse
> +import os
> +import sys
> +import perf
> +from textual.app import App, ComposeResult

[Severity: Low]
Would it be helpful to catch the ImportError for the textual module and print
a user-friendly instruction to install it? Currently, users without this
third-party dependency installed will hit a raw ModuleNotFoundError stack
trace.

[ ... ]

> +class ProfileBuilder:
> +    """Constructs a profile tree from a stream of events."""
> +    def __init__(self):
> +        self.root = ProfileNode("root", parent=None)
> +
> +    def process_event(self, sample) -> None:
> +        """Called by session.process_events to update the profile tree."""
> +        ev_name = str(sample.evsel)[6:-1]

[Severity: High]
Does the perf Python C extension currently expose the evsel attribute on
sample objects? It appears this might raise an AttributeError at runtime
since sample.evsel doesn't seem to be implemented in tools/perf/util/python.c.

[Severity: Low]
Also, is it safe to rely on hardcoded string slicing [6:-1] here? If the
string representation format of the event changes slightly, could this rigid
slicing fail to correctly isolate the event name?

> +        ev_root = self.root.find_or_create_node(ev_name)
> +        ev_root.process_event(sample)

[ ... ]

> +    input_file = args.input or "perf.data"
> +    if not os.path.exists(input_file):
> +        print(f"Error: {input_file} not found. (try 'perf record' first)", file=sys.stderr)
> +        sys.exit(1)
> +
> +    profile = ProfileBuilder()
> +    try:
> +        session = perf.session(perf.data(input_file), sample=profile.process_event)

[Severity: High]
Are perf.session() and perf.data() supported in the current python API?
Looking at the existing perf python bindings, it doesn't appear these
methods are implemented. Will this unconditionally crash with an
AttributeError when executed?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260808065743.2328212-1-irogers@google.com?part=1

  reply	other threads:[~2026-08-08  7:13 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-25  8:24 [PATCH v1 1/2] perf script: New treport script Ian Rogers
2025-07-25  8:24 ` [PATCH v1 2/2] perf script: treport add flamegraph support Ian Rogers
2025-07-25  8:38   ` Ian Rogers
2026-08-08  6:57     ` [PATCH v2 0/2] perf python TUI report and flamegraph Ian Rogers
2026-08-08  6:57       ` [PATCH v2 1/2] perf python: New treport script Ian Rogers
2026-08-08  7:13         ` sashiko-bot [this message]
2026-08-08  6:57       ` [PATCH v2 2/2] perf python: treport add flamegraph support Ian Rogers
2026-08-09  4:16       ` [PATCH v3 0/2] perf python TUI report and flamegraph Ian Rogers
2026-08-09  4:16         ` [PATCH v3 1/2] perf python: New treport script Ian Rogers
2026-08-09  4:29           ` sashiko-bot
2026-08-09  4:16         ` [PATCH v3] perf test: Fixes for check branch stack sampling Ian Rogers
2026-08-09  5:21           ` Ian Rogers
2026-08-09  4:16         ` [PATCH v3 2/2] perf python: treport add flamegraph support Ian Rogers
2026-08-09  4:36           ` sashiko-bot
2026-08-09  5:18         ` [PATCH v4 0/2] perf python TUI report and flamegraph Ian Rogers
2026-08-09  5:18           ` [PATCH v4 1/2] perf python: New treport script Ian Rogers
2026-08-09  5:18           ` [PATCH v4 2/2] perf python: treport add flamegraph support Ian Rogers
2025-07-26  6:43   ` [PATCH v1 2/2] perf script: " Namhyung Kim
2025-07-26  6:39 ` [PATCH v1 1/2] perf script: New treport script Namhyung Kim

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=20260808071303.A489E1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=irogers@google.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