bpftool: Flush tracelog output
PATCH v2 1/1 bpftool: Flush tracelog output
The output of bpftool prog tracelog is currently buffered, which is inconvenient when piping the output into other commands. A simple tracelog | grep will typically not display anything. This patch fixes it by flushing the tracelog output after each line from the trace_pipe file.
---
Changes in v2:
- Resending to fix a format error.
tools/bpf/bpftool/tracelog.c | 1 + 1 file changed, 1 insertion(+)
tools/bpf/bpftool/tracelog.c +1 -0
@@ -158,6 +158,7 @@ int do_tracelog(int argc, char **argv)jsonw_string (json_wtr, buff); else printf("%s", buff); +fflush (stdout); }fclose (trace_pipe_fd);
Signature · 1 line
2.25.1
Quoted 21 lines · Paul Chaignon
The output of bpftool prog tracelog is currently buffered, which is inconvenient when piping the output into other commands. A simple tracelog | grep will typically not display anything. This patch fixes it by flushing the tracelog output after each line from the
trace_pipefile.Fixes 30da46b5dc3a ("tools: bpftool: add a command to dump the trace pipe")Signed-off-by Quentin Monnet <[email protected]>Signed-off-by Paul Chaignon <[email protected]>---
Changes in v2:
- Resending to fix a format error.tools/bpf/bpftool/tracelog.c | 1 + 1 file changed, 1 insertion(+)tools/bpf/bpftool/tracelog.c +0
-0
tools/bpf/bpftool/tracelog.c int do_tracelog(int argc, char **argv) · line 161
Quoted 4 lines
tools/bpf/bpftool/tracelog.c +1
-0@@ -158,6 +158,7 @@ int do_tracelog(int argc, char **argv)jsonw_string (json_wtr, buff); else printf("%s", buff); +fflush (stdout);
maybe it's better to
setlinebuf(stdout);
for the entire bpftool instead?
Quoted 6 lines
tools/bpf/bpftool/tracelog.c +0
-1}fclose (trace_pipe_fd); --2.25.1
Quoted 29 lines · Andrii Nakryiko
Quoted 21 lines · Paul Chaignon
The output of bpftool prog tracelog is currently buffered, which is inconvenient when piping the output into other commands. A simple tracelog | grep will typically not display anything. This patch fixes it by flushing the tracelog output after each line from the
trace_pipefile.Fixes 30da46b5dc3a ("tools: bpftool: add a command to dump the trace pipe")Signed-off-by Quentin Monnet <[email protected]>Signed-off-by Paul Chaignon <[email protected]>---
Changes in v2:
- Resending to fix a format error.tools/bpf/bpftool/tracelog.c | 1 + 1 file changed, 1 insertion(+)tools/bpf/bpftool/tracelog.c +0
-0tools/bpf/bpftool/tracelog.c int do_tracelog(int argc, char **argv) · line 161
Quoted 4 lines
tools/bpf/bpftool/tracelog.c +1
-0@@ -158,6 +158,7 @@ int do_tracelog(int argc, char **argv)jsonw_string (json_wtr, buff); else printf("%s", buff); +fflush (stdout);maybe it's better to
Quoted 3 lines
setlinebuf(stdout);
for the entire bpftool instead?
Makes sense. I've sent a v3 at
https://lore.kernel.org/bpf/20211220214528.GA11706@Mem/T/.
Quoted 8 lines
Quoted 8 lines
tools/bpf/bpftool/tracelog.c +0
-1}fclose (trace_pipe_fd); --2.25.1