libbpf-bootstrap
libbpf-bootstrap copied to clipboard
Compiling profile files in libbpf-bootstrap/examples/c/
Hi,
I like to see the stacktrace using ebpf. I see some example code under profile.c file under libbpf-bootstrap/examples/c. But it's not included in the Makefile. What is the reason for it? I tried to include them. But including it caused blaze library is not linked. Is blaze part of your docker or has to be built?
Thanks, Deepak
Did you check the Makefile? The program is very much part of the build process, but you need a Rust toolchain installed.
https://github.com/libbpf/libbpf-bootstrap/blob/2dffae1fca82fd9ef4ba15df67606cbfd2eb5412/examples/c/Makefile#L30-L38
For Docker specifically, I am not really familiar with the infra we have there. It's possible that the container does not come with a Rust toolchain and so it would suffer from the aforementioned problem. Feel free to open a pull request if you have a fix.
With installing rustc and cargo in my ubuntu docker, I'm able to build and run profile program now.
Followint are the steps. curl https://sh.rustup.rs -sSf | sh -s -- -y PATH="/root/.cargo/bin:${PATH}" cargo --version && rustc --version cargo build --release <--- From blazesym directory.
But I got following error when executed profile. Are there any limitation in doing perf from docker. I'm running in a mac system?
root@c1da7c025d63:/src/libbpf-bootstrap/build# ./profile Fail to set up performance monitor on a CPU/Core err: No such file or directory fd: -1 cpu: 0
In file profile.c, of libbpf-bootstrap, I get this error while calling perf_event_open.
for (cpu = 0; cpu < num_cpus; cpu++) {
/* skip offline/not present CPUs */
if (cpu >= num_online_cpus || !online_mask[cpu])
continue;
/* Set up performance monitoring on a CPU/Core */
pefd = perf_event_open(&attr, pid, cpu, -1, PERF_FLAG_FD_CLOEXEC);
if (pefd < 0) {
fprintf(stderr, "Fail to set up performance monitor on a CPU/Core err: %s fd: %d cpu: %d\n", strerror(errno), pefd, cpu);
fprintf(stderr, "Cpu cycles: %lld", attr.config);
err = -1;
goto cleanup;
}
Thanks, Deepak
I guess this has been solved as evidenced by the progress here. Can we close it?
Sure. I'll close it. Do you see value in adding a Docker file to run bpf into this repository so that, it's easy for users to do tinkering in libbpf without other head aches.
May be a good idea. Feel free to open a PR.