KFunc bpf_stream_vprintk
Write a message to a
Definition
Parameters
stream_id
: The ID of the stream to write to (BPF_STDOUT
(1), or BPF_STDERR
(2))
fmt__str
: Format string following the same formatting as bpf_trace_printk
args
: Pointer to an array of u64 argument values.
len_sz
: Number of elements in args
.
aux__prog
: Pseudo argument, any value passed in is ignored.
Returns
Signature
int bpf_stream_vprintk(int stream_id, const char *fmt__str, const void *args, u32 len__sz, void *aux__prog)
Usage
This kfunc allows programs to write formatted strings to streams, the API is made to resemble
These streams are intended for debugging, an alternative to bpf_trace_printk
and bpf_trace_vprintk
which write to a system wide trace log. These streams are per-program, thus making it easier to consume logs from a specific program instead of having to figure out which log message in the system wide log is produces my the program you are interested in.
bpftool can be used to inspect these streams with the following command: bpftool prog tracelog { stdout | stderr } *PROG*
The libbpf eBPF side library defines a helper macro bpf_stream_printk
which makes using this kfunc easier.
Program types
The following program types can make use of this kfunc:
BPF_PROG_TYPE_CGROUP_DEVICE
v6.12 -BPF_PROG_TYPE_CGROUP_SKB
BPF_PROG_TYPE_CGROUP_SOCK
v6.12 -BPF_PROG_TYPE_CGROUP_SOCKOPT
v6.12 -BPF_PROG_TYPE_CGROUP_SOCK_ADDR
v6.7 -BPF_PROG_TYPE_CGROUP_SYSCTL
v6.12 -BPF_PROG_TYPE_LSM
BPF_PROG_TYPE_LWT_IN
BPF_PROG_TYPE_LWT_OUT
BPF_PROG_TYPE_LWT_SEG6LOCAL
BPF_PROG_TYPE_LWT_XMIT
BPF_PROG_TYPE_NETFILTER
BPF_PROG_TYPE_PERF_EVENT
v6.12 -BPF_PROG_TYPE_SCHED_ACT
BPF_PROG_TYPE_SCHED_CLS
BPF_PROG_TYPE_SK_SKB
BPF_PROG_TYPE_SOCKET_FILTER
BPF_PROG_TYPE_SOCK_OPS
v6.15 -BPF_PROG_TYPE_STRUCT_OPS
BPF_PROG_TYPE_SYSCALL
BPF_PROG_TYPE_TRACEPOINT
v6.12 -BPF_PROG_TYPE_TRACING
BPF_PROG_TYPE_XDP
Example
Docs could be improved
This part of the docs is incomplete, contributions are very welcome