From: Steven Rostedt <rostedt@goodmis.org>
To: Linux Trace Devel <linux-trace-devel@vger.kernel.org>
Subject: [PATCH] trace-cmd stat: Show all filter functions that are enabled
Date: Tue, 7 Jun 2022 18:31:42 -0400 [thread overview]
Message-ID: <20220607183142.00dac63f@gandalf.local.home> (raw)
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
The way the files are printed in trace-cmd stat uses a read loop and keeps
allocating memory to read the content. It reads at BUFSIZ increments. But
if a read does not read exactly BUFSIZ it stops reading and returns what
it read but may not return the rest.
This does not work with the filter functions as the read may not fill the
buffer (it does not return an unfinished function). This makes the loop
exit early.
Instead just increase with BUFSIZ against what was allocated and comparing
to the total.
The way to trigger the issue is by:
# trace-cmd start -p nop -l "*"
# trace-cmd show --ftrace_filter |wc -l
50979
# trace-cmd stat | wc -l
234
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=212489
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
tracecmd/trace-stat.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/tracecmd/trace-stat.c b/tracecmd/trace-stat.c
index a5fb777b32b8..4c3dc6494922 100644
--- a/tracecmd/trace-stat.c
+++ b/tracecmd/trace-stat.c
@@ -71,21 +71,24 @@ char *append_file(const char *dir, const char *name)
static char *get_fd_content(int fd, const char *file)
{
+ size_t total = 0;
+ size_t alloc;
char *str = NULL;
- int cnt = 0;
int ret;
for (;;) {
- str = realloc(str, BUFSIZ * ++cnt);
+ alloc = ((total + BUFSIZ) / BUFSIZ) * BUFSIZ;
+ str = realloc(str, alloc + 1);
if (!str)
die("malloc");
- ret = read(fd, str + BUFSIZ * (cnt - 1), BUFSIZ);
+ ret = read(fd, str + total, alloc - total);
if (ret < 0)
die("reading %s\n", file);
- if (ret < BUFSIZ)
+ total += ret;
+ if (!ret)
break;
}
- str[BUFSIZ * (cnt-1) + ret] = 0;
+ str[total] = 0;
return str;
}
--
2.35.1
reply other threads:[~2022-06-08 1:18 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20220607183142.00dac63f@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=linux-trace-devel@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).