1libtracefs(3) 2============= 3 4NAME 5---- 6tracefs_trace_pipe_stream, tracefs_trace_pipe_print, tracefs_trace_pipe_stop - 7redirect the stream of trace data to an output or stdout. 8 9SYNOPSIS 10-------- 11[verse] 12-- 13*#include <tracefs.h>* 14 15ssize_t *tracefs_trace_pipe_stream*(int _fd_, struct tracefs_instance pass:[*]_instance_, int _flags_); 16ssize_t *tracefs_trace_pipe_print*(struct tracefs_instance pass:[*]_instance_, int _flags_); 17void *tracefs_trace_pipe_stop*(struct tracefs_instance pass:[*]_instance_); 18 19 20-- 21 22DESCRIPTION 23----------- 24If NULL is passed as _instance_, the top trace instance is used. 25 26The reading of the trace_pipe file can be stopped by calling *tracefs_trace_pipe_stop()* 27which could be placed in a signal handler in case the application wants to stop the 28reading, for example, with the user pressing Ctrl-C. 29 30The *tracefs_trace_pipe_stream()* function redirects the stream of trace data to an output 31file. The "splice" system call is used to moves the data without copying between kernel 32address space and user address space. The _fd_ is the file descriptor of the output file 33and _flags_ is a bit mask of flags to be passed to the open system call of the trace_pipe 34file (see ). If flags contain O_NONBLOCK, then that is also passed to the splice calls 35that may read the file to the output stream file descriptor. 36 37The *tracefs_trace_pipe_print()* function is similar to *tracefs_trace_pipe_stream()*, but 38the stream of trace data is redirected to stdout. 39 40 41RETURN VALUE 42------------ 43The *tracefs_trace_pipe_stream()*, and *tracefs_trace_pipe_print()* functions return the 44number of bytes transfered if the operation is successful, or -1 in case of an error. 45 46EXAMPLE 47------- 48[source,c] 49-- 50#include <stdio.h> 51#include <stdlib.h> 52#include <unistd.h> 53#include <signal.h> 54#include <fcntl.h> 55 56#include <tracefs.h> 57 58void stop(int sig) 59{ 60 tracefs_trace_pipe_stop(NULL); 61} 62 63int main(int argc, char **argv) 64{ 65 mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; 66 const char *filename; 67 int fd; 68 int ret; 69 70 if (argc < 2) { 71 fprintf(stderr, "usage: %s output_file\n", argv[0]); 72 exit(-1); 73 } 74 filename = argv[1]; 75 fd = creat(filename, mode); 76 if (fd < 0) { 77 perror(filename); 78 exit(-1); 79 } 80 signal(SIGINT, stop); 81 ret = tracefs_trace_pipe_stream(fd, NULL, SPLICE_F_NONBLOCK); 82 close(fd); 83 84 return ret; 85} 86-- 87FILES 88----- 89[verse] 90-- 91*tracefs.h* 92 Header file to include in order to have access to the library APIs. 93*-ltracefs* 94 Linker switch to add when building a program that uses the library. 95-- 96 97SEE ALSO 98-------- 99*libtracefs*(3), 100*libtraceevent*(3), 101*trace-cmd*(1), 102Documentation/trace/ftrace.rst from the Linux kernel tree 103 104AUTHOR 105------ 106[verse] 107-- 108*Steven Rostedt* <[email protected]> 109*Tzvetomir Stoyanov* <[email protected]> 110-- 111REPORTING BUGS 112-------------- 113Report bugs to <[email protected]> 114 115LICENSE 116------- 117libtracefs is Free Software licensed under the GNU LGPL 2.1 118 119RESOURCES 120--------- 121https://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git/ 122 123COPYING 124------- 125Copyright \(C) 2021 VMware, Inc. Free use of this software is granted under 126the terms of the GNU Public License (GPL). 127