Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 1 | /* |
| 2 | * builtin-list.c |
| 3 | * |
| 4 | * Builtin list command: list all event types |
| 5 | * |
| 6 | * Copyright (C) 2009, Thomas Gleixner <tglx@linutronix.de> |
| 7 | * Copyright (C) 2008-2009, Red Hat Inc, Ingo Molnar <mingo@redhat.com> |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 8 | * Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com> |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 9 | */ |
| 10 | #include "builtin.h" |
| 11 | |
| 12 | #include "perf.h" |
| 13 | |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 14 | #include "util/parse-events.h" |
Arnaldo Carvalho de Melo | 8f7a0dc | 2009-08-12 14:44:59 -0300 | [diff] [blame] | 15 | #include "util/cache.h" |
Andi Kleen | dc098b3 | 2013-04-20 11:02:29 -0700 | [diff] [blame] | 16 | #include "util/pmu.h" |
Josh Poimboeuf | 4b6ab94 | 2015-12-15 09:39:39 -0600 | [diff] [blame] | 17 | #include <subcmd/parse-options.h> |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 18 | |
Andi Kleen | 1c5f01f | 2016-09-15 15:24:45 -0700 | [diff] [blame] | 19 | static bool desc_flag = true; |
| 20 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 21 | int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused) |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 22 | { |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 23 | int i; |
Taesoo Kim | b350520 | 2014-12-30 22:36:55 -0500 | [diff] [blame] | 24 | bool raw_dump = false; |
Sukadev Bhattiprolu | c8d6828 | 2016-09-15 15:24:48 -0700 | [diff] [blame] | 25 | bool long_desc_flag = false; |
Taesoo Kim | b350520 | 2014-12-30 22:36:55 -0500 | [diff] [blame] | 26 | struct option list_options[] = { |
| 27 | OPT_BOOLEAN(0, "raw-dump", &raw_dump, "Dump raw events"), |
Andi Kleen | 1c5f01f | 2016-09-15 15:24:45 -0700 | [diff] [blame] | 28 | OPT_BOOLEAN('d', "desc", &desc_flag, |
| 29 | "Print extra event descriptions. --no-desc to not print."), |
Sukadev Bhattiprolu | c8d6828 | 2016-09-15 15:24:48 -0700 | [diff] [blame] | 30 | OPT_BOOLEAN('v', "long-desc", &long_desc_flag, |
| 31 | "Print longer event descriptions."), |
David Ahern | 44d742e | 2013-10-30 10:28:29 -0600 | [diff] [blame] | 32 | OPT_END() |
| 33 | }; |
| 34 | const char * const list_usage[] = { |
Sukadev Bhattiprolu | c8d6828 | 2016-09-15 15:24:48 -0700 | [diff] [blame] | 35 | "perf list [<options>] [hw|sw|cache|tracepoint|pmu|sdt|event_glob]", |
David Ahern | 44d742e | 2013-10-30 10:28:29 -0600 | [diff] [blame] | 36 | NULL |
| 37 | }; |
| 38 | |
Taesoo Kim | b350520 | 2014-12-30 22:36:55 -0500 | [diff] [blame] | 39 | set_option_flag(list_options, 0, "raw-dump", PARSE_OPT_HIDDEN); |
| 40 | |
David Ahern | 44d742e | 2013-10-30 10:28:29 -0600 | [diff] [blame] | 41 | argc = parse_options(argc, argv, list_options, list_usage, |
| 42 | PARSE_OPT_STOP_AT_NON_OPTION); |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 43 | |
Arnaldo Carvalho de Melo | 8f7a0dc | 2009-08-12 14:44:59 -0300 | [diff] [blame] | 44 | setup_pager(); |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 45 | |
Arnaldo Carvalho de Melo | dfc431c | 2015-09-30 17:13:26 -0300 | [diff] [blame] | 46 | if (!raw_dump && pager_in_use()) |
Yunlong Song | 619a303 | 2015-02-13 21:11:55 +0800 | [diff] [blame] | 47 | printf("\nList of pre-defined events (to be used in -e):\n\n"); |
| 48 | |
David Ahern | 44d742e | 2013-10-30 10:28:29 -0600 | [diff] [blame] | 49 | if (argc == 0) { |
Sukadev Bhattiprolu | c8d6828 | 2016-09-15 15:24:48 -0700 | [diff] [blame] | 50 | print_events(NULL, raw_dump, !desc_flag, long_desc_flag); |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 51 | return 0; |
| 52 | } |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 53 | |
David Ahern | 44d742e | 2013-10-30 10:28:29 -0600 | [diff] [blame] | 54 | for (i = 0; i < argc; ++i) { |
Arnaldo Carvalho de Melo | dbc6740 | 2015-10-01 12:12:22 -0300 | [diff] [blame] | 55 | char *sep, *s; |
| 56 | |
Yunlong Song | 1611495 | 2015-02-27 18:21:26 +0800 | [diff] [blame] | 57 | if (strcmp(argv[i], "tracepoint") == 0) |
Yunlong Song | 5ef803e | 2015-02-27 18:21:28 +0800 | [diff] [blame] | 58 | print_tracepoint_events(NULL, NULL, raw_dump); |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 59 | else if (strcmp(argv[i], "hw") == 0 || |
| 60 | strcmp(argv[i], "hardware") == 0) |
Yunlong Song | 705750f | 2015-02-27 18:21:27 +0800 | [diff] [blame] | 61 | print_symbol_events(NULL, PERF_TYPE_HARDWARE, |
Yunlong Song | 5ef803e | 2015-02-27 18:21:28 +0800 | [diff] [blame] | 62 | event_symbols_hw, PERF_COUNT_HW_MAX, raw_dump); |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 63 | else if (strcmp(argv[i], "sw") == 0 || |
| 64 | strcmp(argv[i], "software") == 0) |
Yunlong Song | 705750f | 2015-02-27 18:21:27 +0800 | [diff] [blame] | 65 | print_symbol_events(NULL, PERF_TYPE_SOFTWARE, |
Yunlong Song | 5ef803e | 2015-02-27 18:21:28 +0800 | [diff] [blame] | 66 | event_symbols_sw, PERF_COUNT_SW_MAX, raw_dump); |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 67 | else if (strcmp(argv[i], "cache") == 0 || |
| 68 | strcmp(argv[i], "hwcache") == 0) |
Yunlong Song | 5ef803e | 2015-02-27 18:21:28 +0800 | [diff] [blame] | 69 | print_hwcache_events(NULL, raw_dump); |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 70 | else if (strcmp(argv[i], "pmu") == 0) |
Sukadev Bhattiprolu | c8d6828 | 2016-09-15 15:24:48 -0700 | [diff] [blame] | 71 | print_pmu_events(NULL, raw_dump, !desc_flag, |
| 72 | long_desc_flag); |
Masami Hiramatsu | 40218da | 2016-06-24 18:06:46 +0900 | [diff] [blame] | 73 | else if (strcmp(argv[i], "sdt") == 0) |
| 74 | print_sdt_events(NULL, NULL, raw_dump); |
Arnaldo Carvalho de Melo | dbc6740 | 2015-10-01 12:12:22 -0300 | [diff] [blame] | 75 | else if ((sep = strchr(argv[i], ':')) != NULL) { |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 76 | int sep_idx; |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 77 | |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 78 | if (sep == NULL) { |
Sukadev Bhattiprolu | c8d6828 | 2016-09-15 15:24:48 -0700 | [diff] [blame] | 79 | print_events(argv[i], raw_dump, !desc_flag, |
| 80 | long_desc_flag); |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 81 | continue; |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 82 | } |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 83 | sep_idx = sep - argv[i]; |
| 84 | s = strdup(argv[i]); |
| 85 | if (s == NULL) |
| 86 | return -1; |
| 87 | |
| 88 | s[sep_idx] = '\0'; |
Yunlong Song | 5ef803e | 2015-02-27 18:21:28 +0800 | [diff] [blame] | 89 | print_tracepoint_events(s, s + sep_idx + 1, raw_dump); |
Masami Hiramatsu | 40218da | 2016-06-24 18:06:46 +0900 | [diff] [blame] | 90 | print_sdt_events(s, s + sep_idx + 1, raw_dump); |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 91 | free(s); |
Arnaldo Carvalho de Melo | dbc6740 | 2015-10-01 12:12:22 -0300 | [diff] [blame] | 92 | } else { |
| 93 | if (asprintf(&s, "*%s*", argv[i]) < 0) { |
| 94 | printf("Critical: Not enough memory! Trying to continue...\n"); |
| 95 | continue; |
| 96 | } |
| 97 | print_symbol_events(s, PERF_TYPE_HARDWARE, |
| 98 | event_symbols_hw, PERF_COUNT_HW_MAX, raw_dump); |
| 99 | print_symbol_events(s, PERF_TYPE_SOFTWARE, |
| 100 | event_symbols_sw, PERF_COUNT_SW_MAX, raw_dump); |
| 101 | print_hwcache_events(s, raw_dump); |
Sukadev Bhattiprolu | c8d6828 | 2016-09-15 15:24:48 -0700 | [diff] [blame] | 102 | print_pmu_events(s, raw_dump, !desc_flag, |
| 103 | long_desc_flag); |
Arnaldo Carvalho de Melo | dbc6740 | 2015-10-01 12:12:22 -0300 | [diff] [blame] | 104 | print_tracepoint_events(NULL, s, raw_dump); |
Masami Hiramatsu | 40218da | 2016-06-24 18:06:46 +0900 | [diff] [blame] | 105 | print_sdt_events(NULL, s, raw_dump); |
Arnaldo Carvalho de Melo | dbc6740 | 2015-10-01 12:12:22 -0300 | [diff] [blame] | 106 | free(s); |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 107 | } |
| 108 | } |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 109 | return 0; |
| 110 | } |