18c2ecf20Sopenharmony_cilibtraceevent(3) 28c2ecf20Sopenharmony_ci================ 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ciNAME 58c2ecf20Sopenharmony_ci---- 68c2ecf20Sopenharmony_citep_register_comm, tep_override_comm, tep_pid_is_registered, 78c2ecf20Sopenharmony_citep_data_comm_from_pid, tep_data_pid_from_comm, tep_cmdline_pid - 88c2ecf20Sopenharmony_ciManage pid to process name mappings. 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ciSYNOPSIS 118c2ecf20Sopenharmony_ci-------- 128c2ecf20Sopenharmony_ci[verse] 138c2ecf20Sopenharmony_ci-- 148c2ecf20Sopenharmony_ci*#include <event-parse.h>* 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ciint *tep_register_comm*(struct tep_handle pass:[*]_tep_, const char pass:[*]_comm_, int _pid_); 178c2ecf20Sopenharmony_ciint *tep_override_comm*(struct tep_handle pass:[*]_tep_, const char pass:[*]_comm_, int _pid_); 188c2ecf20Sopenharmony_cibool *tep_is_pid_registered*(struct tep_handle pass:[*]_tep_, int _pid_); 198c2ecf20Sopenharmony_ciconst char pass:[*]*tep_data_comm_from_pid*(struct tep_handle pass:[*]_pevent_, int _pid_); 208c2ecf20Sopenharmony_cistruct cmdline pass:[*]*tep_data_pid_from_comm*(struct tep_handle pass:[*]_pevent_, const char pass:[*]_comm_, struct cmdline pass:[*]_next_); 218c2ecf20Sopenharmony_ciint *tep_cmdline_pid*(struct tep_handle pass:[*]_pevent_, struct cmdline pass:[*]_cmdline_); 228c2ecf20Sopenharmony_ci-- 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ciDESCRIPTION 258c2ecf20Sopenharmony_ci----------- 268c2ecf20Sopenharmony_ciThese functions can be used to handle the mapping between pid and process name. 278c2ecf20Sopenharmony_ciThe library builds a cache of these mappings, which is used to display the name 288c2ecf20Sopenharmony_ciof the process, instead of its pid. This information can be retrieved from 298c2ecf20Sopenharmony_citracefs/saved_cmdlines file. 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ciThe _tep_register_comm()_ function registers a _pid_ / process name mapping. 328c2ecf20Sopenharmony_ciIf a command with the same _pid_ is already registered, an error is returned. 338c2ecf20Sopenharmony_ciThe _pid_ argument is the process ID, the _comm_ argument is the process name, 348c2ecf20Sopenharmony_ci_tep_ is the event context. The _comm_ is duplicated internally. 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ciThe _tep_override_comm()_ function registers a _pid_ / process name mapping. 378c2ecf20Sopenharmony_ciIf a process with the same pid is already registered, the process name string is 388c2ecf20Sopenharmony_ciudapted with the new one. The _pid_ argument is the process ID, the _comm_ 398c2ecf20Sopenharmony_ciargument is the process name, _tep_ is the event context. The _comm_ is 408c2ecf20Sopenharmony_ciduplicated internally. 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ciThe _tep_is_pid_registered()_ function checks if a pid has a process name 438c2ecf20Sopenharmony_cimapping registered. The _pid_ argument is the process ID, _tep_ is the event 448c2ecf20Sopenharmony_cicontext. 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ciThe _tep_data_comm_from_pid()_ function returns the process name for a given 478c2ecf20Sopenharmony_cipid. The _pid_ argument is the process ID, _tep_ is the event context. 488c2ecf20Sopenharmony_ciThe returned string should not be freed, but will be freed when the _tep_ 498c2ecf20Sopenharmony_cihandler is closed. 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ciThe _tep_data_pid_from_comm()_ function returns a pid for a given process name. 528c2ecf20Sopenharmony_ciThe _comm_ argument is the process name, _tep_ is the event context. 538c2ecf20Sopenharmony_ciThe argument _next_ is the cmdline structure to search for the next pid. 548c2ecf20Sopenharmony_ciAs there may be more than one pid for a given process, the result of this call 558c2ecf20Sopenharmony_cican be passed back into a recurring call in the _next_ parameter, to search for 568c2ecf20Sopenharmony_cithe next pid. If _next_ is NULL, it will return the first pid associated with 578c2ecf20Sopenharmony_cithe _comm_. The function performs a linear search, so it may be slow. 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ciThe _tep_cmdline_pid()_ function returns the pid associated with a given 608c2ecf20Sopenharmony_ci_cmdline_. The _tep_ argument is the event context. 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ciRETURN VALUE 638c2ecf20Sopenharmony_ci------------ 648c2ecf20Sopenharmony_ci_tep_register_comm()_ function returns 0 on success. In case of an error -1 is 658c2ecf20Sopenharmony_cireturned and errno is set to indicate the cause of the problem: ENOMEM, if there 668c2ecf20Sopenharmony_ciis not enough memory to duplicate the _comm_ or EEXIST if a mapping for this 678c2ecf20Sopenharmony_ci_pid_ is already registered. 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci_tep_override_comm()_ function returns 0 on success. In case of an error -1 is 708c2ecf20Sopenharmony_cireturned and errno is set to indicate the cause of the problem: ENOMEM, if there 718c2ecf20Sopenharmony_ciis not enough memory to duplicate the _comm_. 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci_tep_is_pid_registered()_ function returns true if the _pid_ has a process name 748c2ecf20Sopenharmony_cimapped to it, false otherwise. 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci_tep_data_comm_from_pid()_ function returns the process name as string, or the 778c2ecf20Sopenharmony_cistring "<...>" if there is no mapping for the given pid. 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci_tep_data_pid_from_comm()_ function returns a pointer to a struct cmdline, that 808c2ecf20Sopenharmony_ciholds a pid for a given process, or NULL if none is found. This result can be 818c2ecf20Sopenharmony_cipassed back into a recurring call as the _next_ parameter of the function. 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci_tep_cmdline_pid()_ functions returns the pid for the give cmdline. If _cmdline_ 848c2ecf20Sopenharmony_ci is NULL, then -1 is returned. 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ciEXAMPLE 878c2ecf20Sopenharmony_ci------- 888c2ecf20Sopenharmony_ciThe following example registers pid for command "ls", in context of event _tep_ 898c2ecf20Sopenharmony_ciand performs various searches for pid / process name mappings: 908c2ecf20Sopenharmony_ci[source,c] 918c2ecf20Sopenharmony_ci-- 928c2ecf20Sopenharmony_ci#include <event-parse.h> 938c2ecf20Sopenharmony_ci... 948c2ecf20Sopenharmony_ciint ret; 958c2ecf20Sopenharmony_ciint ls_pid = 1021; 968c2ecf20Sopenharmony_cistruct tep_handle *tep = tep_alloc(); 978c2ecf20Sopenharmony_ci... 988c2ecf20Sopenharmony_ci ret = tep_register_comm(tep, "ls", ls_pid); 998c2ecf20Sopenharmony_ci if (ret != 0 && errno == EEXIST) 1008c2ecf20Sopenharmony_ci ret = tep_override_comm(tep, "ls", ls_pid); 1018c2ecf20Sopenharmony_ci if (ret != 0) { 1028c2ecf20Sopenharmony_ci /* Failed to register pid / command mapping */ 1038c2ecf20Sopenharmony_ci } 1048c2ecf20Sopenharmony_ci... 1058c2ecf20Sopenharmony_ci if (tep_is_pid_registered(tep, ls_pid) == 0) { 1068c2ecf20Sopenharmony_ci /* Command mapping for ls_pid is not registered */ 1078c2ecf20Sopenharmony_ci } 1088c2ecf20Sopenharmony_ci... 1098c2ecf20Sopenharmony_ci const char *comm = tep_data_comm_from_pid(tep, ls_pid); 1108c2ecf20Sopenharmony_ci if (comm) { 1118c2ecf20Sopenharmony_ci /* Found process name for ls_pid */ 1128c2ecf20Sopenharmony_ci } 1138c2ecf20Sopenharmony_ci... 1148c2ecf20Sopenharmony_ci int pid; 1158c2ecf20Sopenharmony_ci struct cmdline *cmd = tep_data_pid_from_comm(tep, "ls", NULL); 1168c2ecf20Sopenharmony_ci while (cmd) { 1178c2ecf20Sopenharmony_ci pid = tep_cmdline_pid(tep, cmd); 1188c2ecf20Sopenharmony_ci /* Found pid for process "ls" */ 1198c2ecf20Sopenharmony_ci cmd = tep_data_pid_from_comm(tep, "ls", cmd); 1208c2ecf20Sopenharmony_ci } 1218c2ecf20Sopenharmony_ci-- 1228c2ecf20Sopenharmony_ciFILES 1238c2ecf20Sopenharmony_ci----- 1248c2ecf20Sopenharmony_ci[verse] 1258c2ecf20Sopenharmony_ci-- 1268c2ecf20Sopenharmony_ci*event-parse.h* 1278c2ecf20Sopenharmony_ci Header file to include in order to have access to the library APIs. 1288c2ecf20Sopenharmony_ci*-ltraceevent* 1298c2ecf20Sopenharmony_ci Linker switch to add when building a program that uses the library. 1308c2ecf20Sopenharmony_ci-- 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ciSEE ALSO 1338c2ecf20Sopenharmony_ci-------- 1348c2ecf20Sopenharmony_ci_libtraceevent(3)_, _trace-cmd(1)_ 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ciAUTHOR 1378c2ecf20Sopenharmony_ci------ 1388c2ecf20Sopenharmony_ci[verse] 1398c2ecf20Sopenharmony_ci-- 1408c2ecf20Sopenharmony_ci*Steven Rostedt* <rostedt@goodmis.org>, author of *libtraceevent*. 1418c2ecf20Sopenharmony_ci*Tzvetomir Stoyanov* <tz.stoyanov@gmail.com>, author of this man page. 1428c2ecf20Sopenharmony_ci-- 1438c2ecf20Sopenharmony_ciREPORTING BUGS 1448c2ecf20Sopenharmony_ci-------------- 1458c2ecf20Sopenharmony_ciReport bugs to <linux-trace-devel@vger.kernel.org> 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ciLICENSE 1488c2ecf20Sopenharmony_ci------- 1498c2ecf20Sopenharmony_cilibtraceevent is Free Software licensed under the GNU LGPL 2.1 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ciRESOURCES 1528c2ecf20Sopenharmony_ci--------- 1538c2ecf20Sopenharmony_cihttps://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 154