Skip to content

Commit

Permalink
Add some trace logs to BPF programs using ringbuf
Browse files Browse the repository at this point in the history
Add some trace logs to BPF programs using ringbuf to give anybody at
least a fighting chance to understand where issues are. Retrieve them
by reading /sys/kernel/debug/tracing/trace_pipe.

Signed-off-by: Daniel Müller <deso@posteo.net>
  • Loading branch information
d-e-s-o authored and danielocfb committed Jun 24, 2024
1 parent 6c3a615 commit 373de77
Show file tree
Hide file tree
Showing 18 changed files with 42 additions and 21 deletions.
Binary file modified libbpf-rs/tests/bin/ksyscall.bpf.o
Binary file not shown.
Binary file modified libbpf-rs/tests/bin/map_auto_pin.bpf.o
Binary file not shown.
Binary file modified libbpf-rs/tests/bin/mapiter.bpf.o
Binary file not shown.
Binary file modified libbpf-rs/tests/bin/percpu_map.bpf.o
Binary file not shown.
Binary file modified libbpf-rs/tests/bin/ringbuf.bpf.o
Binary file not shown.
Binary file modified libbpf-rs/tests/bin/run_prog.bpf.o
Binary file not shown.
Binary file modified libbpf-rs/tests/bin/runqslower.bpf.o
Binary file not shown.
9 changes: 6 additions & 3 deletions libbpf-rs/tests/bin/src/ksyscall.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ int handle__ksyscall(pid_t pid, int sig) {
int *value;

value = bpf_ringbuf_reserve(&ringbuf, sizeof(int), 0);
if (value) {
*value = 1;
bpf_ringbuf_submit(value, 0);
if (!value) {
bpf_printk("handle__ksyscall: failed to reserve ring buffer space");
return 1;
}

*value = 1;
bpf_ringbuf_submit(value, 0);
bpf_printk("handle__ksyscall: submitted ringbuf value");
return 0;
}

Expand Down
18 changes: 12 additions & 6 deletions libbpf-rs/tests/bin/src/tracepoint.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ int handle__tracepoint(void *ctx)
int *value;

value = bpf_ringbuf_reserve(&ringbuf, sizeof(int), 0);
if (value) {
*value = 1;
bpf_ringbuf_submit(value, 0);
if (!value) {
bpf_printk("handle__tracepoint: failed to reserve ring buffer space");
return 1;
}

*value = 1;
bpf_ringbuf_submit(value, 0);
bpf_printk("handle__tracepoint: submitted ringbuf value");
return 0;
}

Expand All @@ -28,11 +31,14 @@ int handle__tracepoint_with_cookie(void *ctx)
int *value;

value = bpf_ringbuf_reserve(&ringbuf, sizeof(int), 0);
if (value) {
*value = bpf_get_attach_cookie(ctx);
bpf_ringbuf_submit(value, 0);
if (!value) {
bpf_printk("handle__tracepoint_with_cookie: failed to reserve ring buffer space");
return 1;
}

*value = bpf_get_attach_cookie(ctx);
bpf_printk("handle__tracepoint_with_cookie: cookie=%d", *value);
bpf_ringbuf_submit(value, 0);
return 0;
}

Expand Down
18 changes: 12 additions & 6 deletions libbpf-rs/tests/bin/src/uprobe.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ int handle__uprobe(void *ctx)
int *value;

value = bpf_ringbuf_reserve(&ringbuf, sizeof(int), 0);
if (value) {
*value = 1;
bpf_ringbuf_submit(value, 0);
if (!value) {
bpf_printk("handle__uprobe: failed to reserve ring buffer space");
return 1;
}

*value = 1;
bpf_ringbuf_submit(value, 0);
bpf_printk("handle__uprobe: submitted ringbuf value");
return 0;
}

Expand All @@ -29,11 +32,14 @@ int handle__uprobe_with_cookie(void *ctx)
int *value;

value = bpf_ringbuf_reserve(&ringbuf, sizeof(int), 0);
if (value) {
*value = bpf_get_attach_cookie(ctx);
bpf_ringbuf_submit(value, 0);
if (!value) {
bpf_printk("handle__uprobe_with_cookie: failed to reserve ring buffer space");
return 1;
}

*value = bpf_get_attach_cookie(ctx);
bpf_printk("handle__uprobe_with_cookie: cookie=%d", *value);
bpf_ringbuf_submit(value, 0);
return 0;
}

Expand Down
18 changes: 12 additions & 6 deletions libbpf-rs/tests/bin/src/usdt.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ int handle__usdt(void *ctx)
int *value;

value = bpf_ringbuf_reserve(&ringbuf, sizeof(int), 0);
if (value) {
*value = 1;
bpf_ringbuf_submit(value, 0);
if (!value) {
bpf_printk("handle__usdt: failed to reserve ring buffer space");
return 1;
}

*value = 1;
bpf_ringbuf_submit(value, 0);
bpf_printk("handle__usdt: submitted ringbuf value");
return 0;
}

Expand All @@ -29,11 +32,14 @@ int handle__usdt_with_cookie(void *ctx)
int *value;

value = bpf_ringbuf_reserve(&ringbuf, sizeof(int), 0);
if (value) {
*value = bpf_usdt_cookie(ctx);
bpf_ringbuf_submit(value, 0);
if (!value) {
bpf_printk("handle__usdt_with_cookie: failed to reserve ring buffer space");
return 1;
}

*value = bpf_usdt_cookie(ctx);
bpf_printk("handle__usdt_with_cookie: cookie=%d", *value);
bpf_ringbuf_submit(value, 0);
return 0;
}

Expand Down
Binary file modified libbpf-rs/tests/bin/taskiter.bpf.o
Binary file not shown.
Binary file modified libbpf-rs/tests/bin/tc-unit.bpf.o
Binary file not shown.
Binary file modified libbpf-rs/tests/bin/tracepoint.bpf.o
Binary file not shown.
Binary file modified libbpf-rs/tests/bin/uprobe.bpf.o
Binary file not shown.
Binary file modified libbpf-rs/tests/bin/usdt.bpf.o
Binary file not shown.
Binary file modified libbpf-rs/tests/bin/user_ringbuf.bpf.o
Binary file not shown.
Binary file modified libbpf-rs/tests/bin/xdp.bpf.o
Binary file not shown.

0 comments on commit 373de77

Please sign in to comment.