blob: ba9322ff858bead84884e832f84dc73476c6862a [file] [log] [blame]
Thomas Gleixner86847b62009-06-06 12:24:17 +02001/*
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 Melo668b8782011-02-17 15:38:58 -02008 * Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
Thomas Gleixner86847b62009-06-06 12:24:17 +02009 */
10#include "builtin.h"
11
12#include "perf.h"
13
Thomas Gleixner86847b62009-06-06 12:24:17 +020014#include "util/parse-events.h"
Arnaldo Carvalho de Melo8f7a0dc2009-08-12 14:44:59 -030015#include "util/cache.h"
Andi Kleendc098b32013-04-20 11:02:29 -070016#include "util/pmu.h"
Josh Poimboeuf4b6ab942015-12-15 09:39:39 -060017#include <subcmd/parse-options.h>
Thomas Gleixner86847b62009-06-06 12:24:17 +020018
Andi Kleen1c5f01f2016-09-15 15:24:45 -070019static bool desc_flag = true;
20
Irina Tirdea1d037ca2012-09-11 01:15:03 +030021int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
Thomas Gleixner86847b62009-06-06 12:24:17 +020022{
David Ahern8e00ddc2013-10-30 10:15:06 -060023 int i;
Taesoo Kimb3505202014-12-30 22:36:55 -050024 bool raw_dump = false;
Sukadev Bhattiproluc8d68282016-09-15 15:24:48 -070025 bool long_desc_flag = false;
Taesoo Kimb3505202014-12-30 22:36:55 -050026 struct option list_options[] = {
27 OPT_BOOLEAN(0, "raw-dump", &raw_dump, "Dump raw events"),
Andi Kleen1c5f01f2016-09-15 15:24:45 -070028 OPT_BOOLEAN('d', "desc", &desc_flag,
29 "Print extra event descriptions. --no-desc to not print."),
Sukadev Bhattiproluc8d68282016-09-15 15:24:48 -070030 OPT_BOOLEAN('v', "long-desc", &long_desc_flag,
31 "Print longer event descriptions."),
David Ahern44d742e2013-10-30 10:28:29 -060032 OPT_END()
33 };
34 const char * const list_usage[] = {
Sukadev Bhattiproluc8d68282016-09-15 15:24:48 -070035 "perf list [<options>] [hw|sw|cache|tracepoint|pmu|sdt|event_glob]",
David Ahern44d742e2013-10-30 10:28:29 -060036 NULL
37 };
38
Taesoo Kimb3505202014-12-30 22:36:55 -050039 set_option_flag(list_options, 0, "raw-dump", PARSE_OPT_HIDDEN);
40
David Ahern44d742e2013-10-30 10:28:29 -060041 argc = parse_options(argc, argv, list_options, list_usage,
42 PARSE_OPT_STOP_AT_NON_OPTION);
David Ahern8e00ddc2013-10-30 10:15:06 -060043
Arnaldo Carvalho de Melo8f7a0dc2009-08-12 14:44:59 -030044 setup_pager();
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -020045
Arnaldo Carvalho de Melodfc431c2015-09-30 17:13:26 -030046 if (!raw_dump && pager_in_use())
Yunlong Song619a3032015-02-13 21:11:55 +080047 printf("\nList of pre-defined events (to be used in -e):\n\n");
48
David Ahern44d742e2013-10-30 10:28:29 -060049 if (argc == 0) {
Sukadev Bhattiproluc8d68282016-09-15 15:24:48 -070050 print_events(NULL, raw_dump, !desc_flag, long_desc_flag);
David Ahern8e00ddc2013-10-30 10:15:06 -060051 return 0;
52 }
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -020053
David Ahern44d742e2013-10-30 10:28:29 -060054 for (i = 0; i < argc; ++i) {
Arnaldo Carvalho de Melodbc67402015-10-01 12:12:22 -030055 char *sep, *s;
56
Yunlong Song16114952015-02-27 18:21:26 +080057 if (strcmp(argv[i], "tracepoint") == 0)
Yunlong Song5ef803e2015-02-27 18:21:28 +080058 print_tracepoint_events(NULL, NULL, raw_dump);
David Ahern8e00ddc2013-10-30 10:15:06 -060059 else if (strcmp(argv[i], "hw") == 0 ||
60 strcmp(argv[i], "hardware") == 0)
Yunlong Song705750f2015-02-27 18:21:27 +080061 print_symbol_events(NULL, PERF_TYPE_HARDWARE,
Yunlong Song5ef803e2015-02-27 18:21:28 +080062 event_symbols_hw, PERF_COUNT_HW_MAX, raw_dump);
David Ahern8e00ddc2013-10-30 10:15:06 -060063 else if (strcmp(argv[i], "sw") == 0 ||
64 strcmp(argv[i], "software") == 0)
Yunlong Song705750f2015-02-27 18:21:27 +080065 print_symbol_events(NULL, PERF_TYPE_SOFTWARE,
Yunlong Song5ef803e2015-02-27 18:21:28 +080066 event_symbols_sw, PERF_COUNT_SW_MAX, raw_dump);
David Ahern8e00ddc2013-10-30 10:15:06 -060067 else if (strcmp(argv[i], "cache") == 0 ||
68 strcmp(argv[i], "hwcache") == 0)
Yunlong Song5ef803e2015-02-27 18:21:28 +080069 print_hwcache_events(NULL, raw_dump);
David Ahern8e00ddc2013-10-30 10:15:06 -060070 else if (strcmp(argv[i], "pmu") == 0)
Sukadev Bhattiproluc8d68282016-09-15 15:24:48 -070071 print_pmu_events(NULL, raw_dump, !desc_flag,
72 long_desc_flag);
Masami Hiramatsu40218da2016-06-24 18:06:46 +090073 else if (strcmp(argv[i], "sdt") == 0)
74 print_sdt_events(NULL, NULL, raw_dump);
Arnaldo Carvalho de Melodbc67402015-10-01 12:12:22 -030075 else if ((sep = strchr(argv[i], ':')) != NULL) {
David Ahern8e00ddc2013-10-30 10:15:06 -060076 int sep_idx;
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -020077
David Ahern8e00ddc2013-10-30 10:15:06 -060078 if (sep == NULL) {
Sukadev Bhattiproluc8d68282016-09-15 15:24:48 -070079 print_events(argv[i], raw_dump, !desc_flag,
80 long_desc_flag);
David Ahern8e00ddc2013-10-30 10:15:06 -060081 continue;
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -020082 }
David Ahern8e00ddc2013-10-30 10:15:06 -060083 sep_idx = sep - argv[i];
84 s = strdup(argv[i]);
85 if (s == NULL)
86 return -1;
87
88 s[sep_idx] = '\0';
Yunlong Song5ef803e2015-02-27 18:21:28 +080089 print_tracepoint_events(s, s + sep_idx + 1, raw_dump);
Masami Hiramatsu40218da2016-06-24 18:06:46 +090090 print_sdt_events(s, s + sep_idx + 1, raw_dump);
David Ahern8e00ddc2013-10-30 10:15:06 -060091 free(s);
Arnaldo Carvalho de Melodbc67402015-10-01 12:12:22 -030092 } else {
93 if (asprintf(&s, "*%s*", argv[i]) < 0) {
94 printf("Critical: Not enough memory! Trying to continue...\n");
95 continue;
96 }
97 print_symbol_events(s, PERF_TYPE_HARDWARE,
98 event_symbols_hw, PERF_COUNT_HW_MAX, raw_dump);
99 print_symbol_events(s, PERF_TYPE_SOFTWARE,
100 event_symbols_sw, PERF_COUNT_SW_MAX, raw_dump);
101 print_hwcache_events(s, raw_dump);
Sukadev Bhattiproluc8d68282016-09-15 15:24:48 -0700102 print_pmu_events(s, raw_dump, !desc_flag,
103 long_desc_flag);
Arnaldo Carvalho de Melodbc67402015-10-01 12:12:22 -0300104 print_tracepoint_events(NULL, s, raw_dump);
Masami Hiramatsu40218da2016-06-24 18:06:46 +0900105 print_sdt_events(NULL, s, raw_dump);
Arnaldo Carvalho de Melodbc67402015-10-01 12:12:22 -0300106 free(s);
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -0200107 }
108 }
Thomas Gleixner86847b62009-06-06 12:24:17 +0200109 return 0;
110}