tracefs_instance_get_subbuf_size(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_instance_get_subbuf_size, tracefs_instance_set_subbuf_size
       - Helper functions for working with ring buffer sub buffers.

SYNOPSIS         top

       #include <tracefs.h>

       size_t tracefs_instance_get_subbuf_size(struct tracefs_instance *instance);
       int tracefs_instance_set_subbuf_size(struct tracefs_instance *instance, size_t size);

DESCRIPTION         top

       Helper functions for working with the sub-buffers of the tracing
       ring buffer. The tracing ring buffer is broken up into
       sub-buffers. An event can not be bigger than the data section of
       the sub-buffer (see tep_get_sub_buffer_data_size(3)). By default,
       the ring buffer uses the architectures page_size as the default
       size of the sub-buffer, but this can be limiting if there is a
       need for large events, for example, the application wants to write
       large strings into the trace_marker file.

       The tracefs_instance_get_subbuf_size() returns the current size in
       kilobytes fo the ring buffer sub-buffers.

       The tracefs_instance_set_subbuf_size() will write the size in
       kilobytes of what the new sub-buffer size should be. Note, that
       this is only a hint to what the minimum sub-buffer size should be.
       It also does not take into account the meta-data that is used by
       the sub-buffer, so the size written should be no less than 16
       bytes more than the maximum event size that will be used. The
       kernel will likely make the sub-buffer size larger than specified,
       as it may need to align the size for implementation purposes.

RETURN VALUE         top

       The tracefs_instance_get_subbuf_size() returns the size of the
       current sub-buffer for the given instance ring buffer or -1 on
       error.

       The tracefs_instance_set_subbuf_size() will return 0 if it
       successfully set the instance ring buffer sub-buffer size in
       kilobytes, or -1 on error.

EXAMPLE         top

           #include <stdlib.h>
           #include <tracefs.h>
           #include <errno.h>

           int main(int argc, char **argv)
           {
                   struct tep_handle *tep;
                   ssize_t save_subsize;
                   ssize_t subsize;
                   char *trace;
                   char buf[3000];
                   int meta_size;
                   int ret;
                   int i;

                   tep = tep_alloc();
                   ret = tracefs_load_headers(NULL, tep);
                   tep_free(tep);

                   if (ret < 0) {
                           perror("reading headers");
                           exit(-1);
                   }

                   meta_size = tep_get_sub_buffer_size(tep) - tep_get_sub_buffer_data_size(tep);

                   save_subsize = tracefs_instance_get_subbuf_size(NULL);
                   if (save_subsize < 0) {
                           printf("Changing sub-buffer size not available\n");
                           exit(-1);
                   }

                   subsize = save_subsize * 1024;

                   /* Have at least 4 writes fit on a sub-buffer */
                   if (subsize - meta_size < sizeof(buf) *4 ) {
                           subsize = ((sizeof(buf) * 4 + meta_size) + 1023) / 1024;
                           tracefs_instance_set_subbuf_size(NULL, subsize);
                   }

                   for (i = 0; i < sizeof(buf) - 1; i++) {
                           buf[i] = '0' + i % 10;
                   }
                   buf[i] = '\0';

                   tracefs_instance_clear(NULL);

                   for (i = 0; i < 4; i++) {
                           ret = tracefs_printf(NULL, "%s\n", buf);
                           if (ret < 0)
                                   perror("write");
                   }

                   trace = tracefs_instance_file_read(NULL, "trace", NULL);
                   printf("%s\n", trace);
                   free(trace);

                   printf("Buffer size was: %zd * 1024\n",
                          tracefs_instance_get_subbuf_size(NULL));

                   tracefs_instance_set_subbuf_size(NULL, save_subsize);
           }

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)

AUTHOR         top

           Steven Rostedt <rostedt@goodmis.org[1]>
           Tzvetomir Stoyanov <tz.stoyanov@gmail.com[2]>

REPORTING BUGS         top

       Report bugs to <linux-trace-devel@vger.kernel.org[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) 2020 VMware, Inc. Free use of this software is
       granted under the terms of the GNU Public License (GPL).

NOTES         top

        1. rostedt@goodmis.org
           mailto:rostedt@goodmis.org

        2. tz.stoyanov@gmail.com
           mailto:tz.stoyanov@gmail.com

        3. linux-trace-devel@vger.kernel.org
           mailto:linux-trace-devel@vger.kernel.org

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
       2025-02-02.  (At that time, the date of the most recent commit
       that was found in the repository was 2024-11-22.)  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 man-pages@man7.org

libtracefs 1.8.1                01/02/2025                  LIBTRACEFS(3)