aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-kmem.c
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung@kernel.org>2014-08-12 02:40:38 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2014-08-13 15:33:07 -0400
commit2b2b2c68c64fb9db392940b42355944064f2a4ca (patch)
tree5c4518c91b39ed5a619e980ff57839f8d451fd4d /tools/perf/builtin-kmem.c
parent1cb8bdcca0e2f738a492c3857568cf34ba4a4373 (diff)
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(). Signed-off-by: Namhyung Kim <namhyung@kernel.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Minchan Kim <minchan@kernel.org> Cc: Namhyung Kim <namhyung.kim@lge.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/1407825645-24586-7-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/builtin-kmem.c')
-rw-r--r--tools/perf/builtin-kmem.c49
1 files changed, 28 insertions, 21 deletions
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 84b82397a28e..349d9b46098e 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -405,10 +405,9 @@ static void sort_result(void)
405 __sort_result(&root_caller_stat, &root_caller_sorted, &caller_sort); 405 __sort_result(&root_caller_stat, &root_caller_sorted, &caller_sort);
406} 406}
407 407
408static int __cmd_kmem(void) 408static int __cmd_kmem(struct perf_session *session)
409{ 409{
410 int err = -EINVAL; 410 int err = -EINVAL;
411 struct perf_session *session;
412 const struct perf_evsel_str_handler kmem_tracepoints[] = { 411 const struct perf_evsel_str_handler kmem_tracepoints[] = {
413 { "kmem:kmalloc", perf_evsel__process_alloc_event, }, 412 { "kmem:kmalloc", perf_evsel__process_alloc_event, },
414 { "kmem:kmem_cache_alloc", perf_evsel__process_alloc_event, }, 413 { "kmem:kmem_cache_alloc", perf_evsel__process_alloc_event, },
@@ -417,31 +416,22 @@ static int __cmd_kmem(void)
417 { "kmem:kfree", perf_evsel__process_free_event, }, 416 { "kmem:kfree", perf_evsel__process_free_event, },
418 { "kmem:kmem_cache_free", perf_evsel__process_free_event, }, 417 { "kmem:kmem_cache_free", perf_evsel__process_free_event, },
419 }; 418 };
420 struct perf_data_file file = {
421 .path = input_name,
422 .mode = PERF_DATA_MODE_READ,
423 };
424
425 session = perf_session__new(&file, false, &perf_kmem);
426 if (session == NULL)
427 return -ENOMEM;
428 419
429 if (!perf_session__has_traces(session, "kmem record")) 420 if (!perf_session__has_traces(session, "kmem record"))
430 goto out_delete; 421 goto out;
431 422
432 if (perf_session__set_tracepoints_handlers(session, kmem_tracepoints)) { 423 if (perf_session__set_tracepoints_handlers(session, kmem_tracepoints)) {
433 pr_err("Initializing perf session tracepoint handlers failed\n"); 424 pr_err("Initializing perf session tracepoint handlers failed\n");
434 return -1; 425 goto out;
435 } 426 }
436 427
437 setup_pager(); 428 setup_pager();
438 err = perf_session__process_events(session, &perf_kmem); 429 err = perf_session__process_events(session, &perf_kmem);
439 if (err != 0) 430 if (err != 0)
440 goto out_delete; 431 goto out;
441 sort_result(); 432 sort_result();
442 print_result(session); 433 print_result(session);
443out_delete: 434out:
444 perf_session__delete(session);
445 return err; 435 return err;
446} 436}
447 437
@@ -688,29 +678,46 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)
688 NULL, 678 NULL,
689 NULL 679 NULL
690 }; 680 };
681 struct perf_session *session;
682 struct perf_data_file file = {
683 .path = input_name,
684 .mode = PERF_DATA_MODE_READ,
685 };
686 int ret = -1;
687
691 argc = parse_options_subcommand(argc, argv, kmem_options, 688 argc = parse_options_subcommand(argc, argv, kmem_options,
692 kmem_subcommands, kmem_usage, 0); 689 kmem_subcommands, kmem_usage, 0);
693 690
694 if (!argc) 691 if (!argc)
695 usage_with_options(kmem_usage, kmem_options); 692 usage_with_options(kmem_usage, kmem_options);
696 693
697 symbol__init();
698
699 if (!strncmp(argv[0], "rec", 3)) { 694 if (!strncmp(argv[0], "rec", 3)) {
695 symbol__init();
700 return __cmd_record(argc, argv); 696 return __cmd_record(argc, argv);
701 } else if (!strcmp(argv[0], "stat")) { 697 }
698
699 session = perf_session__new(&file, false, &perf_kmem);
700 if (session == NULL)
701 return -ENOMEM;
702
703 symbol__init();
704
705 if (!strcmp(argv[0], "stat")) {
702 if (cpu__setup_cpunode_map()) 706 if (cpu__setup_cpunode_map())
703 return -1; 707 goto out_delete;
704 708
705 if (list_empty(&caller_sort)) 709 if (list_empty(&caller_sort))
706 setup_sorting(&caller_sort, default_sort_order); 710 setup_sorting(&caller_sort, default_sort_order);
707 if (list_empty(&alloc_sort)) 711 if (list_empty(&alloc_sort))
708 setup_sorting(&alloc_sort, default_sort_order); 712 setup_sorting(&alloc_sort, default_sort_order);
709 713
710 return __cmd_kmem(); 714 ret = __cmd_kmem(session);
711 } else 715 } else
712 usage_with_options(kmem_usage, kmem_options); 716 usage_with_options(kmem_usage, kmem_options);
713 717
714 return 0; 718out_delete:
719 perf_session__delete(session);
720
721 return ret;
715} 722}
716 723