Skip to contentSkip to conversation

bpftool: Flush tracelog output

PATCH In review Paul Chaignon 2 participants 3 messages Dec 17, 2021 – Dec 20, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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.

Fixes 30da46b5dc3a ("tools: bpftool: add a command to dump the trace pipe")

---
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
index e80a5c79b38f..b310229abb07 100644
@@ -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
#1 lore raw
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_pipe file.

Fixes 30da46b5dc3a ("tools: bpftool: add a command to dump the trace pipe")

---
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
index e80a5c79b38f..b310229abb07 100644

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

#2 lore raw
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_pipe file.

Fixes 30da46b5dc3a ("tools: bpftool: add a command to dump the trace pipe")

---
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
index e80a5c79b38f..b310229abb07 100644

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

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