I am using the bpf_printk() helper to print to the kernel debug to trace some BPF programs. The usage is as follows:
#include <stdio.h>
#include <linux/bpf.h>
#include <sys/socket.h>
#include <bpf/bpf_helpers.h>
char LICENSE[] SEC("license") = "GPL";
SEC("sk_msg")
int http_state_machine(struct sk_msg_md *msg) {
long len = (long)msg->data_end - (long)msg->data;
if (len > 0) {
bpf_printk("Message length: %ld\n", len);
}
return SK_PASS;
}
Then I try to read the trace_pipe via sudo cat /sys/kernel/debug/tracing/trace_pipe > check.log. My goal is to read only the first few lines of the trace, instead of the entire trace. However, this takes a very long time (in the order of minutes) to move all the output into check.log.
I learnt from this answer, that the output of the trace_pipe is also the same in the static file /sys/kernel/debug/tracing/trace. And the trace file has nearly 10k lines.
My question is: How can I clear the entire output of the trace_pipe and/or trace - either by moving the entire output to a new file or discarding the output (after having read the first few lines)?