tracefs_print_init(3) — Linux manual page

NAME | SYNOPSIS | DESCRIPTION | RETURN VALUE | EXAMPLE | FILES | SEE ALSO | AUTHOR | REPORTING BUGS | LICENSE | RESOURCES | COPYING | NOTES | COLOPHON

LIBTRACEFS(3)               libtracefs Manual              LIBTRACEFS(3)

NAME         top

       tracefs_print_init, tracefs_print_close, tracefs_printf,
       tracefs_vprintf - Open, close and write formated strings in the
       trace buffer.

SYNOPSIS         top

       #include <tracefs.h>

       int tracefs_print_init(struct tracefs_instance *instance);
       int tracefs_printf(struct tracefs_instance *instance, const char *fmt, ...);
       int tracefs_vprintf(struct tracefs_instance *instance, const char *fmt, va_list ap);
       void tracefs_print_close(struct tracefs_instance *instance);

DESCRIPTION         top

       Set of functions to write formated strings in the trace buffer.
       See Documentation/trace/ftrace.rst from the Linux kernel tree for
       more information about writing data from user space in the trace
       buffer. All these APIs have instance as a first argument. If NULL
       is passed as instance, the top trace instance is used.

       The tracefs_print_init() function initializes the library for
       writing into the trace buffer of the selected instance. It is not
       mandatory to call this API before writing strings, any of the
       printf APIs will call it automatically, if the library is not yet
       initialized. But calling tracefs_print_init() in advance will
       speed up the writing.

       The tracefs_printf() function writes a formatted string in the
       trace buffer of the selected instance. The fmt argument is a
       string in printf format, followed by variable arguments ....

       The tracefs_vprintf() function writes a formatted string in the
       trace buffer of the selected instance. The fmt argument is a
       string in printf format, followed by list ap of arguments.

       The tracefs_print_close() function closes the resources, used by
       the library for writing in the trace buffer of the selected
       instance.

RETURN VALUE         top

       The tracefs_print_init(), tracefs_printf(), and tracefs_vprintf()
       functions return 0 if the operation is successful, or -1 in case
       of an error.

EXAMPLE         top

           #include <tracefs.h>

           if (tracefs_print_init(NULL) < 0) {
            /* Failed to initialize the library for writing in the trace buffer of the top trace instance */
           }

           void foo_print(char *format, ...)
           {
                   va_list ap;
                   va_start(ap, format);
                   if (tracefs_vprintf(NULL, format, ap) < 0) {
                           /* Failed to print in the trace buffer */
                   }
                   va_end(ap);
           }

           void foo_print_string(char *message)
           {
                   if (tracefs_printf(NULL, "Message from user space: %s", message) < 0) {
                           /* Failed to print in the trace buffer */
                   }
           }

           tracefs_print_close();

FILES         top

           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         top

       libtracefs(3), libtraceevent(3), trace-cmd(1),
       Documentation/trace/ftrace.rst from the Linux kernel tree

AUTHOR         top

           Steven Rostedt <[email protected][1]>
           Tzvetomir Stoyanov <[email protected][2]>

REPORTING BUGS         top

       Report bugs to <[email protected][3]>

LICENSE         top

       libtracefs is Free Software licensed under the GNU LGPL 2.1

RESOURCES         top

       https://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git/ 

COPYING         top

       Copyright (C) 2021 VMware, Inc. Free use of this software is
       granted under the terms of the GNU Public License (GPL).

NOTES         top

        1. [email protected]
           mailto:[email protected]

        2. [email protected]
           mailto:[email protected]

        3. [email protected]
           mailto:[email protected]

COLOPHON         top

       This page is part of the libtracefs (Linux kernel trace file
       system library) project.  Information about the project can be
       found at ⟨https://www.trace-cmd.org/⟩.  If you have a bug report
       for this manual page, see ⟨https://www.trace-cmd.org/⟩.  This
       page was obtained from the project's upstream Git repository
       ⟨https://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git⟩ on
       2024-06-14.  (At that time, the date of the most recent commit
       that was found in the repository was 2024-05-17.)  If you
       discover any rendering problems in this HTML version of the page,
       or you believe there is a better or more up-to-date source for
       the page, or you have corrections or improvements to the
       information in this COLOPHON (which is not part of the original
       manual page), send a mail to [email protected]

libtracefs 1.7.0               12/22/2023                  LIBTRACEFS(3)