aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-kmem.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2012-10-01 14:20:58 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-10-02 17:36:32 -0400
commit0433ffbe47d66c5c561b54340ee47adf8826bcc4 (patch)
tree3bad3ffdd6c42f5fd1200336c227833a7dce458f /tools/perf/builtin-kmem.c
parent2bae1d1b1aa3b763b99431101a04dfe24ec5ba7f (diff)
perf kmem: Don't use globals where not needed to
Some variables were global but used in just one function, so move it to where it belongs. Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Namhyung Kim <namhyung@gmail.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/n/tip-wu8lz0g2qg26aqgi51xgzkpp@git.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.c66
1 files changed, 26 insertions, 40 deletions
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index bc912c68f49a..14bf82f63659 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -21,8 +21,6 @@
21struct alloc_stat; 21struct alloc_stat;
22typedef int (*sort_fn_t)(struct alloc_stat *, struct alloc_stat *); 22typedef int (*sort_fn_t)(struct alloc_stat *, struct alloc_stat *);
23 23
24static const char *input_name;
25
26static int alloc_flag; 24static int alloc_flag;
27static int caller_flag; 25static int caller_flag;
28 26
@@ -31,8 +29,6 @@ static int caller_lines = -1;
31 29
32static bool raw_ip; 30static bool raw_ip;
33 31
34static char default_sort_order[] = "frag,hit,bytes";
35
36static int *cpunode_map; 32static int *cpunode_map;
37static int max_cpu_num; 33static int max_cpu_num;
38 34
@@ -481,7 +477,7 @@ static void sort_result(void)
481 __sort_result(&root_caller_stat, &root_caller_sorted, &caller_sort); 477 __sort_result(&root_caller_stat, &root_caller_sorted, &caller_sort);
482} 478}
483 479
484static int __cmd_kmem(void) 480static int __cmd_kmem(const char *input_name)
485{ 481{
486 int err = -EINVAL; 482 int err = -EINVAL;
487 struct perf_session *session; 483 struct perf_session *session;
@@ -520,11 +516,6 @@ out_delete:
520 return err; 516 return err;
521} 517}
522 518
523static const char * const kmem_usage[] = {
524 "perf kmem [<options>] {record|stat}",
525 NULL
526};
527
528static int ptr_cmp(struct alloc_stat *l, struct alloc_stat *r) 519static int ptr_cmp(struct alloc_stat *l, struct alloc_stat *r)
529{ 520{
530 if (l->ptr < r->ptr) 521 if (l->ptr < r->ptr)
@@ -720,41 +711,17 @@ static int parse_line_opt(const struct option *opt __maybe_unused,
720 return 0; 711 return 0;
721} 712}
722 713
723static const struct option kmem_options[] = { 714static int __cmd_record(int argc, const char **argv)
724 OPT_STRING('i', "input", &input_name, "file", 715{
725 "input file name"), 716 const char * const record_args[] = {
726 OPT_CALLBACK_NOOPT(0, "caller", NULL, NULL, 717 "record", "-a", "-R", "-f", "-c", "1",
727 "show per-callsite statistics",
728 parse_caller_opt),
729 OPT_CALLBACK_NOOPT(0, "alloc", NULL, NULL,
730 "show per-allocation statistics",
731 parse_alloc_opt),
732 OPT_CALLBACK('s', "sort", NULL, "key[,key2...]",
733 "sort by keys: ptr, call_site, bytes, hit, pingpong, frag",
734 parse_sort_opt),
735 OPT_CALLBACK('l', "line", NULL, "num",
736 "show n lines",
737 parse_line_opt),
738 OPT_BOOLEAN(0, "raw-ip", &raw_ip, "show raw ip instead of symbol"),
739 OPT_END()
740};
741
742static const char *record_args[] = {
743 "record",
744 "-a",
745 "-R",
746 "-f",
747 "-c", "1",
748 "-e", "kmem:kmalloc", 718 "-e", "kmem:kmalloc",
749 "-e", "kmem:kmalloc_node", 719 "-e", "kmem:kmalloc_node",
750 "-e", "kmem:kfree", 720 "-e", "kmem:kfree",
751 "-e", "kmem:kmem_cache_alloc", 721 "-e", "kmem:kmem_cache_alloc",
752 "-e", "kmem:kmem_cache_alloc_node", 722 "-e", "kmem:kmem_cache_alloc_node",
753 "-e", "kmem:kmem_cache_free", 723 "-e", "kmem:kmem_cache_free",
754}; 724 };
755
756static int __cmd_record(int argc, const char **argv)
757{
758 unsigned int rec_argc, i, j; 725 unsigned int rec_argc, i, j;
759 const char **rec_argv; 726 const char **rec_argv;
760 727
@@ -775,6 +742,25 @@ static int __cmd_record(int argc, const char **argv)
775 742
776int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused) 743int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)
777{ 744{
745 const char * const default_sort_order = "frag,hit,bytes";
746 const char *input_name = NULL;
747 const struct option kmem_options[] = {
748 OPT_STRING('i', "input", &input_name, "file", "input file name"),
749 OPT_CALLBACK_NOOPT(0, "caller", NULL, NULL,
750 "show per-callsite statistics", parse_caller_opt),
751 OPT_CALLBACK_NOOPT(0, "alloc", NULL, NULL,
752 "show per-allocation statistics", parse_alloc_opt),
753 OPT_CALLBACK('s', "sort", NULL, "key[,key2...]",
754 "sort by keys: ptr, call_site, bytes, hit, pingpong, frag",
755 parse_sort_opt),
756 OPT_CALLBACK('l', "line", NULL, "num", "show n lines", parse_line_opt),
757 OPT_BOOLEAN(0, "raw-ip", &raw_ip, "show raw ip instead of symbol"),
758 OPT_END()
759 };
760 const char * const kmem_usage[] = {
761 "perf kmem [<options>] {record|stat}",
762 NULL
763 };
778 argc = parse_options(argc, argv, kmem_options, kmem_usage, 0); 764 argc = parse_options(argc, argv, kmem_options, kmem_usage, 0);
779 765
780 if (!argc) 766 if (!argc)
@@ -793,7 +779,7 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)
793 if (list_empty(&alloc_sort)) 779 if (list_empty(&alloc_sort))
794 setup_sorting(&alloc_sort, default_sort_order); 780 setup_sorting(&alloc_sort, default_sort_order);
795 781
796 return __cmd_kmem(); 782 return __cmd_kmem(input_name);
797 } else 783 } else
798 usage_with_options(kmem_usage, kmem_options); 784 usage_with_options(kmem_usage, kmem_options);
799 785