perf tools: Fix vmlinux search path initialization
Namhyung Kim
maintainercover perf tools: Fix vmlinux search path initialization
Hello,
Currently, when perf reports kernel symbols, it tries to look up the sample ip from kallsyms/vmlinux in the build-id cache, and then a running kernel. This can be a problem if it's recorded on a different kernel and failed to find it from the build-id cache for some reason.
We can fix it by using --symfs option but it's annoying for user to do it always. As we already have the kernel version info in the perf.data file, it'd be better to change it to use the info to search the correct file automatically.
Minchan Kim reported this during his kernel work. And this patchset fixes it by using the recorded kernel info.
The patch 1 and 2 are independent fixes so can be applied separately. The patch 3 to 12 are preparation for the patch 13 which move symbol__init() after creating a session.
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_instructionAfter:
# Overhead Command Shared Object Symbol
# ........ .......... ................. ....................
71.87% swapper [kernel.kallsyms] [k] native_safe_haltYou can also get it from 'perf/vmlinux-v1' branch on my tree:
git://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git
Any comments are welcome.
Thanks,
Namhyung
Namhyung Kim (13):
perf script: Fix possible memory leaks
perf tools: Fix a memory leak in vmlinux_path__init() perf annotate: Move session handling out of __cmd_annotate() perf buildid-cache: Move session handling into cmd_buildid_cache() perf inject: Move session handling out of __cmd_inject() perf kmem: Move session handling out of __cmd_kmem() perf kvm: Move call to symbol__init() after creating session perf lock: Move call to symbol__init() after creating session perf sched: Move call to symbol__init() after creating session perf script: Move call to symbol__init() after creating session perf timechart: Move call to symbol__init() after creating session perf trace: Move call to symbol__init() after creating session perf tools: Check recorded kernel version when finding vmlinux
tools/perf/builtin-annotate.c | 75 ++++++++++++++++++++------------------ tools/perf/builtin-buildid-cache.c | 37 +++++++++++-------- tools/perf/builtin-diff.c | 2 +- tools/perf/builtin-inject.c | 31 +++++++++------- tools/perf/builtin-kmem.c | 49 ++++++++++++++----------- tools/perf/builtin-kvm.c | 6 +-- tools/perf/builtin-lock.c | 3 +- tools/perf/builtin-mem.c | 2 +- tools/perf/builtin-record.c | 2 +- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-sched.c | 3 +- tools/perf/builtin-script.c | 40 ++++++++++++-------- tools/perf/builtin-timechart.c | 4 +- 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 | 26 ++++++++----- tools/perf/util/symbol.h | 3 +- 19 files changed, 172 insertions(+), 127 deletions(-)
Signature · 1 line
2.0.0
Namhyung Kim
maintainerPATCH 1/13 perf script: Fix possible memory leaks
Some paths in perf script don't call perf_session__delete() after creating a new session.
--- tools/perf/builtin-script.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-)
tools/perf/builtin-script.c +22 -13
@@ -1471,12 +1471,13 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)bool show_full_info = false;bool header = false;bool header_only = false; +bool script_started = false;char *rec_script_path =NULL ;char *rep_script_path =NULL ;struct perf_session *session;char *script_path =NULL ;const char **__argv; -int i, j, err; +int i, j, err =0 ;struct perf_script script = { .tool = { .sample = process_sample_event,
@@ -1730,14 +1731,15 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)if (header || header_only) {perf_session__fprintf_info (session, stdout, show_full_info);if (header_only) -return 0 ; + goto out_delete; } script.session = session;if (cpu_list) { -if (perf_session__cpu_bitmap (session, cpu_list, cpu_bitmap)) -return -1 ; + err =perf_session__cpu_bitmap (session, cpu_list, cpu_bitmap); +if (err <0 ) + goto out_delete; }if (!no_callchain)
@@ -1752,53 +1754,60 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)if (output_set_by_user ()) {fprintf (stderr,"custom fields not supported for generated scripts" ); -return -1 ; + err = -EINVAL ; + goto out_delete; } input =open (file.path,O_RDONLY );/* input_name */ if (input <0 ) {perror ("failed to open file" ); -return -1 ; + err = -errno; + goto out_delete; } err =fstat (input, &perf_stat);if (err <0 ) {perror ("failed to stat file" ); -return -1 ; + goto out_delete; }if (!perf_stat.st_size) {fprintf (stderr,"zero-sized file, nothing to do!\n" ); -return 0 ; + goto out_delete; } scripting_ops =script_spec__lookup (generate_script_lang);if (!scripting_ops) {fprintf (stderr,"invalid language specifier" ); -return -1 ; + err = -ENOENT ; + goto out_delete; } err = scripting_ops->generate_script (session->tevent.pevent,"perf-script" ); - goto out; + goto out_delete; }if (script_name) { err = scripting_ops->start_script (script_name, argc, argv);if (err) - goto out; + goto out_delete;pr_debug ("perf script started with script %s\n\n" , script_name); + script_started = true; } err =perf_session__check_output_opt (session);if (err <0 ) - goto out; + goto out_delete; err =__cmd_script (&script); +out_delete:perf_session__delete (session); -cleanup_scripting (); + +if (script_started) +cleanup_scripting (); out:return err; }
Signature · 1 line
2.0.0
Adrian Hunter
reviewerRe: [PATCH 01/13] perf script: Fix possible memory leaks
Quoted 51 lines · Namhyung Kim
Some paths in perf script don't call
perf_session__delete()after creating a new session.Cc Adrian Hunter <[email protected]>Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/builtin-script.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-)tools/perf/builtin-script.c +6
-4@@ -1471,12 +1471,13 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)bool show_full_info = false;bool header = false;bool header_only = false; +bool script_started = false;char *rec_script_path =NULL ;char *rep_script_path =NULL ;struct perf_session *session;char *script_path =NULL ;const char **__argv; -int i, j, err; +int i, j, err =0 ;struct perf_script script = { .tool = { .sample = process_sample_event,@@ -1730,14 +1731,15 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)if (header || header_only) {perf_session__fprintf_info (session, stdout, show_full_info);if (header_only) -return 0 ; + goto out_delete; } script.session = session;if (cpu_list) { -if (perf_session__cpu_bitmap (session, cpu_list, cpu_bitmap)) -return -1 ; + err =perf_session__cpu_bitmap (session, cpu_list, cpu_bitmap); +if (err <0 ) + goto out_delete; }if (!no_callchain)@@ -1752,53 +1754,60 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)if (output_set_by_user ()) {fprintf (stderr,"custom fields not supported for generated scripts" );
tools/perf/builtin-script.c int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) · line 1764
Quoted 10 lines
tools/perf/builtin-script.c +3
-2-return -1 ; + err = -EINVAL ; + goto out_delete; } input =open (file.path,O_RDONLY );/* input_name */ if (input <0 ) {perror ("failed to open file" ); -return -1 ; + err = -errno;
Need to get errno before calling perror().
Quoted 38 lines
tools/perf/builtin-script.c +8
-5+ goto out_delete; } err =fstat (input, &perf_stat);if (err <0 ) {perror ("failed to stat file" ); -return -1 ; + goto out_delete; }if (!perf_stat.st_size) {fprintf (stderr,"zero-sized file, nothing to do!\n" ); -return 0 ; + goto out_delete; } scripting_ops =script_spec__lookup (generate_script_lang);if (!scripting_ops) {fprintf (stderr,"invalid language specifier" ); -return -1 ; + err = -ENOENT ; + goto out_delete; } err = scripting_ops->generate_script (session->tevent.pevent,"perf-script" ); - goto out; + goto out_delete; }if (script_name) { err = scripting_ops->start_script (script_name, argc, argv);if (err) - goto out; + goto out_delete;pr_debug ("perf script started with script %s\n\n" , script_name); + script_started = true; }
tools/perf/builtin-script.c int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) · line 1806
Quoted 10 lines
tools/perf/builtin-script.c +2
-1err =perf_session__check_output_opt (session);if (err <0 ) - goto out; + goto out_delete; err =__cmd_script (&script); +out_delete:
I added a flush method in a patch which acme has stashed in his tmp.perf/core branch. It would go here:
if (script_started) flush_scripting();
Quoted 9 lines
tools/perf/builtin-script.c +3
-1perf_session__delete (session); -cleanup_scripting (); + +if (script_started) +cleanup_scripting (); out:return err; }
Namhyung Kim
maintainerRe: [PATCH 01/13] perf script: Fix possible memory leaks
Quoted 8 lines · Adrian Hunter
tools/perf/builtin-script.c int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) · line 1764
Quoted 5 lines · Namhyung Kim
tools/perf/builtin-script.c +1
-1input =open (file.path,O_RDONLY );/* input_name */ if (input <0 ) {perror ("failed to open file" ); -return -1 ; + err = -errno;Need to get errno before calling
perror().
Argh, right.
Quoted 48 lines
Quoted 48 lines
tools/perf/builtin-script.c +9
-6+ goto out_delete; } err =fstat (input, &perf_stat);if (err <0 ) {perror ("failed to stat file" ); -return -1 ; + goto out_delete; }if (!perf_stat.st_size) {fprintf (stderr,"zero-sized file, nothing to do!\n" ); -return 0 ; + goto out_delete; } scripting_ops =script_spec__lookup (generate_script_lang);if (!scripting_ops) {fprintf (stderr,"invalid language specifier" ); -return -1 ; + err = -ENOENT ; + goto out_delete; } err = scripting_ops->generate_script (session->tevent.pevent,"perf-script" ); - goto out; + goto out_delete; }if (script_name) { err = scripting_ops->start_script (script_name, argc, argv);if (err) - goto out; + goto out_delete;pr_debug ("perf script started with script %s\n\n" , script_name); + script_started = true; } err =perf_session__check_output_opt (session);if (err <0 ) - goto out; + goto out_delete; err =__cmd_script (&script);
Quoted 7 lines
Quoted 1 line
+out_delete:
I added a flush method in a patch which acme has stashed in his tmp.perf/core branch. It would go here:
if (script_started) flush_scripting();
Thanks for the info. I'll update once it's merged into acme/perf/core.
Thanks,
Namhyung
Quoted 10 lines
Quoted 10 lines
tools/perf/builtin-script.c +3
-1perf_session__delete (session); -cleanup_scripting (); + +if (script_started) +cleanup_scripting (); out:return err; }
Arnaldo Carvalho de Melo
maintainerRe: [PATCH 01/13] perf script: Fix possible memory leaks
Em Wed, Aug 13, 2014 at 04:05:24PM +0900, Namhyung Kim escreveu:
Quoted 11 lines · Adrian Hunter
Quoted 8 lines · Namhyung Kim
tools/perf/builtin-script.c int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) · line 1764
Quoted 5 lines
tools/perf/builtin-script.c +1
-1input =open (file.path,O_RDONLY );/* input_name */ if (input <0 ) {perror ("failed to open file" ); -return -1 ; + err = -errno;Need to get errno before calling
perror().Argh, right.
I'll fix this up, no need to resubmit.
- Arnaldo
tip-bot for Namhyung Kim
merge bot[tip:perf/core] perf script: Fix possible memory leaks
In reply to Namhyung Kimperf script: Fix possible memory leaks
Commit-ID: 6cc870f09da4d50722bc1caa27cad51733ce36f6 Gitweb: http://git.kernel.org/tip/6cc870f09da4d50722bc1caa27cad51733ce36f6 Author: Namhyung Kim <[email protected]> AuthorDate: Tue, 12 Aug 2014 15:40:33 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 13 Aug 2014 16:29:43 -0300
perf script: Fix possible memory leaks
Some paths in perf script don't call perf_session__delete() after creating a new session.
--- tools/perf/builtin-script.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-)
tools/perf/builtin-script.c +22 -13
@@ -1471,12 +1471,13 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)bool show_full_info = false;bool header = false;bool header_only = false; +bool script_started = false;char *rec_script_path =NULL ;char *rep_script_path =NULL ;struct perf_session *session;char *script_path =NULL ;const char **__argv; -int i, j, err; +int i, j, err =0 ;struct perf_script script = { .tool = { .sample = process_sample_event,
@@ -1730,14 +1731,15 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)if (header || header_only) {perf_session__fprintf_info (session, stdout, show_full_info);if (header_only) -return 0 ; + goto out_delete; } script.session = session;if (cpu_list) { -if (perf_session__cpu_bitmap (session, cpu_list, cpu_bitmap)) -return -1 ; + err =perf_session__cpu_bitmap (session, cpu_list, cpu_bitmap); +if (err <0 ) + goto out_delete; }if (!no_callchain)
@@ -1752,53 +1754,60 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)if (output_set_by_user ()) {fprintf (stderr,"custom fields not supported for generated scripts" ); -return -1 ; + err = -EINVAL ; + goto out_delete; } input =open (file.path,O_RDONLY );/* input_name */ if (input <0 ) { + err = -errno;perror ("failed to open file" ); -return -1 ; + goto out_delete; } err =fstat (input, &perf_stat);if (err <0 ) {perror ("failed to stat file" ); -return -1 ; + goto out_delete; }if (!perf_stat.st_size) {fprintf (stderr,"zero-sized file, nothing to do!\n" ); -return 0 ; + goto out_delete; } scripting_ops =script_spec__lookup (generate_script_lang);if (!scripting_ops) {fprintf (stderr,"invalid language specifier" ); -return -1 ; + err = -ENOENT ; + goto out_delete; } err = scripting_ops->generate_script (session->tevent.pevent,"perf-script" ); - goto out; + goto out_delete; }if (script_name) { err = scripting_ops->start_script (script_name, argc, argv);if (err) - goto out; + goto out_delete;pr_debug ("perf script started with script %s\n\n" , script_name); + script_started = true; } err =perf_session__check_output_opt (session);if (err <0 ) - goto out; + goto out_delete; err =__cmd_script (&script); +out_delete:perf_session__delete (session); -cleanup_scripting (); + +if (script_started) +cleanup_scripting (); out:return err; }
Namhyung Kim
maintainerPATCH 2/13 perf tools: Fix a memory leak in vmlinux_path__init()
In reply to Namhyung KimWhen uname() failed, it should free vmlinux_path.
--- tools/perf/util/symbol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/symbol.c +1 -1
@@ -1772,7 +1772,7 @@ static int vmlinux_path__init(void)return 0 ;if (uname (&uts) <0 ) -return -1 ; + goto out_fail;snprintf (bf,sizeof (bf),"/boot/vmlinux-%s" , uts.release); vmlinux_path[vmlinux_path__nr_entries] =strdup (bf);
Signature · 1 line
2.0.0
tip-bot for Namhyung Kim
merge bot[tip:perf/core] perf symbols: Fix a memory leak in vmlinux_path__init()
perf symbols: Fix a memory leak in vmlinux_path__init()
Commit-ID: e96c674fe2c228fd5c16fd7a7607c60dea4cdaa2 Gitweb: http://git.kernel.org/tip/e96c674fe2c228fd5c16fd7a7607c60dea4cdaa2 Author: Namhyung Kim <[email protected]> AuthorDate: Tue, 12 Aug 2014 15:40:34 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 13 Aug 2014 16:30:22 -0300
perf symbols: Fix a memory leak in vmlinux_path__init()
When uname() failed, it should free vmlinux_path.
--- tools/perf/util/symbol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/symbol.c +1 -1
@@ -1772,7 +1772,7 @@ static int vmlinux_path__init(void)return 0 ;if (uname (&uts) <0 ) -return -1 ; + goto out_fail;snprintf (bf,sizeof (bf),"/boot/vmlinux-%s" , uts.release); vmlinux_path[vmlinux_path__nr_entries] =strdup (bf);
Namhyung Kim
maintainerPATCH 3/13 perf annotate: Move session handling out of __cmd_annotate()
In reply to Namhyung KimThis is a preparation of fixing dso__load_kernel_sym(). It needs a session info before calling symbol__init().
--- tools/perf/builtin-annotate.c | 75 +++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 35 deletions(-)
tools/perf/builtin-annotate.c +40 -35
@@ -36,7 +36,8 @@struct perf_annotate {struct perf_tool tool; -bool force, use_tui, use_stdio, use_gtk; +struct perf_session *session; +bool use_tui, use_stdio, use_gtk;bool full_paths;bool print_line;bool skip_missing;
@@ -188,18 +189,9 @@ find_next:static int __cmd_annotate (struct perf_annotate *ann) {int ret; -struct perf_session *session; +struct perf_session *session = ann->session;struct perf_evsel *pos;u64 total_nr_samples; -struct perf_data_file file = { - .path = input_name, - .mode =PERF_DATA_MODE_READ , - .force = ann->force, - }; - - session =perf_session__new (&file, false, &ann->tool); -if (session ==NULL ) -return -ENOMEM ;machines__set_symbol_filter (&session->machines, symbol__annotate_init);
@@ -207,22 +199,22 @@ static int __cmd_annotate(struct perf_annotate *ann) ret =perf_session__cpu_bitmap (session, ann->cpu_list, ann->cpu_bitmap);if (ret) - goto out_delete; + goto out; }if (!objdump_path) { ret =perf_session_env__lookup_objdump (&session->header.env);if (ret) - goto out_delete; + goto out; } ret =perf_session__process_events (session, &ann->tool);if (ret) - goto out_delete; + goto out;if (dump_trace) {perf_session__fprintf_nr_events (session, stdout); - goto out_delete; + goto out; }if (verbose >3 )
@@ -250,8 +242,8 @@ static int __cmd_annotate(struct perf_annotate *ann) }if (total_nr_samples ==0 ) { -ui__error ("The %s file has no samples!\n" , file.path); - goto out_delete; +ui__error ("The %s file has no samples!\n" , session->file->path); + goto out; }if (use_browser ==2 ) {
@@ -261,24 +253,12 @@ static int __cmd_annotate(struct perf_annotate *ann) "perf_gtk__show_annotations");if (show_annotations ==NULL ) {ui__error ("GTK browser not found!\n" ); - goto out_delete; + goto out; }show_annotations (); } -out_delete: -/* -* Speed up the exit process, for large files this can -* take quite a while. -* -* XXX Enable this when using valgrind or if we ever -* librarize this command. -* -* Also experiment with obstacks to see how much speed -* up we'll get here. -* -* perf_session__delete(session); -*/ +out:return ret; }
@@ -301,6 +281,10 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused) .ordering_requires_timestamps = true, }, }; +struct perf_data_file file = { + .path = input_name, + .mode =PERF_DATA_MODE_READ , + };const struct option options[] = {OPT_STRING ('i' ,"input" , &input_name,"file" , "input file name"),
@@ -308,7 +292,7 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused) "only consider symbols in these dsos"),OPT_STRING ('s' ,"symbol" , &annotate.sym_hist_filter,"symbol" ,"symbol to annotate" ), -OPT_BOOLEAN ('f' ,"force" , &annotate.force,"don't complain, do it" ), +OPT_BOOLEAN ('f' ,"force" , &file.force,"don't complain, do it" ),OPT_INCR ('v' ,"verbose" , &verbose,"be more verbose (show symbol address, etc)" ), OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
@@ -341,6 +325,7 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused) "Show event group information together"), OPT_END() }; +int ret; argc =parse_options (argc, argv, options, annotate_usage,0 );
@@ -353,11 +338,16 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused)setup_browser (true); + annotate.session =perf_session__new (&file, false, &annotate.tool); +if (annotate.session ==NULL ) +return -ENOMEM ; + symbol_conf.priv_size =sizeof (struct annotation ); symbol_conf.try_vmlinux_path = true; -if (symbol__init () <0 ) -return -1 ; + ret =symbol__init (); +if (ret <0 ) + goto out_delete;if (setup_sorting () <0 )usage_with_options (annotate_usage, options);
@@ -373,5 +363,20 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused) annotate.sym_hist_filter = argv[0 ]; } -return __cmd_annotate (&annotate); + ret =__cmd_annotate (&annotate); + +out_delete: +/* +* Speed up the exit process, for large files this can +* take quite a while. +* +* XXX Enable this when using valgrind or if we ever +* librarize this command. +* +* Also experiment with obstacks to see how much speed +* up we'll get here. +* +* perf_session__delete(session); +*/ +return ret; }
Signature · 1 line
2.0.0
Re: [PATCH 03/13] perf annotate: Move session handling out of __cmd_annotate()
On Tue, Aug 12, 2014 at 03:40:35PM +0900, Namhyung Kim wrote:
SNIP
Quoted 30 lines
tools/perf/builtin-annotate.c +6
-1@@ -301,6 +281,10 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused) .ordering_requires_timestamps = true, }, }; +struct perf_data_file file = { + .path = input_name, + .mode =PERF_DATA_MODE_READ , + };const struct option options[] = {OPT_STRING ('i' ,"input" , &input_name,"file" , "input file name"),@@ -308,7 +292,7 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused) "only consider symbols in these dsos"),OPT_STRING ('s' ,"symbol" , &annotate.sym_hist_filter,"symbol" ,"symbol to annotate" ), -OPT_BOOLEAN ('f' ,"force" , &annotate.force,"don't complain, do it" ), +OPT_BOOLEAN ('f' ,"force" , &file.force,"don't complain, do it" ),OPT_INCR ('v' ,"verbose" , &verbose,"be more verbose (show symbol address, etc)" ), OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,@@ -341,6 +325,7 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused) "Show event group information together"), OPT_END() }; +int ret; argc =parse_options (argc, argv, options, annotate_usage,0 );
tools/perf/builtin-annotate.c int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused) · line 343
Quoted 6 lines
tools/perf/builtin-annotate.c +3
-0@@ -353,11 +338,16 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused)setup_browser (true); + annotate.session =perf_session__new (&file, false, &annotate.tool); +if (annotate.session ==NULL ) +return -ENOMEM ;
I know you're just moving code, but perf_session__new could fail for more reasons than just ENOMEM, which is the most unlikely case ;-) -1 is probably better option here
jirka
Re: [PATCH 03/13] perf annotate: Move session handling out of __cmd_annotate()
Quoted 8 lines · Jiri Olsa
tools/perf/builtin-annotate.c int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused) · line 343
Quoted 3 lines · Namhyung Kim
tools/perf/builtin-annotate.c +3
-0+ annotate.session =perf_session__new (&file, false, &annotate.tool); +if (annotate.session ==NULL ) +return -ENOMEM ;I know you're just moving code, but
perf_session__newcould fail for more reasons than just ENOMEM, which is the most unlikely case ;-) -1 is probably better option here
Okay, will change as a separate fix later.
Thanks,
Namhyung
tip-bot for Namhyung Kim
merge bot[tip:perf/core] perf annotate: Move session handling out of __cmd_annotate()
In reply to Namhyung Kimperf annotate: Move session handling out of __cmd_annotate()
Commit-ID: fa10f316d59f39020d19d3f4a323598d05afa65c Gitweb: http://git.kernel.org/tip/fa10f316d59f39020d19d3f4a323598d05afa65c Author: Namhyung Kim <[email protected]> AuthorDate: Tue, 12 Aug 2014 15:40:35 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 13 Aug 2014 16:31:23 -0300
perf annotate: Move session handling out of __cmd_annotate()
This is a preparation of fixing dso__load_kernel_sym(). It needs a session info before calling symbol__init().
--- tools/perf/builtin-annotate.c | 75 +++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 35 deletions(-)
tools/perf/builtin-annotate.c +40 -35
@@ -36,7 +36,8 @@struct perf_annotate {struct perf_tool tool; -bool force, use_tui, use_stdio, use_gtk; +struct perf_session *session; +bool use_tui, use_stdio, use_gtk;bool full_paths;bool print_line;bool skip_missing;
@@ -188,18 +189,9 @@ find_next:static int __cmd_annotate (struct perf_annotate *ann) {int ret; -struct perf_session *session; +struct perf_session *session = ann->session;struct perf_evsel *pos;u64 total_nr_samples; -struct perf_data_file file = { - .path = input_name, - .mode =PERF_DATA_MODE_READ , - .force = ann->force, - }; - - session =perf_session__new (&file, false, &ann->tool); -if (session ==NULL ) -return -ENOMEM ;machines__set_symbol_filter (&session->machines, symbol__annotate_init);
@@ -207,22 +199,22 @@ static int __cmd_annotate(struct perf_annotate *ann) ret =perf_session__cpu_bitmap (session, ann->cpu_list, ann->cpu_bitmap);if (ret) - goto out_delete; + goto out; }if (!objdump_path) { ret =perf_session_env__lookup_objdump (&session->header.env);if (ret) - goto out_delete; + goto out; } ret =perf_session__process_events (session, &ann->tool);if (ret) - goto out_delete; + goto out;if (dump_trace) {perf_session__fprintf_nr_events (session, stdout); - goto out_delete; + goto out; }if (verbose >3 )
@@ -250,8 +242,8 @@ static int __cmd_annotate(struct perf_annotate *ann) }if (total_nr_samples ==0 ) { -ui__error ("The %s file has no samples!\n" , file.path); - goto out_delete; +ui__error ("The %s file has no samples!\n" , session->file->path); + goto out; }if (use_browser ==2 ) {
@@ -261,24 +253,12 @@ static int __cmd_annotate(struct perf_annotate *ann) "perf_gtk__show_annotations");if (show_annotations ==NULL ) {ui__error ("GTK browser not found!\n" ); - goto out_delete; + goto out; }show_annotations (); } -out_delete: -/* -* Speed up the exit process, for large files this can -* take quite a while. -* -* XXX Enable this when using valgrind or if we ever -* librarize this command. -* -* Also experiment with obstacks to see how much speed -* up we'll get here. -* -* perf_session__delete(session); -*/ +out:return ret; }
@@ -301,6 +281,10 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused) .ordering_requires_timestamps = true, }, }; +struct perf_data_file file = { + .path = input_name, + .mode =PERF_DATA_MODE_READ , + };const struct option options[] = {OPT_STRING ('i' ,"input" , &input_name,"file" , "input file name"),
@@ -308,7 +292,7 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused) "only consider symbols in these dsos"),OPT_STRING ('s' ,"symbol" , &annotate.sym_hist_filter,"symbol" ,"symbol to annotate" ), -OPT_BOOLEAN ('f' ,"force" , &annotate.force,"don't complain, do it" ), +OPT_BOOLEAN ('f' ,"force" , &file.force,"don't complain, do it" ),OPT_INCR ('v' ,"verbose" , &verbose,"be more verbose (show symbol address, etc)" ), OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
@@ -341,6 +325,7 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused) "Show event group information together"), OPT_END() }; +int ret; argc =parse_options (argc, argv, options, annotate_usage,0 );
@@ -353,11 +338,16 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused)setup_browser (true); + annotate.session =perf_session__new (&file, false, &annotate.tool); +if (annotate.session ==NULL ) +return -ENOMEM ; + symbol_conf.priv_size =sizeof (struct annotation ); symbol_conf.try_vmlinux_path = true; -if (symbol__init () <0 ) -return -1 ; + ret =symbol__init (); +if (ret <0 ) + goto out_delete;if (setup_sorting () <0 )usage_with_options (annotate_usage, options);
@@ -373,5 +363,20 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused) annotate.sym_hist_filter = argv[0 ]; } -return __cmd_annotate (&annotate); + ret =__cmd_annotate (&annotate); + +out_delete: +/* +* Speed up the exit process, for large files this can +* take quite a while. +* +* XXX Enable this when using valgrind or if we ever +* librarize this command. +* +* Also experiment with obstacks to see how much speed +* up we'll get here. +* +* perf_session__delete(session); +*/ +return ret; }
Namhyung Kim
maintainerPATCH 4/13 perf buildid-cache: Move session handling into cmd_buildid_cache()
In reply to Namhyung KimThis is a preparation of fixing dso__load_kernel_sym(). It needs a session info before calling symbol__init().
--- tools/perf/builtin-buildid-cache.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-)
tools/perf/builtin-buildid-cache.c +21 -14
@@ -246,20 +246,9 @@ static bool dso__missing_buildid_cache(struct dso *dso, int parm __maybe_unused)return true; } -static int build_id_cache__fprintf_missing (const char *filename,bool force,FILE *fp) +static int build_id_cache__fprintf_missing (struct perf_session *session,FILE *fp) { -struct perf_data_file file = { - .path = filename, - .mode =PERF_DATA_MODE_READ , - .force = force, - }; -struct perf_session *session =perf_session__new (&file, false,NULL ); -if (session ==NULL ) -return -1 ; -perf_session__fprintf_dsos_buildid (session, fp, dso__missing_buildid_cache,0 ); -perf_session__delete (session); -return 0 ; }
@@ -303,6 +292,11 @@ int cmd_buildid_cache(int argc, const char **argv, *update_name_list_str =NULL , *kcore_filename; +struct perf_data_file file = { + .mode =PERF_DATA_MODE_READ , + }; +struct perf_session *session =NULL ; +const struct option buildid_cache_options[] = {OPT_STRING ('a' ,"add" , &add_name_list_str,"file list" ,"file(s) to add" ),
@@ -326,8 +320,17 @@ int cmd_buildid_cache(int argc, const char **argv, argc =parse_options (argc, argv, buildid_cache_options, buildid_cache_usage,0 ); +if (missing_filename) { + file.path = missing_filename; + file.force = force; + + session =perf_session__new (&file, false,NULL ); +if (session ==NULL ) +return -1 ; + } +if (symbol__init () <0 ) -return -1 ; + goto out;setup_pager ();
@@ -370,7 +373,7 @@ int cmd_buildid_cache(int argc, const char **argv, }if (missing_filename) - ret =build_id_cache__fprintf_missing (missing_filename, force, stdout); + ret =build_id_cache__fprintf_missing (session, stdout);if (update_name_list_str) { list =strlist__new (true, update_name_list_str);
@@ -394,5 +397,9 @@ int cmd_buildid_cache(int argc, const char **argv, build_id_cache__add_kcore(kcore_filename, debugdir, force))pr_warning ("Couldn't add %s\n" , kcore_filename); +out: +if (session) +perf_session__delete (session); +return ret; }
Signature · 1 line
2.0.0
tip-bot for Namhyung Kim
merge bot[tip:perf/core] perf buildid-cache: Move session handling into cmd_buildid_cache()
perf buildid-cache: Move session handling into cmd_buildid_cache()
Commit-ID: e3ed75bb537a860a375ca1e09ad1b87c707f1636 Gitweb: http://git.kernel.org/tip/e3ed75bb537a860a375ca1e09ad1b87c707f1636 Author: Namhyung Kim <[email protected]> AuthorDate: Tue, 12 Aug 2014 15:40:36 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 13 Aug 2014 16:32:19 -0300
perf buildid-cache: Move session handling into cmd_buildid_cache()
This is a preparation of fixing dso__load_kernel_sym(). It needs a session info before calling symbol__init().
--- tools/perf/builtin-buildid-cache.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-)
tools/perf/builtin-buildid-cache.c +21 -14
@@ -246,20 +246,9 @@ static bool dso__missing_buildid_cache(struct dso *dso, int parm __maybe_unused)return true; } -static int build_id_cache__fprintf_missing (const char *filename,bool force,FILE *fp) +static int build_id_cache__fprintf_missing (struct perf_session *session,FILE *fp) { -struct perf_data_file file = { - .path = filename, - .mode =PERF_DATA_MODE_READ , - .force = force, - }; -struct perf_session *session =perf_session__new (&file, false,NULL ); -if (session ==NULL ) -return -1 ; -perf_session__fprintf_dsos_buildid (session, fp, dso__missing_buildid_cache,0 ); -perf_session__delete (session); -return 0 ; }
@@ -303,6 +292,11 @@ int cmd_buildid_cache(int argc, const char **argv, *update_name_list_str =NULL , *kcore_filename; +struct perf_data_file file = { + .mode =PERF_DATA_MODE_READ , + }; +struct perf_session *session =NULL ; +const struct option buildid_cache_options[] = {OPT_STRING ('a' ,"add" , &add_name_list_str,"file list" ,"file(s) to add" ),
@@ -326,8 +320,17 @@ int cmd_buildid_cache(int argc, const char **argv, argc =parse_options (argc, argv, buildid_cache_options, buildid_cache_usage,0 ); +if (missing_filename) { + file.path = missing_filename; + file.force = force; + + session =perf_session__new (&file, false,NULL ); +if (session ==NULL ) +return -1 ; + } +if (symbol__init () <0 ) -return -1 ; + goto out;setup_pager ();
@@ -370,7 +373,7 @@ int cmd_buildid_cache(int argc, const char **argv, }if (missing_filename) - ret =build_id_cache__fprintf_missing (missing_filename, force, stdout); + ret =build_id_cache__fprintf_missing (session, stdout);if (update_name_list_str) { list =strlist__new (true, update_name_list_str);
@@ -394,5 +397,9 @@ int cmd_buildid_cache(int argc, const char **argv, build_id_cache__add_kcore(kcore_filename, debugdir, force))pr_warning ("Couldn't add %s\n" , kcore_filename); +out: +if (session) +perf_session__delete (session); +return ret; }
Namhyung Kim
maintainerPATCH 5/13 perf inject: Move session handling out of __cmd_inject()
In reply to Namhyung KimThis is a preparation of fixing dso__load_kernel_sym(). It needs a session info before calling symbol__init().
--- tools/perf/builtin-inject.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-)
tools/perf/builtin-inject.c +17 -12
@@ -23,6 +23,7 @@struct perf_inject {struct perf_tool tool; +struct perf_session *session;bool build_ids;bool sched_stat;const char *input_name;
@@ -340,12 +341,8 @@ static int perf_evsel__check_stype(struct perf_evsel *evsel,static int __cmd_inject (struct perf_inject *inject) { -struct perf_session *session;int ret = -EINVAL ; -struct perf_data_file file = { - .path = inject->input_name, - .mode =PERF_DATA_MODE_READ , - }; +struct perf_session *session = inject->session;struct perf_data_file *file_out = &inject->output;signal (SIGINT , sig_handler);
@@ -357,10 +354,6 @@ static int __cmd_inject(struct perf_inject *inject) inject->tool.tracing_data = perf_event__repipe_tracing_data; } - session =perf_session__new (&file, true, &inject->tool); -if (session ==NULL ) -return -ENOMEM ; -if (inject->build_ids) { inject->tool.sample = perf_event__inject_buildid; }else if (inject->sched_stat) {
@@ -396,8 +389,6 @@ static int __cmd_inject(struct perf_inject *inject)perf_session__write_header (session, session->evlist, file_out->fd, true); } -perf_session__delete (session); -return ret; }
@@ -427,6 +418,11 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused) .mode = PERF_DATA_MODE_WRITE, }, }; +struct perf_data_file file = { + .mode =PERF_DATA_MODE_READ , + }; +int ret; +const struct option options[] = {OPT_BOOLEAN ('b' ,"build-ids" , &inject.build_ids, "Inject build-ids into the output stream"),
@@ -461,8 +457,17 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)return -1 ; } + file.path = inject.input_name; + inject.session =perf_session__new (&file, true, &inject.tool); +if (inject.session ==NULL ) +return -ENOMEM ; +if (symbol__init () <0 )return -1 ; -return __cmd_inject (&inject); + ret =__cmd_inject (&inject); + +perf_session__delete (inject.session); + +return ret; }
Signature · 1 line
2.0.0
tip-bot for Namhyung Kim
merge bot[tip:perf/core] perf inject: Move session handling out of __cmd_inject()
perf inject: Move session handling out of __cmd_inject()
Commit-ID: 1cb8bdcca0e2f738a492c3857568cf34ba4a4373 Gitweb: http://git.kernel.org/tip/1cb8bdcca0e2f738a492c3857568cf34ba4a4373 Author: Namhyung Kim <[email protected]> AuthorDate: Tue, 12 Aug 2014 15:40:37 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 13 Aug 2014 16:32:39 -0300
perf inject: Move session handling out of __cmd_inject()
This is a preparation of fixing dso__load_kernel_sym(). It needs a session info before calling symbol__init().
--- tools/perf/builtin-inject.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-)
tools/perf/builtin-inject.c +17 -12
@@ -23,6 +23,7 @@struct perf_inject {struct perf_tool tool; +struct perf_session *session;bool build_ids;bool sched_stat;const char *input_name;
@@ -340,12 +341,8 @@ static int perf_evsel__check_stype(struct perf_evsel *evsel,static int __cmd_inject (struct perf_inject *inject) { -struct perf_session *session;int ret = -EINVAL ; -struct perf_data_file file = { - .path = inject->input_name, - .mode =PERF_DATA_MODE_READ , - }; +struct perf_session *session = inject->session;struct perf_data_file *file_out = &inject->output;signal (SIGINT , sig_handler);
@@ -357,10 +354,6 @@ static int __cmd_inject(struct perf_inject *inject) inject->tool.tracing_data = perf_event__repipe_tracing_data; } - session =perf_session__new (&file, true, &inject->tool); -if (session ==NULL ) -return -ENOMEM ; -if (inject->build_ids) { inject->tool.sample = perf_event__inject_buildid; }else if (inject->sched_stat) {
@@ -396,8 +389,6 @@ static int __cmd_inject(struct perf_inject *inject)perf_session__write_header (session, session->evlist, file_out->fd, true); } -perf_session__delete (session); -return ret; }
@@ -427,6 +418,11 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused) .mode = PERF_DATA_MODE_WRITE, }, }; +struct perf_data_file file = { + .mode =PERF_DATA_MODE_READ , + }; +int ret; +const struct option options[] = {OPT_BOOLEAN ('b' ,"build-ids" , &inject.build_ids, "Inject build-ids into the output stream"),
@@ -461,8 +457,17 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)return -1 ; } + file.path = inject.input_name; + inject.session =perf_session__new (&file, true, &inject.tool); +if (inject.session ==NULL ) +return -ENOMEM ; +if (symbol__init () <0 )return -1 ; -return __cmd_inject (&inject); + ret =__cmd_inject (&inject); + +perf_session__delete (inject.session); + +return ret; }
Namhyung Kim
maintainerPATCH 6/13 perf kmem: Move session handling out of __cmd_kmem()
In reply to Namhyung KimThis is a preparation of fixing dso__load_kernel_sym(). It needs a session info before calling symbol__init().
--- tools/perf/builtin-kmem.c | 49 +++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 21 deletions(-)
tools/perf/builtin-kmem.c +28 -21
@@ -405,10 +405,9 @@ static void sort_result(void)__sort_result (&root_caller_stat, &root_caller_sorted, &caller_sort); } -static int __cmd_kmem (void ) +static int __cmd_kmem (struct perf_session *session) {int err = -EINVAL ; -struct perf_session *session;const struct perf_evsel_str_handler kmem_tracepoints[] = { {"kmem:kmalloc" , perf_evsel__process_alloc_event, }, {"kmem:kmem_cache_alloc" , perf_evsel__process_alloc_event, },
@@ -417,31 +416,22 @@ static int __cmd_kmem(void) { "kmem:kfree", perf_evsel__process_free_event, }, { "kmem:kmem_cache_free", perf_evsel__process_free_event, }, }; -struct perf_data_file file = { - .path = input_name, - .mode =PERF_DATA_MODE_READ , - }; - - session =perf_session__new (&file, false, &perf_kmem); -if (session ==NULL ) -return -ENOMEM ;if (!perf_session__has_traces (session,"kmem record" )) - goto out_delete; + goto out;if (perf_session__set_tracepoints_handlers (session, kmem_tracepoints)) {pr_err ("Initializing perf session tracepoint handlers failed\n" ); -return -1 ; + goto out; }setup_pager (); err =perf_session__process_events (session, &perf_kmem);if (err !=0 ) - goto out_delete; + goto out;sort_result ();print_result (session); -out_delete: -perf_session__delete (session); +out:return err; }
@@ -688,29 +678,46 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)NULL ,NULL }; +struct perf_session *session; +struct perf_data_file file = { + .path = input_name, + .mode =PERF_DATA_MODE_READ , + }; +int ret =-1 ; + argc =parse_options_subcommand (argc, argv, kmem_options, kmem_subcommands, kmem_usage,0 );if (!argc)usage_with_options (kmem_usage, kmem_options); -symbol__init (); -if (!strncmp (argv[0 ],"rec" ,3 )) { +symbol__init ();return __cmd_record (argc, argv); - }else if (!strcmp (argv[0 ],"stat" )) { + } + + session =perf_session__new (&file, false, &perf_kmem); +if (session ==NULL ) +return -ENOMEM ; + +symbol__init (); + +if (!strcmp (argv[0 ],"stat" )) {if (cpu__setup_cpunode_map ()) -return -1 ; + goto out_delete;if (list_empty (&caller_sort))setup_sorting (&caller_sort, default_sort_order);if (list_empty (&alloc_sort))setup_sorting (&alloc_sort, default_sort_order); -return __cmd_kmem (); + ret =__cmd_kmem (session); }else usage_with_options (kmem_usage, kmem_options); -return 0 ; +out_delete: +perf_session__delete (session); + +return ret; }
Signature · 1 line
2.0.0
tip-bot for Namhyung Kim
merge bot[tip:perf/core] perf kmem: Move session handling out of __cmd_kmem()
perf kmem: Move session handling out of __cmd_kmem()
Commit-ID: 2b2b2c68c64fb9db392940b42355944064f2a4ca Gitweb: http://git.kernel.org/tip/2b2b2c68c64fb9db392940b42355944064f2a4ca Author: Namhyung Kim <[email protected]> AuthorDate: Tue, 12 Aug 2014 15:40:38 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 13 Aug 2014 16:33:07 -0300
perf kmem: Move session handling out of __cmd_kmem()
This is a preparation of fixing dso__load_kernel_sym(). It needs a session info before calling symbol__init().
--- tools/perf/builtin-kmem.c | 49 +++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 21 deletions(-)
tools/perf/builtin-kmem.c +28 -21
@@ -405,10 +405,9 @@ static void sort_result(void)__sort_result (&root_caller_stat, &root_caller_sorted, &caller_sort); } -static int __cmd_kmem (void ) +static int __cmd_kmem (struct perf_session *session) {int err = -EINVAL ; -struct perf_session *session;const struct perf_evsel_str_handler kmem_tracepoints[] = { {"kmem:kmalloc" , perf_evsel__process_alloc_event, }, {"kmem:kmem_cache_alloc" , perf_evsel__process_alloc_event, },
@@ -417,31 +416,22 @@ static int __cmd_kmem(void) { "kmem:kfree", perf_evsel__process_free_event, }, { "kmem:kmem_cache_free", perf_evsel__process_free_event, }, }; -struct perf_data_file file = { - .path = input_name, - .mode =PERF_DATA_MODE_READ , - }; - - session =perf_session__new (&file, false, &perf_kmem); -if (session ==NULL ) -return -ENOMEM ;if (!perf_session__has_traces (session,"kmem record" )) - goto out_delete; + goto out;if (perf_session__set_tracepoints_handlers (session, kmem_tracepoints)) {pr_err ("Initializing perf session tracepoint handlers failed\n" ); -return -1 ; + goto out; }setup_pager (); err =perf_session__process_events (session, &perf_kmem);if (err !=0 ) - goto out_delete; + goto out;sort_result ();print_result (session); -out_delete: -perf_session__delete (session); +out:return err; }
@@ -688,29 +678,46 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)NULL ,NULL }; +struct perf_session *session; +struct perf_data_file file = { + .path = input_name, + .mode =PERF_DATA_MODE_READ , + }; +int ret =-1 ; + argc =parse_options_subcommand (argc, argv, kmem_options, kmem_subcommands, kmem_usage,0 );if (!argc)usage_with_options (kmem_usage, kmem_options); -symbol__init (); -if (!strncmp (argv[0 ],"rec" ,3 )) { +symbol__init ();return __cmd_record (argc, argv); - }else if (!strcmp (argv[0 ],"stat" )) { + } + + session =perf_session__new (&file, false, &perf_kmem); +if (session ==NULL ) +return -ENOMEM ; + +symbol__init (); + +if (!strcmp (argv[0 ],"stat" )) {if (cpu__setup_cpunode_map ()) -return -1 ; + goto out_delete;if (list_empty (&caller_sort))setup_sorting (&caller_sort, default_sort_order);if (list_empty (&alloc_sort))setup_sorting (&alloc_sort, default_sort_order); -return __cmd_kmem (); + ret =__cmd_kmem (session); }else usage_with_options (kmem_usage, kmem_options); -return 0 ; +out_delete: +perf_session__delete (session); + +return ret; }
Namhyung Kim
maintainerPATCH 7/13 perf kvm: Move call to symbol__init() after creating session
In reply to Namhyung KimThis is a preparation of fixing dso__load_kernel_sym(). It needs a session info before calling symbol__init().
--- tools/perf/builtin-kvm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/builtin-kvm.c +2 -2
@@ -1072,6 +1072,8 @@ static int read_events(struct perf_kvm_stat *kvm)return -EINVAL ; } +symbol__init (); +if (!perf_session__has_traces (kvm->session,"kvm record" ))return -EINVAL ;
@@ -1201,8 +1203,6 @@ kvm_events_report(struct perf_kvm_stat *kvm, int argc, const char **argv)NULL }; -symbol__init (); -if (argc) { argc = parse_options(argc, argv, kvm_events_report_options,
Signature · 1 line
2.0.0
tip-bot for Namhyung Kim
merge bot[tip:perf/core] perf kvm: Move call to symbol__init() after creating session
perf kvm: Move call to symbol__init() after creating session
Commit-ID: 14d37f38e956ba0dd4f2206f68534eb418ecd905 Gitweb: http://git.kernel.org/tip/14d37f38e956ba0dd4f2206f68534eb418ecd905 Author: Namhyung Kim <[email protected]> AuthorDate: Tue, 12 Aug 2014 15:40:39 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 13 Aug 2014 16:33:43 -0300
perf kvm: Move call to symbol__init() after creating session
This is a preparation of fixing dso__load_kernel_sym(). It needs a session info before calling symbol__init().
--- tools/perf/builtin-kvm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/builtin-kvm.c +2 -2
@@ -1064,6 +1064,8 @@ static int read_events(struct perf_kvm_stat *kvm)return -EINVAL ; } +symbol__init (); +if (!perf_session__has_traces (kvm->session,"kvm record" ))return -EINVAL ;
@@ -1193,8 +1195,6 @@ kvm_events_report(struct perf_kvm_stat *kvm, int argc, const char **argv)NULL }; -symbol__init (); -if (argc) { argc = parse_options(argc, argv, kvm_events_report_options,
Namhyung Kim
maintainerPATCH 8/13 perf lock: Move call to symbol__init() after creating session
In reply to Namhyung KimThis is a preparation of fixing dso__load_kernel_sym(). It needs a session info before calling symbol__init().
--- tools/perf/builtin-lock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/builtin-lock.c +2 -1
@@ -865,6 +865,8 @@ static int __cmd_report(bool display_info)return -ENOMEM ; } +symbol__init (); +if (!perf_session__has_traces (session,"lock record" )) goto out_delete;
@@ -974,7 +976,6 @@ int cmd_lock(int argc, const char **argv, const char *prefix __maybe_unused)unsigned int i;int rc =0 ; -symbol__init ();for (i =0 ; i <LOCKHASH_SIZE ; i++)INIT_LIST_HEAD (lockhash_table + i);
Signature · 1 line
2.0.0
tip-bot for Namhyung Kim
merge bot[tip:perf/core] perf lock: Move call to symbol__init() after creating session
perf lock: Move call to symbol__init() after creating session
Commit-ID: 6fd6c6b462c55f33c20f38051f1116dc52054d67 Gitweb: http://git.kernel.org/tip/6fd6c6b462c55f33c20f38051f1116dc52054d67 Author: Namhyung Kim <[email protected]> AuthorDate: Tue, 12 Aug 2014 15:40:40 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 13 Aug 2014 16:34:06 -0300
perf lock: Move call to symbol__init() after creating session
This is a preparation of fixing dso__load_kernel_sym(). It needs a session info before calling symbol__init().
--- tools/perf/builtin-lock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/builtin-lock.c +2 -1
@@ -865,6 +865,8 @@ static int __cmd_report(bool display_info)return -ENOMEM ; } +symbol__init (); +if (!perf_session__has_traces (session,"lock record" )) goto out_delete;
@@ -974,7 +976,6 @@ int cmd_lock(int argc, const char **argv, const char *prefix __maybe_unused)unsigned int i;int rc =0 ; -symbol__init ();for (i =0 ; i <LOCKHASH_SIZE ; i++)INIT_LIST_HEAD (lockhash_table + i);
Namhyung Kim
maintainerPATCH 9/13 perf sched: Move call to symbol__init() after creating session
In reply to Namhyung KimThis is a preparation of fixing dso__load_kernel_sym(). It needs a session info before calling symbol__init().
--- tools/perf/builtin-sched.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/builtin-sched.c +2 -1
@@ -1462,6 +1462,8 @@ static int perf_sched__read_events(struct perf_sched *sched,return -1 ; } +symbol__init (); +if (perf_session__set_tracepoints_handlers (session, handlers)) goto out_delete;
@@ -1747,7 +1749,6 @@ 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 ();if (!strncmp (argv[0 ],"rec" ,3 )) {return __cmd_record (argc, argv); }else if (!strncmp (argv[0 ],"lat" ,3 )) {
Signature · 1 line
2.0.0
tip-bot for Namhyung Kim
merge bot[tip:perf/core] perf sched: Move call to symbol__init() after creating session
perf sched: Move call to symbol__init() after creating session
Commit-ID: 0493410612486cadaa4e076caf4df3fa9cd20fde Gitweb: http://git.kernel.org/tip/0493410612486cadaa4e076caf4df3fa9cd20fde Author: Namhyung Kim <[email protected]> AuthorDate: Tue, 12 Aug 2014 15:40:41 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 13 Aug 2014 16:34:29 -0300
perf sched: Move call to symbol__init() after creating session
This is a preparation of fixing dso__load_kernel_sym(). It needs a session info before calling symbol__init().
--- tools/perf/builtin-sched.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/builtin-sched.c +2 -1
@@ -1462,6 +1462,8 @@ static int perf_sched__read_events(struct perf_sched *sched,return -1 ; } +symbol__init (); +if (perf_session__set_tracepoints_handlers (session, handlers)) goto out_delete;
@@ -1747,7 +1749,6 @@ 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 ();if (!strncmp (argv[0 ],"rec" ,3 )) {return __cmd_record (argc, argv); }else if (!strncmp (argv[0 ],"lat" ,3 )) {
Namhyung Kim
maintainerPATCH 10/13 perf script: Move call to symbol__init() after creating session
In reply to Namhyung KimThis is a preparation of fixing dso__load_kernel_sym(). It needs a session info before calling symbol__init().
--- tools/perf/builtin-script.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
tools/perf/builtin-script.c +3 -2
@@ -1719,8 +1719,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 ();
@@ -1734,6 +1732,9 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) goto out_delete; } +if (symbol__init () <0 ) + goto out_delete; + script.session = session;if (cpu_list) {
Signature · 1 line
2.0.0
tip-bot for Namhyung Kim
merge bot[tip:perf/core] perf script: Move call to symbol__init() after creating session
perf script: Move call to symbol__init() after creating session
Commit-ID: 38520dc31206bae1dc811ddd59ccea3a6536784d Gitweb: http://git.kernel.org/tip/38520dc31206bae1dc811ddd59ccea3a6536784d Author: Namhyung Kim <[email protected]> AuthorDate: Tue, 12 Aug 2014 15:40:42 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 13 Aug 2014 16:35:00 -0300
perf script: Move call to symbol__init() after creating session
This is a preparation of fixing dso__load_kernel_sym(). It needs a session info before calling symbol__init().
--- tools/perf/builtin-script.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
tools/perf/builtin-script.c +3 -2
@@ -1719,8 +1719,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 ();
@@ -1734,6 +1732,9 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) goto out_delete; } +if (symbol__init () <0 ) + goto out_delete; + script.session = session;if (cpu_list) {
Namhyung Kim
maintainerPATCH 11/13 perf timechart: Move call to symbol__init() after creating session
In reply to Namhyung KimThis is a preparation of fixing dso__load_kernel_sym(). It needs a session info before calling symbol__init().
--- tools/perf/builtin-timechart.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/builtin-timechart.c +2 -2
@@ -1607,6 +1607,8 @@ static int __cmd_timechart(struct timechart *tchart, const char *output_name)if (session ==NULL )return -ENOMEM ; +symbol__init (); + (void)perf_header__process_sections(&session->header, perf_data_file__fd(session->file), tchart,
@@ -1982,8 +1984,6 @@ int cmd_timechart(int argc, const char **argv,return -1 ; } -symbol__init (); -if (argc && !strncmp (argv[0 ],"rec" ,3 )) { argc =parse_options (argc, argv, record_options, record_usage,PARSE_OPT_STOP_AT_NON_OPTION );
Signature · 1 line
2.0.0
tip-bot for Namhyung Kim
merge bot[tip:perf/core] perf timechart: Move call to symbol__init() after creating session
perf timechart: Move call to symbol__init() after creating session
Commit-ID: dc5c8190b800dc59eff6bb2aa47ea749712197df Gitweb: http://git.kernel.org/tip/dc5c8190b800dc59eff6bb2aa47ea749712197df Author: Namhyung Kim <[email protected]> AuthorDate: Tue, 12 Aug 2014 15:40:43 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 13 Aug 2014 16:35:19 -0300
perf timechart: Move call to symbol__init() after creating session
This is a preparation of fixing dso__load_kernel_sym(). It needs a session info before calling symbol__init().
--- tools/perf/builtin-timechart.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/builtin-timechart.c +2 -2
@@ -1607,6 +1607,8 @@ static int __cmd_timechart(struct timechart *tchart, const char *output_name)if (session ==NULL )return -ENOMEM ; +symbol__init (); + (void)perf_header__process_sections(&session->header, perf_data_file__fd(session->file), tchart,
@@ -1982,8 +1984,6 @@ int cmd_timechart(int argc, const char **argv,return -1 ; } -symbol__init (); -if (argc && !strncmp (argv[0 ],"rec" ,3 )) { argc =parse_options (argc, argv, record_options, record_usage,PARSE_OPT_STOP_AT_NON_OPTION );
Namhyung Kim
maintainerPATCH 12/13 perf trace: Move call to symbol__init() after creating session
In reply to Namhyung KimThis is a preparation of fixing dso__load_kernel_sym(). It needs a session info before calling symbol__init().
--- tools/perf/builtin-trace.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/perf/builtin-trace.c +3 -3
@@ -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 () <0 ) + goto out; + trace->host = &session->machines.host; err =perf_session__set_tracepoints_handlers (session, handlers);
Signature · 1 line
2.0.0
tip-bot for Namhyung Kim
merge bot[tip:perf/core] perf trace: Move call to symbol__init() after creating session
perf trace: Move call to symbol__init() after creating session
Commit-ID: cb2ffae241cfdd6d90acb7ec5f52ad8401885dd2 Gitweb: http://git.kernel.org/tip/cb2ffae241cfdd6d90acb7ec5f52ad8401885dd2 Author: Namhyung Kim <[email protected]> AuthorDate: Tue, 12 Aug 2014 15:40:44 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 13 Aug 2014 16:41:38 -0300
perf trace: Move call to symbol__init() after creating session
This is a preparation of fixing dso__load_kernel_sym(). It needs a session info before calling symbol__init().
--- tools/perf/builtin-trace.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/perf/builtin-trace.c +3 -3
@@ -2241,13 +2241,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 () <0 ) + goto out; + trace->host = &session->machines.host; err =perf_session__set_tracepoints_handlers (session, handlers);
Namhyung Kim
maintainerPATCH 13/13 perf tools: Check recorded kernel version when finding vmlinux
In reply to Namhyung KimCurrently 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 kernel version 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_instructionAfter:
# 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 *.
--- 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 | 4 ++-- 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 | 2 +- tools/perf/builtin-timechart.c | 2 +- tools/perf/builtin-top.c | 2 +- tools/perf/builtin-trace.c | 4 ++-- tools/perf/tests/builtin-test.c | 2 +- tools/perf/util/probe-event.c | 2 +- tools/perf/util/symbol.c | 26 +++++++++++++++++--------- tools/perf/util/symbol.h | 3 ++- 19 files changed, 39 insertions(+), 30 deletions(-)
tools/perf/builtin-annotate.c +1 -1
@@ -345,7 +345,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; - ret =symbol__init (); + ret =symbol__init (&annotate.session->header.env);if (ret <0 ) goto out_delete;
tools/perf/builtin-buildid-cache.c +1 -1
@@ -329,7 +329,7 @@ int cmd_buildid_cache(int argc, const char **argv,return -1 ; } -if (symbol__init () <0 ) +if (symbol__init (session ? &session->header.env :NULL ) <0 ) goto out;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
@@ -462,7 +462,7 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)if (inject.session ==NULL )return -ENOMEM ; -if (symbol__init () <0 ) +if (symbol__init (&inject.session->header.env) <0 )return -1 ; ret =__cmd_inject (&inject);
tools/perf/builtin-kmem.c +2 -2
@@ -692,7 +692,7 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)usage_with_options (kmem_usage, kmem_options);if (!strncmp (argv[0 ],"rec" ,3 )) { -symbol__init (); +symbol__init (NULL );return __cmd_record (argc, argv); }
@@ -700,7 +700,7 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)if (session ==NULL )return -ENOMEM ; -symbol__init (); +symbol__init (&session->header.env);if (!strcmp (argv[0 ],"stat" )) {if (cpu__setup_cpunode_map ())
tools/perf/builtin-kvm.c +2 -2
@@ -1072,7 +1072,7 @@ static int read_events(struct perf_kvm_stat *kvm)return -EINVAL ; } -symbol__init (); +symbol__init (&kvm->session->header.env);if (!perf_session__has_traces (kvm->session,"kvm record" ))return -EINVAL ;
@@ -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
@@ -865,7 +865,7 @@ static int __cmd_report(bool display_info)return -ENOMEM ; } -symbol__init (); +symbol__init (&session->header.env);if (!perf_session__has_traces (session,"lock record" )) goto out_delete;
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
@@ -908,7 +908,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
@@ -798,7 +798,7 @@ repeat: } } -if (symbol__init () <0 ) +if (symbol__init (&session->header.env) <0 ) goto error;if (argc) {
tools/perf/builtin-sched.c +1 -1
@@ -1462,7 +1462,7 @@ static int perf_sched__read_events(struct perf_sched *sched,return -1 ; } -symbol__init (); +symbol__init (&session->header.env);if (perf_session__set_tracepoints_handlers (session, handlers)) goto out_delete;
tools/perf/builtin-script.c +1 -1
@@ -1732,7 +1732,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) goto out_delete; } -if (symbol__init () <0 ) +if (symbol__init (&session->header.env) <0 ) goto out_delete; script.session = session;
tools/perf/builtin-timechart.c +1 -1
@@ -1607,7 +1607,7 @@ static int __cmd_timechart(struct timechart *tchart, const char *output_name)if (session ==NULL )return -ENOMEM ; -symbol__init (); +symbol__init (&session->header.env); (void)perf_header__process_sections(&session->header, perf_data_file__fd(session->file),
tools/perf/builtin-top.c +1 -1
@@ -1222,7 +1222,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 +2 -2
@@ -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;
@@ -2219,7 +2219,7 @@ static int trace__replay(struct trace *trace)if (session ==NULL )return -ENOMEM ; -if (symbol__init () <0 ) +if (symbol__init (&session->header.env) <0 ) goto out; trace->host = &session->machines.host;
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 +17 -9
@@ -15,6 +15,7 @@#include "machine.h" #include "symbol.h" #include "strlist.h" +#include "header.h" #include <elf.h> #include <limits.h>
@@ -1749,10 +1750,11 @@ 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 ]; +char *kernel_version; vmlinux_path =malloc (sizeof (char *) *5 );if (vmlinux_path ==NULL )
@@ -1767,25 +1769,31 @@ static int vmlinux_path__init(void) goto out_fail; ++vmlinux_path__nr_entries; -/* only try running kernel version if no symfs was given */ +/* only try kernel version if no symfs was given */ if (symbol_conf.symfs[0 ] !=0 )return 0 ; -if (uname (&uts) <0 ) - goto out_fail; +if (env) { + kernel_version = env->os_release; + }else { +if (uname (&uts) <0 ) + goto out_fail; + + kernel_version = uts.release; + } -snprintf (bf,sizeof (bf),"/boot/vmlinux-%s" , uts.release); +snprintf (bf,sizeof (bf),"/boot/vmlinux-%s" , kernel_version); vmlinux_path[vmlinux_path__nr_entries] =strdup (bf);if (vmlinux_path[vmlinux_path__nr_entries] ==NULL ) goto out_fail; ++vmlinux_path__nr_entries; -snprintf (bf,sizeof (bf),"/lib/modules/%s/build/vmlinux" , uts.release); +snprintf (bf,sizeof (bf),"/lib/modules/%s/build/vmlinux" , kernel_version); vmlinux_path[vmlinux_path__nr_entries] =strdup (bf);if (vmlinux_path[vmlinux_path__nr_entries] ==NULL ) goto out_fail; ++vmlinux_path__nr_entries;snprintf (bf,sizeof (bf),"/usr/lib/debug/lib/modules/%s/vmlinux" , - uts.release); + kernel_version); vmlinux_path[vmlinux_path__nr_entries] =strdup (bf);if (vmlinux_path[vmlinux_path__nr_entries] ==NULL ) goto out_fail;
@@ -1831,7 +1839,7 @@ static bool symbol__read_kptr_restrict(void)return value; } -int symbol__init (void ) +int symbol__init (struct perf_session_env *env) {const char *symfs;
@@ -1846,7 +1854,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
@@ -262,7 +262,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
tip-bot for Namhyung Kim
merge bot[tip:perf/core] perf tools: Check recorded kernel version when finding vmlinux
perf tools: Check recorded kernel version when finding vmlinux
Commit-ID: 0a7e6d1b6844bec2d6817615a693c7fce447b80d Gitweb: http://git.kernel.org/tip/0a7e6d1b6844bec2d6817615a693c7fce447b80d Author: Namhyung Kim <[email protected]> AuthorDate: Tue, 12 Aug 2014 15:40:45 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 13 Aug 2014 16:42:21 -0300
perf tools: Check recorded kernel version when finding vmlinux
Currently 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 kernel version 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_instructionAfter:
# 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 *.
--- 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 | 4 ++-- 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 | 2 +- tools/perf/builtin-timechart.c | 2 +- tools/perf/builtin-top.c | 2 +- tools/perf/builtin-trace.c | 4 ++-- tools/perf/tests/builtin-test.c | 2 +- tools/perf/util/probe-event.c | 2 +- tools/perf/util/symbol.c | 26 +++++++++++++++++--------- tools/perf/util/symbol.h | 3 ++- 19 files changed, 39 insertions(+), 30 deletions(-)
tools/perf/builtin-annotate.c +1 -1
@@ -345,7 +345,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; - ret =symbol__init (); + ret =symbol__init (&annotate.session->header.env);if (ret <0 ) goto out_delete;
tools/perf/builtin-buildid-cache.c +1 -1
@@ -329,7 +329,7 @@ int cmd_buildid_cache(int argc, const char **argv,return -1 ; } -if (symbol__init () <0 ) +if (symbol__init (session ? &session->header.env :NULL ) <0 ) goto out;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
@@ -462,7 +462,7 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)if (inject.session ==NULL )return -ENOMEM ; -if (symbol__init () <0 ) +if (symbol__init (&inject.session->header.env) <0 )return -1 ; ret =__cmd_inject (&inject);
tools/perf/builtin-kmem.c +2 -2
@@ -692,7 +692,7 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)usage_with_options (kmem_usage, kmem_options);if (!strncmp (argv[0 ],"rec" ,3 )) { -symbol__init (); +symbol__init (NULL );return __cmd_record (argc, argv); }
@@ -700,7 +700,7 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)if (session ==NULL )return -ENOMEM ; -symbol__init (); +symbol__init (&session->header.env);if (!strcmp (argv[0 ],"stat" )) {if (cpu__setup_cpunode_map ())
tools/perf/builtin-kvm.c +2 -2
@@ -1064,7 +1064,7 @@ static int read_events(struct perf_kvm_stat *kvm)return -EINVAL ; } -symbol__init (); +symbol__init (&kvm->session->header.env);if (!perf_session__has_traces (kvm->session,"kvm record" ))return -EINVAL ;
@@ -1314,7 +1314,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
@@ -865,7 +865,7 @@ static int __cmd_report(bool display_info)return -ENOMEM ; } -symbol__init (); +symbol__init (&session->header.env);if (!perf_session__has_traces (session,"lock record" )) goto out_delete;
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
@@ -908,7 +908,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
@@ -798,7 +798,7 @@ repeat: } } -if (symbol__init () <0 ) +if (symbol__init (&session->header.env) <0 ) goto error;if (argc) {
tools/perf/builtin-sched.c +1 -1
@@ -1462,7 +1462,7 @@ static int perf_sched__read_events(struct perf_sched *sched,return -1 ; } -symbol__init (); +symbol__init (&session->header.env);if (perf_session__set_tracepoints_handlers (session, handlers)) goto out_delete;
tools/perf/builtin-script.c +1 -1
@@ -1732,7 +1732,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) goto out_delete; } -if (symbol__init () <0 ) +if (symbol__init (&session->header.env) <0 ) goto out_delete; script.session = session;
tools/perf/builtin-timechart.c +1 -1
@@ -1607,7 +1607,7 @@ static int __cmd_timechart(struct timechart *tchart, const char *output_name)if (session ==NULL )return -ENOMEM ; -symbol__init (); +symbol__init (&session->header.env); (void)perf_header__process_sections(&session->header, perf_data_file__fd(session->file),
tools/perf/builtin-top.c +1 -1
@@ -1234,7 +1234,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 +2 -2
@@ -1411,7 +1411,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;
@@ -2245,7 +2245,7 @@ static int trace__replay(struct trace *trace)if (session ==NULL )return -ENOMEM ; -if (symbol__init () <0 ) +if (symbol__init (&session->header.env) <0 ) goto out; trace->host = &session->machines.host;
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 +17 -9
@@ -15,6 +15,7 @@#include "machine.h" #include "symbol.h" #include "strlist.h" +#include "header.h" #include <elf.h> #include <limits.h>
@@ -1749,10 +1750,11 @@ 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 ]; +char *kernel_version; vmlinux_path =malloc (sizeof (char *) *5 );if (vmlinux_path ==NULL )
@@ -1767,25 +1769,31 @@ static int vmlinux_path__init(void) goto out_fail; ++vmlinux_path__nr_entries; -/* only try running kernel version if no symfs was given */ +/* only try kernel version if no symfs was given */ if (symbol_conf.symfs[0 ] !=0 )return 0 ; -if (uname (&uts) <0 ) - goto out_fail; +if (env) { + kernel_version = env->os_release; + }else { +if (uname (&uts) <0 ) + goto out_fail; + + kernel_version = uts.release; + } -snprintf (bf,sizeof (bf),"/boot/vmlinux-%s" , uts.release); +snprintf (bf,sizeof (bf),"/boot/vmlinux-%s" , kernel_version); vmlinux_path[vmlinux_path__nr_entries] =strdup (bf);if (vmlinux_path[vmlinux_path__nr_entries] ==NULL ) goto out_fail; ++vmlinux_path__nr_entries; -snprintf (bf,sizeof (bf),"/lib/modules/%s/build/vmlinux" , uts.release); +snprintf (bf,sizeof (bf),"/lib/modules/%s/build/vmlinux" , kernel_version); vmlinux_path[vmlinux_path__nr_entries] =strdup (bf);if (vmlinux_path[vmlinux_path__nr_entries] ==NULL ) goto out_fail; ++vmlinux_path__nr_entries;snprintf (bf,sizeof (bf),"/usr/lib/debug/lib/modules/%s/vmlinux" , - uts.release); + kernel_version); vmlinux_path[vmlinux_path__nr_entries] =strdup (bf);if (vmlinux_path[vmlinux_path__nr_entries] ==NULL ) goto out_fail;
@@ -1831,7 +1839,7 @@ static bool symbol__read_kptr_restrict(void)return value; } -int symbol__init (void ) +int symbol__init (struct perf_session_env *env) {const char *symfs;
@@ -1846,7 +1854,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
@@ -262,7 +262,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);
On Tue, Aug 12, 2014 at 03:40:32PM +0900, Namhyung Kim wrote:
SNIP
Quoted 4 lines
Thanks,
Namhyung
Quoted 14 lines
Namhyung Kim (13):
perf script: Fix possible memory leaks
perf tools: Fix a memory leak invmlinux_path__init()perf annotate: Move session handling out of__cmd_annotate()perf buildid-cache: Move session handling intocmd_buildid_cache()perf inject: Move session handling out of__cmd_inject()perf kmem: Move session handling out of__cmd_kmem()perf kvm: Move call tosymbol__init()after creating session perf lock: Move call tosymbol__init()after creating session perf sched: Move call tosymbol__init()after creating session perf script: Move call tosymbol__init()after creating session perf timechart: Move call tosymbol__init()after creating session perf trace: Move call tosymbol__init()after creating session perf tools: Check recorded kernel version when finding vmlinux
apart from that issue found by Adrian
thanks,
jirka