Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Shivani Nittor" <shivani@linux.ibm.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v2] perf scripts: Add configurable sorting option to powerpc-hcalls
Date: Wed, 17 Jun 2026 14:46:41 +0000	[thread overview]
Message-ID: <20260617144642.092BE1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260617144011.17359-1-shivani@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The `--sort` argument value is not validated, leading to silently ignored user intent and misleading output for invalid keys.
--

commit 1aa1f92efbcdcc2ec41737225787d40ac02abf40
Author: Shivani Nittor <shivani@linux.ibm.com>

perf scripts: Add configurable sorting option to powerpc-hcalls

The powerpc-hcalls.py script currently prints hypercall statistics in a
fixed sort order based on the number of hcall occurrences. This patch
adds a --sort option to runtime-configure the sort order (count, min, max, avg).

> diff --git a/tools/perf/scripts/python/powerpc-hcalls.py b/tools/perf/scripts/python/powerpc-hcalls.py
> index 8b78dc790adb1..e5b0c1bee65fb 100644
> --- a/tools/perf/scripts/python/powerpc-hcalls.py
> +++ b/tools/perf/scripts/python/powerpc-hcalls.py

[ ... ]

> @@ -158,10 +159,45 @@ def hcall_table_lookup(opcode):
>  
>  print_ptrn = '%-28s%10s%10s%10s%10s'
>  
> +def sort_output(opcode):
> +	stats = output[opcode]
> +
> +	if sort_key == 'min':
> +		return stats['min']
> +	if sort_key == 'max':
> +		return stats['max']
> +	if sort_key == 'avg':
> +		return stats['time'] // stats['cnt']
> +
> +	return stats['cnt']
> +
> +def trace_begin():
> +    global sort_key
> +
> +    i = 1
> +    while i < len(sys.argv):
> +        arg = sys.argv[i]
> +
> +        if arg == '-s' or arg == '--sort':
> +            if i + 1 >= len(sys.argv):
> +                print("Error: -s/--sort requires a sort key argument")
> +                sys.exit(1)
> +            sort_key = sys.argv[i + 1]
> +            i += 2
> +            continue
> +
> +        if arg.startswith('--sort='):
> +            sort_key = arg.split('=', 1)[1]
> +
> +        i += 1
> +
> +    print("SORT KEY =", sort_key)

[Severity: Medium]
Will this result in silently falling back to sorting by count if an invalid
sort key is provided?

If a user runs the script with an invalid sort option like --sort=latency,
trace_begin() will assign it to sort_key and print "SORT KEY = latency".

Then in sort_output(), it will fall through the conditionals and return
stats['cnt'], leaving the user with output sorted by count despite the
printed sort key.

Could we add validation for the sort_key argument to error out if it isn't
one of the expected values (count, min, max, avg)?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260617144011.17359-1-shivani@linux.ibm.com?part=1

      reply	other threads:[~2026-06-17 14:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-17 14:40 [PATCH v2] perf scripts: Add configurable sorting option to powerpc-hcalls Shivani Nittor
2026-06-17 14:46 ` sashiko-bot [this message]

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=20260617144642.092BE1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shivani@linux.ibm.com \
    /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