A simple perf library to manage the perf ring buffer
This library provides a simple wrapping layer for the perf
mmap ring buffer. This allows to access perf events in
zero-copy from a user program.
perf_iter_init - Initialize iterator for perf ring buffer
void
perf_iter_init
(struct perf_iter * iter,
struct perf_fd * pfd)
Arguments
- iter
- Iterator to initialize.
- pfd
- perf_fd from perf_fd_open to use with the iterator.
Description
Needs to be called first to start walking a perf buffer.
perf_buffer_read - Access data in perf ring iterator.
struct perf_event_header *
perf_buffer_read
(struct perf_iter * iter,
void * buffer,
int bufsize)
Arguments
- iter
- Iterator to copy data from
- buffer
- Temporary buffer to use for wrapped events
- bufsize
- Size of buffer
Description
Return the next available perf_event_header in the ring buffer.
This normally does zero copy, but for wrapped events
they are copied into the temporary buffer supplied and a
pointer into that is returned.
Return
NULL when nothing available, otherwise perf_event_header.
perf_iter_continue - Allow the kernel to log over our data.
void
perf_iter_continue
(struct perf_iter * iter)
Arguments
- iter
- Iterator.
Tell the kernel we are finished with the data and it can
continue logging.
perf_fd_open - Open a perf event with ring buffer for the current thread
int
perf_fd_open
(struct perf_fd * p,
struct perf_event_attr * attr,
int buf_size_shift)
Arguments
- p
- perf_fd to initialize
- attr
- perf event attribute to use
- buf_size_shift
- log2 of buffer size.
Return
-1 on error, otherwise 0.
perf_fd_close - Close perf_fd
void
perf_fd_close
(struct perf_fd * p)
Arguments
- p
- pfd to close.
perf_enable - Start perf collection on pfd
int
perf_enable
(struct perf_fd * p)
Arguments
- p
- perf fd
Return
-1 for error, otherwise 0.
perf_disable - Stop perf collection on pfd
int
perf_disable
(struct perf_fd * p)
Arguments
- p
- perf fd
Return
-1 for error, otherwise 0.
mem_loads_event - Return precise mem load event for current CPU. This is an event which supports load address monitoring.
unsigned
mem_loads_event
( void)
Arguments
- void
- no arguments
Return
raw event, can be put int perf_event_attr->config.
-1 or error.
mem_stores_event - Return precise mem stores event for current CPU. This is an event which supports load address monitoring.
unsigned
mem_stores_event
( void)
Arguments
- void
- no arguments
Return
raw event, can be put int perf_event_attr->config.
-1 or error.