[PATCH] trace-cmd stat: Show all filter functions that are enabled

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Steven Rostedt (Google)" <rostedt@xxxxxxxxxxx>

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@xxxxxxxxxxx>
---
 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




[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux