LIBTRACEEVENT(3)

πŸ’– LIBTRACEEVENT(3) πŸ’–

okay bestie, so this is a page from the libtraceevent Manual and honestly? it's a good one. buckle up, we're talking event lists πŸ’…


✨ NAME ✨

tep_list_events, tep_list_events_copy β€” get a list of events, sorted by whatever criteria u picked πŸ’«


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <event-parse.h>

enum tep_event_sort_type {
        TEP_EVENT_SORT_ID,
        TEP_EVENT_SORT_NAME,
        TEP_EVENT_SORT_SYSTEM,
};

struct tep_event **tep_list_events(struct tep_handle *tep, enum tep_event_sort_type sort_type);
struct tep_event **tep_list_events_copy(struct tep_handle *tep, enum tep_event_sort_type sort_type);

🌸 DESCRIPTION 🌸

so tep_list_events() hands u back an array of pointers to the events, all sorted by the sort_type criteria u asked for. the last element of that array is NULL β€” that's ur little "the list ends here bestie" marker πŸ›‘

🚨 IMPORTANT: the memory u get back must not be freed. it's managed by the library, not by u. hands off. also, this function is not thread safe β€” do not come for it from multiple threads at once, she will simply not cope πŸ™ˆ

the tep argument is ur trace event parser context. and sort_type is the sort criteria u want, and there are literally three options:

  • TEP_EVENT_SORT_ID β€” sorts by the event ID πŸ†”
  • TEP_EVENT_SORT_NAME β€” sorts by the event (name, system, id) triplet ✨
  • TEP_EVENT_SORT_SYSTEM β€” sorts by the event (system, name, id) triplet 🌈

now, tep_list_events_copy() is the thread safe version of tep_list_events(). same behavior, same vibe, BUT the returned array is allocated internally and it's on u to free it β€” that's the deal. note that the content of the array still must not be freed (peep the EXAMPLE down below, it's giving instructions πŸ‘€).


πŸ‘‘ RETURN VALUE πŸ‘‘

tep_list_events() returns an array of pointers to events. if something goes wrong? NULL. and again, for the people in the back: the returned array must not be freed, it is managed by the library. 🫢

tep_list_events_copy() returns an array of pointers to events. on error, NULL. and this returned array must be freed by the caller. yes queen, u own this one πŸ’…


πŸŽ€ EXAMPLE πŸŽ€

#include <event-parse.h>
...
struct tep_handle *tep = tep_alloc();
...
int i;
struct tep_event_format **events;

i=0;
events = tep_list_events(tep, TEP_EVENT_SORT_ID);
if (events == NULL) {
        /* Failed to get the events, sorted by ID */
} else {
        while(events[i]) {
                /* walk through the list of the events, sorted by ID */
                i++;
        }
}

i=0;
events = tep_list_events_copy(tep, TEP_EVENT_SORT_NAME);
if (events == NULL) {
        /* Failed to get the events, sorted by name */
} else {
        while(events[i]) {
                /* walk through the list of the events, sorted by name */
                i++;
        }
        free(events);
}

...

see how the copy one gets a lil free(events) at the end and the other one doesn't?? that's the whole tea β˜• the way that detail matters fr fr.


🧚 FILES 🧚

  • event-parse.h β€” the header file u include so u can actually access the library APIs πŸ“„
  • -ltraceevent β€” the linker switch u add when building a program that uses the library πŸ”—

🌈 SEE ALSO 🌈

libtraceevent(3), trace-cmd(1)


πŸ’œ AUTHOR πŸ’œ

  • Steven Rostedt <rostedt@goodmis.org[1]>, author of libtraceevent πŸ‘‘
  • Tzvetomir Stoyanov <tz.stoyanov@gmail.com[2]>, author of this man page ✍️

πŸ“ REPORTING BUGS πŸ“

found a bug? report it to <linux-trace-devel@vger.kernel.org[3]> β€” they wanna hear about it, no cap πŸ›


⭐ LICENSE ⭐

libtraceevent is Free Software licensed under the GNU LGPL 2.1 πŸ“œ


πŸ”₯ RESOURCES πŸ”₯

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


πŸ’€ NOTES πŸ’€

  1. rostedt@goodmis.org mailto:rostedt@goodmis.org
  2. tz.stoyanov@gmail.com mailto:tz.stoyanov@gmail.com
  3. linux-trace-devel@vger.kernel.org mailto:linux-trace-devel@vger.kernel.org

and that's the whole page bestie!! 🫢 this was libtraceevent 1.9.0, dated 06/15/2026, and it's genuinely iconic of u to read the whole thing. go sort some events, u absolute main character πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from