libbpf-bootstrap icon indicating copy to clipboard operation
libbpf-bootstrap copied to clipboard

Compiling profile files in libbpf-bootstrap/examples/c/

Open deepakpjose opened this issue 1 year ago • 3 comments

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

deepakpjose avatar Jun 09 '24 13:06 deepakpjose

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

danielocfb avatar Jun 10 '24 16:06 danielocfb

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.

danielocfb avatar Jun 14 '24 23:06 danielocfb

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

deepakpjose avatar Jun 22 '24 18:06 deepakpjose

I guess this has been solved as evidenced by the progress here. Can we close it?

d-e-s-o avatar Jul 17 '24 17:07 d-e-s-o

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.

deepakpjose avatar Jul 18 '24 03:07 deepakpjose

May be a good idea. Feel free to open a PR.

danielocfb avatar Jul 18 '24 15:07 danielocfb