@@ -3,7 +3,8 @@ libtraceevent(3)
NAME
----
-tep_parse_kallsyms - Parses mappings of address to function names from kallsyms format file
+tep_parse_saved_cmdlines, tep_parse_kallsyms
+- Parsing functions to load mappings
SYNOPSIS
--------
@@ -11,11 +12,19 @@ SYNOPSIS
--
*#include <event-parse.h>*
+int *tep_parse_saved_cmdlines*(struct tep_handle pass:[*]_tep_, const char pass:[*]_buf_);
int *tep_parse_kallsyms*(struct tep_handle pass:[*]_tep_, const char pass:[*]_buf_);
--
DESCRIPTION
-----------
+*tep_parse_saved_cmdlines* is a helper function to parse content in the tracefs
+file system of the "saved_cmdlines" file (stored in a string buffer passed in by _buf_)
+and loads the mapping of the process IDs (pid) to the comm names in the
+_tep_ handler. The events store the pid and this is used to be able to show the
+process names associated to those process ids. It parses the string _buf_ that
+holds the content of saved_cmdlines and ends with a nul character ('\0').
+
*tep_parse_kallsyms* is a helper function to parse the Linux kernel /proc/kallsyms format
(stored in a string buffer passed in by _buf_) and load the functions into the
_tep_ handler such that function IP addresses can be mapped to their name when
@@ -24,6 +33,9 @@ holds the content of /proc/kallsyms and ends with a nul character ('\0').
RETURN VALUE
------------
+The *tep_parse_saved_cmdlines*() function returns 0 in case of success, or -1
+in case of an error.
+
The *tep_parse_kallsyms*() function returns 0 in case of success, or -1
in case of an error.
@@ -33,8 +45,22 @@ EXAMPLE
--
...
#include <event-parse.h>
+#include <tracefs.h>
#include <stdlib.h>
+int load_cmdlines(struct tep_handle *tep)
+{
+ char *buf = NULL;
+ int r;
+
+ buf = tracefs_instance_file_read(NULL, "saved_cmdlines", NULL);
+ if (!buf)
+ return -1;
+ r = tep_parse_saved_cmdlines(tep, buf);
+ free(buf);
+ return r;
+}
+
int load_kallsyms(struct tep_handle *tep)
{
char *line = NULL;
@@ -75,7 +101,7 @@ FILES
SEE ALSO
--------
-_libtraceevent(3)_, _trace-cmd(1)_, _tep_register_function(3)_
+_libtraceevent(3)_, _trace-cmd(1)_, _tep_register_comm(3)_, _tep_register_function(3)_
AUTHOR
------
@@ -387,6 +387,48 @@ int tep_override_comm(struct tep_handle *tep, const char *comm, int pid)
return _tep_register_comm(tep, comm, pid, true);
}
+/**
+ * tep_parse_saved_cmdlines - parse the comms from the saved_cmdlines file
+ * @tep: a handle to the trace event parser
+ * @buf: A string buffer that holds the content of saved_cmdlines and ends with '\0'
+ *
+ * This is a helper function to parse the comms in the tracefs saved_cmdlines
+ * file (stored in a string buffer) and load the comms into the @tep handler
+ * such that comm name matches an process ID (pid). This is used to show
+ * the names of the processes as the events only hold the pid.
+ *
+ * Returns 0 on success, and -1 on error.
+ */
+int tep_parse_saved_cmdlines(struct tep_handle *tep, const char *buf)
+{
+ char *copy;
+ char *comm;
+ char *line;
+ char *next = NULL;
+ int pid;
+ int ret = -1;
+ int n;
+
+ copy = strdup(buf);
+ if (!copy)
+ return -1;
+
+ line = strtok_r(copy, "\n", &next);
+ while (line) {
+ errno = 0;
+ n = sscanf(line, "%d %m[^\n]s", &pid, &comm);
+ if (errno || n != 2 || !comm)
+ goto out;
+ tep_register_comm(tep, comm, pid);
+ free(comm);
+ line = strtok_r(NULL, "\n", &next);
+ }
+ ret = 0;
+ out:
+ free(copy);
+ return ret;
+}
+
struct func_map {
unsigned long long addr;
char *func;
@@ -439,6 +439,7 @@ int tep_set_function_resolver(struct tep_handle *tep,
void tep_reset_function_resolver(struct tep_handle *tep);
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);
+int tep_parse_saved_cmdlines(struct tep_handle *tep, const char *buf);
int tep_parse_kallsyms(struct tep_handle *tep, const char *kallsyms);
int tep_register_function(struct tep_handle *tep, char *name,
unsigned long long addr, char *mod);