blob: 4bf2cb4d25aa6bdba591495974f65091078d0b85 [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"
Andi Kleenf2361022017-01-27 18:03:40 -080017#include "util/debug.h"
Josh Poimboeuf4b6ab942015-12-15 09:39:39 -060018#include <subcmd/parse-options.h>
Thomas Gleixner86847b62009-06-06 12:24:17 +020019
Andi Kleen1c5f01f2016-09-15 15:24:45 -070020static bool desc_flag = true;
Andi Kleenbf874fc2017-03-20 13:17:11 -070021static bool details_flag;
Andi Kleen1c5f01f2016-09-15 15:24:45 -070022
Arnaldo Carvalho de Melob0ad8ea2017-03-27 11:47:20 -030023int cmd_list(int argc, const char **argv)
Thomas Gleixner86847b62009-06-06 12:24:17 +020024{
David Ahern8e00ddc2013-10-30 10:15:06 -060025 int i;
Taesoo Kimb3505202014-12-30 22:36:55 -050026 bool raw_dump = false;
Sukadev Bhattiproluc8d68282016-09-15 15:24:48 -070027 bool long_desc_flag = false;
Taesoo Kimb3505202014-12-30 22:36:55 -050028 struct option list_options[] = {
29 OPT_BOOLEAN(0, "raw-dump", &raw_dump, "Dump raw events"),
Andi Kleen1c5f01f2016-09-15 15:24:45 -070030 OPT_BOOLEAN('d', "desc", &desc_flag,
31 "Print extra event descriptions. --no-desc to not print."),
Sukadev Bhattiproluc8d68282016-09-15 15:24:48 -070032 OPT_BOOLEAN('v', "long-desc", &long_desc_flag,
33 "Print longer event descriptions."),
Andi Kleenbf874fc2017-03-20 13:17:11 -070034 OPT_BOOLEAN(0, "details", &details_flag,
35 "Print information on the perf event names and expressions used internally by events."),
Andi Kleenf2361022017-01-27 18:03:40 -080036 OPT_INCR(0, "debug", &verbose,
37 "Enable debugging output"),
David Ahern44d742e2013-10-30 10:28:29 -060038 OPT_END()
39 };
40 const char * const list_usage[] = {
Sukadev Bhattiproluc8d68282016-09-15 15:24:48 -070041 "perf list [<options>] [hw|sw|cache|tracepoint|pmu|sdt|event_glob]",
David Ahern44d742e2013-10-30 10:28:29 -060042 NULL
43 };
44
Taesoo Kimb3505202014-12-30 22:36:55 -050045 set_option_flag(list_options, 0, "raw-dump", PARSE_OPT_HIDDEN);
46
David Ahern44d742e2013-10-30 10:28:29 -060047 argc = parse_options(argc, argv, list_options, list_usage,
48 PARSE_OPT_STOP_AT_NON_OPTION);
David Ahern8e00ddc2013-10-30 10:15:06 -060049
Arnaldo Carvalho de Melo8f7a0dc2009-08-12 14:44:59 -030050 setup_pager();
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -020051
Arnaldo Carvalho de Melodfc431c2015-09-30 17:13:26 -030052 if (!raw_dump && pager_in_use())
Yunlong Song619a3032015-02-13 21:11:55 +080053 printf("\nList of pre-defined events (to be used in -e):\n\n");
54
David Ahern44d742e2013-10-30 10:28:29 -060055 if (argc == 0) {
Andi Kleenbf874fc2017-03-20 13:17:11 -070056 print_events(NULL, raw_dump, !desc_flag, long_desc_flag,
57 details_flag);
David Ahern8e00ddc2013-10-30 10:15:06 -060058 return 0;
59 }
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -020060
David Ahern44d742e2013-10-30 10:28:29 -060061 for (i = 0; i < argc; ++i) {
Arnaldo Carvalho de Melodbc67402015-10-01 12:12:22 -030062 char *sep, *s;
63
Yunlong Song16114952015-02-27 18:21:26 +080064 if (strcmp(argv[i], "tracepoint") == 0)
Yunlong Song5ef803e2015-02-27 18:21:28 +080065 print_tracepoint_events(NULL, NULL, raw_dump);
David Ahern8e00ddc2013-10-30 10:15:06 -060066 else if (strcmp(argv[i], "hw") == 0 ||
67 strcmp(argv[i], "hardware") == 0)
Yunlong Song705750f2015-02-27 18:21:27 +080068 print_symbol_events(NULL, PERF_TYPE_HARDWARE,
Yunlong Song5ef803e2015-02-27 18:21:28 +080069 event_symbols_hw, PERF_COUNT_HW_MAX, raw_dump);
David Ahern8e00ddc2013-10-30 10:15:06 -060070 else if (strcmp(argv[i], "sw") == 0 ||
71 strcmp(argv[i], "software") == 0)
Yunlong Song705750f2015-02-27 18:21:27 +080072 print_symbol_events(NULL, PERF_TYPE_SOFTWARE,
Yunlong Song5ef803e2015-02-27 18:21:28 +080073 event_symbols_sw, PERF_COUNT_SW_MAX, raw_dump);
David Ahern8e00ddc2013-10-30 10:15:06 -060074 else if (strcmp(argv[i], "cache") == 0 ||
75 strcmp(argv[i], "hwcache") == 0)
Yunlong Song5ef803e2015-02-27 18:21:28 +080076 print_hwcache_events(NULL, raw_dump);
David Ahern8e00ddc2013-10-30 10:15:06 -060077 else if (strcmp(argv[i], "pmu") == 0)
Sukadev Bhattiproluc8d68282016-09-15 15:24:48 -070078 print_pmu_events(NULL, raw_dump, !desc_flag,
Andi Kleenbf874fc2017-03-20 13:17:11 -070079 long_desc_flag, details_flag);
Masami Hiramatsu40218da2016-06-24 18:06:46 +090080 else if (strcmp(argv[i], "sdt") == 0)
81 print_sdt_events(NULL, NULL, raw_dump);
Arnaldo Carvalho de Melodbc67402015-10-01 12:12:22 -030082 else if ((sep = strchr(argv[i], ':')) != NULL) {
David Ahern8e00ddc2013-10-30 10:15:06 -060083 int sep_idx;
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -020084
David Ahern8e00ddc2013-10-30 10:15:06 -060085 if (sep == NULL) {
Sukadev Bhattiproluc8d68282016-09-15 15:24:48 -070086 print_events(argv[i], raw_dump, !desc_flag,
Andi Kleenbf874fc2017-03-20 13:17:11 -070087 long_desc_flag,
88 details_flag);
David Ahern8e00ddc2013-10-30 10:15:06 -060089 continue;
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -020090 }
David Ahern8e00ddc2013-10-30 10:15:06 -060091 sep_idx = sep - argv[i];
92 s = strdup(argv[i]);
93 if (s == NULL)
94 return -1;
95
96 s[sep_idx] = '\0';
Yunlong Song5ef803e2015-02-27 18:21:28 +080097 print_tracepoint_events(s, s + sep_idx + 1, raw_dump);
Masami Hiramatsu40218da2016-06-24 18:06:46 +090098 print_sdt_events(s, s + sep_idx + 1, raw_dump);
David Ahern8e00ddc2013-10-30 10:15:06 -060099 free(s);
Arnaldo Carvalho de Melodbc67402015-10-01 12:12:22 -0300100 } else {
101 if (asprintf(&s, "*%s*", argv[i]) < 0) {
102 printf("Critical: Not enough memory! Trying to continue...\n");
103 continue;
104 }
105 print_symbol_events(s, PERF_TYPE_HARDWARE,
106 event_symbols_hw, PERF_COUNT_HW_MAX, raw_dump);
107 print_symbol_events(s, PERF_TYPE_SOFTWARE,
108 event_symbols_sw, PERF_COUNT_SW_MAX, raw_dump);
109 print_hwcache_events(s, raw_dump);
Sukadev Bhattiproluc8d68282016-09-15 15:24:48 -0700110 print_pmu_events(s, raw_dump, !desc_flag,
Andi Kleenbf874fc2017-03-20 13:17:11 -0700111 long_desc_flag,
112 details_flag);
Arnaldo Carvalho de Melodbc67402015-10-01 12:12:22 -0300113 print_tracepoint_events(NULL, s, raw_dump);
Masami Hiramatsu40218da2016-06-24 18:06:46 +0900114 print_sdt_events(NULL, s, raw_dump);
Arnaldo Carvalho de Melodbc67402015-10-01 12:12:22 -0300115 free(s);
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -0200116 }
117 }
Thomas Gleixner86847b62009-06-06 12:24:17 +0200118 return 0;
119}