blob: 5e22db4684b86a7a226c5d070594f160f2bc9237 [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
Irina Tirdea1d037ca2012-09-11 01:15:03 +030019int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
Thomas Gleixner86847b62009-06-06 12:24:17 +020020{
David Ahern8e00ddc2013-10-30 10:15:06 -060021 int i;
Taesoo Kimb3505202014-12-30 22:36:55 -050022 bool raw_dump = false;
23 struct option list_options[] = {
24 OPT_BOOLEAN(0, "raw-dump", &raw_dump, "Dump raw events"),
David Ahern44d742e2013-10-30 10:28:29 -060025 OPT_END()
26 };
27 const char * const list_usage[] = {
28 "perf list [hw|sw|cache|tracepoint|pmu|event_glob]",
29 NULL
30 };
31
Taesoo Kimb3505202014-12-30 22:36:55 -050032 set_option_flag(list_options, 0, "raw-dump", PARSE_OPT_HIDDEN);
33
David Ahern44d742e2013-10-30 10:28:29 -060034 argc = parse_options(argc, argv, list_options, list_usage,
35 PARSE_OPT_STOP_AT_NON_OPTION);
David Ahern8e00ddc2013-10-30 10:15:06 -060036
Arnaldo Carvalho de Melo8f7a0dc2009-08-12 14:44:59 -030037 setup_pager();
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -020038
Arnaldo Carvalho de Melodfc431c2015-09-30 17:13:26 -030039 if (!raw_dump && pager_in_use())
Yunlong Song619a3032015-02-13 21:11:55 +080040 printf("\nList of pre-defined events (to be used in -e):\n\n");
41
David Ahern44d742e2013-10-30 10:28:29 -060042 if (argc == 0) {
Yunlong Song5ef803e2015-02-27 18:21:28 +080043 print_events(NULL, raw_dump);
David Ahern8e00ddc2013-10-30 10:15:06 -060044 return 0;
45 }
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -020046
David Ahern44d742e2013-10-30 10:28:29 -060047 for (i = 0; i < argc; ++i) {
Arnaldo Carvalho de Melodbc67402015-10-01 12:12:22 -030048 char *sep, *s;
49
Yunlong Song16114952015-02-27 18:21:26 +080050 if (strcmp(argv[i], "tracepoint") == 0)
Yunlong Song5ef803e2015-02-27 18:21:28 +080051 print_tracepoint_events(NULL, NULL, raw_dump);
David Ahern8e00ddc2013-10-30 10:15:06 -060052 else if (strcmp(argv[i], "hw") == 0 ||
53 strcmp(argv[i], "hardware") == 0)
Yunlong Song705750f2015-02-27 18:21:27 +080054 print_symbol_events(NULL, PERF_TYPE_HARDWARE,
Yunlong Song5ef803e2015-02-27 18:21:28 +080055 event_symbols_hw, PERF_COUNT_HW_MAX, raw_dump);
David Ahern8e00ddc2013-10-30 10:15:06 -060056 else if (strcmp(argv[i], "sw") == 0 ||
57 strcmp(argv[i], "software") == 0)
Yunlong Song705750f2015-02-27 18:21:27 +080058 print_symbol_events(NULL, PERF_TYPE_SOFTWARE,
Yunlong Song5ef803e2015-02-27 18:21:28 +080059 event_symbols_sw, PERF_COUNT_SW_MAX, raw_dump);
David Ahern8e00ddc2013-10-30 10:15:06 -060060 else if (strcmp(argv[i], "cache") == 0 ||
61 strcmp(argv[i], "hwcache") == 0)
Yunlong Song5ef803e2015-02-27 18:21:28 +080062 print_hwcache_events(NULL, raw_dump);
David Ahern8e00ddc2013-10-30 10:15:06 -060063 else if (strcmp(argv[i], "pmu") == 0)
Yunlong Song5ef803e2015-02-27 18:21:28 +080064 print_pmu_events(NULL, raw_dump);
Arnaldo Carvalho de Melodbc67402015-10-01 12:12:22 -030065 else if ((sep = strchr(argv[i], ':')) != NULL) {
David Ahern8e00ddc2013-10-30 10:15:06 -060066 int sep_idx;
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -020067
David Ahern8e00ddc2013-10-30 10:15:06 -060068 if (sep == NULL) {
Yunlong Song5ef803e2015-02-27 18:21:28 +080069 print_events(argv[i], raw_dump);
David Ahern8e00ddc2013-10-30 10:15:06 -060070 continue;
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -020071 }
David Ahern8e00ddc2013-10-30 10:15:06 -060072 sep_idx = sep - argv[i];
73 s = strdup(argv[i]);
74 if (s == NULL)
75 return -1;
76
77 s[sep_idx] = '\0';
Yunlong Song5ef803e2015-02-27 18:21:28 +080078 print_tracepoint_events(s, s + sep_idx + 1, raw_dump);
David Ahern8e00ddc2013-10-30 10:15:06 -060079 free(s);
Arnaldo Carvalho de Melodbc67402015-10-01 12:12:22 -030080 } else {
81 if (asprintf(&s, "*%s*", argv[i]) < 0) {
82 printf("Critical: Not enough memory! Trying to continue...\n");
83 continue;
84 }
85 print_symbol_events(s, PERF_TYPE_HARDWARE,
86 event_symbols_hw, PERF_COUNT_HW_MAX, raw_dump);
87 print_symbol_events(s, PERF_TYPE_SOFTWARE,
88 event_symbols_sw, PERF_COUNT_SW_MAX, raw_dump);
89 print_hwcache_events(s, raw_dump);
90 print_pmu_events(s, raw_dump);
91 print_tracepoint_events(NULL, s, raw_dump);
92 free(s);
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -020093 }
94 }
Thomas Gleixner86847b62009-06-06 12:24:17 +020095 return 0;
96}