LIBTRACEFS(3)
π LIBTRACEFS(3) β libtracefs Manual, bestie edition π
okay so this is the libtracefs manual page, and today we're talking about the little squad of functions that turn tracing on and off. six functions, one job: flipping the switch on your ring buffer. let's get into it β¨
β¨ NAME β¨
tracefs_trace_is_on, tracefs_trace_on, tracefs_trace_off, tracefs_trace_on_get_fd, tracefs_trace_on_fd, tracefs_trace_off_fd β literally the functions that enable or disable tracing. that's the whole vibe π¦
πΈ SYNOPSIS πΈ
#include <tracefs.h>
int tracefs_trace_is_on(struct tracefs_instance *instance);
int tracefs_trace_on(struct tracefs_instance *instance);
int tracefs_trace_off(struct tracefs_instance *instance);
int tracefs_trace_on_get_fd(struct tracefs_instance *instance);
int tracefs_trace_on_fd(int fd);
int tracefs_trace_off_fd(int fd);
π DESCRIPTION π
this whole little set of functions is your ring-buffer remote control πΊ β you use them to check, enable, or disable writing to the ring buffer in whatever trace instance you're messing with. and like, the rule is simple: tracing is enabled when writing to the ring buffer is enabled. that's it. iykyk.
tracefs_trace_is_on()β checks whether tracing is enabled for the instance you gave it. ifinstanceisNULL, it just uses the top instance. king of defaults πtracefs_trace_on()andtracefs_trace_off()β set the tracing in that instance to enabled or disabled. and yeah, ifinstanceisNULL, top instance again. iconic consistency.tracefs_trace_on_get_fd()β hands you a file descriptor to the"tracing_on"file of the given instance.instanceisNULL? top trace instance, obviously πββοΈ. the descriptor it gives back is the fast path for enabling or disabling tracing on that instance β keep it around, it's your shortcut.tracefs_trace_on_fd()andtracefs_trace_off_fd()β enable or disable tracing using thatfd. heads up though: this descriptor must be opened for writing withtracefs_trace_on_get_fd(3)on the trace instance you actually want. and bestie, these two are faster thantracefs_trace_onandtracefs_trace_off. speed. ποΈ
π₯ RETURN VALUE π₯
tracefs_trace_is_on()β returns0if tracing is disabled,1if it's enabled, or-1if something went wrong π.tracefs_trace_on_get_fd()β returns a file descriptor to the"tracing_on"file, open for reading and writing, and you must close it withclose(). if there's an error, you get-1. no cap.tracefs_trace_on(),tracefs_trace_off(),tracefs_trace_on_fd()andtracefs_trace_off_fd()β return-1on an error, or0otherwise. clean. simple. slay.
π¦ EXAMPLE π¦
#include <tracefs.h>
int ret;
ret = tracefs_trace_is_on(NULL);
if (ret == 0) {
/* Tracing is disabled in the top instance */
} else if (ret == 1) {
/* Tracing is enabled in the top instance */
} else {
/* Error getting tracing state of the top instance */
}
...
if (!tracefs_trace_on(NULL)) {
/* Enabled tracing in the top instance */
...
if (!tracefs_trace_off(NULL)) {
/* Disabled tracing in the top instance */
} else {
/* Error disabling tracing in the top instance */
}
} else {
/* Error enabling tracing in the top instance */
}
...
int fd = tracefs_trace_on_get_fd(NULL);
if (fd < 0) {
/* Error opening tracing_on file */
}
...
if (!tracefs_trace_on_fd(fd)) {
/* Enabled tracing in the top instance */
...
if (!tracefs_trace_off_fd(fd)) {
/* Disabled tracing in the top instance */
} else {
/* Error disabling tracing in the top instance */
}
} else {
/* Error enabling tracing in the top instance */
}
...
close(fd);
see? open it, flip it, flip it back, close it. the whole character arc π«Ά
π FILES π
tracefs.hβ the header file you include so you actually get access to the library APIs. don't forget it, bestie, it's kind of important.-ltracefsβ the linker switch you add when building a program that uses the library. link it or it simply won't work π
π SEE ALSO π
libtracefs(3), libtraceevent(3), trace-cmd(1)
go read those too, they're all in the same friend group π
π AUTHOR π
- Steven Rostedt
<rostedt@goodmis.org> - Tzvetomir Stoyanov
<tz.stoyanov@gmail.com>
π REPORTING BUGS π
found a bug? report it to <linux-trace-devel@vger.kernel.org>. they're nice, i promise π
β LICENSE β
libtracefs is Free Software licensed under the GNU LGPL 2.1. periodt.
π§ RESOURCES π§
https://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git/
that's the repo, go wild β¨
π COPYING π
Copyright (C) 2021 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!! π this was libtracefs version 1.8.4, dated 10/21/2026 β shoutout to the libtracefs girlies, go enable some tracing for me, 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