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