LIBTRACEFS(3)
π LIBTRACEFS(3) β the libtracefs manual, bestie edition β¨
okay so this is the page for the libtracefs manual, and it's literally all about managing trace instances. stay with me, it's gonna slay π
πΈ NAME πΈ
tracefs_instance_create, tracefs_instance_destroy, tracefs_instance_alloc, tracefs_instance_free, tracefs_instance_is_new, tracefs_instances, tracefs_instance_clear, tracefs_instance_reset β Manage trace instances. that's the whole vibe π
β¨ SYNOPSIS β¨
#include <tracefs.h>
struct tracefs_instance *tracefs_instance_create(const char *name);
int tracefs_instance_destroy(struct tracefs_instance *instance);
struct tracefs_instance *tracefs_instance_alloc(const char *tracing_dir, const char *name);
void tracefs_instance_free(struct tracefs_instance *instance);
bool tracefs_instance_is_new(struct tracefs_instance *instance);
char **tracefs_instances(const char *regex);
void tracefs_instance_clear(struct tracefs_instance *instance);
void tracefs_instance_reset(struct tracefs_instance *instance);
π¦ DESCRIPTION π¦
so this whole little family of functions is your group chat for managing trace instances. and what even is a trace instance? periodt, let me explain: it's a sub buffer used by the Linux tracing system. give it a unique name, and the events you enable inside it do not touch the main tracing system, and they don't touch other instances either β and the flip side is true too, the events enabled in the main tracing system or in other instances don't affect your instance. fully separate vibes, no crossover, iykyk π
tracefs_instance_create()β this one allocates and initializes a newtracefs_instancestructure and hands it right back to you π«Ά. if the instance with name doesn't exist in the system yet, it gets created. the name can beNULL, and then the newtracefs_instancestructure is initialized for the top instance. β οΈ but note β the top instance cannot be created in the system, so if it doesn't exist, that's just how it is, no cap.tracefs_instance_destroy()β removes the instance from the system, but does not free the structure. you still gotta calltracefs_instance_free()on instance. don't leave your girl hanging with a leak πtracefs_instance_alloc()β allocates a newtracefs_instancestructure for an instance that already exists. if the instance doesn't exist in the system, this function just fails, that's it, that's the tweet π. the tracing_dir parameter points to the system trace directory, and it can beNULL, in which case the default system trace directory is used. this parameter is genuinely iconic for allocating instances to trace directories that were copied from another machine π§. name is the name of the instance, orNULLfor the top instance in the given tracing_dir.tracefs_instance_free()β frees thetracefs_instancestructure, without removing the trace instance from the system. bye structure, instance stays living its best life β¨tracefs_instance_is_new()β checks if the given instance was newly created bytracefs_instance_create(), or whether it was already chilling in the system before that. the vibe check of functions, honestly πtracefs_instances()β returns a list of instances that exist in the system which match the regular expression regex. if regex isNULL, then it matches all the instances that exist. the returned list must be freed withtracefs_list_free(3). π and note β if no instances are found, an empty list is returned, and that empty list also needs to be freed withtracefs_list_free(3). free your empties, bestie, fr fr.tracefs_instance_clear()β clears the ring buffer of the given instance, or the top level ring buffer if instance isNULL. fresh start energy πtracefs_instance_reset()β resets the given instance to its default state. factory settings, main character reborn π
π₯ RETURN VALUE π₯
tracefs_instance_create()andtracefs_instance_alloc()return a pointer to a newly allocatedtracefs_instancestructure. it must be freed withtracefs_instance_free(). non-negotiable π«Άtracefs_instance_destroy()returns0if it succeeds in removing the instance, otherwise it returns-1if the instance does not exist or if it fails to remove it.tracefs_instance_is_new()returnstrueif thetracefs_instance_create()that allocated instance also created the trace instance in the system, orfalseif the trace instance already existed in the system when instance was allocated bytracefs_instance_create()ortracefs_instance_alloc().tracefs_instances()returns a list of instance names that exist on the system. the list must be freed withtracefs_list_free(3). an empty list is returned if no instance exists that matches regex, and this needs to be freed withtracefs_list_free(3)as well.NULLis returned on error πtracefs_instance_clear()returns0if it successfully cleared the ring buffer, or-1on error.
π EXAMPLE π
#include <tracefs.h>
struct tracefs_instance *inst = tracefs_instance_create("foo");
if (!inst) {
/* Error creating a new trace instance */
...
}
...
if (tracefs_instance_is_new(inst))
tracefs_instance_destroy(inst);
tracefs_instance_free(inst);
...
struct tracefs_instance *inst = tracefs_instance_alloc(NULL, "bar");
if (!inst) {
/* Error allocating 'bar' trace instance */
...
}
...
tracefs_instance_reset(inst);
tracefs_instance_free(inst);
see how it's done? create it, check if it's new, destroy it if so, then free it. then alloc an existing one, reset it, free it. chef's kiss, no notes π©βπ³π
π 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. add it, or your build will simply not go off π
β SEE ALSO β
libtracefs(3), libtraceevent(3), trace-cmd(1)
go read those too, the whole friend group is worth knowing π«Ά
π AUTHOR π
- Steven Rostedt
<rostedt@goodmis.org[1]> - Tzvetomir Stoyanov
<tz.stoyanov@gmail.com[2]>
icons, both of them π
π REPORTING BUGS π
Report bugs to <linux-trace-devel@vger.kernel.org[3]>
π 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.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 page, bestie π¦ this was libtracefs 1.8.4, dated 10/21/2026, and yes it's still called LIBTRACEFS(3) β mwah, go manage some instances, you've got this πβ¨
π¦ 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