Re: [PATCH bpf-next v2 3/3] bpftool: Display cookie for raw_tp link probe

From: Quentin Monnet
Date: Tue Jun 03 2025 - 05:37:01 EST


On 03/06/2025 03:26, Tao Chen wrote:
> Display cookie for raw_tp link probe, in plain mode:
>
> #bpftool link
>
> 22: raw_tracepoint prog 14
> tp 'sys_enter' cookie 23925373020405760
> pids test_progs(176)
>
> And in json mode:
>
> #bpftool link -j | jq
>
> [
> {
> "id": 47,
> "type": "raw_tracepoint",
> "prog_id": 79,
> "tp_name": "sys_enter",
> "cookie": 23925373020405760,
> "pids": [
> {
> "pid": 274,
> "comm": "test_progs"
> }
> ]
> }
> ]
>
> Signed-off-by: Tao Chen <chen.dylane@xxxxxxxxx>
> ---
> tools/bpf/bpftool/link.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/tools/bpf/bpftool/link.c b/tools/bpf/bpftool/link.c
> index 52fd2c9fac..bd37f364be 100644
> --- a/tools/bpf/bpftool/link.c
> +++ b/tools/bpf/bpftool/link.c
> @@ -484,6 +484,7 @@ static int show_link_close_json(int fd, struct bpf_link_info *info)
> case BPF_LINK_TYPE_RAW_TRACEPOINT:
> jsonw_string_field(json_wtr, "tp_name",
> u64_to_ptr(info->raw_tracepoint.tp_name));
> + jsonw_lluint_field(json_wtr, "cookie", info->raw_tracepoint.cookie);
> break;
> case BPF_LINK_TYPE_TRACING:
> err = get_prog_info(info->prog_id, &prog_info);
> @@ -876,6 +877,8 @@ static int show_link_close_plain(int fd, struct bpf_link_info *info)
> case BPF_LINK_TYPE_RAW_TRACEPOINT:
> printf("\n\ttp '%s' ",


Nit: See how we use a double space at the end of the string here, to
separate the different fields in the plain output...


> (const char *)u64_to_ptr(info->raw_tracepoint.tp_name));
> + if (info->raw_tracepoint.cookie)
> + printf("cookie %llu ", info->raw_tracepoint.cookie);


... Please use a double space here in a similar way, at the end of your
"cookie %llu " format string.

Looks good otherwise. Thanks,
Quentin