'\" t .\" Title: libtracefs .\" Author: [see the "AUTHOR" section] .\" Generator: DocBook XSL Stylesheets vsnapshot .\" Date: 10/08/2022 .\" Manual: libtracefs Manual .\" Source: libtracefs 1.5.0 .\" Language: English .\" .TH "LIBTRACEFS" "3" "10/08/2022" "libtracefs 1\&.5\&.0" "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" tracefs_event_get_file, tracefs_event_file_read, tracefs_event_file_write, tracefs_event_file_append, tracefs_event_file_clear, tracefs_event_file_exists \- Work with trace event files\&. .SH "SYNOPSIS" .sp .nf \fB#include \fR char *\fBtracefs_event_get_file\fR(struct tracefs_instance *\fIinstance\fR, const char *\fIsystem\fR, const char *\fIevent\fR, const char *\fIfile\fR); char *\fBtracefs_event_file_read\fR(struct tracefs_instance *\fIinstance\fR, const char *\fIsystem\fR, const char *\fIevent\fR, const char *\fIfile\fR, int *\fIpsize\fR); int \fBtracefs_event_file_write\fR(struct tracefs_instance *\fIinstance\fR, const char *\fIsystem\fR, const char *\fIevent\fR, const char *\fIfile\fR, const char *\fIstr\fR); int \fBtracefs_event_file_append\fR(struct tracefs_instance *\fIinstance\fR, const char *\fIsystem\fR, const char *\fIevent\fR, const char *\fIfile\fR, const char *\fIstr\fR); int \fBtracefs_event_file_clear\fR(struct tracefs_instance *\fIinstance\fR, const char *\fIsystem\fR, const char *\fIevent\fR, const char *\fIfile\fR); bool \fBtracefs_event_file_exists\fR(struct tracefs_instance *\fIinstance\fR, const char *\fIsystem\fR, const char *\fIevent\fR, const char *\fIfile\fR) .fi .SH "DESCRIPTION" .sp These are functions for accessing tracefs event specific files\&. These functions act similar to the tracefs instance file functions but are easier to get to if the system and events are known before hand\&. .sp The \fBtracefs_event_get_file()\fR returns the full path of the \fIfile\fR for the given \fIsystem\fR and \fIevent\fR that is within the given \fIinstance\fR\&. If \fIinstance\fR is NULL, then the file for the \fIevent\fR for the top level instance is returned\&. Note, there is no check to see if the file actually exists or even if the system and event exist\&. It only creates the path name for such an event if it did exist\&. This acts similar to the \fBtracefs_instance_get_file\fR(3), but is to be used to get to event files if the \fIsystem\fR and \fIevent\fR are already known\&. .sp The \fBtracefs_event_file_read()\fR reads the content for the \fIevent\fR \fIfile\fR for the given \fIinstance\fR or the top level instance if \fIinstance\fR is NULL\&. The content of the file is returned and \fIpsize\fR is set to the amount of data that was read\&. The returned content must be freed with \fBfree\fR(3)\&. This acts similar to the \fBtracefs_instance_file_read\fR(3), but is to be used to read the event file if the \fIsystem\fR and \fIevent\fR are already known\&. .sp The \fBtracefs_event_file_write()\fR writes \fIstr\fR to the \fIevent\fR \fIfile\fR\&. It will truncate anything that is already in that file\&. This acts similar to the \fBtracefs_instance_file_write\fR(3), but is to be used to read the event file if the \fIsystem\fR and \fIevent\fR are already known\&. .sp The \fBtracefs_event_file_append()\fR appends \fIstr\fR to the \fIevent\fR \fIfile\fR\&. It will not clear out the file as it writes \fIsting\fR\&. This acts similar to the \fBtracefs_instance_file_append\fR(3), but is to be used to read the event file if the \fIsystem\fR and \fIevent\fR are already known\&. .sp The \fBtracefs_event_file_clear()\fR clears the content of the \fIevent\fR \fIfile\fR\&. This acts similar to the \fBtracefs_instance_file_clear\fR(3), but is to be used to read the event file if the \fIsystem\fR and \fIevent\fR are already known\&. .sp The \fBtracefs_event_file_exists()\fR returns true if the \fIevent\fR \fIfile\fR exists, and false otherwise\&. This acts similar to the \fBtracefs_instance_file_exists\fR(3), but is to be used to read the event file if the \fIsystem\fR and \fIevent\fR are already known\&. .SH "RETURN VALUE" .sp \fBtracefs_event_get_file()\fR returns the path of the given \fIsystem\fR/\fIevent\fR \fIfile\fR on success and NULL on error\&. The return value must be freed with \fBtracefs_put_tracing_file\fR(3)\&. .sp \fBtracefs_event_file_read()\fR reads the content of the \fIsystem\fR/\fIevent\fR \fIfile\fR or NULL on error\&. The return pointer must be freed with \fBfree\fR(3)\&. .sp \fBtracefs_event_file_write()\fR and \fBtracefs_event_file_append()\fR returns the number of bytes written to the \fIsystem\fR/\fIevent\fR \fIfile\fR or negative on error\&. .sp \fBtracefs_event_file_clear()\fR returns zero on success and \-1 on error\&. .sp \fBtracefs_event_file_exists()\fR returns true if the \fIsystem\fR/\fIevent\fR \fIfile\fR exists for the given \fIinstance\fR (or top level if \fIinstance\fR is NULL) or false otherwise\&. .SH "EXAMPLE" .sp .if n \{\ .RS 4 .\} .nf #include #include #include #include int main(int argc, char **argv) { char *system; char *event; char *file; char *cmd = NULL; char *buf; char *str; char ch = \*(Aqr\*(Aq; int size; if (argc < 4) { printf("usage: %s sytem event file [(\-a|\-w) write | \-c]\en" " reads the system/event file or writes if [write is supplied]\en", 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\en", system, event, file); exit(\-1); } if (cmd) { if (cmd[0] != \*(Aq\-\*(Aq) ch = cmd[0]; else ch = cmd[1]; if (!ch) ch = \*(Aqc\*(Aq; } switch (ch) { case \*(Aqr\*(Aq: buf = tracefs_event_file_read(NULL, system, event, file, &size); if (buf) printf("%s", buf); else fprintf(stderr, "Failed to read %s/%s/%s\en", system, event, file); free(buf); break; case \*(Aqw\*(Aq: case \*(Aqa\*(Aq: if (argc < 6) { fprintf(stderr, "%s command requires something to write\en", ch == \*(Aqw\*(Aq ? "write" : "append"); exit(\-1); } if (ch == \*(Aqw\*(Aq) 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 \*(Aq%s\*(Aq to %s/%s/%s\en", argv[5], system, event, file); exit(\-1); } break; case \*(Aqc\*(Aq: if (tracefs_event_file_clear(NULL, system, event, file) < 0) { fprintf(stderr, "Failed to clear %s/%s/%s\en", system, event, file); exit(\-1); } break; default: fprintf(stderr, "Unknown command \*(Aq%c\*(Aq\en", ch); exit(\-1); } exit(0); } .fi .if n \{\ .RE .\} .SH "FILES" .sp .if n \{\ .RS 4 .\} .nf \fBtracefs\&.h\fR Header file to include in order to have access to the library APIs\&. \fB\-ltracefs\fR Linker switch to add when building a program that uses the library\&. .fi .if n \{\ .RE .\} .SH "SEE ALSO" .sp \fBlibtracefs\fR(3), \fBlibtraceevent\fR(3), \fBtrace\-cmd\fR(1) .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> .fi .if n \{\ .RE .\} .SH "REPORTING BUGS" .sp Report bugs to <\m[blue]\fBlinux\-trace\-devel@vger\&.kernel\&.org\fR\m[]\&\s-2\u[2]\d\s+2> .SH "LICENSE" .sp libtracefs is Free Software licensed under the GNU LGPL 2\&.1 .SH "RESOURCES" .sp \m[blue]\fBhttps://git\&.kernel\&.org/pub/scm/libs/libtrace/libtracefs\&.git/\fR\m[] .SH "COPYING" .sp Copyright (C) 2022 Google, 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 linux-trace-devel@vger.kernel.org .RS 4 \%mailto:linux-trace-devel@vger.kernel.org .RE