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