1libtracefs(3) 2============= 3 4NAME 5---- 6tracefs_print_init, tracefs_print_close, tracefs_printf, tracefs_vprintf - 7Open, close and write formated strings in the trace buffer. 8 9SYNOPSIS 10-------- 11[verse] 12-- 13*#include <tracefs.h>* 14 15int *tracefs_print_init*(struct tracefs_instance pass:[*]_instance_); 16int *tracefs_printf*(struct tracefs_instance pass:[*]_instance_, const char pass:[*]_fmt_, _..._); 17int *tracefs_vprintf*(struct tracefs_instance pass:[*]_instance_, const char pass:[*]_fmt_, va_list _ap_); 18void *tracefs_print_close*(struct tracefs_instance pass:[*]_instance_); 19 20-- 21 22DESCRIPTION 23----------- 24Set of functions to write formated strings in the trace buffer. 25See Documentation/trace/ftrace.rst from the Linux kernel tree for more information about writing 26data from user space in the trace buffer. All these APIs have _instance_ as a first argument. If 27NULL is passed as _instance_, the top trace instance is used. 28 29The *tracefs_print_init()* function initializes the library for writing into the trace buffer of 30the selected _instance_. It is not mandatory to call this API before writing strings, any of 31the printf APIs will call it automatically, if the library is not yet initialized. But calling 32*tracefs_print_init()* in advance will speed up the writing. 33 34The *tracefs_printf()* function writes a formatted string in the trace buffer of the selected 35_instance_. The _fmt_ argument is a string in printf format, followed by variable arguments _..._. 36 37The *tracefs_vprintf()* function writes a formatted string in the trace buffer of the selected 38_instance_. The _fmt_ argument is a string in printf format, followed by list _ap_ of arguments. 39 40The *tracefs_print_close()* function closes the resources, used by the library for writing in 41the trace buffer of the selected instance. 42 43RETURN VALUE 44------------ 45The *tracefs_print_init()*, *tracefs_printf()*, and *tracefs_vprintf()* functions return 0 if 46the operation is successful, or -1 in case of an error. 47 48EXAMPLE 49------- 50[source,c] 51-- 52#include <tracefs.h> 53 54if (tracefs_print_init(NULL) < 0) { 55 /* Failed to initialize the library for writing in the trace buffer of the top trace instance */ 56} 57 58void foo_print(char *format, ...) 59{ 60 va_list ap; 61 va_start(ap, format); 62 if (tracefs_vprintf(NULL, format, ap) < 0) { 63 /* Failed to print in the trace buffer */ 64 } 65 va_end(ap); 66} 67 68void foo_print_string(char *message) 69{ 70 if (tracefs_printf(NULL, "Message from user space: %s", message) < 0) { 71 /* Failed to print in the trace buffer */ 72 } 73} 74 75tracefs_print_close(); 76-- 77FILES 78----- 79[verse] 80-- 81*tracefs.h* 82 Header file to include in order to have access to the library APIs. 83*-ltracefs* 84 Linker switch to add when building a program that uses the library. 85-- 86 87SEE ALSO 88-------- 89*libtracefs*(3), 90*libtraceevent*(3), 91*trace-cmd*(1), 92Documentation/trace/ftrace.rst from the Linux kernel tree 93 94AUTHOR 95------ 96[verse] 97-- 98*Steven Rostedt* <[email protected]> 99*Tzvetomir Stoyanov* <[email protected]> 100-- 101REPORTING BUGS 102-------------- 103Report bugs to <[email protected]> 104 105LICENSE 106------- 107libtracefs is Free Software licensed under the GNU LGPL 2.1 108 109RESOURCES 110--------- 111https://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git/ 112 113COPYING 114------- 115Copyright \(C) 2021 VMware, Inc. Free use of this software is granted under 116the terms of the GNU Public License (GPL). 117