LIBTRACEEVENT(3)
β¨ NAME β¨
tep_filter_alloc, tep_filter_free, tep_filter_reset, tep_filter_make_string, tep_filter_copy, tep_filter_compare, tep_filter_match, tep_event_filtered, tep_filter_remove_event, tep_filter_strerror, tep_filter_add_filter_str β bestie, these are the Event filter related APIs π
Okay so this whole page lives in the libtraceevent manual, and it's basically the filter girlies' group chat π
πΈ SYNOPSIS πΈ
#include <event-parse.h>
struct tep_event_filter *tep_filter_alloc(struct tep_handle *tep);
void tep_filter_free(struct tep_event_filter *filter);
void tep_filter_reset(struct tep_event_filter *filter);
enum tep_errno tep_filter_add_filter_str(struct tep_event_filter *filter, const char *filter_str);
int tep_event_filtered(struct tep_event_filter *filter, int event_id);
int tep_filter_remove_event(struct tep_event_filter *filter, int event_id);
enum tep_errno tep_filter_match(struct tep_event_filter *filter, struct tep_record *record);
int tep_filter_copy(struct tep_event_filter *dest, struct tep_event_filter *source);
int tep_filter_compare(struct tep_event_filter *filter1, struct tep_event_filter *filter2);
char *tep_filter_make_string(struct tep_event_filter *filter, int event_id);
int tep_filter_strerror(struct tep_event_filter *filter, enum tep_errno err, char *buf, size_t buflen);
π DESCRIPTION π
So like, filters can be attached to traced events. The whole point? Filtering out various events when you're outputting them π¦ Each event can be filtered based on its parameters, which are described in the event's format file. This little squad of functions lets you create, delete, modify, and attach event filters. Slay.
tep_filter_alloc()β creates a brand new event filter, no cap. Thetepargument is the trace event parser context. She's the main character here.tep_filter_free()β frees an event filter and literally all the resources it had used. Everything. Gone. Bye πtep_filter_reset()β removes all rules from an event filter and resets it. Clean slate energy β¨tep_filter_add_filter_str()β adds a new rule to the filter. Thefilter_strargument is the filter string, and that's the thing holding the actual rule.tep_event_filtered()β checks if the event withevent_idhas a filter. Just a lil vibe check.tep_filter_remove_event()β removes a filter for an event withevent_id. Not me deleting it πtep_filter_match()β tests if a record matches the given filter. The moment of truth fr fr.tep_filter_copy()β copies asourcefilter into adestfilter. Twin making π«Άtep_filter_compare()β compares two filters,filter1andfilter2. Are they the same girl or not πtep_filter_make_string()β constructs a string displaying the filter contents for the givenevent_id. Receipts.tep_filter_strerror()β copies the filter error buffer into the givenbufwith the sizebuflen. And if the error buffer is empty, then what gets copied intobufis a string describing the errorerr. Lowkey thoughtful π
π RETURN VALUE π
tep_filter_alloc()β hands you a pointer to the freshly created event filter, orNULLif something went wrong πtep_filter_add_filter_str()β returns0if the rule was successfully added, or a negative error code. Usetep_filter_strerror()to see the actual error message when it goes bad. It's giving "read the error, bestie".tep_event_filtered()β returns1if the filter is found for the given event, or0otherwise.tep_filter_remove_event()β returns1if the event was removed, or0if the event was not found.tep_filter_match()β returns atep_errno, according to the result:TEP_ERRNO__FILTER_MATCHβ filter found for event, the record matches. Iconic.TEP_ERRNO__FILTER_MISSβ filter found for event, the record does not match. Not the vibe.TEP_ERRNO__FILTER_NOT_FOUNDβ no filter found for record's event.TEP_ERRNO__NO_FILTERβ no rules in the filter. Empty filter, empty brain, still valid.
β¦or any other tep_errno, if an error occurred during the test.
tep_filter_copy()β returns0on success, or-1if not all rules were copied. Partial copy = partial heartbreak.tep_filter_compare()β returns1if the two filters hold the same content, or0if they do not.tep_filter_make_string()β returns a string, which must be freed withfree(), orNULLin case of an error. (Free your strings, bestie, the allocator is watching π)tep_filter_strerror()β returns0if the message was filled successfully, or-1in case of an error.
π₯ EXAMPLE π₯
#include <event-parse.h>
...
struct tep_handle *tep = tep_alloc();
...
char errstr[200];
int ret;
struct tep_event_filter *filter = tep_filter_alloc(tep);
struct tep_event_filter *filter1 = tep_filter_alloc(tep);
ret = tep_filter_add_filter_str(filter, "sched/sched_wakeup:target_cpu==1");
if(ret < 0) {
tep_filter_strerror(filter, ret, errstr, sizeof(errstr));
/* Failed to add a new rule to the filter, the error string is in errstr */
}
if (tep_filter_copy(filter1, filter) != 0) {
/* Failed to copy filter in filter1 */
}
...
if (tep_filter_compare(filter, filter1) != 1) {
/* Both filters are different */
}
...
void process_record(struct tep_handle *tep, struct tep_record *record)
{
struct tep_event *event;
char *fstring;
event = tep_find_event_by_record(tep, record);
if (tep_event_filtered(filter, event->id) == 1) {
/* The event has filter */
fstring = tep_filter_make_string(filter, event->id);
if (fstring != NULL) {
/* The filter for the event is in fstring */
free(fstring);
}
}
switch (tep_filter_match(filter, record)) {
case TEP_ERRNO__FILTER_MATCH:
/* The filter matches the record */
break;
case TEP_ERRNO__FILTER_MISS:
/* The filter does not match the record */
break;
case TEP_ERRNO__FILTER_NOT_FOUND:
/* No filter found for record's event */
break;
case TEP_ERRNO__NO_FILTER:
/* There are no rules in the filter */
break
default:
/* An error occurred during the test */
break;
}
if (tep_filter_remove_event(filter, event->id) == 1) {
/* The event was removed from the filter */
}
}
...
tep_filter_reset(filter);
...
tep_filter_free(filter);
tep_filter_free(filter1);
...
π FILES π
event-parse.h- Header file to include in order to have access to the library APIs. Yes, you gotta
#includeher first π
- Header file to include in order to have access to the library APIs. Yes, you gotta
-ltraceevent- Linker switch to add when building a program that uses the library. Don't forget it or the linker WILL be dramatic π€
π SEE ALSO π
libtraceevent(3), trace-cmd(1)
iykyk π¦
π AUTHOR π
- Steven Rostedt <rostedt@goodmis.org[1]>, author of libtraceevent.
- Tzvetomir Stoyanov <tz.stoyanov@gmail.com[2]>, author of this man page.
Legends, honestly π«Ά
π«Ά REPORTING BUGS π«Ά
Report bugs to <linux-trace-devel@vger.kernel.org[3]>
π LICENSE π
libtraceevent is Free Software licensed under the GNU LGPL 2.1. Periodt. π
β RESOURCES β
https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/
π NOTES π
rostedt@goodmis.orgmailto:rostedt@goodmis.orgtz.stoyanov@gmail.commailto:tz.stoyanov@gmail.comlinux-trace-devel@vger.kernel.orgmailto:linux-trace-devel@vger.kernel.org
and that's the whole page, bestie β¨ this was libtraceevent 1.9.0, dated 06/15/2026 β go filter some events, you absolute icon πππ¦π
π¦ where this page comes from
- ubuntu stonking: libtraceevent-doc 1:1.9.0-2 Β· LGPL-2.1-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms