Re: [PATCH bpf-next v2 10/11] bpftool: Add support for dumping streams

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

 



2025-05-23 18:18 UTC-0700 ~ Kumar Kartikeya Dwivedi <memxor@xxxxxxxxx>
> Add support for printing the BPF stream contents of a program in
> bpftool. The new bpftool prog tracelog command is extended to take
> stdout and stderr arguments, and then the prog specification.
> 
> The bpf_prog_stream_read() API added in previous patch is simply reused
> to grab data and then it is dumped to the respective file. The stdout
> data is sent to stdout, and stderr is printed to stderr.
> 
> Cc: Quentin Monnet <qmo@xxxxxxxxxx>
> Signed-off-by: Kumar Kartikeya Dwivedi <memxor@xxxxxxxxx>
> ---
>  .../bpftool/Documentation/bpftool-prog.rst    |  7 +++
>  tools/bpf/bpftool/bash-completion/bpftool     | 16 +++++-
>  tools/bpf/bpftool/prog.c                      | 50 ++++++++++++++++++-
>  3 files changed, 71 insertions(+), 2 deletions(-)
> 

> diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
> index f010295350be..3f31fbb8a99c 100644
> --- a/tools/bpf/bpftool/prog.c
> +++ b/tools/bpf/bpftool/prog.c
> @@ -1113,6 +1113,53 @@ static int do_detach(int argc, char **argv)
>  	return 0;
>  }
>  
> +enum prog_tracelog_mode {
> +	TRACE_STDOUT,
> +	TRACE_STDERR,
> +};


You could have TRACE_STDOUT = 1 and TRACE_STDERR = 2 in this enum, and
later do "stream_id = mode". This would avoid passing "1" or "2" inside
of the prog_tracelog_stream() function. Although thinking again, it's
maybe confusing to use the same enum for the mode and the stream_id?
Your call.


> +
> +static int
> +prog_tracelog_stream(int prog_fd, enum prog_tracelog_mode mode)
> +{
> +	FILE *file = mode == TRACE_STDOUT ? stdout : stderr;
> +	int stream_id = mode == TRACE_STDOUT ? 1 : 2;
> +	static char buf[512];


Why static?


> +	int ret;
> +
> +	ret = 0;
> +	do {
> +		ret = bpf_prog_stream_read(prog_fd, stream_id, buf, sizeof(buf));
> +		if (ret > 0) {
> +			fwrite(buf, sizeof(buf[0]), ret, file);
> +		}


Nit: No brackets needed around fwrite()

Otherwise looks good, thanks!

Quentin




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux