From: sashiko-bot@kernel.org
To: "Aaron Tomlin" <atomlin@atomlin.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH perf-tools-next v5 1/5] perf ftrace: Optimise __cmd_ftrace() stack frame with strbuf streaming
Date: Thu, 15 Oct 2026 01:20:15 +0000 [thread overview]
Message-ID: <sashiko-outbox-172085@kernel.org> (raw)
In-Reply-To: <20261015011155.414667-2-atomlin@atomlin.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] perf: missing explicit inclusion of <stdio.h> for POSIX stdio streams
--
commit 84dafb5e4aabd0b60e918d9f85e26ec8e27d5c88
Author: Aaron Tomlin <atomlin@atomlin.com>
perf ftrace: Optimise __cmd_ftrace() stack frame with strbuf streaming
This commit optimizes __cmd_ftrace() by replacing a fixed-size stack buffer
with heap allocation and a dynamic strbuf for trace data accumulation. It
also introduces error checking and stream flushing to improve robustness
during steady-state polling.
> diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
> index 6017493ff1797..6ee72ae90f67a 100644
> --- a/tools/perf/builtin-ftrace.c
> +++ b/tools/perf/builtin-ftrace.c
> @@ -41,7 +41,10 @@
> #include "util/units.h"
> #include "util/parse-sublevel-options.h"
>
> +#include "util/strbuf.h"
> +
[Severity: Low]
Does this file explicitly include <stdio.h>?
This isn't a runtime bug, but relying on implicit inclusion via other headers
for POSIX stdio streams and functions (like stdout, fprintf, fflush, and
ferror) violates the perf subsystem guidelines for musl compatibility.
Explicitly including <stdio.h> ensures the code doesn't cause build breakages
on libc implementations that strictly separate declarations, like musl.
[ ... ]
> @@ -806,24 +818,42 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace)
> }
>
> while (!done) {
> - if (poll(&pollfd, 1, -1) < 0)
> + if (poll(&pollfd, 1, -1) < 0) {
> + if (errno == EINTR)
> + continue;
> break;
> + }
>
> if (pollfd.revents & POLLIN) {
> - int n = read(trace_fd, buf, sizeof(buf));
> - if (n < 0)
> + int n = read(trace_fd, buf, TRACE_BUF_SIZE);
> +
> + if (n < 0) {
> + if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
> + continue;
> break;
> - if (fwrite(buf, n, 1, stdout) != 1)
> + }
> + if (n == 0)
> break;
> + for (int i = 0; i < n; i++) {
> + if (buf[i] == '\n') {
> + if (fprintf(stdout, "%s\n", linebuf.buf) < 0)
> + break;
> + strbuf_setlen(&linebuf, 0);
> + } else {
> + if (strbuf_addch(&linebuf, buf[i]) < 0)
> + goto out_close_fd;
> + }
> + }
> /* flush output since stdout is in full buffering mode due to pager */
> - fflush(stdout);
> + if (fflush(stdout) < 0 || ferror(stdout))
> + break;
> }
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261015011155.414667-1-atomlin@atomlin.com?part=1
next prev parent reply other threads:[~2026-10-15 1:20 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-15 1:11 [PATCH perf-tools-next v5 0/5] perf ftrace: Support inlined functions and display enhancements in function graph tracer Aaron Tomlin
2026-10-15 1:11 ` [PATCH perf-tools-next v5 1/5] perf ftrace: Optimise __cmd_ftrace() stack frame with strbuf streaming Aaron Tomlin
2026-10-15 1:20 ` sashiko-bot [this message]
2026-10-15 1:11 ` [PATCH perf-tools-next v5 2/5] perf ftrace: Support filtering return address comments Aaron Tomlin
2026-10-15 1:22 ` sashiko-bot
2026-10-15 1:11 ` [PATCH perf-tools-next v5 3/5] perf ftrace: Support display of inlined functions in function graph tracer Aaron Tomlin
2026-10-15 1:24 ` sashiko-bot
2026-10-15 1:11 ` [PATCH perf-tools-next v5 4/5] perf ftrace: Support omitting execution duration " Aaron Tomlin
2026-10-15 1:19 ` sashiko-bot
2026-10-15 1:11 ` [PATCH perf-tools-next v5 5/5] perf ftrace: Filter extraneous functions " Aaron Tomlin
2026-10-15 1:24 ` 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-172085@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=atomlin@atomlin.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.