LIBTRACEFS(3)
π LIBTRACEFS(3) β the libtracefs manual, bestie edition π
okay so this is the libtracefs manual page, and today we're doing the cute little helper functions for poking at the trace file system. no cap, these are the glue functions you'll reach for constantly. let's go π«Ά
β¨ NAME β¨
tracefs_tracers, tracefs_tracer_available, tracefs_get_clock, tracefs_list_free, tracefs_list_add, tracefs_list_size β literally the helper functions for working with the trace file system. that's the whole vibe. π
πΈ SYNOPSIS πΈ
#include <tracefs.h>
char **tracefs_tracers(const char *tracing_dir);
bool tracefs_tracer_available(const char *tracing_dir, const char *tracer);
char *tracefs_get_clock(struct tracefs_instance *instance);
void tracefs_list_free(char **list);
char **tracefs_list_add(char *list, const char *string);
int *tracefs_list_size(char **list);
copy these exactly, they're iconic and we don't edit icons β¨
π¦ DESCRIPTION π¦
so basically: various useful functions for working with the trace file system. that's the summary. now the tea, one function at a time β
tracefs_tracers()β returns an array of strings with the names of all the supported tracer plugins, pulled from whatevertracing_dirdirectory you hand it. and bestie,tracing_dirhas range: it can beNULL, or it can be the location of the tracefs mount point for your local machine's trace systems, or it can even be a path to a copy of a tracefs directory from another machine. so flexible, we love her π the last entry in the array is aNULLpointer (classic terminator behavior, periodt). and the array must be freed with thetracefs_list_free()API. don't forget, or it's giving leak energy πtracefs_tracer_available()β returnstrueif thetraceris available in the giventracing_dirdirectory, andfalseotherwise. simple, clean, no notes πtracefs_get_clock()β returns the name of the current trace clock used in the giveninstance. ifinstanceisNULL, you get the clock of the main trace instance instead. the returned string must be freed withfree(). yes, plainfree(), not the list one. iykyk πtracefs_list_free()β frees an array of strings, specifically the ones returned by thetracefs_event_systems(),tracefs_system_events()andtracefs_tracers()APIs. this is your cleanup bestie, be nice to her π§Ήtracefs_list_add()β addsstringto the string list. here's the mechanics, listen up:- if
listisNULL, then a new list is created with the first element being a copy ofstring, and the second element being aNULLpointer. brand new list, fresh start, main character energy β¨ - if
listis notNULL, then it is reallocated to include a new element and aNULLterminator, and the new allocated array is returned. - β οΈ the list you passed in should be ignored, because it will be freed if a new one was allocated. do not touch it. do not look at it. it's gone, girl π
- if
tracefs_list_size()β a fast way to find out the number of elements in a string array that is to be freed withtracefs_list_free(). but real talk: this depends on meta data that is created for these lists, and it will not work on normal string arrays likeargv. so don't try it onargv. i'm serious. it will not slay. π
π₯ RETURN VALUE π₯
tracefs_tracers()returns an array of strings. the last element in that array is aNULLpointer. the array must be freed withtracefs_list_free()API. in case of an error,NULLis returned. πtracefs_tracer_available()returnstrueif the tracer is available, andfalseotherwise. short and sweet πtracefs_get_clock()returns a string β which you must free withfree()β orNULLin case of an error.tracefs_list_add()returns an allocated string array that must be freed withtracefs_list_free()on success, orNULLon error. and here's the important bit: ifNULLis returned, then the passed-inlistis untouched. so you should treattracefs_list_add()similarly torealloc(3). same energy, same rules, no cap βtracefs_list_size()returns the number of strings in the list. the passed-in list must be one that is to be freed withtracefs_list_free(), because the list has meta data that's used to determine the size β and this does not work on any normal string array likeargv. saying it twice because it matters, bestie π«Ά
π EXAMPLE π
#include <tracefs.h>
char **tracers = tracefs_tracers(NULL);
if (tracers) {
/* Got tracer plugins from the top trace instance */
...
tracefs_list_free(tracers);
}
....
char *clock = tracefs_get_clock(NULL);
if (clock) {
/* Got current trace clock of the top trace instance */
...
free(clock);
}
see how each one gets cleaned up with the right free function? that's the whole lesson. she's consistent, she's tidy, she ate π
π FILES π
tracefs.hβ the header file to include in order to have access to the library APIs. include her or nothing works, bestie.-ltracefsβ the linker switch to add when building a program that uses the library. don't forget it or you'll be staring at undefined references like π
π SEE ALSO π
libtracefs(3), libtraceevent(3), trace-cmd(1)
go read those too, they're the supporting cast and they're all icons in their own right πΈ
π AUTHOR π
- Steven Rostedt
<rostedt@goodmis.org<sup>1</sup>> - Tzvetomir Stoyanov
<tz.stoyanov@gmail.com<sup>2</sup>>
absolute legends, we stan π«Ά
π REPORTING BUGS π
report bugs to <linux-trace-devel@vger.kernel.org<sup>3</sup>>
found a bug? tell the mailing list, don't just suffer in silence π
π LICENSE π
libtracefs is Free Software licensed under the GNU LGPL 2.1. free as in freedom, protected as in license π
π§ RESOURCES π§
https://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git/
that's the repo. go look at it. touch grass after, but look at it first β¨
β 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.orgtz.stoyanov@gmail.comβmailto:tz.stoyanov@gmail.comlinux-trace-devel@vger.kernel.orgβmailto:linux-trace-devel@vger.kernel.org
and that's the page!! π this whole thing is libtracefs 1.8.4, dated 10/21/2026 β so go forth, free your lists, free your strings with the correct free, and remember: tracefs_list_size() does not work on argv. love u, 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