'\" t .\" Title: libtracecmd .\" Author: [see the "AUTHOR" section] .\" Generator: DocBook XSL Stylesheets vsnapshot .\" Date: 05/12/2022 .\" Manual: libtracefs Manual .\" Source: libtracefs .\" Language: English .\" .TH "LIBTRACECMD" "3" "05/12/2022" "libtracefs" "libtracefs Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" tracecmd_open, tracecmd_open_fd, tracecmd_open_head, tracecmd_init_data, tracecmd_close \- Open and close a trace file\&. .SH "SYNOPSIS" .sp .nf \fB#include \fR struct tracecmd_input *\fBtracecmd_open\fR(const char *\fIfile\fR, int \fIflags\fR); struct tracecmd_input *\fBtracecmd_open_fd\fR(int \fIfd\fR, int \fIflags\fR); struct tracecmd_input *\fBtracecmd_open_head\fR(const char *\fIfile\fR, int \fIflags\fR); int \fBtracecmd_init_data\fR(struct tracecmd_input *\fIhandle\fR); void \fBtracecmd_close\fR(struct tracecmd_input *\fIhandle\fR); .fi .SH "DESCRIPTION" .sp This set of APIs can be used to open and close a trace file recorded by \fItrace\-cmd(1)\fR and containing tracing information from ftrace, the official Linux kernel tracer\&. The opened file is represented by a \fItracecmd_input\fR structure, all other library APIs that work with the file require a pointer to the structure\&. The APIs for opening a trace file have a \fIflag\fR input parameter, which controls how the file will be opened and parsed\&. The \fIflag\fR is a combination of these options: .sp .if n \{\ .RS 4 .\} .nf TRACECMD_FL_LOAD_NO_PLUGINS \- Do not load any plugins TRACECMD_FL_LOAD_NO_SYSTEM_PLUGINS \- Do not load system wide plugins, load only "local only" plugins from user\*(Aqs home directory\&. .fi .if n \{\ .RE .\} .sp The \fItracecmd_open()\fR function opens a given trace \fIfile\fR, parses the metadata headers from the file, allocates and initializes а \fItracecmd_input\fR handler structure representing the file\&. It also initializes the handler for reading trace data from the file\&. The returned handler is ready to be used with \fItracecmd_read_\fR APIs\&. .sp The \fItracecmd_open_fd()\fR function does the same as \fItracecmd_open()\fR, but works with a file descriptor to a trace file, opened for reading\&. .sp The \fItracecmd_open_head()\fR function is the same as \fItracecmd_open()\fR, but does not initialize the handler for reading trace data\&. It reads and parses the metadata headers only\&. The \fItracecmd_init_data()\fR should be used before using the \fItracecmd_read_\fR APIs\&. .sp The \fItracecmd_init_data()\fR function initializes a \fIhandle\fR, allocated with \fItracecmd_open_head()\fR, for reading trace data from the file associated with it\&. This API must be called before any of the \fItracecmd_read_\fR APIs\&. .sp The \fItracecmd_close()\fR function frees a \fIhandle\fR, pointer to tracecmd_input structure, previously allocated with \fItracecmd_open()\fR, \fItracecmd_open_fd()\fR or \fItracecmd_open_head()\fR APIs\&. .SH "RETURN VALUE" .sp The \fItracecmd_open()\fR, \fItracecmd_open_fd()\fR and \fItracecmd_open_head()\fR functions return a pointer to tracecmd_input structure or NULL in case of an error\&. The returned structure must be free with \fItracecmd_close()\fR\&. Note that if \fItracecmd_open_fd()\fR is used to allocate a tracecmd_input handler, when \fItracecmd_close()\fR is called to close it, that fd will be closed also\&. .sp The \fItracecmd_init_data()\fR function returns \-1 in case of an error or 0 otherwise\&. .SH "EXAMPLE" .sp .if n \{\ .RS 4 .\} .nf The are two different use patterns for opening and reading trace data from a trace file, which can be used depending on the use case\&. 1\&. Open and initialise the trace file in а single step: #include \&.\&.\&. struct tracecmd_input *handle = tracecmd_open("trace\&.dat"); if (!handle) { /* Failed to open trace\&.dat file */ } \&.\&.\&. /* Read tracing data from the file, using the handle */ \&.\&.\&. tracecmd_close(handle); \&.\&.\&. int fd; fd = = open("trace\&.dat", O_RDONLY); if (fd < 0) { /* Failed to open trace file for reading */ } handle = tracecmd_open_fd(fd); if (!handle) { close(fd); /* Failed to initialise handler for reading the trace file */ } \&.\&.\&. /* Read tracing data from the file, using the handle */ \&.\&.\&. tracecmd_close(handle); \&.\&.\&. 2\&. Open and initialise the trace file in two steps\&. This allows to perform some processing based on metadata, read from the file, before initialising the trace data for reading\&. Example for such use case is when opening multiple trace files recorded in a same trace session\&. In that case timestamps of all trace events must be adjusted based on the information from the file\*(Aqs metadata and before reading the trace data\&. #include \&.\&.\&. struct tracecmd_input *handle = tracecmd_open_head("trace\&.dat"); if (!handle) { /* Failed to open trace\&.dat file */ } \&.\&.\&. /* do some processing, before initialising the trace data for reading */ \&.\&.\&. if (tracecmd_init_data(handle) < 0) { /* Failed to initialize hadle for reading the trace data */ } \&.\&.\&. /* Read tracing data from the file, using the handle */ \&.\&.\&. tracecmd_close(handle); \&.\&.\&. .fi .if n \{\ .RE .\} .SH "FILES" .sp .if n \{\ .RS 4 .\} .nf \fBtrace\-cmd\&.h\fR Header file to include in order to have access to the library APIs\&. \fB\-ltracecmd\fR Linker switch to add when building a program that uses the library\&. .fi .if n \{\ .RE .\} .SH "SEE ALSO" .sp \fIlibtracefs(3)\fR, \fIlibtraceevent(3)\fR, \fItrace\-cmd(1)\fR \fItrace\-cmd\&.dat(5)\fR .SH "AUTHOR" .sp .if n \{\ .RS 4 .\} .nf \fBSteven Rostedt\fR <\m[blue]\fBrostedt@goodmis\&.org\fR\m[]\&\s-2\u[1]\d\s+2> \fBTzvetomir Stoyanov\fR <\m[blue]\fBtz\&.stoyanov@gmail\&.com\fR\m[]\&\s-2\u[2]\d\s+2> .fi .if n \{\ .RE .\} .SH "REPORTING BUGS" .sp Report bugs to <\m[blue]\fBlinux\-trace\-devel@vger\&.kernel\&.org\fR\m[]\&\s-2\u[3]\d\s+2> .SH "LICENSE" .sp libtracecmd is Free Software licensed under the GNU LGPL 2\&.1 .SH "RESOURCES" .sp \m[blue]\fBhttps://git\&.kernel\&.org/pub/scm/utils/trace\-cmd/trace\-cmd\&.git/\fR\m[] .SH "COPYING" .sp Copyright (C) 2020 VMware, Inc\&. Free use of this software is granted under the terms of the GNU Public License (GPL)\&. .SH "NOTES" .IP " 1." 4 rostedt@goodmis.org .RS 4 \%mailto:rostedt@goodmis.org .RE .IP " 2." 4 tz.stoyanov@gmail.com .RS 4 \%mailto:tz.stoyanov@gmail.com .RE .IP " 3." 4 linux-trace-devel@vger.kernel.org .RS 4 \%mailto:linux-trace-devel@vger.kernel.org .RE