diff options
author | Ingo Molnar <mingo@elte.hu> | 2009-05-26 03:17:18 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-05-26 07:05:27 -0400 |
commit | 53cb8bc2a3d976efd1a800c3de4640a7220afbb3 (patch) | |
tree | fdffc1cb0f09d663d1ed40617294fbc3b271459e /Documentation/perf_counter/builtin-report.c | |
parent | f3e08c5341c528284460530b546608f27232f737 (diff) |
perf record: Convert to Git option parsing
Remove getopt usage and use Git's much more advanced and more compact
command option library.
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: John Kacur <jkacur@redhat.com>
LKML-Reference: <new-submission>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'Documentation/perf_counter/builtin-report.c')
-rw-r--r-- | Documentation/perf_counter/builtin-report.c | 126 |
1 files changed, 38 insertions, 88 deletions
diff --git a/Documentation/perf_counter/builtin-report.c b/Documentation/perf_counter/builtin-report.c index 21386a8c6f62..9e59d6071ef3 100644 --- a/Documentation/perf_counter/builtin-report.c +++ b/Documentation/perf_counter/builtin-report.c | |||
@@ -1,52 +1,29 @@ | |||
1 | #define _GNU_SOURCE | 1 | #include "util/util.h" |
2 | #include <sys/types.h> | 2 | |
3 | #include <sys/stat.h> | 3 | #include <libelf.h> |
4 | #include <sys/time.h> | ||
5 | #include <unistd.h> | ||
6 | #include <stdint.h> | ||
7 | #include <stdbool.h> | ||
8 | #include <stdlib.h> | ||
9 | #include <string.h> | ||
10 | #include <limits.h> | ||
11 | #include <gelf.h> | 4 | #include <gelf.h> |
12 | #include <elf.h> | 5 | #include <elf.h> |
13 | #include <libelf.h> | 6 | |
14 | #include <fcntl.h> | ||
15 | #include <stdio.h> | ||
16 | #include <errno.h> | ||
17 | #include <ctype.h> | ||
18 | #include <time.h> | ||
19 | #include <getopt.h> | ||
20 | #include <assert.h> | ||
21 | #include <search.h> | ||
22 | |||
23 | #include <sys/ioctl.h> | ||
24 | #include <sys/poll.h> | ||
25 | #include <sys/prctl.h> | ||
26 | #include <sys/wait.h> | ||
27 | #include <sys/mman.h> | ||
28 | #include <sys/types.h> | ||
29 | #include <sys/stat.h> | ||
30 | |||
31 | #include <linux/unistd.h> | ||
32 | #include <linux/types.h> | ||
33 | |||
34 | #include "../../include/linux/perf_counter.h" | ||
35 | #include "util/list.h" | 7 | #include "util/list.h" |
36 | #include "util/rbtree.h" | 8 | #include "util/rbtree.h" |
37 | 9 | ||
10 | #include "perf.h" | ||
11 | |||
12 | #include "util/parse-options.h" | ||
13 | #include "util/parse-events.h" | ||
14 | |||
38 | #define SHOW_KERNEL 1 | 15 | #define SHOW_KERNEL 1 |
39 | #define SHOW_USER 2 | 16 | #define SHOW_USER 2 |
40 | #define SHOW_HV 4 | 17 | #define SHOW_HV 4 |
41 | 18 | ||
42 | static char const *input_name = "output.perf"; | 19 | static char const *input_name = "output.perf"; |
43 | static int input; | 20 | static int input; |
44 | static int show_mask = SHOW_KERNEL | SHOW_USER | SHOW_HV; | 21 | static int show_mask = SHOW_KERNEL | SHOW_USER | SHOW_HV; |
45 | 22 | ||
46 | static unsigned long page_size; | 23 | static unsigned long page_size; |
47 | static unsigned long mmap_window = 32; | 24 | static unsigned long mmap_window = 32; |
48 | 25 | ||
49 | static const char *perf_event_names[] = { | 26 | const char *perf_event_names[] = { |
50 | [PERF_EVENT_MMAP] = " PERF_EVENT_MMAP", | 27 | [PERF_EVENT_MMAP] = " PERF_EVENT_MMAP", |
51 | [PERF_EVENT_MUNMAP] = " PERF_EVENT_MUNMAP", | 28 | [PERF_EVENT_MUNMAP] = " PERF_EVENT_MUNMAP", |
52 | [PERF_EVENT_COMM] = " PERF_EVENT_COMM", | 29 | [PERF_EVENT_COMM] = " PERF_EVENT_COMM", |
@@ -86,7 +63,7 @@ struct section { | |||
86 | char name[0]; | 63 | char name[0]; |
87 | }; | 64 | }; |
88 | 65 | ||
89 | static struct section *section__new(uint64_t start, uint64_t size, | 66 | struct section *section__new(uint64_t start, uint64_t size, |
90 | uint64_t offset, char *name) | 67 | uint64_t offset, char *name) |
91 | { | 68 | { |
92 | struct section *self = malloc(sizeof(*self) + strlen(name) + 1); | 69 | struct section *self = malloc(sizeof(*self) + strlen(name) + 1); |
@@ -241,7 +218,7 @@ static inline uint8_t elf_sym__type(const GElf_Sym *sym) | |||
241 | return GELF_ST_TYPE(sym->st_info); | 218 | return GELF_ST_TYPE(sym->st_info); |
242 | } | 219 | } |
243 | 220 | ||
244 | static inline bool elf_sym__is_function(const GElf_Sym *sym) | 221 | static inline int elf_sym__is_function(const GElf_Sym *sym) |
245 | { | 222 | { |
246 | return elf_sym__type(sym) == STT_FUNC && | 223 | return elf_sym__type(sym) == STT_FUNC && |
247 | sym->st_name != 0 && | 224 | sym->st_name != 0 && |
@@ -393,7 +370,7 @@ out_delete_dso: | |||
393 | return NULL; | 370 | return NULL; |
394 | } | 371 | } |
395 | 372 | ||
396 | static void dsos__fprintf(FILE *fp) | 373 | void dsos__fprintf(FILE *fp) |
397 | { | 374 | { |
398 | struct dso *pos; | 375 | struct dso *pos; |
399 | 376 | ||
@@ -503,7 +480,7 @@ static struct symhist *symhist__new(struct symbol *sym, uint64_t ip, | |||
503 | return self; | 480 | return self; |
504 | } | 481 | } |
505 | 482 | ||
506 | static void symhist__delete(struct symhist *self) | 483 | void symhist__delete(struct symhist *self) |
507 | { | 484 | { |
508 | free(self); | 485 | free(self); |
509 | } | 486 | } |
@@ -587,7 +564,7 @@ static int thread__set_comm(struct thread *self, const char *comm) | |||
587 | return self->comm ? 0 : -ENOMEM; | 564 | return self->comm ? 0 : -ENOMEM; |
588 | } | 565 | } |
589 | 566 | ||
590 | static size_t thread__maps_fprintf(struct thread *self, FILE *fp) | 567 | size_t thread__maps_fprintf(struct thread *self, FILE *fp) |
591 | { | 568 | { |
592 | struct map *pos; | 569 | struct map *pos; |
593 | size_t ret = 0; | 570 | size_t ret = 0; |
@@ -668,49 +645,7 @@ static void threads__fprintf(FILE *fp) | |||
668 | } | 645 | } |
669 | } | 646 | } |
670 | 647 | ||
671 | static void display_help(void) | 648 | static int __cmd_report(void) |
672 | { | ||
673 | printf( | ||
674 | "Usage: perf-report [<options>]\n" | ||
675 | " -i file --input=<file> # input file\n" | ||
676 | ); | ||
677 | |||
678 | exit(0); | ||
679 | } | ||
680 | |||
681 | static void process_options(int argc, char *argv[]) | ||
682 | { | ||
683 | int error = 0; | ||
684 | |||
685 | for (;;) { | ||
686 | int option_index = 0; | ||
687 | /** Options for getopt */ | ||
688 | static struct option long_options[] = { | ||
689 | {"input", required_argument, NULL, 'i'}, | ||
690 | {"no-user", no_argument, NULL, 'u'}, | ||
691 | {"no-kernel", no_argument, NULL, 'k'}, | ||
692 | {"no-hv", no_argument, NULL, 'h'}, | ||
693 | {NULL, 0, NULL, 0 } | ||
694 | }; | ||
695 | int c = getopt_long(argc, argv, "+:i:kuh", | ||
696 | long_options, &option_index); | ||
697 | if (c == -1) | ||
698 | break; | ||
699 | |||
700 | switch (c) { | ||
701 | case 'i': input_name = strdup(optarg); break; | ||
702 | case 'k': show_mask &= ~SHOW_KERNEL; break; | ||
703 | case 'u': show_mask &= ~SHOW_USER; break; | ||
704 | case 'h': show_mask &= ~SHOW_HV; break; | ||
705 | default: error = 1; break; | ||
706 | } | ||
707 | } | ||
708 | |||
709 | if (error) | ||
710 | display_help(); | ||
711 | } | ||
712 | |||
713 | int cmd_report(int argc, char **argv) | ||
714 | { | 649 | { |
715 | unsigned long offset = 0; | 650 | unsigned long offset = 0; |
716 | unsigned long head = 0; | 651 | unsigned long head = 0; |
@@ -720,12 +655,6 @@ int cmd_report(int argc, char **argv) | |||
720 | int ret, rc = EXIT_FAILURE; | 655 | int ret, rc = EXIT_FAILURE; |
721 | unsigned long total = 0; | 656 | unsigned long total = 0; |
722 | 657 | ||
723 | elf_version(EV_CURRENT); | ||
724 | |||
725 | page_size = getpagesize(); | ||
726 | |||
727 | process_options(argc, argv); | ||
728 | |||
729 | input = open(input_name, O_RDONLY); | 658 | input = open(input_name, O_RDONLY); |
730 | if (input < 0) { | 659 | if (input < 0) { |
731 | perror("failed to open file"); | 660 | perror("failed to open file"); |
@@ -867,3 +796,24 @@ done: | |||
867 | return rc; | 796 | return rc; |
868 | } | 797 | } |
869 | 798 | ||
799 | static const char * const report_usage[] = { | ||
800 | "perf report [<options>] <command>", | ||
801 | NULL | ||
802 | }; | ||
803 | |||
804 | static const struct option options[] = { | ||
805 | OPT_STRING('i', "input", &input_name, "file", | ||
806 | "input file name"), | ||
807 | OPT_END() | ||
808 | }; | ||
809 | |||
810 | int cmd_report(int argc, const char **argv, const char *prefix) | ||
811 | { | ||
812 | elf_version(EV_CURRENT); | ||
813 | |||
814 | page_size = getpagesize(); | ||
815 | |||
816 | parse_options(argc, argv, options, report_usage, 0); | ||
817 | |||
818 | return __cmd_report(); | ||
819 | } | ||