libtracefs: Add APIs for data streaming
PATCH v4 1/1 libtracefs: Add APIs for data streaming
From: "Yordan Karadzhov (VMware)" <[email protected]>
The new APIs can be used to dump the content of "trace_pipe" into a file or directly to "stdout". The "splice" system call is used to moves the data without copying. The new functionality is essentially identical to what 'trace-cmd show -p' does.
Signed-off-by Yordan Karadzhov (VMware) <[email protected]>
[ Updated to fix writing to STDOUT ]
Signed-off-by Steven Rostedt (VMware) <[email protected]>
--- Documentation/libtracefs-stream.txt | 106 +++++++++++++++++++++ include/tracefs-local.h | 1 + include/tracefs.h | 5 + src/tracefs-tools.c | 140 ++++++++++++++++++++++++++++ 4 files changed, 252 insertions(+) create mode 100644 Documentation/libtracefs-stream.txt
Documentation/libtracefs-stream.txt new file +106 -0
@@ -0,0 +1,106 @@ +libtracefs(3) +============= + +NAME +---- +tracefs_trace_pipe_stream, tracefs_trace_pipe_print - +redirect the stream of trace data to an output or stdout. + +SYNOPSIS +-------- +[verse] +-- +*#include <tracefs.h>* + +ssize_t tracefs_trace_pipe_stream(int fd, struct tracefs_instance *instance, int flags); +ssize_t tracefs_trace_pipe_print(struct tracefs_instance *instance); + +-- + +DESCRIPTION +----------- +If NULL is passed as _instance_, the top trace instance is used. +The user can interrupt the streaming of the data by pressing Ctrl-c. + +The _tracefs_trace_pipe_stream()_ function redirects the stream of trace data to an output +file. The "splice" system call is used to moves the data without copying between kernel +address space and user address space. The _fd_ is the file descriptor of the output file +and _flags_ is a bit mask of flags to be passed to the "splice" system call. + +The _tracefs_trace_pipe_print()_ function is similar to _tracefs_trace_pipe_stream()_, but +the stream of trace data is redirected to stdout. + + +RETURN VALUE +------------ +The _tracefs_trace_pipe_stream()_, and _tracefs_trace_pipe_print()_ functions return the +number of bytes transfered if the operation is successful, or -1 in case of an error. + +EXAMPLE +------- +[source,c] +-- +#include <unistd.h> +#include <signal.h> + +#include <tracefs.h> + +void stop(int sig) +{ + tracefs_trace_pipe_stop(NULL); +} + +int main() +{ + mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; + const char *filename = "trace.txt"; + int fd = creat(filename, mode); + int ret; + + signal(SIGINT, stop); + ret = tracefs_trace_pipe_stream(fd, NULL, SPLICE_F_NONBLOCK); + close(fd); + + return ret; +} +-- +FILES +----- +[verse] +-- +*tracefs.h* + Header file to include in order to have access to the library APIs. +*-ltracefs* + Linker switch to add when building a program that uses the library. +-- + +SEE ALSO +-------- +_libtracefs(3)_, +_libtraceevent(3)_, +_trace-cmd(1)_, +Documentation/trace/ftrace.rst from the Linux kernel tree + +AUTHOR +------ +[verse] +-- +*Steven Rostedt* <[email protected]> +*Tzvetomir Stoyanov* <[email protected]> +-- +REPORTING BUGS +-------------- +Report bugs to <[email protected]> + +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) 2021 VMware, Inc. Free use of this software is granted under +the terms of the GNU Public License (GPL).
include/tracefs-local.h +1 -0
@@ -30,6 +30,7 @@ struct tracefs_instance {int ftrace_notrace_fd;int ftrace_marker_fd;int ftrace_marker_raw_fd; +bool pipe_keep_going; };extern pthread_mutex_t toplevel_lock;
include/tracefs.h +5 -0
@@ -184,4 +184,9 @@ int tracefs_function_notrace(struct tracefs_instance *instance, const char *filt/* Control library logs */ void tracefs_set_loglevel (enum tep_loglevel level); +ssize_t tracefs_trace_pipe_stream (int fd,struct tracefs_instance *instance,int flags); +ssize_t tracefs_trace_pipe_print (struct tracefs_instance *instance); +void tracefs_trace_pipe_stop (struct tracefs_instance *instance); + +#endif /* _TRACE_FS_H */
src/tracefs-tools.c +140 -0
143 lines not on this page · raw message
Signature · 1 line
2.30.2