LIBTRACECMD(3)
π¦ LIBTRACECMD(3) β the libtracefs manual, bestie edition β¨
okay so this page is from the libtracefs manual, and it's literally all about peeking at tracing instances that are chillin' inside a trace file. let's get into it π
πΈ NAME πΈ
tracecmd_buffer_instances, tracecmd_buffer_instance_name, tracecmd_buffer_instance_handle β the little trio that lets you read tracing instances out of a trace file. that's the whole vibe π«Ά
β¨ SYNOPSIS β¨
#include <trace-cmd.h>
int tracecmd_buffer_instances(struct tracecmd_input *handle);
const char *tracecmd_buffer_instance_name(struct tracecmd_input *handle, int indx);
struct tracecmd_input *tracecmd_buffer_instance_handle(struct tracecmd_input *handle, int indx);
π DESCRIPTION π
so this whole set of APIs is your go-to for getting info and reading tracing data from tracing instances that are stored inside a trace file. iconic behavior tbh.
tracecmd_buffer_instances() gets you the number of tracing instances recorded in a trace file. β οΈ heads up: the top instance is not counted, so don't come for me when the number's smaller than you expected. the handle is a tracecmd_input handler that came from tracecmd_open_head().
tracecmd_buffer_instance_name() gets you the name of the tracing instance at the given index indx, recorded in a trace file. the indx is a number in the interval [0 .. count-1], where count is the number that tracecmd_buffer_instances() gave you. and yeah, the handle is a tracecmd_input handler returned by tracecmd_open_head().
tracecmd_buffer_instance_handle() allocates and initializes a tracecmd_input handle that's associated with the trace instance at index indx from a trace file. again: handle is a tracecmd_input handler from tracecmd_open_head(), and indx is in the interval [0 .. count-1] where count came from tracecmd_buffer_instances(). slay, consistent indexing π
π₯ RETURN VALUE π₯
tracecmd_buffer_instances()β returns the number of tracing instances recorded in a trace file. it's giving "just a number, no drama" β¨tracecmd_buffer_instance_name()β returns a string, the name of a tracing instance, orNULLin case of an error. > π¨ the string must not be freed. like, do not touch it. put your hands down. it's not yours πtracecmd_buffer_instance_handle()β returns a pointer to a newly allocatedtracecmd_inputhandler, orNULLin case of an error. > πΈ the returned handler must be closed bytracecmd_close()(3)β don't just leave it hanging, that's rude.
π§ EXAMPLE π§
here's the whole thing in action, bestie π
#include <trace-cmd.h>
...
struct tracecmd_input *handle = tracecmd_open_head("trace.dat");
if (!handle) {
/* Failed to open trace.dat file */
}
...
int num = tracecmd_buffer_instances(handle);
while(num) {
struct tracecmd_input *h;
char *name;
name = tracecmd_buffer_instance_name(handle, num);
if (!name) {
/* Failed to get name of instance num */
}
h = tracecmd_buffer_instance_handle(handle, num);
if (!h) {
/* Failed to initialize handler for instance num */
}
...
tracecmd_close(h);
num--;
}
...
tracecmd_close(handle);
see how we open it, loop through, close every h, then close the main handle? that's the self-care routine π
π FILES π
trace-cmd.hβ the header file to include so you actually have access to the library APIs. no include, no vibes.-ltracecmdβ the linker switch to add when you're building a program that uses the library. don't forget it, or the linker will simply not know her π
π SEE ALSO π
libtracefs(3), libtraceevent(3), trace-cmd(1) trace-cmd.dat(5)
π 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're lovely, promise π«Ά
β LICENSE β
libtracecmd is Free Software licensed under the GNU LGPL 2.1. free as in freedom, bestie β¨
π RESOURCES π
https://git.kernel.org/pub/scm/utils/trace-cmd/trace-cmd.git/
go forth and clone π₯
π 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
k that's the whole page!! π this was the libtracefs manual, dated 03/09/2026, page LIBTRACECMD(3) β mwah, go read your trace files, ily ππ¦
π¦ where this page comes from
- arch rolling: trace-cmd 3.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