eunomia-bpf / bpftime

Userspace eBPF runtime for Observability, Network & General Extensions Framework
https://eunomia.dev/bpftime/
MIT License
788 stars 74 forks source link

[QUESTION] How to dump user eBPF map? #307

Open janetat opened 3 months ago

janetat commented 3 months ago

Source Code

#define BPF_NO_GLOBAL_DATA
#include <vmlinux.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>

struct {
    __uint(type, BPF_MAP_TYPE_HASH);
    __uint(max_entries, 1024);
    __type(key, u32);
    __type(value, u64);
} libc_malloc_calls_total SEC(".maps");

SEC("uprobe/benchmark/test:__benchmark_test_function3")
int test_update(struct pt_regs *ctx)
{
    u32 key = 0;
    u64 value = 0;
    bpf_map_update_elem(&libc_malloc_calls_total, &key, &value, 0);

    return 0;
}

SEC("uprobe/benchmark/test:__benchmark_test_function2")
int test_delete(struct pt_regs *ctx)
{
    u32 key = 0;
    u64 value = 0;
    bpf_map_delete_elem(&libc_malloc_calls_total, &key);

    return 0;
}

SEC("uprobe/benchmark/test:__benchmark_test_function1")
int test_lookup(struct pt_regs *ctx)
{
    u32 key = 0;
    u64 value = 0;
    bpf_map_lookup_elem(&libc_malloc_calls_total, &key);

    return 0;
}

char LICENSE[] SEC("license") = "GPL";

Question

How to dump libc_malloc_calls_total maps when running this eBPF prog in user runtime?

Officeyutong commented 3 months ago

We haven't provide such tools yet. You may write a program that links against bpftime and call APIs like https://github.com/eunomia-bpf/bpftime/blob/88a79587639afd59103b88747940c6627a434cc4/runtime/include/bpftime_shm.hpp#L290 to dump maps.

See https://github.com/eunomia-bpf/bpftime/tree/master/example/libbpftime_example for how to use APIs of bpftime