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