Skip to content

Libbpf userspace function perf_buffer__new

0.6.0

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 of BPF_PERF_EVENT_ARRAY BPF map that will be used by BPF code to send data over to user-space
  • page_cnt: number of memory pages allocated for each per-CPU buffer
  • sample_cb: function called on each received data record
  • lost_cb: function called when record loss has occurred
  • ctx: user-provided extra context passed into sample_cb and lost_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

1.2.0

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