Movatterモバイル変換


[0]ホーム

URL:


man7.org > Linux >man-pages

Linux/UNIX system programming training


tracefs_event_get_file(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_event_get_file, tracefs_event_file_read,       tracefs_event_file_write, tracefs_event_file_append,       tracefs_event_file_clear, tracefs_event_file_exists - Work with       trace event files.

SYNOPSIS        top

#include <tracefs.h>       char *tracefs_event_get_file(struct tracefs_instance *instance, const char *system, const char *event,                                    const char *file);       char *tracefs_event_file_read(struct tracefs_instance *instance, const char *system, const char *event,                                     const char *file, int *psize);       inttracefs_event_file_write(struct tracefs_instance *instance, const char *system, const char *event,                                    const char *file, const char *str);       inttracefs_event_file_append(struct tracefs_instance *instance, const char *system, const char *event,                                     const char *file, const char *str);       inttracefs_event_file_clear(struct tracefs_instance *instance, const char *system, const char *event,                                    const char *file);       booltracefs_event_file_exists(struct tracefs_instance *instance, const char *system, const char *event,                                      const char *file);

DESCRIPTION        top

       These are functions for accessing tracefs event specific files.       These functions act similar to the tracefs instance file functions       but are easier to get to if the system and events are known before       hand.       Thetracefs_event_get_file()returns the full path of thefile for       the givensystem andevent that is within the giveninstance. Ifinstance is NULL, then the file for theevent for the top level       instance is returned. Note, there is no check to see if the file       actually exists or even if the system and event exist. It only       creates the path name for such an event if it did exist. This acts       similar to thetracefs_instance_get_file(3), but is to be used to       get to event files if thesystem andevent are already known.       Thetracefs_event_file_read()reads the content for theevent file       for the giveninstance or the top level instance ifinstance is       NULL. The content of the file is returned andpsize is set to the       amount of data that was read. The returned content must be freed       withfree(3). This acts similar to thetracefs_instance_file_read(3), but is to be used to read the event       file if thesystem andevent are already known.       Thetracefs_event_file_write()writesstr to theevent file. It       will truncate anything that is already in that file. This acts       similar to thetracefs_instance_file_write(3), but is to be used       to read the event file if thesystem andevent are already known.       Thetracefs_event_file_append()appendsstr to theevent file. It       will not clear out the file as it writessting. This acts similar       to thetracefs_instance_file_append(3), but is to be used to read       the event file if thesystem andevent are already known.       Thetracefs_event_file_clear()clears the content of theeventfile. This acts similar to thetracefs_instance_file_clear(3), but       is to be used to read the event file if thesystem andevent are       already known.       Thetracefs_event_file_exists()returns true if theevent file       exists, and false otherwise. This acts similar to thetracefs_instance_file_exists(3), but is to be used to read the       event file if thesystem andevent are already known.

RETURN VALUE        top

tracefs_event_get_file()returns the path of the givensystem/event file on success and NULL on error. The return value       must be freed withtracefs_put_tracing_file(3).tracefs_event_file_read()reads the content of thesystem/eventfile or NULL on error. The return pointer must be freed withfree(3).tracefs_event_file_write()andtracefs_event_file_append()returns       the number of bytes written to thesystem/event file or negative       on error.tracefs_event_file_clear()returns zero on success and -1 on       error.tracefs_event_file_exists()returns true if thesystem/event file       exists for the giveninstance (or top level ifinstance is NULL)       or false otherwise.

EXAMPLE        top

           #include <stdio.h>           #include <stdlib.h>           #include <unistd.h>           #include <tracefs.h>           int main(int argc, char **argv)           {                   char *system;                   char *event;                   char *file;                   char *cmd = NULL;                   char *buf;                   char *str;                   char ch = 'r';                   int size;                   if (argc < 4) {                           printf("usage: %s sytem event file [(-a|-w) write | -c]\n"                                  "   reads the system/event file or writes if [write is supplied]\n",                                  argv[0]);                           exit(0);                   }                   system = argv[1];                   event = argv[2];                   file = argv[3];                   if (argc > 4)                           cmd = argv[4];                   if (!tracefs_event_file_exists(NULL, system, event, file)) {                           fprintf(stderr, "File %s/%s/%s does not exist\n",                                           system, event, file);                           exit(-1);                   }                   if (cmd) {                           if (cmd[0] != '-')                                   ch = cmd[0];                           else                                   ch = cmd[1];                           if (!ch)                                   ch = 'c';                   }                   switch (ch) {                   case 'r':                           buf = tracefs_event_file_read(NULL, system, event, file, &size);                           if (buf)                                   printf("%s", buf);                           else                                   fprintf(stderr, "Failed to read %s/%s/%s\n",                                           system, event, file);                           free(buf);                           break;                   case 'w':                   case 'a':                           if (argc < 6) {                                   fprintf(stderr, "%s command requires something to write\n",                                           ch == 'w' ? "write" : "append");                                   exit(-1);                           }                           if (ch == 'w')                                   size = tracefs_event_file_write(NULL, system, event, file, argv[5]);                           else                                   size = tracefs_event_file_append(NULL, system, event, file, argv[5]);                           if (size < 0) {                                   fprintf(stderr, "Failed to write '%s' to %s/%s/%s\n",                                                   argv[5], system, event, file);                                   exit(-1);                           }                           break;                   case 'c':                           if (tracefs_event_file_clear(NULL, system, event, file) < 0) {                                   fprintf(stderr, "Failed to clear %s/%s/%s\n",                                           system, event, file);                                   exit(-1);                           }                           break;                   default:                           fprintf(stderr, "Unknown command '%c'\n", ch);                           exit(-1);                   }                   exit(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

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_synth_create(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