LIBTRACEFS(3)
β¨ LIBTRACEFS(3) β¨
okay bestie, welcome to the libtracefs Manual π this one is all about the little functions that let you poke at trace event files without losing your whole entire mind. it's giving "I know the system and the event already, just gimme the file" energy, and honestly? iconic.
πΈ NAME πΈ
tracefs_event_get_file, tracefs_event_file_read, tracefs_event_file_write, tracefs_event_file_append, tracefs_event_file_clear, tracefs_event_file_exists β literally all the functions for working with trace event files π
π¦ SYNOPSIS π¦
#include <tracefs.h>
char *tracefs_event_get_file(struct tracefs_instance *instance, const char *system, const char *event,
const char *file);
char *tracefs_event_file_read(struct tracefs_instance *instance, const char *system, const char *event,
const char *file, int *psize);
int tracefs_event_file_write(struct tracefs_instance *instance, const char *system, const char *event,
const char *file, const char *str);
int tracefs_event_file_append(struct tracefs_instance *instance, const char *system, const char *event,
const char *file, const char *str);
int tracefs_event_file_clear(struct tracefs_instance *instance, const char *system, const char *event,
const char *file);
bool tracefs_event_file_exists(struct tracefs_instance *instance, const char *system, const char *event,
const char *file);
π DESCRIPTION π
so these are the functions for getting at tracefs event-specific files. they do the same kind of thing as the tracefs instance file functions, but they're way easier to reach when you already know the system and the event upfront. no cap, it's just less running around.
tracefs_event_get_file()β returns the full path of the file for the given system and event, inside the given instance. if instance isNULL, you get the file for that event in the top level instance instead. β οΈ heads up though: it does not check whether the file actually exists, and it doesn't even check whether the system and event exist. it just builds the path name for that event as if it did exist. this behaves liketracefs_instance_get_file(3), but it's the one you use to get to event files when the system and event are already known.tracefs_event_file_read()β reads the content of the event file for the given instance, or the top level instance if instance isNULL. you get the content back, and psize is set to the amount of data that was read. the returned content must be freed withfree(3). behaves liketracefs_instance_file_read(3), but for reading the event file when the system and event are already known.tracefs_event_file_write()β writes str to the event file. it truncates anything already in that file, so don't say I didn't warn you π. behaves liketracefs_instance_file_write(3), but for the event file when the system and event are already known.tracefs_event_file_append()β appends str to the event file. it does not clear out the file when it writes the string. behaves liketracefs_instance_file_append(3), but for the event file when the system and event are already known.tracefs_event_file_clear()β clears the content of the event file. behaves liketracefs_instance_file_clear(3), but for the event file when the system and event are already known.tracefs_event_file_exists()β returnstrueif the event file exists, andfalseotherwise. behaves liketracefs_instance_file_exists(3), but for the event file when the system and event are already known.
π«Ά RETURN VALUE π«Ά
tracefs_event_get_file()β returns the path of the given system/event file on success, andNULLon error. you gotta free that return value withtracefs_put_tracing_file(3).tracefs_event_file_read()β reads the content of the system/event file, or returnsNULLon error. the returned pointer must be freed withfree(3).tracefs_event_file_write()andtracefs_event_file_append()β return the number of bytes written to the system/event file, or a negative value on error.tracefs_event_file_clear()β returns zero on success, and-1on error.tracefs_event_file_exists()β returnstrueif the system/event file exists for the given instance (or top level if instance isNULL), orfalseotherwise.
π§ EXAMPLE π§
here's the whole demo program, copied exactly because we do not mess with code in this house π
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <tracefs.h>
int main(int argc, char **argv)
{
char *system;
char *event;
char *file;
char *cmd = NULL;
char *buf;
char *str;
char ch = 'r';
int size;
if (argc < 4) {
printf("usage: %s sytem event file [(-a|-w) write | -c]\n"
" reads the system/event file or writes if [write is supplied]\n",
argv[0]);
exit(0);
}
system = argv[1];
event = argv[2];
file = argv[3];
if (argc > 4)
cmd = argv[4];
if (!tracefs_event_file_exists(NULL, system, event, file)) {
fprintf(stderr, "File %s/%s/%s does not exist\n",
system, event, file);
exit(-1);
}
if (cmd) {
if (cmd[0] != '-')
ch = cmd[0];
else
ch = cmd[1];
if (!ch)
ch = 'c';
}
switch (ch) {
case 'r':
buf = tracefs_event_file_read(NULL, system, event, file, &size);
if (buf)
printf("%s", buf);
else
fprintf(stderr, "Failed to read %s/%s/%s\n",
system, event, file);
free(buf);
break;
case 'w':
case 'a':
if (argc < 6) {
fprintf(stderr, "%s command requires something to write\n",
ch == 'w' ? "write" : "append");
exit(-1);
}
if (ch == 'w')
size = tracefs_event_file_write(NULL, system, event, file, argv[5]);
else
size = tracefs_event_file_append(NULL, system, event, file, argv[5]);
if (size < 0) {
fprintf(stderr, "Failed to write '%s' to %s/%s/%s\n",
argv[5], system, event, file);
exit(-1);
}
break;
case 'c':
if (tracefs_event_file_clear(NULL, system, event, file) < 0) {
fprintf(stderr, "Failed to clear %s/%s/%s\n",
system, event, file);
exit(-1);
}
break;
default:
fprintf(stderr, "Unknown command '%c'\n", ch);
exit(-1);
}
exit(0);
}
π FILES π
tracefs.hβ the header file you include so you can actually use the library APIs π-ltracefsβ the linker switch you add when building a program that uses the library.
π SEE ALSO π
libtracefs(3), libtraceevent(3), trace-cmd(1)
π AUTHOR π
Steven Rostedt <rostedt@goodmis.org>
π REPORTING BUGS π
report bugs to <linux-trace-devel@vger.kernel.org> β they wanna hear about it, fr fr.
π 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) 2022 Google, Inc. Free use of this software is granted under the terms of the GNU Public License (GPL).
π NOTES π
rostedt@goodmis.orgmailto:rostedt@goodmis.orglinux-trace-devel@vger.kernel.orgmailto:linux-trace-devel@vger.kernel.org
and that's the whole page bestie π¦β¨ this was libtracefs 1.8.4, dated 10/21/2026 β go forth and read those event files, you absolute main character π
π
π¦ 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