David Howells | d2709c7 | 2012-11-19 22:21:03 +0000 | [diff] [blame] | 1 | #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" |
Kan Liang | 42f60c2 | 2014-10-07 11:08:49 -0400 | [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" |
Masami Hiramatsu | 6e81c74 | 2014-08-14 02:22:36 +0000 | [diff] [blame] | 13 | #include "debug.h" |
Borislav Petkov | 553873e | 2013-12-09 17:14:23 +0100 | [diff] [blame] | 14 | #include <api/fs/debugfs.h> |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 15 | #include "parse-events-bison.h" |
Jiri Olsa | 90e2b22 | 2012-06-15 14:31:40 +0800 | [diff] [blame] | 16 | #define YY_EXTRA_TYPE int |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 17 | #include "parse-events-flex.h" |
Jiri Olsa | 5f537a2 | 2012-03-15 20:09:18 +0100 | [diff] [blame] | 18 | #include "pmu.h" |
Namhyung Kim | b41f1ce | 2013-08-27 11:41:53 +0900 | [diff] [blame] | 19 | #include "thread_map.h" |
Jiri Olsa | b39b839 | 2015-04-22 21:10:16 +0200 | [diff] [blame] | 20 | #include "asm/bug.h" |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 21 | |
| 22 | #define MAX_NAME_LEN 100 |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 23 | |
Jiri Olsa | 82ba1f2 | 2012-05-21 09:12:50 +0200 | [diff] [blame] | 24 | #ifdef PARSER_DEBUG |
| 25 | extern int parse_events_debug; |
| 26 | #endif |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 27 | int parse_events_parse(void *data, void *scanner); |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 28 | |
Kan Liang | dcb4e10 | 2014-10-07 11:08:50 -0400 | [diff] [blame] | 29 | static struct perf_pmu_event_symbol *perf_pmu_events_list; |
| 30 | /* |
| 31 | * The variable indicates the number of supported pmu event symbols. |
| 32 | * 0 means not initialized and ready to init |
| 33 | * -1 means failed to init, don't try anymore |
| 34 | * >0 is the number of supported pmu event symbols |
| 35 | */ |
| 36 | static int perf_pmu_events_list_num; |
| 37 | |
Yunlong Song | 705750f | 2015-02-27 18:21:27 +0800 | [diff] [blame] | 38 | struct event_symbol event_symbols_hw[PERF_COUNT_HW_MAX] = { |
Jiri Olsa | 1dc1276 | 2012-07-04 00:00:44 +0200 | [diff] [blame] | 39 | [PERF_COUNT_HW_CPU_CYCLES] = { |
| 40 | .symbol = "cpu-cycles", |
| 41 | .alias = "cycles", |
| 42 | }, |
| 43 | [PERF_COUNT_HW_INSTRUCTIONS] = { |
| 44 | .symbol = "instructions", |
| 45 | .alias = "", |
| 46 | }, |
| 47 | [PERF_COUNT_HW_CACHE_REFERENCES] = { |
| 48 | .symbol = "cache-references", |
| 49 | .alias = "", |
| 50 | }, |
| 51 | [PERF_COUNT_HW_CACHE_MISSES] = { |
| 52 | .symbol = "cache-misses", |
| 53 | .alias = "", |
| 54 | }, |
| 55 | [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = { |
| 56 | .symbol = "branch-instructions", |
| 57 | .alias = "branches", |
| 58 | }, |
| 59 | [PERF_COUNT_HW_BRANCH_MISSES] = { |
| 60 | .symbol = "branch-misses", |
| 61 | .alias = "", |
| 62 | }, |
| 63 | [PERF_COUNT_HW_BUS_CYCLES] = { |
| 64 | .symbol = "bus-cycles", |
| 65 | .alias = "", |
| 66 | }, |
| 67 | [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = { |
| 68 | .symbol = "stalled-cycles-frontend", |
| 69 | .alias = "idle-cycles-frontend", |
| 70 | }, |
| 71 | [PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = { |
| 72 | .symbol = "stalled-cycles-backend", |
| 73 | .alias = "idle-cycles-backend", |
| 74 | }, |
| 75 | [PERF_COUNT_HW_REF_CPU_CYCLES] = { |
| 76 | .symbol = "ref-cycles", |
| 77 | .alias = "", |
| 78 | }, |
| 79 | }; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 80 | |
Yunlong Song | 705750f | 2015-02-27 18:21:27 +0800 | [diff] [blame] | 81 | struct event_symbol event_symbols_sw[PERF_COUNT_SW_MAX] = { |
Jiri Olsa | 1dc1276 | 2012-07-04 00:00:44 +0200 | [diff] [blame] | 82 | [PERF_COUNT_SW_CPU_CLOCK] = { |
| 83 | .symbol = "cpu-clock", |
| 84 | .alias = "", |
| 85 | }, |
| 86 | [PERF_COUNT_SW_TASK_CLOCK] = { |
| 87 | .symbol = "task-clock", |
| 88 | .alias = "", |
| 89 | }, |
| 90 | [PERF_COUNT_SW_PAGE_FAULTS] = { |
| 91 | .symbol = "page-faults", |
| 92 | .alias = "faults", |
| 93 | }, |
| 94 | [PERF_COUNT_SW_CONTEXT_SWITCHES] = { |
| 95 | .symbol = "context-switches", |
| 96 | .alias = "cs", |
| 97 | }, |
| 98 | [PERF_COUNT_SW_CPU_MIGRATIONS] = { |
| 99 | .symbol = "cpu-migrations", |
| 100 | .alias = "migrations", |
| 101 | }, |
| 102 | [PERF_COUNT_SW_PAGE_FAULTS_MIN] = { |
| 103 | .symbol = "minor-faults", |
| 104 | .alias = "", |
| 105 | }, |
| 106 | [PERF_COUNT_SW_PAGE_FAULTS_MAJ] = { |
| 107 | .symbol = "major-faults", |
| 108 | .alias = "", |
| 109 | }, |
| 110 | [PERF_COUNT_SW_ALIGNMENT_FAULTS] = { |
| 111 | .symbol = "alignment-faults", |
| 112 | .alias = "", |
| 113 | }, |
| 114 | [PERF_COUNT_SW_EMULATION_FAULTS] = { |
| 115 | .symbol = "emulation-faults", |
| 116 | .alias = "", |
| 117 | }, |
Adrian Hunter | d22d1a2 | 2013-08-31 21:50:52 +0300 | [diff] [blame] | 118 | [PERF_COUNT_SW_DUMMY] = { |
| 119 | .symbol = "dummy", |
| 120 | .alias = "", |
| 121 | }, |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 122 | }; |
| 123 | |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 124 | #define __PERF_EVENT_FIELD(config, name) \ |
| 125 | ((config & PERF_EVENT_##name##_MASK) >> PERF_EVENT_##name##_SHIFT) |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 126 | |
Ingo Molnar | 1fc570a | 2011-04-27 05:20:22 +0200 | [diff] [blame] | 127 | #define PERF_EVENT_RAW(config) __PERF_EVENT_FIELD(config, RAW) |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 128 | #define PERF_EVENT_CONFIG(config) __PERF_EVENT_FIELD(config, CONFIG) |
Ingo Molnar | 1fc570a | 2011-04-27 05:20:22 +0200 | [diff] [blame] | 129 | #define PERF_EVENT_TYPE(config) __PERF_EVENT_FIELD(config, TYPE) |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 130 | #define PERF_EVENT_ID(config) __PERF_EVENT_FIELD(config, EVENT) |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 131 | |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 132 | #define for_each_subsystem(sys_dir, sys_dirent, sys_next) \ |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 133 | while (!readdir_r(sys_dir, &sys_dirent, &sys_next) && sys_next) \ |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 134 | if (sys_dirent.d_type == DT_DIR && \ |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 135 | (strcmp(sys_dirent.d_name, ".")) && \ |
| 136 | (strcmp(sys_dirent.d_name, ".."))) |
| 137 | |
Peter Zijlstra | ae07b63 | 2009-08-06 16:48:54 +0200 | [diff] [blame] | 138 | static int tp_event_has_id(struct dirent *sys_dir, struct dirent *evt_dir) |
| 139 | { |
| 140 | char evt_path[MAXPATHLEN]; |
| 141 | int fd; |
| 142 | |
Arnaldo Carvalho de Melo | ebf294b | 2011-11-16 14:03:07 -0200 | [diff] [blame] | 143 | snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", tracing_events_path, |
Peter Zijlstra | ae07b63 | 2009-08-06 16:48:54 +0200 | [diff] [blame] | 144 | sys_dir->d_name, evt_dir->d_name); |
| 145 | fd = open(evt_path, O_RDONLY); |
| 146 | if (fd < 0) |
| 147 | return -EINVAL; |
| 148 | close(fd); |
| 149 | |
| 150 | return 0; |
| 151 | } |
| 152 | |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 153 | #define for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) \ |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 154 | while (!readdir_r(evt_dir, &evt_dirent, &evt_next) && evt_next) \ |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 155 | if (evt_dirent.d_type == DT_DIR && \ |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 156 | (strcmp(evt_dirent.d_name, ".")) && \ |
Peter Zijlstra | ae07b63 | 2009-08-06 16:48:54 +0200 | [diff] [blame] | 157 | (strcmp(evt_dirent.d_name, "..")) && \ |
| 158 | (!tp_event_has_id(&sys_dirent, &evt_dirent))) |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 159 | |
Li Zefan | 270bbbe | 2009-09-17 16:34:51 +0800 | [diff] [blame] | 160 | #define MAX_EVENT_LENGTH 512 |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 161 | |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 162 | |
Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 163 | struct tracepoint_path *tracepoint_id_to_path(u64 config) |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 164 | { |
Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 165 | struct tracepoint_path *path = NULL; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 166 | DIR *sys_dir, *evt_dir; |
| 167 | struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; |
Stephane Eranian | 8aa8a7c | 2012-03-13 16:51:02 +0100 | [diff] [blame] | 168 | char id_buf[24]; |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 169 | int fd; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 170 | u64 id; |
| 171 | char evt_path[MAXPATHLEN]; |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 172 | char dir_path[MAXPATHLEN]; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 173 | |
Arnaldo Carvalho de Melo | ebf294b | 2011-11-16 14:03:07 -0200 | [diff] [blame] | 174 | sys_dir = opendir(tracing_events_path); |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 175 | if (!sys_dir) |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 176 | return NULL; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 177 | |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 178 | for_each_subsystem(sys_dir, sys_dirent, sys_next) { |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 179 | |
Arnaldo Carvalho de Melo | ebf294b | 2011-11-16 14:03:07 -0200 | [diff] [blame] | 180 | snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path, |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 181 | sys_dirent.d_name); |
| 182 | evt_dir = opendir(dir_path); |
| 183 | if (!evt_dir) |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 184 | continue; |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 185 | |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 186 | for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 187 | |
| 188 | snprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path, |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 189 | evt_dirent.d_name); |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 190 | fd = open(evt_path, O_RDONLY); |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 191 | if (fd < 0) |
| 192 | continue; |
| 193 | if (read(fd, id_buf, sizeof(id_buf)) < 0) { |
| 194 | close(fd); |
| 195 | continue; |
| 196 | } |
| 197 | close(fd); |
| 198 | id = atoll(id_buf); |
| 199 | if (id == config) { |
| 200 | closedir(evt_dir); |
| 201 | closedir(sys_dir); |
Julia Lawall | 59b4cae | 2009-12-06 10:16:30 +0100 | [diff] [blame] | 202 | path = zalloc(sizeof(*path)); |
Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 203 | path->system = malloc(MAX_EVENT_LENGTH); |
| 204 | if (!path->system) { |
| 205 | free(path); |
| 206 | return NULL; |
| 207 | } |
| 208 | path->name = malloc(MAX_EVENT_LENGTH); |
| 209 | if (!path->name) { |
Arnaldo Carvalho de Melo | 74cf249 | 2013-12-27 16:55:14 -0300 | [diff] [blame] | 210 | zfree(&path->system); |
Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 211 | free(path); |
| 212 | return NULL; |
| 213 | } |
| 214 | strncpy(path->system, sys_dirent.d_name, |
| 215 | MAX_EVENT_LENGTH); |
| 216 | strncpy(path->name, evt_dirent.d_name, |
| 217 | MAX_EVENT_LENGTH); |
| 218 | return path; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | closedir(evt_dir); |
| 222 | } |
| 223 | |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 224 | closedir(sys_dir); |
Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 225 | return NULL; |
| 226 | } |
| 227 | |
Namhyung Kim | e7c93f0 | 2013-06-26 16:14:05 +0900 | [diff] [blame] | 228 | struct tracepoint_path *tracepoint_name_to_path(const char *name) |
| 229 | { |
| 230 | struct tracepoint_path *path = zalloc(sizeof(*path)); |
| 231 | char *str = strchr(name, ':'); |
| 232 | |
| 233 | if (path == NULL || str == NULL) { |
| 234 | free(path); |
| 235 | return NULL; |
| 236 | } |
| 237 | |
| 238 | path->system = strndup(name, str - name); |
| 239 | path->name = strdup(str+1); |
| 240 | |
| 241 | if (path->system == NULL || path->name == NULL) { |
Arnaldo Carvalho de Melo | 74cf249 | 2013-12-27 16:55:14 -0300 | [diff] [blame] | 242 | zfree(&path->system); |
| 243 | zfree(&path->name); |
Namhyung Kim | e7c93f0 | 2013-06-26 16:14:05 +0900 | [diff] [blame] | 244 | free(path); |
| 245 | path = NULL; |
| 246 | } |
| 247 | |
| 248 | return path; |
| 249 | } |
| 250 | |
David Ahern | 1424dc9 | 2011-03-09 22:23:28 -0700 | [diff] [blame] | 251 | const char *event_type(int type) |
| 252 | { |
| 253 | switch (type) { |
| 254 | case PERF_TYPE_HARDWARE: |
| 255 | return "hardware"; |
| 256 | |
| 257 | case PERF_TYPE_SOFTWARE: |
| 258 | return "software"; |
| 259 | |
| 260 | case PERF_TYPE_TRACEPOINT: |
| 261 | return "tracepoint"; |
| 262 | |
| 263 | case PERF_TYPE_HW_CACHE: |
| 264 | return "hardware-cache"; |
| 265 | |
| 266 | default: |
| 267 | break; |
| 268 | } |
| 269 | |
| 270 | return "unknown"; |
| 271 | } |
| 272 | |
Yan, Zheng | 7ae92e7 | 2012-09-10 15:53:50 +0800 | [diff] [blame] | 273 | |
| 274 | |
Stephane Eranian | 410136f | 2013-11-12 17:58:49 +0100 | [diff] [blame] | 275 | static struct perf_evsel * |
| 276 | __add_event(struct list_head *list, int *idx, |
| 277 | struct perf_event_attr *attr, |
| 278 | char *name, struct cpu_map *cpus) |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 279 | { |
| 280 | struct perf_evsel *evsel; |
| 281 | |
| 282 | event_attr_init(attr); |
| 283 | |
Arnaldo Carvalho de Melo | ef50383 | 2013-11-07 16:41:19 -0300 | [diff] [blame] | 284 | evsel = perf_evsel__new_idx(attr, (*idx)++); |
David Ahern | c5cd8ac | 2013-07-02 13:27:25 -0600 | [diff] [blame] | 285 | if (!evsel) |
Stephane Eranian | 410136f | 2013-11-12 17:58:49 +0100 | [diff] [blame] | 286 | return NULL; |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 287 | |
Yan, Zheng | 7ae92e7 | 2012-09-10 15:53:50 +0800 | [diff] [blame] | 288 | evsel->cpus = cpus; |
Arnaldo Carvalho de Melo | 9db1763 | 2012-06-12 13:45:00 -0300 | [diff] [blame] | 289 | if (name) |
| 290 | evsel->name = strdup(name); |
Jiri Olsa | b847cbd | 2012-05-21 09:12:51 +0200 | [diff] [blame] | 291 | list_add_tail(&evsel->node, list); |
Stephane Eranian | 410136f | 2013-11-12 17:58:49 +0100 | [diff] [blame] | 292 | return evsel; |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 293 | } |
| 294 | |
David Ahern | c5cd8ac | 2013-07-02 13:27:25 -0600 | [diff] [blame] | 295 | static int add_event(struct list_head *list, int *idx, |
Yan, Zheng | 7ae92e7 | 2012-09-10 15:53:50 +0800 | [diff] [blame] | 296 | struct perf_event_attr *attr, char *name) |
| 297 | { |
Stephane Eranian | 410136f | 2013-11-12 17:58:49 +0100 | [diff] [blame] | 298 | return __add_event(list, idx, attr, name, NULL) ? 0 : -ENOMEM; |
Yan, Zheng | 7ae92e7 | 2012-09-10 15:53:50 +0800 | [diff] [blame] | 299 | } |
| 300 | |
Arnaldo Carvalho de Melo | 0b668bc | 2012-06-11 14:08:07 -0300 | [diff] [blame] | 301 | static int parse_aliases(char *str, const char *names[][PERF_EVSEL__MAX_ALIASES], int size) |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 302 | { |
| 303 | int i, j; |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 304 | int n, longest = -1; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 305 | |
| 306 | for (i = 0; i < size; i++) { |
Arnaldo Carvalho de Melo | 0b668bc | 2012-06-11 14:08:07 -0300 | [diff] [blame] | 307 | for (j = 0; j < PERF_EVSEL__MAX_ALIASES && names[i][j]; j++) { |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 308 | n = strlen(names[i][j]); |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 309 | if (n > longest && !strncasecmp(str, names[i][j], n)) |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 310 | longest = n; |
| 311 | } |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 312 | if (longest > 0) |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 313 | return i; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 314 | } |
| 315 | |
Ingo Molnar | 8953645 | 2009-06-06 21:04:17 +0200 | [diff] [blame] | 316 | return -1; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 317 | } |
| 318 | |
David Ahern | c5cd8ac | 2013-07-02 13:27:25 -0600 | [diff] [blame] | 319 | int parse_events_add_cache(struct list_head *list, int *idx, |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 320 | char *type, char *op_result1, char *op_result2) |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 321 | { |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 322 | struct perf_event_attr attr; |
| 323 | char name[MAX_NAME_LEN]; |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 324 | int cache_type = -1, cache_op = -1, cache_result = -1; |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 325 | char *op_result[2] = { op_result1, op_result2 }; |
| 326 | int i, n; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 327 | |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 328 | /* |
| 329 | * No fallback - if we cannot get a clear cache type |
| 330 | * then bail out: |
| 331 | */ |
Arnaldo Carvalho de Melo | 0b668bc | 2012-06-11 14:08:07 -0300 | [diff] [blame] | 332 | cache_type = parse_aliases(type, perf_evsel__hw_cache, |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 333 | PERF_COUNT_HW_CACHE_MAX); |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 334 | if (cache_type == -1) |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 335 | return -EINVAL; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 336 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 337 | n = snprintf(name, MAX_NAME_LEN, "%s", type); |
| 338 | |
| 339 | for (i = 0; (i < 2) && (op_result[i]); i++) { |
| 340 | char *str = op_result[i]; |
| 341 | |
Jiri Olsa | 275ef38 | 2012-09-05 19:51:33 +0200 | [diff] [blame] | 342 | n += snprintf(name + n, MAX_NAME_LEN - n, "-%s", str); |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 343 | |
| 344 | if (cache_op == -1) { |
Arnaldo Carvalho de Melo | 0b668bc | 2012-06-11 14:08:07 -0300 | [diff] [blame] | 345 | cache_op = parse_aliases(str, perf_evsel__hw_cache_op, |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 346 | PERF_COUNT_HW_CACHE_OP_MAX); |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 347 | if (cache_op >= 0) { |
Arnaldo Carvalho de Melo | 0b668bc | 2012-06-11 14:08:07 -0300 | [diff] [blame] | 348 | if (!perf_evsel__is_cache_op_valid(cache_type, cache_op)) |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 349 | return -EINVAL; |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 350 | continue; |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | if (cache_result == -1) { |
Arnaldo Carvalho de Melo | 0b668bc | 2012-06-11 14:08:07 -0300 | [diff] [blame] | 355 | cache_result = parse_aliases(str, perf_evsel__hw_cache_result, |
| 356 | PERF_COUNT_HW_CACHE_RESULT_MAX); |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 357 | if (cache_result >= 0) |
| 358 | continue; |
| 359 | } |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 360 | } |
| 361 | |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 362 | /* |
| 363 | * Fall back to reads: |
| 364 | */ |
Ingo Molnar | 8953645 | 2009-06-06 21:04:17 +0200 | [diff] [blame] | 365 | if (cache_op == -1) |
| 366 | cache_op = PERF_COUNT_HW_CACHE_OP_READ; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 367 | |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 368 | /* |
| 369 | * Fall back to accesses: |
| 370 | */ |
| 371 | if (cache_result == -1) |
| 372 | cache_result = PERF_COUNT_HW_CACHE_RESULT_ACCESS; |
| 373 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 374 | memset(&attr, 0, sizeof(attr)); |
| 375 | attr.config = cache_type | (cache_op << 8) | (cache_result << 16); |
| 376 | attr.type = PERF_TYPE_HW_CACHE; |
| 377 | return add_event(list, idx, &attr, name); |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 378 | } |
| 379 | |
David Ahern | c5cd8ac | 2013-07-02 13:27:25 -0600 | [diff] [blame] | 380 | static int add_tracepoint(struct list_head *list, int *idx, |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 381 | char *sys_name, char *evt_name) |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 382 | { |
Arnaldo Carvalho de Melo | 82fe1c2 | 2012-09-26 17:13:07 -0300 | [diff] [blame] | 383 | struct perf_evsel *evsel; |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 384 | |
Arnaldo Carvalho de Melo | ef50383 | 2013-11-07 16:41:19 -0300 | [diff] [blame] | 385 | evsel = perf_evsel__newtp_idx(sys_name, evt_name, (*idx)++); |
David Ahern | c5cd8ac | 2013-07-02 13:27:25 -0600 | [diff] [blame] | 386 | if (!evsel) |
Arnaldo Carvalho de Melo | 82fe1c2 | 2012-09-26 17:13:07 -0300 | [diff] [blame] | 387 | return -ENOMEM; |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 388 | |
Arnaldo Carvalho de Melo | 82fe1c2 | 2012-09-26 17:13:07 -0300 | [diff] [blame] | 389 | list_add_tail(&evsel->node, list); |
David Ahern | c5cd8ac | 2013-07-02 13:27:25 -0600 | [diff] [blame] | 390 | |
Arnaldo Carvalho de Melo | 82fe1c2 | 2012-09-26 17:13:07 -0300 | [diff] [blame] | 391 | return 0; |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 392 | } |
| 393 | |
David Ahern | c5cd8ac | 2013-07-02 13:27:25 -0600 | [diff] [blame] | 394 | static int add_tracepoint_multi_event(struct list_head *list, int *idx, |
Jiri Olsa | f35488f | 2012-12-17 14:08:37 +0100 | [diff] [blame] | 395 | char *sys_name, char *evt_name) |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 396 | { |
| 397 | char evt_path[MAXPATHLEN]; |
| 398 | struct dirent *evt_ent; |
| 399 | DIR *evt_dir; |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 400 | int ret = 0; |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 401 | |
Arnaldo Carvalho de Melo | ebf294b | 2011-11-16 14:03:07 -0200 | [diff] [blame] | 402 | snprintf(evt_path, MAXPATHLEN, "%s/%s", tracing_events_path, sys_name); |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 403 | evt_dir = opendir(evt_path); |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 404 | if (!evt_dir) { |
| 405 | perror("Can't open event dir"); |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 406 | return -1; |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 407 | } |
| 408 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 409 | while (!ret && (evt_ent = readdir(evt_dir))) { |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 410 | if (!strcmp(evt_ent->d_name, ".") |
| 411 | || !strcmp(evt_ent->d_name, "..") |
| 412 | || !strcmp(evt_ent->d_name, "enable") |
| 413 | || !strcmp(evt_ent->d_name, "filter")) |
| 414 | continue; |
| 415 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 416 | if (!strglobmatch(evt_ent->d_name, evt_name)) |
Masami Hiramatsu | fb1d2ed | 2010-01-05 17:47:17 -0500 | [diff] [blame] | 417 | continue; |
| 418 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 419 | ret = add_tracepoint(list, idx, sys_name, evt_ent->d_name); |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 420 | } |
| 421 | |
Jiri Olsa | 0bd3f08 | 2012-12-17 14:08:36 +0100 | [diff] [blame] | 422 | closedir(evt_dir); |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 423 | return ret; |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 424 | } |
| 425 | |
David Ahern | c5cd8ac | 2013-07-02 13:27:25 -0600 | [diff] [blame] | 426 | static int add_tracepoint_event(struct list_head *list, int *idx, |
Jiri Olsa | f35488f | 2012-12-17 14:08:37 +0100 | [diff] [blame] | 427 | char *sys_name, char *evt_name) |
| 428 | { |
| 429 | return strpbrk(evt_name, "*?") ? |
| 430 | add_tracepoint_multi_event(list, idx, sys_name, evt_name) : |
| 431 | add_tracepoint(list, idx, sys_name, evt_name); |
| 432 | } |
| 433 | |
David Ahern | c5cd8ac | 2013-07-02 13:27:25 -0600 | [diff] [blame] | 434 | static int add_tracepoint_multi_sys(struct list_head *list, int *idx, |
Jiri Olsa | f35488f | 2012-12-17 14:08:37 +0100 | [diff] [blame] | 435 | char *sys_name, char *evt_name) |
| 436 | { |
| 437 | struct dirent *events_ent; |
| 438 | DIR *events_dir; |
| 439 | int ret = 0; |
| 440 | |
| 441 | events_dir = opendir(tracing_events_path); |
| 442 | if (!events_dir) { |
| 443 | perror("Can't open event dir"); |
| 444 | return -1; |
| 445 | } |
| 446 | |
| 447 | while (!ret && (events_ent = readdir(events_dir))) { |
| 448 | if (!strcmp(events_ent->d_name, ".") |
| 449 | || !strcmp(events_ent->d_name, "..") |
| 450 | || !strcmp(events_ent->d_name, "enable") |
| 451 | || !strcmp(events_ent->d_name, "header_event") |
| 452 | || !strcmp(events_ent->d_name, "header_page")) |
| 453 | continue; |
| 454 | |
| 455 | if (!strglobmatch(events_ent->d_name, sys_name)) |
| 456 | continue; |
| 457 | |
| 458 | ret = add_tracepoint_event(list, idx, events_ent->d_name, |
| 459 | evt_name); |
| 460 | } |
| 461 | |
| 462 | closedir(events_dir); |
| 463 | return ret; |
| 464 | } |
| 465 | |
David Ahern | c5cd8ac | 2013-07-02 13:27:25 -0600 | [diff] [blame] | 466 | int parse_events_add_tracepoint(struct list_head *list, int *idx, |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 467 | char *sys, char *event) |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 468 | { |
Jiri Olsa | f35488f | 2012-12-17 14:08:37 +0100 | [diff] [blame] | 469 | if (strpbrk(sys, "*?")) |
| 470 | return add_tracepoint_multi_sys(list, idx, sys, event); |
| 471 | else |
| 472 | return add_tracepoint_event(list, idx, sys, event); |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 473 | } |
| 474 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 475 | static int |
| 476 | parse_breakpoint_type(const char *type, struct perf_event_attr *attr) |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 477 | { |
| 478 | int i; |
| 479 | |
| 480 | for (i = 0; i < 3; i++) { |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 481 | if (!type || !type[i]) |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 482 | break; |
| 483 | |
Jiri Olsa | 7582732 | 2012-06-29 09:22:54 +0200 | [diff] [blame] | 484 | #define CHECK_SET_TYPE(bit) \ |
| 485 | do { \ |
| 486 | if (attr->bp_type & bit) \ |
| 487 | return -EINVAL; \ |
| 488 | else \ |
| 489 | attr->bp_type |= bit; \ |
| 490 | } while (0) |
| 491 | |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 492 | switch (type[i]) { |
| 493 | case 'r': |
Jiri Olsa | 7582732 | 2012-06-29 09:22:54 +0200 | [diff] [blame] | 494 | CHECK_SET_TYPE(HW_BREAKPOINT_R); |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 495 | break; |
| 496 | case 'w': |
Jiri Olsa | 7582732 | 2012-06-29 09:22:54 +0200 | [diff] [blame] | 497 | CHECK_SET_TYPE(HW_BREAKPOINT_W); |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 498 | break; |
| 499 | case 'x': |
Jiri Olsa | 7582732 | 2012-06-29 09:22:54 +0200 | [diff] [blame] | 500 | CHECK_SET_TYPE(HW_BREAKPOINT_X); |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 501 | break; |
| 502 | default: |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 503 | return -EINVAL; |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 504 | } |
| 505 | } |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 506 | |
Jiri Olsa | 7582732 | 2012-06-29 09:22:54 +0200 | [diff] [blame] | 507 | #undef CHECK_SET_TYPE |
| 508 | |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 509 | if (!attr->bp_type) /* Default */ |
| 510 | attr->bp_type = HW_BREAKPOINT_R | HW_BREAKPOINT_W; |
| 511 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 512 | return 0; |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 513 | } |
| 514 | |
David Ahern | c5cd8ac | 2013-07-02 13:27:25 -0600 | [diff] [blame] | 515 | int parse_events_add_breakpoint(struct list_head *list, int *idx, |
Jacob Shin | 3741eb9 | 2014-05-29 17:26:51 +0200 | [diff] [blame] | 516 | void *ptr, char *type, u64 len) |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 517 | { |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 518 | struct perf_event_attr attr; |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 519 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 520 | memset(&attr, 0, sizeof(attr)); |
Jiri Olsa | 9fafd98 | 2012-03-20 19:15:39 +0100 | [diff] [blame] | 521 | attr.bp_addr = (unsigned long) ptr; |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 522 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 523 | if (parse_breakpoint_type(type, &attr)) |
| 524 | return -EINVAL; |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 525 | |
Jacob Shin | 3741eb9 | 2014-05-29 17:26:51 +0200 | [diff] [blame] | 526 | /* Provide some defaults if len is not specified */ |
| 527 | if (!len) { |
| 528 | if (attr.bp_type == HW_BREAKPOINT_X) |
| 529 | len = sizeof(long); |
| 530 | else |
| 531 | len = HW_BREAKPOINT_LEN_4; |
| 532 | } |
| 533 | |
| 534 | attr.bp_len = len; |
Frederic Weisbecker | aa59a48 | 2010-06-24 21:36:19 +0200 | [diff] [blame] | 535 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 536 | attr.type = PERF_TYPE_BREAKPOINT; |
Jovi Zhang | 4a841d6 | 2012-07-15 03:03:10 +0800 | [diff] [blame] | 537 | attr.sample_period = 1; |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 538 | |
Jiri Olsa | 287e74a | 2012-06-28 23:18:49 +0200 | [diff] [blame] | 539 | return add_event(list, idx, &attr, NULL); |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 540 | } |
| 541 | |
Jiri Olsa | 3b0e371 | 2015-04-22 21:10:22 +0200 | [diff] [blame] | 542 | static int check_type_val(struct parse_events_term *term, |
| 543 | struct parse_events_error *err, |
| 544 | int type) |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 545 | { |
Jiri Olsa | 3b0e371 | 2015-04-22 21:10:22 +0200 | [diff] [blame] | 546 | if (type == term->type_val) |
| 547 | return 0; |
| 548 | |
| 549 | if (err) { |
| 550 | err->idx = term->err_val; |
| 551 | if (type == PARSE_EVENTS__TERM_TYPE_NUM) |
| 552 | err->str = strdup("expected numeric value"); |
| 553 | else |
| 554 | err->str = strdup("expected string value"); |
| 555 | } |
| 556 | return -EINVAL; |
| 557 | } |
| 558 | |
| 559 | static int config_term(struct perf_event_attr *attr, |
| 560 | struct parse_events_term *term, |
| 561 | struct parse_events_error *err) |
| 562 | { |
| 563 | #define CHECK_TYPE_VAL(type) \ |
| 564 | do { \ |
| 565 | if (check_type_val(term, err, PARSE_EVENTS__TERM_TYPE_ ## type)) \ |
| 566 | return -EINVAL; \ |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 567 | } while (0) |
| 568 | |
| 569 | switch (term->type_term) { |
Jiri Olsa | c056ba6a | 2015-04-22 21:10:18 +0200 | [diff] [blame] | 570 | case PARSE_EVENTS__TERM_TYPE_USER: |
| 571 | /* |
| 572 | * Always succeed for sysfs terms, as we dont know |
| 573 | * at this point what type they need to have. |
| 574 | */ |
| 575 | return 0; |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 576 | case PARSE_EVENTS__TERM_TYPE_CONFIG: |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 577 | CHECK_TYPE_VAL(NUM); |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 578 | attr->config = term->val.num; |
| 579 | break; |
| 580 | case PARSE_EVENTS__TERM_TYPE_CONFIG1: |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 581 | CHECK_TYPE_VAL(NUM); |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 582 | attr->config1 = term->val.num; |
| 583 | break; |
| 584 | case PARSE_EVENTS__TERM_TYPE_CONFIG2: |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 585 | CHECK_TYPE_VAL(NUM); |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 586 | attr->config2 = term->val.num; |
| 587 | break; |
| 588 | case PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD: |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 589 | CHECK_TYPE_VAL(NUM); |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 590 | attr->sample_period = term->val.num; |
| 591 | break; |
| 592 | case PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE: |
| 593 | /* |
| 594 | * TODO uncomment when the field is available |
| 595 | * attr->branch_sample_type = term->val.num; |
| 596 | */ |
| 597 | break; |
Jiri Olsa | 6b5fc39 | 2012-05-21 09:12:53 +0200 | [diff] [blame] | 598 | case PARSE_EVENTS__TERM_TYPE_NAME: |
| 599 | CHECK_TYPE_VAL(STR); |
| 600 | break; |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 601 | default: |
| 602 | return -EINVAL; |
| 603 | } |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 604 | |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 605 | return 0; |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 606 | #undef CHECK_TYPE_VAL |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | static int config_attr(struct perf_event_attr *attr, |
Jiri Olsa | 3b0e371 | 2015-04-22 21:10:22 +0200 | [diff] [blame] | 610 | struct list_head *head, |
| 611 | struct parse_events_error *err) |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 612 | { |
Arnaldo Carvalho de Melo | 6cee6cd | 2013-01-18 16:29:49 -0300 | [diff] [blame] | 613 | struct parse_events_term *term; |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 614 | |
| 615 | list_for_each_entry(term, head, list) |
Jiri Olsa | 3b0e371 | 2015-04-22 21:10:22 +0200 | [diff] [blame] | 616 | if (config_term(attr, term, err)) |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 617 | return -EINVAL; |
| 618 | |
| 619 | return 0; |
| 620 | } |
| 621 | |
Jiri Olsa | 87d650b | 2015-04-22 21:10:24 +0200 | [diff] [blame] | 622 | int parse_events_add_numeric(struct parse_events_evlist *data, |
| 623 | struct list_head *list, |
Robert Richter | b527bab | 2012-08-07 19:43:13 +0200 | [diff] [blame] | 624 | u32 type, u64 config, |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 625 | struct list_head *head_config) |
Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 626 | { |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 627 | struct perf_event_attr attr; |
Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 628 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 629 | memset(&attr, 0, sizeof(attr)); |
| 630 | attr.type = type; |
| 631 | attr.config = config; |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 632 | |
| 633 | if (head_config && |
Jiri Olsa | 87d650b | 2015-04-22 21:10:24 +0200 | [diff] [blame] | 634 | config_attr(&attr, head_config, data->error)) |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 635 | return -EINVAL; |
| 636 | |
Jiri Olsa | 87d650b | 2015-04-22 21:10:24 +0200 | [diff] [blame] | 637 | return add_event(list, &data->idx, &attr, NULL); |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 638 | } |
| 639 | |
Arnaldo Carvalho de Melo | 6cee6cd | 2013-01-18 16:29:49 -0300 | [diff] [blame] | 640 | static int parse_events__is_name_term(struct parse_events_term *term) |
Jiri Olsa | 6b5fc39 | 2012-05-21 09:12:53 +0200 | [diff] [blame] | 641 | { |
| 642 | return term->type_term == PARSE_EVENTS__TERM_TYPE_NAME; |
| 643 | } |
| 644 | |
Arnaldo Carvalho de Melo | 9db1763 | 2012-06-12 13:45:00 -0300 | [diff] [blame] | 645 | static char *pmu_event_name(struct list_head *head_terms) |
Jiri Olsa | 6b5fc39 | 2012-05-21 09:12:53 +0200 | [diff] [blame] | 646 | { |
Arnaldo Carvalho de Melo | 6cee6cd | 2013-01-18 16:29:49 -0300 | [diff] [blame] | 647 | struct parse_events_term *term; |
Jiri Olsa | 6b5fc39 | 2012-05-21 09:12:53 +0200 | [diff] [blame] | 648 | |
| 649 | list_for_each_entry(term, head_terms, list) |
| 650 | if (parse_events__is_name_term(term)) |
| 651 | return term->val.str; |
| 652 | |
Arnaldo Carvalho de Melo | 9db1763 | 2012-06-12 13:45:00 -0300 | [diff] [blame] | 653 | return NULL; |
Jiri Olsa | 6b5fc39 | 2012-05-21 09:12:53 +0200 | [diff] [blame] | 654 | } |
| 655 | |
Jiri Olsa | 36adec8 | 2015-04-22 21:10:19 +0200 | [diff] [blame] | 656 | int parse_events_add_pmu(struct parse_events_evlist *data, |
| 657 | struct list_head *list, char *name, |
| 658 | struct list_head *head_config) |
Jiri Olsa | 5f537a2 | 2012-03-15 20:09:18 +0100 | [diff] [blame] | 659 | { |
| 660 | struct perf_event_attr attr; |
Matt Fleming | 46441bd | 2014-09-24 15:04:06 +0100 | [diff] [blame] | 661 | struct perf_pmu_info info; |
Jiri Olsa | 5f537a2 | 2012-03-15 20:09:18 +0100 | [diff] [blame] | 662 | struct perf_pmu *pmu; |
Stephane Eranian | 410136f | 2013-11-12 17:58:49 +0100 | [diff] [blame] | 663 | struct perf_evsel *evsel; |
Jiri Olsa | 5f537a2 | 2012-03-15 20:09:18 +0100 | [diff] [blame] | 664 | |
| 665 | pmu = perf_pmu__find(name); |
| 666 | if (!pmu) |
| 667 | return -EINVAL; |
| 668 | |
Adrian Hunter | dc0a620 | 2014-07-31 09:00:49 +0300 | [diff] [blame] | 669 | if (pmu->default_config) { |
| 670 | memcpy(&attr, pmu->default_config, |
| 671 | sizeof(struct perf_event_attr)); |
| 672 | } else { |
| 673 | memset(&attr, 0, sizeof(attr)); |
| 674 | } |
Jiri Olsa | 5f537a2 | 2012-03-15 20:09:18 +0100 | [diff] [blame] | 675 | |
Adrian Hunter | ad96227 | 2014-08-15 22:08:40 +0300 | [diff] [blame] | 676 | if (!head_config) { |
| 677 | attr.type = pmu->type; |
Jiri Olsa | 36adec8 | 2015-04-22 21:10:19 +0200 | [diff] [blame] | 678 | evsel = __add_event(list, &data->idx, &attr, NULL, pmu->cpus); |
Adrian Hunter | ad96227 | 2014-08-15 22:08:40 +0300 | [diff] [blame] | 679 | return evsel ? 0 : -ENOMEM; |
| 680 | } |
| 681 | |
Matt Fleming | 46441bd | 2014-09-24 15:04:06 +0100 | [diff] [blame] | 682 | if (perf_pmu__check_alias(pmu, head_config, &info)) |
Zheng Yan | a6146d5 | 2012-06-15 14:31:41 +0800 | [diff] [blame] | 683 | return -EINVAL; |
| 684 | |
Jiri Olsa | 5f537a2 | 2012-03-15 20:09:18 +0100 | [diff] [blame] | 685 | /* |
| 686 | * Configure hardcoded terms first, no need to check |
| 687 | * return value when called with fail == 0 ;) |
| 688 | */ |
Jiri Olsa | 3b0e371 | 2015-04-22 21:10:22 +0200 | [diff] [blame] | 689 | if (config_attr(&attr, head_config, data->error)) |
Jiri Olsa | c056ba6a | 2015-04-22 21:10:18 +0200 | [diff] [blame] | 690 | return -EINVAL; |
Jiri Olsa | 5f537a2 | 2012-03-15 20:09:18 +0100 | [diff] [blame] | 691 | |
Jiri Olsa | e64b020 | 2015-04-22 21:10:21 +0200 | [diff] [blame] | 692 | if (perf_pmu__config(pmu, &attr, head_config, data->error)) |
Jiri Olsa | 5f537a2 | 2012-03-15 20:09:18 +0100 | [diff] [blame] | 693 | return -EINVAL; |
| 694 | |
Jiri Olsa | 36adec8 | 2015-04-22 21:10:19 +0200 | [diff] [blame] | 695 | evsel = __add_event(list, &data->idx, &attr, |
| 696 | pmu_event_name(head_config), pmu->cpus); |
Stephane Eranian | 410136f | 2013-11-12 17:58:49 +0100 | [diff] [blame] | 697 | if (evsel) { |
Matt Fleming | 46441bd | 2014-09-24 15:04:06 +0100 | [diff] [blame] | 698 | evsel->unit = info.unit; |
| 699 | evsel->scale = info.scale; |
Matt Fleming | 044330c | 2014-11-21 10:31:12 +0100 | [diff] [blame] | 700 | evsel->per_pkg = info.per_pkg; |
Jiri Olsa | 1d9e446 | 2014-11-21 10:31:13 +0100 | [diff] [blame] | 701 | evsel->snapshot = info.snapshot; |
Stephane Eranian | 410136f | 2013-11-12 17:58:49 +0100 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | return evsel ? 0 : -ENOMEM; |
Jiri Olsa | 5f537a2 | 2012-03-15 20:09:18 +0100 | [diff] [blame] | 705 | } |
| 706 | |
Jiri Olsa | 6a4bb04 | 2012-08-08 12:22:36 +0200 | [diff] [blame] | 707 | int parse_events__modifier_group(struct list_head *list, |
| 708 | char *event_mod) |
Jiri Olsa | 89efb02 | 2012-08-08 12:14:14 +0200 | [diff] [blame] | 709 | { |
Jiri Olsa | 6a4bb04 | 2012-08-08 12:22:36 +0200 | [diff] [blame] | 710 | return parse_events__modifier_event(list, event_mod, true); |
| 711 | } |
| 712 | |
Arnaldo Carvalho de Melo | 63dab22 | 2012-08-14 16:35:48 -0300 | [diff] [blame] | 713 | void parse_events__set_leader(char *name, struct list_head *list) |
Jiri Olsa | 6a4bb04 | 2012-08-08 12:22:36 +0200 | [diff] [blame] | 714 | { |
| 715 | struct perf_evsel *leader; |
| 716 | |
Arnaldo Carvalho de Melo | 63dab22 | 2012-08-14 16:35:48 -0300 | [diff] [blame] | 717 | __perf_evlist__set_leader(list); |
| 718 | leader = list_entry(list->next, struct perf_evsel, node); |
Jiri Olsa | 6a4bb04 | 2012-08-08 12:22:36 +0200 | [diff] [blame] | 719 | leader->group_name = name ? strdup(name) : NULL; |
Jiri Olsa | 89efb02 | 2012-08-08 12:14:14 +0200 | [diff] [blame] | 720 | } |
| 721 | |
David Ahern | c5cd8ac | 2013-07-02 13:27:25 -0600 | [diff] [blame] | 722 | /* list_event is assumed to point to malloc'ed memory */ |
Jiri Olsa | 5d7be90 | 2012-03-20 19:15:40 +0100 | [diff] [blame] | 723 | void parse_events_update_lists(struct list_head *list_event, |
| 724 | struct list_head *list_all) |
| 725 | { |
| 726 | /* |
| 727 | * Called for single event definition. Update the |
Jiri Olsa | 89efb02 | 2012-08-08 12:14:14 +0200 | [diff] [blame] | 728 | * 'all event' list, and reinit the 'single event' |
Jiri Olsa | 5d7be90 | 2012-03-20 19:15:40 +0100 | [diff] [blame] | 729 | * list, for next event definition. |
| 730 | */ |
| 731 | list_splice_tail(list_event, list_all); |
Jiri Olsa | b847cbd | 2012-05-21 09:12:51 +0200 | [diff] [blame] | 732 | free(list_event); |
Jiri Olsa | 5d7be90 | 2012-03-20 19:15:40 +0100 | [diff] [blame] | 733 | } |
| 734 | |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 735 | struct event_modifier { |
| 736 | int eu; |
| 737 | int ek; |
| 738 | int eh; |
| 739 | int eH; |
| 740 | int eG; |
Jiri Olsa | a1e12da | 2015-04-07 23:25:14 +0200 | [diff] [blame] | 741 | int eI; |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 742 | int precise; |
| 743 | int exclude_GH; |
Jiri Olsa | 3c17631 | 2012-10-10 17:39:03 +0200 | [diff] [blame] | 744 | int sample_read; |
Michael Ellerman | e9a7c41 | 2013-08-06 23:28:05 +1000 | [diff] [blame] | 745 | int pinned; |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 746 | }; |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 747 | |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 748 | static int get_event_modifier(struct event_modifier *mod, char *str, |
| 749 | struct perf_evsel *evsel) |
| 750 | { |
| 751 | int eu = evsel ? evsel->attr.exclude_user : 0; |
| 752 | int ek = evsel ? evsel->attr.exclude_kernel : 0; |
| 753 | int eh = evsel ? evsel->attr.exclude_hv : 0; |
| 754 | int eH = evsel ? evsel->attr.exclude_host : 0; |
| 755 | int eG = evsel ? evsel->attr.exclude_guest : 0; |
Jiri Olsa | a1e12da | 2015-04-07 23:25:14 +0200 | [diff] [blame] | 756 | int eI = evsel ? evsel->attr.exclude_idle : 0; |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 757 | int precise = evsel ? evsel->attr.precise_ip : 0; |
Jiri Olsa | 3c17631 | 2012-10-10 17:39:03 +0200 | [diff] [blame] | 758 | int sample_read = 0; |
Michael Ellerman | e9a7c41 | 2013-08-06 23:28:05 +1000 | [diff] [blame] | 759 | int pinned = evsel ? evsel->attr.pinned : 0; |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 760 | |
| 761 | int exclude = eu | ek | eh; |
| 762 | int exclude_GH = evsel ? evsel->exclude_GH : 0; |
| 763 | |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 764 | memset(mod, 0, sizeof(*mod)); |
Ingo Molnar | ceb53fb | 2011-04-27 04:06:33 +0200 | [diff] [blame] | 765 | |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 766 | while (*str) { |
Peter Zijlstra | ab60834 | 2010-04-08 23:03:20 +0200 | [diff] [blame] | 767 | if (*str == 'u') { |
| 768 | if (!exclude) |
| 769 | exclude = eu = ek = eh = 1; |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 770 | eu = 0; |
Peter Zijlstra | ab60834 | 2010-04-08 23:03:20 +0200 | [diff] [blame] | 771 | } else if (*str == 'k') { |
| 772 | if (!exclude) |
| 773 | exclude = eu = ek = eh = 1; |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 774 | ek = 0; |
Peter Zijlstra | ab60834 | 2010-04-08 23:03:20 +0200 | [diff] [blame] | 775 | } else if (*str == 'h') { |
| 776 | if (!exclude) |
| 777 | exclude = eu = ek = eh = 1; |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 778 | eh = 0; |
Joerg Roedel | 99320cc | 2012-01-04 17:54:19 +0100 | [diff] [blame] | 779 | } else if (*str == 'G') { |
| 780 | if (!exclude_GH) |
| 781 | exclude_GH = eG = eH = 1; |
| 782 | eG = 0; |
| 783 | } else if (*str == 'H') { |
| 784 | if (!exclude_GH) |
| 785 | exclude_GH = eG = eH = 1; |
| 786 | eH = 0; |
Jiri Olsa | a1e12da | 2015-04-07 23:25:14 +0200 | [diff] [blame] | 787 | } else if (*str == 'I') { |
| 788 | eI = 1; |
Peter Zijlstra | ab60834 | 2010-04-08 23:03:20 +0200 | [diff] [blame] | 789 | } else if (*str == 'p') { |
| 790 | precise++; |
David Ahern | 1342798 | 2012-09-13 14:59:13 -0600 | [diff] [blame] | 791 | /* use of precise requires exclude_guest */ |
| 792 | if (!exclude_GH) |
| 793 | eG = 1; |
Jiri Olsa | 3c17631 | 2012-10-10 17:39:03 +0200 | [diff] [blame] | 794 | } else if (*str == 'S') { |
| 795 | sample_read = 1; |
Michael Ellerman | e9a7c41 | 2013-08-06 23:28:05 +1000 | [diff] [blame] | 796 | } else if (*str == 'D') { |
| 797 | pinned = 1; |
Peter Zijlstra | ab60834 | 2010-04-08 23:03:20 +0200 | [diff] [blame] | 798 | } else |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 799 | break; |
Peter Zijlstra | ab60834 | 2010-04-08 23:03:20 +0200 | [diff] [blame] | 800 | |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 801 | ++str; |
| 802 | } |
Ingo Molnar | ceb53fb | 2011-04-27 04:06:33 +0200 | [diff] [blame] | 803 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 804 | /* |
| 805 | * precise ip: |
| 806 | * |
| 807 | * 0 - SAMPLE_IP can have arbitrary skid |
| 808 | * 1 - SAMPLE_IP must have constant skid |
| 809 | * 2 - SAMPLE_IP requested to have 0 skid |
| 810 | * 3 - SAMPLE_IP must have 0 skid |
| 811 | * |
| 812 | * See also PERF_RECORD_MISC_EXACT_IP |
| 813 | */ |
| 814 | if (precise > 3) |
| 815 | return -EINVAL; |
Ingo Molnar | ceb53fb | 2011-04-27 04:06:33 +0200 | [diff] [blame] | 816 | |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 817 | mod->eu = eu; |
| 818 | mod->ek = ek; |
| 819 | mod->eh = eh; |
| 820 | mod->eH = eH; |
| 821 | mod->eG = eG; |
Jiri Olsa | a1e12da | 2015-04-07 23:25:14 +0200 | [diff] [blame] | 822 | mod->eI = eI; |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 823 | mod->precise = precise; |
| 824 | mod->exclude_GH = exclude_GH; |
Jiri Olsa | 3c17631 | 2012-10-10 17:39:03 +0200 | [diff] [blame] | 825 | mod->sample_read = sample_read; |
Michael Ellerman | e9a7c41 | 2013-08-06 23:28:05 +1000 | [diff] [blame] | 826 | mod->pinned = pinned; |
| 827 | |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 828 | return 0; |
| 829 | } |
| 830 | |
Jiri Olsa | 534123f | 2012-11-13 15:32:58 +0100 | [diff] [blame] | 831 | /* |
| 832 | * Basic modifier sanity check to validate it contains only one |
| 833 | * instance of any modifier (apart from 'p') present. |
| 834 | */ |
| 835 | static int check_modifier(char *str) |
| 836 | { |
| 837 | char *p = str; |
| 838 | |
| 839 | /* The sizeof includes 0 byte as well. */ |
Jiri Olsa | a1e12da | 2015-04-07 23:25:14 +0200 | [diff] [blame] | 840 | if (strlen(str) > (sizeof("ukhGHpppSDI") - 1)) |
Jiri Olsa | 534123f | 2012-11-13 15:32:58 +0100 | [diff] [blame] | 841 | return -1; |
| 842 | |
| 843 | while (*p) { |
| 844 | if (*p != 'p' && strchr(p + 1, *p)) |
| 845 | return -1; |
| 846 | p++; |
| 847 | } |
| 848 | |
| 849 | return 0; |
| 850 | } |
| 851 | |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 852 | int parse_events__modifier_event(struct list_head *list, char *str, bool add) |
| 853 | { |
| 854 | struct perf_evsel *evsel; |
| 855 | struct event_modifier mod; |
| 856 | |
| 857 | if (str == NULL) |
| 858 | return 0; |
| 859 | |
Jiri Olsa | 534123f | 2012-11-13 15:32:58 +0100 | [diff] [blame] | 860 | if (check_modifier(str)) |
| 861 | return -EINVAL; |
| 862 | |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 863 | if (!add && get_event_modifier(&mod, str, NULL)) |
| 864 | return -EINVAL; |
| 865 | |
Arnaldo Carvalho de Melo | 0050f7a | 2014-01-10 10:37:27 -0300 | [diff] [blame] | 866 | __evlist__for_each(list, evsel) { |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 867 | if (add && get_event_modifier(&mod, str, evsel)) |
| 868 | return -EINVAL; |
| 869 | |
| 870 | evsel->attr.exclude_user = mod.eu; |
| 871 | evsel->attr.exclude_kernel = mod.ek; |
| 872 | evsel->attr.exclude_hv = mod.eh; |
| 873 | evsel->attr.precise_ip = mod.precise; |
| 874 | evsel->attr.exclude_host = mod.eH; |
| 875 | evsel->attr.exclude_guest = mod.eG; |
Jiri Olsa | a1e12da | 2015-04-07 23:25:14 +0200 | [diff] [blame] | 876 | evsel->attr.exclude_idle = mod.eI; |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 877 | evsel->exclude_GH = mod.exclude_GH; |
Jiri Olsa | 3c17631 | 2012-10-10 17:39:03 +0200 | [diff] [blame] | 878 | evsel->sample_read = mod.sample_read; |
Michael Ellerman | e9a7c41 | 2013-08-06 23:28:05 +1000 | [diff] [blame] | 879 | |
| 880 | if (perf_evsel__is_group_leader(evsel)) |
| 881 | evsel->attr.pinned = mod.pinned; |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 882 | } |
Ingo Molnar | ceb53fb | 2011-04-27 04:06:33 +0200 | [diff] [blame] | 883 | |
Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 884 | return 0; |
| 885 | } |
| 886 | |
Robert Richter | ac2ba9f | 2012-08-16 21:10:21 +0200 | [diff] [blame] | 887 | int parse_events_name(struct list_head *list, char *name) |
| 888 | { |
| 889 | struct perf_evsel *evsel; |
| 890 | |
Arnaldo Carvalho de Melo | 0050f7a | 2014-01-10 10:37:27 -0300 | [diff] [blame] | 891 | __evlist__for_each(list, evsel) { |
Robert Richter | ac2ba9f | 2012-08-16 21:10:21 +0200 | [diff] [blame] | 892 | if (!evsel->name) |
| 893 | evsel->name = strdup(name); |
| 894 | } |
| 895 | |
| 896 | return 0; |
| 897 | } |
| 898 | |
Kan Liang | dcb4e10 | 2014-10-07 11:08:50 -0400 | [diff] [blame] | 899 | static int |
| 900 | comp_pmu(const void *p1, const void *p2) |
| 901 | { |
| 902 | struct perf_pmu_event_symbol *pmu1 = (struct perf_pmu_event_symbol *) p1; |
| 903 | struct perf_pmu_event_symbol *pmu2 = (struct perf_pmu_event_symbol *) p2; |
| 904 | |
| 905 | return strcmp(pmu1->symbol, pmu2->symbol); |
| 906 | } |
| 907 | |
| 908 | static void perf_pmu__parse_cleanup(void) |
| 909 | { |
| 910 | if (perf_pmu_events_list_num > 0) { |
| 911 | struct perf_pmu_event_symbol *p; |
| 912 | int i; |
| 913 | |
| 914 | for (i = 0; i < perf_pmu_events_list_num; i++) { |
| 915 | p = perf_pmu_events_list + i; |
| 916 | free(p->symbol); |
| 917 | } |
| 918 | free(perf_pmu_events_list); |
| 919 | perf_pmu_events_list = NULL; |
| 920 | perf_pmu_events_list_num = 0; |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | #define SET_SYMBOL(str, stype) \ |
| 925 | do { \ |
| 926 | p->symbol = str; \ |
| 927 | if (!p->symbol) \ |
| 928 | goto err; \ |
| 929 | p->type = stype; \ |
| 930 | } while (0) |
| 931 | |
| 932 | /* |
| 933 | * Read the pmu events list from sysfs |
| 934 | * Save it into perf_pmu_events_list |
| 935 | */ |
| 936 | static void perf_pmu__parse_init(void) |
| 937 | { |
| 938 | |
| 939 | struct perf_pmu *pmu = NULL; |
| 940 | struct perf_pmu_alias *alias; |
| 941 | int len = 0; |
| 942 | |
| 943 | pmu = perf_pmu__find("cpu"); |
| 944 | if ((pmu == NULL) || list_empty(&pmu->aliases)) { |
| 945 | perf_pmu_events_list_num = -1; |
| 946 | return; |
| 947 | } |
| 948 | list_for_each_entry(alias, &pmu->aliases, list) { |
| 949 | if (strchr(alias->name, '-')) |
| 950 | len++; |
| 951 | len++; |
| 952 | } |
| 953 | perf_pmu_events_list = malloc(sizeof(struct perf_pmu_event_symbol) * len); |
| 954 | if (!perf_pmu_events_list) |
| 955 | return; |
| 956 | perf_pmu_events_list_num = len; |
| 957 | |
| 958 | len = 0; |
| 959 | list_for_each_entry(alias, &pmu->aliases, list) { |
| 960 | struct perf_pmu_event_symbol *p = perf_pmu_events_list + len; |
| 961 | char *tmp = strchr(alias->name, '-'); |
| 962 | |
| 963 | if (tmp != NULL) { |
| 964 | SET_SYMBOL(strndup(alias->name, tmp - alias->name), |
| 965 | PMU_EVENT_SYMBOL_PREFIX); |
| 966 | p++; |
| 967 | SET_SYMBOL(strdup(++tmp), PMU_EVENT_SYMBOL_SUFFIX); |
| 968 | len += 2; |
| 969 | } else { |
| 970 | SET_SYMBOL(strdup(alias->name), PMU_EVENT_SYMBOL); |
| 971 | len++; |
| 972 | } |
| 973 | } |
| 974 | qsort(perf_pmu_events_list, len, |
| 975 | sizeof(struct perf_pmu_event_symbol), comp_pmu); |
| 976 | |
| 977 | return; |
| 978 | err: |
| 979 | perf_pmu__parse_cleanup(); |
| 980 | } |
| 981 | |
| 982 | enum perf_pmu_event_symbol_type |
| 983 | perf_pmu__parse_check(const char *name) |
| 984 | { |
| 985 | struct perf_pmu_event_symbol p, *r; |
| 986 | |
| 987 | /* scan kernel pmu events from sysfs if needed */ |
| 988 | if (perf_pmu_events_list_num == 0) |
| 989 | perf_pmu__parse_init(); |
| 990 | /* |
| 991 | * name "cpu" could be prefix of cpu-cycles or cpu// events. |
| 992 | * cpu-cycles has been handled by hardcode. |
| 993 | * So it must be cpu// events, not kernel pmu event. |
| 994 | */ |
| 995 | if ((perf_pmu_events_list_num <= 0) || !strcmp(name, "cpu")) |
| 996 | return PMU_EVENT_SYMBOL_ERR; |
| 997 | |
| 998 | p.symbol = strdup(name); |
| 999 | r = bsearch(&p, perf_pmu_events_list, |
| 1000 | (size_t) perf_pmu_events_list_num, |
| 1001 | sizeof(struct perf_pmu_event_symbol), comp_pmu); |
| 1002 | free(p.symbol); |
| 1003 | return r ? r->type : PMU_EVENT_SYMBOL_ERR; |
| 1004 | } |
| 1005 | |
Jiri Olsa | 90e2b22 | 2012-06-15 14:31:40 +0800 | [diff] [blame] | 1006 | static int parse_events__scanner(const char *str, void *data, int start_token) |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 1007 | { |
| 1008 | YY_BUFFER_STATE buffer; |
| 1009 | void *scanner; |
| 1010 | int ret; |
| 1011 | |
Jiri Olsa | 90e2b22 | 2012-06-15 14:31:40 +0800 | [diff] [blame] | 1012 | ret = parse_events_lex_init_extra(start_token, &scanner); |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 1013 | if (ret) |
| 1014 | return ret; |
| 1015 | |
| 1016 | buffer = parse_events__scan_string(str, scanner); |
| 1017 | |
| 1018 | #ifdef PARSER_DEBUG |
| 1019 | parse_events_debug = 1; |
| 1020 | #endif |
| 1021 | ret = parse_events_parse(data, scanner); |
| 1022 | |
| 1023 | parse_events__flush_buffer(buffer, scanner); |
| 1024 | parse_events__delete_buffer(buffer, scanner); |
| 1025 | parse_events_lex_destroy(scanner); |
| 1026 | return ret; |
| 1027 | } |
| 1028 | |
Jiri Olsa | 90e2b22 | 2012-06-15 14:31:40 +0800 | [diff] [blame] | 1029 | /* |
| 1030 | * parse event config string, return a list of event terms. |
| 1031 | */ |
| 1032 | int parse_events_terms(struct list_head *terms, const char *str) |
| 1033 | { |
Arnaldo Carvalho de Melo | 23b6339 | 2013-01-18 16:56:57 -0300 | [diff] [blame] | 1034 | struct parse_events_terms data = { |
Jiri Olsa | 90e2b22 | 2012-06-15 14:31:40 +0800 | [diff] [blame] | 1035 | .terms = NULL, |
| 1036 | }; |
| 1037 | int ret; |
| 1038 | |
| 1039 | ret = parse_events__scanner(str, &data, PE_START_TERMS); |
| 1040 | if (!ret) { |
| 1041 | list_splice(data.terms, terms); |
Arnaldo Carvalho de Melo | 74cf249 | 2013-12-27 16:55:14 -0300 | [diff] [blame] | 1042 | zfree(&data.terms); |
Jiri Olsa | 90e2b22 | 2012-06-15 14:31:40 +0800 | [diff] [blame] | 1043 | return 0; |
| 1044 | } |
| 1045 | |
Adrian Hunter | b2c34fd | 2013-07-04 16:20:23 +0300 | [diff] [blame] | 1046 | if (data.terms) |
| 1047 | parse_events__free_terms(data.terms); |
Jiri Olsa | 90e2b22 | 2012-06-15 14:31:40 +0800 | [diff] [blame] | 1048 | return ret; |
| 1049 | } |
| 1050 | |
Jiri Olsa | b39b839 | 2015-04-22 21:10:16 +0200 | [diff] [blame] | 1051 | int parse_events(struct perf_evlist *evlist, const char *str, |
| 1052 | struct parse_events_error *err) |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 1053 | { |
Arnaldo Carvalho de Melo | 23b6339 | 2013-01-18 16:56:57 -0300 | [diff] [blame] | 1054 | struct parse_events_evlist data = { |
Jiri Olsa | b39b839 | 2015-04-22 21:10:16 +0200 | [diff] [blame] | 1055 | .list = LIST_HEAD_INIT(data.list), |
| 1056 | .idx = evlist->nr_entries, |
| 1057 | .error = err, |
Jiri Olsa | 46010ab | 2012-06-15 14:31:38 +0800 | [diff] [blame] | 1058 | }; |
Jiri Olsa | 46010ab | 2012-06-15 14:31:38 +0800 | [diff] [blame] | 1059 | int ret; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 1060 | |
Jiri Olsa | 90e2b22 | 2012-06-15 14:31:40 +0800 | [diff] [blame] | 1061 | ret = parse_events__scanner(str, &data, PE_START_EVENTS); |
Kan Liang | dcb4e10 | 2014-10-07 11:08:50 -0400 | [diff] [blame] | 1062 | perf_pmu__parse_cleanup(); |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 1063 | if (!ret) { |
Jiri Olsa | 46010ab | 2012-06-15 14:31:38 +0800 | [diff] [blame] | 1064 | int entries = data.idx - evlist->nr_entries; |
| 1065 | perf_evlist__splice_list_tail(evlist, &data.list, entries); |
Namhyung Kim | 97f63e4 | 2013-01-22 18:09:29 +0900 | [diff] [blame] | 1066 | evlist->nr_groups += data.nr_groups; |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 1067 | return 0; |
| 1068 | } |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 1069 | |
Jiri Olsa | 5d7be90 | 2012-03-20 19:15:40 +0100 | [diff] [blame] | 1070 | /* |
| 1071 | * There are 2 users - builtin-record and builtin-test objects. |
| 1072 | * Both call perf_evlist__delete in case of error, so we dont |
| 1073 | * need to bother. |
| 1074 | */ |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 1075 | return ret; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 1076 | } |
| 1077 | |
Jiri Olsa | b39b839 | 2015-04-22 21:10:16 +0200 | [diff] [blame] | 1078 | #define MAX_WIDTH 1000 |
| 1079 | static int get_term_width(void) |
| 1080 | { |
| 1081 | struct winsize ws; |
| 1082 | |
| 1083 | get_term_dimensions(&ws); |
| 1084 | return ws.ws_col > MAX_WIDTH ? MAX_WIDTH : ws.ws_col; |
| 1085 | } |
| 1086 | |
| 1087 | static void parse_events_print_error(struct parse_events_error *err, |
| 1088 | const char *event) |
| 1089 | { |
| 1090 | const char *str = "invalid or unsupported event: "; |
| 1091 | char _buf[MAX_WIDTH]; |
| 1092 | char *buf = (char *) event; |
| 1093 | int idx = 0; |
| 1094 | |
| 1095 | if (err->str) { |
| 1096 | /* -2 for extra '' in the final fprintf */ |
| 1097 | int width = get_term_width() - 2; |
| 1098 | int len_event = strlen(event); |
| 1099 | int len_str, max_len, cut = 0; |
| 1100 | |
| 1101 | /* |
| 1102 | * Maximum error index indent, we will cut |
| 1103 | * the event string if it's bigger. |
| 1104 | */ |
| 1105 | int max_err_idx = 10; |
| 1106 | |
| 1107 | /* |
| 1108 | * Let's be specific with the message when |
| 1109 | * we have the precise error. |
| 1110 | */ |
| 1111 | str = "event syntax error: "; |
| 1112 | len_str = strlen(str); |
| 1113 | max_len = width - len_str; |
| 1114 | |
| 1115 | buf = _buf; |
| 1116 | |
| 1117 | /* We're cutting from the beggining. */ |
| 1118 | if (err->idx > max_err_idx) |
| 1119 | cut = err->idx - max_err_idx; |
| 1120 | |
| 1121 | strncpy(buf, event + cut, max_len); |
| 1122 | |
| 1123 | /* Mark cut parts with '..' on both sides. */ |
| 1124 | if (cut) |
| 1125 | buf[0] = buf[1] = '.'; |
| 1126 | |
| 1127 | if ((len_event - cut) > max_len) { |
| 1128 | buf[max_len - 1] = buf[max_len - 2] = '.'; |
| 1129 | buf[max_len] = 0; |
| 1130 | } |
| 1131 | |
| 1132 | idx = len_str + err->idx - cut; |
| 1133 | } |
| 1134 | |
| 1135 | fprintf(stderr, "%s'%s'\n", str, buf); |
| 1136 | if (idx) { |
| 1137 | fprintf(stderr, "%*s\\___ %s\n", idx + 1, "", err->str); |
| 1138 | if (err->help) |
| 1139 | fprintf(stderr, "\n%s\n", err->help); |
| 1140 | free(err->str); |
| 1141 | free(err->help); |
| 1142 | } |
| 1143 | |
| 1144 | fprintf(stderr, "Run 'perf list' for a list of valid events\n"); |
| 1145 | } |
| 1146 | |
| 1147 | #undef MAX_WIDTH |
| 1148 | |
Jiri Olsa | f120f9d | 2011-07-14 11:25:32 +0200 | [diff] [blame] | 1149 | int parse_events_option(const struct option *opt, const char *str, |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 1150 | int unset __maybe_unused) |
Jiri Olsa | f120f9d | 2011-07-14 11:25:32 +0200 | [diff] [blame] | 1151 | { |
| 1152 | struct perf_evlist *evlist = *(struct perf_evlist **)opt->value; |
Jiri Olsa | b39b839 | 2015-04-22 21:10:16 +0200 | [diff] [blame] | 1153 | struct parse_events_error err = { .idx = 0, }; |
| 1154 | int ret = parse_events(evlist, str, &err); |
Andi Kleen | 9175ce1 | 2012-10-26 13:30:06 -0700 | [diff] [blame] | 1155 | |
Jiri Olsa | b39b839 | 2015-04-22 21:10:16 +0200 | [diff] [blame] | 1156 | if (ret) |
| 1157 | parse_events_print_error(&err, str); |
| 1158 | |
Andi Kleen | 9175ce1 | 2012-10-26 13:30:06 -0700 | [diff] [blame] | 1159 | return ret; |
Jiri Olsa | f120f9d | 2011-07-14 11:25:32 +0200 | [diff] [blame] | 1160 | } |
| 1161 | |
Arnaldo Carvalho de Melo | 361c99a | 2011-01-11 20:56:53 -0200 | [diff] [blame] | 1162 | int parse_filter(const struct option *opt, const char *str, |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 1163 | int unset __maybe_unused) |
Li Zefan | c171b55 | 2009-10-15 11:22:07 +0800 | [diff] [blame] | 1164 | { |
Arnaldo Carvalho de Melo | 361c99a | 2011-01-11 20:56:53 -0200 | [diff] [blame] | 1165 | struct perf_evlist *evlist = *(struct perf_evlist **)opt->value; |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 1166 | struct perf_evsel *last = NULL; |
Li Zefan | c171b55 | 2009-10-15 11:22:07 +0800 | [diff] [blame] | 1167 | |
Arnaldo Carvalho de Melo | 361c99a | 2011-01-11 20:56:53 -0200 | [diff] [blame] | 1168 | if (evlist->nr_entries > 0) |
Arnaldo Carvalho de Melo | 0c21f73 | 2012-08-14 16:42:15 -0300 | [diff] [blame] | 1169 | last = perf_evlist__last(evlist); |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 1170 | |
| 1171 | if (last == NULL || last->attr.type != PERF_TYPE_TRACEPOINT) { |
Li Zefan | c171b55 | 2009-10-15 11:22:07 +0800 | [diff] [blame] | 1172 | fprintf(stderr, |
Arnaldo Carvalho de Melo | 281f92f | 2014-10-01 15:05:32 -0300 | [diff] [blame] | 1173 | "--filter option should follow a -e tracepoint option\n"); |
Li Zefan | c171b55 | 2009-10-15 11:22:07 +0800 | [diff] [blame] | 1174 | return -1; |
| 1175 | } |
| 1176 | |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 1177 | last->filter = strdup(str); |
| 1178 | if (last->filter == NULL) { |
Li Zefan | c171b55 | 2009-10-15 11:22:07 +0800 | [diff] [blame] | 1179 | fprintf(stderr, "not enough memory to hold filter string\n"); |
| 1180 | return -1; |
| 1181 | } |
Li Zefan | c171b55 | 2009-10-15 11:22:07 +0800 | [diff] [blame] | 1182 | |
| 1183 | return 0; |
| 1184 | } |
| 1185 | |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 1186 | static const char * const event_type_descriptors[] = { |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 1187 | "Hardware event", |
| 1188 | "Software event", |
| 1189 | "Tracepoint event", |
| 1190 | "Hardware cache event", |
Liming Wang | 41bdcb2 | 2009-12-29 16:37:07 +0800 | [diff] [blame] | 1191 | "Raw hardware event descriptor", |
| 1192 | "Hardware breakpoint", |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 1193 | }; |
| 1194 | |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 1195 | static int cmp_string(const void *a, const void *b) |
| 1196 | { |
| 1197 | const char * const *as = a; |
| 1198 | const char * const *bs = b; |
| 1199 | |
| 1200 | return strcmp(*as, *bs); |
| 1201 | } |
| 1202 | |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 1203 | /* |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 1204 | * Print the events from <debugfs_mount_point>/tracing/events |
| 1205 | */ |
| 1206 | |
Frederic Weisbecker | a3277d2 | 2012-08-09 16:31:52 +0200 | [diff] [blame] | 1207 | void print_tracepoint_events(const char *subsys_glob, const char *event_glob, |
| 1208 | bool name_only) |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 1209 | { |
| 1210 | DIR *sys_dir, *evt_dir; |
| 1211 | struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 1212 | char evt_path[MAXPATHLEN]; |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 1213 | char dir_path[MAXPATHLEN]; |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 1214 | char **evt_list = NULL; |
| 1215 | unsigned int evt_i = 0, evt_num = 0; |
| 1216 | bool evt_num_known = false; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 1217 | |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 1218 | restart: |
Arnaldo Carvalho de Melo | ebf294b | 2011-11-16 14:03:07 -0200 | [diff] [blame] | 1219 | sys_dir = opendir(tracing_events_path); |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 1220 | if (!sys_dir) |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 1221 | return; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 1222 | |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 1223 | if (evt_num_known) { |
| 1224 | evt_list = zalloc(sizeof(char *) * evt_num); |
| 1225 | if (!evt_list) |
| 1226 | goto out_close_sys_dir; |
| 1227 | } |
| 1228 | |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 1229 | for_each_subsystem(sys_dir, sys_dirent, sys_next) { |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1230 | if (subsys_glob != NULL && |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 1231 | !strglobmatch(sys_dirent.d_name, subsys_glob)) |
| 1232 | continue; |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 1233 | |
Arnaldo Carvalho de Melo | ebf294b | 2011-11-16 14:03:07 -0200 | [diff] [blame] | 1234 | snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path, |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 1235 | sys_dirent.d_name); |
| 1236 | evt_dir = opendir(dir_path); |
| 1237 | if (!evt_dir) |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 1238 | continue; |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 1239 | |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 1240 | for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1241 | if (event_glob != NULL && |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 1242 | !strglobmatch(evt_dirent.d_name, event_glob)) |
| 1243 | continue; |
| 1244 | |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 1245 | if (!evt_num_known) { |
| 1246 | evt_num++; |
Frederic Weisbecker | a3277d2 | 2012-08-09 16:31:52 +0200 | [diff] [blame] | 1247 | continue; |
| 1248 | } |
| 1249 | |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 1250 | snprintf(evt_path, MAXPATHLEN, "%s:%s", |
| 1251 | sys_dirent.d_name, evt_dirent.d_name); |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 1252 | |
| 1253 | evt_list[evt_i] = strdup(evt_path); |
| 1254 | if (evt_list[evt_i] == NULL) |
| 1255 | goto out_close_evt_dir; |
| 1256 | evt_i++; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 1257 | } |
| 1258 | closedir(evt_dir); |
| 1259 | } |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 1260 | closedir(sys_dir); |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 1261 | |
| 1262 | if (!evt_num_known) { |
| 1263 | evt_num_known = true; |
| 1264 | goto restart; |
| 1265 | } |
| 1266 | qsort(evt_list, evt_num, sizeof(char *), cmp_string); |
| 1267 | evt_i = 0; |
| 1268 | while (evt_i < evt_num) { |
| 1269 | if (name_only) { |
| 1270 | printf("%s ", evt_list[evt_i++]); |
| 1271 | continue; |
| 1272 | } |
| 1273 | printf(" %-50s [%s]\n", evt_list[evt_i++], |
| 1274 | event_type_descriptors[PERF_TYPE_TRACEPOINT]); |
| 1275 | } |
| 1276 | if (evt_num) |
| 1277 | printf("\n"); |
| 1278 | |
| 1279 | out_free: |
| 1280 | evt_num = evt_i; |
| 1281 | for (evt_i = 0; evt_i < evt_num; evt_i++) |
| 1282 | zfree(&evt_list[evt_i]); |
| 1283 | zfree(&evt_list); |
| 1284 | return; |
| 1285 | |
| 1286 | out_close_evt_dir: |
| 1287 | closedir(evt_dir); |
| 1288 | out_close_sys_dir: |
| 1289 | closedir(sys_dir); |
| 1290 | |
| 1291 | printf("FATAL: not enough memory to print %s\n", |
| 1292 | event_type_descriptors[PERF_TYPE_TRACEPOINT]); |
| 1293 | if (evt_list) |
| 1294 | goto out_free; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 1295 | } |
| 1296 | |
| 1297 | /* |
Thomas Renninger | 20c457b | 2011-01-03 17:50:45 +0100 | [diff] [blame] | 1298 | * Check whether event is in <debugfs_mount_point>/tracing/events |
| 1299 | */ |
| 1300 | |
| 1301 | int is_valid_tracepoint(const char *event_string) |
| 1302 | { |
| 1303 | DIR *sys_dir, *evt_dir; |
| 1304 | struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; |
| 1305 | char evt_path[MAXPATHLEN]; |
| 1306 | char dir_path[MAXPATHLEN]; |
| 1307 | |
Arnaldo Carvalho de Melo | ebf294b | 2011-11-16 14:03:07 -0200 | [diff] [blame] | 1308 | sys_dir = opendir(tracing_events_path); |
Thomas Renninger | 20c457b | 2011-01-03 17:50:45 +0100 | [diff] [blame] | 1309 | if (!sys_dir) |
| 1310 | return 0; |
| 1311 | |
| 1312 | for_each_subsystem(sys_dir, sys_dirent, sys_next) { |
| 1313 | |
Arnaldo Carvalho de Melo | ebf294b | 2011-11-16 14:03:07 -0200 | [diff] [blame] | 1314 | snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path, |
Thomas Renninger | 20c457b | 2011-01-03 17:50:45 +0100 | [diff] [blame] | 1315 | sys_dirent.d_name); |
| 1316 | evt_dir = opendir(dir_path); |
| 1317 | if (!evt_dir) |
| 1318 | continue; |
| 1319 | |
| 1320 | for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { |
| 1321 | snprintf(evt_path, MAXPATHLEN, "%s:%s", |
| 1322 | sys_dirent.d_name, evt_dirent.d_name); |
| 1323 | if (!strcmp(evt_path, event_string)) { |
| 1324 | closedir(evt_dir); |
| 1325 | closedir(sys_dir); |
| 1326 | return 1; |
| 1327 | } |
| 1328 | } |
| 1329 | closedir(evt_dir); |
| 1330 | } |
| 1331 | closedir(sys_dir); |
| 1332 | return 0; |
| 1333 | } |
| 1334 | |
Namhyung Kim | b41f1ce | 2013-08-27 11:41:53 +0900 | [diff] [blame] | 1335 | static bool is_event_supported(u8 type, unsigned config) |
| 1336 | { |
| 1337 | bool ret = true; |
Vince Weaver | 88fee52 | 2013-12-30 15:39:45 -0500 | [diff] [blame] | 1338 | int open_return; |
Namhyung Kim | b41f1ce | 2013-08-27 11:41:53 +0900 | [diff] [blame] | 1339 | struct perf_evsel *evsel; |
| 1340 | struct perf_event_attr attr = { |
| 1341 | .type = type, |
| 1342 | .config = config, |
| 1343 | .disabled = 1, |
Namhyung Kim | b41f1ce | 2013-08-27 11:41:53 +0900 | [diff] [blame] | 1344 | }; |
| 1345 | struct { |
| 1346 | struct thread_map map; |
| 1347 | int threads[1]; |
| 1348 | } tmap = { |
| 1349 | .map.nr = 1, |
| 1350 | .threads = { 0 }, |
| 1351 | }; |
| 1352 | |
Arnaldo Carvalho de Melo | ef50383 | 2013-11-07 16:41:19 -0300 | [diff] [blame] | 1353 | evsel = perf_evsel__new(&attr); |
Namhyung Kim | b41f1ce | 2013-08-27 11:41:53 +0900 | [diff] [blame] | 1354 | if (evsel) { |
Vince Weaver | 88fee52 | 2013-12-30 15:39:45 -0500 | [diff] [blame] | 1355 | open_return = perf_evsel__open(evsel, NULL, &tmap.map); |
| 1356 | ret = open_return >= 0; |
| 1357 | |
| 1358 | if (open_return == -EACCES) { |
| 1359 | /* |
| 1360 | * This happens if the paranoid value |
| 1361 | * /proc/sys/kernel/perf_event_paranoid is set to 2 |
| 1362 | * Re-run with exclude_kernel set; we don't do that |
| 1363 | * by default as some ARM machines do not support it. |
| 1364 | * |
| 1365 | */ |
| 1366 | evsel->attr.exclude_kernel = 1; |
| 1367 | ret = perf_evsel__open(evsel, NULL, &tmap.map) >= 0; |
| 1368 | } |
Namhyung Kim | b41f1ce | 2013-08-27 11:41:53 +0900 | [diff] [blame] | 1369 | perf_evsel__delete(evsel); |
| 1370 | } |
| 1371 | |
| 1372 | return ret; |
| 1373 | } |
| 1374 | |
Frederic Weisbecker | a3277d2 | 2012-08-09 16:31:52 +0200 | [diff] [blame] | 1375 | int print_hwcache_events(const char *event_glob, bool name_only) |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 1376 | { |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 1377 | unsigned int type, op, i, evt_i = 0, evt_num = 0; |
Arnaldo Carvalho de Melo | 0b668bc | 2012-06-11 14:08:07 -0300 | [diff] [blame] | 1378 | char name[64]; |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 1379 | char **evt_list = NULL; |
| 1380 | bool evt_num_known = false; |
| 1381 | |
| 1382 | restart: |
| 1383 | if (evt_num_known) { |
| 1384 | evt_list = zalloc(sizeof(char *) * evt_num); |
| 1385 | if (!evt_list) |
| 1386 | goto out_enomem; |
| 1387 | } |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 1388 | |
| 1389 | for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) { |
| 1390 | for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) { |
| 1391 | /* skip invalid cache type */ |
Arnaldo Carvalho de Melo | 0b668bc | 2012-06-11 14:08:07 -0300 | [diff] [blame] | 1392 | if (!perf_evsel__is_cache_op_valid(type, op)) |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 1393 | continue; |
| 1394 | |
| 1395 | for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) { |
Arnaldo Carvalho de Melo | 0b668bc | 2012-06-11 14:08:07 -0300 | [diff] [blame] | 1396 | __perf_evsel__hw_cache_type_op_res_name(type, op, i, |
| 1397 | name, sizeof(name)); |
Ingo Molnar | 947b4ad | 2011-04-29 22:52:42 +0200 | [diff] [blame] | 1398 | if (event_glob != NULL && !strglobmatch(name, event_glob)) |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 1399 | continue; |
| 1400 | |
Namhyung Kim | b41f1ce | 2013-08-27 11:41:53 +0900 | [diff] [blame] | 1401 | if (!is_event_supported(PERF_TYPE_HW_CACHE, |
| 1402 | type | (op << 8) | (i << 16))) |
| 1403 | continue; |
| 1404 | |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 1405 | if (!evt_num_known) { |
| 1406 | evt_num++; |
| 1407 | continue; |
| 1408 | } |
| 1409 | |
| 1410 | evt_list[evt_i] = strdup(name); |
| 1411 | if (evt_list[evt_i] == NULL) |
| 1412 | goto out_enomem; |
| 1413 | evt_i++; |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 1414 | } |
| 1415 | } |
| 1416 | } |
| 1417 | |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 1418 | if (!evt_num_known) { |
| 1419 | evt_num_known = true; |
| 1420 | goto restart; |
| 1421 | } |
| 1422 | qsort(evt_list, evt_num, sizeof(char *), cmp_string); |
| 1423 | evt_i = 0; |
| 1424 | while (evt_i < evt_num) { |
| 1425 | if (name_only) { |
| 1426 | printf("%s ", evt_list[evt_i++]); |
| 1427 | continue; |
| 1428 | } |
| 1429 | printf(" %-50s [%s]\n", evt_list[evt_i++], |
| 1430 | event_type_descriptors[PERF_TYPE_HW_CACHE]); |
| 1431 | } |
| 1432 | if (evt_num) |
Andi Kleen | dc098b3 | 2013-04-20 11:02:29 -0700 | [diff] [blame] | 1433 | printf("\n"); |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 1434 | |
| 1435 | out_free: |
| 1436 | evt_num = evt_i; |
| 1437 | for (evt_i = 0; evt_i < evt_num; evt_i++) |
| 1438 | zfree(&evt_list[evt_i]); |
| 1439 | zfree(&evt_list); |
| 1440 | return evt_num; |
| 1441 | |
| 1442 | out_enomem: |
| 1443 | printf("FATAL: not enough memory to print %s\n", event_type_descriptors[PERF_TYPE_HW_CACHE]); |
| 1444 | if (evt_list) |
| 1445 | goto out_free; |
| 1446 | return evt_num; |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 1447 | } |
| 1448 | |
Yunlong Song | 705750f | 2015-02-27 18:21:27 +0800 | [diff] [blame] | 1449 | void print_symbol_events(const char *event_glob, unsigned type, |
Frederic Weisbecker | a3277d2 | 2012-08-09 16:31:52 +0200 | [diff] [blame] | 1450 | struct event_symbol *syms, unsigned max, |
| 1451 | bool name_only) |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 1452 | { |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 1453 | unsigned int i, evt_i = 0, evt_num = 0; |
Ingo Molnar | 947b4ad | 2011-04-29 22:52:42 +0200 | [diff] [blame] | 1454 | char name[MAX_NAME_LEN]; |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 1455 | char **evt_list = NULL; |
| 1456 | bool evt_num_known = false; |
| 1457 | |
| 1458 | restart: |
| 1459 | if (evt_num_known) { |
| 1460 | evt_list = zalloc(sizeof(char *) * evt_num); |
| 1461 | if (!evt_list) |
| 1462 | goto out_enomem; |
| 1463 | syms -= max; |
| 1464 | } |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 1465 | |
Jiri Olsa | 1dc1276 | 2012-07-04 00:00:44 +0200 | [diff] [blame] | 1466 | for (i = 0; i < max; i++, syms++) { |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 1467 | |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1468 | if (event_glob != NULL && |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 1469 | !(strglobmatch(syms->symbol, event_glob) || |
| 1470 | (syms->alias && strglobmatch(syms->alias, event_glob)))) |
| 1471 | continue; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 1472 | |
Namhyung Kim | b41f1ce | 2013-08-27 11:41:53 +0900 | [diff] [blame] | 1473 | if (!is_event_supported(type, i)) |
| 1474 | continue; |
| 1475 | |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 1476 | if (!evt_num_known) { |
| 1477 | evt_num++; |
Frederic Weisbecker | a3277d2 | 2012-08-09 16:31:52 +0200 | [diff] [blame] | 1478 | continue; |
| 1479 | } |
| 1480 | |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 1481 | if (!name_only && strlen(syms->alias)) |
Ingo Molnar | 947b4ad | 2011-04-29 22:52:42 +0200 | [diff] [blame] | 1482 | 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] | 1483 | else |
Ingo Molnar | 947b4ad | 2011-04-29 22:52:42 +0200 | [diff] [blame] | 1484 | strncpy(name, syms->symbol, MAX_NAME_LEN); |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 1485 | |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 1486 | evt_list[evt_i] = strdup(name); |
| 1487 | if (evt_list[evt_i] == NULL) |
| 1488 | goto out_enomem; |
| 1489 | evt_i++; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 1490 | } |
| 1491 | |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 1492 | if (!evt_num_known) { |
| 1493 | evt_num_known = true; |
| 1494 | goto restart; |
| 1495 | } |
| 1496 | qsort(evt_list, evt_num, sizeof(char *), cmp_string); |
| 1497 | evt_i = 0; |
| 1498 | while (evt_i < evt_num) { |
| 1499 | if (name_only) { |
| 1500 | printf("%s ", evt_list[evt_i++]); |
| 1501 | continue; |
| 1502 | } |
| 1503 | printf(" %-50s [%s]\n", evt_list[evt_i++], event_type_descriptors[type]); |
| 1504 | } |
| 1505 | if (evt_num) |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 1506 | printf("\n"); |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 1507 | |
| 1508 | out_free: |
| 1509 | evt_num = evt_i; |
| 1510 | for (evt_i = 0; evt_i < evt_num; evt_i++) |
| 1511 | zfree(&evt_list[evt_i]); |
| 1512 | zfree(&evt_list); |
| 1513 | return; |
| 1514 | |
| 1515 | out_enomem: |
| 1516 | printf("FATAL: not enough memory to print %s\n", event_type_descriptors[type]); |
| 1517 | if (evt_list) |
| 1518 | goto out_free; |
Jiri Olsa | 1dc1276 | 2012-07-04 00:00:44 +0200 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | /* |
| 1522 | * Print the help text for the event symbols: |
| 1523 | */ |
Frederic Weisbecker | a3277d2 | 2012-08-09 16:31:52 +0200 | [diff] [blame] | 1524 | void print_events(const char *event_glob, bool name_only) |
Jiri Olsa | 1dc1276 | 2012-07-04 00:00:44 +0200 | [diff] [blame] | 1525 | { |
Jiri Olsa | 1dc1276 | 2012-07-04 00:00:44 +0200 | [diff] [blame] | 1526 | print_symbol_events(event_glob, PERF_TYPE_HARDWARE, |
Frederic Weisbecker | a3277d2 | 2012-08-09 16:31:52 +0200 | [diff] [blame] | 1527 | event_symbols_hw, PERF_COUNT_HW_MAX, name_only); |
Jiri Olsa | 1dc1276 | 2012-07-04 00:00:44 +0200 | [diff] [blame] | 1528 | |
| 1529 | print_symbol_events(event_glob, PERF_TYPE_SOFTWARE, |
Frederic Weisbecker | a3277d2 | 2012-08-09 16:31:52 +0200 | [diff] [blame] | 1530 | event_symbols_sw, PERF_COUNT_SW_MAX, name_only); |
Jiri Olsa | 1dc1276 | 2012-07-04 00:00:44 +0200 | [diff] [blame] | 1531 | |
Frederic Weisbecker | a3277d2 | 2012-08-09 16:31:52 +0200 | [diff] [blame] | 1532 | print_hwcache_events(event_glob, name_only); |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 1533 | |
Andi Kleen | dc098b3 | 2013-04-20 11:02:29 -0700 | [diff] [blame] | 1534 | print_pmu_events(event_glob, name_only); |
| 1535 | |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 1536 | if (event_glob != NULL) |
| 1537 | return; |
Jaswinder Singh Rajput | 73c24cb | 2009-07-01 18:36:18 +0530 | [diff] [blame] | 1538 | |
Frederic Weisbecker | a3277d2 | 2012-08-09 16:31:52 +0200 | [diff] [blame] | 1539 | if (!name_only) { |
Frederic Weisbecker | a3277d2 | 2012-08-09 16:31:52 +0200 | [diff] [blame] | 1540 | printf(" %-50s [%s]\n", |
| 1541 | "rNNN", |
| 1542 | event_type_descriptors[PERF_TYPE_RAW]); |
| 1543 | printf(" %-50s [%s]\n", |
| 1544 | "cpu/t1=v1[,t2=v2,t3 ...]/modifier", |
| 1545 | event_type_descriptors[PERF_TYPE_RAW]); |
Borislav Petkov | af3df2c | 2012-09-28 19:47:07 +0200 | [diff] [blame] | 1546 | printf(" (see 'man perf-list' on how to encode it)\n"); |
Frederic Weisbecker | a3277d2 | 2012-08-09 16:31:52 +0200 | [diff] [blame] | 1547 | printf("\n"); |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 1548 | |
Frederic Weisbecker | a3277d2 | 2012-08-09 16:31:52 +0200 | [diff] [blame] | 1549 | printf(" %-50s [%s]\n", |
Jacob Shin | 3741eb9 | 2014-05-29 17:26:51 +0200 | [diff] [blame] | 1550 | "mem:<addr>[/len][:access]", |
Liming Wang | 41bdcb2 | 2009-12-29 16:37:07 +0800 | [diff] [blame] | 1551 | event_type_descriptors[PERF_TYPE_BREAKPOINT]); |
Frederic Weisbecker | a3277d2 | 2012-08-09 16:31:52 +0200 | [diff] [blame] | 1552 | printf("\n"); |
| 1553 | } |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 1554 | |
Frederic Weisbecker | a3277d2 | 2012-08-09 16:31:52 +0200 | [diff] [blame] | 1555 | print_tracepoint_events(NULL, NULL, name_only); |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 1556 | } |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1557 | |
Arnaldo Carvalho de Melo | 6cee6cd | 2013-01-18 16:29:49 -0300 | [diff] [blame] | 1558 | int parse_events__is_hardcoded_term(struct parse_events_term *term) |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1559 | { |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 1560 | return term->type_term != PARSE_EVENTS__TERM_TYPE_USER; |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1561 | } |
| 1562 | |
Arnaldo Carvalho de Melo | 6cee6cd | 2013-01-18 16:29:49 -0300 | [diff] [blame] | 1563 | static int new_term(struct parse_events_term **_term, int type_val, |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 1564 | int type_term, char *config, |
Jiri Olsa | cecf3a2e | 2015-04-22 21:10:20 +0200 | [diff] [blame] | 1565 | char *str, u64 num, int err_term, int err_val) |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1566 | { |
Arnaldo Carvalho de Melo | 6cee6cd | 2013-01-18 16:29:49 -0300 | [diff] [blame] | 1567 | struct parse_events_term *term; |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1568 | |
| 1569 | term = zalloc(sizeof(*term)); |
| 1570 | if (!term) |
| 1571 | return -ENOMEM; |
| 1572 | |
| 1573 | INIT_LIST_HEAD(&term->list); |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 1574 | term->type_val = type_val; |
| 1575 | term->type_term = type_term; |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1576 | term->config = config; |
Jiri Olsa | cecf3a2e | 2015-04-22 21:10:20 +0200 | [diff] [blame] | 1577 | term->err_term = err_term; |
| 1578 | term->err_val = err_val; |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1579 | |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 1580 | switch (type_val) { |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1581 | case PARSE_EVENTS__TERM_TYPE_NUM: |
| 1582 | term->val.num = num; |
| 1583 | break; |
| 1584 | case PARSE_EVENTS__TERM_TYPE_STR: |
| 1585 | term->val.str = str; |
| 1586 | break; |
| 1587 | default: |
Adrian Hunter | 4be8be6 | 2013-07-04 16:20:24 +0300 | [diff] [blame] | 1588 | free(term); |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1589 | return -EINVAL; |
| 1590 | } |
| 1591 | |
| 1592 | *_term = term; |
| 1593 | return 0; |
| 1594 | } |
| 1595 | |
Arnaldo Carvalho de Melo | 6cee6cd | 2013-01-18 16:29:49 -0300 | [diff] [blame] | 1596 | int parse_events_term__num(struct parse_events_term **term, |
Jiri Olsa | cecf3a2e | 2015-04-22 21:10:20 +0200 | [diff] [blame] | 1597 | int type_term, char *config, u64 num, |
Adrian Hunter | bb78ce7 | 2015-05-19 16:05:42 +0300 | [diff] [blame] | 1598 | void *loc_term_, void *loc_val_) |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 1599 | { |
Adrian Hunter | bb78ce7 | 2015-05-19 16:05:42 +0300 | [diff] [blame] | 1600 | YYLTYPE *loc_term = loc_term_; |
| 1601 | YYLTYPE *loc_val = loc_val_; |
| 1602 | |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 1603 | return new_term(term, PARSE_EVENTS__TERM_TYPE_NUM, type_term, |
Jiri Olsa | cecf3a2e | 2015-04-22 21:10:20 +0200 | [diff] [blame] | 1604 | config, NULL, num, |
| 1605 | loc_term ? loc_term->first_column : 0, |
| 1606 | loc_val ? loc_val->first_column : 0); |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 1607 | } |
| 1608 | |
Arnaldo Carvalho de Melo | 6cee6cd | 2013-01-18 16:29:49 -0300 | [diff] [blame] | 1609 | int parse_events_term__str(struct parse_events_term **term, |
Jiri Olsa | cecf3a2e | 2015-04-22 21:10:20 +0200 | [diff] [blame] | 1610 | int type_term, char *config, char *str, |
Adrian Hunter | bb78ce7 | 2015-05-19 16:05:42 +0300 | [diff] [blame] | 1611 | void *loc_term_, void *loc_val_) |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 1612 | { |
Adrian Hunter | bb78ce7 | 2015-05-19 16:05:42 +0300 | [diff] [blame] | 1613 | YYLTYPE *loc_term = loc_term_; |
| 1614 | YYLTYPE *loc_val = loc_val_; |
| 1615 | |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 1616 | return new_term(term, PARSE_EVENTS__TERM_TYPE_STR, type_term, |
Jiri Olsa | cecf3a2e | 2015-04-22 21:10:20 +0200 | [diff] [blame] | 1617 | config, str, 0, |
| 1618 | loc_term ? loc_term->first_column : 0, |
| 1619 | loc_val ? loc_val->first_column : 0); |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 1620 | } |
| 1621 | |
Arnaldo Carvalho de Melo | 6cee6cd | 2013-01-18 16:29:49 -0300 | [diff] [blame] | 1622 | int parse_events_term__sym_hw(struct parse_events_term **term, |
Jiri Olsa | 1d33d6d | 2012-10-10 14:53:17 +0200 | [diff] [blame] | 1623 | char *config, unsigned idx) |
| 1624 | { |
| 1625 | struct event_symbol *sym; |
| 1626 | |
| 1627 | BUG_ON(idx >= PERF_COUNT_HW_MAX); |
| 1628 | sym = &event_symbols_hw[idx]; |
| 1629 | |
| 1630 | if (config) |
| 1631 | return new_term(term, PARSE_EVENTS__TERM_TYPE_STR, |
| 1632 | PARSE_EVENTS__TERM_TYPE_USER, config, |
Jiri Olsa | cecf3a2e | 2015-04-22 21:10:20 +0200 | [diff] [blame] | 1633 | (char *) sym->symbol, 0, 0, 0); |
Jiri Olsa | 1d33d6d | 2012-10-10 14:53:17 +0200 | [diff] [blame] | 1634 | else |
| 1635 | return new_term(term, PARSE_EVENTS__TERM_TYPE_STR, |
| 1636 | PARSE_EVENTS__TERM_TYPE_USER, |
Jiri Olsa | cecf3a2e | 2015-04-22 21:10:20 +0200 | [diff] [blame] | 1637 | (char *) "event", (char *) sym->symbol, |
| 1638 | 0, 0, 0); |
Jiri Olsa | 1d33d6d | 2012-10-10 14:53:17 +0200 | [diff] [blame] | 1639 | } |
| 1640 | |
Arnaldo Carvalho de Melo | 6cee6cd | 2013-01-18 16:29:49 -0300 | [diff] [blame] | 1641 | int parse_events_term__clone(struct parse_events_term **new, |
| 1642 | struct parse_events_term *term) |
Zheng Yan | a6146d5 | 2012-06-15 14:31:41 +0800 | [diff] [blame] | 1643 | { |
| 1644 | return new_term(new, term->type_val, term->type_term, term->config, |
Jiri Olsa | cecf3a2e | 2015-04-22 21:10:20 +0200 | [diff] [blame] | 1645 | term->val.str, term->val.num, |
| 1646 | term->err_term, term->err_val); |
Zheng Yan | a6146d5 | 2012-06-15 14:31:41 +0800 | [diff] [blame] | 1647 | } |
| 1648 | |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1649 | void parse_events__free_terms(struct list_head *terms) |
| 1650 | { |
Arnaldo Carvalho de Melo | 6cee6cd | 2013-01-18 16:29:49 -0300 | [diff] [blame] | 1651 | struct parse_events_term *term, *h; |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1652 | |
| 1653 | list_for_each_entry_safe(term, h, terms, list) |
| 1654 | free(term); |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1655 | } |
Jiri Olsa | b39b839 | 2015-04-22 21:10:16 +0200 | [diff] [blame] | 1656 | |
| 1657 | void parse_events_evlist_error(struct parse_events_evlist *data, |
| 1658 | int idx, const char *str) |
| 1659 | { |
| 1660 | struct parse_events_error *err = data->error; |
| 1661 | |
Adrian Hunter | a6ced2b | 2015-05-19 16:05:44 +0300 | [diff] [blame] | 1662 | if (!err) |
| 1663 | return; |
Jiri Olsa | b39b839 | 2015-04-22 21:10:16 +0200 | [diff] [blame] | 1664 | err->idx = idx; |
| 1665 | err->str = strdup(str); |
| 1666 | WARN_ONCE(!err->str, "WARNING: failed to allocate error string"); |
| 1667 | } |