Movatterモバイル変換


[0]ホーム

URL:


man7.org > Linux >man-pages

Linux/UNIX system programming training


tracefs_cpu_read_buf(3) — Linux manual page

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

LIBTRACEFS(3)               libtracefs ManualLIBTRACEFS(3)

NAME        top

       tracefs_cpu_read_buf, tracefs_cpu_buffered_read_buf,       tracefs_cpu_flush_buf - Reading trace_pipe_raw data returning a       kbuffer

SYNOPSIS        top

#include <tracefs.h>       struct kbuffer *tracefs_cpu_read_buf(struct tracefs_cpu *tcpu, boolnonblock);       struct kbuffer *tracefs_cpu_buffered_read_buf(struct tracefs_cpu *tcpu, boolnonblock);       struct kbuffer *tracefs_cpu_flush_buf(struct tracefs_cpu *tcpu);

DESCRIPTION        top

       This set of APIs can be used to read the raw data from the       trace_pipe_raw files in the tracefs file system and return a       kbuffer structure to read it with.       Thetracefs_cpu_read_buf()reads the trace_pipe_raw files       associated totcpu and returns a kbuffer structure that can be       used to iterate the events. Ifnonblock is set, and there’s no       data available, it will return immediately. Otherwise depending on       howtcpu was opened, it will block. Iftcpu was opened with       nonblock set, then thisnonblock will make no difference.       Thetracefs_cpu_buffered_read_buf()is basically the same astracefs_cpu_read_buf()except that it uses a pipe through splice       to buffer reads. This will batch reads keeping the reading from       the ring buffer less intrusive to the system, as just reading all       the time can cause quite a disturbance. Note, one difference       between this andtracefs_cpu_read()is that it will read only in       sub buffer pages. If the ring buffer has not filled a page, then       it will not return anything, even withnonblock set. Calls totracefs_cpu_flush_buf()ortracefs_cpu_flush()should be done to       read the rest of the file at the end of the trace.       Thetracefs_cpu_flush_buf()reads the trace_pipe_raw file       associated by thetcpu and puts it intobuffer, which must be the       size of the sub buffer which is retrieved. This should be called       at the end of tracing to get the rest of the data. This call will       convert the file descriptor of trace_pipe_raw into non-blocking       mode.

RETURN VALUE        top

       The functionstracefs_cpu_read_buf(),       tracefs_cpu_buffered_read_buf()* andtracefs_cpu_flush()returns a       kbuffer descriptor that can be iterated over to find the events.       Note, this descriptor is part of the tracefs_cpu structure and       should not be freed. It will be freed. It returns NULL on error or       if nonblock is set and there are no events available. In the case       of no events, errno will be set with EAGAIN.

EXAMPLE        top

           #include <stdlib.h>           #include <ctype.h>           #include <tracefs.h>           static void read_page(struct tep_handle *tep, struct kbuffer *kbuf)           {                   static struct trace_seq seq;                   struct tep_record record;                   if (seq.buffer)                           trace_seq_reset(&seq);                   else                           trace_seq_init(&seq);                   while ((record.data = kbuffer_read_event(kbuf, &record.ts))) {                           record.size = kbuffer_event_size(kbuf);                           kbuffer_next_event(kbuf, NULL);                           tep_print_event(tep, &seq, &record,                                           "%s-%d %9d\t%s: %s\n",                                           TEP_PRINT_COMM,                                           TEP_PRINT_PID,                                           TEP_PRINT_TIME,                                           TEP_PRINT_NAME,                                           TEP_PRINT_INFO);                           trace_seq_do_printf(&seq);                           trace_seq_reset(&seq);                   }           }           int main (int argc, char **argv)           {                   struct tracefs_cpu *tcpu;                   struct tep_handle *tep;                   struct kbuffer *kbuf;                   int cpu;                   if (argc < 2 || !isdigit(argv[1][0])) {                           printf("usage: %s cpu\n\n", argv[0]);                           exit(-1);                   }                   cpu = atoi(argv[1]);                   tep = tracefs_local_events(NULL);                   if (!tep) {                           perror("Reading trace event formats");                           exit(-1);                   }                   tcpu = tracefs_cpu_open(NULL, cpu, 0);                   if (!tcpu) {                           perror("Open CPU 0 file");                           exit(-1);                   }                   while ((kbuf = tracefs_cpu_buffered_read_buf(tcpu, true))) {                           read_page(tep, kbuf);                   }                   kbuf = tracefs_cpu_flush_buf(tcpu);                   if (kbuf)                           read_page(tep, kbuf);                   tracefs_cpu_close(tcpu);                   tep_free(tep);                   return 0;           }

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

tracefs_cpu_open(3)tracefs_cpu_close(3)tracefs_cpu_read(3)tracefs_cpu_buffered_read(3)tracefs_cpu_flush(3)libtracefs(3),libtraceevent(3),trace-cmd(1)

AUTHOR        top

Steven Rostedt<rostedt@goodmis.org[1]>

REPORTING BUGS        top

       Report bugs to <linux-trace-devel@vger.kernel.org[2]>

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) 2022 Google, 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. linux-trace-devel@vger.kernel.org           mailto:linux-trace-devel@vger.kernel.org

COLOPHON        top

       This page is part of thelibtracefs (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-08-11.  (At that time, the date of the most recent commit       that was found in the repository was 2025-06-02.)  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 isnot part of the original manual page), send a       mail to man-pages@man7.orglibtracefs 1.8.1                01/02/2025LIBTRACEFS(3)

Pages that refer to this page:tracefs_cpu_open_mapped(3)tracefs_cpu_read_size(3)



HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface.

For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere.

Hosting byjambit GmbH.

Cover of TLPI


[8]ページ先頭

©2009-2025 Movatter.jp