Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
David Howells | d2709c7 | 2012-11-19 22:21:03 +0000 | [diff] [blame] | 2 | #include <linux/hw_breakpoint.h> |
Jiri Olsa | 8dd2a13 | 2015-09-07 10:38:06 +0200 | [diff] [blame] | 3 | #include <linux/err.h> |
Arnaldo Carvalho de Melo | 7f7c536 | 2019-07-04 11:32:27 -0300 | [diff] [blame] | 4 | #include <linux/zalloc.h> |
Arnaldo Carvalho de Melo | 76b31a2 | 2017-04-18 12:26:44 -0300 | [diff] [blame] | 5 | #include <dirent.h> |
Arnaldo Carvalho de Melo | a43783a | 2017-04-18 10:46:11 -0300 | [diff] [blame] | 6 | #include <errno.h> |
Arnaldo Carvalho de Melo | 86a5e0c | 2017-04-19 19:03:14 -0300 | [diff] [blame] | 7 | #include <sys/ioctl.h> |
Arnaldo Carvalho de Melo | bafae98 | 2018-01-22 16:42:16 -0300 | [diff] [blame] | 8 | #include <sys/types.h> |
| 9 | #include <sys/stat.h> |
| 10 | #include <fcntl.h> |
Arnaldo Carvalho de Melo | 391e420 | 2017-04-19 18:51:14 -0300 | [diff] [blame] | 11 | #include <sys/param.h> |
Arnaldo Carvalho de Melo | b0742e9 | 2017-04-18 11:08:10 -0300 | [diff] [blame] | 12 | #include "term.h" |
Arnaldo Carvalho de Melo | 4a3cec8 | 2019-08-30 11:11:01 -0300 | [diff] [blame] | 13 | #include "build-id.h" |
Arnaldo Carvalho de Melo | 361c99a | 2011-01-11 20:56:53 -0200 | [diff] [blame] | 14 | #include "evlist.h" |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 15 | #include "evsel.h" |
Arnaldo Carvalho de Melo | fa0d984 | 2019-08-30 12:52:25 -0300 | [diff] [blame] | 16 | #include <subcmd/pager.h> |
Josh Poimboeuf | 4b6ab94 | 2015-12-15 09:39:39 -0600 | [diff] [blame] | 17 | #include <subcmd/parse-options.h> |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 18 | #include "parse-events.h" |
Josh Poimboeuf | 4b6ab94 | 2015-12-15 09:39:39 -0600 | [diff] [blame] | 19 | #include <subcmd/exec-cmd.h> |
Arnaldo Carvalho de Melo | a067558 | 2017-04-17 16:51:59 -0300 | [diff] [blame] | 20 | #include "string2.h" |
Arnaldo Carvalho de Melo | 8ec20b1 | 2017-04-18 10:57:25 -0300 | [diff] [blame] | 21 | #include "strlist.h" |
Arnaldo Carvalho de Melo | 5aab621 | 2010-03-25 19:59:00 -0300 | [diff] [blame] | 22 | #include "symbol.h" |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 23 | #include "header.h" |
Wang Nan | 84c86ca | 2015-10-14 12:41:14 +0000 | [diff] [blame] | 24 | #include "bpf-loader.h" |
Masami Hiramatsu | 6e81c74 | 2014-08-14 02:22:36 +0000 | [diff] [blame] | 25 | #include "debug.h" |
Jiri Olsa | 592d5a6 | 2015-09-02 09:56:34 +0200 | [diff] [blame] | 26 | #include <api/fs/tracing_path.h> |
Jiri Olsa | 9c3516d | 2019-07-21 13:24:30 +0200 | [diff] [blame] | 27 | #include <perf/cpumap.h> |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 28 | #include "parse-events-bison.h" |
Jiri Olsa | 90e2b22 | 2012-06-15 14:31:40 +0800 | [diff] [blame] | 29 | #define YY_EXTRA_TYPE int |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 30 | #include "parse-events-flex.h" |
Jiri Olsa | 5f537a2 | 2012-03-15 20:09:18 +0100 | [diff] [blame] | 31 | #include "pmu.h" |
Namhyung Kim | b41f1ce | 2013-08-27 11:41:53 +0900 | [diff] [blame] | 32 | #include "thread_map.h" |
Masami Hiramatsu | 40218da | 2016-06-24 18:06:46 +0900 | [diff] [blame] | 33 | #include "probe-file.h" |
Jiri Olsa | b39b839 | 2015-04-22 21:10:16 +0200 | [diff] [blame] | 34 | #include "asm/bug.h" |
Andi Kleen | ac12f67 | 2016-10-12 14:02:06 -0700 | [diff] [blame] | 35 | #include "util/parse-branch-options.h" |
Andi Kleen | 71b0acc | 2017-08-31 12:40:32 -0700 | [diff] [blame] | 36 | #include "metricgroup.h" |
Arnaldo Carvalho de Melo | 95be9d1 | 2019-09-24 15:56:14 -0300 | [diff] [blame] | 37 | #include "util/evsel_config.h" |
Arnaldo Carvalho de Melo | 252a2fd | 2019-09-24 16:07:59 -0300 | [diff] [blame] | 38 | #include "util/event.h" |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 39 | |
| 40 | #define MAX_NAME_LEN 100 |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 41 | |
Jiri Olsa | 82ba1f2 | 2012-05-21 09:12:50 +0200 | [diff] [blame] | 42 | #ifdef PARSER_DEBUG |
| 43 | extern int parse_events_debug; |
| 44 | #endif |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 45 | int parse_events_parse(void *parse_state, void *scanner); |
He Kuang | e637d17 | 2015-09-28 03:52:16 +0000 | [diff] [blame] | 46 | static int get_config_terms(struct list_head *head_config, |
| 47 | struct list_head *head_terms __maybe_unused); |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 48 | |
Kan Liang | dcb4e10 | 2014-10-07 11:08:50 -0400 | [diff] [blame] | 49 | static struct perf_pmu_event_symbol *perf_pmu_events_list; |
| 50 | /* |
| 51 | * The variable indicates the number of supported pmu event symbols. |
| 52 | * 0 means not initialized and ready to init |
| 53 | * -1 means failed to init, don't try anymore |
| 54 | * >0 is the number of supported pmu event symbols |
| 55 | */ |
| 56 | static int perf_pmu_events_list_num; |
| 57 | |
Yunlong Song | 705750f | 2015-02-27 18:21:27 +0800 | [diff] [blame] | 58 | struct event_symbol event_symbols_hw[PERF_COUNT_HW_MAX] = { |
Jiri Olsa | 1dc12760 | 2012-07-04 00:00:44 +0200 | [diff] [blame] | 59 | [PERF_COUNT_HW_CPU_CYCLES] = { |
| 60 | .symbol = "cpu-cycles", |
| 61 | .alias = "cycles", |
| 62 | }, |
| 63 | [PERF_COUNT_HW_INSTRUCTIONS] = { |
| 64 | .symbol = "instructions", |
| 65 | .alias = "", |
| 66 | }, |
| 67 | [PERF_COUNT_HW_CACHE_REFERENCES] = { |
| 68 | .symbol = "cache-references", |
| 69 | .alias = "", |
| 70 | }, |
| 71 | [PERF_COUNT_HW_CACHE_MISSES] = { |
| 72 | .symbol = "cache-misses", |
| 73 | .alias = "", |
| 74 | }, |
| 75 | [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = { |
| 76 | .symbol = "branch-instructions", |
| 77 | .alias = "branches", |
| 78 | }, |
| 79 | [PERF_COUNT_HW_BRANCH_MISSES] = { |
| 80 | .symbol = "branch-misses", |
| 81 | .alias = "", |
| 82 | }, |
| 83 | [PERF_COUNT_HW_BUS_CYCLES] = { |
| 84 | .symbol = "bus-cycles", |
| 85 | .alias = "", |
| 86 | }, |
| 87 | [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = { |
| 88 | .symbol = "stalled-cycles-frontend", |
| 89 | .alias = "idle-cycles-frontend", |
| 90 | }, |
| 91 | [PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = { |
| 92 | .symbol = "stalled-cycles-backend", |
| 93 | .alias = "idle-cycles-backend", |
| 94 | }, |
| 95 | [PERF_COUNT_HW_REF_CPU_CYCLES] = { |
| 96 | .symbol = "ref-cycles", |
| 97 | .alias = "", |
| 98 | }, |
| 99 | }; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 100 | |
Yunlong Song | 705750f | 2015-02-27 18:21:27 +0800 | [diff] [blame] | 101 | struct event_symbol event_symbols_sw[PERF_COUNT_SW_MAX] = { |
Jiri Olsa | 1dc12760 | 2012-07-04 00:00:44 +0200 | [diff] [blame] | 102 | [PERF_COUNT_SW_CPU_CLOCK] = { |
| 103 | .symbol = "cpu-clock", |
| 104 | .alias = "", |
| 105 | }, |
| 106 | [PERF_COUNT_SW_TASK_CLOCK] = { |
| 107 | .symbol = "task-clock", |
| 108 | .alias = "", |
| 109 | }, |
| 110 | [PERF_COUNT_SW_PAGE_FAULTS] = { |
| 111 | .symbol = "page-faults", |
| 112 | .alias = "faults", |
| 113 | }, |
| 114 | [PERF_COUNT_SW_CONTEXT_SWITCHES] = { |
| 115 | .symbol = "context-switches", |
| 116 | .alias = "cs", |
| 117 | }, |
| 118 | [PERF_COUNT_SW_CPU_MIGRATIONS] = { |
| 119 | .symbol = "cpu-migrations", |
| 120 | .alias = "migrations", |
| 121 | }, |
| 122 | [PERF_COUNT_SW_PAGE_FAULTS_MIN] = { |
| 123 | .symbol = "minor-faults", |
| 124 | .alias = "", |
| 125 | }, |
| 126 | [PERF_COUNT_SW_PAGE_FAULTS_MAJ] = { |
| 127 | .symbol = "major-faults", |
| 128 | .alias = "", |
| 129 | }, |
| 130 | [PERF_COUNT_SW_ALIGNMENT_FAULTS] = { |
| 131 | .symbol = "alignment-faults", |
| 132 | .alias = "", |
| 133 | }, |
| 134 | [PERF_COUNT_SW_EMULATION_FAULTS] = { |
| 135 | .symbol = "emulation-faults", |
| 136 | .alias = "", |
| 137 | }, |
Adrian Hunter | d22d1a2 | 2013-08-31 21:50:52 +0300 | [diff] [blame] | 138 | [PERF_COUNT_SW_DUMMY] = { |
| 139 | .symbol = "dummy", |
| 140 | .alias = "", |
| 141 | }, |
Arnaldo Carvalho de Melo | bae9cc4 | 2015-11-27 15:54:33 -0300 | [diff] [blame] | 142 | [PERF_COUNT_SW_BPF_OUTPUT] = { |
| 143 | .symbol = "bpf-output", |
| 144 | .alias = "", |
| 145 | }, |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 146 | }; |
| 147 | |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 148 | #define __PERF_EVENT_FIELD(config, name) \ |
| 149 | ((config & PERF_EVENT_##name##_MASK) >> PERF_EVENT_##name##_SHIFT) |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 150 | |
Ingo Molnar | 1fc570a | 2011-04-27 05:20:22 +0200 | [diff] [blame] | 151 | #define PERF_EVENT_RAW(config) __PERF_EVENT_FIELD(config, RAW) |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 152 | #define PERF_EVENT_CONFIG(config) __PERF_EVENT_FIELD(config, CONFIG) |
Ingo Molnar | 1fc570a | 2011-04-27 05:20:22 +0200 | [diff] [blame] | 153 | #define PERF_EVENT_TYPE(config) __PERF_EVENT_FIELD(config, TYPE) |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 154 | #define PERF_EVENT_ID(config) __PERF_EVENT_FIELD(config, EVENT) |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 155 | |
Arnaldo Carvalho de Melo | 22a9f41 | 2016-04-08 11:53:02 -0300 | [diff] [blame] | 156 | #define for_each_subsystem(sys_dir, sys_dirent) \ |
| 157 | while ((sys_dirent = readdir(sys_dir)) != NULL) \ |
| 158 | if (sys_dirent->d_type == DT_DIR && \ |
| 159 | (strcmp(sys_dirent->d_name, ".")) && \ |
| 160 | (strcmp(sys_dirent->d_name, ".."))) |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 161 | |
Arnaldo Carvalho de Melo | c02cab2 | 2018-05-17 14:22:37 -0300 | [diff] [blame] | 162 | static int tp_event_has_id(const char *dir_path, struct dirent *evt_dir) |
Peter Zijlstra | ae07b63 | 2009-08-06 16:48:54 +0200 | [diff] [blame] | 163 | { |
| 164 | char evt_path[MAXPATHLEN]; |
| 165 | int fd; |
| 166 | |
Arnaldo Carvalho de Melo | c02cab2 | 2018-05-17 14:22:37 -0300 | [diff] [blame] | 167 | snprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path, evt_dir->d_name); |
Peter Zijlstra | ae07b63 | 2009-08-06 16:48:54 +0200 | [diff] [blame] | 168 | fd = open(evt_path, O_RDONLY); |
| 169 | if (fd < 0) |
| 170 | return -EINVAL; |
| 171 | close(fd); |
| 172 | |
| 173 | return 0; |
| 174 | } |
| 175 | |
Arnaldo Carvalho de Melo | c02cab2 | 2018-05-17 14:22:37 -0300 | [diff] [blame] | 176 | #define for_each_event(dir_path, evt_dir, evt_dirent) \ |
Arnaldo Carvalho de Melo | 22a9f41 | 2016-04-08 11:53:02 -0300 | [diff] [blame] | 177 | while ((evt_dirent = readdir(evt_dir)) != NULL) \ |
| 178 | if (evt_dirent->d_type == DT_DIR && \ |
| 179 | (strcmp(evt_dirent->d_name, ".")) && \ |
| 180 | (strcmp(evt_dirent->d_name, "..")) && \ |
Arnaldo Carvalho de Melo | c02cab2 | 2018-05-17 14:22:37 -0300 | [diff] [blame] | 181 | (!tp_event_has_id(dir_path, evt_dirent))) |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 182 | |
Li Zefan | 270bbbe | 2009-09-17 16:34:51 +0800 | [diff] [blame] | 183 | #define MAX_EVENT_LENGTH 512 |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 184 | |
Ian Rogers | 448d732 | 2019-10-30 15:34:39 -0700 | [diff] [blame] | 185 | void parse_events__handle_error(struct parse_events_error *err, int idx, |
| 186 | char *str, char *help) |
| 187 | { |
| 188 | if (WARN(!str, "WARNING: failed to provide error string\n")) { |
| 189 | free(help); |
| 190 | return; |
| 191 | } |
Ian Rogers | a910e46 | 2019-11-15 23:46:52 -0800 | [diff] [blame^] | 192 | switch (err->num_errors) { |
| 193 | case 0: |
| 194 | err->idx = idx; |
| 195 | err->str = str; |
| 196 | err->help = help; |
| 197 | break; |
| 198 | case 1: |
| 199 | err->first_idx = err->idx; |
| 200 | err->idx = idx; |
| 201 | err->first_str = err->str; |
| 202 | err->str = str; |
| 203 | err->first_help = err->help; |
| 204 | err->help = help; |
| 205 | break; |
| 206 | default: |
| 207 | WARN_ONCE(1, "WARNING: multiple event parsing errors\n"); |
| 208 | free(err->str); |
| 209 | err->str = str; |
| 210 | free(err->help); |
| 211 | err->help = help; |
| 212 | break; |
| 213 | } |
| 214 | err->num_errors++; |
Ian Rogers | 448d732 | 2019-10-30 15:34:39 -0700 | [diff] [blame] | 215 | } |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 216 | |
Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 217 | struct tracepoint_path *tracepoint_id_to_path(u64 config) |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 218 | { |
Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 219 | struct tracepoint_path *path = NULL; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 220 | DIR *sys_dir, *evt_dir; |
Arnaldo Carvalho de Melo | 22a9f41 | 2016-04-08 11:53:02 -0300 | [diff] [blame] | 221 | struct dirent *sys_dirent, *evt_dirent; |
Stephane Eranian | 8aa8a7c | 2012-03-13 16:51:02 +0100 | [diff] [blame] | 222 | char id_buf[24]; |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 223 | int fd; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 224 | u64 id; |
| 225 | char evt_path[MAXPATHLEN]; |
Arnaldo Carvalho de Melo | 25a7d914 | 2018-05-17 14:27:29 -0300 | [diff] [blame] | 226 | char *dir_path; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 227 | |
Arnaldo Carvalho de Melo | 7014e0e | 2018-05-17 14:42:39 -0300 | [diff] [blame] | 228 | sys_dir = tracing_events__opendir(); |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 229 | if (!sys_dir) |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 230 | return NULL; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 231 | |
Arnaldo Carvalho de Melo | 22a9f41 | 2016-04-08 11:53:02 -0300 | [diff] [blame] | 232 | for_each_subsystem(sys_dir, sys_dirent) { |
Arnaldo Carvalho de Melo | 25a7d914 | 2018-05-17 14:27:29 -0300 | [diff] [blame] | 233 | dir_path = get_events_file(sys_dirent->d_name); |
| 234 | if (!dir_path) |
| 235 | continue; |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 236 | evt_dir = opendir(dir_path); |
| 237 | if (!evt_dir) |
Arnaldo Carvalho de Melo | 25a7d914 | 2018-05-17 14:27:29 -0300 | [diff] [blame] | 238 | goto next; |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 239 | |
Arnaldo Carvalho de Melo | c02cab2 | 2018-05-17 14:22:37 -0300 | [diff] [blame] | 240 | for_each_event(dir_path, evt_dir, evt_dirent) { |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 241 | |
Jiri Olsa | 77f1815 | 2018-03-19 09:29:01 +0100 | [diff] [blame] | 242 | scnprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path, |
| 243 | evt_dirent->d_name); |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 244 | fd = open(evt_path, O_RDONLY); |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 245 | if (fd < 0) |
| 246 | continue; |
| 247 | if (read(fd, id_buf, sizeof(id_buf)) < 0) { |
| 248 | close(fd); |
| 249 | continue; |
| 250 | } |
| 251 | close(fd); |
| 252 | id = atoll(id_buf); |
| 253 | if (id == config) { |
Arnaldo Carvalho de Melo | 25a7d914 | 2018-05-17 14:27:29 -0300 | [diff] [blame] | 254 | put_events_file(dir_path); |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 255 | closedir(evt_dir); |
| 256 | closedir(sys_dir); |
Julia Lawall | 59b4cae | 2009-12-06 10:16:30 +0100 | [diff] [blame] | 257 | path = zalloc(sizeof(*path)); |
Taeung Song | 5aa365f | 2017-02-01 21:34:05 +0900 | [diff] [blame] | 258 | if (!path) |
| 259 | return NULL; |
Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 260 | path->system = malloc(MAX_EVENT_LENGTH); |
| 261 | if (!path->system) { |
| 262 | free(path); |
| 263 | return NULL; |
| 264 | } |
| 265 | path->name = malloc(MAX_EVENT_LENGTH); |
| 266 | if (!path->name) { |
Arnaldo Carvalho de Melo | 74cf249 | 2013-12-27 16:55:14 -0300 | [diff] [blame] | 267 | zfree(&path->system); |
Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 268 | free(path); |
| 269 | return NULL; |
| 270 | } |
Arnaldo Carvalho de Melo | 22a9f41 | 2016-04-08 11:53:02 -0300 | [diff] [blame] | 271 | strncpy(path->system, sys_dirent->d_name, |
Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 272 | MAX_EVENT_LENGTH); |
Arnaldo Carvalho de Melo | 22a9f41 | 2016-04-08 11:53:02 -0300 | [diff] [blame] | 273 | strncpy(path->name, evt_dirent->d_name, |
Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 274 | MAX_EVENT_LENGTH); |
| 275 | return path; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 276 | } |
| 277 | } |
| 278 | closedir(evt_dir); |
Arnaldo Carvalho de Melo | 25a7d914 | 2018-05-17 14:27:29 -0300 | [diff] [blame] | 279 | next: |
| 280 | put_events_file(dir_path); |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 281 | } |
| 282 | |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 283 | closedir(sys_dir); |
Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 284 | return NULL; |
| 285 | } |
| 286 | |
Namhyung Kim | e7c93f0 | 2013-06-26 16:14:05 +0900 | [diff] [blame] | 287 | struct tracepoint_path *tracepoint_name_to_path(const char *name) |
| 288 | { |
| 289 | struct tracepoint_path *path = zalloc(sizeof(*path)); |
| 290 | char *str = strchr(name, ':'); |
| 291 | |
| 292 | if (path == NULL || str == NULL) { |
| 293 | free(path); |
| 294 | return NULL; |
| 295 | } |
| 296 | |
| 297 | path->system = strndup(name, str - name); |
| 298 | path->name = strdup(str+1); |
| 299 | |
| 300 | if (path->system == NULL || path->name == NULL) { |
Arnaldo Carvalho de Melo | 74cf249 | 2013-12-27 16:55:14 -0300 | [diff] [blame] | 301 | zfree(&path->system); |
| 302 | zfree(&path->name); |
Taeung Song | 506fde1 | 2017-02-01 21:34:06 +0900 | [diff] [blame] | 303 | zfree(&path); |
Namhyung Kim | e7c93f0 | 2013-06-26 16:14:05 +0900 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | return path; |
| 307 | } |
| 308 | |
David Ahern | 1424dc9 | 2011-03-09 22:23:28 -0700 | [diff] [blame] | 309 | const char *event_type(int type) |
| 310 | { |
| 311 | switch (type) { |
| 312 | case PERF_TYPE_HARDWARE: |
| 313 | return "hardware"; |
| 314 | |
| 315 | case PERF_TYPE_SOFTWARE: |
| 316 | return "software"; |
| 317 | |
| 318 | case PERF_TYPE_TRACEPOINT: |
| 319 | return "tracepoint"; |
| 320 | |
| 321 | case PERF_TYPE_HW_CACHE: |
| 322 | return "hardware-cache"; |
| 323 | |
| 324 | default: |
| 325 | break; |
| 326 | } |
| 327 | |
| 328 | return "unknown"; |
| 329 | } |
| 330 | |
Wang Nan | e814fdd | 2016-02-19 11:43:59 +0000 | [diff] [blame] | 331 | static int parse_events__is_name_term(struct parse_events_term *term) |
| 332 | { |
| 333 | return term->type_term == PARSE_EVENTS__TERM_TYPE_NAME; |
| 334 | } |
Yan, Zheng | 7ae92e7 | 2012-09-10 15:53:50 +0800 | [diff] [blame] | 335 | |
Wang Nan | e814fdd | 2016-02-19 11:43:59 +0000 | [diff] [blame] | 336 | static char *get_config_name(struct list_head *head_terms) |
| 337 | { |
| 338 | struct parse_events_term *term; |
| 339 | |
| 340 | if (!head_terms) |
| 341 | return NULL; |
| 342 | |
| 343 | list_for_each_entry(term, head_terms, list) |
| 344 | if (parse_events__is_name_term(term)) |
| 345 | return term->val.str; |
| 346 | |
| 347 | return NULL; |
| 348 | } |
Yan, Zheng | 7ae92e7 | 2012-09-10 15:53:50 +0800 | [diff] [blame] | 349 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 350 | static struct evsel * |
Stephane Eranian | 410136f | 2013-11-12 17:58:49 +0100 | [diff] [blame] | 351 | __add_event(struct list_head *list, int *idx, |
| 352 | struct perf_event_attr *attr, |
Mark Rutland | 66ec1191 | 2017-10-06 19:38:22 +0100 | [diff] [blame] | 353 | char *name, struct perf_pmu *pmu, |
Andi Kleen | f0fbb11 | 2019-03-26 15:18:21 -0700 | [diff] [blame] | 354 | struct list_head *config_terms, bool auto_merge_stats, |
| 355 | const char *cpu_list) |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 356 | { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 357 | struct evsel *evsel; |
Jiri Olsa | f854839 | 2019-07-21 13:23:49 +0200 | [diff] [blame] | 358 | struct perf_cpu_map *cpus = pmu ? pmu->cpus : |
Jiri Olsa | 9c3516d | 2019-07-21 13:24:30 +0200 | [diff] [blame] | 359 | cpu_list ? perf_cpu_map__new(cpu_list) : NULL; |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 360 | |
| 361 | event_attr_init(attr); |
| 362 | |
Taeung Song | 75fc5ae | 2017-02-01 21:34:04 +0900 | [diff] [blame] | 363 | evsel = perf_evsel__new_idx(attr, *idx); |
David Ahern | c5cd8ac | 2013-07-02 13:27:25 -0600 | [diff] [blame] | 364 | if (!evsel) |
Stephane Eranian | 410136f | 2013-11-12 17:58:49 +0100 | [diff] [blame] | 365 | return NULL; |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 366 | |
Taeung Song | 75fc5ae | 2017-02-01 21:34:04 +0900 | [diff] [blame] | 367 | (*idx)++; |
Jiri Olsa | d400bd3 | 2019-07-21 13:24:37 +0200 | [diff] [blame] | 368 | evsel->core.cpus = perf_cpu_map__get(cpus); |
Jiri Olsa | fe1f61b | 2019-07-21 13:24:38 +0200 | [diff] [blame] | 369 | evsel->core.own_cpus = perf_cpu_map__get(cpus); |
Jiri Olsa | 648b5af | 2019-08-06 11:35:19 +0200 | [diff] [blame] | 370 | evsel->core.system_wide = pmu ? pmu->is_uncore : false; |
Arnaldo Carvalho de Melo | 63ce844 | 2017-08-31 15:32:18 -0300 | [diff] [blame] | 371 | evsel->auto_merge_stats = auto_merge_stats; |
Jiri Olsa | f30a79b | 2015-06-23 00:36:04 +0200 | [diff] [blame] | 372 | |
Arnaldo Carvalho de Melo | 9db1763 | 2012-06-12 13:45:00 -0300 | [diff] [blame] | 373 | if (name) |
| 374 | evsel->name = strdup(name); |
Jiri Olsa | 930a2e2 | 2015-07-29 05:42:10 -0400 | [diff] [blame] | 375 | |
| 376 | if (config_terms) |
| 377 | list_splice(config_terms, &evsel->config_terms); |
| 378 | |
Jiri Olsa | b27c4ec | 2019-07-21 13:24:22 +0200 | [diff] [blame] | 379 | list_add_tail(&evsel->core.node, list); |
Stephane Eranian | 410136f | 2013-11-12 17:58:49 +0100 | [diff] [blame] | 380 | return evsel; |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 381 | } |
| 382 | |
David Ahern | c5cd8ac | 2013-07-02 13:27:25 -0600 | [diff] [blame] | 383 | static int add_event(struct list_head *list, int *idx, |
Jiri Olsa | 930a2e2 | 2015-07-29 05:42:10 -0400 | [diff] [blame] | 384 | struct perf_event_attr *attr, char *name, |
| 385 | struct list_head *config_terms) |
Yan, Zheng | 7ae92e7 | 2012-09-10 15:53:50 +0800 | [diff] [blame] | 386 | { |
Andi Kleen | f0fbb11 | 2019-03-26 15:18:21 -0700 | [diff] [blame] | 387 | return __add_event(list, idx, attr, name, NULL, config_terms, false, NULL) ? 0 : -ENOMEM; |
| 388 | } |
| 389 | |
| 390 | static int add_event_tool(struct list_head *list, int *idx, |
| 391 | enum perf_tool_event tool_event) |
| 392 | { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 393 | struct evsel *evsel; |
Andi Kleen | f0fbb11 | 2019-03-26 15:18:21 -0700 | [diff] [blame] | 394 | struct perf_event_attr attr = { |
| 395 | .type = PERF_TYPE_SOFTWARE, |
| 396 | .config = PERF_COUNT_SW_DUMMY, |
| 397 | }; |
| 398 | |
| 399 | evsel = __add_event(list, idx, &attr, NULL, NULL, NULL, false, "0"); |
| 400 | if (!evsel) |
| 401 | return -ENOMEM; |
| 402 | evsel->tool_event = tool_event; |
| 403 | if (tool_event == PERF_TOOL_DURATION_TIME) |
| 404 | evsel->unit = strdup("ns"); |
| 405 | return 0; |
Yan, Zheng | 7ae92e7 | 2012-09-10 15:53:50 +0800 | [diff] [blame] | 406 | } |
| 407 | |
Arnaldo Carvalho de Melo | 0b668bc | 2012-06-11 14:08:07 -0300 | [diff] [blame] | 408 | 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] | 409 | { |
| 410 | int i, j; |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 411 | int n, longest = -1; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 412 | |
| 413 | for (i = 0; i < size; i++) { |
Arnaldo Carvalho de Melo | 0b668bc | 2012-06-11 14:08:07 -0300 | [diff] [blame] | 414 | for (j = 0; j < PERF_EVSEL__MAX_ALIASES && names[i][j]; j++) { |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 415 | n = strlen(names[i][j]); |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 416 | if (n > longest && !strncasecmp(str, names[i][j], n)) |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 417 | longest = n; |
| 418 | } |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 419 | if (longest > 0) |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 420 | return i; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 421 | } |
| 422 | |
Ingo Molnar | 8953645 | 2009-06-06 21:04:17 +0200 | [diff] [blame] | 423 | return -1; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 424 | } |
| 425 | |
Wang Nan | 43d0b97 | 2016-02-19 11:44:01 +0000 | [diff] [blame] | 426 | typedef int config_term_func_t(struct perf_event_attr *attr, |
| 427 | struct parse_events_term *term, |
| 428 | struct parse_events_error *err); |
| 429 | static int config_term_common(struct perf_event_attr *attr, |
| 430 | struct parse_events_term *term, |
| 431 | struct parse_events_error *err); |
| 432 | static int config_attr(struct perf_event_attr *attr, |
| 433 | struct list_head *head, |
| 434 | struct parse_events_error *err, |
| 435 | config_term_func_t config_term); |
| 436 | |
David Ahern | c5cd8ac | 2013-07-02 13:27:25 -0600 | [diff] [blame] | 437 | int parse_events_add_cache(struct list_head *list, int *idx, |
Wang Nan | 43d0b97 | 2016-02-19 11:44:01 +0000 | [diff] [blame] | 438 | char *type, char *op_result1, char *op_result2, |
Arnaldo Carvalho de Melo | 2c97b0d | 2016-02-19 19:47:04 -0300 | [diff] [blame] | 439 | struct parse_events_error *err, |
Wang Nan | 43d0b97 | 2016-02-19 11:44:01 +0000 | [diff] [blame] | 440 | struct list_head *head_config) |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 441 | { |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 442 | struct perf_event_attr attr; |
Wang Nan | 43d0b97 | 2016-02-19 11:44:01 +0000 | [diff] [blame] | 443 | LIST_HEAD(config_terms); |
| 444 | char name[MAX_NAME_LEN], *config_name; |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 445 | int cache_type = -1, cache_op = -1, cache_result = -1; |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 446 | char *op_result[2] = { op_result1, op_result2 }; |
| 447 | int i, n; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 448 | |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 449 | /* |
| 450 | * No fallback - if we cannot get a clear cache type |
| 451 | * then bail out: |
| 452 | */ |
Arnaldo Carvalho de Melo | 0b668bc | 2012-06-11 14:08:07 -0300 | [diff] [blame] | 453 | cache_type = parse_aliases(type, perf_evsel__hw_cache, |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 454 | PERF_COUNT_HW_CACHE_MAX); |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 455 | if (cache_type == -1) |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 456 | return -EINVAL; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 457 | |
Wang Nan | 43d0b97 | 2016-02-19 11:44:01 +0000 | [diff] [blame] | 458 | config_name = get_config_name(head_config); |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 459 | n = snprintf(name, MAX_NAME_LEN, "%s", type); |
| 460 | |
| 461 | for (i = 0; (i < 2) && (op_result[i]); i++) { |
| 462 | char *str = op_result[i]; |
| 463 | |
Jiri Olsa | 275ef38 | 2012-09-05 19:51:33 +0200 | [diff] [blame] | 464 | n += snprintf(name + n, MAX_NAME_LEN - n, "-%s", str); |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 465 | |
| 466 | if (cache_op == -1) { |
Arnaldo Carvalho de Melo | 0b668bc | 2012-06-11 14:08:07 -0300 | [diff] [blame] | 467 | cache_op = parse_aliases(str, perf_evsel__hw_cache_op, |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 468 | PERF_COUNT_HW_CACHE_OP_MAX); |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 469 | if (cache_op >= 0) { |
Arnaldo Carvalho de Melo | 0b668bc | 2012-06-11 14:08:07 -0300 | [diff] [blame] | 470 | if (!perf_evsel__is_cache_op_valid(cache_type, cache_op)) |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 471 | return -EINVAL; |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 472 | continue; |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | if (cache_result == -1) { |
Arnaldo Carvalho de Melo | 0b668bc | 2012-06-11 14:08:07 -0300 | [diff] [blame] | 477 | cache_result = parse_aliases(str, perf_evsel__hw_cache_result, |
| 478 | PERF_COUNT_HW_CACHE_RESULT_MAX); |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 479 | if (cache_result >= 0) |
| 480 | continue; |
| 481 | } |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 482 | } |
| 483 | |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 484 | /* |
| 485 | * Fall back to reads: |
| 486 | */ |
Ingo Molnar | 8953645 | 2009-06-06 21:04:17 +0200 | [diff] [blame] | 487 | if (cache_op == -1) |
| 488 | cache_op = PERF_COUNT_HW_CACHE_OP_READ; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 489 | |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 490 | /* |
| 491 | * Fall back to accesses: |
| 492 | */ |
| 493 | if (cache_result == -1) |
| 494 | cache_result = PERF_COUNT_HW_CACHE_RESULT_ACCESS; |
| 495 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 496 | memset(&attr, 0, sizeof(attr)); |
| 497 | attr.config = cache_type | (cache_op << 8) | (cache_result << 16); |
| 498 | attr.type = PERF_TYPE_HW_CACHE; |
Wang Nan | 43d0b97 | 2016-02-19 11:44:01 +0000 | [diff] [blame] | 499 | |
| 500 | if (head_config) { |
Arnaldo Carvalho de Melo | 2c97b0d | 2016-02-19 19:47:04 -0300 | [diff] [blame] | 501 | if (config_attr(&attr, head_config, err, |
Wang Nan | 43d0b97 | 2016-02-19 11:44:01 +0000 | [diff] [blame] | 502 | config_term_common)) |
| 503 | return -EINVAL; |
| 504 | |
| 505 | if (get_config_terms(head_config, &config_terms)) |
| 506 | return -ENOMEM; |
| 507 | } |
| 508 | return add_event(list, idx, &attr, config_name ? : name, &config_terms); |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 509 | } |
| 510 | |
Jiri Olsa | 272ed29 | 2015-09-29 17:05:31 +0200 | [diff] [blame] | 511 | static void tracepoint_error(struct parse_events_error *e, int err, |
Wang Nan | 8c619d6 | 2016-07-13 10:44:03 +0000 | [diff] [blame] | 512 | const char *sys, const char *name) |
Jiri Olsa | 1965817 | 2015-09-07 10:38:07 +0200 | [diff] [blame] | 513 | { |
| 514 | char help[BUFSIZ]; |
| 515 | |
Adrian Hunter | ec183d2 | 2016-01-26 14:05:20 +0200 | [diff] [blame] | 516 | if (!e) |
| 517 | return; |
| 518 | |
Jiri Olsa | 1965817 | 2015-09-07 10:38:07 +0200 | [diff] [blame] | 519 | /* |
| 520 | * We get error directly from syscall errno ( > 0), |
| 521 | * or from encoded pointer's error ( < 0). |
| 522 | */ |
| 523 | err = abs(err); |
| 524 | |
| 525 | switch (err) { |
| 526 | case EACCES: |
Jiri Olsa | 272ed29 | 2015-09-29 17:05:31 +0200 | [diff] [blame] | 527 | e->str = strdup("can't access trace events"); |
Jiri Olsa | 1965817 | 2015-09-07 10:38:07 +0200 | [diff] [blame] | 528 | break; |
| 529 | case ENOENT: |
Jiri Olsa | 272ed29 | 2015-09-29 17:05:31 +0200 | [diff] [blame] | 530 | e->str = strdup("unknown tracepoint"); |
Jiri Olsa | 1965817 | 2015-09-07 10:38:07 +0200 | [diff] [blame] | 531 | break; |
| 532 | default: |
Jiri Olsa | 272ed29 | 2015-09-29 17:05:31 +0200 | [diff] [blame] | 533 | e->str = strdup("failed to add tracepoint"); |
Jiri Olsa | 1965817 | 2015-09-07 10:38:07 +0200 | [diff] [blame] | 534 | break; |
| 535 | } |
| 536 | |
| 537 | tracing_path__strerror_open_tp(err, help, sizeof(help), sys, name); |
Jiri Olsa | 272ed29 | 2015-09-29 17:05:31 +0200 | [diff] [blame] | 538 | e->help = strdup(help); |
Jiri Olsa | 1965817 | 2015-09-07 10:38:07 +0200 | [diff] [blame] | 539 | } |
| 540 | |
David Ahern | c5cd8ac | 2013-07-02 13:27:25 -0600 | [diff] [blame] | 541 | static int add_tracepoint(struct list_head *list, int *idx, |
Wang Nan | 8c619d6 | 2016-07-13 10:44:03 +0000 | [diff] [blame] | 542 | const char *sys_name, const char *evt_name, |
Jiri Olsa | 272ed29 | 2015-09-29 17:05:31 +0200 | [diff] [blame] | 543 | struct parse_events_error *err, |
He Kuang | e637d17 | 2015-09-28 03:52:16 +0000 | [diff] [blame] | 544 | struct list_head *head_config) |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 545 | { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 546 | struct evsel *evsel; |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 547 | |
Arnaldo Carvalho de Melo | ef50383 | 2013-11-07 16:41:19 -0300 | [diff] [blame] | 548 | evsel = perf_evsel__newtp_idx(sys_name, evt_name, (*idx)++); |
Jiri Olsa | 1965817 | 2015-09-07 10:38:07 +0200 | [diff] [blame] | 549 | if (IS_ERR(evsel)) { |
Jiri Olsa | 272ed29 | 2015-09-29 17:05:31 +0200 | [diff] [blame] | 550 | tracepoint_error(err, PTR_ERR(evsel), sys_name, evt_name); |
Jiri Olsa | 8dd2a13 | 2015-09-07 10:38:06 +0200 | [diff] [blame] | 551 | return PTR_ERR(evsel); |
Jiri Olsa | 1965817 | 2015-09-07 10:38:07 +0200 | [diff] [blame] | 552 | } |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 553 | |
He Kuang | e637d17 | 2015-09-28 03:52:16 +0000 | [diff] [blame] | 554 | if (head_config) { |
| 555 | LIST_HEAD(config_terms); |
| 556 | |
| 557 | if (get_config_terms(head_config, &config_terms)) |
| 558 | return -ENOMEM; |
| 559 | list_splice(&config_terms, &evsel->config_terms); |
| 560 | } |
| 561 | |
Jiri Olsa | b27c4ec | 2019-07-21 13:24:22 +0200 | [diff] [blame] | 562 | list_add_tail(&evsel->core.node, list); |
Arnaldo Carvalho de Melo | 82fe1c2 | 2012-09-26 17:13:07 -0300 | [diff] [blame] | 563 | return 0; |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 564 | } |
| 565 | |
David Ahern | c5cd8ac | 2013-07-02 13:27:25 -0600 | [diff] [blame] | 566 | static int add_tracepoint_multi_event(struct list_head *list, int *idx, |
Wang Nan | 8c619d6 | 2016-07-13 10:44:03 +0000 | [diff] [blame] | 567 | const char *sys_name, const char *evt_name, |
Jiri Olsa | 272ed29 | 2015-09-29 17:05:31 +0200 | [diff] [blame] | 568 | struct parse_events_error *err, |
He Kuang | e637d17 | 2015-09-28 03:52:16 +0000 | [diff] [blame] | 569 | struct list_head *head_config) |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 570 | { |
Arnaldo Carvalho de Melo | 25a7d914 | 2018-05-17 14:27:29 -0300 | [diff] [blame] | 571 | char *evt_path; |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 572 | struct dirent *evt_ent; |
| 573 | DIR *evt_dir; |
Jiri Olsa | 27bf90b | 2015-10-05 21:31:17 +0200 | [diff] [blame] | 574 | int ret = 0, found = 0; |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 575 | |
Arnaldo Carvalho de Melo | 25a7d914 | 2018-05-17 14:27:29 -0300 | [diff] [blame] | 576 | evt_path = get_events_file(sys_name); |
| 577 | if (!evt_path) { |
| 578 | tracepoint_error(err, errno, sys_name, evt_name); |
| 579 | return -1; |
| 580 | } |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 581 | evt_dir = opendir(evt_path); |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 582 | if (!evt_dir) { |
Arnaldo Carvalho de Melo | 25a7d914 | 2018-05-17 14:27:29 -0300 | [diff] [blame] | 583 | put_events_file(evt_path); |
Jiri Olsa | 272ed29 | 2015-09-29 17:05:31 +0200 | [diff] [blame] | 584 | tracepoint_error(err, errno, sys_name, evt_name); |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 585 | return -1; |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 586 | } |
| 587 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 588 | while (!ret && (evt_ent = readdir(evt_dir))) { |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 589 | if (!strcmp(evt_ent->d_name, ".") |
| 590 | || !strcmp(evt_ent->d_name, "..") |
| 591 | || !strcmp(evt_ent->d_name, "enable") |
| 592 | || !strcmp(evt_ent->d_name, "filter")) |
| 593 | continue; |
| 594 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 595 | if (!strglobmatch(evt_ent->d_name, evt_name)) |
Masami Hiramatsu | fb1d2ed | 2010-01-05 17:47:17 -0500 | [diff] [blame] | 596 | continue; |
| 597 | |
Jiri Olsa | 27bf90b | 2015-10-05 21:31:17 +0200 | [diff] [blame] | 598 | found++; |
| 599 | |
He Kuang | e637d17 | 2015-09-28 03:52:16 +0000 | [diff] [blame] | 600 | ret = add_tracepoint(list, idx, sys_name, evt_ent->d_name, |
Jiri Olsa | 272ed29 | 2015-09-29 17:05:31 +0200 | [diff] [blame] | 601 | err, head_config); |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 602 | } |
| 603 | |
Jiri Olsa | 27bf90b | 2015-10-05 21:31:17 +0200 | [diff] [blame] | 604 | if (!found) { |
| 605 | tracepoint_error(err, ENOENT, sys_name, evt_name); |
| 606 | ret = -1; |
| 607 | } |
| 608 | |
Arnaldo Carvalho de Melo | 25a7d914 | 2018-05-17 14:27:29 -0300 | [diff] [blame] | 609 | put_events_file(evt_path); |
Jiri Olsa | 0bd3f08 | 2012-12-17 14:08:36 +0100 | [diff] [blame] | 610 | closedir(evt_dir); |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 611 | return ret; |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 612 | } |
| 613 | |
David Ahern | c5cd8ac | 2013-07-02 13:27:25 -0600 | [diff] [blame] | 614 | static int add_tracepoint_event(struct list_head *list, int *idx, |
Wang Nan | 8c619d6 | 2016-07-13 10:44:03 +0000 | [diff] [blame] | 615 | const char *sys_name, const char *evt_name, |
Jiri Olsa | 272ed29 | 2015-09-29 17:05:31 +0200 | [diff] [blame] | 616 | struct parse_events_error *err, |
He Kuang | e637d17 | 2015-09-28 03:52:16 +0000 | [diff] [blame] | 617 | struct list_head *head_config) |
Jiri Olsa | f35488f | 2012-12-17 14:08:37 +0100 | [diff] [blame] | 618 | { |
| 619 | return strpbrk(evt_name, "*?") ? |
He Kuang | e637d17 | 2015-09-28 03:52:16 +0000 | [diff] [blame] | 620 | add_tracepoint_multi_event(list, idx, sys_name, evt_name, |
Jiri Olsa | 272ed29 | 2015-09-29 17:05:31 +0200 | [diff] [blame] | 621 | err, head_config) : |
He Kuang | e637d17 | 2015-09-28 03:52:16 +0000 | [diff] [blame] | 622 | add_tracepoint(list, idx, sys_name, evt_name, |
Jiri Olsa | 272ed29 | 2015-09-29 17:05:31 +0200 | [diff] [blame] | 623 | err, head_config); |
Jiri Olsa | f35488f | 2012-12-17 14:08:37 +0100 | [diff] [blame] | 624 | } |
| 625 | |
David Ahern | c5cd8ac | 2013-07-02 13:27:25 -0600 | [diff] [blame] | 626 | static int add_tracepoint_multi_sys(struct list_head *list, int *idx, |
Wang Nan | 8c619d6 | 2016-07-13 10:44:03 +0000 | [diff] [blame] | 627 | const char *sys_name, const char *evt_name, |
Jiri Olsa | 272ed29 | 2015-09-29 17:05:31 +0200 | [diff] [blame] | 628 | struct parse_events_error *err, |
He Kuang | e637d17 | 2015-09-28 03:52:16 +0000 | [diff] [blame] | 629 | struct list_head *head_config) |
Jiri Olsa | f35488f | 2012-12-17 14:08:37 +0100 | [diff] [blame] | 630 | { |
| 631 | struct dirent *events_ent; |
| 632 | DIR *events_dir; |
| 633 | int ret = 0; |
| 634 | |
Arnaldo Carvalho de Melo | 7014e0e | 2018-05-17 14:42:39 -0300 | [diff] [blame] | 635 | events_dir = tracing_events__opendir(); |
Jiri Olsa | f35488f | 2012-12-17 14:08:37 +0100 | [diff] [blame] | 636 | if (!events_dir) { |
Jiri Olsa | 272ed29 | 2015-09-29 17:05:31 +0200 | [diff] [blame] | 637 | tracepoint_error(err, errno, sys_name, evt_name); |
Jiri Olsa | f35488f | 2012-12-17 14:08:37 +0100 | [diff] [blame] | 638 | return -1; |
| 639 | } |
| 640 | |
| 641 | while (!ret && (events_ent = readdir(events_dir))) { |
| 642 | if (!strcmp(events_ent->d_name, ".") |
| 643 | || !strcmp(events_ent->d_name, "..") |
| 644 | || !strcmp(events_ent->d_name, "enable") |
| 645 | || !strcmp(events_ent->d_name, "header_event") |
| 646 | || !strcmp(events_ent->d_name, "header_page")) |
| 647 | continue; |
| 648 | |
| 649 | if (!strglobmatch(events_ent->d_name, sys_name)) |
| 650 | continue; |
| 651 | |
| 652 | ret = add_tracepoint_event(list, idx, events_ent->d_name, |
Jiri Olsa | 272ed29 | 2015-09-29 17:05:31 +0200 | [diff] [blame] | 653 | evt_name, err, head_config); |
Jiri Olsa | f35488f | 2012-12-17 14:08:37 +0100 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | closedir(events_dir); |
| 657 | return ret; |
| 658 | } |
| 659 | |
Wang Nan | 4edf30e | 2015-10-14 12:41:17 +0000 | [diff] [blame] | 660 | struct __add_bpf_event_param { |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 661 | struct parse_events_state *parse_state; |
Wang Nan | 4edf30e | 2015-10-14 12:41:17 +0000 | [diff] [blame] | 662 | struct list_head *list; |
Wang Nan | 95088a5 | 2016-02-22 09:10:36 +0000 | [diff] [blame] | 663 | struct list_head *head_config; |
Wang Nan | 4edf30e | 2015-10-14 12:41:17 +0000 | [diff] [blame] | 664 | }; |
| 665 | |
Arnaldo Carvalho de Melo | af4a099 | 2019-07-15 16:22:57 -0300 | [diff] [blame] | 666 | static int add_bpf_event(const char *group, const char *event, int fd, struct bpf_object *obj, |
Wang Nan | 4edf30e | 2015-10-14 12:41:17 +0000 | [diff] [blame] | 667 | void *_param) |
| 668 | { |
| 669 | LIST_HEAD(new_evsels); |
| 670 | struct __add_bpf_event_param *param = _param; |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 671 | struct parse_events_state *parse_state = param->parse_state; |
Wang Nan | 4edf30e | 2015-10-14 12:41:17 +0000 | [diff] [blame] | 672 | struct list_head *list = param->list; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 673 | struct evsel *pos; |
Wang Nan | 4edf30e | 2015-10-14 12:41:17 +0000 | [diff] [blame] | 674 | int err; |
Arnaldo Carvalho de Melo | 2620b7e | 2019-07-15 15:29:34 -0300 | [diff] [blame] | 675 | /* |
| 676 | * Check if we should add the event, i.e. if it is a TP but starts with a '!', |
| 677 | * then don't add the tracepoint, this will be used for something else, like |
| 678 | * adding to a BPF_MAP_TYPE_PROG_ARRAY. |
| 679 | * |
| 680 | * See tools/perf/examples/bpf/augmented_raw_syscalls.c |
| 681 | */ |
| 682 | if (group[0] == '!') |
| 683 | return 0; |
Wang Nan | 4edf30e | 2015-10-14 12:41:17 +0000 | [diff] [blame] | 684 | |
| 685 | pr_debug("add bpf event %s:%s and attach bpf program %d\n", |
Wang Nan | cd102d7 | 2016-07-13 10:44:04 +0000 | [diff] [blame] | 686 | group, event, fd); |
Wang Nan | 4edf30e | 2015-10-14 12:41:17 +0000 | [diff] [blame] | 687 | |
Arnaldo Carvalho de Melo | 5d369a7 | 2017-08-17 14:13:25 -0300 | [diff] [blame] | 688 | err = parse_events_add_tracepoint(&new_evsels, &parse_state->idx, group, |
| 689 | event, parse_state->error, |
Wang Nan | 95088a5 | 2016-02-22 09:10:36 +0000 | [diff] [blame] | 690 | param->head_config); |
Wang Nan | 4edf30e | 2015-10-14 12:41:17 +0000 | [diff] [blame] | 691 | if (err) { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 692 | struct evsel *evsel, *tmp; |
Wang Nan | 4edf30e | 2015-10-14 12:41:17 +0000 | [diff] [blame] | 693 | |
| 694 | pr_debug("Failed to add BPF event %s:%s\n", |
Wang Nan | cd102d7 | 2016-07-13 10:44:04 +0000 | [diff] [blame] | 695 | group, event); |
Jiri Olsa | b27c4ec | 2019-07-21 13:24:22 +0200 | [diff] [blame] | 696 | list_for_each_entry_safe(evsel, tmp, &new_evsels, core.node) { |
| 697 | list_del_init(&evsel->core.node); |
Jiri Olsa | 5eb2dd2 | 2019-07-21 13:23:57 +0200 | [diff] [blame] | 698 | evsel__delete(evsel); |
Wang Nan | 4edf30e | 2015-10-14 12:41:17 +0000 | [diff] [blame] | 699 | } |
| 700 | return err; |
| 701 | } |
Wang Nan | cd102d7 | 2016-07-13 10:44:04 +0000 | [diff] [blame] | 702 | pr_debug("adding %s:%s\n", group, event); |
Wang Nan | 4edf30e | 2015-10-14 12:41:17 +0000 | [diff] [blame] | 703 | |
Jiri Olsa | b27c4ec | 2019-07-21 13:24:22 +0200 | [diff] [blame] | 704 | list_for_each_entry(pos, &new_evsels, core.node) { |
Wang Nan | 1f45b1d | 2015-10-14 12:41:18 +0000 | [diff] [blame] | 705 | pr_debug("adding %s:%s to %p\n", |
Wang Nan | cd102d7 | 2016-07-13 10:44:04 +0000 | [diff] [blame] | 706 | group, event, pos); |
Wang Nan | 1f45b1d | 2015-10-14 12:41:18 +0000 | [diff] [blame] | 707 | pos->bpf_fd = fd; |
Arnaldo Carvalho de Melo | af4a099 | 2019-07-15 16:22:57 -0300 | [diff] [blame] | 708 | pos->bpf_obj = obj; |
Wang Nan | 1f45b1d | 2015-10-14 12:41:18 +0000 | [diff] [blame] | 709 | } |
Wang Nan | 4edf30e | 2015-10-14 12:41:17 +0000 | [diff] [blame] | 710 | list_splice(&new_evsels, list); |
| 711 | return 0; |
| 712 | } |
| 713 | |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 714 | int parse_events_load_bpf_obj(struct parse_events_state *parse_state, |
Wang Nan | 84c86ca | 2015-10-14 12:41:14 +0000 | [diff] [blame] | 715 | struct list_head *list, |
Wang Nan | 95088a5 | 2016-02-22 09:10:36 +0000 | [diff] [blame] | 716 | struct bpf_object *obj, |
| 717 | struct list_head *head_config) |
Wang Nan | 84c86ca | 2015-10-14 12:41:14 +0000 | [diff] [blame] | 718 | { |
| 719 | int err; |
| 720 | char errbuf[BUFSIZ]; |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 721 | struct __add_bpf_event_param param = {parse_state, list, head_config}; |
Wang Nan | aa3abf3 | 2015-10-14 12:41:15 +0000 | [diff] [blame] | 722 | static bool registered_unprobe_atexit = false; |
Wang Nan | 84c86ca | 2015-10-14 12:41:14 +0000 | [diff] [blame] | 723 | |
| 724 | if (IS_ERR(obj) || !obj) { |
| 725 | snprintf(errbuf, sizeof(errbuf), |
| 726 | "Internal error: load bpf obj with NULL"); |
| 727 | err = -EINVAL; |
| 728 | goto errout; |
| 729 | } |
| 730 | |
| 731 | /* |
Wang Nan | aa3abf3 | 2015-10-14 12:41:15 +0000 | [diff] [blame] | 732 | * Register atexit handler before calling bpf__probe() so |
| 733 | * bpf__probe() don't need to unprobe probe points its already |
| 734 | * created when failure. |
| 735 | */ |
| 736 | if (!registered_unprobe_atexit) { |
| 737 | atexit(bpf__clear); |
| 738 | registered_unprobe_atexit = true; |
| 739 | } |
| 740 | |
| 741 | err = bpf__probe(obj); |
| 742 | if (err) { |
| 743 | bpf__strerror_probe(obj, err, errbuf, sizeof(errbuf)); |
| 744 | goto errout; |
| 745 | } |
| 746 | |
Wang Nan | 1e5e3ee | 2015-10-14 12:41:16 +0000 | [diff] [blame] | 747 | err = bpf__load(obj); |
| 748 | if (err) { |
| 749 | bpf__strerror_load(obj, err, errbuf, sizeof(errbuf)); |
| 750 | goto errout; |
| 751 | } |
| 752 | |
Wang Nan | cd102d7 | 2016-07-13 10:44:04 +0000 | [diff] [blame] | 753 | err = bpf__foreach_event(obj, add_bpf_event, ¶m); |
Wang Nan | 4edf30e | 2015-10-14 12:41:17 +0000 | [diff] [blame] | 754 | if (err) { |
| 755 | snprintf(errbuf, sizeof(errbuf), |
| 756 | "Attach events in BPF object failed"); |
| 757 | goto errout; |
| 758 | } |
| 759 | |
| 760 | return 0; |
Wang Nan | 84c86ca | 2015-10-14 12:41:14 +0000 | [diff] [blame] | 761 | errout: |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 762 | parse_state->error->help = strdup("(add -v to see detail)"); |
| 763 | parse_state->error->str = strdup(errbuf); |
Wang Nan | 84c86ca | 2015-10-14 12:41:14 +0000 | [diff] [blame] | 764 | return err; |
| 765 | } |
| 766 | |
Wang Nan | a34f3be | 2016-02-22 09:10:31 +0000 | [diff] [blame] | 767 | static int |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 768 | parse_events_config_bpf(struct parse_events_state *parse_state, |
Wang Nan | a34f3be | 2016-02-22 09:10:31 +0000 | [diff] [blame] | 769 | struct bpf_object *obj, |
| 770 | struct list_head *head_config) |
| 771 | { |
| 772 | struct parse_events_term *term; |
| 773 | int error_pos; |
| 774 | |
| 775 | if (!head_config || list_empty(head_config)) |
| 776 | return 0; |
| 777 | |
| 778 | list_for_each_entry(term, head_config, list) { |
| 779 | char errbuf[BUFSIZ]; |
| 780 | int err; |
| 781 | |
| 782 | if (term->type_term != PARSE_EVENTS__TERM_TYPE_USER) { |
| 783 | snprintf(errbuf, sizeof(errbuf), |
| 784 | "Invalid config term for BPF object"); |
| 785 | errbuf[BUFSIZ - 1] = '\0'; |
| 786 | |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 787 | parse_state->error->idx = term->err_term; |
| 788 | parse_state->error->str = strdup(errbuf); |
Wang Nan | a34f3be | 2016-02-22 09:10:31 +0000 | [diff] [blame] | 789 | return -EINVAL; |
| 790 | } |
| 791 | |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 792 | err = bpf__config_obj(obj, term, parse_state->evlist, &error_pos); |
Wang Nan | a34f3be | 2016-02-22 09:10:31 +0000 | [diff] [blame] | 793 | if (err) { |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 794 | bpf__strerror_config_obj(obj, term, parse_state->evlist, |
Wang Nan | a34f3be | 2016-02-22 09:10:31 +0000 | [diff] [blame] | 795 | &error_pos, err, errbuf, |
| 796 | sizeof(errbuf)); |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 797 | parse_state->error->help = strdup( |
Wang Nan | 7630b3e | 2016-02-22 09:10:33 +0000 | [diff] [blame] | 798 | "Hint:\tValid config terms:\n" |
Wang Nan | e571e02 | 2016-02-22 09:10:35 +0000 | [diff] [blame] | 799 | " \tmap:[<arraymap>].value<indices>=[value]\n" |
| 800 | " \tmap:[<eventmap>].event<indices>=[event]\n" |
Wang Nan | 7630b3e | 2016-02-22 09:10:33 +0000 | [diff] [blame] | 801 | "\n" |
Wang Nan | e571e02 | 2016-02-22 09:10:35 +0000 | [diff] [blame] | 802 | " \twhere <indices> is something like [0,3...5] or [all]\n" |
Wang Nan | a34f3be | 2016-02-22 09:10:31 +0000 | [diff] [blame] | 803 | " \t(add -v to see detail)"); |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 804 | parse_state->error->str = strdup(errbuf); |
Wang Nan | a34f3be | 2016-02-22 09:10:31 +0000 | [diff] [blame] | 805 | if (err == -BPF_LOADER_ERRNO__OBJCONF_MAP_VALUE) |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 806 | parse_state->error->idx = term->err_val; |
Wang Nan | a34f3be | 2016-02-22 09:10:31 +0000 | [diff] [blame] | 807 | else |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 808 | parse_state->error->idx = term->err_term + error_pos; |
Wang Nan | a34f3be | 2016-02-22 09:10:31 +0000 | [diff] [blame] | 809 | return err; |
| 810 | } |
| 811 | } |
| 812 | return 0; |
| 813 | } |
| 814 | |
Wang Nan | 95088a5 | 2016-02-22 09:10:36 +0000 | [diff] [blame] | 815 | /* |
| 816 | * Split config terms: |
| 817 | * perf record -e bpf.c/call-graph=fp,map:array.value[0]=1/ ... |
| 818 | * 'call-graph=fp' is 'evt config', should be applied to each |
| 819 | * events in bpf.c. |
| 820 | * 'map:array.value[0]=1' is 'obj config', should be processed |
| 821 | * with parse_events_config_bpf. |
| 822 | * |
| 823 | * Move object config terms from the first list to obj_head_config. |
| 824 | */ |
| 825 | static void |
| 826 | split_bpf_config_terms(struct list_head *evt_head_config, |
| 827 | struct list_head *obj_head_config) |
| 828 | { |
| 829 | struct parse_events_term *term, *temp; |
| 830 | |
| 831 | /* |
| 832 | * Currectly, all possible user config term |
| 833 | * belong to bpf object. parse_events__is_hardcoded_term() |
| 834 | * happends to be a good flag. |
| 835 | * |
| 836 | * See parse_events_config_bpf() and |
| 837 | * config_term_tracepoint(). |
| 838 | */ |
| 839 | list_for_each_entry_safe(term, temp, evt_head_config, list) |
| 840 | if (!parse_events__is_hardcoded_term(term)) |
| 841 | list_move_tail(&term->list, obj_head_config); |
| 842 | } |
| 843 | |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 844 | int parse_events_load_bpf(struct parse_events_state *parse_state, |
Wang Nan | 84c86ca | 2015-10-14 12:41:14 +0000 | [diff] [blame] | 845 | struct list_head *list, |
Wang Nan | d509db0 | 2015-10-14 12:41:20 +0000 | [diff] [blame] | 846 | char *bpf_file_name, |
Wang Nan | a34f3be | 2016-02-22 09:10:31 +0000 | [diff] [blame] | 847 | bool source, |
| 848 | struct list_head *head_config) |
Wang Nan | 84c86ca | 2015-10-14 12:41:14 +0000 | [diff] [blame] | 849 | { |
Wang Nan | a34f3be | 2016-02-22 09:10:31 +0000 | [diff] [blame] | 850 | int err; |
Wang Nan | 95088a5 | 2016-02-22 09:10:36 +0000 | [diff] [blame] | 851 | struct bpf_object *obj; |
| 852 | LIST_HEAD(obj_head_config); |
| 853 | |
| 854 | if (head_config) |
| 855 | split_bpf_config_terms(head_config, &obj_head_config); |
Wang Nan | 84c86ca | 2015-10-14 12:41:14 +0000 | [diff] [blame] | 856 | |
Wang Nan | d509db0 | 2015-10-14 12:41:20 +0000 | [diff] [blame] | 857 | obj = bpf__prepare_load(bpf_file_name, source); |
Wang Nan | 6371ca3b | 2015-11-06 13:49:37 +0000 | [diff] [blame] | 858 | if (IS_ERR(obj)) { |
Wang Nan | 84c86ca | 2015-10-14 12:41:14 +0000 | [diff] [blame] | 859 | char errbuf[BUFSIZ]; |
Wang Nan | 84c86ca | 2015-10-14 12:41:14 +0000 | [diff] [blame] | 860 | |
Wang Nan | 6371ca3b | 2015-11-06 13:49:37 +0000 | [diff] [blame] | 861 | err = PTR_ERR(obj); |
Wang Nan | 84c86ca | 2015-10-14 12:41:14 +0000 | [diff] [blame] | 862 | |
| 863 | if (err == -ENOTSUP) |
| 864 | snprintf(errbuf, sizeof(errbuf), |
| 865 | "BPF support is not compiled"); |
| 866 | else |
Wang Nan | d3e0ce3 | 2015-11-06 13:58:09 +0000 | [diff] [blame] | 867 | bpf__strerror_prepare_load(bpf_file_name, |
| 868 | source, |
| 869 | -err, errbuf, |
| 870 | sizeof(errbuf)); |
Wang Nan | 84c86ca | 2015-10-14 12:41:14 +0000 | [diff] [blame] | 871 | |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 872 | parse_state->error->help = strdup("(add -v to see detail)"); |
| 873 | parse_state->error->str = strdup(errbuf); |
Wang Nan | 84c86ca | 2015-10-14 12:41:14 +0000 | [diff] [blame] | 874 | return err; |
| 875 | } |
| 876 | |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 877 | err = parse_events_load_bpf_obj(parse_state, list, obj, head_config); |
Wang Nan | a34f3be | 2016-02-22 09:10:31 +0000 | [diff] [blame] | 878 | if (err) |
| 879 | return err; |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 880 | err = parse_events_config_bpf(parse_state, obj, &obj_head_config); |
Wang Nan | 95088a5 | 2016-02-22 09:10:36 +0000 | [diff] [blame] | 881 | |
| 882 | /* |
| 883 | * Caller doesn't know anything about obj_head_config, |
| 884 | * so combine them together again before returnning. |
| 885 | */ |
| 886 | if (head_config) |
| 887 | list_splice_tail(&obj_head_config, head_config); |
| 888 | return err; |
Wang Nan | 84c86ca | 2015-10-14 12:41:14 +0000 | [diff] [blame] | 889 | } |
| 890 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 891 | static int |
| 892 | parse_breakpoint_type(const char *type, struct perf_event_attr *attr) |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 893 | { |
| 894 | int i; |
| 895 | |
| 896 | for (i = 0; i < 3; i++) { |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 897 | if (!type || !type[i]) |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 898 | break; |
| 899 | |
Jiri Olsa | 7582732 | 2012-06-29 09:22:54 +0200 | [diff] [blame] | 900 | #define CHECK_SET_TYPE(bit) \ |
| 901 | do { \ |
| 902 | if (attr->bp_type & bit) \ |
| 903 | return -EINVAL; \ |
| 904 | else \ |
| 905 | attr->bp_type |= bit; \ |
| 906 | } while (0) |
| 907 | |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 908 | switch (type[i]) { |
| 909 | case 'r': |
Jiri Olsa | 7582732 | 2012-06-29 09:22:54 +0200 | [diff] [blame] | 910 | CHECK_SET_TYPE(HW_BREAKPOINT_R); |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 911 | break; |
| 912 | case 'w': |
Jiri Olsa | 7582732 | 2012-06-29 09:22:54 +0200 | [diff] [blame] | 913 | CHECK_SET_TYPE(HW_BREAKPOINT_W); |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 914 | break; |
| 915 | case 'x': |
Jiri Olsa | 7582732 | 2012-06-29 09:22:54 +0200 | [diff] [blame] | 916 | CHECK_SET_TYPE(HW_BREAKPOINT_X); |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 917 | break; |
| 918 | default: |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 919 | return -EINVAL; |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 920 | } |
| 921 | } |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 922 | |
Jiri Olsa | 7582732 | 2012-06-29 09:22:54 +0200 | [diff] [blame] | 923 | #undef CHECK_SET_TYPE |
| 924 | |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 925 | if (!attr->bp_type) /* Default */ |
| 926 | attr->bp_type = HW_BREAKPOINT_R | HW_BREAKPOINT_W; |
| 927 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 928 | return 0; |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 929 | } |
| 930 | |
David Ahern | c5cd8ac | 2013-07-02 13:27:25 -0600 | [diff] [blame] | 931 | int parse_events_add_breakpoint(struct list_head *list, int *idx, |
Jacob Shin | 3741eb9 | 2014-05-29 17:26:51 +0200 | [diff] [blame] | 932 | void *ptr, char *type, u64 len) |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 933 | { |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 934 | struct perf_event_attr attr; |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 935 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 936 | memset(&attr, 0, sizeof(attr)); |
Jiri Olsa | 9fafd98 | 2012-03-20 19:15:39 +0100 | [diff] [blame] | 937 | attr.bp_addr = (unsigned long) ptr; |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 938 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 939 | if (parse_breakpoint_type(type, &attr)) |
| 940 | return -EINVAL; |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 941 | |
Jacob Shin | 3741eb9 | 2014-05-29 17:26:51 +0200 | [diff] [blame] | 942 | /* Provide some defaults if len is not specified */ |
| 943 | if (!len) { |
| 944 | if (attr.bp_type == HW_BREAKPOINT_X) |
| 945 | len = sizeof(long); |
| 946 | else |
| 947 | len = HW_BREAKPOINT_LEN_4; |
| 948 | } |
| 949 | |
| 950 | attr.bp_len = len; |
Frederic Weisbecker | aa59a48 | 2010-06-24 21:36:19 +0200 | [diff] [blame] | 951 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 952 | attr.type = PERF_TYPE_BREAKPOINT; |
Jovi Zhang | 4a841d6 | 2012-07-15 03:03:10 +0800 | [diff] [blame] | 953 | attr.sample_period = 1; |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 954 | |
Jiri Olsa | 930a2e2 | 2015-07-29 05:42:10 -0400 | [diff] [blame] | 955 | return add_event(list, idx, &attr, NULL, NULL); |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 956 | } |
| 957 | |
Jiri Olsa | 3b0e371 | 2015-04-22 21:10:22 +0200 | [diff] [blame] | 958 | static int check_type_val(struct parse_events_term *term, |
| 959 | struct parse_events_error *err, |
| 960 | int type) |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 961 | { |
Jiri Olsa | 3b0e371 | 2015-04-22 21:10:22 +0200 | [diff] [blame] | 962 | if (type == term->type_val) |
| 963 | return 0; |
| 964 | |
| 965 | if (err) { |
Ian Rogers | 448d732 | 2019-10-30 15:34:39 -0700 | [diff] [blame] | 966 | parse_events__handle_error(err, term->err_val, |
| 967 | type == PARSE_EVENTS__TERM_TYPE_NUM |
| 968 | ? strdup("expected numeric value") |
| 969 | : strdup("expected string value"), |
| 970 | NULL); |
Jiri Olsa | 3b0e371 | 2015-04-22 21:10:22 +0200 | [diff] [blame] | 971 | } |
| 972 | return -EINVAL; |
| 973 | } |
| 974 | |
Wang Nan | 17cb5f8 | 2016-02-19 11:43:57 +0000 | [diff] [blame] | 975 | /* |
| 976 | * Update according to parse-events.l |
| 977 | */ |
| 978 | static const char *config_term_names[__PARSE_EVENTS__TERM_TYPE_NR] = { |
| 979 | [PARSE_EVENTS__TERM_TYPE_USER] = "<sysfs term>", |
| 980 | [PARSE_EVENTS__TERM_TYPE_CONFIG] = "config", |
| 981 | [PARSE_EVENTS__TERM_TYPE_CONFIG1] = "config1", |
| 982 | [PARSE_EVENTS__TERM_TYPE_CONFIG2] = "config2", |
| 983 | [PARSE_EVENTS__TERM_TYPE_NAME] = "name", |
| 984 | [PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD] = "period", |
| 985 | [PARSE_EVENTS__TERM_TYPE_SAMPLE_FREQ] = "freq", |
| 986 | [PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE] = "branch_type", |
| 987 | [PARSE_EVENTS__TERM_TYPE_TIME] = "time", |
| 988 | [PARSE_EVENTS__TERM_TYPE_CALLGRAPH] = "call-graph", |
| 989 | [PARSE_EVENTS__TERM_TYPE_STACKSIZE] = "stack-size", |
| 990 | [PARSE_EVENTS__TERM_TYPE_NOINHERIT] = "no-inherit", |
| 991 | [PARSE_EVENTS__TERM_TYPE_INHERIT] = "inherit", |
Arnaldo Carvalho de Melo | 792d48b | 2016-04-28 19:03:42 -0300 | [diff] [blame] | 992 | [PARSE_EVENTS__TERM_TYPE_MAX_STACK] = "max-stack", |
Arnaldo Carvalho de Melo | 2fda5ad | 2018-10-19 15:47:34 -0300 | [diff] [blame] | 993 | [PARSE_EVENTS__TERM_TYPE_MAX_EVENTS] = "nr", |
Wang Nan | 626a6b7 | 2016-07-14 08:34:45 +0000 | [diff] [blame] | 994 | [PARSE_EVENTS__TERM_TYPE_OVERWRITE] = "overwrite", |
| 995 | [PARSE_EVENTS__TERM_TYPE_NOOVERWRITE] = "no-overwrite", |
Mathieu Poirier | dd60fba | 2016-09-06 10:37:15 -0600 | [diff] [blame] | 996 | [PARSE_EVENTS__TERM_TYPE_DRV_CFG] = "driver-config", |
Jin Yao | 064b4e8 | 2019-04-12 21:59:47 +0800 | [diff] [blame] | 997 | [PARSE_EVENTS__TERM_TYPE_PERCORE] = "percore", |
Adrian Hunter | 1b99215 | 2019-08-06 11:46:05 +0300 | [diff] [blame] | 998 | [PARSE_EVENTS__TERM_TYPE_AUX_OUTPUT] = "aux-output", |
Wang Nan | 17cb5f8 | 2016-02-19 11:43:57 +0000 | [diff] [blame] | 999 | }; |
| 1000 | |
Wang Nan | 1669e50 | 2016-02-19 11:43:58 +0000 | [diff] [blame] | 1001 | static bool config_term_shrinked; |
| 1002 | |
| 1003 | static bool |
| 1004 | config_term_avail(int term_type, struct parse_events_error *err) |
| 1005 | { |
Ian Rogers | 448d732 | 2019-10-30 15:34:39 -0700 | [diff] [blame] | 1006 | char *err_str; |
| 1007 | |
Wang Nan | 1669e50 | 2016-02-19 11:43:58 +0000 | [diff] [blame] | 1008 | if (term_type < 0 || term_type >= __PARSE_EVENTS__TERM_TYPE_NR) { |
Ian Rogers | 448d732 | 2019-10-30 15:34:39 -0700 | [diff] [blame] | 1009 | parse_events__handle_error(err, -1, |
| 1010 | strdup("Invalid term_type"), NULL); |
Wang Nan | 1669e50 | 2016-02-19 11:43:58 +0000 | [diff] [blame] | 1011 | return false; |
| 1012 | } |
| 1013 | if (!config_term_shrinked) |
| 1014 | return true; |
| 1015 | |
| 1016 | switch (term_type) { |
| 1017 | case PARSE_EVENTS__TERM_TYPE_CONFIG: |
| 1018 | case PARSE_EVENTS__TERM_TYPE_CONFIG1: |
| 1019 | case PARSE_EVENTS__TERM_TYPE_CONFIG2: |
| 1020 | case PARSE_EVENTS__TERM_TYPE_NAME: |
Sukadev Bhattiprolu | 0683554 | 2016-09-15 15:24:56 -0700 | [diff] [blame] | 1021 | case PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD: |
Jin Yao | 064b4e8 | 2019-04-12 21:59:47 +0800 | [diff] [blame] | 1022 | case PARSE_EVENTS__TERM_TYPE_PERCORE: |
Wang Nan | 1669e50 | 2016-02-19 11:43:58 +0000 | [diff] [blame] | 1023 | return true; |
| 1024 | default: |
| 1025 | if (!err) |
| 1026 | return false; |
| 1027 | |
| 1028 | /* term_type is validated so indexing is safe */ |
Ian Rogers | 448d732 | 2019-10-30 15:34:39 -0700 | [diff] [blame] | 1029 | if (asprintf(&err_str, "'%s' is not usable in 'perf stat'", |
| 1030 | config_term_names[term_type]) >= 0) |
| 1031 | parse_events__handle_error(err, -1, err_str, NULL); |
Wang Nan | 1669e50 | 2016-02-19 11:43:58 +0000 | [diff] [blame] | 1032 | return false; |
| 1033 | } |
| 1034 | } |
| 1035 | |
| 1036 | void parse_events__shrink_config_terms(void) |
| 1037 | { |
| 1038 | config_term_shrinked = true; |
| 1039 | } |
| 1040 | |
He Kuang | 0b8891a | 2015-09-28 03:52:13 +0000 | [diff] [blame] | 1041 | static int config_term_common(struct perf_event_attr *attr, |
| 1042 | struct parse_events_term *term, |
| 1043 | struct parse_events_error *err) |
Jiri Olsa | 3b0e371 | 2015-04-22 21:10:22 +0200 | [diff] [blame] | 1044 | { |
| 1045 | #define CHECK_TYPE_VAL(type) \ |
| 1046 | do { \ |
| 1047 | if (check_type_val(term, err, PARSE_EVENTS__TERM_TYPE_ ## type)) \ |
| 1048 | return -EINVAL; \ |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 1049 | } while (0) |
| 1050 | |
| 1051 | switch (term->type_term) { |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1052 | case PARSE_EVENTS__TERM_TYPE_CONFIG: |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 1053 | CHECK_TYPE_VAL(NUM); |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1054 | attr->config = term->val.num; |
| 1055 | break; |
| 1056 | case PARSE_EVENTS__TERM_TYPE_CONFIG1: |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 1057 | CHECK_TYPE_VAL(NUM); |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1058 | attr->config1 = term->val.num; |
| 1059 | break; |
| 1060 | case PARSE_EVENTS__TERM_TYPE_CONFIG2: |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 1061 | CHECK_TYPE_VAL(NUM); |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1062 | attr->config2 = term->val.num; |
| 1063 | break; |
| 1064 | case PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD: |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 1065 | CHECK_TYPE_VAL(NUM); |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1066 | break; |
Namhyung Kim | 09af2a5 | 2015-08-09 15:45:23 +0900 | [diff] [blame] | 1067 | case PARSE_EVENTS__TERM_TYPE_SAMPLE_FREQ: |
| 1068 | CHECK_TYPE_VAL(NUM); |
| 1069 | break; |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1070 | case PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE: |
Andi Kleen | ac12f67 | 2016-10-12 14:02:06 -0700 | [diff] [blame] | 1071 | CHECK_TYPE_VAL(STR); |
| 1072 | if (strcmp(term->val.str, "no") && |
Ian Rogers | 448d732 | 2019-10-30 15:34:39 -0700 | [diff] [blame] | 1073 | parse_branch_str(term->val.str, |
| 1074 | &attr->branch_sample_type)) { |
| 1075 | parse_events__handle_error(err, term->err_val, |
| 1076 | strdup("invalid branch sample type"), |
| 1077 | NULL); |
Andi Kleen | ac12f67 | 2016-10-12 14:02:06 -0700 | [diff] [blame] | 1078 | return -EINVAL; |
| 1079 | } |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1080 | break; |
Kan Liang | 3206771 | 2015-08-04 04:30:19 -0400 | [diff] [blame] | 1081 | case PARSE_EVENTS__TERM_TYPE_TIME: |
| 1082 | CHECK_TYPE_VAL(NUM); |
| 1083 | if (term->val.num > 1) { |
Ian Rogers | 448d732 | 2019-10-30 15:34:39 -0700 | [diff] [blame] | 1084 | parse_events__handle_error(err, term->err_val, |
| 1085 | strdup("expected 0 or 1"), |
| 1086 | NULL); |
Kan Liang | 3206771 | 2015-08-04 04:30:19 -0400 | [diff] [blame] | 1087 | return -EINVAL; |
| 1088 | } |
| 1089 | break; |
Kan Liang | d457c96 | 2015-08-11 06:30:47 -0400 | [diff] [blame] | 1090 | case PARSE_EVENTS__TERM_TYPE_CALLGRAPH: |
| 1091 | CHECK_TYPE_VAL(STR); |
| 1092 | break; |
| 1093 | case PARSE_EVENTS__TERM_TYPE_STACKSIZE: |
| 1094 | CHECK_TYPE_VAL(NUM); |
| 1095 | break; |
Wang Nan | 374ce93 | 2015-10-28 10:55:02 +0000 | [diff] [blame] | 1096 | case PARSE_EVENTS__TERM_TYPE_INHERIT: |
| 1097 | CHECK_TYPE_VAL(NUM); |
| 1098 | break; |
| 1099 | case PARSE_EVENTS__TERM_TYPE_NOINHERIT: |
| 1100 | CHECK_TYPE_VAL(NUM); |
| 1101 | break; |
Wang Nan | 626a6b7 | 2016-07-14 08:34:45 +0000 | [diff] [blame] | 1102 | case PARSE_EVENTS__TERM_TYPE_OVERWRITE: |
| 1103 | CHECK_TYPE_VAL(NUM); |
| 1104 | break; |
| 1105 | case PARSE_EVENTS__TERM_TYPE_NOOVERWRITE: |
| 1106 | CHECK_TYPE_VAL(NUM); |
| 1107 | break; |
Jiri Olsa | 6b5fc39 | 2012-05-21 09:12:53 +0200 | [diff] [blame] | 1108 | case PARSE_EVENTS__TERM_TYPE_NAME: |
| 1109 | CHECK_TYPE_VAL(STR); |
| 1110 | break; |
Arnaldo Carvalho de Melo | 792d48b | 2016-04-28 19:03:42 -0300 | [diff] [blame] | 1111 | case PARSE_EVENTS__TERM_TYPE_MAX_STACK: |
| 1112 | CHECK_TYPE_VAL(NUM); |
| 1113 | break; |
Arnaldo Carvalho de Melo | 2fda5ad | 2018-10-19 15:47:34 -0300 | [diff] [blame] | 1114 | case PARSE_EVENTS__TERM_TYPE_MAX_EVENTS: |
| 1115 | CHECK_TYPE_VAL(NUM); |
| 1116 | break; |
Jin Yao | 064b4e8 | 2019-04-12 21:59:47 +0800 | [diff] [blame] | 1117 | case PARSE_EVENTS__TERM_TYPE_PERCORE: |
| 1118 | CHECK_TYPE_VAL(NUM); |
| 1119 | if ((unsigned int)term->val.num > 1) { |
Ian Rogers | 448d732 | 2019-10-30 15:34:39 -0700 | [diff] [blame] | 1120 | parse_events__handle_error(err, term->err_val, |
| 1121 | strdup("expected 0 or 1"), |
| 1122 | NULL); |
Jin Yao | 064b4e8 | 2019-04-12 21:59:47 +0800 | [diff] [blame] | 1123 | return -EINVAL; |
| 1124 | } |
| 1125 | break; |
Adrian Hunter | 1b99215 | 2019-08-06 11:46:05 +0300 | [diff] [blame] | 1126 | case PARSE_EVENTS__TERM_TYPE_AUX_OUTPUT: |
| 1127 | CHECK_TYPE_VAL(NUM); |
| 1128 | break; |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1129 | default: |
Ian Rogers | 448d732 | 2019-10-30 15:34:39 -0700 | [diff] [blame] | 1130 | parse_events__handle_error(err, term->err_term, |
| 1131 | strdup("unknown term"), |
| 1132 | parse_events_formats_error_string(NULL)); |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1133 | return -EINVAL; |
| 1134 | } |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 1135 | |
Wang Nan | 1669e50 | 2016-02-19 11:43:58 +0000 | [diff] [blame] | 1136 | /* |
| 1137 | * Check term availbility after basic checking so |
| 1138 | * PARSE_EVENTS__TERM_TYPE_USER can be found and filtered. |
| 1139 | * |
| 1140 | * If check availbility at the entry of this function, |
| 1141 | * user will see "'<sysfs term>' is not usable in 'perf stat'" |
| 1142 | * if an invalid config term is provided for legacy events |
| 1143 | * (for example, instructions/badterm/...), which is confusing. |
| 1144 | */ |
| 1145 | if (!config_term_avail(term->type_term, err)) |
| 1146 | return -EINVAL; |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1147 | return 0; |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 1148 | #undef CHECK_TYPE_VAL |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1149 | } |
| 1150 | |
He Kuang | 0b8891a | 2015-09-28 03:52:13 +0000 | [diff] [blame] | 1151 | static int config_term_pmu(struct perf_event_attr *attr, |
| 1152 | struct parse_events_term *term, |
| 1153 | struct parse_events_error *err) |
| 1154 | { |
Mathieu Poirier | dd60fba | 2016-09-06 10:37:15 -0600 | [diff] [blame] | 1155 | if (term->type_term == PARSE_EVENTS__TERM_TYPE_USER || |
| 1156 | term->type_term == PARSE_EVENTS__TERM_TYPE_DRV_CFG) |
He Kuang | 0b8891a | 2015-09-28 03:52:13 +0000 | [diff] [blame] | 1157 | /* |
| 1158 | * Always succeed for sysfs terms, as we dont know |
| 1159 | * at this point what type they need to have. |
| 1160 | */ |
| 1161 | return 0; |
| 1162 | else |
| 1163 | return config_term_common(attr, term, err); |
| 1164 | } |
| 1165 | |
He Kuang | e637d17 | 2015-09-28 03:52:16 +0000 | [diff] [blame] | 1166 | static int config_term_tracepoint(struct perf_event_attr *attr, |
| 1167 | struct parse_events_term *term, |
| 1168 | struct parse_events_error *err) |
| 1169 | { |
| 1170 | switch (term->type_term) { |
| 1171 | case PARSE_EVENTS__TERM_TYPE_CALLGRAPH: |
| 1172 | case PARSE_EVENTS__TERM_TYPE_STACKSIZE: |
Wang Nan | 374ce93 | 2015-10-28 10:55:02 +0000 | [diff] [blame] | 1173 | case PARSE_EVENTS__TERM_TYPE_INHERIT: |
| 1174 | case PARSE_EVENTS__TERM_TYPE_NOINHERIT: |
Arnaldo Carvalho de Melo | 792d48b | 2016-04-28 19:03:42 -0300 | [diff] [blame] | 1175 | case PARSE_EVENTS__TERM_TYPE_MAX_STACK: |
Arnaldo Carvalho de Melo | 2fda5ad | 2018-10-19 15:47:34 -0300 | [diff] [blame] | 1176 | case PARSE_EVENTS__TERM_TYPE_MAX_EVENTS: |
Wang Nan | 626a6b7 | 2016-07-14 08:34:45 +0000 | [diff] [blame] | 1177 | case PARSE_EVENTS__TERM_TYPE_OVERWRITE: |
| 1178 | case PARSE_EVENTS__TERM_TYPE_NOOVERWRITE: |
Adrian Hunter | 1b99215 | 2019-08-06 11:46:05 +0300 | [diff] [blame] | 1179 | case PARSE_EVENTS__TERM_TYPE_AUX_OUTPUT: |
He Kuang | e637d17 | 2015-09-28 03:52:16 +0000 | [diff] [blame] | 1180 | return config_term_common(attr, term, err); |
| 1181 | default: |
| 1182 | if (err) { |
Ian Rogers | 448d732 | 2019-10-30 15:34:39 -0700 | [diff] [blame] | 1183 | parse_events__handle_error(err, term->err_term, |
| 1184 | strdup("unknown term"), |
| 1185 | strdup("valid terms: call-graph,stack-size\n")); |
He Kuang | e637d17 | 2015-09-28 03:52:16 +0000 | [diff] [blame] | 1186 | } |
| 1187 | return -EINVAL; |
| 1188 | } |
| 1189 | |
| 1190 | return 0; |
| 1191 | } |
| 1192 | |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1193 | static int config_attr(struct perf_event_attr *attr, |
Jiri Olsa | 3b0e371 | 2015-04-22 21:10:22 +0200 | [diff] [blame] | 1194 | struct list_head *head, |
He Kuang | 0b8891a | 2015-09-28 03:52:13 +0000 | [diff] [blame] | 1195 | struct parse_events_error *err, |
| 1196 | config_term_func_t config_term) |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1197 | { |
Arnaldo Carvalho de Melo | 6cee6cd | 2013-01-18 16:29:49 -0300 | [diff] [blame] | 1198 | struct parse_events_term *term; |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1199 | |
| 1200 | list_for_each_entry(term, head, list) |
Jiri Olsa | 3b0e371 | 2015-04-22 21:10:22 +0200 | [diff] [blame] | 1201 | if (config_term(attr, term, err)) |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1202 | return -EINVAL; |
| 1203 | |
| 1204 | return 0; |
| 1205 | } |
| 1206 | |
Jiri Olsa | 930a2e2 | 2015-07-29 05:42:10 -0400 | [diff] [blame] | 1207 | static int get_config_terms(struct list_head *head_config, |
| 1208 | struct list_head *head_terms __maybe_unused) |
| 1209 | { |
| 1210 | #define ADD_CONFIG_TERM(__type, __name, __val) \ |
| 1211 | do { \ |
| 1212 | struct perf_evsel_config_term *__t; \ |
| 1213 | \ |
| 1214 | __t = zalloc(sizeof(*__t)); \ |
| 1215 | if (!__t) \ |
| 1216 | return -ENOMEM; \ |
| 1217 | \ |
| 1218 | INIT_LIST_HEAD(&__t->list); \ |
| 1219 | __t->type = PERF_EVSEL__CONFIG_TERM_ ## __type; \ |
| 1220 | __t->val.__name = __val; \ |
Andi Kleen | c2f1cea | 2017-10-20 13:27:55 -0700 | [diff] [blame] | 1221 | __t->weak = term->weak; \ |
Jiri Olsa | 930a2e2 | 2015-07-29 05:42:10 -0400 | [diff] [blame] | 1222 | list_add_tail(&__t->list, head_terms); \ |
| 1223 | } while (0) |
| 1224 | |
| 1225 | struct parse_events_term *term; |
| 1226 | |
| 1227 | list_for_each_entry(term, head_config, list) { |
| 1228 | switch (term->type_term) { |
Jiri Olsa | ee4c758 | 2015-07-29 05:42:11 -0400 | [diff] [blame] | 1229 | case PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD: |
| 1230 | ADD_CONFIG_TERM(PERIOD, period, term->val.num); |
Kan Liang | 3206771 | 2015-08-04 04:30:19 -0400 | [diff] [blame] | 1231 | break; |
Namhyung Kim | 09af2a5 | 2015-08-09 15:45:23 +0900 | [diff] [blame] | 1232 | case PARSE_EVENTS__TERM_TYPE_SAMPLE_FREQ: |
| 1233 | ADD_CONFIG_TERM(FREQ, freq, term->val.num); |
| 1234 | break; |
Kan Liang | 3206771 | 2015-08-04 04:30:19 -0400 | [diff] [blame] | 1235 | case PARSE_EVENTS__TERM_TYPE_TIME: |
| 1236 | ADD_CONFIG_TERM(TIME, time, term->val.num); |
| 1237 | break; |
Kan Liang | d457c96 | 2015-08-11 06:30:47 -0400 | [diff] [blame] | 1238 | case PARSE_EVENTS__TERM_TYPE_CALLGRAPH: |
| 1239 | ADD_CONFIG_TERM(CALLGRAPH, callgraph, term->val.str); |
| 1240 | break; |
Andi Kleen | ac12f67 | 2016-10-12 14:02:06 -0700 | [diff] [blame] | 1241 | case PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE: |
| 1242 | ADD_CONFIG_TERM(BRANCH, branch, term->val.str); |
| 1243 | break; |
Kan Liang | d457c96 | 2015-08-11 06:30:47 -0400 | [diff] [blame] | 1244 | case PARSE_EVENTS__TERM_TYPE_STACKSIZE: |
| 1245 | ADD_CONFIG_TERM(STACK_USER, stack_user, term->val.num); |
| 1246 | break; |
Wang Nan | 374ce93 | 2015-10-28 10:55:02 +0000 | [diff] [blame] | 1247 | case PARSE_EVENTS__TERM_TYPE_INHERIT: |
| 1248 | ADD_CONFIG_TERM(INHERIT, inherit, term->val.num ? 1 : 0); |
| 1249 | break; |
| 1250 | case PARSE_EVENTS__TERM_TYPE_NOINHERIT: |
| 1251 | ADD_CONFIG_TERM(INHERIT, inherit, term->val.num ? 0 : 1); |
| 1252 | break; |
Arnaldo Carvalho de Melo | 792d48b | 2016-04-28 19:03:42 -0300 | [diff] [blame] | 1253 | case PARSE_EVENTS__TERM_TYPE_MAX_STACK: |
| 1254 | ADD_CONFIG_TERM(MAX_STACK, max_stack, term->val.num); |
| 1255 | break; |
Arnaldo Carvalho de Melo | 2fda5ad | 2018-10-19 15:47:34 -0300 | [diff] [blame] | 1256 | case PARSE_EVENTS__TERM_TYPE_MAX_EVENTS: |
| 1257 | ADD_CONFIG_TERM(MAX_EVENTS, max_events, term->val.num); |
| 1258 | break; |
Wang Nan | 626a6b7 | 2016-07-14 08:34:45 +0000 | [diff] [blame] | 1259 | case PARSE_EVENTS__TERM_TYPE_OVERWRITE: |
| 1260 | ADD_CONFIG_TERM(OVERWRITE, overwrite, term->val.num ? 1 : 0); |
| 1261 | break; |
| 1262 | case PARSE_EVENTS__TERM_TYPE_NOOVERWRITE: |
| 1263 | ADD_CONFIG_TERM(OVERWRITE, overwrite, term->val.num ? 0 : 1); |
| 1264 | break; |
Mathieu Poirier | dd60fba | 2016-09-06 10:37:15 -0600 | [diff] [blame] | 1265 | case PARSE_EVENTS__TERM_TYPE_DRV_CFG: |
| 1266 | ADD_CONFIG_TERM(DRV_CFG, drv_cfg, term->val.str); |
| 1267 | break; |
Jin Yao | 064b4e8 | 2019-04-12 21:59:47 +0800 | [diff] [blame] | 1268 | case PARSE_EVENTS__TERM_TYPE_PERCORE: |
| 1269 | ADD_CONFIG_TERM(PERCORE, percore, |
| 1270 | term->val.num ? true : false); |
| 1271 | break; |
Adrian Hunter | 1b99215 | 2019-08-06 11:46:05 +0300 | [diff] [blame] | 1272 | case PARSE_EVENTS__TERM_TYPE_AUX_OUTPUT: |
| 1273 | ADD_CONFIG_TERM(AUX_OUTPUT, aux_output, term->val.num ? 1 : 0); |
| 1274 | break; |
Jiri Olsa | 930a2e2 | 2015-07-29 05:42:10 -0400 | [diff] [blame] | 1275 | default: |
| 1276 | break; |
| 1277 | } |
| 1278 | } |
| 1279 | #undef ADD_EVSEL_CONFIG |
| 1280 | return 0; |
| 1281 | } |
| 1282 | |
He Kuang | e637d17 | 2015-09-28 03:52:16 +0000 | [diff] [blame] | 1283 | int parse_events_add_tracepoint(struct list_head *list, int *idx, |
Wang Nan | 8c619d6 | 2016-07-13 10:44:03 +0000 | [diff] [blame] | 1284 | const char *sys, const char *event, |
Jiri Olsa | 272ed29 | 2015-09-29 17:05:31 +0200 | [diff] [blame] | 1285 | struct parse_events_error *err, |
He Kuang | e637d17 | 2015-09-28 03:52:16 +0000 | [diff] [blame] | 1286 | struct list_head *head_config) |
| 1287 | { |
| 1288 | if (head_config) { |
| 1289 | struct perf_event_attr attr; |
| 1290 | |
Jiri Olsa | 272ed29 | 2015-09-29 17:05:31 +0200 | [diff] [blame] | 1291 | if (config_attr(&attr, head_config, err, |
He Kuang | e637d17 | 2015-09-28 03:52:16 +0000 | [diff] [blame] | 1292 | config_term_tracepoint)) |
| 1293 | return -EINVAL; |
| 1294 | } |
| 1295 | |
| 1296 | if (strpbrk(sys, "*?")) |
| 1297 | return add_tracepoint_multi_sys(list, idx, sys, event, |
Jiri Olsa | 272ed29 | 2015-09-29 17:05:31 +0200 | [diff] [blame] | 1298 | err, head_config); |
He Kuang | e637d17 | 2015-09-28 03:52:16 +0000 | [diff] [blame] | 1299 | else |
| 1300 | return add_tracepoint_event(list, idx, sys, event, |
Jiri Olsa | 272ed29 | 2015-09-29 17:05:31 +0200 | [diff] [blame] | 1301 | err, head_config); |
He Kuang | e637d17 | 2015-09-28 03:52:16 +0000 | [diff] [blame] | 1302 | } |
| 1303 | |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 1304 | int parse_events_add_numeric(struct parse_events_state *parse_state, |
Jiri Olsa | 87d650b | 2015-04-22 21:10:24 +0200 | [diff] [blame] | 1305 | struct list_head *list, |
Robert Richter | b527bab | 2012-08-07 19:43:13 +0200 | [diff] [blame] | 1306 | u32 type, u64 config, |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1307 | struct list_head *head_config) |
Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 1308 | { |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 1309 | struct perf_event_attr attr; |
Jiri Olsa | 930a2e2 | 2015-07-29 05:42:10 -0400 | [diff] [blame] | 1310 | LIST_HEAD(config_terms); |
Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 1311 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 1312 | memset(&attr, 0, sizeof(attr)); |
| 1313 | attr.type = type; |
| 1314 | attr.config = config; |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1315 | |
Jiri Olsa | 930a2e2 | 2015-07-29 05:42:10 -0400 | [diff] [blame] | 1316 | if (head_config) { |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 1317 | if (config_attr(&attr, head_config, parse_state->error, |
He Kuang | 0b8891a | 2015-09-28 03:52:13 +0000 | [diff] [blame] | 1318 | config_term_common)) |
Jiri Olsa | 930a2e2 | 2015-07-29 05:42:10 -0400 | [diff] [blame] | 1319 | return -EINVAL; |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 1320 | |
Jiri Olsa | 930a2e2 | 2015-07-29 05:42:10 -0400 | [diff] [blame] | 1321 | if (get_config_terms(head_config, &config_terms)) |
| 1322 | return -ENOMEM; |
| 1323 | } |
| 1324 | |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 1325 | return add_event(list, &parse_state->idx, &attr, |
Wang Nan | 10bf358 | 2016-02-19 11:44:00 +0000 | [diff] [blame] | 1326 | get_config_name(head_config), &config_terms); |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 1327 | } |
| 1328 | |
Andi Kleen | f0fbb11 | 2019-03-26 15:18:21 -0700 | [diff] [blame] | 1329 | int parse_events_add_tool(struct parse_events_state *parse_state, |
| 1330 | struct list_head *list, |
| 1331 | enum perf_tool_event tool_event) |
| 1332 | { |
| 1333 | return add_event_tool(list, &parse_state->idx, tool_event); |
| 1334 | } |
| 1335 | |
Jin Yao | 064b4e8 | 2019-04-12 21:59:47 +0800 | [diff] [blame] | 1336 | static bool config_term_percore(struct list_head *config_terms) |
| 1337 | { |
| 1338 | struct perf_evsel_config_term *term; |
| 1339 | |
| 1340 | list_for_each_entry(term, config_terms, list) { |
| 1341 | if (term->type == PERF_EVSEL__CONFIG_TERM_PERCORE) |
| 1342 | return term->val.percore; |
| 1343 | } |
| 1344 | |
| 1345 | return false; |
| 1346 | } |
| 1347 | |
Agustin Vega-Frias | c199c11 | 2018-03-06 09:04:44 -0500 | [diff] [blame] | 1348 | int parse_events_add_pmu(struct parse_events_state *parse_state, |
Jiri Olsa | 36adec8 | 2015-04-22 21:10:19 +0200 | [diff] [blame] | 1349 | struct list_head *list, char *name, |
Kan Liang | 3cdc5c2 | 2018-05-07 14:13:43 -0700 | [diff] [blame] | 1350 | struct list_head *head_config, |
| 1351 | bool auto_merge_stats, |
| 1352 | bool use_alias) |
Jiri Olsa | 5f537a2 | 2012-03-15 20:09:18 +0100 | [diff] [blame] | 1353 | { |
| 1354 | struct perf_event_attr attr; |
Matt Fleming | 46441bd | 2014-09-24 15:04:06 +0100 | [diff] [blame] | 1355 | struct perf_pmu_info info; |
Jiri Olsa | 5f537a2 | 2012-03-15 20:09:18 +0100 | [diff] [blame] | 1356 | struct perf_pmu *pmu; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1357 | struct evsel *evsel; |
Andi Kleen | 333b566 | 2017-09-13 14:50:06 -0700 | [diff] [blame] | 1358 | struct parse_events_error *err = parse_state->error; |
Kan Liang | 3cdc5c2 | 2018-05-07 14:13:43 -0700 | [diff] [blame] | 1359 | bool use_uncore_alias; |
Jiri Olsa | 930a2e2 | 2015-07-29 05:42:10 -0400 | [diff] [blame] | 1360 | LIST_HEAD(config_terms); |
Jiri Olsa | 5f537a2 | 2012-03-15 20:09:18 +0100 | [diff] [blame] | 1361 | |
| 1362 | pmu = perf_pmu__find(name); |
Andi Kleen | 333b566 | 2017-09-13 14:50:06 -0700 | [diff] [blame] | 1363 | if (!pmu) { |
Ian Rogers | 448d732 | 2019-10-30 15:34:39 -0700 | [diff] [blame] | 1364 | char *err_str; |
| 1365 | |
| 1366 | if (asprintf(&err_str, |
Andi Kleen | 333b566 | 2017-09-13 14:50:06 -0700 | [diff] [blame] | 1367 | "Cannot find PMU `%s'. Missing kernel support?", |
Ian Rogers | 448d732 | 2019-10-30 15:34:39 -0700 | [diff] [blame] | 1368 | name) >= 0) |
Ian Rogers | a910e46 | 2019-11-15 23:46:52 -0800 | [diff] [blame^] | 1369 | parse_events__handle_error(err, 0, err_str, NULL); |
Jiri Olsa | 5f537a2 | 2012-03-15 20:09:18 +0100 | [diff] [blame] | 1370 | return -EINVAL; |
Andi Kleen | 333b566 | 2017-09-13 14:50:06 -0700 | [diff] [blame] | 1371 | } |
Jiri Olsa | 5f537a2 | 2012-03-15 20:09:18 +0100 | [diff] [blame] | 1372 | |
Adrian Hunter | dc0a620 | 2014-07-31 09:00:49 +0300 | [diff] [blame] | 1373 | if (pmu->default_config) { |
| 1374 | memcpy(&attr, pmu->default_config, |
| 1375 | sizeof(struct perf_event_attr)); |
| 1376 | } else { |
| 1377 | memset(&attr, 0, sizeof(attr)); |
| 1378 | } |
Jiri Olsa | 5f537a2 | 2012-03-15 20:09:18 +0100 | [diff] [blame] | 1379 | |
Kan Liang | 3cdc5c2 | 2018-05-07 14:13:43 -0700 | [diff] [blame] | 1380 | use_uncore_alias = (pmu->is_uncore && use_alias); |
| 1381 | |
Adrian Hunter | ad96227 | 2014-08-15 22:08:40 +0300 | [diff] [blame] | 1382 | if (!head_config) { |
| 1383 | attr.type = pmu->type; |
Andi Kleen | f0fbb11 | 2019-03-26 15:18:21 -0700 | [diff] [blame] | 1384 | evsel = __add_event(list, &parse_state->idx, &attr, NULL, pmu, NULL, |
| 1385 | auto_merge_stats, NULL); |
Agustin Vega-Frias | 8c5421c | 2018-03-06 09:04:43 -0500 | [diff] [blame] | 1386 | if (evsel) { |
| 1387 | evsel->pmu_name = name; |
Kan Liang | 3cdc5c2 | 2018-05-07 14:13:43 -0700 | [diff] [blame] | 1388 | evsel->use_uncore_alias = use_uncore_alias; |
Agustin Vega-Frias | 8c5421c | 2018-03-06 09:04:43 -0500 | [diff] [blame] | 1389 | return 0; |
| 1390 | } else { |
| 1391 | return -ENOMEM; |
| 1392 | } |
Adrian Hunter | ad96227 | 2014-08-15 22:08:40 +0300 | [diff] [blame] | 1393 | } |
| 1394 | |
Matt Fleming | 46441bd | 2014-09-24 15:04:06 +0100 | [diff] [blame] | 1395 | if (perf_pmu__check_alias(pmu, head_config, &info)) |
Zheng Yan | a6146d5 | 2012-06-15 14:31:41 +0800 | [diff] [blame] | 1396 | return -EINVAL; |
| 1397 | |
Jiri Olsa | 5f537a2 | 2012-03-15 20:09:18 +0100 | [diff] [blame] | 1398 | /* |
| 1399 | * Configure hardcoded terms first, no need to check |
| 1400 | * return value when called with fail == 0 ;) |
| 1401 | */ |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 1402 | if (config_attr(&attr, head_config, parse_state->error, config_term_pmu)) |
Jiri Olsa | c056ba6a | 2015-04-22 21:10:18 +0200 | [diff] [blame] | 1403 | return -EINVAL; |
Jiri Olsa | 5f537a2 | 2012-03-15 20:09:18 +0100 | [diff] [blame] | 1404 | |
Jiri Olsa | 930a2e2 | 2015-07-29 05:42:10 -0400 | [diff] [blame] | 1405 | if (get_config_terms(head_config, &config_terms)) |
| 1406 | return -ENOMEM; |
| 1407 | |
Ian Rogers | 38f2c42 | 2019-10-30 15:34:46 -0700 | [diff] [blame] | 1408 | if (perf_pmu__config(pmu, &attr, head_config, parse_state->error)) { |
| 1409 | struct perf_evsel_config_term *pos, *tmp; |
| 1410 | |
| 1411 | list_for_each_entry_safe(pos, tmp, &config_terms, list) { |
| 1412 | list_del_init(&pos->list); |
| 1413 | free(pos); |
| 1414 | } |
Jiri Olsa | 5f537a2 | 2012-03-15 20:09:18 +0100 | [diff] [blame] | 1415 | return -EINVAL; |
Ian Rogers | 38f2c42 | 2019-10-30 15:34:46 -0700 | [diff] [blame] | 1416 | } |
Jiri Olsa | 5f537a2 | 2012-03-15 20:09:18 +0100 | [diff] [blame] | 1417 | |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 1418 | evsel = __add_event(list, &parse_state->idx, &attr, |
Mark Rutland | 66ec1191 | 2017-10-06 19:38:22 +0100 | [diff] [blame] | 1419 | get_config_name(head_config), pmu, |
Andi Kleen | f0fbb11 | 2019-03-26 15:18:21 -0700 | [diff] [blame] | 1420 | &config_terms, auto_merge_stats, NULL); |
Stephane Eranian | 410136f | 2013-11-12 17:58:49 +0100 | [diff] [blame] | 1421 | if (evsel) { |
Matt Fleming | 46441bd | 2014-09-24 15:04:06 +0100 | [diff] [blame] | 1422 | evsel->unit = info.unit; |
| 1423 | evsel->scale = info.scale; |
Matt Fleming | 044330c | 2014-11-21 10:31:12 +0100 | [diff] [blame] | 1424 | evsel->per_pkg = info.per_pkg; |
Jiri Olsa | 1d9e446 | 2014-11-21 10:31:13 +0100 | [diff] [blame] | 1425 | evsel->snapshot = info.snapshot; |
Andi Kleen | 37932c1 | 2017-03-20 13:17:08 -0700 | [diff] [blame] | 1426 | evsel->metric_expr = info.metric_expr; |
Andi Kleen | 9628481 | 2017-03-20 13:17:10 -0700 | [diff] [blame] | 1427 | evsel->metric_name = info.metric_name; |
Agustin Vega-Frias | 8c5421c | 2018-03-06 09:04:43 -0500 | [diff] [blame] | 1428 | evsel->pmu_name = name; |
Kan Liang | 3cdc5c2 | 2018-05-07 14:13:43 -0700 | [diff] [blame] | 1429 | evsel->use_uncore_alias = use_uncore_alias; |
Jin Yao | 064b4e8 | 2019-04-12 21:59:47 +0800 | [diff] [blame] | 1430 | evsel->percore = config_term_percore(&evsel->config_terms); |
Stephane Eranian | 410136f | 2013-11-12 17:58:49 +0100 | [diff] [blame] | 1431 | } |
| 1432 | |
| 1433 | return evsel ? 0 : -ENOMEM; |
Jiri Olsa | 5f537a2 | 2012-03-15 20:09:18 +0100 | [diff] [blame] | 1434 | } |
| 1435 | |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 1436 | int parse_events_multi_pmu_add(struct parse_events_state *parse_state, |
Andi Kleen | 2073ad3 | 2017-03-20 13:17:02 -0700 | [diff] [blame] | 1437 | char *str, struct list_head **listp) |
| 1438 | { |
Andi Kleen | 2073ad3 | 2017-03-20 13:17:02 -0700 | [diff] [blame] | 1439 | struct parse_events_term *term; |
| 1440 | struct list_head *list; |
| 1441 | struct perf_pmu *pmu = NULL; |
| 1442 | int ok = 0; |
| 1443 | |
| 1444 | *listp = NULL; |
| 1445 | /* Add it for all PMUs that support the alias */ |
| 1446 | list = malloc(sizeof(struct list_head)); |
| 1447 | if (!list) |
| 1448 | return -1; |
| 1449 | INIT_LIST_HEAD(list); |
| 1450 | while ((pmu = perf_pmu__scan(pmu)) != NULL) { |
| 1451 | struct perf_pmu_alias *alias; |
| 1452 | |
| 1453 | list_for_each_entry(alias, &pmu->aliases, list) { |
| 1454 | if (!strcasecmp(alias->name, str)) { |
Ian Rogers | b6645a7 | 2019-10-30 15:34:43 -0700 | [diff] [blame] | 1455 | struct list_head *head; |
| 1456 | char *config; |
| 1457 | |
Andi Kleen | 2073ad3 | 2017-03-20 13:17:02 -0700 | [diff] [blame] | 1458 | head = malloc(sizeof(struct list_head)); |
| 1459 | if (!head) |
| 1460 | return -1; |
| 1461 | INIT_LIST_HEAD(head); |
Ian Rogers | b6645a7 | 2019-10-30 15:34:43 -0700 | [diff] [blame] | 1462 | config = strdup(str); |
| 1463 | if (!config) |
Andi Kleen | 2073ad3 | 2017-03-20 13:17:02 -0700 | [diff] [blame] | 1464 | return -1; |
Ian Rogers | b6645a7 | 2019-10-30 15:34:43 -0700 | [diff] [blame] | 1465 | if (parse_events_term__num(&term, |
| 1466 | PARSE_EVENTS__TERM_TYPE_USER, |
| 1467 | config, 1, false, &config, |
| 1468 | NULL) < 0) { |
| 1469 | free(list); |
| 1470 | free(config); |
| 1471 | return -1; |
| 1472 | } |
Andi Kleen | 2073ad3 | 2017-03-20 13:17:02 -0700 | [diff] [blame] | 1473 | list_add_tail(&term->list, head); |
| 1474 | |
Agustin Vega-Frias | c199c11 | 2018-03-06 09:04:44 -0500 | [diff] [blame] | 1475 | if (!parse_events_add_pmu(parse_state, list, |
Kan Liang | 3cdc5c2 | 2018-05-07 14:13:43 -0700 | [diff] [blame] | 1476 | pmu->name, head, |
| 1477 | true, true)) { |
Ian Rogers | b6645a7 | 2019-10-30 15:34:43 -0700 | [diff] [blame] | 1478 | pr_debug("%s -> %s/%s/\n", config, |
Andi Kleen | 2073ad3 | 2017-03-20 13:17:02 -0700 | [diff] [blame] | 1479 | pmu->name, alias->str); |
| 1480 | ok++; |
| 1481 | } |
| 1482 | |
| 1483 | parse_events_terms__delete(head); |
| 1484 | } |
| 1485 | } |
| 1486 | } |
Ian Rogers | b6645a7 | 2019-10-30 15:34:43 -0700 | [diff] [blame] | 1487 | if (!ok) { |
| 1488 | free(list); |
Andi Kleen | 2073ad3 | 2017-03-20 13:17:02 -0700 | [diff] [blame] | 1489 | return -1; |
Ian Rogers | b6645a7 | 2019-10-30 15:34:43 -0700 | [diff] [blame] | 1490 | } |
Andi Kleen | 2073ad3 | 2017-03-20 13:17:02 -0700 | [diff] [blame] | 1491 | *listp = list; |
| 1492 | return 0; |
| 1493 | } |
| 1494 | |
Jiri Olsa | 6a4bb04 | 2012-08-08 12:22:36 +0200 | [diff] [blame] | 1495 | int parse_events__modifier_group(struct list_head *list, |
| 1496 | char *event_mod) |
Jiri Olsa | 89efb02 | 2012-08-08 12:14:14 +0200 | [diff] [blame] | 1497 | { |
Jiri Olsa | 6a4bb04 | 2012-08-08 12:22:36 +0200 | [diff] [blame] | 1498 | return parse_events__modifier_event(list, event_mod, true); |
| 1499 | } |
| 1500 | |
Kan Liang | 3cdc5c2 | 2018-05-07 14:13:43 -0700 | [diff] [blame] | 1501 | /* |
| 1502 | * Check if the two uncore PMUs are from the same uncore block |
| 1503 | * The format of the uncore PMU name is uncore_#blockname_#pmuidx |
| 1504 | */ |
| 1505 | static bool is_same_uncore_block(const char *pmu_name_a, const char *pmu_name_b) |
| 1506 | { |
| 1507 | char *end_a, *end_b; |
| 1508 | |
| 1509 | end_a = strrchr(pmu_name_a, '_'); |
| 1510 | end_b = strrchr(pmu_name_b, '_'); |
| 1511 | |
| 1512 | if (!end_a || !end_b) |
| 1513 | return false; |
| 1514 | |
| 1515 | if ((end_a - pmu_name_a) != (end_b - pmu_name_b)) |
| 1516 | return false; |
| 1517 | |
| 1518 | return (strncmp(pmu_name_a, pmu_name_b, end_a - pmu_name_a) == 0); |
| 1519 | } |
| 1520 | |
| 1521 | static int |
| 1522 | parse_events__set_leader_for_uncore_aliase(char *name, struct list_head *list, |
| 1523 | struct parse_events_state *parse_state) |
| 1524 | { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1525 | struct evsel *evsel, *leader; |
Kan Liang | 3cdc5c2 | 2018-05-07 14:13:43 -0700 | [diff] [blame] | 1526 | uintptr_t *leaders; |
| 1527 | bool is_leader = true; |
| 1528 | int i, nr_pmu = 0, total_members, ret = 0; |
| 1529 | |
Jiri Olsa | b27c4ec | 2019-07-21 13:24:22 +0200 | [diff] [blame] | 1530 | leader = list_first_entry(list, struct evsel, core.node); |
| 1531 | evsel = list_last_entry(list, struct evsel, core.node); |
Kan Liang | 3cdc5c2 | 2018-05-07 14:13:43 -0700 | [diff] [blame] | 1532 | total_members = evsel->idx - leader->idx + 1; |
| 1533 | |
| 1534 | leaders = calloc(total_members, sizeof(uintptr_t)); |
| 1535 | if (WARN_ON(!leaders)) |
| 1536 | return 0; |
| 1537 | |
| 1538 | /* |
| 1539 | * Going through the whole group and doing sanity check. |
| 1540 | * All members must use alias, and be from the same uncore block. |
| 1541 | * Also, storing the leader events in an array. |
| 1542 | */ |
| 1543 | __evlist__for_each_entry(list, evsel) { |
| 1544 | |
| 1545 | /* Only split the uncore group which members use alias */ |
| 1546 | if (!evsel->use_uncore_alias) |
| 1547 | goto out; |
| 1548 | |
| 1549 | /* The events must be from the same uncore block */ |
| 1550 | if (!is_same_uncore_block(leader->pmu_name, evsel->pmu_name)) |
| 1551 | goto out; |
| 1552 | |
| 1553 | if (!is_leader) |
| 1554 | continue; |
| 1555 | /* |
| 1556 | * If the event's PMU name starts to repeat, it must be a new |
| 1557 | * event. That can be used to distinguish the leader from |
| 1558 | * other members, even they have the same event name. |
| 1559 | */ |
| 1560 | if ((leader != evsel) && (leader->pmu_name == evsel->pmu_name)) { |
| 1561 | is_leader = false; |
| 1562 | continue; |
| 1563 | } |
| 1564 | /* The name is always alias name */ |
| 1565 | WARN_ON(strcmp(leader->name, evsel->name)); |
| 1566 | |
| 1567 | /* Store the leader event for each PMU */ |
| 1568 | leaders[nr_pmu++] = (uintptr_t) evsel; |
| 1569 | } |
| 1570 | |
| 1571 | /* only one event alias */ |
| 1572 | if (nr_pmu == total_members) { |
| 1573 | parse_state->nr_groups--; |
| 1574 | goto handled; |
| 1575 | } |
| 1576 | |
| 1577 | /* |
| 1578 | * An uncore event alias is a joint name which means the same event |
| 1579 | * runs on all PMUs of a block. |
| 1580 | * Perf doesn't support mixed events from different PMUs in the same |
| 1581 | * group. The big group has to be split into multiple small groups |
| 1582 | * which only include the events from the same PMU. |
| 1583 | * |
| 1584 | * Here the uncore event aliases must be from the same uncore block. |
| 1585 | * The number of PMUs must be same for each alias. The number of new |
| 1586 | * small groups equals to the number of PMUs. |
| 1587 | * Setting the leader event for corresponding members in each group. |
| 1588 | */ |
| 1589 | i = 0; |
| 1590 | __evlist__for_each_entry(list, evsel) { |
| 1591 | if (i >= nr_pmu) |
| 1592 | i = 0; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1593 | evsel->leader = (struct evsel *) leaders[i++]; |
Kan Liang | 3cdc5c2 | 2018-05-07 14:13:43 -0700 | [diff] [blame] | 1594 | } |
| 1595 | |
| 1596 | /* The number of members and group name are same for each group */ |
| 1597 | for (i = 0; i < nr_pmu; i++) { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1598 | evsel = (struct evsel *) leaders[i]; |
Jiri Olsa | 5643b1a | 2019-07-21 13:24:46 +0200 | [diff] [blame] | 1599 | evsel->core.nr_members = total_members / nr_pmu; |
Kan Liang | 3cdc5c2 | 2018-05-07 14:13:43 -0700 | [diff] [blame] | 1600 | evsel->group_name = name ? strdup(name) : NULL; |
| 1601 | } |
| 1602 | |
| 1603 | /* Take the new small groups into account */ |
| 1604 | parse_state->nr_groups += nr_pmu - 1; |
| 1605 | |
| 1606 | handled: |
| 1607 | ret = 1; |
| 1608 | out: |
| 1609 | free(leaders); |
| 1610 | return ret; |
| 1611 | } |
| 1612 | |
| 1613 | void parse_events__set_leader(char *name, struct list_head *list, |
| 1614 | struct parse_events_state *parse_state) |
Jiri Olsa | 6a4bb04 | 2012-08-08 12:22:36 +0200 | [diff] [blame] | 1615 | { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1616 | struct evsel *leader; |
Jiri Olsa | 6a4bb04 | 2012-08-08 12:22:36 +0200 | [diff] [blame] | 1617 | |
Wang Nan | 854f736 | 2015-09-06 07:13:17 +0000 | [diff] [blame] | 1618 | if (list_empty(list)) { |
| 1619 | WARN_ONCE(true, "WARNING: failed to set leader: empty list"); |
| 1620 | return; |
| 1621 | } |
| 1622 | |
Kan Liang | 3cdc5c2 | 2018-05-07 14:13:43 -0700 | [diff] [blame] | 1623 | if (parse_events__set_leader_for_uncore_aliase(name, list, parse_state)) |
| 1624 | return; |
| 1625 | |
Arnaldo Carvalho de Melo | 63dab22 | 2012-08-14 16:35:48 -0300 | [diff] [blame] | 1626 | __perf_evlist__set_leader(list); |
Jiri Olsa | b27c4ec | 2019-07-21 13:24:22 +0200 | [diff] [blame] | 1627 | leader = list_entry(list->next, struct evsel, core.node); |
Jiri Olsa | 6a4bb04 | 2012-08-08 12:22:36 +0200 | [diff] [blame] | 1628 | leader->group_name = name ? strdup(name) : NULL; |
Jiri Olsa | 89efb02 | 2012-08-08 12:14:14 +0200 | [diff] [blame] | 1629 | } |
| 1630 | |
David Ahern | c5cd8ac | 2013-07-02 13:27:25 -0600 | [diff] [blame] | 1631 | /* list_event is assumed to point to malloc'ed memory */ |
Jiri Olsa | 5d7be90 | 2012-03-20 19:15:40 +0100 | [diff] [blame] | 1632 | void parse_events_update_lists(struct list_head *list_event, |
| 1633 | struct list_head *list_all) |
| 1634 | { |
| 1635 | /* |
| 1636 | * Called for single event definition. Update the |
Jiri Olsa | 89efb02 | 2012-08-08 12:14:14 +0200 | [diff] [blame] | 1637 | * 'all event' list, and reinit the 'single event' |
Jiri Olsa | 5d7be90 | 2012-03-20 19:15:40 +0100 | [diff] [blame] | 1638 | * list, for next event definition. |
| 1639 | */ |
| 1640 | list_splice_tail(list_event, list_all); |
Jiri Olsa | b847cbd | 2012-05-21 09:12:51 +0200 | [diff] [blame] | 1641 | free(list_event); |
Jiri Olsa | 5d7be90 | 2012-03-20 19:15:40 +0100 | [diff] [blame] | 1642 | } |
| 1643 | |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 1644 | struct event_modifier { |
| 1645 | int eu; |
| 1646 | int ek; |
| 1647 | int eh; |
| 1648 | int eH; |
| 1649 | int eG; |
Jiri Olsa | a1e12da | 2015-04-07 23:25:14 +0200 | [diff] [blame] | 1650 | int eI; |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 1651 | int precise; |
Jiri Olsa | 7f94af7 | 2015-10-05 20:06:05 +0200 | [diff] [blame] | 1652 | int precise_max; |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 1653 | int exclude_GH; |
Jiri Olsa | 3c17631 | 2012-10-10 17:39:03 +0200 | [diff] [blame] | 1654 | int sample_read; |
Michael Ellerman | e9a7c41 | 2013-08-06 23:28:05 +1000 | [diff] [blame] | 1655 | int pinned; |
Andi Kleen | 5a5dfe4 | 2017-08-31 12:40:26 -0700 | [diff] [blame] | 1656 | int weak; |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 1657 | }; |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 1658 | |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 1659 | static int get_event_modifier(struct event_modifier *mod, char *str, |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1660 | struct evsel *evsel) |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 1661 | { |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 1662 | int eu = evsel ? evsel->core.attr.exclude_user : 0; |
| 1663 | int ek = evsel ? evsel->core.attr.exclude_kernel : 0; |
| 1664 | int eh = evsel ? evsel->core.attr.exclude_hv : 0; |
| 1665 | int eH = evsel ? evsel->core.attr.exclude_host : 0; |
| 1666 | int eG = evsel ? evsel->core.attr.exclude_guest : 0; |
| 1667 | int eI = evsel ? evsel->core.attr.exclude_idle : 0; |
| 1668 | int precise = evsel ? evsel->core.attr.precise_ip : 0; |
Jiri Olsa | 7f94af7 | 2015-10-05 20:06:05 +0200 | [diff] [blame] | 1669 | int precise_max = 0; |
Jiri Olsa | 3c17631 | 2012-10-10 17:39:03 +0200 | [diff] [blame] | 1670 | int sample_read = 0; |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 1671 | int pinned = evsel ? evsel->core.attr.pinned : 0; |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 1672 | |
| 1673 | int exclude = eu | ek | eh; |
| 1674 | int exclude_GH = evsel ? evsel->exclude_GH : 0; |
Andi Kleen | 5a5dfe4 | 2017-08-31 12:40:26 -0700 | [diff] [blame] | 1675 | int weak = 0; |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 1676 | |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 1677 | memset(mod, 0, sizeof(*mod)); |
Ingo Molnar | ceb53fb | 2011-04-27 04:06:33 +0200 | [diff] [blame] | 1678 | |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 1679 | while (*str) { |
Peter Zijlstra | ab60834 | 2010-04-08 23:03:20 +0200 | [diff] [blame] | 1680 | if (*str == 'u') { |
| 1681 | if (!exclude) |
| 1682 | exclude = eu = ek = eh = 1; |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 1683 | eu = 0; |
Peter Zijlstra | ab60834 | 2010-04-08 23:03:20 +0200 | [diff] [blame] | 1684 | } else if (*str == 'k') { |
| 1685 | if (!exclude) |
| 1686 | exclude = eu = ek = eh = 1; |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 1687 | ek = 0; |
Peter Zijlstra | ab60834 | 2010-04-08 23:03:20 +0200 | [diff] [blame] | 1688 | } else if (*str == 'h') { |
| 1689 | if (!exclude) |
| 1690 | exclude = eu = ek = eh = 1; |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 1691 | eh = 0; |
Joerg Roedel | 99320cc | 2012-01-04 17:54:19 +0100 | [diff] [blame] | 1692 | } else if (*str == 'G') { |
| 1693 | if (!exclude_GH) |
| 1694 | exclude_GH = eG = eH = 1; |
| 1695 | eG = 0; |
| 1696 | } else if (*str == 'H') { |
| 1697 | if (!exclude_GH) |
| 1698 | exclude_GH = eG = eH = 1; |
| 1699 | eH = 0; |
Jiri Olsa | a1e12da | 2015-04-07 23:25:14 +0200 | [diff] [blame] | 1700 | } else if (*str == 'I') { |
| 1701 | eI = 1; |
Peter Zijlstra | ab60834 | 2010-04-08 23:03:20 +0200 | [diff] [blame] | 1702 | } else if (*str == 'p') { |
| 1703 | precise++; |
David Ahern | 1342798 | 2012-09-13 14:59:13 -0600 | [diff] [blame] | 1704 | /* use of precise requires exclude_guest */ |
| 1705 | if (!exclude_GH) |
| 1706 | eG = 1; |
Jiri Olsa | 7f94af7 | 2015-10-05 20:06:05 +0200 | [diff] [blame] | 1707 | } else if (*str == 'P') { |
| 1708 | precise_max = 1; |
Jiri Olsa | 3c17631 | 2012-10-10 17:39:03 +0200 | [diff] [blame] | 1709 | } else if (*str == 'S') { |
| 1710 | sample_read = 1; |
Michael Ellerman | e9a7c41 | 2013-08-06 23:28:05 +1000 | [diff] [blame] | 1711 | } else if (*str == 'D') { |
| 1712 | pinned = 1; |
Andi Kleen | 5a5dfe4 | 2017-08-31 12:40:26 -0700 | [diff] [blame] | 1713 | } else if (*str == 'W') { |
| 1714 | weak = 1; |
Peter Zijlstra | ab60834 | 2010-04-08 23:03:20 +0200 | [diff] [blame] | 1715 | } else |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 1716 | break; |
Peter Zijlstra | ab60834 | 2010-04-08 23:03:20 +0200 | [diff] [blame] | 1717 | |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 1718 | ++str; |
| 1719 | } |
Ingo Molnar | ceb53fb | 2011-04-27 04:06:33 +0200 | [diff] [blame] | 1720 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 1721 | /* |
| 1722 | * precise ip: |
| 1723 | * |
| 1724 | * 0 - SAMPLE_IP can have arbitrary skid |
| 1725 | * 1 - SAMPLE_IP must have constant skid |
| 1726 | * 2 - SAMPLE_IP requested to have 0 skid |
| 1727 | * 3 - SAMPLE_IP must have 0 skid |
| 1728 | * |
| 1729 | * See also PERF_RECORD_MISC_EXACT_IP |
| 1730 | */ |
| 1731 | if (precise > 3) |
| 1732 | return -EINVAL; |
Ingo Molnar | ceb53fb | 2011-04-27 04:06:33 +0200 | [diff] [blame] | 1733 | |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 1734 | mod->eu = eu; |
| 1735 | mod->ek = ek; |
| 1736 | mod->eh = eh; |
| 1737 | mod->eH = eH; |
| 1738 | mod->eG = eG; |
Jiri Olsa | a1e12da | 2015-04-07 23:25:14 +0200 | [diff] [blame] | 1739 | mod->eI = eI; |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 1740 | mod->precise = precise; |
Jiri Olsa | 7f94af7 | 2015-10-05 20:06:05 +0200 | [diff] [blame] | 1741 | mod->precise_max = precise_max; |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 1742 | mod->exclude_GH = exclude_GH; |
Jiri Olsa | 3c17631 | 2012-10-10 17:39:03 +0200 | [diff] [blame] | 1743 | mod->sample_read = sample_read; |
Michael Ellerman | e9a7c41 | 2013-08-06 23:28:05 +1000 | [diff] [blame] | 1744 | mod->pinned = pinned; |
Andi Kleen | 5a5dfe4 | 2017-08-31 12:40:26 -0700 | [diff] [blame] | 1745 | mod->weak = weak; |
Michael Ellerman | e9a7c41 | 2013-08-06 23:28:05 +1000 | [diff] [blame] | 1746 | |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 1747 | return 0; |
| 1748 | } |
| 1749 | |
Jiri Olsa | 534123f | 2012-11-13 15:32:58 +0100 | [diff] [blame] | 1750 | /* |
| 1751 | * Basic modifier sanity check to validate it contains only one |
| 1752 | * instance of any modifier (apart from 'p') present. |
| 1753 | */ |
| 1754 | static int check_modifier(char *str) |
| 1755 | { |
| 1756 | char *p = str; |
| 1757 | |
| 1758 | /* The sizeof includes 0 byte as well. */ |
Andi Kleen | 5a5dfe4 | 2017-08-31 12:40:26 -0700 | [diff] [blame] | 1759 | if (strlen(str) > (sizeof("ukhGHpppPSDIW") - 1)) |
Jiri Olsa | 534123f | 2012-11-13 15:32:58 +0100 | [diff] [blame] | 1760 | return -1; |
| 1761 | |
| 1762 | while (*p) { |
| 1763 | if (*p != 'p' && strchr(p + 1, *p)) |
| 1764 | return -1; |
| 1765 | p++; |
| 1766 | } |
| 1767 | |
| 1768 | return 0; |
| 1769 | } |
| 1770 | |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 1771 | int parse_events__modifier_event(struct list_head *list, char *str, bool add) |
| 1772 | { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1773 | struct evsel *evsel; |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 1774 | struct event_modifier mod; |
| 1775 | |
| 1776 | if (str == NULL) |
| 1777 | return 0; |
| 1778 | |
Jiri Olsa | 534123f | 2012-11-13 15:32:58 +0100 | [diff] [blame] | 1779 | if (check_modifier(str)) |
| 1780 | return -EINVAL; |
| 1781 | |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 1782 | if (!add && get_event_modifier(&mod, str, NULL)) |
| 1783 | return -EINVAL; |
| 1784 | |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 1785 | __evlist__for_each_entry(list, evsel) { |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 1786 | if (add && get_event_modifier(&mod, str, evsel)) |
| 1787 | return -EINVAL; |
| 1788 | |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 1789 | evsel->core.attr.exclude_user = mod.eu; |
| 1790 | evsel->core.attr.exclude_kernel = mod.ek; |
| 1791 | evsel->core.attr.exclude_hv = mod.eh; |
| 1792 | evsel->core.attr.precise_ip = mod.precise; |
| 1793 | evsel->core.attr.exclude_host = mod.eH; |
| 1794 | evsel->core.attr.exclude_guest = mod.eG; |
| 1795 | evsel->core.attr.exclude_idle = mod.eI; |
Jiri Olsa | f5b1135 | 2012-08-08 12:21:54 +0200 | [diff] [blame] | 1796 | evsel->exclude_GH = mod.exclude_GH; |
Jiri Olsa | 3c17631 | 2012-10-10 17:39:03 +0200 | [diff] [blame] | 1797 | evsel->sample_read = mod.sample_read; |
Jiri Olsa | 7f94af7 | 2015-10-05 20:06:05 +0200 | [diff] [blame] | 1798 | evsel->precise_max = mod.precise_max; |
Andi Kleen | 5a5dfe4 | 2017-08-31 12:40:26 -0700 | [diff] [blame] | 1799 | evsel->weak_group = mod.weak; |
Michael Ellerman | e9a7c41 | 2013-08-06 23:28:05 +1000 | [diff] [blame] | 1800 | |
| 1801 | if (perf_evsel__is_group_leader(evsel)) |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 1802 | evsel->core.attr.pinned = mod.pinned; |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 1803 | } |
Ingo Molnar | ceb53fb | 2011-04-27 04:06:33 +0200 | [diff] [blame] | 1804 | |
Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 1805 | return 0; |
| 1806 | } |
| 1807 | |
Robert Richter | ac2ba9f | 2012-08-16 21:10:21 +0200 | [diff] [blame] | 1808 | int parse_events_name(struct list_head *list, char *name) |
| 1809 | { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1810 | struct evsel *evsel; |
Robert Richter | ac2ba9f | 2012-08-16 21:10:21 +0200 | [diff] [blame] | 1811 | |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 1812 | __evlist__for_each_entry(list, evsel) { |
Robert Richter | ac2ba9f | 2012-08-16 21:10:21 +0200 | [diff] [blame] | 1813 | if (!evsel->name) |
| 1814 | evsel->name = strdup(name); |
| 1815 | } |
| 1816 | |
| 1817 | return 0; |
| 1818 | } |
| 1819 | |
Kan Liang | dcb4e10 | 2014-10-07 11:08:50 -0400 | [diff] [blame] | 1820 | static int |
| 1821 | comp_pmu(const void *p1, const void *p2) |
| 1822 | { |
| 1823 | struct perf_pmu_event_symbol *pmu1 = (struct perf_pmu_event_symbol *) p1; |
| 1824 | struct perf_pmu_event_symbol *pmu2 = (struct perf_pmu_event_symbol *) p2; |
| 1825 | |
Andi Kleen | e312bcf | 2016-09-15 15:24:53 -0700 | [diff] [blame] | 1826 | return strcasecmp(pmu1->symbol, pmu2->symbol); |
Kan Liang | dcb4e10 | 2014-10-07 11:08:50 -0400 | [diff] [blame] | 1827 | } |
| 1828 | |
| 1829 | static void perf_pmu__parse_cleanup(void) |
| 1830 | { |
| 1831 | if (perf_pmu_events_list_num > 0) { |
| 1832 | struct perf_pmu_event_symbol *p; |
| 1833 | int i; |
| 1834 | |
| 1835 | for (i = 0; i < perf_pmu_events_list_num; i++) { |
| 1836 | p = perf_pmu_events_list + i; |
Taeung Song | 360e071 | 2017-02-01 21:34:07 +0900 | [diff] [blame] | 1837 | zfree(&p->symbol); |
Kan Liang | dcb4e10 | 2014-10-07 11:08:50 -0400 | [diff] [blame] | 1838 | } |
Taeung Song | 506fde1 | 2017-02-01 21:34:06 +0900 | [diff] [blame] | 1839 | zfree(&perf_pmu_events_list); |
Kan Liang | dcb4e10 | 2014-10-07 11:08:50 -0400 | [diff] [blame] | 1840 | perf_pmu_events_list_num = 0; |
| 1841 | } |
| 1842 | } |
| 1843 | |
| 1844 | #define SET_SYMBOL(str, stype) \ |
| 1845 | do { \ |
| 1846 | p->symbol = str; \ |
| 1847 | if (!p->symbol) \ |
| 1848 | goto err; \ |
| 1849 | p->type = stype; \ |
| 1850 | } while (0) |
| 1851 | |
| 1852 | /* |
| 1853 | * Read the pmu events list from sysfs |
| 1854 | * Save it into perf_pmu_events_list |
| 1855 | */ |
| 1856 | static void perf_pmu__parse_init(void) |
| 1857 | { |
| 1858 | |
| 1859 | struct perf_pmu *pmu = NULL; |
| 1860 | struct perf_pmu_alias *alias; |
| 1861 | int len = 0; |
| 1862 | |
Andi Kleen | 231bb2a | 2017-01-27 18:03:39 -0800 | [diff] [blame] | 1863 | pmu = NULL; |
| 1864 | while ((pmu = perf_pmu__scan(pmu)) != NULL) { |
| 1865 | list_for_each_entry(alias, &pmu->aliases, list) { |
| 1866 | if (strchr(alias->name, '-')) |
| 1867 | len++; |
| 1868 | len++; |
| 1869 | } |
| 1870 | } |
| 1871 | |
| 1872 | if (len == 0) { |
Kan Liang | dcb4e10 | 2014-10-07 11:08:50 -0400 | [diff] [blame] | 1873 | perf_pmu_events_list_num = -1; |
| 1874 | return; |
| 1875 | } |
Kan Liang | dcb4e10 | 2014-10-07 11:08:50 -0400 | [diff] [blame] | 1876 | perf_pmu_events_list = malloc(sizeof(struct perf_pmu_event_symbol) * len); |
| 1877 | if (!perf_pmu_events_list) |
| 1878 | return; |
| 1879 | perf_pmu_events_list_num = len; |
| 1880 | |
| 1881 | len = 0; |
Andi Kleen | 231bb2a | 2017-01-27 18:03:39 -0800 | [diff] [blame] | 1882 | pmu = NULL; |
| 1883 | while ((pmu = perf_pmu__scan(pmu)) != NULL) { |
| 1884 | list_for_each_entry(alias, &pmu->aliases, list) { |
| 1885 | struct perf_pmu_event_symbol *p = perf_pmu_events_list + len; |
| 1886 | char *tmp = strchr(alias->name, '-'); |
Kan Liang | dcb4e10 | 2014-10-07 11:08:50 -0400 | [diff] [blame] | 1887 | |
Andi Kleen | 231bb2a | 2017-01-27 18:03:39 -0800 | [diff] [blame] | 1888 | if (tmp != NULL) { |
| 1889 | SET_SYMBOL(strndup(alias->name, tmp - alias->name), |
| 1890 | PMU_EVENT_SYMBOL_PREFIX); |
| 1891 | p++; |
| 1892 | SET_SYMBOL(strdup(++tmp), PMU_EVENT_SYMBOL_SUFFIX); |
| 1893 | len += 2; |
| 1894 | } else { |
| 1895 | SET_SYMBOL(strdup(alias->name), PMU_EVENT_SYMBOL); |
| 1896 | len++; |
| 1897 | } |
Kan Liang | dcb4e10 | 2014-10-07 11:08:50 -0400 | [diff] [blame] | 1898 | } |
| 1899 | } |
| 1900 | qsort(perf_pmu_events_list, len, |
| 1901 | sizeof(struct perf_pmu_event_symbol), comp_pmu); |
| 1902 | |
| 1903 | return; |
| 1904 | err: |
| 1905 | perf_pmu__parse_cleanup(); |
| 1906 | } |
| 1907 | |
| 1908 | enum perf_pmu_event_symbol_type |
| 1909 | perf_pmu__parse_check(const char *name) |
| 1910 | { |
| 1911 | struct perf_pmu_event_symbol p, *r; |
| 1912 | |
| 1913 | /* scan kernel pmu events from sysfs if needed */ |
| 1914 | if (perf_pmu_events_list_num == 0) |
| 1915 | perf_pmu__parse_init(); |
| 1916 | /* |
| 1917 | * name "cpu" could be prefix of cpu-cycles or cpu// events. |
| 1918 | * cpu-cycles has been handled by hardcode. |
| 1919 | * So it must be cpu// events, not kernel pmu event. |
| 1920 | */ |
| 1921 | if ((perf_pmu_events_list_num <= 0) || !strcmp(name, "cpu")) |
| 1922 | return PMU_EVENT_SYMBOL_ERR; |
| 1923 | |
| 1924 | p.symbol = strdup(name); |
| 1925 | r = bsearch(&p, perf_pmu_events_list, |
| 1926 | (size_t) perf_pmu_events_list_num, |
| 1927 | sizeof(struct perf_pmu_event_symbol), comp_pmu); |
Taeung Song | 360e071 | 2017-02-01 21:34:07 +0900 | [diff] [blame] | 1928 | zfree(&p.symbol); |
Kan Liang | dcb4e10 | 2014-10-07 11:08:50 -0400 | [diff] [blame] | 1929 | return r ? r->type : PMU_EVENT_SYMBOL_ERR; |
| 1930 | } |
| 1931 | |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 1932 | static int parse_events__scanner(const char *str, void *parse_state, int start_token) |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 1933 | { |
| 1934 | YY_BUFFER_STATE buffer; |
| 1935 | void *scanner; |
| 1936 | int ret; |
| 1937 | |
Jiri Olsa | 90e2b22 | 2012-06-15 14:31:40 +0800 | [diff] [blame] | 1938 | ret = parse_events_lex_init_extra(start_token, &scanner); |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 1939 | if (ret) |
| 1940 | return ret; |
| 1941 | |
| 1942 | buffer = parse_events__scan_string(str, scanner); |
| 1943 | |
| 1944 | #ifdef PARSER_DEBUG |
| 1945 | parse_events_debug = 1; |
| 1946 | #endif |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 1947 | ret = parse_events_parse(parse_state, scanner); |
Zheng Yan | ac20de6f | 2012-06-15 14:31:39 +0800 | [diff] [blame] | 1948 | |
| 1949 | parse_events__flush_buffer(buffer, scanner); |
| 1950 | parse_events__delete_buffer(buffer, scanner); |
| 1951 | parse_events_lex_destroy(scanner); |
| 1952 | return ret; |
| 1953 | } |
| 1954 | |
Jiri Olsa | 90e2b22 | 2012-06-15 14:31:40 +0800 | [diff] [blame] | 1955 | /* |
| 1956 | * parse event config string, return a list of event terms. |
| 1957 | */ |
| 1958 | int parse_events_terms(struct list_head *terms, const char *str) |
| 1959 | { |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 1960 | struct parse_events_state parse_state = { |
Jiri Olsa | 90e2b22 | 2012-06-15 14:31:40 +0800 | [diff] [blame] | 1961 | .terms = NULL, |
| 1962 | }; |
| 1963 | int ret; |
| 1964 | |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 1965 | ret = parse_events__scanner(str, &parse_state, PE_START_TERMS); |
Jiri Olsa | 90e2b22 | 2012-06-15 14:31:40 +0800 | [diff] [blame] | 1966 | if (!ret) { |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 1967 | list_splice(parse_state.terms, terms); |
| 1968 | zfree(&parse_state.terms); |
Jiri Olsa | 90e2b22 | 2012-06-15 14:31:40 +0800 | [diff] [blame] | 1969 | return 0; |
| 1970 | } |
| 1971 | |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 1972 | parse_events_terms__delete(parse_state.terms); |
Jiri Olsa | 90e2b22 | 2012-06-15 14:31:40 +0800 | [diff] [blame] | 1973 | return ret; |
| 1974 | } |
| 1975 | |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 1976 | int parse_events(struct evlist *evlist, const char *str, |
Jiri Olsa | b39b839 | 2015-04-22 21:10:16 +0200 | [diff] [blame] | 1977 | struct parse_events_error *err) |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 1978 | { |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 1979 | struct parse_events_state parse_state = { |
| 1980 | .list = LIST_HEAD_INIT(parse_state.list), |
Jiri Olsa | 6484d2f | 2019-07-21 13:24:28 +0200 | [diff] [blame] | 1981 | .idx = evlist->core.nr_entries, |
Wang Nan | 7630b3e | 2016-02-22 09:10:33 +0000 | [diff] [blame] | 1982 | .error = err, |
| 1983 | .evlist = evlist, |
Jiri Olsa | 46010ab | 2012-06-15 14:31:38 +0800 | [diff] [blame] | 1984 | }; |
Jiri Olsa | 46010ab | 2012-06-15 14:31:38 +0800 | [diff] [blame] | 1985 | int ret; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 1986 | |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 1987 | ret = parse_events__scanner(str, &parse_state, PE_START_EVENTS); |
Kan Liang | dcb4e10 | 2014-10-07 11:08:50 -0400 | [diff] [blame] | 1988 | perf_pmu__parse_cleanup(); |
Ian Rogers | 8e8714c | 2019-10-25 11:08:22 -0700 | [diff] [blame] | 1989 | |
| 1990 | if (!ret && list_empty(&parse_state.list)) { |
| 1991 | WARN_ONCE(true, "WARNING: event parser found nothing\n"); |
| 1992 | return -1; |
| 1993 | } |
| 1994 | |
| 1995 | /* |
| 1996 | * Add list to the evlist even with errors to allow callers to clean up. |
| 1997 | */ |
| 1998 | perf_evlist__splice_list_tail(evlist, &parse_state.list); |
| 1999 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 2000 | if (!ret) { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2001 | struct evsel *last; |
Wang Nan | 15bfd2c | 2015-07-10 07:36:09 +0000 | [diff] [blame] | 2002 | |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 2003 | evlist->nr_groups += parse_state.nr_groups; |
Jiri Olsa | 515dbe4 | 2019-09-03 10:39:52 +0200 | [diff] [blame] | 2004 | last = evlist__last(evlist); |
Wang Nan | 15bfd2c | 2015-07-10 07:36:09 +0000 | [diff] [blame] | 2005 | last->cmdline_group_boundary = true; |
| 2006 | |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 2007 | return 0; |
| 2008 | } |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 2009 | |
Jiri Olsa | 5d7be90 | 2012-03-20 19:15:40 +0100 | [diff] [blame] | 2010 | /* |
| 2011 | * There are 2 users - builtin-record and builtin-test objects. |
Jiri Olsa | c12995a | 2019-07-21 13:23:56 +0200 | [diff] [blame] | 2012 | * Both call evlist__delete in case of error, so we dont |
Jiri Olsa | 5d7be90 | 2012-03-20 19:15:40 +0100 | [diff] [blame] | 2013 | * need to bother. |
| 2014 | */ |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 2015 | return ret; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 2016 | } |
| 2017 | |
Jiri Olsa | b39b839 | 2015-04-22 21:10:16 +0200 | [diff] [blame] | 2018 | #define MAX_WIDTH 1000 |
| 2019 | static int get_term_width(void) |
| 2020 | { |
| 2021 | struct winsize ws; |
| 2022 | |
| 2023 | get_term_dimensions(&ws); |
| 2024 | return ws.ws_col > MAX_WIDTH ? MAX_WIDTH : ws.ws_col; |
| 2025 | } |
| 2026 | |
Ian Rogers | a910e46 | 2019-11-15 23:46:52 -0800 | [diff] [blame^] | 2027 | static void __parse_events_print_error(int err_idx, const char *err_str, |
| 2028 | const char *err_help, const char *event) |
Jiri Olsa | b39b839 | 2015-04-22 21:10:16 +0200 | [diff] [blame] | 2029 | { |
| 2030 | const char *str = "invalid or unsupported event: "; |
| 2031 | char _buf[MAX_WIDTH]; |
| 2032 | char *buf = (char *) event; |
| 2033 | int idx = 0; |
Ian Rogers | a910e46 | 2019-11-15 23:46:52 -0800 | [diff] [blame^] | 2034 | if (err_str) { |
Jiri Olsa | b39b839 | 2015-04-22 21:10:16 +0200 | [diff] [blame] | 2035 | /* -2 for extra '' in the final fprintf */ |
| 2036 | int width = get_term_width() - 2; |
| 2037 | int len_event = strlen(event); |
| 2038 | int len_str, max_len, cut = 0; |
| 2039 | |
| 2040 | /* |
| 2041 | * Maximum error index indent, we will cut |
| 2042 | * the event string if it's bigger. |
| 2043 | */ |
Adrian Hunter | 141b2d3 | 2015-07-17 19:33:51 +0300 | [diff] [blame] | 2044 | int max_err_idx = 13; |
Jiri Olsa | b39b839 | 2015-04-22 21:10:16 +0200 | [diff] [blame] | 2045 | |
| 2046 | /* |
| 2047 | * Let's be specific with the message when |
| 2048 | * we have the precise error. |
| 2049 | */ |
| 2050 | str = "event syntax error: "; |
| 2051 | len_str = strlen(str); |
| 2052 | max_len = width - len_str; |
| 2053 | |
| 2054 | buf = _buf; |
| 2055 | |
Adam Buchbinder | bd1a0be5 | 2016-02-24 10:02:25 -0800 | [diff] [blame] | 2056 | /* We're cutting from the beginning. */ |
Ian Rogers | a910e46 | 2019-11-15 23:46:52 -0800 | [diff] [blame^] | 2057 | if (err_idx > max_err_idx) |
| 2058 | cut = err_idx - max_err_idx; |
Jiri Olsa | b39b839 | 2015-04-22 21:10:16 +0200 | [diff] [blame] | 2059 | |
| 2060 | strncpy(buf, event + cut, max_len); |
| 2061 | |
| 2062 | /* Mark cut parts with '..' on both sides. */ |
| 2063 | if (cut) |
| 2064 | buf[0] = buf[1] = '.'; |
| 2065 | |
| 2066 | if ((len_event - cut) > max_len) { |
| 2067 | buf[max_len - 1] = buf[max_len - 2] = '.'; |
| 2068 | buf[max_len] = 0; |
| 2069 | } |
| 2070 | |
Ian Rogers | a910e46 | 2019-11-15 23:46:52 -0800 | [diff] [blame^] | 2071 | idx = len_str + err_idx - cut; |
Jiri Olsa | b39b839 | 2015-04-22 21:10:16 +0200 | [diff] [blame] | 2072 | } |
| 2073 | |
| 2074 | fprintf(stderr, "%s'%s'\n", str, buf); |
| 2075 | if (idx) { |
Ian Rogers | a910e46 | 2019-11-15 23:46:52 -0800 | [diff] [blame^] | 2076 | fprintf(stderr, "%*s\\___ %s\n", idx + 1, "", err_str); |
| 2077 | if (err_help) |
| 2078 | fprintf(stderr, "\n%s\n", err_help); |
| 2079 | } |
| 2080 | } |
| 2081 | |
| 2082 | void parse_events_print_error(struct parse_events_error *err, |
| 2083 | const char *event) |
| 2084 | { |
| 2085 | if (!err->num_errors) |
| 2086 | return; |
| 2087 | |
| 2088 | __parse_events_print_error(err->idx, err->str, err->help, event); |
| 2089 | zfree(&err->str); |
| 2090 | zfree(&err->help); |
| 2091 | |
| 2092 | if (err->num_errors > 1) { |
| 2093 | fputs("\nInitial error:\n", stderr); |
| 2094 | __parse_events_print_error(err->first_idx, err->first_str, |
| 2095 | err->first_help, event); |
| 2096 | zfree(&err->first_str); |
| 2097 | zfree(&err->first_help); |
Jiri Olsa | b39b839 | 2015-04-22 21:10:16 +0200 | [diff] [blame] | 2098 | } |
Jiri Olsa | b39b839 | 2015-04-22 21:10:16 +0200 | [diff] [blame] | 2099 | } |
| 2100 | |
| 2101 | #undef MAX_WIDTH |
| 2102 | |
Jiri Olsa | f120f9d | 2011-07-14 11:25:32 +0200 | [diff] [blame] | 2103 | int parse_events_option(const struct option *opt, const char *str, |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 2104 | int unset __maybe_unused) |
Jiri Olsa | f120f9d | 2011-07-14 11:25:32 +0200 | [diff] [blame] | 2105 | { |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 2106 | struct evlist *evlist = *(struct evlist **)opt->value; |
Ian Rogers | a910e46 | 2019-11-15 23:46:52 -0800 | [diff] [blame^] | 2107 | struct parse_events_error err; |
| 2108 | int ret; |
| 2109 | |
| 2110 | bzero(&err, sizeof(err)); |
| 2111 | ret = parse_events(evlist, str, &err); |
Andi Kleen | 9175ce1 | 2012-10-26 13:30:06 -0700 | [diff] [blame] | 2112 | |
Andi Kleen | 333b566 | 2017-09-13 14:50:06 -0700 | [diff] [blame] | 2113 | if (ret) { |
Jiri Olsa | b39b839 | 2015-04-22 21:10:16 +0200 | [diff] [blame] | 2114 | parse_events_print_error(&err, str); |
Andi Kleen | 333b566 | 2017-09-13 14:50:06 -0700 | [diff] [blame] | 2115 | fprintf(stderr, "Run 'perf list' for a list of valid events\n"); |
| 2116 | } |
Jiri Olsa | b39b839 | 2015-04-22 21:10:16 +0200 | [diff] [blame] | 2117 | |
Andi Kleen | 9175ce1 | 2012-10-26 13:30:06 -0700 | [diff] [blame] | 2118 | return ret; |
Jiri Olsa | f120f9d | 2011-07-14 11:25:32 +0200 | [diff] [blame] | 2119 | } |
| 2120 | |
Wang Nan | 4ba1faa | 2015-07-10 07:36:10 +0000 | [diff] [blame] | 2121 | static int |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 2122 | foreach_evsel_in_last_glob(struct evlist *evlist, |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2123 | int (*func)(struct evsel *evsel, |
Wang Nan | 4ba1faa | 2015-07-10 07:36:10 +0000 | [diff] [blame] | 2124 | const void *arg), |
| 2125 | const void *arg) |
Li Zefan | c171b55 | 2009-10-15 11:22:07 +0800 | [diff] [blame] | 2126 | { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2127 | struct evsel *last = NULL; |
Wang Nan | 4ba1faa | 2015-07-10 07:36:10 +0000 | [diff] [blame] | 2128 | int err; |
Li Zefan | c171b55 | 2009-10-15 11:22:07 +0800 | [diff] [blame] | 2129 | |
Wang Nan | 854f736 | 2015-09-06 07:13:17 +0000 | [diff] [blame] | 2130 | /* |
| 2131 | * Don't return when list_empty, give func a chance to report |
| 2132 | * error when it found last == NULL. |
| 2133 | * |
| 2134 | * So no need to WARN here, let *func do this. |
| 2135 | */ |
Jiri Olsa | 6484d2f | 2019-07-21 13:24:28 +0200 | [diff] [blame] | 2136 | if (evlist->core.nr_entries > 0) |
Jiri Olsa | 515dbe4 | 2019-09-03 10:39:52 +0200 | [diff] [blame] | 2137 | last = evlist__last(evlist); |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 2138 | |
Wang Nan | 15bfd2c | 2015-07-10 07:36:09 +0000 | [diff] [blame] | 2139 | do { |
Wang Nan | 4ba1faa | 2015-07-10 07:36:10 +0000 | [diff] [blame] | 2140 | err = (*func)(last, arg); |
| 2141 | if (err) |
Wang Nan | 15bfd2c | 2015-07-10 07:36:09 +0000 | [diff] [blame] | 2142 | return -1; |
Wang Nan | 4ba1faa | 2015-07-10 07:36:10 +0000 | [diff] [blame] | 2143 | if (!last) |
| 2144 | return 0; |
Wang Nan | 15bfd2c | 2015-07-10 07:36:09 +0000 | [diff] [blame] | 2145 | |
Jiri Olsa | ce9036a | 2019-07-21 13:24:23 +0200 | [diff] [blame] | 2146 | if (last->core.node.prev == &evlist->core.entries) |
Wang Nan | 15bfd2c | 2015-07-10 07:36:09 +0000 | [diff] [blame] | 2147 | return 0; |
Jiri Olsa | b27c4ec | 2019-07-21 13:24:22 +0200 | [diff] [blame] | 2148 | last = list_entry(last->core.node.prev, struct evsel, core.node); |
Wang Nan | 15bfd2c | 2015-07-10 07:36:09 +0000 | [diff] [blame] | 2149 | } while (!last->cmdline_group_boundary); |
Li Zefan | c171b55 | 2009-10-15 11:22:07 +0800 | [diff] [blame] | 2150 | |
| 2151 | return 0; |
| 2152 | } |
| 2153 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2154 | static int set_filter(struct evsel *evsel, const void *arg) |
Wang Nan | 4ba1faa | 2015-07-10 07:36:10 +0000 | [diff] [blame] | 2155 | { |
| 2156 | const char *str = arg; |
Mathieu Poirier | 1e85748 | 2016-09-16 08:44:05 -0600 | [diff] [blame] | 2157 | bool found = false; |
| 2158 | int nr_addr_filters = 0; |
| 2159 | struct perf_pmu *pmu = NULL; |
Wang Nan | 4ba1faa | 2015-07-10 07:36:10 +0000 | [diff] [blame] | 2160 | |
Jack Henschel | 49836f7 | 2018-07-04 14:13:45 +0200 | [diff] [blame] | 2161 | if (evsel == NULL) { |
| 2162 | fprintf(stderr, |
| 2163 | "--filter option should follow a -e tracepoint or HW tracer option\n"); |
| 2164 | return -1; |
| 2165 | } |
Mathieu Poirier | 1e85748 | 2016-09-16 08:44:05 -0600 | [diff] [blame] | 2166 | |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 2167 | if (evsel->core.attr.type == PERF_TYPE_TRACEPOINT) { |
Mathieu Poirier | 1e85748 | 2016-09-16 08:44:05 -0600 | [diff] [blame] | 2168 | if (perf_evsel__append_tp_filter(evsel, str) < 0) { |
| 2169 | fprintf(stderr, |
| 2170 | "not enough memory to hold filter string\n"); |
| 2171 | return -1; |
| 2172 | } |
| 2173 | |
| 2174 | return 0; |
Wang Nan | 4ba1faa | 2015-07-10 07:36:10 +0000 | [diff] [blame] | 2175 | } |
| 2176 | |
Mathieu Poirier | 1e85748 | 2016-09-16 08:44:05 -0600 | [diff] [blame] | 2177 | while ((pmu = perf_pmu__scan(pmu)) != NULL) |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 2178 | if (pmu->type == evsel->core.attr.type) { |
Mathieu Poirier | 1e85748 | 2016-09-16 08:44:05 -0600 | [diff] [blame] | 2179 | found = true; |
| 2180 | break; |
| 2181 | } |
| 2182 | |
| 2183 | if (found) |
| 2184 | perf_pmu__scan_file(pmu, "nr_addr_filters", |
| 2185 | "%d", &nr_addr_filters); |
| 2186 | |
Jack Henschel | 49836f7 | 2018-07-04 14:13:45 +0200 | [diff] [blame] | 2187 | if (!nr_addr_filters) { |
| 2188 | fprintf(stderr, |
| 2189 | "This CPU does not support address filtering\n"); |
| 2190 | return -1; |
| 2191 | } |
Mathieu Poirier | 1e85748 | 2016-09-16 08:44:05 -0600 | [diff] [blame] | 2192 | |
| 2193 | if (perf_evsel__append_addr_filter(evsel, str) < 0) { |
Wang Nan | 4ba1faa | 2015-07-10 07:36:10 +0000 | [diff] [blame] | 2194 | fprintf(stderr, |
| 2195 | "not enough memory to hold filter string\n"); |
| 2196 | return -1; |
| 2197 | } |
| 2198 | |
| 2199 | return 0; |
| 2200 | } |
| 2201 | |
| 2202 | int parse_filter(const struct option *opt, const char *str, |
| 2203 | int unset __maybe_unused) |
| 2204 | { |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 2205 | struct evlist *evlist = *(struct evlist **)opt->value; |
Wang Nan | 4ba1faa | 2015-07-10 07:36:10 +0000 | [diff] [blame] | 2206 | |
| 2207 | return foreach_evsel_in_last_glob(evlist, set_filter, |
| 2208 | (const void *)str); |
| 2209 | } |
| 2210 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2211 | static int add_exclude_perf_filter(struct evsel *evsel, |
Wang Nan | 4ba1faa | 2015-07-10 07:36:10 +0000 | [diff] [blame] | 2212 | const void *arg __maybe_unused) |
| 2213 | { |
| 2214 | char new_filter[64]; |
| 2215 | |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 2216 | if (evsel == NULL || evsel->core.attr.type != PERF_TYPE_TRACEPOINT) { |
Wang Nan | 4ba1faa | 2015-07-10 07:36:10 +0000 | [diff] [blame] | 2217 | fprintf(stderr, |
| 2218 | "--exclude-perf option should follow a -e tracepoint option\n"); |
| 2219 | return -1; |
| 2220 | } |
| 2221 | |
| 2222 | snprintf(new_filter, sizeof(new_filter), "common_pid != %d", getpid()); |
| 2223 | |
Mathieu Poirier | 3541c03 | 2016-09-16 08:44:04 -0600 | [diff] [blame] | 2224 | if (perf_evsel__append_tp_filter(evsel, new_filter) < 0) { |
Wang Nan | 4ba1faa | 2015-07-10 07:36:10 +0000 | [diff] [blame] | 2225 | fprintf(stderr, |
| 2226 | "not enough memory to hold filter string\n"); |
| 2227 | return -1; |
| 2228 | } |
| 2229 | |
| 2230 | return 0; |
| 2231 | } |
| 2232 | |
| 2233 | int exclude_perf(const struct option *opt, |
| 2234 | const char *arg __maybe_unused, |
| 2235 | int unset __maybe_unused) |
| 2236 | { |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 2237 | struct evlist *evlist = *(struct evlist **)opt->value; |
Wang Nan | 4ba1faa | 2015-07-10 07:36:10 +0000 | [diff] [blame] | 2238 | |
| 2239 | return foreach_evsel_in_last_glob(evlist, add_exclude_perf_filter, |
| 2240 | NULL); |
| 2241 | } |
| 2242 | |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 2243 | static const char * const event_type_descriptors[] = { |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 2244 | "Hardware event", |
| 2245 | "Software event", |
| 2246 | "Tracepoint event", |
| 2247 | "Hardware cache event", |
Liming Wang | 41bdcb2 | 2009-12-29 16:37:07 +0800 | [diff] [blame] | 2248 | "Raw hardware event descriptor", |
| 2249 | "Hardware breakpoint", |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 2250 | }; |
| 2251 | |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 2252 | static int cmp_string(const void *a, const void *b) |
| 2253 | { |
| 2254 | const char * const *as = a; |
| 2255 | const char * const *bs = b; |
| 2256 | |
| 2257 | return strcmp(*as, *bs); |
| 2258 | } |
| 2259 | |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 2260 | /* |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 2261 | * Print the events from <debugfs_mount_point>/tracing/events |
| 2262 | */ |
| 2263 | |
Frederic Weisbecker | a3277d2 | 2012-08-09 16:31:52 +0200 | [diff] [blame] | 2264 | void print_tracepoint_events(const char *subsys_glob, const char *event_glob, |
| 2265 | bool name_only) |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 2266 | { |
| 2267 | DIR *sys_dir, *evt_dir; |
Arnaldo Carvalho de Melo | 22a9f41 | 2016-04-08 11:53:02 -0300 | [diff] [blame] | 2268 | struct dirent *sys_dirent, *evt_dirent; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 2269 | char evt_path[MAXPATHLEN]; |
Arnaldo Carvalho de Melo | 25a7d914 | 2018-05-17 14:27:29 -0300 | [diff] [blame] | 2270 | char *dir_path; |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 2271 | char **evt_list = NULL; |
| 2272 | unsigned int evt_i = 0, evt_num = 0; |
| 2273 | bool evt_num_known = false; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 2274 | |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 2275 | restart: |
Arnaldo Carvalho de Melo | 7014e0e | 2018-05-17 14:42:39 -0300 | [diff] [blame] | 2276 | sys_dir = tracing_events__opendir(); |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 2277 | if (!sys_dir) |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 2278 | return; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 2279 | |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 2280 | if (evt_num_known) { |
| 2281 | evt_list = zalloc(sizeof(char *) * evt_num); |
| 2282 | if (!evt_list) |
| 2283 | goto out_close_sys_dir; |
| 2284 | } |
| 2285 | |
Arnaldo Carvalho de Melo | 22a9f41 | 2016-04-08 11:53:02 -0300 | [diff] [blame] | 2286 | for_each_subsystem(sys_dir, sys_dirent) { |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 2287 | if (subsys_glob != NULL && |
Arnaldo Carvalho de Melo | 22a9f41 | 2016-04-08 11:53:02 -0300 | [diff] [blame] | 2288 | !strglobmatch(sys_dirent->d_name, subsys_glob)) |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 2289 | continue; |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 2290 | |
Arnaldo Carvalho de Melo | 25a7d914 | 2018-05-17 14:27:29 -0300 | [diff] [blame] | 2291 | dir_path = get_events_file(sys_dirent->d_name); |
| 2292 | if (!dir_path) |
| 2293 | continue; |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 2294 | evt_dir = opendir(dir_path); |
| 2295 | if (!evt_dir) |
Arnaldo Carvalho de Melo | 25a7d914 | 2018-05-17 14:27:29 -0300 | [diff] [blame] | 2296 | goto next; |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 2297 | |
Arnaldo Carvalho de Melo | c02cab2 | 2018-05-17 14:22:37 -0300 | [diff] [blame] | 2298 | for_each_event(dir_path, evt_dir, evt_dirent) { |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 2299 | if (event_glob != NULL && |
Arnaldo Carvalho de Melo | 22a9f41 | 2016-04-08 11:53:02 -0300 | [diff] [blame] | 2300 | !strglobmatch(evt_dirent->d_name, event_glob)) |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 2301 | continue; |
| 2302 | |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 2303 | if (!evt_num_known) { |
| 2304 | evt_num++; |
Frederic Weisbecker | a3277d2 | 2012-08-09 16:31:52 +0200 | [diff] [blame] | 2305 | continue; |
| 2306 | } |
| 2307 | |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 2308 | snprintf(evt_path, MAXPATHLEN, "%s:%s", |
Arnaldo Carvalho de Melo | 22a9f41 | 2016-04-08 11:53:02 -0300 | [diff] [blame] | 2309 | sys_dirent->d_name, evt_dirent->d_name); |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 2310 | |
| 2311 | evt_list[evt_i] = strdup(evt_path); |
Arnaldo Carvalho de Melo | 25a7d914 | 2018-05-17 14:27:29 -0300 | [diff] [blame] | 2312 | if (evt_list[evt_i] == NULL) { |
| 2313 | put_events_file(dir_path); |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 2314 | goto out_close_evt_dir; |
Arnaldo Carvalho de Melo | 25a7d914 | 2018-05-17 14:27:29 -0300 | [diff] [blame] | 2315 | } |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 2316 | evt_i++; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 2317 | } |
| 2318 | closedir(evt_dir); |
Arnaldo Carvalho de Melo | 25a7d914 | 2018-05-17 14:27:29 -0300 | [diff] [blame] | 2319 | next: |
| 2320 | put_events_file(dir_path); |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 2321 | } |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 2322 | closedir(sys_dir); |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 2323 | |
| 2324 | if (!evt_num_known) { |
| 2325 | evt_num_known = true; |
| 2326 | goto restart; |
| 2327 | } |
| 2328 | qsort(evt_list, evt_num, sizeof(char *), cmp_string); |
| 2329 | evt_i = 0; |
| 2330 | while (evt_i < evt_num) { |
| 2331 | if (name_only) { |
| 2332 | printf("%s ", evt_list[evt_i++]); |
| 2333 | continue; |
| 2334 | } |
| 2335 | printf(" %-50s [%s]\n", evt_list[evt_i++], |
| 2336 | event_type_descriptors[PERF_TYPE_TRACEPOINT]); |
| 2337 | } |
Arnaldo Carvalho de Melo | dfc431c | 2015-09-30 17:13:26 -0300 | [diff] [blame] | 2338 | if (evt_num && pager_in_use()) |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 2339 | printf("\n"); |
| 2340 | |
| 2341 | out_free: |
| 2342 | evt_num = evt_i; |
| 2343 | for (evt_i = 0; evt_i < evt_num; evt_i++) |
| 2344 | zfree(&evt_list[evt_i]); |
| 2345 | zfree(&evt_list); |
| 2346 | return; |
| 2347 | |
| 2348 | out_close_evt_dir: |
| 2349 | closedir(evt_dir); |
| 2350 | out_close_sys_dir: |
| 2351 | closedir(sys_dir); |
| 2352 | |
| 2353 | printf("FATAL: not enough memory to print %s\n", |
| 2354 | event_type_descriptors[PERF_TYPE_TRACEPOINT]); |
| 2355 | if (evt_list) |
| 2356 | goto out_free; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 2357 | } |
| 2358 | |
| 2359 | /* |
Thomas Renninger | 20c457b | 2011-01-03 17:50:45 +0100 | [diff] [blame] | 2360 | * Check whether event is in <debugfs_mount_point>/tracing/events |
| 2361 | */ |
| 2362 | |
| 2363 | int is_valid_tracepoint(const char *event_string) |
| 2364 | { |
| 2365 | DIR *sys_dir, *evt_dir; |
Arnaldo Carvalho de Melo | 22a9f41 | 2016-04-08 11:53:02 -0300 | [diff] [blame] | 2366 | struct dirent *sys_dirent, *evt_dirent; |
Thomas Renninger | 20c457b | 2011-01-03 17:50:45 +0100 | [diff] [blame] | 2367 | char evt_path[MAXPATHLEN]; |
Arnaldo Carvalho de Melo | 25a7d914 | 2018-05-17 14:27:29 -0300 | [diff] [blame] | 2368 | char *dir_path; |
Thomas Renninger | 20c457b | 2011-01-03 17:50:45 +0100 | [diff] [blame] | 2369 | |
Arnaldo Carvalho de Melo | 7014e0e | 2018-05-17 14:42:39 -0300 | [diff] [blame] | 2370 | sys_dir = tracing_events__opendir(); |
Thomas Renninger | 20c457b | 2011-01-03 17:50:45 +0100 | [diff] [blame] | 2371 | if (!sys_dir) |
| 2372 | return 0; |
| 2373 | |
Arnaldo Carvalho de Melo | 22a9f41 | 2016-04-08 11:53:02 -0300 | [diff] [blame] | 2374 | for_each_subsystem(sys_dir, sys_dirent) { |
Arnaldo Carvalho de Melo | 25a7d914 | 2018-05-17 14:27:29 -0300 | [diff] [blame] | 2375 | dir_path = get_events_file(sys_dirent->d_name); |
| 2376 | if (!dir_path) |
| 2377 | continue; |
Thomas Renninger | 20c457b | 2011-01-03 17:50:45 +0100 | [diff] [blame] | 2378 | evt_dir = opendir(dir_path); |
| 2379 | if (!evt_dir) |
Arnaldo Carvalho de Melo | 25a7d914 | 2018-05-17 14:27:29 -0300 | [diff] [blame] | 2380 | goto next; |
Thomas Renninger | 20c457b | 2011-01-03 17:50:45 +0100 | [diff] [blame] | 2381 | |
Arnaldo Carvalho de Melo | c02cab2 | 2018-05-17 14:22:37 -0300 | [diff] [blame] | 2382 | for_each_event(dir_path, evt_dir, evt_dirent) { |
Thomas Renninger | 20c457b | 2011-01-03 17:50:45 +0100 | [diff] [blame] | 2383 | snprintf(evt_path, MAXPATHLEN, "%s:%s", |
Arnaldo Carvalho de Melo | 22a9f41 | 2016-04-08 11:53:02 -0300 | [diff] [blame] | 2384 | sys_dirent->d_name, evt_dirent->d_name); |
Thomas Renninger | 20c457b | 2011-01-03 17:50:45 +0100 | [diff] [blame] | 2385 | if (!strcmp(evt_path, event_string)) { |
| 2386 | closedir(evt_dir); |
| 2387 | closedir(sys_dir); |
| 2388 | return 1; |
| 2389 | } |
| 2390 | } |
| 2391 | closedir(evt_dir); |
Arnaldo Carvalho de Melo | 25a7d914 | 2018-05-17 14:27:29 -0300 | [diff] [blame] | 2392 | next: |
| 2393 | put_events_file(dir_path); |
Thomas Renninger | 20c457b | 2011-01-03 17:50:45 +0100 | [diff] [blame] | 2394 | } |
| 2395 | closedir(sys_dir); |
| 2396 | return 0; |
| 2397 | } |
| 2398 | |
Namhyung Kim | b41f1ce | 2013-08-27 11:41:53 +0900 | [diff] [blame] | 2399 | static bool is_event_supported(u8 type, unsigned config) |
| 2400 | { |
| 2401 | bool ret = true; |
Vince Weaver | 88fee52 | 2013-12-30 15:39:45 -0500 | [diff] [blame] | 2402 | int open_return; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2403 | struct evsel *evsel; |
Namhyung Kim | b41f1ce | 2013-08-27 11:41:53 +0900 | [diff] [blame] | 2404 | struct perf_event_attr attr = { |
| 2405 | .type = type, |
| 2406 | .config = config, |
| 2407 | .disabled = 1, |
Namhyung Kim | b41f1ce | 2013-08-27 11:41:53 +0900 | [diff] [blame] | 2408 | }; |
Jiri Olsa | 9749b90 | 2019-07-21 13:23:50 +0200 | [diff] [blame] | 2409 | struct perf_thread_map *tmap = thread_map__new_by_tid(0); |
Arnaldo Carvalho de Melo | 8989605 | 2017-02-14 10:59:04 -0300 | [diff] [blame] | 2410 | |
| 2411 | if (tmap == NULL) |
| 2412 | return false; |
Namhyung Kim | b41f1ce | 2013-08-27 11:41:53 +0900 | [diff] [blame] | 2413 | |
Jiri Olsa | 365c3ae | 2019-07-21 13:23:58 +0200 | [diff] [blame] | 2414 | evsel = evsel__new(&attr); |
Namhyung Kim | b41f1ce | 2013-08-27 11:41:53 +0900 | [diff] [blame] | 2415 | if (evsel) { |
Jiri Olsa | 5972d1e | 2019-07-21 13:24:01 +0200 | [diff] [blame] | 2416 | open_return = evsel__open(evsel, NULL, tmap); |
Vince Weaver | 88fee52 | 2013-12-30 15:39:45 -0500 | [diff] [blame] | 2417 | ret = open_return >= 0; |
| 2418 | |
| 2419 | if (open_return == -EACCES) { |
| 2420 | /* |
| 2421 | * This happens if the paranoid value |
| 2422 | * /proc/sys/kernel/perf_event_paranoid is set to 2 |
| 2423 | * Re-run with exclude_kernel set; we don't do that |
| 2424 | * by default as some ARM machines do not support it. |
| 2425 | * |
| 2426 | */ |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 2427 | evsel->core.attr.exclude_kernel = 1; |
Jiri Olsa | 5972d1e | 2019-07-21 13:24:01 +0200 | [diff] [blame] | 2428 | ret = evsel__open(evsel, NULL, tmap) >= 0; |
Vince Weaver | 88fee52 | 2013-12-30 15:39:45 -0500 | [diff] [blame] | 2429 | } |
Jiri Olsa | 5eb2dd2 | 2019-07-21 13:23:57 +0200 | [diff] [blame] | 2430 | evsel__delete(evsel); |
Namhyung Kim | b41f1ce | 2013-08-27 11:41:53 +0900 | [diff] [blame] | 2431 | } |
| 2432 | |
Jiri Olsa | 7836e52 | 2019-07-21 13:24:20 +0200 | [diff] [blame] | 2433 | perf_thread_map__put(tmap); |
Namhyung Kim | b41f1ce | 2013-08-27 11:41:53 +0900 | [diff] [blame] | 2434 | return ret; |
| 2435 | } |
| 2436 | |
Masami Hiramatsu | 40218da | 2016-06-24 18:06:46 +0900 | [diff] [blame] | 2437 | void print_sdt_events(const char *subsys_glob, const char *event_glob, |
| 2438 | bool name_only) |
| 2439 | { |
| 2440 | struct probe_cache *pcache; |
| 2441 | struct probe_cache_entry *ent; |
| 2442 | struct strlist *bidlist, *sdtlist; |
| 2443 | struct strlist_config cfg = {.dont_dupstr = true}; |
| 2444 | struct str_node *nd, *nd2; |
| 2445 | char *buf, *path, *ptr = NULL; |
| 2446 | bool show_detail = false; |
| 2447 | int ret; |
| 2448 | |
| 2449 | sdtlist = strlist__new(NULL, &cfg); |
| 2450 | if (!sdtlist) { |
| 2451 | pr_debug("Failed to allocate new strlist for SDT\n"); |
| 2452 | return; |
| 2453 | } |
| 2454 | bidlist = build_id_cache__list_all(true); |
| 2455 | if (!bidlist) { |
| 2456 | pr_debug("Failed to get buildids: %d\n", errno); |
| 2457 | return; |
| 2458 | } |
| 2459 | strlist__for_each_entry(nd, bidlist) { |
Krister Johansen | f045b8c | 2017-07-05 18:48:11 -0700 | [diff] [blame] | 2460 | pcache = probe_cache__new(nd->s, NULL); |
Masami Hiramatsu | 40218da | 2016-06-24 18:06:46 +0900 | [diff] [blame] | 2461 | if (!pcache) |
| 2462 | continue; |
| 2463 | list_for_each_entry(ent, &pcache->entries, node) { |
| 2464 | if (!ent->sdt) |
| 2465 | continue; |
| 2466 | if (subsys_glob && |
| 2467 | !strglobmatch(ent->pev.group, subsys_glob)) |
| 2468 | continue; |
| 2469 | if (event_glob && |
| 2470 | !strglobmatch(ent->pev.event, event_glob)) |
| 2471 | continue; |
| 2472 | ret = asprintf(&buf, "%s:%s@%s", ent->pev.group, |
| 2473 | ent->pev.event, nd->s); |
| 2474 | if (ret > 0) |
| 2475 | strlist__add(sdtlist, buf); |
| 2476 | } |
| 2477 | probe_cache__delete(pcache); |
| 2478 | } |
| 2479 | strlist__delete(bidlist); |
| 2480 | |
| 2481 | strlist__for_each_entry(nd, sdtlist) { |
| 2482 | buf = strchr(nd->s, '@'); |
| 2483 | if (buf) |
| 2484 | *(buf++) = '\0'; |
| 2485 | if (name_only) { |
| 2486 | printf("%s ", nd->s); |
| 2487 | continue; |
| 2488 | } |
| 2489 | nd2 = strlist__next(nd); |
| 2490 | if (nd2) { |
| 2491 | ptr = strchr(nd2->s, '@'); |
| 2492 | if (ptr) |
| 2493 | *ptr = '\0'; |
| 2494 | if (strcmp(nd->s, nd2->s) == 0) |
| 2495 | show_detail = true; |
| 2496 | } |
| 2497 | if (show_detail) { |
| 2498 | path = build_id_cache__origname(buf); |
| 2499 | ret = asprintf(&buf, "%s@%s(%.12s)", nd->s, path, buf); |
| 2500 | if (ret > 0) { |
| 2501 | printf(" %-50s [%s]\n", buf, "SDT event"); |
| 2502 | free(buf); |
| 2503 | } |
Changbin Du | 8bde851 | 2019-03-16 16:05:46 +0800 | [diff] [blame] | 2504 | free(path); |
Masami Hiramatsu | 40218da | 2016-06-24 18:06:46 +0900 | [diff] [blame] | 2505 | } else |
| 2506 | printf(" %-50s [%s]\n", nd->s, "SDT event"); |
| 2507 | if (nd2) { |
| 2508 | if (strcmp(nd->s, nd2->s) != 0) |
| 2509 | show_detail = false; |
| 2510 | if (ptr) |
| 2511 | *ptr = '@'; |
| 2512 | } |
| 2513 | } |
| 2514 | strlist__delete(sdtlist); |
| 2515 | } |
| 2516 | |
Frederic Weisbecker | a3277d2 | 2012-08-09 16:31:52 +0200 | [diff] [blame] | 2517 | 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] | 2518 | { |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 2519 | 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] | 2520 | char name[64]; |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 2521 | char **evt_list = NULL; |
| 2522 | bool evt_num_known = false; |
| 2523 | |
| 2524 | restart: |
| 2525 | if (evt_num_known) { |
| 2526 | evt_list = zalloc(sizeof(char *) * evt_num); |
| 2527 | if (!evt_list) |
| 2528 | goto out_enomem; |
| 2529 | } |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 2530 | |
| 2531 | for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) { |
| 2532 | for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) { |
| 2533 | /* skip invalid cache type */ |
Arnaldo Carvalho de Melo | 0b668bc | 2012-06-11 14:08:07 -0300 | [diff] [blame] | 2534 | if (!perf_evsel__is_cache_op_valid(type, op)) |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 2535 | continue; |
| 2536 | |
| 2537 | 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] | 2538 | __perf_evsel__hw_cache_type_op_res_name(type, op, i, |
| 2539 | name, sizeof(name)); |
Ingo Molnar | 947b4ad | 2011-04-29 22:52:42 +0200 | [diff] [blame] | 2540 | if (event_glob != NULL && !strglobmatch(name, event_glob)) |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 2541 | continue; |
| 2542 | |
Namhyung Kim | b41f1ce | 2013-08-27 11:41:53 +0900 | [diff] [blame] | 2543 | if (!is_event_supported(PERF_TYPE_HW_CACHE, |
| 2544 | type | (op << 8) | (i << 16))) |
| 2545 | continue; |
| 2546 | |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 2547 | if (!evt_num_known) { |
| 2548 | evt_num++; |
| 2549 | continue; |
| 2550 | } |
| 2551 | |
| 2552 | evt_list[evt_i] = strdup(name); |
| 2553 | if (evt_list[evt_i] == NULL) |
| 2554 | goto out_enomem; |
| 2555 | evt_i++; |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 2556 | } |
| 2557 | } |
| 2558 | } |
| 2559 | |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 2560 | if (!evt_num_known) { |
| 2561 | evt_num_known = true; |
| 2562 | goto restart; |
| 2563 | } |
| 2564 | qsort(evt_list, evt_num, sizeof(char *), cmp_string); |
| 2565 | evt_i = 0; |
| 2566 | while (evt_i < evt_num) { |
| 2567 | if (name_only) { |
| 2568 | printf("%s ", evt_list[evt_i++]); |
| 2569 | continue; |
| 2570 | } |
| 2571 | printf(" %-50s [%s]\n", evt_list[evt_i++], |
| 2572 | event_type_descriptors[PERF_TYPE_HW_CACHE]); |
| 2573 | } |
Arnaldo Carvalho de Melo | dfc431c | 2015-09-30 17:13:26 -0300 | [diff] [blame] | 2574 | if (evt_num && pager_in_use()) |
Andi Kleen | dc098b3 | 2013-04-20 11:02:29 -0700 | [diff] [blame] | 2575 | printf("\n"); |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 2576 | |
| 2577 | out_free: |
| 2578 | evt_num = evt_i; |
| 2579 | for (evt_i = 0; evt_i < evt_num; evt_i++) |
| 2580 | zfree(&evt_list[evt_i]); |
| 2581 | zfree(&evt_list); |
| 2582 | return evt_num; |
| 2583 | |
| 2584 | out_enomem: |
| 2585 | printf("FATAL: not enough memory to print %s\n", event_type_descriptors[PERF_TYPE_HW_CACHE]); |
| 2586 | if (evt_list) |
| 2587 | goto out_free; |
| 2588 | return evt_num; |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 2589 | } |
| 2590 | |
Andi Kleen | 5e0861b | 2019-03-26 15:18:23 -0700 | [diff] [blame] | 2591 | static void print_tool_event(const char *name, const char *event_glob, |
| 2592 | bool name_only) |
| 2593 | { |
| 2594 | if (event_glob && !strglobmatch(name, event_glob)) |
| 2595 | return; |
| 2596 | if (name_only) |
| 2597 | printf("%s ", name); |
| 2598 | else |
| 2599 | printf(" %-50s [%s]\n", name, "Tool event"); |
| 2600 | |
| 2601 | } |
| 2602 | |
| 2603 | void print_tool_events(const char *event_glob, bool name_only) |
| 2604 | { |
| 2605 | print_tool_event("duration_time", event_glob, name_only); |
| 2606 | if (pager_in_use()) |
| 2607 | printf("\n"); |
| 2608 | } |
| 2609 | |
Yunlong Song | 705750f | 2015-02-27 18:21:27 +0800 | [diff] [blame] | 2610 | void print_symbol_events(const char *event_glob, unsigned type, |
Frederic Weisbecker | a3277d2 | 2012-08-09 16:31:52 +0200 | [diff] [blame] | 2611 | struct event_symbol *syms, unsigned max, |
| 2612 | bool name_only) |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 2613 | { |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 2614 | unsigned int i, evt_i = 0, evt_num = 0; |
Ingo Molnar | 947b4ad | 2011-04-29 22:52:42 +0200 | [diff] [blame] | 2615 | char name[MAX_NAME_LEN]; |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 2616 | char **evt_list = NULL; |
| 2617 | bool evt_num_known = false; |
| 2618 | |
| 2619 | restart: |
| 2620 | if (evt_num_known) { |
| 2621 | evt_list = zalloc(sizeof(char *) * evt_num); |
| 2622 | if (!evt_list) |
| 2623 | goto out_enomem; |
| 2624 | syms -= max; |
| 2625 | } |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 2626 | |
Jiri Olsa | 1dc12760 | 2012-07-04 00:00:44 +0200 | [diff] [blame] | 2627 | for (i = 0; i < max; i++, syms++) { |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 2628 | |
Arnaldo Carvalho de Melo | e37df6c | 2015-11-27 16:04:58 -0300 | [diff] [blame] | 2629 | if (event_glob != NULL && syms->symbol != NULL && |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 2630 | !(strglobmatch(syms->symbol, event_glob) || |
| 2631 | (syms->alias && strglobmatch(syms->alias, event_glob)))) |
| 2632 | continue; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 2633 | |
Namhyung Kim | b41f1ce | 2013-08-27 11:41:53 +0900 | [diff] [blame] | 2634 | if (!is_event_supported(type, i)) |
| 2635 | continue; |
| 2636 | |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 2637 | if (!evt_num_known) { |
| 2638 | evt_num++; |
Frederic Weisbecker | a3277d2 | 2012-08-09 16:31:52 +0200 | [diff] [blame] | 2639 | continue; |
| 2640 | } |
| 2641 | |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 2642 | if (!name_only && strlen(syms->alias)) |
Ingo Molnar | 947b4ad | 2011-04-29 22:52:42 +0200 | [diff] [blame] | 2643 | 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] | 2644 | else |
Arnaldo Carvalho de Melo | bd8d57f | 2018-12-06 13:52:13 -0300 | [diff] [blame] | 2645 | strlcpy(name, syms->symbol, MAX_NAME_LEN); |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 2646 | |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 2647 | evt_list[evt_i] = strdup(name); |
| 2648 | if (evt_list[evt_i] == NULL) |
| 2649 | goto out_enomem; |
| 2650 | evt_i++; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 2651 | } |
| 2652 | |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 2653 | if (!evt_num_known) { |
| 2654 | evt_num_known = true; |
| 2655 | goto restart; |
| 2656 | } |
| 2657 | qsort(evt_list, evt_num, sizeof(char *), cmp_string); |
| 2658 | evt_i = 0; |
| 2659 | while (evt_i < evt_num) { |
| 2660 | if (name_only) { |
| 2661 | printf("%s ", evt_list[evt_i++]); |
| 2662 | continue; |
| 2663 | } |
| 2664 | printf(" %-50s [%s]\n", evt_list[evt_i++], event_type_descriptors[type]); |
| 2665 | } |
Arnaldo Carvalho de Melo | dfc431c | 2015-09-30 17:13:26 -0300 | [diff] [blame] | 2666 | if (evt_num && pager_in_use()) |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 2667 | printf("\n"); |
Yunlong Song | ab0e480 | 2015-02-27 18:21:25 +0800 | [diff] [blame] | 2668 | |
| 2669 | out_free: |
| 2670 | evt_num = evt_i; |
| 2671 | for (evt_i = 0; evt_i < evt_num; evt_i++) |
| 2672 | zfree(&evt_list[evt_i]); |
| 2673 | zfree(&evt_list); |
| 2674 | return; |
| 2675 | |
| 2676 | out_enomem: |
| 2677 | printf("FATAL: not enough memory to print %s\n", event_type_descriptors[type]); |
| 2678 | if (evt_list) |
| 2679 | goto out_free; |
Jiri Olsa | 1dc12760 | 2012-07-04 00:00:44 +0200 | [diff] [blame] | 2680 | } |
| 2681 | |
| 2682 | /* |
| 2683 | * Print the help text for the event symbols: |
| 2684 | */ |
Sukadev Bhattiprolu | c8d6828 | 2016-09-15 15:24:48 -0700 | [diff] [blame] | 2685 | void print_events(const char *event_glob, bool name_only, bool quiet_flag, |
Jin Yao | a7f6c8c | 2019-10-15 10:53:57 +0800 | [diff] [blame] | 2686 | bool long_desc, bool details_flag, bool deprecated) |
Jiri Olsa | 1dc12760 | 2012-07-04 00:00:44 +0200 | [diff] [blame] | 2687 | { |
Jiri Olsa | 1dc12760 | 2012-07-04 00:00:44 +0200 | [diff] [blame] | 2688 | print_symbol_events(event_glob, PERF_TYPE_HARDWARE, |
Frederic Weisbecker | a3277d2 | 2012-08-09 16:31:52 +0200 | [diff] [blame] | 2689 | event_symbols_hw, PERF_COUNT_HW_MAX, name_only); |
Jiri Olsa | 1dc12760 | 2012-07-04 00:00:44 +0200 | [diff] [blame] | 2690 | |
| 2691 | print_symbol_events(event_glob, PERF_TYPE_SOFTWARE, |
Frederic Weisbecker | a3277d2 | 2012-08-09 16:31:52 +0200 | [diff] [blame] | 2692 | event_symbols_sw, PERF_COUNT_SW_MAX, name_only); |
Andi Kleen | 5e0861b | 2019-03-26 15:18:23 -0700 | [diff] [blame] | 2693 | print_tool_events(event_glob, name_only); |
Jiri Olsa | 1dc12760 | 2012-07-04 00:00:44 +0200 | [diff] [blame] | 2694 | |
Frederic Weisbecker | a3277d2 | 2012-08-09 16:31:52 +0200 | [diff] [blame] | 2695 | print_hwcache_events(event_glob, name_only); |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 2696 | |
Andi Kleen | bf874fc | 2017-03-20 13:17:11 -0700 | [diff] [blame] | 2697 | print_pmu_events(event_glob, name_only, quiet_flag, long_desc, |
Jin Yao | a7f6c8c | 2019-10-15 10:53:57 +0800 | [diff] [blame] | 2698 | details_flag, deprecated); |
Andi Kleen | dc098b3 | 2013-04-20 11:02:29 -0700 | [diff] [blame] | 2699 | |
Arnaldo Carvalho de Melo | 668b878 | 2011-02-17 15:38:58 -0200 | [diff] [blame] | 2700 | if (event_glob != NULL) |
| 2701 | return; |
Jaswinder Singh Rajput | 73c24cb | 2009-07-01 18:36:18 +0530 | [diff] [blame] | 2702 | |
Frederic Weisbecker | a3277d2 | 2012-08-09 16:31:52 +0200 | [diff] [blame] | 2703 | if (!name_only) { |
Frederic Weisbecker | a3277d2 | 2012-08-09 16:31:52 +0200 | [diff] [blame] | 2704 | printf(" %-50s [%s]\n", |
| 2705 | "rNNN", |
| 2706 | event_type_descriptors[PERF_TYPE_RAW]); |
| 2707 | printf(" %-50s [%s]\n", |
| 2708 | "cpu/t1=v1[,t2=v2,t3 ...]/modifier", |
| 2709 | event_type_descriptors[PERF_TYPE_RAW]); |
Arnaldo Carvalho de Melo | dfc431c | 2015-09-30 17:13:26 -0300 | [diff] [blame] | 2710 | if (pager_in_use()) |
| 2711 | printf(" (see 'man perf-list' on how to encode it)\n\n"); |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 2712 | |
Frederic Weisbecker | a3277d2 | 2012-08-09 16:31:52 +0200 | [diff] [blame] | 2713 | printf(" %-50s [%s]\n", |
Jacob Shin | 3741eb9 | 2014-05-29 17:26:51 +0200 | [diff] [blame] | 2714 | "mem:<addr>[/len][:access]", |
Liming Wang | 41bdcb2 | 2009-12-29 16:37:07 +0800 | [diff] [blame] | 2715 | event_type_descriptors[PERF_TYPE_BREAKPOINT]); |
Arnaldo Carvalho de Melo | dfc431c | 2015-09-30 17:13:26 -0300 | [diff] [blame] | 2716 | if (pager_in_use()) |
| 2717 | printf("\n"); |
Frederic Weisbecker | a3277d2 | 2012-08-09 16:31:52 +0200 | [diff] [blame] | 2718 | } |
Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 2719 | |
Frederic Weisbecker | a3277d2 | 2012-08-09 16:31:52 +0200 | [diff] [blame] | 2720 | print_tracepoint_events(NULL, NULL, name_only); |
Masami Hiramatsu | 40218da | 2016-06-24 18:06:46 +0900 | [diff] [blame] | 2721 | |
| 2722 | print_sdt_events(NULL, NULL, name_only); |
Andi Kleen | 71b0acc | 2017-08-31 12:40:32 -0700 | [diff] [blame] | 2723 | |
Jiri Olsa | 33bbc57 | 2019-02-13 13:32:41 +0100 | [diff] [blame] | 2724 | metricgroup__print(true, true, NULL, name_only, details_flag); |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 2725 | } |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 2726 | |
Arnaldo Carvalho de Melo | 6cee6cd | 2013-01-18 16:29:49 -0300 | [diff] [blame] | 2727 | int parse_events__is_hardcoded_term(struct parse_events_term *term) |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 2728 | { |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 2729 | return term->type_term != PARSE_EVENTS__TERM_TYPE_USER; |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 2730 | } |
| 2731 | |
Jiri Olsa | 67b49b3 | 2017-02-17 15:00:55 +0100 | [diff] [blame] | 2732 | static int new_term(struct parse_events_term **_term, |
| 2733 | struct parse_events_term *temp, |
| 2734 | char *str, u64 num) |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 2735 | { |
Arnaldo Carvalho de Melo | 6cee6cd | 2013-01-18 16:29:49 -0300 | [diff] [blame] | 2736 | struct parse_events_term *term; |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 2737 | |
Jiri Olsa | 67b49b3 | 2017-02-17 15:00:55 +0100 | [diff] [blame] | 2738 | term = malloc(sizeof(*term)); |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 2739 | if (!term) |
| 2740 | return -ENOMEM; |
| 2741 | |
Jiri Olsa | 67b49b3 | 2017-02-17 15:00:55 +0100 | [diff] [blame] | 2742 | *term = *temp; |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 2743 | INIT_LIST_HEAD(&term->list); |
Andi Kleen | c2f1cea | 2017-10-20 13:27:55 -0700 | [diff] [blame] | 2744 | term->weak = false; |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 2745 | |
Jiri Olsa | 67b49b3 | 2017-02-17 15:00:55 +0100 | [diff] [blame] | 2746 | switch (term->type_val) { |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 2747 | case PARSE_EVENTS__TERM_TYPE_NUM: |
| 2748 | term->val.num = num; |
| 2749 | break; |
| 2750 | case PARSE_EVENTS__TERM_TYPE_STR: |
| 2751 | term->val.str = str; |
| 2752 | break; |
| 2753 | default: |
Adrian Hunter | 4be8be6 | 2013-07-04 16:20:24 +0300 | [diff] [blame] | 2754 | free(term); |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 2755 | return -EINVAL; |
| 2756 | } |
| 2757 | |
| 2758 | *_term = term; |
| 2759 | return 0; |
| 2760 | } |
| 2761 | |
Arnaldo Carvalho de Melo | 6cee6cd | 2013-01-18 16:29:49 -0300 | [diff] [blame] | 2762 | int parse_events_term__num(struct parse_events_term **term, |
Jiri Olsa | cecf3a2e | 2015-04-22 21:10:20 +0200 | [diff] [blame] | 2763 | int type_term, char *config, u64 num, |
Jiri Olsa | 99e7138 | 2017-02-17 15:00:56 +0100 | [diff] [blame] | 2764 | bool no_value, |
Adrian Hunter | bb78ce7 | 2015-05-19 16:05:42 +0300 | [diff] [blame] | 2765 | void *loc_term_, void *loc_val_) |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 2766 | { |
Adrian Hunter | bb78ce7 | 2015-05-19 16:05:42 +0300 | [diff] [blame] | 2767 | YYLTYPE *loc_term = loc_term_; |
| 2768 | YYLTYPE *loc_val = loc_val_; |
| 2769 | |
Jiri Olsa | 67b49b3 | 2017-02-17 15:00:55 +0100 | [diff] [blame] | 2770 | struct parse_events_term temp = { |
| 2771 | .type_val = PARSE_EVENTS__TERM_TYPE_NUM, |
| 2772 | .type_term = type_term, |
| 2773 | .config = config, |
Jiri Olsa | 99e7138 | 2017-02-17 15:00:56 +0100 | [diff] [blame] | 2774 | .no_value = no_value, |
Jiri Olsa | 67b49b3 | 2017-02-17 15:00:55 +0100 | [diff] [blame] | 2775 | .err_term = loc_term ? loc_term->first_column : 0, |
| 2776 | .err_val = loc_val ? loc_val->first_column : 0, |
| 2777 | }; |
| 2778 | |
| 2779 | return new_term(term, &temp, NULL, num); |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 2780 | } |
| 2781 | |
Arnaldo Carvalho de Melo | 6cee6cd | 2013-01-18 16:29:49 -0300 | [diff] [blame] | 2782 | int parse_events_term__str(struct parse_events_term **term, |
Jiri Olsa | cecf3a2e | 2015-04-22 21:10:20 +0200 | [diff] [blame] | 2783 | int type_term, char *config, char *str, |
Adrian Hunter | bb78ce7 | 2015-05-19 16:05:42 +0300 | [diff] [blame] | 2784 | void *loc_term_, void *loc_val_) |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 2785 | { |
Adrian Hunter | bb78ce7 | 2015-05-19 16:05:42 +0300 | [diff] [blame] | 2786 | YYLTYPE *loc_term = loc_term_; |
| 2787 | YYLTYPE *loc_val = loc_val_; |
| 2788 | |
Jiri Olsa | 67b49b3 | 2017-02-17 15:00:55 +0100 | [diff] [blame] | 2789 | struct parse_events_term temp = { |
| 2790 | .type_val = PARSE_EVENTS__TERM_TYPE_STR, |
| 2791 | .type_term = type_term, |
| 2792 | .config = config, |
| 2793 | .err_term = loc_term ? loc_term->first_column : 0, |
| 2794 | .err_val = loc_val ? loc_val->first_column : 0, |
| 2795 | }; |
| 2796 | |
| 2797 | return new_term(term, &temp, str, 0); |
Jiri Olsa | 16fa7e8 | 2012-04-25 18:24:57 +0200 | [diff] [blame] | 2798 | } |
| 2799 | |
Arnaldo Carvalho de Melo | 6cee6cd | 2013-01-18 16:29:49 -0300 | [diff] [blame] | 2800 | int parse_events_term__sym_hw(struct parse_events_term **term, |
Jiri Olsa | 1d33d6d | 2012-10-10 14:53:17 +0200 | [diff] [blame] | 2801 | char *config, unsigned idx) |
| 2802 | { |
| 2803 | struct event_symbol *sym; |
Ian Rogers | b6645a7 | 2019-10-30 15:34:43 -0700 | [diff] [blame] | 2804 | char *str; |
Jiri Olsa | 67b49b3 | 2017-02-17 15:00:55 +0100 | [diff] [blame] | 2805 | struct parse_events_term temp = { |
| 2806 | .type_val = PARSE_EVENTS__TERM_TYPE_STR, |
| 2807 | .type_term = PARSE_EVENTS__TERM_TYPE_USER, |
Ian Rogers | b6645a7 | 2019-10-30 15:34:43 -0700 | [diff] [blame] | 2808 | .config = config, |
Jiri Olsa | 67b49b3 | 2017-02-17 15:00:55 +0100 | [diff] [blame] | 2809 | }; |
Jiri Olsa | 1d33d6d | 2012-10-10 14:53:17 +0200 | [diff] [blame] | 2810 | |
Ian Rogers | b6645a7 | 2019-10-30 15:34:43 -0700 | [diff] [blame] | 2811 | if (!temp.config) { |
| 2812 | temp.config = strdup("event"); |
| 2813 | if (!temp.config) |
| 2814 | return -ENOMEM; |
| 2815 | } |
Jiri Olsa | 1d33d6d | 2012-10-10 14:53:17 +0200 | [diff] [blame] | 2816 | BUG_ON(idx >= PERF_COUNT_HW_MAX); |
| 2817 | sym = &event_symbols_hw[idx]; |
| 2818 | |
Ian Rogers | b6645a7 | 2019-10-30 15:34:43 -0700 | [diff] [blame] | 2819 | str = strdup(sym->symbol); |
| 2820 | if (!str) |
| 2821 | return -ENOMEM; |
| 2822 | return new_term(term, &temp, str, 0); |
Jiri Olsa | 1d33d6d | 2012-10-10 14:53:17 +0200 | [diff] [blame] | 2823 | } |
| 2824 | |
Arnaldo Carvalho de Melo | 6cee6cd | 2013-01-18 16:29:49 -0300 | [diff] [blame] | 2825 | int parse_events_term__clone(struct parse_events_term **new, |
| 2826 | struct parse_events_term *term) |
Zheng Yan | a6146d5 | 2012-06-15 14:31:41 +0800 | [diff] [blame] | 2827 | { |
Ian Rogers | b6645a7 | 2019-10-30 15:34:43 -0700 | [diff] [blame] | 2828 | char *str; |
Jiri Olsa | 67b49b3 | 2017-02-17 15:00:55 +0100 | [diff] [blame] | 2829 | struct parse_events_term temp = { |
| 2830 | .type_val = term->type_val, |
| 2831 | .type_term = term->type_term, |
Ian Rogers | b6645a7 | 2019-10-30 15:34:43 -0700 | [diff] [blame] | 2832 | .config = NULL, |
Jiri Olsa | 67b49b3 | 2017-02-17 15:00:55 +0100 | [diff] [blame] | 2833 | .err_term = term->err_term, |
| 2834 | .err_val = term->err_val, |
| 2835 | }; |
| 2836 | |
Ian Rogers | b6645a7 | 2019-10-30 15:34:43 -0700 | [diff] [blame] | 2837 | if (term->config) { |
| 2838 | temp.config = strdup(term->config); |
| 2839 | if (!temp.config) |
| 2840 | return -ENOMEM; |
| 2841 | } |
| 2842 | if (term->type_val == PARSE_EVENTS__TERM_TYPE_NUM) |
| 2843 | return new_term(new, &temp, NULL, term->val.num); |
| 2844 | |
| 2845 | str = strdup(term->val.str); |
| 2846 | if (!str) |
| 2847 | return -ENOMEM; |
| 2848 | return new_term(new, &temp, str, 0); |
Zheng Yan | a6146d5 | 2012-06-15 14:31:41 +0800 | [diff] [blame] | 2849 | } |
| 2850 | |
Ian Rogers | 1dc9255 | 2019-10-30 15:34:47 -0700 | [diff] [blame] | 2851 | void parse_events_term__delete(struct parse_events_term *term) |
| 2852 | { |
| 2853 | if (term->array.nr_ranges) |
| 2854 | zfree(&term->array.ranges); |
| 2855 | |
| 2856 | if (term->type_val != PARSE_EVENTS__TERM_TYPE_NUM) |
| 2857 | zfree(&term->val.str); |
| 2858 | |
| 2859 | zfree(&term->config); |
| 2860 | free(term); |
| 2861 | } |
| 2862 | |
Andi Kleen | 8255718 | 2017-03-20 13:17:03 -0700 | [diff] [blame] | 2863 | int parse_events_copy_term_list(struct list_head *old, |
| 2864 | struct list_head **new) |
| 2865 | { |
| 2866 | struct parse_events_term *term, *n; |
| 2867 | int ret; |
| 2868 | |
| 2869 | if (!old) { |
| 2870 | *new = NULL; |
| 2871 | return 0; |
| 2872 | } |
| 2873 | |
| 2874 | *new = malloc(sizeof(struct list_head)); |
| 2875 | if (!*new) |
| 2876 | return -ENOMEM; |
| 2877 | INIT_LIST_HEAD(*new); |
| 2878 | |
| 2879 | list_for_each_entry (term, old, list) { |
| 2880 | ret = parse_events_term__clone(&n, term); |
| 2881 | if (ret) |
| 2882 | return ret; |
| 2883 | list_add_tail(&n->list, *new); |
| 2884 | } |
| 2885 | return 0; |
| 2886 | } |
| 2887 | |
Arnaldo Carvalho de Melo | fc0a2c1 | 2016-02-12 16:43:02 -0300 | [diff] [blame] | 2888 | void parse_events_terms__purge(struct list_head *terms) |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 2889 | { |
Arnaldo Carvalho de Melo | 6cee6cd | 2013-01-18 16:29:49 -0300 | [diff] [blame] | 2890 | struct parse_events_term *term, *h; |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 2891 | |
Wang Nan | a8adfce | 2016-02-12 16:31:23 -0300 | [diff] [blame] | 2892 | list_for_each_entry_safe(term, h, terms, list) { |
| 2893 | list_del_init(&term->list); |
Ian Rogers | 1dc9255 | 2019-10-30 15:34:47 -0700 | [diff] [blame] | 2894 | parse_events_term__delete(term); |
Wang Nan | a8adfce | 2016-02-12 16:31:23 -0300 | [diff] [blame] | 2895 | } |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame] | 2896 | } |
Jiri Olsa | b39b839 | 2015-04-22 21:10:16 +0200 | [diff] [blame] | 2897 | |
Arnaldo Carvalho de Melo | 2146afc | 2016-02-12 17:09:17 -0300 | [diff] [blame] | 2898 | void parse_events_terms__delete(struct list_head *terms) |
Arnaldo Carvalho de Melo | fc0a2c1 | 2016-02-12 16:43:02 -0300 | [diff] [blame] | 2899 | { |
Arnaldo Carvalho de Melo | 2146afc | 2016-02-12 17:09:17 -0300 | [diff] [blame] | 2900 | if (!terms) |
| 2901 | return; |
Arnaldo Carvalho de Melo | fc0a2c1 | 2016-02-12 16:43:02 -0300 | [diff] [blame] | 2902 | parse_events_terms__purge(terms); |
Wang Nan | d20a5f2 | 2016-02-12 17:01:17 -0300 | [diff] [blame] | 2903 | free(terms); |
Arnaldo Carvalho de Melo | fc0a2c1 | 2016-02-12 16:43:02 -0300 | [diff] [blame] | 2904 | } |
| 2905 | |
Wang Nan | 2d055bf | 2016-02-22 09:10:34 +0000 | [diff] [blame] | 2906 | void parse_events__clear_array(struct parse_events_array *a) |
| 2907 | { |
Taeung Song | 360e071 | 2017-02-01 21:34:07 +0900 | [diff] [blame] | 2908 | zfree(&a->ranges); |
Wang Nan | 2d055bf | 2016-02-22 09:10:34 +0000 | [diff] [blame] | 2909 | } |
| 2910 | |
Arnaldo Carvalho de Melo | 5d9cdc1 | 2017-08-17 16:13:34 -0300 | [diff] [blame] | 2911 | void parse_events_evlist_error(struct parse_events_state *parse_state, |
Jiri Olsa | b39b839 | 2015-04-22 21:10:16 +0200 | [diff] [blame] | 2912 | int idx, const char *str) |
| 2913 | { |
Ian Rogers | 448d732 | 2019-10-30 15:34:39 -0700 | [diff] [blame] | 2914 | if (!parse_state->error) |
Adrian Hunter | a6ced2b | 2015-05-19 16:05:44 +0300 | [diff] [blame] | 2915 | return; |
Ian Rogers | 448d732 | 2019-10-30 15:34:39 -0700 | [diff] [blame] | 2916 | |
| 2917 | parse_events__handle_error(parse_state->error, idx, strdup(str), NULL); |
Jiri Olsa | b39b839 | 2015-04-22 21:10:16 +0200 | [diff] [blame] | 2918 | } |
He Kuang | ffeb883 | 2015-09-28 03:52:14 +0000 | [diff] [blame] | 2919 | |
Wang Nan | 17cb5f8 | 2016-02-19 11:43:57 +0000 | [diff] [blame] | 2920 | static void config_terms_list(char *buf, size_t buf_sz) |
| 2921 | { |
| 2922 | int i; |
| 2923 | bool first = true; |
| 2924 | |
| 2925 | buf[0] = '\0'; |
| 2926 | for (i = 0; i < __PARSE_EVENTS__TERM_TYPE_NR; i++) { |
| 2927 | const char *name = config_term_names[i]; |
| 2928 | |
Wang Nan | 1669e50 | 2016-02-19 11:43:58 +0000 | [diff] [blame] | 2929 | if (!config_term_avail(i, NULL)) |
| 2930 | continue; |
Wang Nan | 17cb5f8 | 2016-02-19 11:43:57 +0000 | [diff] [blame] | 2931 | if (!name) |
| 2932 | continue; |
| 2933 | if (name[0] == '<') |
| 2934 | continue; |
| 2935 | |
| 2936 | if (strlen(buf) + strlen(name) + 2 >= buf_sz) |
| 2937 | return; |
| 2938 | |
| 2939 | if (!first) |
| 2940 | strcat(buf, ","); |
| 2941 | else |
| 2942 | first = false; |
| 2943 | strcat(buf, name); |
| 2944 | } |
| 2945 | } |
| 2946 | |
He Kuang | ffeb883 | 2015-09-28 03:52:14 +0000 | [diff] [blame] | 2947 | /* |
| 2948 | * Return string contains valid config terms of an event. |
| 2949 | * @additional_terms: For terms such as PMU sysfs terms. |
| 2950 | */ |
| 2951 | char *parse_events_formats_error_string(char *additional_terms) |
| 2952 | { |
| 2953 | char *str; |
Wang Nan | 626a6b7 | 2016-07-14 08:34:45 +0000 | [diff] [blame] | 2954 | /* "no-overwrite" is the longest name */ |
Wang Nan | 17cb5f8 | 2016-02-19 11:43:57 +0000 | [diff] [blame] | 2955 | char static_terms[__PARSE_EVENTS__TERM_TYPE_NR * |
Wang Nan | 626a6b7 | 2016-07-14 08:34:45 +0000 | [diff] [blame] | 2956 | (sizeof("no-overwrite") - 1)]; |
He Kuang | ffeb883 | 2015-09-28 03:52:14 +0000 | [diff] [blame] | 2957 | |
Wang Nan | 17cb5f8 | 2016-02-19 11:43:57 +0000 | [diff] [blame] | 2958 | config_terms_list(static_terms, sizeof(static_terms)); |
He Kuang | ffeb883 | 2015-09-28 03:52:14 +0000 | [diff] [blame] | 2959 | /* valid terms */ |
| 2960 | if (additional_terms) { |
Wang Nan | 26dee02 | 2016-02-19 11:43:52 +0000 | [diff] [blame] | 2961 | if (asprintf(&str, "valid terms: %s,%s", |
| 2962 | additional_terms, static_terms) < 0) |
He Kuang | ffeb883 | 2015-09-28 03:52:14 +0000 | [diff] [blame] | 2963 | goto fail; |
| 2964 | } else { |
Wang Nan | 26dee02 | 2016-02-19 11:43:52 +0000 | [diff] [blame] | 2965 | if (asprintf(&str, "valid terms: %s", static_terms) < 0) |
He Kuang | ffeb883 | 2015-09-28 03:52:14 +0000 | [diff] [blame] | 2966 | goto fail; |
| 2967 | } |
| 2968 | return str; |
| 2969 | |
| 2970 | fail: |
| 2971 | return NULL; |
| 2972 | } |