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