blob: 468958154ed900da80a64eb5aba7d043316ff8ae [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Thomas Gleixner86847b62009-06-06 12:24:17 +02002/*
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 Melo668b8782011-02-17 15:38:58 -02009 * Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
Thomas Gleixner86847b62009-06-06 12:24:17 +020010 */
11#include "builtin.h"
12
Thomas Gleixner86847b62009-06-06 12:24:17 +020013#include "util/parse-events.h"
Andi Kleendc098b32013-04-20 11:02:29 -070014#include "util/pmu.h"
Jin Yao0e0ae872021-09-03 10:52:39 +080015#include "util/pmu-hybrid.h"
Andi Kleenf2361022017-01-27 18:03:40 -080016#include "util/debug.h"
Andi Kleen71b0acc2017-08-31 12:40:32 -070017#include "util/metricgroup.h"
Arnaldo Carvalho de Melofa0d9842019-08-30 12:52:25 -030018#include <subcmd/pager.h>
Josh Poimboeuf4b6ab942015-12-15 09:39:39 -060019#include <subcmd/parse-options.h>
Arnaldo Carvalho de Melo8520a982019-08-29 16:18:59 -030020#include <stdio.h>
Thomas Gleixner86847b62009-06-06 12:24:17 +020021
Andi Kleen1c5f01f2016-09-15 15:24:45 -070022static bool desc_flag = true;
Andi Kleenbf874fc2017-03-20 13:17:11 -070023static bool details_flag;
Jin Yao0e0ae872021-09-03 10:52:39 +080024static const char *hybrid_type;
Andi Kleen1c5f01f2016-09-15 15:24:45 -070025
Arnaldo Carvalho de Melob0ad8ea2017-03-27 11:47:20 -030026int cmd_list(int argc, const char **argv)
Thomas Gleixner86847b62009-06-06 12:24:17 +020027{
Jin Yao0e0ae872021-09-03 10:52:39 +080028 int i, ret = 0;
Taesoo Kimb35052082014-12-30 22:36:55 -050029 bool raw_dump = false;
Sukadev Bhattiproluc8d68282016-09-15 15:24:48 -070030 bool long_desc_flag = false;
Jin Yaoa7f6c8c2019-10-15 10:53:57 +080031 bool deprecated = false;
Jin Yao0e0ae872021-09-03 10:52:39 +080032 char *pmu_name = NULL;
Taesoo Kimb35052082014-12-30 22:36:55 -050033 struct option list_options[] = {
34 OPT_BOOLEAN(0, "raw-dump", &raw_dump, "Dump raw events"),
Andi Kleen1c5f01f2016-09-15 15:24:45 -070035 OPT_BOOLEAN('d', "desc", &desc_flag,
36 "Print extra event descriptions. --no-desc to not print."),
Sukadev Bhattiproluc8d68282016-09-15 15:24:48 -070037 OPT_BOOLEAN('v', "long-desc", &long_desc_flag,
38 "Print longer event descriptions."),
Andi Kleenbf874fc2017-03-20 13:17:11 -070039 OPT_BOOLEAN(0, "details", &details_flag,
40 "Print information on the perf event names and expressions used internally by events."),
Jin Yaoa7f6c8c2019-10-15 10:53:57 +080041 OPT_BOOLEAN(0, "deprecated", &deprecated,
42 "Print deprecated events."),
Jin Yao0e0ae872021-09-03 10:52:39 +080043 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 Kleenf2361022017-01-27 18:03:40 -080046 OPT_INCR(0, "debug", &verbose,
47 "Enable debugging output"),
David Ahern44d742e2013-10-30 10:28:29 -060048 OPT_END()
49 };
50 const char * const list_usage[] = {
Ian Rogersa90a1c52020-05-21 23:45:46 -070051 "perf list [<options>] [hw|sw|cache|tracepoint|pmu|sdt|metric|metricgroup|event_glob]",
David Ahern44d742e2013-10-30 10:28:29 -060052 NULL
53 };
54
Taesoo Kimb35052082014-12-30 22:36:55 -050055 set_option_flag(list_options, 0, "raw-dump", PARSE_OPT_HIDDEN);
56
David Ahern44d742e2013-10-30 10:28:29 -060057 argc = parse_options(argc, argv, list_options, list_usage,
58 PARSE_OPT_STOP_AT_NON_OPTION);
David Ahern8e00ddc2013-10-30 10:15:06 -060059
Arnaldo Carvalho de Melo8f7a0dc2009-08-12 14:44:59 -030060 setup_pager();
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -020061
Arnaldo Carvalho de Melodfc431c2015-09-30 17:13:26 -030062 if (!raw_dump && pager_in_use())
Yunlong Song619a3032015-02-13 21:11:55 +080063 printf("\nList of pre-defined events (to be used in -e):\n\n");
64
Jin Yao0e0ae872021-09-03 10:52:39 +080065 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 Ahern44d742e2013-10-30 10:28:29 -060071 if (argc == 0) {
Andi Kleenbf874fc2017-03-20 13:17:11 -070072 print_events(NULL, raw_dump, !desc_flag, long_desc_flag,
Jin Yao0e0ae872021-09-03 10:52:39 +080073 details_flag, deprecated, pmu_name);
74 goto out;
David Ahern8e00ddc2013-10-30 10:15:06 -060075 }
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -020076
David Ahern44d742e2013-10-30 10:28:29 -060077 for (i = 0; i < argc; ++i) {
Arnaldo Carvalho de Melodbc67402015-10-01 12:12:22 -030078 char *sep, *s;
79
Yunlong Song16114952015-02-27 18:21:26 +080080 if (strcmp(argv[i], "tracepoint") == 0)
Yunlong Song5ef803e2015-02-27 18:21:28 +080081 print_tracepoint_events(NULL, NULL, raw_dump);
David Ahern8e00ddc2013-10-30 10:15:06 -060082 else if (strcmp(argv[i], "hw") == 0 ||
83 strcmp(argv[i], "hardware") == 0)
Yunlong Song705750f2015-02-27 18:21:27 +080084 print_symbol_events(NULL, PERF_TYPE_HARDWARE,
Yunlong Song5ef803e2015-02-27 18:21:28 +080085 event_symbols_hw, PERF_COUNT_HW_MAX, raw_dump);
David Ahern8e00ddc2013-10-30 10:15:06 -060086 else if (strcmp(argv[i], "sw") == 0 ||
Andi Kleen5e0861b2019-03-26 15:18:23 -070087 strcmp(argv[i], "software") == 0) {
Yunlong Song705750f2015-02-27 18:21:27 +080088 print_symbol_events(NULL, PERF_TYPE_SOFTWARE,
Yunlong Song5ef803e2015-02-27 18:21:28 +080089 event_symbols_sw, PERF_COUNT_SW_MAX, raw_dump);
Andi Kleen5e0861b2019-03-26 15:18:23 -070090 print_tool_events(NULL, raw_dump);
91 } else if (strcmp(argv[i], "cache") == 0 ||
David Ahern8e00ddc2013-10-30 10:15:06 -060092 strcmp(argv[i], "hwcache") == 0)
Yunlong Song5ef803e2015-02-27 18:21:28 +080093 print_hwcache_events(NULL, raw_dump);
David Ahern8e00ddc2013-10-30 10:15:06 -060094 else if (strcmp(argv[i], "pmu") == 0)
Sukadev Bhattiproluc8d68282016-09-15 15:24:48 -070095 print_pmu_events(NULL, raw_dump, !desc_flag,
Jin Yaoa7f6c8c2019-10-15 10:53:57 +080096 long_desc_flag, details_flag,
Jin Yao0e0ae872021-09-03 10:52:39 +080097 deprecated, pmu_name);
Masami Hiramatsu40218da2016-06-24 18:06:46 +090098 else if (strcmp(argv[i], "sdt") == 0)
99 print_sdt_events(NULL, NULL, raw_dump);
Kim Phillips8788d362019-09-19 15:43:05 -0500100 else if (strcmp(argv[i], "metric") == 0 || strcmp(argv[i], "metrics") == 0)
Jin Yao0e0ae872021-09-03 10:52:39 +0800101 metricgroup__print(true, false, NULL, raw_dump, details_flag, pmu_name);
Kim Phillips8788d362019-09-19 15:43:05 -0500102 else if (strcmp(argv[i], "metricgroup") == 0 || strcmp(argv[i], "metricgroups") == 0)
Jin Yao0e0ae872021-09-03 10:52:39 +0800103 metricgroup__print(false, true, NULL, raw_dump, details_flag, pmu_name);
Arnaldo Carvalho de Melodbc67402015-10-01 12:12:22 -0300104 else if ((sep = strchr(argv[i], ':')) != NULL) {
David Ahern8e00ddc2013-10-30 10:15:06 -0600105 int sep_idx;
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -0200106
David Ahern8e00ddc2013-10-30 10:15:06 -0600107 sep_idx = sep - argv[i];
108 s = strdup(argv[i]);
Jin Yao0e0ae872021-09-03 10:52:39 +0800109 if (s == NULL) {
110 ret = -1;
111 goto out;
112 }
David Ahern8e00ddc2013-10-30 10:15:06 -0600113
114 s[sep_idx] = '\0';
Yunlong Song5ef803e2015-02-27 18:21:28 +0800115 print_tracepoint_events(s, s + sep_idx + 1, raw_dump);
Masami Hiramatsu40218da2016-06-24 18:06:46 +0900116 print_sdt_events(s, s + sep_idx + 1, raw_dump);
Jin Yao0e0ae872021-09-03 10:52:39 +0800117 metricgroup__print(true, true, s, raw_dump, details_flag, pmu_name);
David Ahern8e00ddc2013-10-30 10:15:06 -0600118 free(s);
Arnaldo Carvalho de Melodbc67402015-10-01 12:12:22 -0300119 } 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 Kleen5e0861b2019-03-26 15:18:23 -0700128 print_tool_events(s, raw_dump);
Arnaldo Carvalho de Melodbc67402015-10-01 12:12:22 -0300129 print_hwcache_events(s, raw_dump);
Sukadev Bhattiproluc8d68282016-09-15 15:24:48 -0700130 print_pmu_events(s, raw_dump, !desc_flag,
Andi Kleenbf874fc2017-03-20 13:17:11 -0700131 long_desc_flag,
Jin Yaoa7f6c8c2019-10-15 10:53:57 +0800132 details_flag,
Jin Yao0e0ae872021-09-03 10:52:39 +0800133 deprecated,
134 pmu_name);
Arnaldo Carvalho de Melodbc67402015-10-01 12:12:22 -0300135 print_tracepoint_events(NULL, s, raw_dump);
Masami Hiramatsu40218da2016-06-24 18:06:46 +0900136 print_sdt_events(NULL, s, raw_dump);
Jin Yao0e0ae872021-09-03 10:52:39 +0800137 metricgroup__print(true, true, s, raw_dump, details_flag, pmu_name);
Arnaldo Carvalho de Melodbc67402015-10-01 12:12:22 -0300138 free(s);
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -0200139 }
140 }
Jin Yao0e0ae872021-09-03 10:52:39 +0800141
142out:
143 free(pmu_name);
144 return ret;
Thomas Gleixner86847b62009-06-06 12:24:17 +0200145}