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 | |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 13 | #include "util/parse-events.h" |
Andi Kleen | dc098b3 | 2013-04-20 11:02:29 -0700 | [diff] [blame] | 14 | #include "util/pmu.h" |
Jin Yao | 0e0ae87 | 2021-09-03 10:52:39 +0800 | [diff] [blame] | 15 | #include "util/pmu-hybrid.h" |
Andi Kleen | f236102 | 2017-01-27 18:03:40 -0800 | [diff] [blame] | 16 | #include "util/debug.h" |
Andi Kleen | 71b0acc | 2017-08-31 12:40:32 -0700 | [diff] [blame] | 17 | #include "util/metricgroup.h" |
Arnaldo Carvalho de Melo | fa0d984 | 2019-08-30 12:52:25 -0300 | [diff] [blame] | 18 | #include <subcmd/pager.h> |
Josh Poimboeuf | 4b6ab94 | 2015-12-15 09:39:39 -0600 | [diff] [blame] | 19 | #include <subcmd/parse-options.h> |
Arnaldo Carvalho de Melo | 8520a98 | 2019-08-29 16:18:59 -0300 | [diff] [blame] | 20 | #include <stdio.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; |
Jin Yao | 0e0ae87 | 2021-09-03 10:52:39 +0800 | [diff] [blame] | 24 | static const char *hybrid_type; |
Andi Kleen | 1c5f01f | 2016-09-15 15:24:45 -0700 | [diff] [blame] | 25 | |
Arnaldo Carvalho de Melo | b0ad8ea | 2017-03-27 11:47:20 -0300 | [diff] [blame] | 26 | int cmd_list(int argc, const char **argv) |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 27 | { |
Jin Yao | 0e0ae87 | 2021-09-03 10:52:39 +0800 | [diff] [blame] | 28 | int i, ret = 0; |
Taesoo Kim | b3505208 | 2014-12-30 22:36:55 -0500 | [diff] [blame] | 29 | bool raw_dump = false; |
Sukadev Bhattiprolu | c8d6828 | 2016-09-15 15:24:48 -0700 | [diff] [blame] | 30 | bool long_desc_flag = false; |
Jin Yao | a7f6c8c | 2019-10-15 10:53:57 +0800 | [diff] [blame] | 31 | bool deprecated = false; |
Jin Yao | 0e0ae87 | 2021-09-03 10:52:39 +0800 | [diff] [blame] | 32 | char *pmu_name = NULL; |
Taesoo Kim | b3505208 | 2014-12-30 22:36:55 -0500 | [diff] [blame] | 33 | struct option list_options[] = { |
| 34 | OPT_BOOLEAN(0, "raw-dump", &raw_dump, "Dump raw events"), |
Andi Kleen | 1c5f01f | 2016-09-15 15:24:45 -0700 | [diff] [blame] | 35 | OPT_BOOLEAN('d', "desc", &desc_flag, |
| 36 | "Print extra event descriptions. --no-desc to not print."), |
Sukadev Bhattiprolu | c8d6828 | 2016-09-15 15:24:48 -0700 | [diff] [blame] | 37 | OPT_BOOLEAN('v', "long-desc", &long_desc_flag, |
| 38 | "Print longer event descriptions."), |
Andi Kleen | bf874fc | 2017-03-20 13:17:11 -0700 | [diff] [blame] | 39 | OPT_BOOLEAN(0, "details", &details_flag, |
| 40 | "Print information on the perf event names and expressions used internally by events."), |
Jin Yao | a7f6c8c | 2019-10-15 10:53:57 +0800 | [diff] [blame] | 41 | OPT_BOOLEAN(0, "deprecated", &deprecated, |
| 42 | "Print deprecated events."), |
Jin Yao | 0e0ae87 | 2021-09-03 10:52:39 +0800 | [diff] [blame] | 43 | OPT_STRING(0, "cputype", &hybrid_type, "hybrid cpu type", |
| 44 | "Print events applying cpu with this type for hybrid platform " |
| 45 | "(e.g. core or atom)"), |
Andi Kleen | f236102 | 2017-01-27 18:03:40 -0800 | [diff] [blame] | 46 | OPT_INCR(0, "debug", &verbose, |
| 47 | "Enable debugging output"), |
David Ahern | 44d742e | 2013-10-30 10:28:29 -0600 | [diff] [blame] | 48 | OPT_END() |
| 49 | }; |
| 50 | const char * const list_usage[] = { |
Ian Rogers | a90a1c5 | 2020-05-21 23:45:46 -0700 | [diff] [blame] | 51 | "perf list [<options>] [hw|sw|cache|tracepoint|pmu|sdt|metric|metricgroup|event_glob]", |
David Ahern | 44d742e | 2013-10-30 10:28:29 -0600 | [diff] [blame] | 52 | NULL |
| 53 | }; |
| 54 | |
Taesoo Kim | b3505208 | 2014-12-30 22:36:55 -0500 | [diff] [blame] | 55 | set_option_flag(list_options, 0, "raw-dump", PARSE_OPT_HIDDEN); |
| 56 | |
David Ahern | 44d742e | 2013-10-30 10:28:29 -0600 | [diff] [blame] | 57 | argc = parse_options(argc, argv, list_options, list_usage, |
| 58 | PARSE_OPT_STOP_AT_NON_OPTION); |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 59 | |
Arnaldo Carvalho de Melo | 8f7a0dc | 2009-08-12 14:44:59 -0300 | [diff] [blame] | 60 | setup_pager(); |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 61 | |
Arnaldo Carvalho de Melo | dfc431c | 2015-09-30 17:13:26 -0300 | [diff] [blame] | 62 | if (!raw_dump && pager_in_use()) |
Yunlong Song | 619a303 | 2015-02-13 21:11:55 +0800 | [diff] [blame] | 63 | printf("\nList of pre-defined events (to be used in -e):\n\n"); |
| 64 | |
Jin Yao | 0e0ae87 | 2021-09-03 10:52:39 +0800 | [diff] [blame] | 65 | if (hybrid_type) { |
| 66 | pmu_name = perf_pmu__hybrid_type_to_pmu(hybrid_type); |
| 67 | if (!pmu_name) |
| 68 | pr_warning("WARNING: hybrid cputype is not supported!\n"); |
| 69 | } |
| 70 | |
David Ahern | 44d742e | 2013-10-30 10:28:29 -0600 | [diff] [blame] | 71 | if (argc == 0) { |
Andi Kleen | bf874fc | 2017-03-20 13:17:11 -0700 | [diff] [blame] | 72 | print_events(NULL, raw_dump, !desc_flag, long_desc_flag, |
Jin Yao | 0e0ae87 | 2021-09-03 10:52:39 +0800 | [diff] [blame] | 73 | details_flag, deprecated, pmu_name); |
| 74 | goto out; |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 75 | } |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 76 | |
David Ahern | 44d742e | 2013-10-30 10:28:29 -0600 | [diff] [blame] | 77 | for (i = 0; i < argc; ++i) { |
Arnaldo Carvalho de Melo | dbc6740 | 2015-10-01 12:12:22 -0300 | [diff] [blame] | 78 | char *sep, *s; |
| 79 | |
Yunlong Song | 1611495 | 2015-02-27 18:21:26 +0800 | [diff] [blame] | 80 | if (strcmp(argv[i], "tracepoint") == 0) |
Yunlong Song | 5ef803e | 2015-02-27 18:21:28 +0800 | [diff] [blame] | 81 | print_tracepoint_events(NULL, NULL, raw_dump); |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 82 | else if (strcmp(argv[i], "hw") == 0 || |
| 83 | strcmp(argv[i], "hardware") == 0) |
Yunlong Song | 705750f | 2015-02-27 18:21:27 +0800 | [diff] [blame] | 84 | print_symbol_events(NULL, PERF_TYPE_HARDWARE, |
Yunlong Song | 5ef803e | 2015-02-27 18:21:28 +0800 | [diff] [blame] | 85 | event_symbols_hw, PERF_COUNT_HW_MAX, raw_dump); |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 86 | else if (strcmp(argv[i], "sw") == 0 || |
Andi Kleen | 5e0861b | 2019-03-26 15:18:23 -0700 | [diff] [blame] | 87 | strcmp(argv[i], "software") == 0) { |
Yunlong Song | 705750f | 2015-02-27 18:21:27 +0800 | [diff] [blame] | 88 | print_symbol_events(NULL, PERF_TYPE_SOFTWARE, |
Yunlong Song | 5ef803e | 2015-02-27 18:21:28 +0800 | [diff] [blame] | 89 | event_symbols_sw, PERF_COUNT_SW_MAX, raw_dump); |
Andi Kleen | 5e0861b | 2019-03-26 15:18:23 -0700 | [diff] [blame] | 90 | print_tool_events(NULL, raw_dump); |
| 91 | } else if (strcmp(argv[i], "cache") == 0 || |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 92 | strcmp(argv[i], "hwcache") == 0) |
Yunlong Song | 5ef803e | 2015-02-27 18:21:28 +0800 | [diff] [blame] | 93 | print_hwcache_events(NULL, raw_dump); |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 94 | else if (strcmp(argv[i], "pmu") == 0) |
Sukadev Bhattiprolu | c8d6828 | 2016-09-15 15:24:48 -0700 | [diff] [blame] | 95 | print_pmu_events(NULL, raw_dump, !desc_flag, |
Jin Yao | a7f6c8c | 2019-10-15 10:53:57 +0800 | [diff] [blame] | 96 | long_desc_flag, details_flag, |
Jin Yao | 0e0ae87 | 2021-09-03 10:52:39 +0800 | [diff] [blame] | 97 | deprecated, pmu_name); |
Masami Hiramatsu | 40218da | 2016-06-24 18:06:46 +0900 | [diff] [blame] | 98 | else if (strcmp(argv[i], "sdt") == 0) |
| 99 | print_sdt_events(NULL, NULL, raw_dump); |
Kim Phillips | 8788d36 | 2019-09-19 15:43:05 -0500 | [diff] [blame] | 100 | else if (strcmp(argv[i], "metric") == 0 || strcmp(argv[i], "metrics") == 0) |
Jin Yao | 0e0ae87 | 2021-09-03 10:52:39 +0800 | [diff] [blame] | 101 | metricgroup__print(true, false, NULL, raw_dump, details_flag, pmu_name); |
Kim Phillips | 8788d36 | 2019-09-19 15:43:05 -0500 | [diff] [blame] | 102 | else if (strcmp(argv[i], "metricgroup") == 0 || strcmp(argv[i], "metricgroups") == 0) |
Jin Yao | 0e0ae87 | 2021-09-03 10:52:39 +0800 | [diff] [blame] | 103 | metricgroup__print(false, true, NULL, raw_dump, details_flag, pmu_name); |
Arnaldo Carvalho de Melo | dbc6740 | 2015-10-01 12:12:22 -0300 | [diff] [blame] | 104 | else if ((sep = strchr(argv[i], ':')) != NULL) { |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 105 | int sep_idx; |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 106 | |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 107 | sep_idx = sep - argv[i]; |
| 108 | s = strdup(argv[i]); |
Jin Yao | 0e0ae87 | 2021-09-03 10:52:39 +0800 | [diff] [blame] | 109 | if (s == NULL) { |
| 110 | ret = -1; |
| 111 | goto out; |
| 112 | } |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 113 | |
| 114 | s[sep_idx] = '\0'; |
Yunlong Song | 5ef803e | 2015-02-27 18:21:28 +0800 | [diff] [blame] | 115 | print_tracepoint_events(s, s + sep_idx + 1, raw_dump); |
Masami Hiramatsu | 40218da | 2016-06-24 18:06:46 +0900 | [diff] [blame] | 116 | print_sdt_events(s, s + sep_idx + 1, raw_dump); |
Jin Yao | 0e0ae87 | 2021-09-03 10:52:39 +0800 | [diff] [blame] | 117 | metricgroup__print(true, true, s, raw_dump, details_flag, pmu_name); |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 118 | free(s); |
Arnaldo Carvalho de Melo | dbc6740 | 2015-10-01 12:12:22 -0300 | [diff] [blame] | 119 | } else { |
| 120 | if (asprintf(&s, "*%s*", argv[i]) < 0) { |
| 121 | printf("Critical: Not enough memory! Trying to continue...\n"); |
| 122 | continue; |
| 123 | } |
| 124 | print_symbol_events(s, PERF_TYPE_HARDWARE, |
| 125 | event_symbols_hw, PERF_COUNT_HW_MAX, raw_dump); |
| 126 | print_symbol_events(s, PERF_TYPE_SOFTWARE, |
| 127 | event_symbols_sw, PERF_COUNT_SW_MAX, raw_dump); |
Andi Kleen | 5e0861b | 2019-03-26 15:18:23 -0700 | [diff] [blame] | 128 | print_tool_events(s, raw_dump); |
Arnaldo Carvalho de Melo | dbc6740 | 2015-10-01 12:12:22 -0300 | [diff] [blame] | 129 | print_hwcache_events(s, raw_dump); |
Sukadev Bhattiprolu | c8d6828 | 2016-09-15 15:24:48 -0700 | [diff] [blame] | 130 | print_pmu_events(s, raw_dump, !desc_flag, |
Andi Kleen | bf874fc | 2017-03-20 13:17:11 -0700 | [diff] [blame] | 131 | long_desc_flag, |
Jin Yao | a7f6c8c | 2019-10-15 10:53:57 +0800 | [diff] [blame] | 132 | details_flag, |
Jin Yao | 0e0ae87 | 2021-09-03 10:52:39 +0800 | [diff] [blame] | 133 | deprecated, |
| 134 | pmu_name); |
Arnaldo Carvalho de Melo | dbc6740 | 2015-10-01 12:12:22 -0300 | [diff] [blame] | 135 | print_tracepoint_events(NULL, s, raw_dump); |
Masami Hiramatsu | 40218da | 2016-06-24 18:06:46 +0900 | [diff] [blame] | 136 | print_sdt_events(NULL, s, raw_dump); |
Jin Yao | 0e0ae87 | 2021-09-03 10:52:39 +0800 | [diff] [blame] | 137 | metricgroup__print(true, true, s, raw_dump, details_flag, pmu_name); |
Arnaldo Carvalho de Melo | dbc6740 | 2015-10-01 12:12:22 -0300 | [diff] [blame] | 138 | free(s); |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 139 | } |
| 140 | } |
Jin Yao | 0e0ae87 | 2021-09-03 10:52:39 +0800 | [diff] [blame] | 141 | |
| 142 | out: |
| 143 | free(pmu_name); |
| 144 | return ret; |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 145 | } |