blob: ad8018e26aa0ca59ef333f765742de50032905a7 [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"
David Ahern44d742e2013-10-30 10:28:29 -060017#include "util/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
Taesoo Kimb3505202014-12-30 22:36:55 -050039 if (raw_dump) {
40 print_events(NULL, true);
41 return 0;
42 }
43
Yunlong Song619a3032015-02-13 21:11:55 +080044 if (!raw_dump)
45 printf("\nList of pre-defined events (to be used in -e):\n\n");
46
David Ahern44d742e2013-10-30 10:28:29 -060047 if (argc == 0) {
Frederic Weisbeckera3277d22012-08-09 16:31:52 +020048 print_events(NULL, false);
David Ahern8e00ddc2013-10-30 10:15:06 -060049 return 0;
50 }
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -020051
David Ahern44d742e2013-10-30 10:28:29 -060052 for (i = 0; i < argc; ++i) {
53 if (i)
David Ahern8e00ddc2013-10-30 10:15:06 -060054 putchar('\n');
55 if (strncmp(argv[i], "tracepoint", 10) == 0)
56 print_tracepoint_events(NULL, NULL, false);
57 else if (strcmp(argv[i], "hw") == 0 ||
58 strcmp(argv[i], "hardware") == 0)
59 print_events_type(PERF_TYPE_HARDWARE);
60 else if (strcmp(argv[i], "sw") == 0 ||
61 strcmp(argv[i], "software") == 0)
62 print_events_type(PERF_TYPE_SOFTWARE);
63 else if (strcmp(argv[i], "cache") == 0 ||
64 strcmp(argv[i], "hwcache") == 0)
65 print_hwcache_events(NULL, false);
66 else if (strcmp(argv[i], "pmu") == 0)
67 print_pmu_events(NULL, false);
David Ahern8e00ddc2013-10-30 10:15:06 -060068 else {
69 char *sep = strchr(argv[i], ':'), *s;
70 int sep_idx;
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -020071
David Ahern8e00ddc2013-10-30 10:15:06 -060072 if (sep == NULL) {
73 print_events(argv[i], false);
74 continue;
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -020075 }
David Ahern8e00ddc2013-10-30 10:15:06 -060076 sep_idx = sep - argv[i];
77 s = strdup(argv[i]);
78 if (s == NULL)
79 return -1;
80
81 s[sep_idx] = '\0';
82 print_tracepoint_events(s, s + sep_idx + 1, false);
83 free(s);
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -020084 }
85 }
Thomas Gleixner86847b62009-06-06 12:24:17 +020086 return 0;
87}