bpftime icon indicating copy to clipboard operation
bpftime copied to clipboard

How to use bpftime as as a library rather than CLI ?

Open Yinwhe opened this issue 4 months ago • 4 comments

The current bpftime/example/libbpftime_example is very incomplete and only demonstrates basic shared memory operations. There's a lack of comprehensive examples showing how to use bpftime as a library rather than through the CLI tools.

Could you provide more complete library usage examples that demonstrate the full lifecycle of eBPF programs using bpftime APIs directly, similar to how the malloc example works but using library calls instead of CLI commands?

Yinwhe avatar Jul 17 '25 08:07 Yinwhe

Ok! We will add it.

yunwei37 avatar Jul 17 '25 09:07 yunwei37

by the way, maybe you can also look at https://github.com/eunomia-bpf/bpftime/tree/master/tools%2Fbpftimetool

yunwei37 avatar Jul 17 '25 10:07 yunwei37

by the way, maybe you can also look at https://github.com/eunomia-bpf/bpftime/tree/master/tools%2Fbpftimetool

Thank you for your response and for confirming that you'll add more comprehensive examples!

I also have a follow-up question regarding the usage of libbpftime.a: when using bpftime as a library, is it sufficient to link only the static library file (libbpftime.a), or are other compiled .so shared libraries also required?

Yinwhe avatar Jul 17 '25 11:07 Yinwhe

@yunwei37

I added a minimal “library mode” example (no CLI): https://github.com/Yinwhe/bpftime/tree/yinwhe/dev/example/bpftime-libhelper

Note:

  • This example works by intercepting sys_bpf and routing libbpf calls to bpftime’s userspace implementation; it does not directly use bpftime’s low-level runtime APIs.

Discussion:

  • Would a non-hijacking, non-libbpf example that uses the runtime/handler APIs directly (create program/map/link, run, read, teardown) be valuable?
  • If so, I can draft that example with concise docs and open a PR.

Yinwhe avatar Sep 14 '25 12:09 Yinwhe