Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 1 | #include "../../../include/linux/hw_breakpoint.h" |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 2 | #include "util.h" |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 3 | #include "../perf.h" |
Arnaldo Carvalho de Melo | 361c99a | 2011-01-11 20:56:53 -0200 | [diff] [blame] | 4 | #include "evlist.h" |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 5 | #include "evsel.h" |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 6 | #include "parse-options.h" |
| 7 | #include "parse-events.h" |
| 8 | #include "exec_cmd.h" |
Arnaldo Carvalho de Melo | a0055ae | 2009-06-01 17:50:19 -0300 | [diff] [blame] | 9 | #include "string.h" |
Arnaldo Carvalho de Melo | 5aab621 | 2010-03-25 19:59:00 -0300 | [diff] [blame] | 10 | #include "symbol.h" |
Jason Baron | 5beeded | 2009-07-21 14:16:29 -0400 | [diff] [blame] | 11 | #include "cache.h" |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 12 | #include "header.h" |
Clark Williams | 549104f | 2009-11-08 09:03:07 -0600 | [diff] [blame] | 13 | #include "debugfs.h" |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 14 | #include "parse-events-flex.h" |
Jiri Olsa | 5f537a2 | 2012-03-15 20:09:18 +0100 | [diff] [blame] | 15 | #include "pmu.h" |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 16 | |
| 17 | #define MAX_NAME_LEN 100 |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 18 | |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 19 | struct event_symbol { |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 20 | u8 type; |
| 21 | u64 config; |
| 22 | const char *symbol; |
| 23 | const char *alias; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 24 | }; |
| 25 | |
Jiri Olsa | 82ba1f2 | 2012-05-21 09:12:50 +0200 | [diff] [blame] | 26 | #ifdef PARSER_DEBUG |
| 27 | extern int parse_events_debug; |
| 28 | #endif |
Jiri Olsa | b847cbd | 2012-05-21 09:12:51 +0200 | [diff] [blame^] | 29 | int parse_events_parse(struct list_head *list, int *idx); |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 30 | |
Jaswinder Singh Rajput | 51e2684 | 2009-06-22 16:43:14 +0530 | [diff] [blame] | 31 | #define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x |
| 32 | #define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 33 | |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 34 | static struct event_symbol event_symbols[] = { |
Ingo Molnar | 129c04c | 2011-04-29 14:41:28 +0200 | [diff] [blame] | 35 | { CHW(CPU_CYCLES), "cpu-cycles", "cycles" }, |
| 36 | { CHW(STALLED_CYCLES_FRONTEND), "stalled-cycles-frontend", "idle-cycles-frontend" }, |
| 37 | { CHW(STALLED_CYCLES_BACKEND), "stalled-cycles-backend", "idle-cycles-backend" }, |
| 38 | { CHW(INSTRUCTIONS), "instructions", "" }, |
| 39 | { CHW(CACHE_REFERENCES), "cache-references", "" }, |
| 40 | { CHW(CACHE_MISSES), "cache-misses", "" }, |
| 41 | { CHW(BRANCH_INSTRUCTIONS), "branch-instructions", "branches" }, |
| 42 | { CHW(BRANCH_MISSES), "branch-misses", "" }, |
| 43 | { CHW(BUS_CYCLES), "bus-cycles", "" }, |
Stephane Eranian | f1ac18a | 2011-12-11 00:28:54 +0100 | [diff] [blame] | 44 | { CHW(REF_CPU_CYCLES), "ref-cycles", "" }, |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 45 | |
Ingo Molnar | 129c04c | 2011-04-29 14:41:28 +0200 | [diff] [blame] | 46 | { CSW(CPU_CLOCK), "cpu-clock", "" }, |
| 47 | { CSW(TASK_CLOCK), "task-clock", "" }, |
| 48 | { CSW(PAGE_FAULTS), "page-faults", "faults" }, |
| 49 | { CSW(PAGE_FAULTS_MIN), "minor-faults", "" }, |
| 50 | { CSW(PAGE_FAULTS_MAJ), "major-faults", "" }, |
| 51 | { CSW(CONTEXT_SWITCHES), "context-switches", "cs" }, |
| 52 | { CSW(CPU_MIGRATIONS), "cpu-migrations", "migrations" }, |
| 53 | { CSW(ALIGNMENT_FAULTS), "alignment-faults", "" }, |
| 54 | { CSW(EMULATION_FAULTS), "emulation-faults", "" }, |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 55 | }; |
| 56 | |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 57 | #define __PERF_EVENT_FIELD(config, name) \ |
| 58 | ((config & PERF_EVENT_##name##_MASK) >> PERF_EVENT_##name##_SHIFT) |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 59 | |
Ingo Molnar | 1fc570a | 2011-04-27 05:20:22 +0200 | [diff] [blame] | 60 | #define PERF_EVENT_RAW(config) __PERF_EVENT_FIELD(config, RAW) |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 61 | #define PERF_EVENT_CONFIG(config) __PERF_EVENT_FIELD(config, CONFIG) |
Ingo Molnar | 1fc570a | 2011-04-27 05:20:22 +0200 | [diff] [blame] | 62 | #define PERF_EVENT_TYPE(config) __PERF_EVENT_FIELD(config, TYPE) |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 63 | #define PERF_EVENT_ID(config) __PERF_EVENT_FIELD(config, EVENT) |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 64 | |
Ingo Molnar | d3d1e86 | 2011-04-29 13:49:08 +0200 | [diff] [blame] | 65 | static const char *hw_event_names[PERF_COUNT_HW_MAX] = { |
Ingo Molnar | 8faf3b5 | 2009-06-06 13:58:12 +0200 | [diff] [blame] | 66 | "cycles", |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 67 | "instructions", |
Ingo Molnar | 8faf3b5 | 2009-06-06 13:58:12 +0200 | [diff] [blame] | 68 | "cache-references", |
| 69 | "cache-misses", |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 70 | "branches", |
Ingo Molnar | 8faf3b5 | 2009-06-06 13:58:12 +0200 | [diff] [blame] | 71 | "branch-misses", |
| 72 | "bus-cycles", |
Ingo Molnar | d3d1e86 | 2011-04-29 13:49:08 +0200 | [diff] [blame] | 73 | "stalled-cycles-frontend", |
| 74 | "stalled-cycles-backend", |
Stephane Eranian | f1ac18a | 2011-12-11 00:28:54 +0100 | [diff] [blame] | 75 | "ref-cycles", |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 76 | }; |
| 77 | |
Ingo Molnar | d3d1e86 | 2011-04-29 13:49:08 +0200 | [diff] [blame] | 78 | static const char *sw_event_names[PERF_COUNT_SW_MAX] = { |
Ingo Molnar | 749141d | 2011-04-27 04:24:57 +0200 | [diff] [blame] | 79 | "cpu-clock", |
| 80 | "task-clock", |
Ingo Molnar | 8faf3b5 | 2009-06-06 13:58:12 +0200 | [diff] [blame] | 81 | "page-faults", |
| 82 | "context-switches", |
| 83 | "CPU-migrations", |
| 84 | "minor-faults", |
| 85 | "major-faults", |
Anton Blanchard | f7d7986 | 2009-10-18 01:09:29 +0000 | [diff] [blame] | 86 | "alignment-faults", |
| 87 | "emulation-faults", |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 88 | }; |
| 89 | |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 90 | #define MAX_ALIASES 8 |
| 91 | |
Jiri Olsa | 0111919 | 2011-07-13 22:58:18 +0200 | [diff] [blame] | 92 | static const char *hw_cache[PERF_COUNT_HW_CACHE_MAX][MAX_ALIASES] = { |
Anton Blanchard | 9590b7b | 2009-07-06 22:01:31 +1000 | [diff] [blame] | 93 | { "L1-dcache", "l1-d", "l1d", "L1-data", }, |
| 94 | { "L1-icache", "l1-i", "l1i", "L1-instruction", }, |
Jiri Olsa | 0111919 | 2011-07-13 22:58:18 +0200 | [diff] [blame] | 95 | { "LLC", "L2", }, |
Jaswinder Singh Rajput | e5c5954 | 2009-06-25 18:25:22 +0530 | [diff] [blame] | 96 | { "dTLB", "d-tlb", "Data-TLB", }, |
| 97 | { "iTLB", "i-tlb", "Instruction-TLB", }, |
| 98 | { "branch", "branches", "bpu", "btb", "bpc", }, |
Jiri Olsa | 0111919 | 2011-07-13 22:58:18 +0200 | [diff] [blame] | 99 | { "node", }, |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 100 | }; |
| 101 | |
Jiri Olsa | 0111919 | 2011-07-13 22:58:18 +0200 | [diff] [blame] | 102 | static const char *hw_cache_op[PERF_COUNT_HW_CACHE_OP_MAX][MAX_ALIASES] = { |
Jaswinder Singh Rajput | e5c5954 | 2009-06-25 18:25:22 +0530 | [diff] [blame] | 103 | { "load", "loads", "read", }, |
| 104 | { "store", "stores", "write", }, |
| 105 | { "prefetch", "prefetches", "speculative-read", "speculative-load", }, |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 106 | }; |
| 107 | |
Jiri Olsa | 0111919 | 2011-07-13 22:58:18 +0200 | [diff] [blame] | 108 | static const char *hw_cache_result[PERF_COUNT_HW_CACHE_RESULT_MAX] |
| 109 | [MAX_ALIASES] = { |
Jaswinder Singh Rajput | e5c5954 | 2009-06-25 18:25:22 +0530 | [diff] [blame] | 110 | { "refs", "Reference", "ops", "access", }, |
| 111 | { "misses", "miss", }, |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 112 | }; |
| 113 | |
Jaswinder Singh Rajput | 06813f6 | 2009-06-25 17:16:07 +0530 | [diff] [blame] | 114 | #define C(x) PERF_COUNT_HW_CACHE_##x |
| 115 | #define CACHE_READ (1 << C(OP_READ)) |
| 116 | #define CACHE_WRITE (1 << C(OP_WRITE)) |
| 117 | #define CACHE_PREFETCH (1 << C(OP_PREFETCH)) |
| 118 | #define COP(x) (1 << x) |
| 119 | |
| 120 | /* |
| 121 | * cache operartion stat |
| 122 | * L1I : Read and prefetch only |
| 123 | * ITLB and BPU : Read-only |
| 124 | */ |
| 125 | static unsigned long hw_cache_stat[C(MAX)] = { |
| 126 | [C(L1D)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), |
| 127 | [C(L1I)] = (CACHE_READ | CACHE_PREFETCH), |
| 128 | [C(LL)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), |
| 129 | [C(DTLB)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), |
| 130 | [C(ITLB)] = (CACHE_READ), |
| 131 | [C(BPU)] = (CACHE_READ), |
Jiri Olsa | 0111919 | 2011-07-13 22:58:18 +0200 | [diff] [blame] | 132 | [C(NODE)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), |
Jaswinder Singh Rajput | 06813f6 | 2009-06-25 17:16:07 +0530 | [diff] [blame] | 133 | }; |
| 134 | |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 135 | #define for_each_subsystem(sys_dir, sys_dirent, sys_next) \ |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 136 | while (!readdir_r(sys_dir, &sys_dirent, &sys_next) && sys_next) \ |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 137 | if (sys_dirent.d_type == DT_DIR && \ |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 138 | (strcmp(sys_dirent.d_name, ".")) && \ |
| 139 | (strcmp(sys_dirent.d_name, ".."))) |
| 140 | |
Peter Zijlstra | ae07b63 | 2009-08-06 16:48:54 +0200 | [diff] [blame] | 141 | static int tp_event_has_id(struct dirent *sys_dir, struct dirent *evt_dir) |
| 142 | { |
| 143 | char evt_path[MAXPATHLEN]; |
| 144 | int fd; |
| 145 | |
Arnaldo Carvalho de Melo | ebf294b | 2011-11-16 14:03:07 -0200 | [diff] [blame] | 146 | snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", tracing_events_path, |
Peter Zijlstra | ae07b63 | 2009-08-06 16:48:54 +0200 | [diff] [blame] | 147 | sys_dir->d_name, evt_dir->d_name); |
| 148 | fd = open(evt_path, O_RDONLY); |
| 149 | if (fd < 0) |
| 150 | return -EINVAL; |
| 151 | close(fd); |
| 152 | |
| 153 | return 0; |
| 154 | } |
| 155 | |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 156 | #define for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) \ |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 157 | while (!readdir_r(evt_dir, &evt_dirent, &evt_next) && evt_next) \ |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 158 | if (evt_dirent.d_type == DT_DIR && \ |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 159 | (strcmp(evt_dirent.d_name, ".")) && \ |
Peter Zijlstra | ae07b63 | 2009-08-06 16:48:54 +0200 | [diff] [blame] | 160 | (strcmp(evt_dirent.d_name, "..")) && \ |
| 161 | (!tp_event_has_id(&sys_dirent, &evt_dirent))) |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 162 | |
Li Zefan | 270bbbe | 2009-09-17 16:34:51 +0800 | [diff] [blame] | 163 | #define MAX_EVENT_LENGTH 512 |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 164 | |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 165 | |
Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 166 | struct tracepoint_path *tracepoint_id_to_path(u64 config) |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 167 | { |
Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 168 | struct tracepoint_path *path = NULL; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 169 | DIR *sys_dir, *evt_dir; |
| 170 | struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; |
Stephane Eranian | 8aa8a7c | 2012-03-13 16:51:02 +0100 | [diff] [blame] | 171 | char id_buf[24]; |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 172 | int fd; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 173 | u64 id; |
| 174 | char evt_path[MAXPATHLEN]; |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 175 | char dir_path[MAXPATHLEN]; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 176 | |
Arnaldo Carvalho de Melo | ebf294b | 2011-11-16 14:03:07 -0200 | [diff] [blame] | 177 | if (debugfs_valid_mountpoint(tracing_events_path)) |
Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 178 | return NULL; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 179 | |
Arnaldo Carvalho de Melo | ebf294b | 2011-11-16 14:03:07 -0200 | [diff] [blame] | 180 | sys_dir = opendir(tracing_events_path); |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 181 | if (!sys_dir) |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 182 | return NULL; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 183 | |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 184 | for_each_subsystem(sys_dir, sys_dirent, sys_next) { |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 185 | |
Arnaldo Carvalho de Melo | ebf294b | 2011-11-16 14:03:07 -0200 | [diff] [blame] | 186 | snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path, |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 187 | sys_dirent.d_name); |
| 188 | evt_dir = opendir(dir_path); |
| 189 | if (!evt_dir) |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 190 | continue; |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 191 | |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 192 | for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 193 | |
| 194 | snprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path, |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 195 | evt_dirent.d_name); |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 196 | fd = open(evt_path, O_RDONLY); |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 197 | if (fd < 0) |
| 198 | continue; |
| 199 | if (read(fd, id_buf, sizeof(id_buf)) < 0) { |
| 200 | close(fd); |
| 201 | continue; |
| 202 | } |
| 203 | close(fd); |
| 204 | id = atoll(id_buf); |
| 205 | if (id == config) { |
| 206 | closedir(evt_dir); |
| 207 | closedir(sys_dir); |
Julia Lawall | 59b4cae | 2009-12-06 10:16:30 +0100 | [diff] [blame] | 208 | path = zalloc(sizeof(*path)); |
Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 209 | path->system = malloc(MAX_EVENT_LENGTH); |
| 210 | if (!path->system) { |
| 211 | free(path); |
| 212 | return NULL; |
| 213 | } |
| 214 | path->name = malloc(MAX_EVENT_LENGTH); |
| 215 | if (!path->name) { |
| 216 | free(path->system); |
| 217 | free(path); |
| 218 | return NULL; |
| 219 | } |
| 220 | strncpy(path->system, sys_dirent.d_name, |
| 221 | MAX_EVENT_LENGTH); |
| 222 | strncpy(path->name, evt_dirent.d_name, |
| 223 | MAX_EVENT_LENGTH); |
| 224 | return path; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | closedir(evt_dir); |
| 228 | } |
| 229 | |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 230 | closedir(sys_dir); |
Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 231 | return NULL; |
| 232 | } |
| 233 | |
| 234 | #define TP_PATH_LEN (MAX_EVENT_LENGTH * 2 + 1) |
| 235 | static const char *tracepoint_id_to_name(u64 config) |
| 236 | { |
| 237 | static char buf[TP_PATH_LEN]; |
| 238 | struct tracepoint_path *path; |
| 239 | |
| 240 | path = tracepoint_id_to_path(config); |
| 241 | if (path) { |
| 242 | snprintf(buf, TP_PATH_LEN, "%s:%s", path->system, path->name); |
| 243 | free(path->name); |
| 244 | free(path->system); |
| 245 | free(path); |
| 246 | } else |
| 247 | snprintf(buf, TP_PATH_LEN, "%s:%s", "unknown", "unknown"); |
| 248 | |
| 249 | return buf; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 250 | } |
| 251 | |
Jaswinder Singh Rajput | 06813f6 | 2009-06-25 17:16:07 +0530 | [diff] [blame] | 252 | static int is_cache_op_valid(u8 cache_type, u8 cache_op) |
| 253 | { |
| 254 | if (hw_cache_stat[cache_type] & COP(cache_op)) |
| 255 | return 1; /* valid */ |
| 256 | else |
| 257 | return 0; /* invalid */ |
| 258 | } |
| 259 | |
Jaswinder Singh Rajput | e5c5954 | 2009-06-25 18:25:22 +0530 | [diff] [blame] | 260 | static char *event_cache_name(u8 cache_type, u8 cache_op, u8 cache_result) |
| 261 | { |
| 262 | static char name[50]; |
| 263 | |
| 264 | if (cache_result) { |
| 265 | sprintf(name, "%s-%s-%s", hw_cache[cache_type][0], |
| 266 | hw_cache_op[cache_op][0], |
| 267 | hw_cache_result[cache_result][0]); |
| 268 | } else { |
| 269 | sprintf(name, "%s-%s", hw_cache[cache_type][0], |
| 270 | hw_cache_op[cache_op][1]); |
| 271 | } |
| 272 | |
| 273 | return name; |
| 274 | } |
| 275 | |
David Ahern | 1424dc9 | 2011-03-09 22:23:28 -0700 | [diff] [blame] | 276 | const char *event_type(int type) |
| 277 | { |
| 278 | switch (type) { |
| 279 | case PERF_TYPE_HARDWARE: |
| 280 | return "hardware"; |
| 281 | |
| 282 | case PERF_TYPE_SOFTWARE: |
| 283 | return "software"; |
| 284 | |
| 285 | case PERF_TYPE_TRACEPOINT: |
| 286 | return "tracepoint"; |
| 287 | |
| 288 | case PERF_TYPE_HW_CACHE: |
| 289 | return "hardware-cache"; |
| 290 | |
| 291 | default: |
| 292 | break; |
| 293 | } |
| 294 | |
| 295 | return "unknown"; |
| 296 | } |
| 297 | |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 298 | const char *event_name(struct perf_evsel *evsel) |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 299 | { |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 300 | u64 config = evsel->attr.config; |
| 301 | int type = evsel->attr.type; |
Peter Zijlstra | 8f18aec | 2009-08-06 19:40:28 +0200 | [diff] [blame] | 302 | |
Stephane Eranian | f0c55bc | 2011-02-16 15:10:01 +0200 | [diff] [blame] | 303 | if (evsel->name) |
| 304 | return evsel->name; |
| 305 | |
Peter Zijlstra | 8f18aec | 2009-08-06 19:40:28 +0200 | [diff] [blame] | 306 | return __event_name(type, config); |
| 307 | } |
| 308 | |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 309 | const char *__event_name(int type, u64 config) |
Peter Zijlstra | 8f18aec | 2009-08-06 19:40:28 +0200 | [diff] [blame] | 310 | { |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 311 | static char buf[32]; |
| 312 | |
Peter Zijlstra | 8f18aec | 2009-08-06 19:40:28 +0200 | [diff] [blame] | 313 | if (type == PERF_TYPE_RAW) { |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 314 | sprintf(buf, "raw 0x%" PRIx64, config); |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 315 | return buf; |
| 316 | } |
| 317 | |
| 318 | switch (type) { |
| 319 | case PERF_TYPE_HARDWARE: |
Ingo Molnar | 1fc570a | 2011-04-27 05:20:22 +0200 | [diff] [blame] | 320 | if (config < PERF_COUNT_HW_MAX && hw_event_names[config]) |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 321 | return hw_event_names[config]; |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 322 | return "unknown-hardware"; |
| 323 | |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 324 | case PERF_TYPE_HW_CACHE: { |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 325 | u8 cache_type, cache_op, cache_result; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 326 | |
| 327 | cache_type = (config >> 0) & 0xff; |
| 328 | if (cache_type > PERF_COUNT_HW_CACHE_MAX) |
| 329 | return "unknown-ext-hardware-cache-type"; |
| 330 | |
| 331 | cache_op = (config >> 8) & 0xff; |
Ingo Molnar | 8faf3b5 | 2009-06-06 13:58:12 +0200 | [diff] [blame] | 332 | if (cache_op > PERF_COUNT_HW_CACHE_OP_MAX) |
| 333 | return "unknown-ext-hardware-cache-op"; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 334 | |
| 335 | cache_result = (config >> 16) & 0xff; |
Ingo Molnar | 8faf3b5 | 2009-06-06 13:58:12 +0200 | [diff] [blame] | 336 | if (cache_result > PERF_COUNT_HW_CACHE_RESULT_MAX) |
| 337 | return "unknown-ext-hardware-cache-result"; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 338 | |
Jaswinder Singh Rajput | 06813f6 | 2009-06-25 17:16:07 +0530 | [diff] [blame] | 339 | if (!is_cache_op_valid(cache_type, cache_op)) |
| 340 | return "invalid-cache"; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 341 | |
Jaswinder Singh Rajput | e5c5954 | 2009-06-25 18:25:22 +0530 | [diff] [blame] | 342 | return event_cache_name(cache_type, cache_op, cache_result); |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 343 | } |
| 344 | |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 345 | case PERF_TYPE_SOFTWARE: |
Ingo Molnar | 1fc570a | 2011-04-27 05:20:22 +0200 | [diff] [blame] | 346 | if (config < PERF_COUNT_SW_MAX && sw_event_names[config]) |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 347 | return sw_event_names[config]; |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 348 | return "unknown-software"; |
| 349 | |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 350 | case PERF_TYPE_TRACEPOINT: |
| 351 | return tracepoint_id_to_name(config); |
| 352 | |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 353 | default: |
| 354 | break; |
| 355 | } |
| 356 | |
| 357 | return "unknown"; |
| 358 | } |
| 359 | |
Jiri Olsa | b847cbd | 2012-05-21 09:12:51 +0200 | [diff] [blame^] | 360 | static int add_event(struct list_head **_list, int *idx, |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 361 | struct perf_event_attr *attr, char *name) |
| 362 | { |
| 363 | struct perf_evsel *evsel; |
Jiri Olsa | b847cbd | 2012-05-21 09:12:51 +0200 | [diff] [blame^] | 364 | struct list_head *list = *_list; |
| 365 | |
| 366 | if (!list) { |
| 367 | list = malloc(sizeof(*list)); |
| 368 | if (!list) |
| 369 | return -ENOMEM; |
| 370 | INIT_LIST_HEAD(list); |
| 371 | } |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 372 | |
| 373 | event_attr_init(attr); |
| 374 | |
| 375 | evsel = perf_evsel__new(attr, (*idx)++); |
Jiri Olsa | b847cbd | 2012-05-21 09:12:51 +0200 | [diff] [blame^] | 376 | if (!evsel) { |
| 377 | free(list); |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 378 | return -ENOMEM; |
Jiri Olsa | b847cbd | 2012-05-21 09:12:51 +0200 | [diff] [blame^] | 379 | } |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 380 | |
| 381 | evsel->name = strdup(name); |
Jiri Olsa | b847cbd | 2012-05-21 09:12:51 +0200 | [diff] [blame^] | 382 | list_add_tail(&evsel->node, list); |
| 383 | *_list = list; |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 384 | return 0; |
| 385 | } |
| 386 | |
| 387 | static int parse_aliases(char *str, const char *names[][MAX_ALIASES], int size) |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 388 | { |
| 389 | int i, j; |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 390 | int n, longest = -1; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 391 | |
| 392 | for (i = 0; i < size; i++) { |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 393 | for (j = 0; j < MAX_ALIASES && names[i][j]; j++) { |
| 394 | n = strlen(names[i][j]); |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 395 | if (n > longest && !strncasecmp(str, names[i][j], n)) |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 396 | longest = n; |
| 397 | } |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 398 | if (longest > 0) |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 399 | return i; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 400 | } |
| 401 | |
Ingo Molnar | 8953645 | 2009-06-06 21:04:17 +0200 | [diff] [blame] | 402 | return -1; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 403 | } |
| 404 | |
Jiri Olsa | b847cbd | 2012-05-21 09:12:51 +0200 | [diff] [blame^] | 405 | int parse_events_add_cache(struct list_head **list, int *idx, |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 406 | char *type, char *op_result1, char *op_result2) |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 407 | { |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 408 | struct perf_event_attr attr; |
| 409 | char name[MAX_NAME_LEN]; |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 410 | int cache_type = -1, cache_op = -1, cache_result = -1; |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 411 | char *op_result[2] = { op_result1, op_result2 }; |
| 412 | int i, n; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 413 | |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 414 | /* |
| 415 | * No fallback - if we cannot get a clear cache type |
| 416 | * then bail out: |
| 417 | */ |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 418 | cache_type = parse_aliases(type, hw_cache, |
| 419 | PERF_COUNT_HW_CACHE_MAX); |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 420 | if (cache_type == -1) |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 421 | return -EINVAL; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 422 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 423 | n = snprintf(name, MAX_NAME_LEN, "%s", type); |
| 424 | |
| 425 | for (i = 0; (i < 2) && (op_result[i]); i++) { |
| 426 | char *str = op_result[i]; |
| 427 | |
| 428 | snprintf(name + n, MAX_NAME_LEN - n, "-%s\n", str); |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 429 | |
| 430 | if (cache_op == -1) { |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 431 | cache_op = parse_aliases(str, hw_cache_op, |
| 432 | PERF_COUNT_HW_CACHE_OP_MAX); |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 433 | if (cache_op >= 0) { |
| 434 | if (!is_cache_op_valid(cache_type, cache_op)) |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 435 | return -EINVAL; |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 436 | continue; |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | if (cache_result == -1) { |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 441 | cache_result = parse_aliases(str, hw_cache_result, |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 442 | PERF_COUNT_HW_CACHE_RESULT_MAX); |
| 443 | if (cache_result >= 0) |
| 444 | continue; |
| 445 | } |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 446 | } |
| 447 | |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 448 | /* |
| 449 | * Fall back to reads: |
| 450 | */ |
Ingo Molnar | 8953645 | 2009-06-06 21:04:17 +0200 | [diff] [blame] | 451 | if (cache_op == -1) |
| 452 | cache_op = PERF_COUNT_HW_CACHE_OP_READ; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 453 | |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 454 | /* |
| 455 | * Fall back to accesses: |
| 456 | */ |
| 457 | if (cache_result == -1) |
| 458 | cache_result = PERF_COUNT_HW_CACHE_RESULT_ACCESS; |
| 459 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 460 | memset(&attr, 0, sizeof(attr)); |
| 461 | attr.config = cache_type | (cache_op << 8) | (cache_result << 16); |
| 462 | attr.type = PERF_TYPE_HW_CACHE; |
| 463 | return add_event(list, idx, &attr, name); |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 464 | } |
| 465 | |
Jiri Olsa | b847cbd | 2012-05-21 09:12:51 +0200 | [diff] [blame^] | 466 | static int add_tracepoint(struct list_head **list, int *idx, |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 467 | char *sys_name, char *evt_name) |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 468 | { |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 469 | struct perf_event_attr attr; |
| 470 | char name[MAX_NAME_LEN]; |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 471 | char evt_path[MAXPATHLEN]; |
| 472 | char id_buf[4]; |
| 473 | u64 id; |
| 474 | int fd; |
| 475 | |
Arnaldo Carvalho de Melo | ebf294b | 2011-11-16 14:03:07 -0200 | [diff] [blame] | 476 | snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", tracing_events_path, |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 477 | sys_name, evt_name); |
| 478 | |
| 479 | fd = open(evt_path, O_RDONLY); |
| 480 | if (fd < 0) |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 481 | return -1; |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 482 | |
| 483 | if (read(fd, id_buf, sizeof(id_buf)) < 0) { |
| 484 | close(fd); |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 485 | return -1; |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | close(fd); |
| 489 | id = atoll(id_buf); |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 490 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 491 | memset(&attr, 0, sizeof(attr)); |
| 492 | attr.config = id; |
| 493 | attr.type = PERF_TYPE_TRACEPOINT; |
| 494 | attr.sample_type |= PERF_SAMPLE_RAW; |
| 495 | attr.sample_type |= PERF_SAMPLE_TIME; |
| 496 | attr.sample_type |= PERF_SAMPLE_CPU; |
| 497 | attr.sample_period = 1; |
Stephane Eranian | 5710fca | 2010-04-21 18:06:01 +0200 | [diff] [blame] | 498 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 499 | snprintf(name, MAX_NAME_LEN, "%s:%s", sys_name, evt_name); |
| 500 | return add_event(list, idx, &attr, name); |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 501 | } |
| 502 | |
Jiri Olsa | b847cbd | 2012-05-21 09:12:51 +0200 | [diff] [blame^] | 503 | static int add_tracepoint_multi(struct list_head **list, int *idx, |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 504 | char *sys_name, char *evt_name) |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 505 | { |
| 506 | char evt_path[MAXPATHLEN]; |
| 507 | struct dirent *evt_ent; |
| 508 | DIR *evt_dir; |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 509 | int ret = 0; |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 510 | |
Arnaldo Carvalho de Melo | ebf294b | 2011-11-16 14:03:07 -0200 | [diff] [blame] | 511 | snprintf(evt_path, MAXPATHLEN, "%s/%s", tracing_events_path, sys_name); |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 512 | evt_dir = opendir(evt_path); |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 513 | if (!evt_dir) { |
| 514 | perror("Can't open event dir"); |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 515 | return -1; |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 516 | } |
| 517 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 518 | while (!ret && (evt_ent = readdir(evt_dir))) { |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 519 | if (!strcmp(evt_ent->d_name, ".") |
| 520 | || !strcmp(evt_ent->d_name, "..") |
| 521 | || !strcmp(evt_ent->d_name, "enable") |
| 522 | || !strcmp(evt_ent->d_name, "filter")) |
| 523 | continue; |
| 524 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 525 | if (!strglobmatch(evt_ent->d_name, evt_name)) |
Masami Hiramatsu | fb1d2ed | 2010-01-05 17:47:17 -0500 | [diff] [blame] | 526 | continue; |
| 527 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 528 | ret = add_tracepoint(list, idx, sys_name, evt_ent->d_name); |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 529 | } |
| 530 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 531 | return ret; |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 532 | } |
| 533 | |
Jiri Olsa | b847cbd | 2012-05-21 09:12:51 +0200 | [diff] [blame^] | 534 | int parse_events_add_tracepoint(struct list_head **list, int *idx, |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 535 | char *sys, char *event) |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 536 | { |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 537 | int ret; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 538 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 539 | ret = debugfs_valid_mountpoint(tracing_events_path); |
| 540 | if (ret) |
| 541 | return ret; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 542 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 543 | return strpbrk(event, "*?") ? |
| 544 | add_tracepoint_multi(list, idx, sys, event) : |
| 545 | add_tracepoint(list, idx, sys, event); |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 546 | } |
| 547 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 548 | static int |
| 549 | parse_breakpoint_type(const char *type, struct perf_event_attr *attr) |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 550 | { |
| 551 | int i; |
| 552 | |
| 553 | for (i = 0; i < 3; i++) { |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 554 | if (!type || !type[i]) |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 555 | break; |
| 556 | |
| 557 | switch (type[i]) { |
| 558 | case 'r': |
| 559 | attr->bp_type |= HW_BREAKPOINT_R; |
| 560 | break; |
| 561 | case 'w': |
| 562 | attr->bp_type |= HW_BREAKPOINT_W; |
| 563 | break; |
| 564 | case 'x': |
| 565 | attr->bp_type |= HW_BREAKPOINT_X; |
| 566 | break; |
| 567 | default: |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 568 | return -EINVAL; |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 569 | } |
| 570 | } |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 571 | |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 572 | if (!attr->bp_type) /* Default */ |
| 573 | attr->bp_type = HW_BREAKPOINT_R | HW_BREAKPOINT_W; |
| 574 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 575 | return 0; |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 576 | } |
| 577 | |
Jiri Olsa | b847cbd | 2012-05-21 09:12:51 +0200 | [diff] [blame^] | 578 | int parse_events_add_breakpoint(struct list_head **list, int *idx, |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 579 | void *ptr, char *type) |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 580 | { |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 581 | struct perf_event_attr attr; |
| 582 | char name[MAX_NAME_LEN]; |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 583 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 584 | memset(&attr, 0, sizeof(attr)); |
Jiri Olsa | 9fafd98 | 2012-03-20 19:15:39 +0100 | [diff] [blame] | 585 | attr.bp_addr = (unsigned long) ptr; |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 586 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 587 | if (parse_breakpoint_type(type, &attr)) |
| 588 | return -EINVAL; |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 589 | |
Frederic Weisbecker | aa59a48 | 2010-06-24 21:36:19 +0200 | [diff] [blame] | 590 | /* |
| 591 | * We should find a nice way to override the access length |
| 592 | * Provide some defaults for now |
| 593 | */ |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 594 | if (attr.bp_type == HW_BREAKPOINT_X) |
| 595 | attr.bp_len = sizeof(long); |
Frederic Weisbecker | aa59a48 | 2010-06-24 21:36:19 +0200 | [diff] [blame] | 596 | else |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 597 | attr.bp_len = HW_BREAKPOINT_LEN_4; |
Frederic Weisbecker | aa59a48 | 2010-06-24 21:36:19 +0200 | [diff] [blame] | 598 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 599 | attr.type = PERF_TYPE_BREAKPOINT; |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 600 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 601 | snprintf(name, MAX_NAME_LEN, "mem:%p:%s", ptr, type ? type : "rw"); |
| 602 | return add_event(list, idx, &attr, name); |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 603 | } |
| 604 | |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 605 | static int config_term(struct perf_event_attr *attr, |
| 606 | struct parse_events__term *term) |
| 607 | { |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 608 | #define CHECK_TYPE_VAL(type) \ |
| 609 | do { \ |
| 610 | if (PARSE_EVENTS__TERM_TYPE_ ## type != term->type_val) \ |
| 611 | return -EINVAL; \ |
| 612 | } while (0) |
| 613 | |
| 614 | switch (term->type_term) { |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 615 | case PARSE_EVENTS__TERM_TYPE_CONFIG: |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 616 | CHECK_TYPE_VAL(NUM); |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 617 | attr->config = term->val.num; |
| 618 | break; |
| 619 | case PARSE_EVENTS__TERM_TYPE_CONFIG1: |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 620 | CHECK_TYPE_VAL(NUM); |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 621 | attr->config1 = term->val.num; |
| 622 | break; |
| 623 | case PARSE_EVENTS__TERM_TYPE_CONFIG2: |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 624 | CHECK_TYPE_VAL(NUM); |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 625 | attr->config2 = term->val.num; |
| 626 | break; |
| 627 | case PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD: |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 628 | CHECK_TYPE_VAL(NUM); |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 629 | attr->sample_period = term->val.num; |
| 630 | break; |
| 631 | case PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE: |
| 632 | /* |
| 633 | * TODO uncomment when the field is available |
| 634 | * attr->branch_sample_type = term->val.num; |
| 635 | */ |
| 636 | break; |
| 637 | default: |
| 638 | return -EINVAL; |
| 639 | } |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 640 | |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 641 | return 0; |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 642 | #undef CHECK_TYPE_VAL |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | static int config_attr(struct perf_event_attr *attr, |
| 646 | struct list_head *head, int fail) |
| 647 | { |
| 648 | struct parse_events__term *term; |
| 649 | |
| 650 | list_for_each_entry(term, head, list) |
| 651 | if (config_term(attr, term) && fail) |
| 652 | return -EINVAL; |
| 653 | |
| 654 | return 0; |
| 655 | } |
| 656 | |
Jiri Olsa | b847cbd | 2012-05-21 09:12:51 +0200 | [diff] [blame^] | 657 | int parse_events_add_numeric(struct list_head **list, int *idx, |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 658 | unsigned long type, unsigned long config, |
| 659 | struct list_head *head_config) |
Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 660 | { |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 661 | struct perf_event_attr attr; |
Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 662 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 663 | memset(&attr, 0, sizeof(attr)); |
| 664 | attr.type = type; |
| 665 | attr.config = config; |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 666 | |
| 667 | if (head_config && |
| 668 | config_attr(&attr, head_config, 1)) |
| 669 | return -EINVAL; |
| 670 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 671 | return add_event(list, idx, &attr, |
| 672 | (char *) __event_name(type, config)); |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 673 | } |
| 674 | |
Jiri Olsa | b847cbd | 2012-05-21 09:12:51 +0200 | [diff] [blame^] | 675 | int parse_events_add_pmu(struct list_head **list, int *idx, |
Jiri Olsa | 5f537a2 | 2012-03-15 20:09:18 +0100 | [diff] [blame] | 676 | char *name, struct list_head *head_config) |
| 677 | { |
| 678 | struct perf_event_attr attr; |
| 679 | struct perf_pmu *pmu; |
| 680 | |
| 681 | pmu = perf_pmu__find(name); |
| 682 | if (!pmu) |
| 683 | return -EINVAL; |
| 684 | |
| 685 | memset(&attr, 0, sizeof(attr)); |
| 686 | |
| 687 | /* |
| 688 | * Configure hardcoded terms first, no need to check |
| 689 | * return value when called with fail == 0 ;) |
| 690 | */ |
| 691 | config_attr(&attr, head_config, 0); |
| 692 | |
| 693 | if (perf_pmu__config(pmu, &attr, head_config)) |
| 694 | return -EINVAL; |
| 695 | |
| 696 | return add_event(list, idx, &attr, (char *) "pmu"); |
| 697 | } |
| 698 | |
Jiri Olsa | 5d7be90 | 2012-03-20 19:15:40 +0100 | [diff] [blame] | 699 | void parse_events_update_lists(struct list_head *list_event, |
| 700 | struct list_head *list_all) |
| 701 | { |
| 702 | /* |
| 703 | * Called for single event definition. Update the |
| 704 | * 'all event' list, and reinit the 'signle event' |
| 705 | * list, for next event definition. |
| 706 | */ |
| 707 | list_splice_tail(list_event, list_all); |
Jiri Olsa | b847cbd | 2012-05-21 09:12:51 +0200 | [diff] [blame^] | 708 | free(list_event); |
Jiri Olsa | 5d7be90 | 2012-03-20 19:15:40 +0100 | [diff] [blame] | 709 | } |
| 710 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 711 | int parse_events_modifier(struct list_head *list, char *str) |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 712 | { |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 713 | struct perf_evsel *evsel; |
Joerg Roedel | 99320cc | 2012-01-04 17:54:19 +0100 | [diff] [blame] | 714 | int exclude = 0, exclude_GH = 0; |
| 715 | int eu = 0, ek = 0, eh = 0, eH = 0, eG = 0, precise = 0; |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 716 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 717 | if (str == NULL) |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 718 | return 0; |
Ingo Molnar | ceb53fb | 2011-04-27 04:06:33 +0200 | [diff] [blame] | 719 | |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 720 | while (*str) { |
Peter Zijlstra | ab60834 | 2010-04-08 23:03:20 +0200 | [diff] [blame] | 721 | if (*str == 'u') { |
| 722 | if (!exclude) |
| 723 | exclude = eu = ek = eh = 1; |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 724 | eu = 0; |
Peter Zijlstra | ab60834 | 2010-04-08 23:03:20 +0200 | [diff] [blame] | 725 | } else if (*str == 'k') { |
| 726 | if (!exclude) |
| 727 | exclude = eu = ek = eh = 1; |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 728 | ek = 0; |
Peter Zijlstra | ab60834 | 2010-04-08 23:03:20 +0200 | [diff] [blame] | 729 | } else if (*str == 'h') { |
| 730 | if (!exclude) |
| 731 | exclude = eu = ek = eh = 1; |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 732 | eh = 0; |
Joerg Roedel | 99320cc | 2012-01-04 17:54:19 +0100 | [diff] [blame] | 733 | } else if (*str == 'G') { |
| 734 | if (!exclude_GH) |
| 735 | exclude_GH = eG = eH = 1; |
| 736 | eG = 0; |
| 737 | } else if (*str == 'H') { |
| 738 | if (!exclude_GH) |
| 739 | exclude_GH = eG = eH = 1; |
| 740 | eH = 0; |
Peter Zijlstra | ab60834 | 2010-04-08 23:03:20 +0200 | [diff] [blame] | 741 | } else if (*str == 'p') { |
| 742 | precise++; |
| 743 | } else |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 744 | break; |
Peter Zijlstra | ab60834 | 2010-04-08 23:03:20 +0200 | [diff] [blame] | 745 | |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 746 | ++str; |
| 747 | } |
Ingo Molnar | ceb53fb | 2011-04-27 04:06:33 +0200 | [diff] [blame] | 748 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 749 | /* |
| 750 | * precise ip: |
| 751 | * |
| 752 | * 0 - SAMPLE_IP can have arbitrary skid |
| 753 | * 1 - SAMPLE_IP must have constant skid |
| 754 | * 2 - SAMPLE_IP requested to have 0 skid |
| 755 | * 3 - SAMPLE_IP must have 0 skid |
| 756 | * |
| 757 | * See also PERF_RECORD_MISC_EXACT_IP |
| 758 | */ |
| 759 | if (precise > 3) |
| 760 | return -EINVAL; |
Ingo Molnar | ceb53fb | 2011-04-27 04:06:33 +0200 | [diff] [blame] | 761 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 762 | list_for_each_entry(evsel, list, node) { |
| 763 | evsel->attr.exclude_user = eu; |
| 764 | evsel->attr.exclude_kernel = ek; |
| 765 | evsel->attr.exclude_hv = eh; |
| 766 | evsel->attr.precise_ip = precise; |
| 767 | evsel->attr.exclude_host = eH; |
| 768 | evsel->attr.exclude_guest = eG; |
| 769 | } |
Ingo Molnar | ceb53fb | 2011-04-27 04:06:33 +0200 | [diff] [blame] | 770 | |
Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 771 | return 0; |
| 772 | } |
| 773 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 774 | int parse_events(struct perf_evlist *evlist, const char *str, int unset __used) |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 775 | { |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 776 | LIST_HEAD(list); |
Jiri Olsa | 5d7be90 | 2012-03-20 19:15:40 +0100 | [diff] [blame] | 777 | LIST_HEAD(list_tmp); |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 778 | YY_BUFFER_STATE buffer; |
| 779 | int ret, idx = evlist->nr_entries; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 780 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 781 | buffer = parse_events__scan_string(str); |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 782 | |
Jiri Olsa | 82ba1f2 | 2012-05-21 09:12:50 +0200 | [diff] [blame] | 783 | #ifdef PARSER_DEBUG |
| 784 | parse_events_debug = 1; |
| 785 | #endif |
Jiri Olsa | b847cbd | 2012-05-21 09:12:51 +0200 | [diff] [blame^] | 786 | ret = parse_events_parse(&list, &idx); |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 787 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 788 | parse_events__flush_buffer(buffer); |
| 789 | parse_events__delete_buffer(buffer); |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 790 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 791 | if (!ret) { |
| 792 | int entries = idx - evlist->nr_entries; |
| 793 | perf_evlist__splice_list_tail(evlist, &list, entries); |
| 794 | return 0; |
| 795 | } |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 796 | |
Jiri Olsa | 5d7be90 | 2012-03-20 19:15:40 +0100 | [diff] [blame] | 797 | /* |
| 798 | * There are 2 users - builtin-record and builtin-test objects. |
| 799 | * Both call perf_evlist__delete in case of error, so we dont |
| 800 | * need to bother. |
| 801 | */ |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 802 | fprintf(stderr, "invalid or unsupported event: '%s'\n", str); |
Marti Raudsepp | 85df6f6 | 2009-10-27 00:33:04 +0000 | [diff] [blame] | 803 | fprintf(stderr, "Run 'perf list' for a list of valid events\n"); |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 804 | return ret; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 805 | } |
| 806 | |
Jiri Olsa | f120f9d | 2011-07-14 11:25:32 +0200 | [diff] [blame] | 807 | int parse_events_option(const struct option *opt, const char *str, |
| 808 | int unset __used) |
| 809 | { |
| 810 | struct perf_evlist *evlist = *(struct perf_evlist **)opt->value; |
| 811 | return parse_events(evlist, str, unset); |
| 812 | } |
| 813 | |
Arnaldo Carvalho de Melo | 361c99a | 2011-01-11 20:56:53 -0200 | [diff] [blame] | 814 | int parse_filter(const struct option *opt, const char *str, |
Li Zefan | c171b55 | 2009-10-15 11:22:07 +0800 | [diff] [blame] | 815 | int unset __used) |
| 816 | { |
Arnaldo Carvalho de Melo | 361c99a | 2011-01-11 20:56:53 -0200 | [diff] [blame] | 817 | struct perf_evlist *evlist = *(struct perf_evlist **)opt->value; |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 818 | struct perf_evsel *last = NULL; |
Li Zefan | c171b55 | 2009-10-15 11:22:07 +0800 | [diff] [blame] | 819 | |
Arnaldo Carvalho de Melo | 361c99a | 2011-01-11 20:56:53 -0200 | [diff] [blame] | 820 | if (evlist->nr_entries > 0) |
| 821 | last = list_entry(evlist->entries.prev, struct perf_evsel, node); |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 822 | |
| 823 | if (last == NULL || last->attr.type != PERF_TYPE_TRACEPOINT) { |
Li Zefan | c171b55 | 2009-10-15 11:22:07 +0800 | [diff] [blame] | 824 | fprintf(stderr, |
| 825 | "-F option should follow a -e tracepoint option\n"); |
| 826 | return -1; |
| 827 | } |
| 828 | |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 829 | last->filter = strdup(str); |
| 830 | if (last->filter == NULL) { |
Li Zefan | c171b55 | 2009-10-15 11:22:07 +0800 | [diff] [blame] | 831 | fprintf(stderr, "not enough memory to hold filter string\n"); |
| 832 | return -1; |
| 833 | } |
Li Zefan | c171b55 | 2009-10-15 11:22:07 +0800 | [diff] [blame] | 834 | |
| 835 | return 0; |
| 836 | } |
| 837 | |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 838 | static const char * const event_type_descriptors[] = { |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 839 | "Hardware event", |
| 840 | "Software event", |
| 841 | "Tracepoint event", |
| 842 | "Hardware cache event", |
Liming Wang | 41bdcb2 | 2009-12-29 16:37:07 +0800 | [diff] [blame] | 843 | "Raw hardware event descriptor", |
| 844 | "Hardware breakpoint", |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 845 | }; |
| 846 | |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 847 | /* |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 848 | * Print the events from <debugfs_mount_point>/tracing/events |
| 849 | */ |
| 850 | |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 851 | void print_tracepoint_events(const char *subsys_glob, const char *event_glob) |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 852 | { |
| 853 | DIR *sys_dir, *evt_dir; |
| 854 | struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 855 | char evt_path[MAXPATHLEN]; |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 856 | char dir_path[MAXPATHLEN]; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 857 | |
Arnaldo Carvalho de Melo | ebf294b | 2011-11-16 14:03:07 -0200 | [diff] [blame] | 858 | if (debugfs_valid_mountpoint(tracing_events_path)) |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 859 | return; |
| 860 | |
Arnaldo Carvalho de Melo | ebf294b | 2011-11-16 14:03:07 -0200 | [diff] [blame] | 861 | sys_dir = opendir(tracing_events_path); |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 862 | if (!sys_dir) |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 863 | return; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 864 | |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 865 | for_each_subsystem(sys_dir, sys_dirent, sys_next) { |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 866 | if (subsys_glob != NULL && |
| 867 | !strglobmatch(sys_dirent.d_name, subsys_glob)) |
| 868 | continue; |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 869 | |
Arnaldo Carvalho de Melo | ebf294b | 2011-11-16 14:03:07 -0200 | [diff] [blame] | 870 | snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path, |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 871 | sys_dirent.d_name); |
| 872 | evt_dir = opendir(dir_path); |
| 873 | if (!evt_dir) |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 874 | continue; |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 875 | |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 876 | for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 877 | if (event_glob != NULL && |
| 878 | !strglobmatch(evt_dirent.d_name, event_glob)) |
| 879 | continue; |
| 880 | |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 881 | snprintf(evt_path, MAXPATHLEN, "%s:%s", |
| 882 | sys_dirent.d_name, evt_dirent.d_name); |
Ingo Molnar | 947b4ad | 2011-04-29 22:52:42 +0200 | [diff] [blame] | 883 | printf(" %-50s [%s]\n", evt_path, |
Liming Wang | 41bdcb2 | 2009-12-29 16:37:07 +0800 | [diff] [blame] | 884 | event_type_descriptors[PERF_TYPE_TRACEPOINT]); |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 885 | } |
| 886 | closedir(evt_dir); |
| 887 | } |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 888 | closedir(sys_dir); |
| 889 | } |
| 890 | |
| 891 | /* |
Thomas Renninger | 20c457b | 2011-01-03 17:50:45 +0100 | [diff] [blame] | 892 | * Check whether event is in <debugfs_mount_point>/tracing/events |
| 893 | */ |
| 894 | |
| 895 | int is_valid_tracepoint(const char *event_string) |
| 896 | { |
| 897 | DIR *sys_dir, *evt_dir; |
| 898 | struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; |
| 899 | char evt_path[MAXPATHLEN]; |
| 900 | char dir_path[MAXPATHLEN]; |
| 901 | |
Arnaldo Carvalho de Melo | ebf294b | 2011-11-16 14:03:07 -0200 | [diff] [blame] | 902 | if (debugfs_valid_mountpoint(tracing_events_path)) |
Thomas Renninger | 20c457b | 2011-01-03 17:50:45 +0100 | [diff] [blame] | 903 | return 0; |
| 904 | |
Arnaldo Carvalho de Melo | ebf294b | 2011-11-16 14:03:07 -0200 | [diff] [blame] | 905 | sys_dir = opendir(tracing_events_path); |
Thomas Renninger | 20c457b | 2011-01-03 17:50:45 +0100 | [diff] [blame] | 906 | if (!sys_dir) |
| 907 | return 0; |
| 908 | |
| 909 | for_each_subsystem(sys_dir, sys_dirent, sys_next) { |
| 910 | |
Arnaldo Carvalho de Melo | ebf294b | 2011-11-16 14:03:07 -0200 | [diff] [blame] | 911 | snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path, |
Thomas Renninger | 20c457b | 2011-01-03 17:50:45 +0100 | [diff] [blame] | 912 | sys_dirent.d_name); |
| 913 | evt_dir = opendir(dir_path); |
| 914 | if (!evt_dir) |
| 915 | continue; |
| 916 | |
| 917 | for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { |
| 918 | snprintf(evt_path, MAXPATHLEN, "%s:%s", |
| 919 | sys_dirent.d_name, evt_dirent.d_name); |
| 920 | if (!strcmp(evt_path, event_string)) { |
| 921 | closedir(evt_dir); |
| 922 | closedir(sys_dir); |
| 923 | return 1; |
| 924 | } |
| 925 | } |
| 926 | closedir(evt_dir); |
| 927 | } |
| 928 | closedir(sys_dir); |
| 929 | return 0; |
| 930 | } |
| 931 | |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 932 | void print_events_type(u8 type) |
| 933 | { |
| 934 | struct event_symbol *syms = event_symbols; |
| 935 | unsigned int i; |
| 936 | char name[64]; |
| 937 | |
| 938 | for (i = 0; i < ARRAY_SIZE(event_symbols); i++, syms++) { |
| 939 | if (type != syms->type) |
| 940 | continue; |
| 941 | |
| 942 | if (strlen(syms->alias)) |
| 943 | snprintf(name, sizeof(name), "%s OR %s", |
| 944 | syms->symbol, syms->alias); |
| 945 | else |
| 946 | snprintf(name, sizeof(name), "%s", syms->symbol); |
| 947 | |
Ingo Molnar | 947b4ad | 2011-04-29 22:52:42 +0200 | [diff] [blame] | 948 | printf(" %-50s [%s]\n", name, |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 949 | event_type_descriptors[type]); |
| 950 | } |
| 951 | } |
| 952 | |
| 953 | int print_hwcache_events(const char *event_glob) |
| 954 | { |
| 955 | unsigned int type, op, i, printed = 0; |
| 956 | |
| 957 | for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) { |
| 958 | for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) { |
| 959 | /* skip invalid cache type */ |
| 960 | if (!is_cache_op_valid(type, op)) |
| 961 | continue; |
| 962 | |
| 963 | for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) { |
| 964 | char *name = event_cache_name(type, op, i); |
| 965 | |
Ingo Molnar | 947b4ad | 2011-04-29 22:52:42 +0200 | [diff] [blame] | 966 | if (event_glob != NULL && !strglobmatch(name, event_glob)) |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 967 | continue; |
| 968 | |
Ingo Molnar | 947b4ad | 2011-04-29 22:52:42 +0200 | [diff] [blame] | 969 | printf(" %-50s [%s]\n", name, |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 970 | event_type_descriptors[PERF_TYPE_HW_CACHE]); |
| 971 | ++printed; |
| 972 | } |
| 973 | } |
| 974 | } |
| 975 | |
| 976 | return printed; |
| 977 | } |
| 978 | |
Thomas Renninger | 20c457b | 2011-01-03 17:50:45 +0100 | [diff] [blame] | 979 | /* |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 980 | * Print the help text for the event symbols: |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 981 | */ |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 982 | void print_events(const char *event_glob) |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 983 | { |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 984 | unsigned int i, type, prev_type = -1, printed = 0, ntypes_printed = 0; |
Ingo Molnar | 947b4ad | 2011-04-29 22:52:42 +0200 | [diff] [blame] | 985 | struct event_symbol *syms = event_symbols; |
| 986 | char name[MAX_NAME_LEN]; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 987 | |
Marti Raudsepp | 689d301 | 2009-10-27 00:33:05 +0000 | [diff] [blame] | 988 | printf("\n"); |
| 989 | printf("List of pre-defined events (to be used in -e):\n"); |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 990 | |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 991 | for (i = 0; i < ARRAY_SIZE(event_symbols); i++, syms++) { |
Liming Wang | 41bdcb2 | 2009-12-29 16:37:07 +0800 | [diff] [blame] | 992 | type = syms->type; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 993 | |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 994 | if (type != prev_type && printed) { |
Marti Raudsepp | 689d301 | 2009-10-27 00:33:05 +0000 | [diff] [blame] | 995 | printf("\n"); |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 996 | printed = 0; |
| 997 | ntypes_printed++; |
| 998 | } |
| 999 | |
| 1000 | if (event_glob != NULL && |
| 1001 | !(strglobmatch(syms->symbol, event_glob) || |
| 1002 | (syms->alias && strglobmatch(syms->alias, event_glob)))) |
| 1003 | continue; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 1004 | |
Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 1005 | if (strlen(syms->alias)) |
Ingo Molnar | 947b4ad | 2011-04-29 22:52:42 +0200 | [diff] [blame] | 1006 | snprintf(name, MAX_NAME_LEN, "%s OR %s", syms->symbol, syms->alias); |
Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 1007 | else |
Ingo Molnar | 947b4ad | 2011-04-29 22:52:42 +0200 | [diff] [blame] | 1008 | strncpy(name, syms->symbol, MAX_NAME_LEN); |
| 1009 | printf(" %-50s [%s]\n", name, |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 1010 | event_type_descriptors[type]); |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 1011 | |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 1012 | prev_type = type; |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 1013 | ++printed; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 1014 | } |
| 1015 | |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 1016 | if (ntypes_printed) { |
| 1017 | printed = 0; |
| 1018 | printf("\n"); |
Jaswinder Singh Rajput | 73c24cb | 2009-07-01 18:36:18 +0530 | [diff] [blame] | 1019 | } |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 1020 | print_hwcache_events(event_glob); |
| 1021 | |
| 1022 | if (event_glob != NULL) |
| 1023 | return; |
Jaswinder Singh Rajput | 73c24cb | 2009-07-01 18:36:18 +0530 | [diff] [blame] | 1024 | |
Marti Raudsepp | 689d301 | 2009-10-27 00:33:05 +0000 | [diff] [blame] | 1025 | printf("\n"); |
Ingo Molnar | 947b4ad | 2011-04-29 22:52:42 +0200 | [diff] [blame] | 1026 | printf(" %-50s [%s]\n", |
Jiri Olsa | 5f537a2 | 2012-03-15 20:09:18 +0100 | [diff] [blame] | 1027 | "rNNN", |
Arnaldo Carvalho de Melo | 1cf4a06 | 2010-05-07 14:07:05 -0300 | [diff] [blame] | 1028 | event_type_descriptors[PERF_TYPE_RAW]); |
Jiri Olsa | 5f537a2 | 2012-03-15 20:09:18 +0100 | [diff] [blame] | 1029 | printf(" %-50s [%s]\n", |
| 1030 | "cpu/t1=v1[,t2=v2,t3 ...]/modifier", |
| 1031 | event_type_descriptors[PERF_TYPE_RAW]); |
| 1032 | printf(" (see 'perf list --help' on how to encode it)\n"); |
Marti Raudsepp | 689d301 | 2009-10-27 00:33:05 +0000 | [diff] [blame] | 1033 | printf("\n"); |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 1034 | |
Ingo Molnar | 947b4ad | 2011-04-29 22:52:42 +0200 | [diff] [blame] | 1035 | printf(" %-50s [%s]\n", |
Liming Wang | 41bdcb2 | 2009-12-29 16:37:07 +0800 | [diff] [blame] | 1036 | "mem:<addr>[:access]", |
| 1037 | event_type_descriptors[PERF_TYPE_BREAKPOINT]); |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 1038 | printf("\n"); |
| 1039 | |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 1040 | print_tracepoint_events(NULL, NULL); |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 1041 | } |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1042 | |
| 1043 | int parse_events__is_hardcoded_term(struct parse_events__term *term) |
| 1044 | { |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 1045 | return term->type_term != PARSE_EVENTS__TERM_TYPE_USER; |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1046 | } |
| 1047 | |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 1048 | static int new_term(struct parse_events__term **_term, int type_val, |
| 1049 | int type_term, char *config, |
| 1050 | char *str, long num) |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1051 | { |
| 1052 | struct parse_events__term *term; |
| 1053 | |
| 1054 | term = zalloc(sizeof(*term)); |
| 1055 | if (!term) |
| 1056 | return -ENOMEM; |
| 1057 | |
| 1058 | INIT_LIST_HEAD(&term->list); |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 1059 | term->type_val = type_val; |
| 1060 | term->type_term = type_term; |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1061 | term->config = config; |
| 1062 | |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 1063 | switch (type_val) { |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1064 | case PARSE_EVENTS__TERM_TYPE_NUM: |
| 1065 | term->val.num = num; |
| 1066 | break; |
| 1067 | case PARSE_EVENTS__TERM_TYPE_STR: |
| 1068 | term->val.str = str; |
| 1069 | break; |
| 1070 | default: |
| 1071 | return -EINVAL; |
| 1072 | } |
| 1073 | |
| 1074 | *_term = term; |
| 1075 | return 0; |
| 1076 | } |
| 1077 | |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 1078 | int parse_events__term_num(struct parse_events__term **term, |
| 1079 | int type_term, char *config, long num) |
| 1080 | { |
| 1081 | return new_term(term, PARSE_EVENTS__TERM_TYPE_NUM, type_term, |
| 1082 | config, NULL, num); |
| 1083 | } |
| 1084 | |
| 1085 | int parse_events__term_str(struct parse_events__term **term, |
| 1086 | int type_term, char *config, char *str) |
| 1087 | { |
| 1088 | return new_term(term, PARSE_EVENTS__TERM_TYPE_STR, type_term, |
| 1089 | config, str, 0); |
| 1090 | } |
| 1091 | |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1092 | void parse_events__free_terms(struct list_head *terms) |
| 1093 | { |
| 1094 | struct parse_events__term *term, *h; |
| 1095 | |
| 1096 | list_for_each_entry_safe(term, h, terms, list) |
| 1097 | free(term); |
| 1098 | |
| 1099 | free(terms); |
| 1100 | } |