aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLi Zefan <lizf@cn.fujitsu.com>2009-12-10 02:21:57 -0500
committerIngo Molnar <mingo@elte.hu>2009-12-10 02:30:27 -0500
commit90b86a9f7dc22e7ff8e8c79ed553860454ff8dd9 (patch)
tree3cb7015aa85ed6410eb9947f9bfd607f74f36f95
parent1bbfa6f25673019dc0acc9308b667c96f6cda8bf (diff)
perf kmem: Show usage if no option is specified
As Ingo suggested, make "perf kmem" show help information. "perf kmem stat [--caller] [--alloc] .." will show memory statistics. Signed-off-by: Li Zefan <lizf@cn.fujitsu.com> Acked-by: Pekka Enberg <penberg@cs.helsinki.fi> LKML-Reference: <4B20A195.8030106@cn.fujitsu.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r--tools/perf/Documentation/perf-kmem.txt13
-rw-r--r--tools/perf/builtin-kmem.c52
2 files changed, 37 insertions, 28 deletions
diff --git a/tools/perf/Documentation/perf-kmem.txt b/tools/perf/Documentation/perf-kmem.txt
index 44b0ce35c28a..eac4d852e7cd 100644
--- a/tools/perf/Documentation/perf-kmem.txt
+++ b/tools/perf/Documentation/perf-kmem.txt
@@ -8,16 +8,16 @@ perf-kmem - Tool to trace/measure kernel memory(slab) properties
8SYNOPSIS 8SYNOPSIS
9-------- 9--------
10[verse] 10[verse]
11'perf kmem' {record} [<options>] 11'perf kmem' {record|stat} [<options>]
12 12
13DESCRIPTION 13DESCRIPTION
14----------- 14-----------
15There's two variants of perf kmem: 15There are two variants of perf kmem:
16 16
17 'perf kmem record <command>' to record the kmem events 17 'perf kmem record <command>' to record the kmem events
18 of an arbitrary workload. 18 of an arbitrary workload.
19 19
20 'perf kmem' to report kernel memory statistics. 20 'perf kmem stat' to report kernel memory statistics.
21 21
22OPTIONS 22OPTIONS
23------- 23-------
@@ -25,8 +25,11 @@ OPTIONS
25--input=<file>:: 25--input=<file>::
26 Select the input file (default: perf.data) 26 Select the input file (default: perf.data)
27 27
28--stat=<caller|alloc>:: 28--caller::
29 Select per callsite or per allocation statistics 29 Show per-callsite statistics
30
31--alloc::
32 Show per-allocation statistics
30 33
31-s <key[,key2...]>:: 34-s <key[,key2...]>::
32--sort=<key[,key2...]>:: 35--sort=<key[,key2...]>::
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 7551a5f834b8..1b04787ed90a 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -526,7 +526,7 @@ static int __cmd_kmem(void)
526} 526}
527 527
528static const char * const kmem_usage[] = { 528static const char * const kmem_usage[] = {
529 "perf kmem [<options>] {record}", 529 "perf kmem [<options>] {record|stat}",
530 NULL 530 NULL
531}; 531};
532 532
@@ -686,18 +686,17 @@ static int parse_sort_opt(const struct option *opt __used,
686 return 0; 686 return 0;
687} 687}
688 688
689static int parse_stat_opt(const struct option *opt __used, 689static int parse_caller_opt(const struct option *opt __used,
690 const char *arg, int unset __used) 690 const char *arg, int unset __used)
691{ 691{
692 if (!arg) 692 caller_flag = (alloc_flag + 1);
693 return -1; 693 return 0;
694}
694 695
695 if (strcmp(arg, "alloc") == 0) 696static int parse_alloc_opt(const struct option *opt __used,
696 alloc_flag = (caller_flag + 1); 697 const char *arg, int unset __used)
697 else if (strcmp(arg, "caller") == 0) 698{
698 caller_flag = (alloc_flag + 1); 699 alloc_flag = (caller_flag + 1);
699 else
700 return -1;
701 return 0; 700 return 0;
702} 701}
703 702
@@ -722,14 +721,17 @@ static int parse_line_opt(const struct option *opt __used,
722static const struct option kmem_options[] = { 721static const struct option kmem_options[] = {
723 OPT_STRING('i', "input", &input_name, "file", 722 OPT_STRING('i', "input", &input_name, "file",
724 "input file name"), 723 "input file name"),
725 OPT_CALLBACK(0, "stat", NULL, "<alloc>|<caller>", 724 OPT_CALLBACK_NOOPT(0, "caller", NULL, NULL,
726 "stat selector, Pass 'alloc' or 'caller'.", 725 "show per-callsite statistics",
727 parse_stat_opt), 726 parse_caller_opt),
727 OPT_CALLBACK_NOOPT(0, "alloc", NULL, NULL,
728 "show per-allocation statistics",
729 parse_alloc_opt),
728 OPT_CALLBACK('s', "sort", NULL, "key[,key2...]", 730 OPT_CALLBACK('s', "sort", NULL, "key[,key2...]",
729 "sort by keys: ptr, call_site, bytes, hit, pingpong, frag", 731 "sort by keys: ptr, call_site, bytes, hit, pingpong, frag",
730 parse_sort_opt), 732 parse_sort_opt),
731 OPT_CALLBACK('l', "line", NULL, "num", 733 OPT_CALLBACK('l', "line", NULL, "num",
732 "show n lins", 734 "show n lines",
733 parse_line_opt), 735 parse_line_opt),
734 OPT_BOOLEAN(0, "raw-ip", &raw_ip, "show raw ip instead of symbol"), 736 OPT_BOOLEAN(0, "raw-ip", &raw_ip, "show raw ip instead of symbol"),
735 OPT_END() 737 OPT_END()
@@ -773,18 +775,22 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __used)
773 775
774 argc = parse_options(argc, argv, kmem_options, kmem_usage, 0); 776 argc = parse_options(argc, argv, kmem_options, kmem_usage, 0);
775 777
776 if (argc && !strncmp(argv[0], "rec", 3)) 778 if (!argc)
777 return __cmd_record(argc, argv);
778 else if (argc)
779 usage_with_options(kmem_usage, kmem_options); 779 usage_with_options(kmem_usage, kmem_options);
780 780
781 if (list_empty(&caller_sort)) 781 if (!strncmp(argv[0], "rec", 3)) {
782 setup_sorting(&caller_sort, default_sort_order); 782 return __cmd_record(argc, argv);
783 if (list_empty(&alloc_sort)) 783 } else if (!strcmp(argv[0], "stat")) {
784 setup_sorting(&alloc_sort, default_sort_order); 784 setup_cpunode_map();
785
786 if (list_empty(&caller_sort))
787 setup_sorting(&caller_sort, default_sort_order);
788 if (list_empty(&alloc_sort))
789 setup_sorting(&alloc_sort, default_sort_order);
785 790
786 setup_cpunode_map(); 791 return __cmd_kmem();
792 }
787 793
788 return __cmd_kmem(); 794 return 0;
789} 795}
790 796