bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf v2] bpftool: Flush tracelog output
@ 2021-12-17 14:11 Paul Chaignon
  2021-12-17 16:51 ` Andrii Nakryiko
  0 siblings, 1 reply; 3+ messages in thread
From: Paul Chaignon @ 2021-12-17 14:11 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko; +Cc: bpf, Quentin Monnet

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")
Signed-off-by: Quentin Monnet <quentin@isovalent.com>
Signed-off-by: Paul Chaignon <paul@isovalent.com>
---
Changes in v2:
  - Resending to fix a format error.

 tools/bpf/bpftool/tracelog.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/bpf/bpftool/tracelog.c b/tools/bpf/bpftool/tracelog.c
index e80a5c79b38f..b310229abb07 100644
--- a/tools/bpf/bpftool/tracelog.c
+++ b/tools/bpf/bpftool/tracelog.c
@@ -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);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf v2] bpftool: Flush tracelog output
  2021-12-17 14:11 [PATCH bpf v2] bpftool: Flush tracelog output Paul Chaignon
@ 2021-12-17 16:51 ` Andrii Nakryiko
  2021-12-20 21:48   ` Paul Chaignon
  0 siblings, 1 reply; 3+ messages in thread
From: Andrii Nakryiko @ 2021-12-17 16:51 UTC (permalink / raw)
  To: Paul Chaignon
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, bpf,
	Quentin Monnet

On Fri, Dec 17, 2021 at 6:11 AM Paul Chaignon <paul@isovalent.com> wrote:
>
> 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")
> Signed-off-by: Quentin Monnet <quentin@isovalent.com>
> Signed-off-by: Paul Chaignon <paul@isovalent.com>
> ---
> Changes in v2:
>   - Resending to fix a format error.
>
>  tools/bpf/bpftool/tracelog.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/tools/bpf/bpftool/tracelog.c b/tools/bpf/bpftool/tracelog.c
> index e80a5c79b38f..b310229abb07 100644
> --- a/tools/bpf/bpftool/tracelog.c
> +++ b/tools/bpf/bpftool/tracelog.c
> @@ -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?


>         }
>
>         fclose(trace_pipe_fd);
> --
> 2.25.1
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf v2] bpftool: Flush tracelog output
  2021-12-17 16:51 ` Andrii Nakryiko
@ 2021-12-20 21:48   ` Paul Chaignon
  0 siblings, 0 replies; 3+ messages in thread
From: Paul Chaignon @ 2021-12-20 21:48 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, bpf,
	Quentin Monnet

On Fri, Dec 17, 2021 at 08:51:01AM -0800, Andrii Nakryiko wrote:
> On Fri, Dec 17, 2021 at 6:11 AM Paul Chaignon <paul@isovalent.com> wrote:
> >
> > 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")
> > Signed-off-by: Quentin Monnet <quentin@isovalent.com>
> > Signed-off-by: Paul Chaignon <paul@isovalent.com>
> > ---
> > Changes in v2:
> >   - Resending to fix a format error.
> >
> >  tools/bpf/bpftool/tracelog.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/tools/bpf/bpftool/tracelog.c b/tools/bpf/bpftool/tracelog.c
> > index e80a5c79b38f..b310229abb07 100644
> > --- a/tools/bpf/bpftool/tracelog.c
> > +++ b/tools/bpf/bpftool/tracelog.c
> > @@ -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?

Makes sense. I've sent a v3 at
https://lore.kernel.org/bpf/20211220214528.GA11706@Mem/T/.

> 
> 
> >         }
> >
> >         fclose(trace_pipe_fd);
> > --
> > 2.25.1
> >

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-12-20 21:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-17 14:11 [PATCH bpf v2] bpftool: Flush tracelog output Paul Chaignon
2021-12-17 16:51 ` Andrii Nakryiko
2021-12-20 21:48   ` Paul Chaignon

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).