libtracefs(3)

# libtracefs(3) Manual Page

## NAME

tracefs_iterate_raw_events, tracefs_iterate_stop, tracefs_follow_event, tracefs_follow_missed_events, tracefs_follow_event_clear, tracefs_follow_missed_events_clear, tracefs_iterate_snapshot_events - Iterate over events in the ring buffer

## SYNOPSIS

    #include <tracefs.h>

    int tracefs_iterate_raw_events(struct tep_handle *tep, struct tracefs_instance *instance,
                                     cpu_set_t *cpus, int cpu_size,
                                     int (*callback)(struct tep_event *, struct tep_record *, int, void *),
                                     void *callback_context);
    void tracefs_iterate_stop(struct tracefs_instance *instance);

    int tracefs_follow_event(struct tep_handle *tep, struct tracefs_instance *instance,
                              const char *system, const char *event_name,
                              int (*callback)(struct tep_event *,
                                              struct tep_record *,
                                              int, void *),
                              void *callback_data);
    int tracefs_follow_missed_events(struct tracefs_instance *instance,
                              int (*callback)(struct tep_event *,
                                              struct tep_record *,
                                              int, void *),
                              void *callback_data);

    int tracefs_follow_event_clear(struct tracefs_instance *instance,
                              const char *system, const char *event_name);
    int tracefs_follow_missed_events_clear(struct tracefs_instance *instance);

    int tracefs_iterate_snapshot_events(struct tep_handle *tep, struct tracefs_instance *instance,
                                     cpu_set_t *cpus, int cpu_size,
                                     int (*callback)(struct tep_event *, struct tep_record *, int, void *),
                                     void *callback_context);

## DESCRIPTION

Trace iterator over raw events.

The tracefs_iterate_raw_events() function will read the tracefs raw data buffers and call the specified callback function for every event it encounters. Events are iterated in sorted order: oldest first. An initialized tep handler is required (See tracefs_local_events(3)). If instance is NULL, then the toplevel tracefs buffer is used, otherwise the buffer for the corresponding instance is read. To filter only on a subset of CPUs, cpus and cpu_size may be set to only call callback with events that occurred on the CPUs specified, otherwise if cpus is NULL then the callback function will be called for all events, and cpu_size is ignored. The callback function will be called with the following parameters: A pointer to a struct tep_event that corresponds to the type of event the record is; The record representing the event; The CPU that the event occurred on; and a pointer to user specified callback_context. If the callback returns non-zero, the iteration stops.

The tracefs_iterate_snapshot_events() works the same as tracefs_iterate_raw_events() except that it works on the snapshot buffer.

Use tracefs_iterate_stop() to force a executing tracefs_iterate_raw_events() to halt. This can be called from either a callback that is called by the iterator (even though a return of non-zero will stop it), or from another thread.

The tracefs_follow_event() is used with tracefs_iterate_raw_events() but intead of the callback being called for every event, it is only called for the specified system / event_name given to the function. The callback is the same as for tracefs_iterate_raw_events(), and the passed in callback_context will be passed to the callback as well. Note, if it returns something other than 0, it will stop the loop before the callback of tracefs_iterate_raw_events() is called.

The tracefs_follow_missed_events() will call the callback when missed events are detected. It will set the record parameter of the callback to the record that came after the missed events and event will be of the type of event record is. cpu will be set to the CPU that missed the events, and callback_data will be the content that was passed in to the function.

The tracefs_follow_event_clear() will remove followers from instance that match system and event_name. If system and event_name are both NULL, then it will remove all event followers associated to instance. If just system is NULL, then it will remove all followers that follow events that match event_name. If just event_name is NULL, then it will remove all followers that are attached to events that are apart of a system that matches system.

The tracefs_follow_missed_events_clear() will remove all followers for missed events.

## RETURN VALUE

The tracefs_iterate_raw_events() function returns -1 in case of an error or 0 otherwise.

Both tracefs_follow_event_clear() and tracefs_follow_missed_events_clear() return 0 on success and -1 on error, or if it found no followers that match and should be removed.

## EXAMPLE

## FILES

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

## SEE ALSO

libtracefs(3), libtraceevent(3), trace-cmd(1)

## AUTHOR

    Steven Rostedt <rostedt@goodmis.org>
    Tzvetomir Stoyanov <tz.stoyanov@gmail.com>

## REPORTING BUGS

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

## LICENSE

libtracefs is Free Software licensed under the GNU LGPL 2.1

## RESOURCES

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

## COPYING

Copyright (C) 2020 VMware, Inc. Free use of this software is granted under the terms of the GNU Public License (GPL).