LIBTRACEFS(3)
β¨ LIBTRACEFS π β the one where we mess with function trace filters π
ok so bestie, this is the libtracefs page, and today's main characters are the function filter functions. yes, we're filtering which kernel functions get traced. it's giving "control freak but make it syscalls" β¨
πΈ NAME πΈ
tracefs_function_filter, tracefs_function_notrace, tracefs_filter_functions β literally the functions that let you modify theβ¦ the function trace filters π (yes the original page says "the the", we're keeping the vibe, no cap)
π¦ SYNOPSIS π¦
#include <tracefs.h>
int tracefs_function_filter(struct tracefs_instance *instance, const char *filter, const char *module, int flags);
int tracefs_function_notrace(struct tracefs_instance *instance, const char *filter, const char *module, int flags);
int tracefs_filter_functions(const char *filter, const char *module, char ***list);
π DESCRIPTION π
so tracefs_function_filter and tracefs_function_notrace are the girlies that limit which Linux kernel functions actually get traced by the function and function-graph tracers. iconic behavior honestly.
tracefs_function_filterdefines the list of functions that can be traced πtracefs_function_notracedefines the list of functions that will not be traced π ββοΈ- and if a function is in both lists? it will not be traced. that's it, that's the rule, bestie. periodt. π
They take these args:
instanceβ the instance, and it can beNULLfor the top level tracing πfilterβ a string that represents a filter that should be applied to define what functions are to be tracedmoduleβ limits the filtering to a specific module (orNULLto filter on all functions)flagsβ holds the control knobs on how the filters will be handled (see the FLAGS section below, iykyk)
Then there's tracefs_filter_functions π§ β it returns a list of functions that can be filtered on via the filter and module you supply. If both filter and module are NULL, then all available functions that can be filtered get returned. On success, list must be freed with tracefs_list_free()(3). don't forget, she's your responsibility now π«Ά
π what even is a filter tho
The filter may be either:
- a straight match of a function π―
- a glob β¨
- or a
regex(3)π₯
A glob is where * matches zero or more characters, ? will match zero or one character, and . only matches a period. Simple. Clean. Gorgeous. π
If the filter is determined to be a regex (where it contains anything other than alpha numeric characters, or ., *, ?) the filter will be processed as a regex(3) following the rules of regex(3), and . is not a period, but will match any one character. plot twist!! π
To force a regular expression, either prefixfilterwith^or append it with$as the filter does complete matches of the functions anyway.
π the NULL filter lore
If module is set and filter is NULL, this will imply the same as filter being equal to "*". Which will enable all functions for a given module. slay.
Otherwise the filter may be NULL if a previous call to tracefs_function_filter() with the same instance had TRACEFS_FL_CONTINUE set and this call does not. This is useful to simply commit the previous filters β
It may also be NULL if TRACEFS_FL_RESET is set and the previous call did not have the same instance and TRACEFS_FL_CONTINUE set. This is useful to just clear the filter π§Ό
β FLAGS β
The flags parameter may have the following set, or be zero. (zero is a valid vibe, ngl.)
TRACEFS_FL_RESETβ IfflagscontainsTRACEFS_FL_RESET, then it will clear the filters that are currently set before applyingfilter. Otherwise,filteris added to the current set of filters already enabled. If this flag is set and the previous call totracefs_function_filter()had the sameinstanceand theTRACEFS_FL_CONTINUEflag was set, then the function will fail with a return of-1anderrnoset toEBUSY. π¨ drama!TRACEFS_FL_CONTINUEβ IfflagscontainsTRACEFS_FL_CONTINUE, thenfilterwill not take effect after a successful call totracefs_function_filter(). This allows for multiple calls totracefs_function_filter()to update the filter function and then a single call (one without theTRACEFS_FL_CONTINUEflag set) to commit all the filters. It can be called multiple times to add more filters. A call without this flag set will commit the changes before returning (if thefilterpassed in successfully matched). Atracefs_function_filter()call after one that had theTRACEFS_FL_CONTINUEflag set for the sameinstancewill fail ifTRACEFS_FL_RESETflag is set, as the reset flag is only applicable for the first filter to be added before committing. π it's a whole committed relationship situationTRACEFS_FL_FUTUREβ IfflagscontainsTRACEFS_FL_FUTUREandmoduleholds a string of a module, then if the module is not loaded it will attemp to write the filter with the module in the filter file. (yes, "attemp", we're quoting the ancestors π) Starting in Linux v4.13 module functions could be added to the filter before they are loaded. The filter will be cached, and when the module is loaded, the filter will be set before the module executes, allowing to trace init functions of a module. This will only work if the filter is not a regular expression. π§ββοΈ manifesting the module into existence fr fr
π₯ RETURN VALUE π₯
For tracefs_function_filter() and tracefs_function_notrace() a return of 0 means success β
If the there is an error but the filtering was not started, then 1 is returned. If filtering was started but an error occurs, then -1 is returned. The state of the filtering may be in an unknown state. π yeah. scary. we don't love that but we respect it.
If TRACEFS_FL_CONTINUE was set, and 0 or -1 was returned, then another call to tracefs_function_filter() must be done without TRACEFS_FL_CONTINUE set in order to commit (and close) the filtering. don't leave her hanging π«Ά
For tracefs_filter_functions(), a return of 0 means success, and the list parameter is filled with a list of function names that matched filter and module. list is a string array, where the last string pointer in the array is NULL. The list must be freed with tracefs_list_free(). On failure, a negative is returned, and list is ignored. bye bestie π
π ERRORS π
tracefs_function_filter() can fail with the following errors:
EINVALβ Thefilteris invalid or did not match any functions. πEBUSYβ The previous call oftracefs_function_filter()was called with the sameinstanceandTRACEFS_FL_CONTINUEset and the current call hadTRACEFS_FL_RESETset. π¨
Other errors may also happen caused by internal system calls. (the classic "it's not you it's the syscalls" π)
π¦ EXAMPLE π¦
ok this is the whole thing, verbatim, go off king:
#include <stdio.h>
#include <errno.h>
#include <tracefs.h>
#define INST "dummy"
static const char *filters[] = { "run_init_process", "try_to_run_init_process", "dummy1", NULL };
int main(int argc, char *argv[])
{
struct tracefs_instance *inst = tracefs_instance_create(INST);
char **func_list;
int ret;
int i;
if (!inst) {
/* Error creating new trace instance */
}
if (tracefs_filter_functions("*lock*", NULL, &func_list) < 0) {
printf("Failed to read filter functions\n");
goto out;
}
printf("Ignoring the following functions:\n");
for (i = 0; func_list[i]; i++)
printf(" %s\n", func_list[i]);
tracefs_list_free(func_list);
/* Do not trace any function with the word "lock" in it */
ret = tracefs_function_notrace(inst, "*lock*", NULL, TRACEFS_FL_RESET);
if (ret) {
printf("Failed to set the notrace filter\n");
goto out;
}
/* First reset the filter */
ret = tracefs_function_filter(inst, NULL, NULL,
TRACEFS_FL_RESET | TRACEFS_FL_CONTINUE);
if (ret) {
printf("Failed to reset the filter\n");
/* Make sure it is closed, -1 means filter was started */
if (ret < 0)
tracefs_function_filter(inst, NULL, NULL, 0);
}
for (i = 0; filters[i]; i++) {
ret = tracefs_function_filter(inst, filters[i], NULL,
TRACEFS_FL_CONTINUE);
if (ret) {
if (errno == EINVAL)
printf("Filter %s did not match\n", filters[i]);
else
printf("Failed writing %s\n", filters[i]);
}
}
ret = tracefs_function_filter(inst, "*", "ext4", 0);
if (ret) {
printf("Failed to set filters for ext4\n");
/* Force the function to commit previous filters */
tracefs_function_filter(inst, NULL, NULL, 0);
}
out:
tracefs_instance_destroy(inst);
return ret;
}
π§ 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) β the whole friend group π«Ά
π AUTHOR π
- Steven Rostedt <rostedt@goodmis.org[1]>
- Tzvetomir Stoyanov <tz.stoyanov@gmail.com[2]>
- sameeruddin shaik <sameeruddin.shaik8@gmail.com[3]>
legends, honestly. π
π REPORTING BUGS π
Report bugs to <linux-trace-devel@vger.kernel.org[4]> β they wanna hear from you, bestie π
πΈ 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).
π NOTES π
- rostedt@goodmis.org
mailto:rostedt@goodmis.org - tz.stoyanov@gmail.com
mailto:tz.stoyanov@gmail.com - sameeruddin.shaik8@gmail.com
mailto:sameeruddin.shaik8@gmail.com - linux-trace-devel@vger.kernel.org
mailto:linux-trace-devel@vger.kernel.org
and that's the page!! signing off from libtracefs 1.8.4, dated 10/21/2026 β this was LIBTRACEFS(3), mwah πβ¨ go filter something, ily, bye π
π¦ where this page comes from
- arch rolling: libtracefs 1.8.4-1 Β· GPL-2.0-only AND LGPL-2.1-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms