Skip to content

support for BPF_MAP_TYPE_STACK_TRACE #692

Answered by thediveo
liyan-ah asked this question in Q&A
Discussion options

You must be logged in to vote

Okay, got it working for me now, so here's an outline of how to use BPF_MAP_TYPE_STACK_TRACE, for the benefit of others coming to this question.

ebpf kernel space

Define a map of type BPF_MAP_TYPE_STACK_TRACE, with the key being a u32 we later get from bpf_get_stackid(), and the value being a fixed-size array of u64 (the instruction pointers, or "ips"):

typedef u64 stack[100];

struct {
    __uint(type, BPF_MAP_TYPE_STACK_TRACE);
    __type(key, u32);
    __type(value, stack);
    __uint(max_entries, 1 << 14);
} stacks SEC(".maps");

You'll probably want to have some BPF_MAP_TYPE_RINGBUF for sending events to user space with some event-specific data and including a u32 as the stack ID/key …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ti-mo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants