diff mbox series

[3/3] libtracefs: Add loading of mappings in fill_local_events_system()

Message ID 20210410003727.2288762-4-rostedt@goodmis.org (mailing list archive)
State Accepted
Commit c2c2822673cba3428e3b7506740b39c13f26bfcb
Headers show
Series libtracefs: Map kallsyms, saved_cmdlines and printk_formats | expand

Commit Message

Steven Rostedt April 10, 2021, 12:37 a.m. UTC
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

When writing some code for parsing, I found that tracefs_local_events()
did not load the necessary information to have the printing of events work
just right. It left out reading kallsyms, saved_cmdlines, and
printk_formats, which are necessary for several events to print properly.

Have fill_local_events_system() read and load those files such that the
events can be printed fully. If there's a problem with reading and loading
any of these, it does not make the function called failed. This is a best
effort approach.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 src/tracefs-events.c | 66 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
diff mbox series

Patch

diff --git a/src/tracefs-events.c b/src/tracefs-events.c
index ab474e0..f37ada1 100644
--- a/src/tracefs-events.c
+++ b/src/tracefs-events.c
@@ -599,6 +599,70 @@  static bool contains(const char *name, const char * const *names)
 	return false;
 }
 
+static void load_kallsyms(struct tep_handle *tep)
+{
+	char *buf;
+
+	if (str_read_file("/proc/kallsyms", &buf, false) < 0)
+		return;
+
+	tep_parse_kallsyms(tep, buf);
+	free(buf);
+}
+
+static void load_saved_cmdlines(const char *tracing_dir,
+				struct tep_handle *tep)
+{
+	char *path;
+	char *buf;
+	int ret;
+
+	path = trace_append_file(tracing_dir, "saved_cmdlines");
+	if (!path)
+		return;
+
+	ret = str_read_file(path, &buf, false);
+	free(path);
+	if (ret < 0)
+		return;
+
+	tep_parse_saved_cmdlines(tep, buf);
+	free(buf);
+}
+
+static void load_printk_formats(const char *tracing_dir,
+				struct tep_handle *tep)
+{
+	char *path;
+	char *buf;
+	int ret;
+
+	path = trace_append_file(tracing_dir, "printk_formats");
+	if (!path)
+		return;
+
+	ret = str_read_file(path, &buf, false);
+	free(path);
+	if (ret < 0)
+		return;
+
+	tep_parse_printk_formats(tep, buf);
+	free(buf);
+}
+
+/*
+ * Do a best effort attempt to load kallsyms, saved_cmdlines and
+ * printk_formats. If they can not be loaded, then this will not
+ * do the mappings. But this does not fail the loading of events.
+ */
+static void load_mappings(const char *tracing_dir,
+			  struct tep_handle *tep)
+{
+	load_kallsyms(tep);
+	load_saved_cmdlines(tracing_dir, tep);
+	load_printk_formats(tracing_dir, tep);
+}
+
 static int fill_local_events_system(const char *tracing_dir,
 				    struct tep_handle *tep,
 				    const char * const *sys_names,
@@ -638,6 +702,8 @@  static int fill_local_events_system(const char *tracing_dir,
 	if (!sys_names || contains("ftrace", sys_names))
 		load_events(tep, tracing_dir, "ftrace");
 
+	load_mappings(tracing_dir, tep);
+
 	/* always succeed because parsing failures are not critical */
 	ret = 0;
 out: