^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) libtraceevent(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) ================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) NAME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) ----
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) trace_seq_init, trace_seq_destroy, trace_seq_reset, trace_seq_terminate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) trace_seq_putc, trace_seq_puts, trace_seq_printf, trace_seq_vprintf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) trace_seq_do_fprintf, trace_seq_do_printf -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) Initialize / destroy a trace sequence.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) SYNOPSIS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) --------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) [verse]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) --
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) *#include <event-parse.h>*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) *#include <trace-seq.h>*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) void *trace_seq_init*(struct trace_seq pass:[*]_s_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) void *trace_seq_destroy*(struct trace_seq pass:[*]_s_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) void *trace_seq_reset*(struct trace_seq pass:[*]_s_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) void *trace_seq_terminate*(struct trace_seq pass:[*]_s_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) int *trace_seq_putc*(struct trace_seq pass:[*]_s_, unsigned char _c_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) int *trace_seq_puts*(struct trace_seq pass:[*]_s_, const char pass:[*]_str_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) int *trace_seq_printf*(struct trace_seq pass:[*]_s_, const char pass:[*]_fmt_, _..._);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) int *trace_seq_vprintf*(struct trace_seq pass:[*]_s_, const char pass:[*]_fmt_, va_list _args_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) int *trace_seq_do_printf*(struct trace_seq pass:[*]_s_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) int *trace_seq_do_fprintf*(struct trace_seq pass:[*]_s_, FILE pass:[*]_fp_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) --
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) DESCRIPTION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) -----------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) Trace sequences are used to allow a function to call several other functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) to create a string of data to use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) The _trace_seq_init()_ function initializes the trace sequence _s_.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) The _trace_seq_destroy()_ function destroys the trace sequence _s_ and frees
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) all its resources that it had used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) The _trace_seq_reset()_ function re-initializes the trace sequence _s_. All
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) characters already written in _s_ will be deleted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) The _trace_seq_terminate()_ function terminates the trace sequence _s_. It puts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) the null character pass:['\0'] at the end of the buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) The _trace_seq_putc()_ function puts a single character _c_ in the trace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) sequence _s_.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) The _trace_seq_puts()_ function puts a NULL terminated string _str_ in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) trace sequence _s_.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) The _trace_seq_printf()_ function puts a formated string _fmt _with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) variable arguments _..._ in the trace sequence _s_.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) The _trace_seq_vprintf()_ function puts a formated string _fmt _with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) list of arguments _args_ in the trace sequence _s_.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) The _trace_seq_do_printf()_ function prints the buffer of trace sequence _s_ to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) the standard output stdout.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) The _trace_seq_do_fprintf()_ function prints the buffer of trace sequence _s_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) to the given file _fp_.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) RETURN VALUE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) ------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) Both _trace_seq_putc()_ and _trace_seq_puts()_ functions return the number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) characters put in the trace sequence, or 0 in case of an error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) Both _trace_seq_printf()_ and _trace_seq_vprintf()_ functions return 0 if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) trace oversizes the buffer's free space, the number of characters printed, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) a negative value in case of an error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) Both _trace_seq_do_printf()_ and _trace_seq_do_fprintf()_ functions return the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) number of printed characters, or -1 in case of an error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) EXAMPLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) -------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) [source,c]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) --
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #include <event-parse.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #include <trace-seq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct trace_seq seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) trace_seq_init(&seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) void foo_seq_print(struct trace_seq *tseq, char *format, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) va_list ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) va_start(ap, format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (trace_seq_vprintf(tseq, format, ap) <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) /* Failed to print in the trace sequence */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) va_end(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) trace_seq_reset(&seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) char *str = " MAN page example";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (trace_seq_puts(&seq, str) != strlen(str)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) /* Failed to put str in the trace sequence */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) if (trace_seq_putc(&seq, ':') != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) /* Failed to put ':' in the trace sequence */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (trace_seq_printf(&seq, " trace sequence: %d", 1) <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /* Failed to print in the trace sequence */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) foo_seq_print( &seq, " %d\n", 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) trace_seq_terminate(&seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) if (trace_seq_do_printf(&seq) < 0 ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) /* Failed to print the sequence buffer to the standard output */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) FILE *fp = fopen("trace.txt", "w");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (trace_seq_do_fprintf(&seq, fp) < 0 ) [
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /* Failed to print the sequence buffer to the trace.txt file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) trace_seq_destroy(&seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) --
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) FILES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) -----
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) [verse]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) --
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) *event-parse.h*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) Header file to include in order to have access to the library APIs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) *trace-seq.h*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) Header file to include in order to have access to trace sequences related APIs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) *-ltraceevent*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) Linker switch to add when building a program that uses the library.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) --
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) SEE ALSO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) --------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) _libtraceevent(3)_, _trace-cmd(1)_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) AUTHOR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) ------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) [verse]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) --
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) *Steven Rostedt* <rostedt@goodmis.org>, author of *libtraceevent*.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) *Tzvetomir Stoyanov* <tz.stoyanov@gmail.com>, author of this man page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) --
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) REPORTING BUGS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) --------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) Report bugs to <linux-trace-devel@vger.kernel.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) LICENSE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) -------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) libtraceevent is Free Software licensed under the GNU LGPL 2.1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) RESOURCES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) ---------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git