tep_register_comm(3) — Linux manual page

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

LIBTRACEEVENT(3)          libtraceevent Manual          LIBTRACEEVENT(3)

NAME         top

       tep_register_comm, tep_override_comm, tep_is_pid_registered,
       tep_data_comm_from_pid, tep_data_pid_from_comm, tep_cmdline_pid -
       Manage pid to process name mappings.

SYNOPSIS         top

       #include <event-parse.h>

       int tep_register_comm(struct tep_handle *tep, const char *comm, int pid);
       int tep_override_comm(struct tep_handle *tep, const char *comm, int pid);
       bool tep_is_pid_registered(struct tep_handle *tep, int pid);
       const char *tep_data_comm_from_pid(struct tep_handle *pevent, int pid);
       struct cmdline *tep_data_pid_from_comm(struct tep_handle *pevent, const char *comm, struct cmdline *next);
       int tep_cmdline_pid(struct tep_handle *pevent, struct cmdline *cmdline);

DESCRIPTION         top

       These functions can be used to handle the mapping between pid and
       process name. The library builds a cache of these mappings, which
       is used to display the name of the process, instead of its pid.
       This information can be retrieved from tracefs/saved_cmdlines
       file.

       The tep_register_comm() function registers a pid / process name
       mapping. If a command with the same pid is already registered, an
       error is returned. The pid argument is the process ID, the comm
       argument is the process name, tep is the event context. The comm
       is duplicated internally.

       The tep_override_comm() function registers a pid / process name
       mapping. If a process with the same pid is already registered,
       the process name string is udapted with the new one. The pid
       argument is the process ID, the comm argument is the process
       name, tep is the event context. The comm is duplicated
       internally.

       The tep_is_pid_registered() function checks if a pid has a
       process name mapping registered. The pid argument is the process
       ID, tep is the event context.

       The tep_data_comm_from_pid() function returns the process name
       for a given pid. The pid argument is the process ID, tep is the
       event context. The returned string should not be freed, but will
       be freed when the tep handler is closed.

       The tep_data_pid_from_comm() function returns a pid for a given
       process name. The comm argument is the process name, tep is the
       event context. The argument next is the cmdline structure to
       search for the next pid. As there may be more than one pid for a
       given process, the result of this call can be passed back into a
       recurring call in the next parameter, to search for the next pid.
       If next is NULL, it will return the first pid associated with the
       comm. The function performs a linear search, so it may be slow.

       The tep_cmdline_pid() function returns the pid associated with a
       given cmdline. The tep argument is the event context.

RETURN VALUE         top

       tep_register_comm() function returns 0 on success. In case of an
       error -1 is returned and errno is set to indicate the cause of
       the problem: ENOMEM, if there is not enough memory to duplicate
       the comm or EEXIST if a mapping for this pid is already
       registered.

       tep_override_comm() function returns 0 on success. In case of an
       error -1 is returned and errno is set to indicate the cause of
       the problem: ENOMEM, if there is not enough memory to duplicate
       the comm.

       tep_is_pid_registered() function returns true if the pid has a
       process name mapped to it, false otherwise.

       tep_data_comm_from_pid() function returns the process name as
       string, or the string "<...>" if there is no mapping for the
       given pid.

       tep_data_pid_from_comm() function returns a pointer to a struct
       cmdline, that holds a pid for a given process, or NULL if none is
       found. This result can be passed back into a recurring call as
       the next parameter of the function.

       tep_cmdline_pid() functions returns the pid for the give cmdline.
       If cmdline is NULL, then -1 is returned.

EXAMPLE         top

       The following example registers pid for command "ls", in context
       of event tep and performs various searches for pid / process name
       mappings:

           #include <event-parse.h>
           ...
           int ret;
           int ls_pid = 1021;
           struct tep_handle *tep = tep_alloc();
           ...
                   ret = tep_register_comm(tep, "ls", ls_pid);
                   if (ret != 0 && errno == EEXIST)
                           ret = tep_override_comm(tep, "ls", ls_pid);
                   if (ret != 0) {
                           /* Failed to register pid / command mapping */
                   }
           ...
                   if (tep_is_pid_registered(tep, ls_pid) == 0) {
                           /* Command mapping for ls_pid is not registered */
                   }
           ...
                   const char *comm = tep_data_comm_from_pid(tep, ls_pid);
                   if (comm) {
                           /* Found process name for ls_pid */
                   }
           ...
                   int pid;
                   struct cmdline *cmd = tep_data_pid_from_comm(tep, "ls", NULL);
                   while (cmd) {
                           pid = tep_cmdline_pid(tep, cmd);
                           /* Found pid for process "ls" */
                           cmd = tep_data_pid_from_comm(tep, "ls", cmd);
                   }

FILES         top

           event-parse.h
                   Header file to include in order to have access to the library APIs.
           -ltraceevent
                   Linker switch to add when building a program that uses the library.

SEE ALSO         top

       libtraceevent(3), trace-cmd(1)

AUTHOR         top

           Steven Rostedt <[email protected][1]>, author of libtraceevent.
           Tzvetomir Stoyanov <[email protected][2]>, author of this man page.

REPORTING BUGS         top

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

LICENSE         top

       libtraceevent is Free Software licensed under the GNU LGPL 2.1

RESOURCES         top

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

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 libtraceevent (Linux kernel trace event
       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/libtraceevent.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]

libtraceevent 1.7.3            09/24/2023               LIBTRACEEVENT(3)

Pages that refer to this page: tep_parse_saved_cmdlines(3)