LIBTRACEFS(3)
π LIBTRACEFS(3) β the libtracefs girlies' guide π
okay so bestie, this is a page from the libtracefs manual (yes, manual section 3, the library-call one π«Ά) and it's literally all about the histogram lifecycle: pausing it, continuing it, resetting it, or straight-up clearing it. no cap, it's giving "remote control for your histogram" energy β¨
πΈ NAME πΈ
tracefs_hist_start, tracefs_hist_destroy, tracefs_hist_pause, tracefs_hist_continue, tracefs_hist_reset β pause, continue, or clear an existing histogram π
π SYNOPSIS π
#include <tracefs.h>
int tracefs_hist_start(struct tracefs_instance *instance, struct tracefs_hist *hist);
int tracefs_hist_destroy(struct tracefs_instance *instance, struct tracefs_hist *hist);
int tracefs_hist_pause(struct tracefs_instance *instance, struct tracefs_hist *hist);
int tracefs_hist_continue(struct tracefs_instance *instance, struct tracefs_hist *hist);
int tracefs_hist_reset(struct tracefs_instance *instance, struct tracefs_hist *hist);
β¨ DESCRIPTION β¨
So let's do the vibe check on each one, bestie π every single one of these takes an instance (the instance you're doing the thing in β and if you pass NULL, it does the thing at the top level, iykyk π) plus the hist you're messing with.
tracefs_hist_start()β this is the one you actually call to actually start the histogramhist.instanceis the instance to start the histogram in,NULLif it should start at the top level βtracefs_hist_pause()β called to pause the histogramhist.instanceis the instance to pause the histogram in,NULLif it is in the top level βΈοΈtracefs_hist_continue()β called to continue a paused histogramhist(yes bestie, resume her π).instanceis the instance to continue the histogram,NULLif it is in the top level βΆοΈtracefs_hist_reset()β called to clear / reset the histogramhist.instanceis the instance to clear the histogram,NULLif it is in the top level π§Όtracefs_hist_destroy()β called to delete the histogram, where it will no longer exist π (fr fr, gone gone).instanceis the instance to delete the histogram from,NULLif it is in the top level
lowkey important: destroy is not a soft "hide it" moment β the manpage says it will no longer exist. so like, be sure before you yeet it π
π¦ RETURN VALUE π¦
Every single one of them returns zero on success or -1 on error. that's it, that's the whole mood π
π₯ EXAMPLE π₯
here's the full program, verbatim, no cap π
#include <stdlib.h>
#include <tracefs.h>
enum commands {
START,
PAUSE,
CONT,
RESET,
DELETE,
SHOW,
};
int main (int argc, char **argv, char **env)
{
struct tracefs_instance *instance;
struct tracefs_hist *hist;
struct tep_handle *tep;
enum commands cmd;
char *cmd_str;
int ret;
if (argc < 2) {
fprintf(stderr, "usage: %s command\n", argv[0]);
exit(-1);
}
cmd_str = argv[1];
if (!strcmp(cmd_str, "start"))
cmd = START;
else if (!strcmp(cmd_str, "pause"))
cmd = PAUSE;
else if (!strcmp(cmd_str, "cont"))
cmd = CONT;
else if (!strcmp(cmd_str, "reset"))
cmd = RESET;
else if (!strcmp(cmd_str, "delete"))
cmd = DELETE;
else if (!strcmp(cmd_str, "show"))
cmd = SHOW;
else {
fprintf(stderr, "Unknown command %s\n", cmd_str);
exit(-1);
}
tep = tracefs_local_events(NULL);
if (!tep) {
perror("Reading tracefs");
exit(-1);
}
instance = tracefs_instance_create("hist_test");
if (!instance) {
fprintf(stderr, "Failed instance create\n");
exit(-1);
}
hist = tracefs_hist_alloc_2d(tep, "kmem", "kmalloc",
"call_site",TRACEFS_HIST_KEY_SYM,
"bytes_req", 0);
if (!hist) {
fprintf(stderr, "Failed hist create\n");
exit(-1);
}
ret = tracefs_hist_add_value(hist, "bytes_alloc");
ret |= tracefs_hist_add_sort_key(hist, "bytes_req");
ret |= tracefs_hist_add_sort_key(hist, "bytes_alloc");
ret |= tracefs_hist_sort_key_direction(hist, "bytes_alloc",
TRACEFS_HIST_SORT_DESCENDING);
if (ret) {
fprintf(stderr, "Failed modifying histogram\n");
exit(-1);
}
tracefs_error_clear(instance);
switch (cmd) {
case START:
ret = tracefs_hist_start(instance, hist);
if (ret) {
char *err = tracefs_error_last(instance);
if (err)
fprintf(stderr, "\n%s\n", err);
}
break;
case PAUSE:
ret = tracefs_hist_pause(instance, hist);
break;
case CONT:
ret = tracefs_hist_continue(instance, hist);
break;
case RESET:
ret = tracefs_hist_reset(instance, hist);
break;
case DELETE:
ret = tracefs_hist_destroy(instance, hist);
break;
case SHOW: {
char *content;
content = tracefs_event_file_read(instance, "kmem", "kmalloc",
"hist", NULL);
ret = content ? 0 : -1;
if (content) {
printf("%s\n", content);
free(content);
}
break;
}
}
if (ret)
fprintf(stderr, "Failed: command\n");
exit(ret);
}
π§ FILES π§
tracefs.hβ the header file to include so you have access to the library APIs π«Ά-ltracefsβ the linker switch to add when building a program that uses the library π
π SEE ALSO π
libtracefs(3), libtraceevent(3), trace-cmd(1), tracefs_hist_alloc(3), tracefs_hist_alloc_2d(3), tracefs_hist_alloc_nd(3), tracefs_hist_free(3), tracefs_hist_add_key(3), tracefs_hist_add_value(3), tracefs_hist_add_name(3), tracefs_hist_start(3), tracefs_hist_destory(3), tracefs_hist_add_sort_key(3), tracefs_hist_sort_key_direction(3)
just gonna say it β yes, tracefs_hist_destory(3) is spelled exactly like that in the original list bestie, I'm just the messenger π
π AUTHOR π
- Steven Rostedt
<rostedt@goodmis.org[1]> - Tzvetomir Stoyanov
<tz.stoyanov@gmail.com[2]> - sameeruddin shaik
<sameeruddin.shaik8@gmail.com[3]>
π REPORTING BUGS π
Report bugs to <linux-trace-devel@vger.kernel.org[4]> β they wanna hear 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) 2020 VMware, Inc. Free use of this software is granted under the terms of the GNU Public License (GPL).
π NOTES π
rostedt@goodmis.orgβmailto:rostedt@goodmis.orgtz.stoyanov@gmail.comβmailto:tz.stoyanov@gmail.comsameeruddin.shaik8@gmail.comβmailto:sameeruddin.shaik8@gmail.comlinux-trace-devel@vger.kernel.orgβmailto:linux-trace-devel@vger.kernel.org
aaaand that's the whole page bestie π this was libtracefs 1.8.4, dated 10/21/2026 β go forth and pause your histograms responsibly, mwah ππ¦
π¦ 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