From: sashiko-bot@kernel.org
To: "Arnaldo Carvalho de Melo" <acme@kernel.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v11 8/9] perf scripts: Add perf-stuck, to tell where a running perf is stuck
Date: Sun, 04 Oct 2026 17:38:50 +0000 [thread overview]
Message-ID: <20261004173851.4F4E31F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20261004173000.2863935-9-acme@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] perf scripts: incorrect parsing of /proc/pid/stat starttime causes premature exit
--
commit aa0fa29f56caddf899075009e74dfa310ea7373b
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
perf scripts: Add perf-stuck, to tell where a running perf is stuck
This commit adds a new script to monitor a running process's progress and
identify if it is stuck in a loop. It samples the target process at a fixed
interval and optionally invokes gdb when no progress is observed, verifying
process identity using the start time from the stat file.
> diff --git a/tools/perf/scripts/perf-stuck.sh b/tools/perf/scripts/perf-stuck.sh
> new file mode 100755
> index 0000000000000..57c979f6e58c5
> --- /dev/null
> +++ b/tools/perf/scripts/perf-stuck.sh
[ ... ]
> +# Its start time, in clock ticks, pins the process instance: a PID can
> +# name a different process later, samples or gdb would land on it.
> +pid_ticks=$(awk '{print $22}' /proc/"$pid"/stat)
[Severity: Medium]
In tools/perf/scripts/perf-stuck.sh, will this correctly parse the starttime
if the process name contains spaces? Because awk splits fields by whitespace,
spaces inside the parentheses of the comm field will shift the remaining
fields. If the name contains spaces, capturing field 22 might read volatile
metrics like num_threads or stime instead of the process starttime.
> +
> +echo "watching $pid ($cmdline) every ${interval}s"
> +
> +while :; do
> + # The PID may name some other process by now, if the watched one
> + # exited and its PID was recycled, e.g. within one interval:
> + # checking existence alone is not enough, samples or gdb would
> + # land on the stranger.
> + if [ "$(awk '{print $22}' /proc/"$pid"/stat 2>/dev/null)" != "$pid_ticks" ]; then
[Severity: Medium]
Could this cause the script to exit prematurely? Since the initial extraction
of pid_ticks above might capture a volatile metric when the comm field
contains spaces, this check might trigger when that metric dynamically
updates, falsely detecting that the process has exited.
> + echo "$(date +%T) process gone"
> + break
> + fi
> +
> + # Field 2, the command name, is in parentheses and can contain
> + # spaces, so drop it together with the pid before splitting so the
> + # fields line up. %d keeps the CPU time out of scientific
> + # notation, that bash arithmetic can't parse past six digits.
> + if ! stat_line=$(awk '{ sub(/^[^ ]+ \(.*\) /, "");
> + printf "%s %d %d\n", $1, $12 + $13, $22 }' \
> + /proc/"$pid"/stat 2>/dev/null); then
[Severity: Medium]
This isn't a bug here, but since the comm field is correctly stripped of
spaces in this awk call to avoid shifting fields, could the same protective
logic be applied to the earlier awk commands extracting the starttime?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261004173000.2863935-1-acme@kernel.org?part=8
next prev parent reply other threads:[~2026-10-04 17:38 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-04 17:29 [PATCH v11 0/9] perf tools: Add progress diagnostics and a false-sharing workload Arnaldo Carvalho de Melo
2026-10-04 17:29 ` [PATCH v11 1/9] perf config: Move perf_config__set_variable() to util/config.c Arnaldo Carvalho de Melo
2026-10-04 17:44 ` sashiko-bot
2026-10-04 17:29 ` [PATCH v11 2/9] perf config: Make perf_etc_perfconfig() never return NULL Arnaldo Carvalho de Melo
2026-10-04 17:37 ` sashiko-bot
2026-10-04 17:29 ` [PATCH v11 3/9] perf mutex: Add DEFINE_MUTEX() static initializer Arnaldo Carvalho de Melo
2026-10-04 17:35 ` sashiko-bot
2026-10-04 17:29 ` [PATCH v11 4/9] perf mutex: Add DO_ONCE() for one-time initialization Arnaldo Carvalho de Melo
2026-10-04 17:36 ` sashiko-bot
2026-10-04 17:29 ` [PATCH v11 5/9] perf config: Serialize config file access with a mutex Arnaldo Carvalho de Melo
2026-10-04 17:40 ` sashiko-bot
2026-10-04 17:29 ` [PATCH v11 6/9] perf report: Add --progress option Arnaldo Carvalho de Melo
2026-10-04 17:37 ` sashiko-bot
2026-10-04 17:29 ` [PATCH v11 7/9] perf report: Add --no-progress option Arnaldo Carvalho de Melo
2026-10-04 17:37 ` sashiko-bot
2026-10-04 17:29 ` [PATCH v11 8/9] perf scripts: Add perf-stuck, to tell where a running perf is stuck Arnaldo Carvalho de Melo
2026-10-04 17:38 ` sashiko-bot [this message]
2026-10-04 17:30 ` [PATCH v11 9/9] perf test: Add false_sharing workload exhibiting cross-CPU false sharing Arnaldo Carvalho de Melo
2026-10-04 17:36 ` 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=20261004173851.4F4E31F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=acme@kernel.org \
--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