LIBTRACEFS(3)

πŸ’… LIBTRACEFS(3) πŸ’…

okay so bestie, welcome to the libtracefs manual page πŸ¦‹ β€” this one's about the little family of functions that let you write formatted strings straight into the kernel trace buffer. yes, from user space. yes, it's giving main character energy. let's go ✨


🌸 NAME 🌸

tracefs_print_init, tracefs_print_close, tracefs_printf, tracefs_vprintf β€” open, close and write formated strings in the trace buffer. that's the whole vibe, no cap πŸ’–


✨ SYNOPSIS ✨

#include <tracefs.h>

int tracefs_print_init(struct tracefs_instance *instance);
int tracefs_printf(struct tracefs_instance *instance, const char *fmt, ...);
int tracefs_vprintf(struct tracefs_instance *instance, const char *fmt, va_list ap);
void tracefs_print_close(struct tracefs_instance *instance);

like, copy that header include exactly, don't come at me with a typo πŸ™ˆ


πŸŽ€ DESCRIPTION πŸŽ€

so this is a whole set of functions for writing formated strings into the trace buffer. for the full tea on writing data from user space into the trace buffer, go read Documentation/trace/ftrace.rst from the Linux kernel tree β€” that's the source of truth, iykyk.

all of these APIs take instance as the first argument, periodt. and if you pass NULL as instance, it just uses the top trace instance. easy. 🫢

  • tracefs_print_init() β€” this one initializes the library for writing into the trace buffer of the selected instance. and listen, it is not mandatory to call this before writing strings β€” any of the printf APIs will call it automatically if the library isn't yet initialized. but calling tracefs_print_init() in advance will speed up the writing, so like... do it? ⭐
  • tracefs_printf() β€” writes a formatted string into the trace buffer of the selected instance. the fmt argument is a string in printf format, followed by variable arguments .... classic printf behavior, slay πŸ”₯
  • tracefs_vprintf() β€” writes a formatted string into the trace buffer of the selected instance. the fmt argument is a string in printf format, followed by list ap of arguments. the va_list girlies know πŸ’…
  • tracefs_print_close() β€” closes the resources used by the library for writing in the trace buffer of the selected instance. clean up after yourself bestie 🧹

πŸ‘‘ RETURN VALUE πŸ‘‘

tracefs_print_init(), tracefs_printf(), and tracefs_vprintf() all return 0 if the operation is successful, or -1 in case of an error. that's it. zero is the good number, -1 means something went off 😭


πŸ¦‹ EXAMPLE πŸ¦‹

okay here's the whole thing, verbatim, don't @ me:

#include <tracefs.h>

if (tracefs_print_init(NULL) < 0) {
 /* Failed to initialize the library for writing in the trace buffer of the top trace instance */
}

void foo_print(char *format, ...)
{
        va_list ap;
        va_start(ap, format);
        if (tracefs_vprintf(NULL, format, ap) < 0) {
                /* Failed to print in the trace buffer */
        }
        va_end(ap);
}

void foo_print_string(char *message)
{
        if (tracefs_printf(NULL, "Message from user space: %s", message) < 0) {
                /* Failed to print in the trace buffer */
        }
}

tracefs_print_close();

literally the blueprint πŸ’– notice tracefs_print_close(); there at the end β€” yes, that's exactly how it's written in the original, so keep it that way ✨


🌈 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), Documentation/trace/ftrace.rst from the Linux kernel tree

go read the friends too, they're iconic πŸ’œ


🌸 AUTHOR 🌸

  • Steven Rostedt <rostedt@goodmis.org[1]>
  • Tzvetomir Stoyanov <tz.stoyanov@gmail.com[2]>

legends, fr fr πŸ‘‘


πŸ’€ REPORTING BUGS πŸ’€

report bugs to <linux-trace-devel@vger.kernel.org[3]>

like please actually report them, don't just suffer in silence πŸ™ˆ


⭐ LICENSE ⭐

libtracefs is Free Software licensed under the GNU LGPL 2.1


πŸŽ€ RESOURCES πŸŽ€

https://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git/

the repo. go look. bookmark it. πŸ¦‹


πŸ’– COPYING πŸ’–

Copyright (C) 2021 VMware, Inc. Free use of this software is granted under the terms of the GNU Public License (GPL).


✨ NOTES ✨

  1. rostedt@goodmis.org mailto:rostedt@goodmis.org
  2. tz.stoyanov@gmail.com mailto:tz.stoyanov@gmail.com
  3. linux-trace-devel@vger.kernel.org mailto:linux-trace-devel@vger.kernel.org

and that's the page bestie 🫢 this was libtracefs 1.8.4, dated 10/21/2026, brought to you by the libtracefs Manual. go write some strings into that trace buffer, you absolute icon πŸ’…βœ¨πŸŒ·

πŸ“¦ where this page comes from