Libbpf userspace function perf_buffer__new
Creates BPF perf buffer manager for a specified BPF_PERF_EVENT_ARRAY
map.
Definition
typedef void (*perf_buffer_sample_fn)(void *ctx, int cpu, void *data, __u32 size);
typedef void (*perf_buffer_lost_fn)(void *ctx, int cpu, __u64 cnt);
struct perf_buffer * perf_buffer__new(int map_fd, size_t page_cnt, perf_buffer_sample_fn sample_cb, perf_buffer_lost_fn lost_cb, void *ctx, const struct perf_buffer_opts *opts);
Parameters
map_fd
: file descriptor ofBPF_PERF_EVENT_ARRAY
BPF map that will be used by BPF code to send data over to user-spacepage_cnt
: number of memory pages allocated for each per-CPU buffersample_cb
: function called on each received data recordlost_cb
: function called when record loss has occurredctx
: user-provided extra context passed intosample_cb
andlost_cb
opts
: options for the perf buffer
Return
A new instance of struct perf_buffer
on success, NULL
on error with errno
containing an error code.
struct perf_buffer_opts
struct perf_buffer_opts {
size_t sz;
__u32 sample_period;
size_t :0;
};
sample_period
By default the perf buffer becomes signaled for every event that is being pushed to it. When set, this is the amount of events that need to be pushed to the perf buffer before it becomes signaled.
Processing events in batches can be more efficient than processing them one by one.
Usage
Docs could be improved
This part of the docs is incomplete, contributions are very welcome
Example
Docs could be improved
This part of the docs is incomplete, contributions are very welcome