libtraceevent(3)

# libtraceevent(3) Manual Page

## NAME

kbuffer_read_event, kbuffer_next_event, kbuffer_missed_events, kbuffer_event_size, kbuffer_curr_size, kbuffer_curr_offset, kbuffer_curr_index, kbuffer_read_buffer - Functions to read through the kbuffer sub buffer.

## SYNOPSIS

    #include <kbuffer.h>

    void *kbuffer_read_event(struct kbuffer *kbuf, unsigned long long *ts);
    void *kbuffer_next_event(struct kbuffer *kbuf, unsigned long long *ts);
    void *kbuffer_read_at_offset(struct kbuffer *kbuf, int offset, unsigned long long *ts);
    int kbuffer_missed_events(struct kbuffer *kbuf);
    int kbuffer_event_size(struct kbuffer *kbuf);
    int kbuffer_curr_size(struct kbuffer *kbuf);
    int kbuffer_curr_offset(struct kbuffer *kbuf);
    int kbuffer_curr_index(struct kbuffer *kbuf);
    int kbuffer_read_buffer(struct kbuffer *kbuf, void *buffer, int len);

## DESCRIPTION

The function kbuffer_read_event() reads the next event in the kbuf descriptor and if ts is non NULL, will place its timestamp into it. This does not modify the kbuf descriptor, and calling this function mulitple times will return the same result.

The function kbuffer_next_event() will return the next event in the kbuf descriptor. It will also set the ts to the timestamp of the returned event. NULL is returned if there are no more events and ts will be undefined. Note, if this is called directly after a kbuffer_load_subbuffer() then it will likely give an unexpected result, as it will return the second event and not the first event. Usually this function is only used to move to the next event and to know if there’s any more events to read, and kbuffer_read_event() is always called first.

The function kbuffer_read_at_offset() returns the event located at a given offset from the beginning of the sub-buffer. This offset can be retrieved by kbuffer_curr_offset(). If ts points to an unsigned long long, then it will be set to the event at the given offset’s timestamp.

If the sub-buffer had missed events before it, then kbuffer_missed_events() will return the non zero. If it returns -1, that means there were missed events, but the exact number of missed events is unknown. If it returns a positive number, then the number of missed events is the return value.

The kbuffer_event_size() function returns the size of the data portion of the current event (the one that would be returned by kbuffer_read_event().

The kbuffer_curr_size() function returns the entire record size of the current event (the one that would be returned by kbuffer_read_event(). The difference here is that the return value includes the size of the event record meta data that is not part of what is returned by kbuffer_read_event().

The kbuffer_curr_offset() function returns the offset from the beginning of the sub-buffer of where the current event’s meta data for the record begins. The first event will not be at offset zero. This offset can be used to retrieve the event with kbuffer_read_at_offset().

The kbuffer_curr_index() function returns the index from the beginning of the data portion of the sub-buffer where the current evnet’s meta data is located. The first event will likely be zero, but may not be if there’s a timestamp attached to it.

The kbuffer_read_buffer() function will fill the given buffer from the kbuf the same way the kernel would do a read system call. That is, if the length len is less than the sub buffer size, or the kbuffer current index is non-zero, it will start copying from the kbuf current event and create buffer as a new sub buffer (with a timestamp and commit header) with that event that was found and including all events after that can fit within len. The len must include the size of the sub buffer header as well as the events to include. That is, len is the allocate size of buffer that can be filled. The return from this function is the index of the end of the last event that was added. If there are no more events then zero is returned, and if the buffer can not copy any events because len was too small, then -1 is returned.

## RETURN VALUE

kbuffer_read_event() returns the event that the kbuf descriptor is currently at, or NULL if the last event was passed (by kbuffer_next_event()).

kbuffer_next_event() returns the next event after the current event or NULL if there are no more events.

kbuffer_read_at_offset() returns the event at a given offset from the start of the sub-buffer stored in kbuf, or NULL if there exists no event. Note, offset only needs to be an offset that lands on the record, or is at the start of it. It does not need to be exactly at the beginning of the record.

kbuffer_missed_events() returns 0 if there were no missed events before loaded sub-buffer. Returns -1 if there were an unknown number of missed events, or if the number of missed events is known, that number will be returned.

kbuffer_event_size() returns the size of the data payload of the current event of kbuf.

kbuffer_curr_size() returns the size of the entire record of the current event of kbuf. This includes the size of the meta data for that record.

kbuf_curr_offset() returns the offset of the current record from the beginning of the kbuf sub-buffer.

kbuf_curr_index() returns the index of the current record from the beginning of the kbuf data section.

kbuf_read_buffer() returns the index of the end of the last event that was filled in buffer. If there are no more events to copy from start then 0 is returned. If len is not big enough to hold any events, then -1 is returned.

## EXAMPLE

## FILES

    event-parse.h
            Header file to include in order to have access to the library APIs.
    -ltraceevent
            Linker switch to add when building a program that uses the library.

## SEE ALSO

libtraceevent(3), trace-cmd(1)

## AUTHOR

    Steven Rostedt <rostedt@goodmis.org>, author of libtraceevent.

## REPORTING BUGS

Report bugs to <linux-trace-devel@vger.kernel.org>

## LICENSE

libtraceevent is Free Software licensed under the GNU LGPL 2.1

## RESOURCES

https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/