Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
janetat opened this issue Jun 27, 2024 · 1 comment
Open

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

janetat opened this issue Jun 27, 2024 · 1 comment

Comments

@janetat
Copy link

janetat commented Jun 27, 2024

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
Copy link
Contributor

We haven't provide such tools yet. You may write a program that links against bpftime and call APIs like

// use from bpf syscall to get the next key
to dump maps.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants