Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 1 | /* |
| 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 Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 8 | * Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com> |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 9 | */ |
| 10 | #include "builtin.h" |
| 11 | |
| 12 | #include "perf.h" |
| 13 | |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 14 | #include "util/parse-events.h" |
Arnaldo Carvalho de Melo | 8f7a0dc | 2009-08-12 14:44:59 -0300 | [diff] [blame] | 15 | #include "util/cache.h" |
Andi Kleen | dc098b3 | 2013-04-20 11:02:29 -0700 | [diff] [blame] | 16 | #include "util/pmu.h" |
David Ahern | 44d742e | 2013-10-30 10:28:29 -0600 | [diff] [blame] | 17 | #include "util/parse-options.h" |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 18 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 19 | int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused) |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 20 | { |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 21 | int i; |
Taesoo Kim | b350520 | 2014-12-30 22:36:55 -0500 | [diff] [blame] | 22 | bool raw_dump = false; |
| 23 | struct option list_options[] = { |
| 24 | OPT_BOOLEAN(0, "raw-dump", &raw_dump, "Dump raw events"), |
David Ahern | 44d742e | 2013-10-30 10:28:29 -0600 | [diff] [blame] | 25 | OPT_END() |
| 26 | }; |
| 27 | const char * const list_usage[] = { |
| 28 | "perf list [hw|sw|cache|tracepoint|pmu|event_glob]", |
| 29 | NULL |
| 30 | }; |
| 31 | |
Taesoo Kim | b350520 | 2014-12-30 22:36:55 -0500 | [diff] [blame] | 32 | set_option_flag(list_options, 0, "raw-dump", PARSE_OPT_HIDDEN); |
| 33 | |
David Ahern | 44d742e | 2013-10-30 10:28:29 -0600 | [diff] [blame] | 34 | argc = parse_options(argc, argv, list_options, list_usage, |
| 35 | PARSE_OPT_STOP_AT_NON_OPTION); |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 36 | |
Arnaldo Carvalho de Melo | 8f7a0dc | 2009-08-12 14:44:59 -0300 | [diff] [blame] | 37 | setup_pager(); |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 38 | |
Yunlong Song | 619a303 | 2015-02-13 21:11:55 +0800 | [diff] [blame] | 39 | if (!raw_dump) |
| 40 | printf("\nList of pre-defined events (to be used in -e):\n\n"); |
| 41 | |
David Ahern | 44d742e | 2013-10-30 10:28:29 -0600 | [diff] [blame] | 42 | if (argc == 0) { |
Yunlong Song | 5ef803e | 2015-02-27 18:21:28 +0800 | [diff] [blame] | 43 | print_events(NULL, raw_dump); |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 44 | return 0; |
| 45 | } |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 46 | |
David Ahern | 44d742e | 2013-10-30 10:28:29 -0600 | [diff] [blame] | 47 | for (i = 0; i < argc; ++i) { |
Yunlong Song | 1611495 | 2015-02-27 18:21:26 +0800 | [diff] [blame] | 48 | if (strcmp(argv[i], "tracepoint") == 0) |
Yunlong Song | 5ef803e | 2015-02-27 18:21:28 +0800 | [diff] [blame] | 49 | print_tracepoint_events(NULL, NULL, raw_dump); |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 50 | else if (strcmp(argv[i], "hw") == 0 || |
| 51 | strcmp(argv[i], "hardware") == 0) |
Yunlong Song | 705750f | 2015-02-27 18:21:27 +0800 | [diff] [blame] | 52 | print_symbol_events(NULL, PERF_TYPE_HARDWARE, |
Yunlong Song | 5ef803e | 2015-02-27 18:21:28 +0800 | [diff] [blame] | 53 | event_symbols_hw, PERF_COUNT_HW_MAX, raw_dump); |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 54 | else if (strcmp(argv[i], "sw") == 0 || |
| 55 | strcmp(argv[i], "software") == 0) |
Yunlong Song | 705750f | 2015-02-27 18:21:27 +0800 | [diff] [blame] | 56 | print_symbol_events(NULL, PERF_TYPE_SOFTWARE, |
Yunlong Song | 5ef803e | 2015-02-27 18:21:28 +0800 | [diff] [blame] | 57 | event_symbols_sw, PERF_COUNT_SW_MAX, raw_dump); |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 58 | else if (strcmp(argv[i], "cache") == 0 || |
| 59 | strcmp(argv[i], "hwcache") == 0) |
Yunlong Song | 5ef803e | 2015-02-27 18:21:28 +0800 | [diff] [blame] | 60 | print_hwcache_events(NULL, raw_dump); |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 61 | else if (strcmp(argv[i], "pmu") == 0) |
Yunlong Song | 5ef803e | 2015-02-27 18:21:28 +0800 | [diff] [blame] | 62 | print_pmu_events(NULL, raw_dump); |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 63 | else { |
| 64 | char *sep = strchr(argv[i], ':'), *s; |
| 65 | int sep_idx; |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 66 | |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 67 | if (sep == NULL) { |
Yunlong Song | 5ef803e | 2015-02-27 18:21:28 +0800 | [diff] [blame] | 68 | print_events(argv[i], raw_dump); |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 69 | continue; |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 70 | } |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 71 | sep_idx = sep - argv[i]; |
| 72 | s = strdup(argv[i]); |
| 73 | if (s == NULL) |
| 74 | return -1; |
| 75 | |
| 76 | s[sep_idx] = '\0'; |
Yunlong Song | 5ef803e | 2015-02-27 18:21:28 +0800 | [diff] [blame] | 77 | print_tracepoint_events(s, s + sep_idx + 1, raw_dump); |
David Ahern | 8e00ddc | 2013-10-30 10:15:06 -0600 | [diff] [blame] | 78 | free(s); |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 79 | } |
| 80 | } |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 81 | return 0; |
| 82 | } |