libtracefs: Map kallsyms, saved_cmdlines and printk_formats
cover libtracefs: Map kallsyms, saved_cmdlines and printk_formats
From: "Steven Rostedt (VMware)" <[email protected]>
Now that libtraceevent 1.2 has a way to easily load kallsyms, saved_cmdlines, and printk_formats into the tep handler, have this happen by default when loading the events.
This will make the reading of events have better output as there will be more information to parse the events correctly.
Steven Rostedt (VMware) (3):
libtracefs: Make libtraceevent 1.2 the minimum version
libtracefs: Add parameter to turn off warnings in str_read_file()
libtracefs: Add loading of mappings in fill_local_events_system()
Makefile | 2 +- include/tracefs-local.h | 2 +- src/tracefs-events.c | 72 +++++++++++++++++++++++++++++++++++++++-- src/tracefs-instance.c | 2 +- src/tracefs-utils.c | 8 +++-- 5 files changed, 77 insertions(+), 9 deletions(-)
Signature · 1 line
2.29.2
PATCH 1/3 libtracefs: Make libtraceevent 1.2 the minimum version
From: "Steven Rostedt (VMware)" <[email protected]>
Now that libtraceevent 1.2 has been released, make it the minimum version that this library depends on, and be able to use all the APIs in that library.
--- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
@@ -10,7 +10,7 @@ export TFS_PATCHLEVEL export TFS_EXTRAVERSION export TRACEFS_VERSION -LIBTRACEEVENT_MIN_VERSION = 1.1 +LIBTRACEEVENT_MIN_VERSION = 1.2 # taken from trace-cmd MAKEFLAGS += --no-print-directory
Signature · 1 line
2.29.2
PATCH 2/3 libtracefs: Add parameter to turn off warnings in str_read_file()
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
There may be cases when reading a file that warnings should not be displayed. Add a parameter to str_read_file() that lets the caller tell it not to warn on any errors.
--- include/tracefs-local.h | 2 +- src/tracefs-events.c | 6 +++--- src/tracefs-instance.c | 2 +- src/tracefs-utils.c | 8 +++++--- 4 files changed, 10 insertions(+), 8 deletions(-)
include/tracefs-local.h +1 -1
@@ -42,7 +42,7 @@ static inline pthread_mutex_t *trace_get_lock(struct tracefs_instance *instance)/* Can be overridden */ void tracefs_warning (const char *fmt, ...); -int str_read_file (const char *file,char **buffer); +int str_read_file (const char *file,char **buffer,bool warn);char *trace_append_file (const char *dir,const char *name);char *trace_find_tracing_dir (void );
src/tracefs-events.c +3 -3
@@ -485,7 +485,7 @@ char **tracefs_tracers(const char *tracing_dir)if (ret <0 ) goto out_free; - len =str_read_file (available_tracers, &buf); + len =str_read_file (available_tracers, &buf, true);if (len <=0 ) goto out_free;
@@ -545,7 +545,7 @@ static int load_events(struct tep_handle *tep,if (ret <0 ) goto next_event; - len =str_read_file (format, &buf); + len =str_read_file (format, &buf, true);if (len <=0 ) goto next_event;
@@ -575,7 +575,7 @@ static int read_header(struct tep_handle *tep, const char *tracing_dir)if (ret <0 ) goto out; - len =str_read_file (header, &buf); + len =str_read_file (header, &buf, true);if (len <=0 ) goto out;
src/tracefs-instance.c +1 -1
@@ -400,7 +400,7 @@ char *tracefs_instance_file_read(struct tracefs_instance *instance,if (!path)return NULL ; - size =str_read_file (path, &buf); + size =str_read_file (path, &buf, true);tracefs_put_tracing_file (path);if (buf && psize)
src/tracefs-utils.c +5 -3
@@ -196,7 +196,7 @@ void tracefs_put_tracing_file(char *name)free (name); } -__hidden int str_read_file(const char *file, char **buffer) +__hidden int str_read_file(const char *file, char **buffer, bool warn) {char stbuf[BUFSIZ ];char *buf =NULL ;
@@ -207,7 +207,8 @@ __hidden int str_read_file(const char *file, char **buffer) fd =open (file,O_RDONLY );if (fd <0 ) { -tracefs_warning ("File %s not found" , file); +if (warn) +tracefs_warning ("File %s not found" , file);return -1 ; }
@@ -217,7 +218,8 @@ __hidden int str_read_file(const char *file, char **buffer)continue ; nbuf =realloc (buf, size+r+1 );if (!nbuf) { -tracefs_warning ("Failed to allocate file buffer" ); +if (warn) +tracefs_warning ("Failed to allocate file buffer" ); size =-1 ;break ; }
Signature · 1 line
2.29.2
PATCH 3/3 libtracefs: Add loading of mappings in fill_local_events_system()
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
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.
--- src/tracefs-events.c | 66 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+)
src/tracefs-events.c +66 -0
@@ -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:
Signature · 1 line
2.29.2