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