LIBTRACEFS(3)

πŸ’… LIBTRACEFS(3) β€” the libtracefs manual, bestie edition ✨

okay so this is the libtracefs manual page, and today we're talking about the binary-writing girlies πŸŽ€ (and yes, the manual name is literally libtracefs in case you were wondering πŸ’–)


✨ NAME ✨

tracefs_binary_init, tracefs_binary_close, tracefs_binary_write β€” the trio that opens, closes, and writes binary data into the trace buffer. no cap, that's the whole vibe. πŸ¦‹


🌸 SYNOPSIS 🌸

#include <tracefs.h>

int tracefs_binary_init(struct tracefs_instance *instance);
int tracefs_binary_write(struct tracefs_instance *instance, void *data, int len);
void tracefs_binary_close(struct tracefs_instance *instance);

πŸ’œ DESCRIPTION πŸ’œ

so this is a little set of functions that write binary data into the trace buffer. if you want the deep lore, go read Documentation/trace/ftrace.rst from the Linux kernel tree β€” that's where all the writing-from-user-space-into-the-trace-buffer info lives. πŸ“–

all of these APIs take instance as their first argument. and if you pass NULL as instance? the top trace instance gets used. easy. 😌

  • tracefs_binary_init() β€” initializes the library for writing into the trace buffer of whichever instance you picked. and listen β€” it is not mandatory to call this before writing data, because tracefs_binary_write() will call it automatically if the library isn't initialized yet. but calling tracefs_binary_init() in advance will speed up the writing. so like… technically optional, but iconically efficient. πŸ”₯
  • tracefs_binary_write() β€” writes a binary blob into the trace buffer of the selected instance. data points to the data, and its length is len β€” that's what's going into the trace buffer. πŸ’«
  • tracefs_binary_close() β€” closes the resources the library used for writing into the trace buffer of the selected instance. cleanup era, we love to see it. 🧹✨

⭐ RETURN VALUE ⭐

tracefs_binary_init() and tracefs_binary_write() both return 0 if the operation is successful, or -1 if something went wrong. that's it, that's the check. πŸ’€


πŸ¦‹ EXAMPLE πŸ¦‹

#include <tracefs.h>

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

unsigned int data = 0xdeadbeef;

        if (tracefs_binary_write(NULL, &data, sizeof(data)) < 0) {
                /* Failed to write in the trace buffer */
        }

tracefs_binary_close();

she's writing 0xdeadbeef and closing up shop. main character energy honestly. πŸ‘‘


πŸŽ€ FILES πŸŽ€

  • tracefs.h β€” the header file you include to get access to the library APIs. manifesting those declarations for you. πŸ™
  • -ltracefs β€” the linker switch you add when building a program that uses the library. don't forget her, fr fr. πŸ’…

🌈 SEE ALSO 🌈

libtracefs(3), libtraceevent(3), trace-cmd(1), and Documentation/trace/ftrace.rst from the Linux kernel tree β€” the whole friend group 🫢


πŸ’– AUTHOR πŸ’–

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

πŸ™ˆ REPORTING BUGS πŸ™ˆ

found a bug? report it to <linux-trace-devel@vger.kernel.org[3]> β€” they wanna know, bestie. 😭


πŸ‘‘ LICENSE πŸ‘‘

libtracefs is Free Software licensed under the GNU LGPL 2.1 πŸ’œ


πŸ”₯ RESOURCES πŸ”₯

https://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git/ β€” go look, it's giving open source excellence ✨


🌸 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 whole page, bestie! πŸ₯³ this was libtracefs version 1.8.4, dated 10/21/2026 β€” write it down, screenshot it, put it in the group chat, whatever you gotta do. love u, go write some binary data into that trace buffer πŸ’…βœ¨πŸ«Ά

πŸ“¦ where this page comes from