perf tools: Check recorded kernel version when finding vmlinux
Namhyung Kim
maintainerCurrently vmlinux_path__init() only tries to find vmlinux file from current directory, /boot and some canonical directories with version number of the running kernel. This can be a problem when reporting old data recorded on a custom kernel not running currently.
We can use --symfs option for this but it's annoying for user to do it always. As we already have the info in the perf.data file, it can be changed to use it for the search automatically.
Before:
$ perf report
...
# Samples: 4K of event 'cpu-clock'
# Event count (approx.): 1067250000
#
# Overhead Command Shared Object Symbol
# ........ .......... ................. ...............................
71.87% swapper [kernel.kallsyms] [k] recover_probed_instructtionAfter:
# Overhead Command Shared Object Symbol
# ........ .......... ................. ....................
71.87% swapper [kernel.kallsyms] [k] native_safe_haltThis requires to change signature of symbol__init() to receive struct perf_session_env *. This patch only does some trivial changes - some tools might want to change their structure to setup session info before calling symbol__init() later.
--- tools/perf/builtin-annotate.c | 2 +- tools/perf/builtin-buildid-cache.c | 2 +- tools/perf/builtin-diff.c | 2 +- tools/perf/builtin-inject.c | 2 +- tools/perf/builtin-kmem.c | 2 +- tools/perf/builtin-kvm.c | 4 ++-- tools/perf/builtin-lock.c | 2 +- tools/perf/builtin-mem.c | 2 +- tools/perf/builtin-record.c | 2 +- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-sched.c | 2 +- tools/perf/builtin-script.c | 10 +++++----- tools/perf/builtin-timechart.c | 2 +- tools/perf/builtin-top.c | 2 +- tools/perf/builtin-trace.c | 8 ++++---- tools/perf/tests/builtin-test.c | 2 +- tools/perf/util/probe-event.c | 2 +- tools/perf/util/symbol.c | 18 ++++++++++++++---- tools/perf/util/symbol.h | 3 ++- 19 files changed, 41 insertions(+), 30 deletions(-)
tools/perf/builtin-annotate.c +1 -1
@@ -356,7 +356,7 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused) symbol_conf.priv_size =sizeof (struct annotation ); symbol_conf.try_vmlinux_path = true; -if (symbol__init () <0 ) +if (symbol__init (NULL ) <0 )return -1 ;if (setup_sorting () <0 )
tools/perf/builtin-buildid-cache.c +1 -1
@@ -326,7 +326,7 @@ int cmd_buildid_cache(int argc, const char **argv, argc =parse_options (argc, argv, buildid_cache_options, buildid_cache_usage,0 ); -if (symbol__init () <0 ) +if (symbol__init (NULL ) <0 )return -1 ;setup_pager ();
tools/perf/builtin-diff.c +1 -1
@@ -1143,7 +1143,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix __maybe_unused) argc =parse_options (argc, argv, options, diff_usage,0 ); -if (symbol__init () <0 ) +if (symbol__init (NULL ) <0 )return -1 ;if (data_init (argc, argv) <0 )
tools/perf/builtin-inject.c +1 -1
@@ -459,7 +459,7 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)return -1 ; } -if (symbol__init () <0 ) +if (symbol__init (NULL ) <0 )return -1 ;return __cmd_inject (&inject);
tools/perf/builtin-kmem.c +1 -1
@@ -695,7 +695,7 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)if (!argc)usage_with_options (kmem_usage, kmem_options); -symbol__init (); +symbol__init (NULL );if (!strncmp (argv[0 ],"rec" ,3 )) {return __cmd_record (argc, argv);
tools/perf/builtin-kvm.c +2 -2
@@ -1201,7 +1201,7 @@ kvm_events_report(struct perf_kvm_stat *kvm, int argc, const char **argv)NULL }; -symbol__init (); +symbol__init (NULL );if (argc) { argc = parse_options(argc, argv,
@@ -1322,7 +1322,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm, kvm->opts.target.uid_str =NULL ; kvm->opts.target.uid =UINT_MAX ; -symbol__init (); +symbol__init (NULL );disable_buildid_cache (); use_browser =0 ;
tools/perf/builtin-lock.c +1 -1
@@ -974,7 +974,7 @@ int cmd_lock(int argc, const char **argv, const char *prefix __maybe_unused)unsigned int i;int rc =0 ; -symbol__init (); +symbol__init (NULL );for (i =0 ; i <LOCKHASH_SIZE ; i++)INIT_LIST_HEAD (lockhash_table + i);
tools/perf/builtin-mem.c +1 -1
@@ -133,7 +133,7 @@ static int report_raw_events(struct perf_mem *mem) goto out_delete; } -if (symbol__init () <0 ) +if (symbol__init (&session->header.env) <0 )return -1 ;printf ("# PID, TID, IP, ADDR, LOCAL WEIGHT, DSRC, SYMBOL\n" );
tools/perf/builtin-record.c +1 -1
@@ -902,7 +902,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)usage_with_options (record_usage, record_options); } -symbol__init (); +symbol__init (NULL );if (symbol_conf.kptr_restrict) pr_warning(
tools/perf/builtin-report.c +1 -1
@@ -787,7 +787,7 @@ repeat: } } -if (symbol__init () <0 ) +if (symbol__init (&session->header.env) <0 ) goto error;if (argc) {
tools/perf/builtin-sched.c +1 -1
@@ -1747,7 +1747,7 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)if (!strcmp (argv[0 ],"script" ))return cmd_script (argc, argv, prefix); -symbol__init (); +symbol__init (NULL );if (!strncmp (argv[0 ],"rec" ,3 )) {return __cmd_record (argc, argv); }else if (!strncmp (argv[0 ],"lat" ,3 )) {
tools/perf/builtin-script.c +5 -5
@@ -1740,11 +1740,6 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)exit (-1 ); } -if (symbol__init () <0 ) -return -1 ; -if (!script_name) -setup_pager (); - session =perf_session__new (&file, false, &script.tool);if (session ==NULL )return -ENOMEM ;
@@ -1757,6 +1752,11 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) script.session = session; +if (symbol__init (&session->header.env) <0 ) +return -1 ; +if (!script_name) +setup_pager (); +if (cpu_list) {if (perf_session__cpu_bitmap (session, cpu_list, cpu_bitmap))return -1 ;
tools/perf/builtin-timechart.c +1 -1
@@ -1982,7 +1982,7 @@ int cmd_timechart(int argc, const char **argv,return -1 ; } -symbol__init (); +symbol__init (NULL );if (argc && !strncmp (argv[0 ],"rec" ,3 )) { argc = parse_options(argc, argv, record_options, record_usage,
tools/perf/builtin-top.c +1 -1
@@ -1217,7 +1217,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused) symbol_conf.priv_size =sizeof (struct annotation ); symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name ==NULL ); -if (symbol__init () <0 ) +if (symbol__init (NULL ) <0 )return -1 ;sort__setup_elide (stdout);
tools/perf/builtin-trace.c +4 -4
@@ -1385,7 +1385,7 @@ static int trace__tool_process(struct perf_tool *tool,static int trace__symbols_init (struct trace *trace,struct perf_evlist *evlist) { -int err =symbol__init (); +int err =symbol__init (NULL );if (err)return err;
@@ -2215,13 +2215,13 @@ static int trace__replay(struct trace *trace)/* add tid to output */ trace->multiple_threads = true; -if (symbol__init () <0 ) -return -1 ; - session =perf_session__new (&file, false, &trace->tool);if (session ==NULL )return -ENOMEM ; +if (symbol__init (&session->header.env) <0 ) + goto out; + trace->host = &session->machines.host; err =perf_session__set_tracepoints_handlers (session, handlers);
tools/perf/tests/builtin-test.c +1 -1
@@ -297,7 +297,7 @@ int cmd_test(int argc, const char **argv, const char *prefix __maybe_unused) symbol_conf.sort_by_name = true; symbol_conf.try_vmlinux_path = true; -if (symbol__init () <0 ) +if (symbol__init (NULL ) <0 )return -1 ;if (skip !=NULL )
tools/perf/util/probe-event.c +1 -1
@@ -79,7 +79,7 @@ static int init_symbol_maps(bool user_only)int ret; symbol_conf.sort_by_name = true; - ret =symbol__init (); + ret =symbol__init (NULL );if (ret <0 ) {pr_debug ("Failed to init symbol map.\n" ); goto out;
tools/perf/util/symbol.c +14 -4
@@ -15,6 +15,7 @@#include "machine.h" #include "symbol.h" #include "strlist.h" +#include "header.h" #include <elf.h> #include <limits.h>
@@ -1745,12 +1746,12 @@ static void vmlinux_path__exit(void)zfree (&vmlinux_path); } -static int vmlinux_path__init (void ) +static int vmlinux_path__init (struct perf_session_env *env) {struct utsname uts;char bf[PATH_MAX ]; - vmlinux_path =malloc (sizeof (char *) *5 ); + vmlinux_path =malloc (sizeof (char *) *6 );if (vmlinux_path ==NULL )return -1 ;
@@ -1763,6 +1764,15 @@ static int vmlinux_path__init(void) goto out_fail; ++vmlinux_path__nr_entries; +if (env) { +snprintf (bf,sizeof (bf),"/lib/modules/%s/build/vmlinux" , + env->os_release); + vmlinux_path[vmlinux_path__nr_entries] =strdup (bf); +if (vmlinux_path[vmlinux_path__nr_entries] ==NULL ) + goto out_fail; + ++vmlinux_path__nr_entries; + } +/* only try running kernel version if no symfs was given */ if (symbol_conf.symfs[0 ] !=0 )return 0 ;
@@ -1827,7 +1837,7 @@ static bool symbol__read_kptr_restrict(void)return value; } -int symbol__init (void ) +int symbol__init (struct perf_session_env *env) {char *symfs;
@@ -1842,7 +1852,7 @@ int symbol__init(void) symbol_conf.priv_size += (sizeof (struct symbol_name_rb_node ) -sizeof (struct symbol )); -if (symbol_conf.try_vmlinux_path &&vmlinux_path__init () <0 ) +if (symbol_conf.try_vmlinux_path &&vmlinux_path__init (env) <0 )return -1 ;if (symbol_conf.field_sep && *symbol_conf.field_sep =='.' ) {
tools/perf/util/symbol.h +2 -1
@@ -251,7 +251,8 @@ int modules__parse(const char *filename, void *arg,int filename__read_debuglink (const char *filename,char *debuglink,size_t size); -int symbol__init (void ); +struct perf_session_env ; +int symbol__init (struct perf_session_env *env);void symbol__exit (void );void symbol__elf_init (void );struct symbol *symbol__new (u64 start,u64 len,u8 binding,const char *name);
Signature · 1 line
2.0.0
Quoted 2 lines · Namhyung Kim
This requires to change signature of
symbol__init()to receive structperf_session_env*. This patch only does some trivial changes - some
Why only pass the env for perf-report? Why not for any command analyzing a file? So for live commands env is NULL meaning use host paths; for recorded files pass env from session header and use it (plus symbol settings like symfs).
David
Namhyung Kim
maintainerHi David,
Quoted 8 lines · David Ahern
Quoted 2 lines · Namhyung Kim
This requires to change signature of
symbol__init()to receive structperf_session_env*. This patch only does some trivial changes - someWhy only pass the env for perf-report? Why not for any command analyzing a file? So for live commands env is NULL meaning use host paths; for recorded files pass env from session header and use it (plus symbol settings like symfs).
Yes, it needs other changes like you said. But I'd like to hear from your opinions on the problem and proposed fix before going further.
My other concern is that why it isn't covered by a build-id cache.
Thanks,
Namhyung