^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) libtraceevent(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) ================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) NAME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) ----
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) tep_register_comm, tep_override_comm, tep_pid_is_registered,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) tep_data_comm_from_pid, tep_data_pid_from_comm, tep_cmdline_pid -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) Manage pid to process name mappings.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) SYNOPSIS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) --------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) [verse]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) --
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) *#include <event-parse.h>*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) int *tep_register_comm*(struct tep_handle pass:[*]_tep_, const char pass:[*]_comm_, int _pid_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) int *tep_override_comm*(struct tep_handle pass:[*]_tep_, const char pass:[*]_comm_, int _pid_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) bool *tep_is_pid_registered*(struct tep_handle pass:[*]_tep_, int _pid_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) const char pass:[*]*tep_data_comm_from_pid*(struct tep_handle pass:[*]_pevent_, int _pid_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct cmdline pass:[*]*tep_data_pid_from_comm*(struct tep_handle pass:[*]_pevent_, const char pass:[*]_comm_, struct cmdline pass:[*]_next_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) int *tep_cmdline_pid*(struct tep_handle pass:[*]_pevent_, struct cmdline pass:[*]_cmdline_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) --
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) DESCRIPTION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) -----------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) These functions can be used to handle the mapping between pid and process name.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) The library builds a cache of these mappings, which is used to display the name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) of the process, instead of its pid. This information can be retrieved from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) tracefs/saved_cmdlines file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) The _tep_register_comm()_ function registers a _pid_ / process name mapping.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) If a command with the same _pid_ is already registered, an error is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) The _pid_ argument is the process ID, the _comm_ argument is the process name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) _tep_ is the event context. The _comm_ is duplicated internally.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) The _tep_override_comm()_ function registers a _pid_ / process name mapping.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) If a process with the same pid is already registered, the process name string is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) udapted with the new one. The _pid_ argument is the process ID, the _comm_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) argument is the process name, _tep_ is the event context. The _comm_ is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) duplicated internally.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) The _tep_is_pid_registered()_ function checks if a pid has a process name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) mapping registered. The _pid_ argument is the process ID, _tep_ is the event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) The _tep_data_comm_from_pid()_ function returns the process name for a given
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) pid. The _pid_ argument is the process ID, _tep_ is the event context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) The returned string should not be freed, but will be freed when the _tep_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) handler is closed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) The _tep_data_pid_from_comm()_ function returns a pid for a given process name.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) The _comm_ argument is the process name, _tep_ is the event context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) The argument _next_ is the cmdline structure to search for the next pid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) As there may be more than one pid for a given process, the result of this call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) can be passed back into a recurring call in the _next_ parameter, to search for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) the next pid. If _next_ is NULL, it will return the first pid associated with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) the _comm_. The function performs a linear search, so it may be slow.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) The _tep_cmdline_pid()_ function returns the pid associated with a given
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) _cmdline_. The _tep_ argument is the event context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) RETURN VALUE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) ------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) _tep_register_comm()_ function returns 0 on success. In case of an error -1 is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) returned and errno is set to indicate the cause of the problem: ENOMEM, if there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) is not enough memory to duplicate the _comm_ or EEXIST if a mapping for this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) _pid_ is already registered.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) _tep_override_comm()_ function returns 0 on success. In case of an error -1 is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) returned and errno is set to indicate the cause of the problem: ENOMEM, if there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) is not enough memory to duplicate the _comm_.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) _tep_is_pid_registered()_ function returns true if the _pid_ has a process name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) mapped to it, false otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) _tep_data_comm_from_pid()_ function returns the process name as string, or the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) string "<...>" if there is no mapping for the given pid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) _tep_data_pid_from_comm()_ function returns a pointer to a struct cmdline, that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) holds a pid for a given process, or NULL if none is found. This result can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) passed back into a recurring call as the _next_ parameter of the function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) _tep_cmdline_pid()_ functions returns the pid for the give cmdline. If _cmdline_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) is NULL, then -1 is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) EXAMPLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) -------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) The following example registers pid for command "ls", in context of event _tep_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) and performs various searches for pid / process name mappings:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) [source,c]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) --
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #include <event-parse.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) int ls_pid = 1021;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) struct tep_handle *tep = tep_alloc();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) ret = tep_register_comm(tep, "ls", ls_pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (ret != 0 && errno == EEXIST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) ret = tep_override_comm(tep, "ls", ls_pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) /* Failed to register pid / command mapping */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (tep_is_pid_registered(tep, ls_pid) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /* Command mapping for ls_pid is not registered */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) const char *comm = tep_data_comm_from_pid(tep, ls_pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) if (comm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) /* Found process name for ls_pid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) int pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct cmdline *cmd = tep_data_pid_from_comm(tep, "ls", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) while (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) pid = tep_cmdline_pid(tep, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /* Found pid for process "ls" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) cmd = tep_data_pid_from_comm(tep, "ls", cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) --
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) FILES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) -----
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) [verse]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) --
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) *event-parse.h*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) Header file to include in order to have access to the library APIs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) *-ltraceevent*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) Linker switch to add when building a program that uses the library.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) --
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) SEE ALSO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) --------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) _libtraceevent(3)_, _trace-cmd(1)_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) AUTHOR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) ------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) [verse]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) --
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) *Steven Rostedt* <rostedt@goodmis.org>, author of *libtraceevent*.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) *Tzvetomir Stoyanov* <tz.stoyanov@gmail.com>, author of this man page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) --
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) REPORTING BUGS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) --------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) Report bugs to <linux-trace-devel@vger.kernel.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) LICENSE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) -------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) libtraceevent is Free Software licensed under the GNU LGPL 2.1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) RESOURCES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) ---------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git