diff mbox series

[bpf,v2] bpftool: Flush tracelog output

Message ID 20211217141140.GA26351@Mem (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series [bpf,v2] bpftool: Flush tracelog output | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for bpf
netdev/fixes_present success Fixes tag present in non-next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers fail 1 blamed authors not CCed: kuba@kernel.org; 7 maintainers not CCed: netdev@vger.kernel.org kafai@fb.com songliubraving@fb.com john.fastabend@gmail.com kuba@kernel.org kpsingh@kernel.org yhs@fb.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 7 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-PR fail PR summary
bpf/vmtest-bpf fail VM_Test

Commit Message

Paul Chaignon Dec. 17, 2021, 2:11 p.m. UTC
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(+)

Comments

Andrii Nakryiko Dec. 17, 2021, 4:51 p.m. UTC | #1
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
>
Paul Chaignon Dec. 20, 2021, 9:48 p.m. UTC | #2
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
> >
diff mbox series

Patch

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