blob: 011195e38f2173947550100e62927e908b429d30 [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;
David Ahern44d742e2013-10-30 10:28:29 -060022 const struct option list_options[] = {
23 OPT_END()
24 };
25 const char * const list_usage[] = {
26 "perf list [hw|sw|cache|tracepoint|pmu|event_glob]",
27 NULL
28 };
29
30 argc = parse_options(argc, argv, list_options, list_usage,
31 PARSE_OPT_STOP_AT_NON_OPTION);
David Ahern8e00ddc2013-10-30 10:15:06 -060032
Arnaldo Carvalho de Melo8f7a0dc2009-08-12 14:44:59 -030033 setup_pager();
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -020034
David Ahern44d742e2013-10-30 10:28:29 -060035 if (argc == 0) {
Frederic Weisbeckera3277d22012-08-09 16:31:52 +020036 print_events(NULL, false);
David Ahern8e00ddc2013-10-30 10:15:06 -060037 return 0;
38 }
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -020039
David Ahern44d742e2013-10-30 10:28:29 -060040 for (i = 0; i < argc; ++i) {
41 if (i)
David Ahern8e00ddc2013-10-30 10:15:06 -060042 putchar('\n');
43 if (strncmp(argv[i], "tracepoint", 10) == 0)
44 print_tracepoint_events(NULL, NULL, false);
45 else if (strcmp(argv[i], "hw") == 0 ||
46 strcmp(argv[i], "hardware") == 0)
47 print_events_type(PERF_TYPE_HARDWARE);
48 else if (strcmp(argv[i], "sw") == 0 ||
49 strcmp(argv[i], "software") == 0)
50 print_events_type(PERF_TYPE_SOFTWARE);
51 else if (strcmp(argv[i], "cache") == 0 ||
52 strcmp(argv[i], "hwcache") == 0)
53 print_hwcache_events(NULL, false);
54 else if (strcmp(argv[i], "pmu") == 0)
55 print_pmu_events(NULL, false);
56 else if (strcmp(argv[i], "--raw-dump") == 0)
57 print_events(NULL, true);
58 else {
59 char *sep = strchr(argv[i], ':'), *s;
60 int sep_idx;
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -020061
David Ahern8e00ddc2013-10-30 10:15:06 -060062 if (sep == NULL) {
63 print_events(argv[i], false);
64 continue;
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -020065 }
David Ahern8e00ddc2013-10-30 10:15:06 -060066 sep_idx = sep - argv[i];
67 s = strdup(argv[i]);
68 if (s == NULL)
69 return -1;
70
71 s[sep_idx] = '\0';
72 print_tracepoint_events(s, s + sep_idx + 1, false);
73 free(s);
Arnaldo Carvalho de Melo668b8782011-02-17 15:38:58 -020074 }
75 }
Thomas Gleixner86847b62009-06-06 12:24:17 +020076 return 0;
77}