'\" t .\" Title: libtracefs .\" Author: [see the "AUTHOR" section] .\" Generator: DocBook XSL Stylesheets vsnapshot .\" Date: 01/13/2024 .\" Manual: libtracefs Manual .\" Source: libtracefs 1.8.0 .\" Language: English .\" .TH "LIBTRACEFS" "3" "01/13/2024" "libtracefs 1\&.8\&.0" "libtracefs Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" tracefs_instance_get_subbuf_size, tracefs_instance_set_subbuf_size \- Helper functions for working with ring buffer sub buffers\&. .SH "SYNOPSIS" .sp .nf \fB#include \fR size_t \fBtracefs_instance_get_subbuf_size\fR(struct tracefs_instance *\fIinstance\fR); int \fBtracefs_instance_set_subbuf_size\fR(struct tracefs_instance *\fIinstance\fR, size_t \fIsize\fR); .fi .SH "DESCRIPTION" .sp Helper functions for working with the sub\-buffers of the tracing ring buffer\&. The tracing ring buffer is broken up into \fBsub\-buffers\fR\&. An event can not be bigger than the data section of the sub\-buffer (see \fBtep_get_sub_buffer_data_size\fR(3))\&. By default, the ring buffer uses the architectures \fBpage_size\fR 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\&. .sp The \fBtracefs_instance_get_subbuf_size()\fR returns the current size in kilobytes fo the ring buffer sub\-buffers\&. .sp The \fBtracefs_instance_set_subbuf_size()\fR 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\&. .SH "RETURN VALUE" .sp The \fBtracefs_instance_get_subbuf_size()\fR returns the size of the current sub\-buffer for the given \fIinstance\fR ring buffer or \-1 on error\&. .sp The \fBtracefs_instance_set_subbuf_size()\fR will return 0 if it successfully set the \fIinstance\fR ring buffer sub\-buffer size in kilobytes, or \-1 on error\&. .SH "EXAMPLE" .sp .if n \{\ .RS 4 .\} .nf #include #include #include 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\en"); 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] = \*(Aq0\*(Aq + i % 10; } buf[i] = \*(Aq\e0\*(Aq; tracefs_instance_clear(NULL); for (i = 0; i < 4; i++) { ret = tracefs_printf(NULL, "%s\en", buf); if (ret < 0) perror("write"); } trace = tracefs_instance_file_read(NULL, "trace", NULL); printf("%s\en", trace); free(trace); printf("Buffer size was: %zd * 1024\en", tracefs_instance_get_subbuf_size(NULL)); tracefs_instance_set_subbuf_size(NULL, save_subsize); } .fi .if n \{\ .RE .\} .SH "FILES" .sp .if n \{\ .RS 4 .\} .nf \fBtracefs\&.h\fR Header file to include in order to have access to the library APIs\&. \fB\-ltracefs\fR Linker switch to add when building a program that uses the library\&. .fi .if n \{\ .RE .\} .SH "SEE ALSO" .sp \fBlibtracefs\fR(3), \fBlibtraceevent\fR(3), \fBtrace\-cmd\fR(1) .SH "AUTHOR" .sp .if n \{\ .RS 4 .\} .nf \fBSteven Rostedt\fR <\m[blue]\fBrostedt@goodmis\&.org\fR\m[]\&\s-2\u[1]\d\s+2> \fBTzvetomir Stoyanov\fR <\m[blue]\fBtz\&.stoyanov@gmail\&.com\fR\m[]\&\s-2\u[2]\d\s+2> .fi .if n \{\ .RE .\} .SH "REPORTING BUGS" .sp Report bugs to <\m[blue]\fBlinux\-trace\-devel@vger\&.kernel\&.org\fR\m[]\&\s-2\u[3]\d\s+2> .SH "LICENSE" .sp libtracefs is Free Software licensed under the GNU LGPL 2\&.1 .SH "RESOURCES" .sp \m[blue]\fBhttps://git\&.kernel\&.org/pub/scm/libs/libtrace/libtracefs\&.git/\fR\m[] .SH "COPYING" .sp Copyright (C) 2020 VMware, Inc\&. Free use of this software is granted under the terms of the GNU Public License (GPL)\&. .SH "NOTES" .IP " 1." 4 rostedt@goodmis.org .RS 4 \%mailto:rostedt@goodmis.org .RE .IP " 2." 4 tz.stoyanov@gmail.com .RS 4 \%mailto:tz.stoyanov@gmail.com .RE .IP " 3." 4 linux-trace-devel@vger.kernel.org .RS 4 \%mailto:linux-trace-devel@vger.kernel.org .RE