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