Skip to content

Commit 373de77

Browse files
d-e-s-odanielocfb
authored andcommitted
Add some trace logs to BPF programs using ringbuf
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 <[email protected]>
1 parent 6c3a615 commit 373de77

18 files changed

+42
-21
lines changed

libbpf-rs/tests/bin/ksyscall.bpf.o

632 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

libbpf-rs/tests/bin/mapiter.bpf.o

163 KB
Binary file not shown.

libbpf-rs/tests/bin/percpu_map.bpf.o

-248 Bytes
Binary file not shown.

libbpf-rs/tests/bin/ringbuf.bpf.o

-288 Bytes
Binary file not shown.

libbpf-rs/tests/bin/run_prog.bpf.o

80 Bytes
Binary file not shown.

libbpf-rs/tests/bin/runqslower.bpf.o

162 KB
Binary file not shown.

libbpf-rs/tests/bin/src/ksyscall.bpf.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ int handle__ksyscall(pid_t pid, int sig) {
1313
int *value;
1414

1515
value = bpf_ringbuf_reserve(&ringbuf, sizeof(int), 0);
16-
if (value) {
17-
*value = 1;
18-
bpf_ringbuf_submit(value, 0);
16+
if (!value) {
17+
bpf_printk("handle__ksyscall: failed to reserve ring buffer space");
18+
return 1;
1919
}
2020

21+
*value = 1;
22+
bpf_ringbuf_submit(value, 0);
23+
bpf_printk("handle__ksyscall: submitted ringbuf value");
2124
return 0;
2225
}
2326

libbpf-rs/tests/bin/src/tracepoint.bpf.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ int handle__tracepoint(void *ctx)
1414
int *value;
1515

1616
value = bpf_ringbuf_reserve(&ringbuf, sizeof(int), 0);
17-
if (value) {
18-
*value = 1;
19-
bpf_ringbuf_submit(value, 0);
17+
if (!value) {
18+
bpf_printk("handle__tracepoint: failed to reserve ring buffer space");
19+
return 1;
2020
}
2121

22+
*value = 1;
23+
bpf_ringbuf_submit(value, 0);
24+
bpf_printk("handle__tracepoint: submitted ringbuf value");
2225
return 0;
2326
}
2427

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

3033
value = bpf_ringbuf_reserve(&ringbuf, sizeof(int), 0);
31-
if (value) {
32-
*value = bpf_get_attach_cookie(ctx);
33-
bpf_ringbuf_submit(value, 0);
34+
if (!value) {
35+
bpf_printk("handle__tracepoint_with_cookie: failed to reserve ring buffer space");
36+
return 1;
3437
}
3538

39+
*value = bpf_get_attach_cookie(ctx);
40+
bpf_printk("handle__tracepoint_with_cookie: cookie=%d", *value);
41+
bpf_ringbuf_submit(value, 0);
3642
return 0;
3743
}
3844

libbpf-rs/tests/bin/src/uprobe.bpf.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ int handle__uprobe(void *ctx)
1515
int *value;
1616

1717
value = bpf_ringbuf_reserve(&ringbuf, sizeof(int), 0);
18-
if (value) {
19-
*value = 1;
20-
bpf_ringbuf_submit(value, 0);
18+
if (!value) {
19+
bpf_printk("handle__uprobe: failed to reserve ring buffer space");
20+
return 1;
2121
}
2222

23+
*value = 1;
24+
bpf_ringbuf_submit(value, 0);
25+
bpf_printk("handle__uprobe: submitted ringbuf value");
2326
return 0;
2427
}
2528

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

3134
value = bpf_ringbuf_reserve(&ringbuf, sizeof(int), 0);
32-
if (value) {
33-
*value = bpf_get_attach_cookie(ctx);
34-
bpf_ringbuf_submit(value, 0);
35+
if (!value) {
36+
bpf_printk("handle__uprobe_with_cookie: failed to reserve ring buffer space");
37+
return 1;
3538
}
3639

40+
*value = bpf_get_attach_cookie(ctx);
41+
bpf_printk("handle__uprobe_with_cookie: cookie=%d", *value);
42+
bpf_ringbuf_submit(value, 0);
3743
return 0;
3844
}
3945

libbpf-rs/tests/bin/src/usdt.bpf.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ int handle__usdt(void *ctx)
1515
int *value;
1616

1717
value = bpf_ringbuf_reserve(&ringbuf, sizeof(int), 0);
18-
if (value) {
19-
*value = 1;
20-
bpf_ringbuf_submit(value, 0);
18+
if (!value) {
19+
bpf_printk("handle__usdt: failed to reserve ring buffer space");
20+
return 1;
2121
}
2222

23+
*value = 1;
24+
bpf_ringbuf_submit(value, 0);
25+
bpf_printk("handle__usdt: submitted ringbuf value");
2326
return 0;
2427
}
2528

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

3134
value = bpf_ringbuf_reserve(&ringbuf, sizeof(int), 0);
32-
if (value) {
33-
*value = bpf_usdt_cookie(ctx);
34-
bpf_ringbuf_submit(value, 0);
35+
if (!value) {
36+
bpf_printk("handle__usdt_with_cookie: failed to reserve ring buffer space");
37+
return 1;
3538
}
3639

40+
*value = bpf_usdt_cookie(ctx);
41+
bpf_printk("handle__usdt_with_cookie: cookie=%d", *value);
42+
bpf_ringbuf_submit(value, 0);
3743
return 0;
3844
}
3945

libbpf-rs/tests/bin/taskiter.bpf.o

4.99 KB
Binary file not shown.

libbpf-rs/tests/bin/tc-unit.bpf.o

232 Bytes
Binary file not shown.

libbpf-rs/tests/bin/tracepoint.bpf.o

2.19 KB
Binary file not shown.

libbpf-rs/tests/bin/uprobe.bpf.o

1.32 KB
Binary file not shown.

libbpf-rs/tests/bin/usdt.bpf.o

2.78 KB
Binary file not shown.
-264 Bytes
Binary file not shown.

libbpf-rs/tests/bin/xdp.bpf.o

-704 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)