blob: e0312a1c4792ae49d08d7cb0d33d28e2f9d44f15 [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
13#include "perf.h"
14
Thomas Gleixner86847b62009-06-06 12:24:17 +020015#include "util/parse-events.h"
Arnaldo Carvalho de Melo8f7a0dc2009-08-12 14:44:59 -030016#include "util/cache.h"
Andi Kleendc098b32013-04-20 11:02:29 -070017#include "util/pmu.h"
Andi Kleenf2361022017-01-27 18:03:40 -080018#include "util/debug.h"
Andi Kleen71b0acc2017-08-31 12:40:32 -070019#include "util/metricgroup.h"
Josh Poimboeuf4b6ab942015-12-15 09:39:39 -060020#include <subcmd/parse-options.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;
Andi Kleen1c5f01f2016-09-15 15:24:45 -070024
Arnaldo Carvalho de Melob0ad8ea2017-03-27 11:47:20 -030025int cmd_list(int argc, const char **argv)
Thomas Gleixner86847b62009-06-06 12:24:17 +020026{
David Ahern8e00ddc2013-10-30 10:15:06 -060027 int i;
Taesoo Kimb35052082014-12-30 22:36:55 -050028 bool raw_dump = false;
Sukadev Bhattiproluc8d68282016-09-15 15:24:48 -070029 bool long_desc_flag = false;
Taesoo Kimb35052082014-12-30 22:36:55 -050030 struct option list_options[] = {
31 OPT_BOOLEAN(0, "raw-dump", &raw_dump, "Dump raw events"),
Andi Kleen1c5f01f2016-09-15 15:24:45 -070032 OPT_BOOLEAN('d', "desc", &desc_flag,
33 "Print extra event descriptions. --no-desc to not print."),
Sukadev Bhattiproluc8d68282016-09-15 15:24:48 -070034 OPT_BOOLEAN('v', "long-desc", &long_desc_flag,
35 "Print longer event descriptions."),
Andi Kleenbf874fc2017-03-20 13:17:11 -070036 OPT_BOOLEAN(0, "details", &details_flag,
37 "Print information on the perf event names and expressions used internally by events."),
Andi Kleenf2361022017-01-27 18:03:40 -080038 OPT_INCR(0, "debug", &verbose,
39 "Enable debugging output"),
David Ahern44d742e2013-10-30 10:28:29 -060040 OPT_END()
41 };
42 const char * const list_usage[] = {
Sukadev Bhattiproluc8d68282016-09-15 15:24:48 -070043 "perf list [<options>] [hw|sw|cache|tracepoint|pmu|sdt|event_glob]",
David Ahern44d742e2013-10-30 10:28:29 -060044 NULL
45 };
46
Taesoo Kimb35052082014-12-30 22:36:55 -050047 set_option_flag(list_options, 0, "raw-dump", PARSE_OPT_HIDDEN);
48
David Ahern44d742e2013-10-30 10:28:29 -060049 argc = parse_options(argc, argv, list_options, list_usage,
50 PARSE_OPT_STOP_AT_NON_OPTION);
David Ahern8e00ddc2013-10-30 10:15:06 -060051
Arnaldo Carvalho de Melo8f7a0dc2009-08-12 14:44:59 -030052 setup_pager();
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -020053
Arnaldo Carvalho de Melodfc431c2015-09-30 17:13:26 -030054 if (!raw_dump && pager_in_use())
Yunlong Song619a3032015-02-13 21:11:55 +080055 printf("\nList of pre-defined events (to be used in -e):\n\n");
56
David Ahern44d742e2013-10-30 10:28:29 -060057 if (argc == 0) {
Andi Kleenbf874fc2017-03-20 13:17:11 -070058 print_events(NULL, raw_dump, !desc_flag, long_desc_flag,
59 details_flag);
David Ahern8e00ddc2013-10-30 10:15:06 -060060 return 0;
61 }
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -020062
David Ahern44d742e2013-10-30 10:28:29 -060063 for (i = 0; i < argc; ++i) {
Arnaldo Carvalho de Melodbc67402015-10-01 12:12:22 -030064 char *sep, *s;
65
Yunlong Song16114952015-02-27 18:21:26 +080066 if (strcmp(argv[i], "tracepoint") == 0)
Yunlong Song5ef803e2015-02-27 18:21:28 +080067 print_tracepoint_events(NULL, NULL, raw_dump);
David Ahern8e00ddc2013-10-30 10:15:06 -060068 else if (strcmp(argv[i], "hw") == 0 ||
69 strcmp(argv[i], "hardware") == 0)
Yunlong Song705750f2015-02-27 18:21:27 +080070 print_symbol_events(NULL, PERF_TYPE_HARDWARE,
Yunlong Song5ef803e2015-02-27 18:21:28 +080071 event_symbols_hw, PERF_COUNT_HW_MAX, raw_dump);
David Ahern8e00ddc2013-10-30 10:15:06 -060072 else if (strcmp(argv[i], "sw") == 0 ||
Andi Kleen5e0861b2019-03-26 15:18:23 -070073 strcmp(argv[i], "software") == 0) {
Yunlong Song705750f2015-02-27 18:21:27 +080074 print_symbol_events(NULL, PERF_TYPE_SOFTWARE,
Yunlong Song5ef803e2015-02-27 18:21:28 +080075 event_symbols_sw, PERF_COUNT_SW_MAX, raw_dump);
Andi Kleen5e0861b2019-03-26 15:18:23 -070076 print_tool_events(NULL, raw_dump);
77 } else if (strcmp(argv[i], "cache") == 0 ||
David Ahern8e00ddc2013-10-30 10:15:06 -060078 strcmp(argv[i], "hwcache") == 0)
Yunlong Song5ef803e2015-02-27 18:21:28 +080079 print_hwcache_events(NULL, raw_dump);
David Ahern8e00ddc2013-10-30 10:15:06 -060080 else if (strcmp(argv[i], "pmu") == 0)
Sukadev Bhattiproluc8d68282016-09-15 15:24:48 -070081 print_pmu_events(NULL, raw_dump, !desc_flag,
Andi Kleenbf874fc2017-03-20 13:17:11 -070082 long_desc_flag, details_flag);
Masami Hiramatsu40218da2016-06-24 18:06:46 +090083 else if (strcmp(argv[i], "sdt") == 0)
84 print_sdt_events(NULL, NULL, raw_dump);
Andi Kleen71b0acc2017-08-31 12:40:32 -070085 else if (strcmp(argv[i], "metric") == 0)
Jiri Olsa33bbc572019-02-13 13:32:41 +010086 metricgroup__print(true, false, NULL, raw_dump, details_flag);
Andi Kleen71b0acc2017-08-31 12:40:32 -070087 else if (strcmp(argv[i], "metricgroup") == 0)
Jiri Olsa33bbc572019-02-13 13:32:41 +010088 metricgroup__print(false, true, NULL, raw_dump, details_flag);
Arnaldo Carvalho de Melodbc67402015-10-01 12:12:22 -030089 else if ((sep = strchr(argv[i], ':')) != NULL) {
David Ahern8e00ddc2013-10-30 10:15:06 -060090 int sep_idx;
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -020091
David Ahern8e00ddc2013-10-30 10:15:06 -060092 if (sep == NULL) {
Sukadev Bhattiproluc8d68282016-09-15 15:24:48 -070093 print_events(argv[i], raw_dump, !desc_flag,
Andi Kleenbf874fc2017-03-20 13:17:11 -070094 long_desc_flag,
95 details_flag);
David Ahern8e00ddc2013-10-30 10:15:06 -060096 continue;
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -020097 }
David Ahern8e00ddc2013-10-30 10:15:06 -060098 sep_idx = sep - argv[i];
99 s = strdup(argv[i]);
100 if (s == NULL)
101 return -1;
102
103 s[sep_idx] = '\0';
Yunlong Song5ef803e2015-02-27 18:21:28 +0800104 print_tracepoint_events(s, s + sep_idx + 1, raw_dump);
Masami Hiramatsu40218da2016-06-24 18:06:46 +0900105 print_sdt_events(s, s + sep_idx + 1, raw_dump);
Jiri Olsa33bbc572019-02-13 13:32:41 +0100106 metricgroup__print(true, true, s, raw_dump, details_flag);
David Ahern8e00ddc2013-10-30 10:15:06 -0600107 free(s);
Arnaldo Carvalho de Melodbc67402015-10-01 12:12:22 -0300108 } 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 Kleen5e0861b2019-03-26 15:18:23 -0700117 print_tool_events(s, raw_dump);
Arnaldo Carvalho de Melodbc67402015-10-01 12:12:22 -0300118 print_hwcache_events(s, raw_dump);
Sukadev Bhattiproluc8d68282016-09-15 15:24:48 -0700119 print_pmu_events(s, raw_dump, !desc_flag,
Andi Kleenbf874fc2017-03-20 13:17:11 -0700120 long_desc_flag,
121 details_flag);
Arnaldo Carvalho de Melodbc67402015-10-01 12:12:22 -0300122 print_tracepoint_events(NULL, s, raw_dump);
Masami Hiramatsu40218da2016-06-24 18:06:46 +0900123 print_sdt_events(NULL, s, raw_dump);
Andi Kleen6f40b2a2019-03-14 15:49:53 -0700124 metricgroup__print(true, true, s, raw_dump, details_flag);
Arnaldo Carvalho de Melodbc67402015-10-01 12:12:22 -0300125 free(s);
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -0200126 }
127 }
Thomas Gleixner86847b62009-06-06 12:24:17 +0200128 return 0;
129}