LIBTRACECMD(3)
π LIBTRACECMD(3) β the libtracecmd glow-up
okay so bestie, grab a snack π because this is the manual page for libtracecmd, one of the libtracefs family of manual pages (yes, the top-of-page name says libtracefs, that's her house π ). She's the library that lets your code read, parse and write trace files, and honestly? iconic.
β¨ NAME β¨
libtracecmd β the trace-cmd library APIs π
πΈ SYNOPSIS πΈ
#include <trace-cmd.h>
Open and close trace file:
struct tracecmd_input *tracecmd_open(const char *file, int flags);
struct tracecmd_input *tracecmd_open_fd(int fd, int flags);
struct tracecmd_input *tracecmd_open_head(const char *file, int flags);
void tracecmd_close(struct tracecmd_input *handle);
void tracecmd_set_private(struct tracecmd_input *handle, void *data);
void *tracecmd_get_private(struct tracecmd_input *handle);
Read tracing records from a trace file:
int tracecmd_init_data(struct tracecmd_input *handle);
struct tep_record *tracecmd_read_cpu_first(struct tracecmd_input *handle, int cpu);
struct tep_record *tracecmd_read_data(struct tracecmd_input *handle, int cpu);
struct tep_record *tracecmd_read_at(struct tracecmd_input *handle, unsigned long long offset, int *cpu);
void tracecmd_free_record(struct tep_record *record);
struct tep_handle *tracecmd_get_tep(struct tracecmd_input *handle);
Iterating over events in a trace file:
int tracecmd_iterate_events(struct tracecmd_input *handle,
cpu_set_t *cpus, int cpu_size,
int (*callback)(struct tracecmd_input *,
struct tep_record *,
int, void *),
void *callback_data);
int tracecmd_iterate_events_multi(struct tracecmd_input **handles,
int nr_handles,
int (*callback)(struct tracecmd_input *,
struct tep_record *,
int, void *),
void *callback_data);
int tracecmd_iterate_events_reverse(struct tracecmd_input *handle,
cpu_set_t *cpus, int cpu_size,
int (*callback)(struct tracecmd_input *,
struct tep_record *,
int, void *),
void *callback_data, bool cont);
int tracecmd_follow_event(struct tracecmd_input *handle,
const char *system, const char *event_name,
int (*callback)(struct tracecmd_input *,
struct tep_event *,
struct tep_record *,
int, void *),
void *callback_data);
int tracecmd_follow_missed_events(struct tracecmd_input *handle,
int (*callback)(struct tracecmd_input *,
struct tep_event *,
struct tep_record *,
int, void *),
void *callback_data);
struct tracecmd_filter *tracecmd_filter_add(struct tracecmd_input handle,
const char *filter_str, bool neg);
int *tracecmd_iterate_reset(struct tracecmd_input *handle);
Read tracing instances from a trace file:
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);
Handle time stamps from a trace file:
unsigned long long tracecmd_get_first_ts(struct tracecmd_input *handle);
void tracecmd_add_ts_offset(struct tracecmd_input *handle, long long offset);
int tracecmd_get_tsc2nsec(struct tracecmd_input *handle, int *mult, int pass[]shift, unsigned long long *offset);
that last one is written exactly like that, bestie β int pass[]shift β copy it character for character, no "fixing" it π
Get traceing peer information from a trace file:
unsigned long long *tracecmd_get_traceid(struct tracecmd_input *handle);
int tracecmd_get_guest_cpumap(struct tracecmd_input *handle, unsigned long long trace_id, const char **name, int *vcpu_count, const int **cpu_pid);
Mapping host and guest trace files:
int tracecmd_map_vcpus(struct tracecmd_input **handles, int nr_handles);
struct tracecmd_cpu_map *tracecmd_get_cpu_map(struct tracecmd_input *handle, int cpu);
struct tracecmd_cpu_map *tracecmd_map_find_by_host_pid(struct tracecmd_input *handle,
int host_pid);
int tracecmd_map_get_host_pid(struct tracecmd_cpu_map *map);
struct tracecmd_input *tracecmd_map_get_guest(struct tracecmd_cpu_map *map);
void tracecmd_map_set_private(struct tracecmd_cpu_map *map, void *priv);
void *tracecmd_map_get_private(struct tracecmd_cpu_map *map);
Control library logs:
int tracecmd_set_loglevel(enum tep_loglevel level);
π¦ DESCRIPTION π¦
So like, the libtracecmd(3) library hands you the APIs to read, parse and write trace-cmd.dat(5) files π«Ά. These are the files recorded with the trace-cmd(1) application, and they're carrying tracing information from ftrace, aka the official Linux kernel tracer π.
Read it. Parse it. Write it. She does it all, no cap β¨
π FILES π
trace-cmd.hβ the header file you include so the library APIs are actually available to you π-ltracecmdβ the linker switch you add when building a program that uses the library π
π SEE ALSO π
libtraceevent(3) libtracefs(3) trace-cmd(1) trace-cmd.dat(5)
π AUTHOR π
- Steven Rostedt
<rostedt@goodmis.org[1]> - Tzvetomir Stoyanov
<tz.stoyanov@gmail.com[2]>
π REPORTING BUGS π
Spotted something cursed? Report bugs to <linux-trace-devel@vger.kernel.org[3]> β the devs want to know, fr fr π
β LICENSE β
libtracecmd is Free Software licensed under the GNU LGPL 2.1 π§
π RESOURCES π
https://git.kernel.org/pub/scm/utils/trace-cmd/trace-cmd.git/ β go browse, bestie π¦
π 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
okay that's the whole page, you ate that π
this gorgeous thing comes from the libtracefs manual set, dated 03/09/2026, and the man page itself is LIBTRACECMD(3). go forth and trace, main character π«Άπ₯
π¦ 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