Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 1 | |
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" |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 4 | #include "parse-options.h" |
| 5 | #include "parse-events.h" |
| 6 | #include "exec_cmd.h" |
Arnaldo Carvalho de Melo | a0055ae | 2009-06-01 17:50:19 -0300 | [diff] [blame] | 7 | #include "string.h" |
Jason Baron | 5beeded | 2009-07-21 14:16:29 -0400 | [diff] [blame] | 8 | #include "cache.h" |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 9 | #include "header.h" |
Clark Williams | 549104f | 2009-11-08 09:03:07 -0600 | [diff] [blame^] | 10 | #include "debugfs.h" |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 11 | |
Li Zefan | c171b55 | 2009-10-15 11:22:07 +0800 | [diff] [blame] | 12 | int nr_counters; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 13 | |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 14 | struct perf_event_attr attrs[MAX_COUNTERS]; |
Li Zefan | c171b55 | 2009-10-15 11:22:07 +0800 | [diff] [blame] | 15 | char *filters[MAX_COUNTERS]; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 16 | |
| 17 | struct event_symbol { |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 18 | u8 type; |
| 19 | u64 config; |
| 20 | const char *symbol; |
| 21 | const char *alias; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 22 | }; |
| 23 | |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 24 | enum event_result { |
| 25 | EVT_FAILED, |
| 26 | EVT_HANDLED, |
| 27 | EVT_HANDLED_ALL |
| 28 | }; |
| 29 | |
Jason Baron | 5beeded | 2009-07-21 14:16:29 -0400 | [diff] [blame] | 30 | char debugfs_path[MAXPATHLEN]; |
| 31 | |
Jaswinder Singh Rajput | 51e2684 | 2009-06-22 16:43:14 +0530 | [diff] [blame] | 32 | #define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x |
| 33 | #define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 34 | |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 35 | static struct event_symbol event_symbols[] = { |
Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 36 | { CHW(CPU_CYCLES), "cpu-cycles", "cycles" }, |
| 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 | |
Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 44 | { CSW(CPU_CLOCK), "cpu-clock", "" }, |
| 45 | { CSW(TASK_CLOCK), "task-clock", "" }, |
Jaswinder Singh Rajput | c0c22db | 2009-06-22 20:47:26 +0530 | [diff] [blame] | 46 | { CSW(PAGE_FAULTS), "page-faults", "faults" }, |
Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 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" }, |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 51 | }; |
| 52 | |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 53 | #define __PERF_EVENT_FIELD(config, name) \ |
| 54 | ((config & PERF_EVENT_##name##_MASK) >> PERF_EVENT_##name##_SHIFT) |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 55 | |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 56 | #define PERF_EVENT_RAW(config) __PERF_EVENT_FIELD(config, RAW) |
| 57 | #define PERF_EVENT_CONFIG(config) __PERF_EVENT_FIELD(config, CONFIG) |
| 58 | #define PERF_EVENT_TYPE(config) __PERF_EVENT_FIELD(config, TYPE) |
| 59 | #define PERF_EVENT_ID(config) __PERF_EVENT_FIELD(config, EVENT) |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 60 | |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 61 | static const char *hw_event_names[] = { |
Ingo Molnar | 8faf3b5 | 2009-06-06 13:58:12 +0200 | [diff] [blame] | 62 | "cycles", |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 63 | "instructions", |
Ingo Molnar | 8faf3b5 | 2009-06-06 13:58:12 +0200 | [diff] [blame] | 64 | "cache-references", |
| 65 | "cache-misses", |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 66 | "branches", |
Ingo Molnar | 8faf3b5 | 2009-06-06 13:58:12 +0200 | [diff] [blame] | 67 | "branch-misses", |
| 68 | "bus-cycles", |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 69 | }; |
| 70 | |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 71 | static const char *sw_event_names[] = { |
Ingo Molnar | 44175b6 | 2009-06-13 13:35:00 +0200 | [diff] [blame] | 72 | "cpu-clock-msecs", |
| 73 | "task-clock-msecs", |
Ingo Molnar | 8faf3b5 | 2009-06-06 13:58:12 +0200 | [diff] [blame] | 74 | "page-faults", |
| 75 | "context-switches", |
| 76 | "CPU-migrations", |
| 77 | "minor-faults", |
| 78 | "major-faults", |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 79 | }; |
| 80 | |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 81 | #define MAX_ALIASES 8 |
| 82 | |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 83 | static const char *hw_cache[][MAX_ALIASES] = { |
Anton Blanchard | 9590b7b | 2009-07-06 22:01:31 +1000 | [diff] [blame] | 84 | { "L1-dcache", "l1-d", "l1d", "L1-data", }, |
| 85 | { "L1-icache", "l1-i", "l1i", "L1-instruction", }, |
Jaswinder Singh Rajput | e5c5954 | 2009-06-25 18:25:22 +0530 | [diff] [blame] | 86 | { "LLC", "L2" }, |
| 87 | { "dTLB", "d-tlb", "Data-TLB", }, |
| 88 | { "iTLB", "i-tlb", "Instruction-TLB", }, |
| 89 | { "branch", "branches", "bpu", "btb", "bpc", }, |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 90 | }; |
| 91 | |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 92 | static const char *hw_cache_op[][MAX_ALIASES] = { |
Jaswinder Singh Rajput | e5c5954 | 2009-06-25 18:25:22 +0530 | [diff] [blame] | 93 | { "load", "loads", "read", }, |
| 94 | { "store", "stores", "write", }, |
| 95 | { "prefetch", "prefetches", "speculative-read", "speculative-load", }, |
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_result[][MAX_ALIASES] = { |
Jaswinder Singh Rajput | e5c5954 | 2009-06-25 18:25:22 +0530 | [diff] [blame] | 99 | { "refs", "Reference", "ops", "access", }, |
| 100 | { "misses", "miss", }, |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 101 | }; |
| 102 | |
Jaswinder Singh Rajput | 06813f6 | 2009-06-25 17:16:07 +0530 | [diff] [blame] | 103 | #define C(x) PERF_COUNT_HW_CACHE_##x |
| 104 | #define CACHE_READ (1 << C(OP_READ)) |
| 105 | #define CACHE_WRITE (1 << C(OP_WRITE)) |
| 106 | #define CACHE_PREFETCH (1 << C(OP_PREFETCH)) |
| 107 | #define COP(x) (1 << x) |
| 108 | |
| 109 | /* |
| 110 | * cache operartion stat |
| 111 | * L1I : Read and prefetch only |
| 112 | * ITLB and BPU : Read-only |
| 113 | */ |
| 114 | static unsigned long hw_cache_stat[C(MAX)] = { |
| 115 | [C(L1D)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), |
| 116 | [C(L1I)] = (CACHE_READ | CACHE_PREFETCH), |
| 117 | [C(LL)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), |
| 118 | [C(DTLB)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), |
| 119 | [C(ITLB)] = (CACHE_READ), |
| 120 | [C(BPU)] = (CACHE_READ), |
| 121 | }; |
| 122 | |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 123 | #define for_each_subsystem(sys_dir, sys_dirent, sys_next) \ |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 124 | while (!readdir_r(sys_dir, &sys_dirent, &sys_next) && sys_next) \ |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 125 | if (sys_dirent.d_type == DT_DIR && \ |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 126 | (strcmp(sys_dirent.d_name, ".")) && \ |
| 127 | (strcmp(sys_dirent.d_name, ".."))) |
| 128 | |
Peter Zijlstra | ae07b63 | 2009-08-06 16:48:54 +0200 | [diff] [blame] | 129 | static int tp_event_has_id(struct dirent *sys_dir, struct dirent *evt_dir) |
| 130 | { |
| 131 | char evt_path[MAXPATHLEN]; |
| 132 | int fd; |
| 133 | |
| 134 | snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", debugfs_path, |
| 135 | sys_dir->d_name, evt_dir->d_name); |
| 136 | fd = open(evt_path, O_RDONLY); |
| 137 | if (fd < 0) |
| 138 | return -EINVAL; |
| 139 | close(fd); |
| 140 | |
| 141 | return 0; |
| 142 | } |
| 143 | |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 144 | #define for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) \ |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 145 | while (!readdir_r(evt_dir, &evt_dirent, &evt_next) && evt_next) \ |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 146 | if (evt_dirent.d_type == DT_DIR && \ |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 147 | (strcmp(evt_dirent.d_name, ".")) && \ |
Peter Zijlstra | ae07b63 | 2009-08-06 16:48:54 +0200 | [diff] [blame] | 148 | (strcmp(evt_dirent.d_name, "..")) && \ |
| 149 | (!tp_event_has_id(&sys_dirent, &evt_dirent))) |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 150 | |
Li Zefan | 270bbbe | 2009-09-17 16:34:51 +0800 | [diff] [blame] | 151 | #define MAX_EVENT_LENGTH 512 |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 152 | |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 153 | |
Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 154 | struct tracepoint_path *tracepoint_id_to_path(u64 config) |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 155 | { |
Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 156 | struct tracepoint_path *path = NULL; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 157 | DIR *sys_dir, *evt_dir; |
| 158 | struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 159 | char id_buf[4]; |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 160 | int fd; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 161 | u64 id; |
| 162 | char evt_path[MAXPATHLEN]; |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 163 | char dir_path[MAXPATHLEN]; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 164 | |
Clark Williams | 549104f | 2009-11-08 09:03:07 -0600 | [diff] [blame^] | 165 | if (debugfs_valid_mountpoint(debugfs_path)) |
Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 166 | return NULL; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 167 | |
Jason Baron | 5beeded | 2009-07-21 14:16:29 -0400 | [diff] [blame] | 168 | sys_dir = opendir(debugfs_path); |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 169 | if (!sys_dir) |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 170 | return NULL; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 171 | |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 172 | for_each_subsystem(sys_dir, sys_dirent, sys_next) { |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 173 | |
| 174 | snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path, |
| 175 | sys_dirent.d_name); |
| 176 | evt_dir = opendir(dir_path); |
| 177 | if (!evt_dir) |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 178 | continue; |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 179 | |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 180 | for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 181 | |
| 182 | snprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path, |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 183 | evt_dirent.d_name); |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 184 | fd = open(evt_path, O_RDONLY); |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 185 | if (fd < 0) |
| 186 | continue; |
| 187 | if (read(fd, id_buf, sizeof(id_buf)) < 0) { |
| 188 | close(fd); |
| 189 | continue; |
| 190 | } |
| 191 | close(fd); |
| 192 | id = atoll(id_buf); |
| 193 | if (id == config) { |
| 194 | closedir(evt_dir); |
| 195 | closedir(sys_dir); |
Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 196 | path = calloc(1, sizeof(path)); |
| 197 | path->system = malloc(MAX_EVENT_LENGTH); |
| 198 | if (!path->system) { |
| 199 | free(path); |
| 200 | return NULL; |
| 201 | } |
| 202 | path->name = malloc(MAX_EVENT_LENGTH); |
| 203 | if (!path->name) { |
| 204 | free(path->system); |
| 205 | free(path); |
| 206 | return NULL; |
| 207 | } |
| 208 | strncpy(path->system, sys_dirent.d_name, |
| 209 | MAX_EVENT_LENGTH); |
| 210 | strncpy(path->name, evt_dirent.d_name, |
| 211 | MAX_EVENT_LENGTH); |
| 212 | return path; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 213 | } |
| 214 | } |
| 215 | closedir(evt_dir); |
| 216 | } |
| 217 | |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 218 | closedir(sys_dir); |
Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 219 | return NULL; |
| 220 | } |
| 221 | |
| 222 | #define TP_PATH_LEN (MAX_EVENT_LENGTH * 2 + 1) |
| 223 | static const char *tracepoint_id_to_name(u64 config) |
| 224 | { |
| 225 | static char buf[TP_PATH_LEN]; |
| 226 | struct tracepoint_path *path; |
| 227 | |
| 228 | path = tracepoint_id_to_path(config); |
| 229 | if (path) { |
| 230 | snprintf(buf, TP_PATH_LEN, "%s:%s", path->system, path->name); |
| 231 | free(path->name); |
| 232 | free(path->system); |
| 233 | free(path); |
| 234 | } else |
| 235 | snprintf(buf, TP_PATH_LEN, "%s:%s", "unknown", "unknown"); |
| 236 | |
| 237 | return buf; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 238 | } |
| 239 | |
Jaswinder Singh Rajput | 06813f6 | 2009-06-25 17:16:07 +0530 | [diff] [blame] | 240 | static int is_cache_op_valid(u8 cache_type, u8 cache_op) |
| 241 | { |
| 242 | if (hw_cache_stat[cache_type] & COP(cache_op)) |
| 243 | return 1; /* valid */ |
| 244 | else |
| 245 | return 0; /* invalid */ |
| 246 | } |
| 247 | |
Jaswinder Singh Rajput | e5c5954 | 2009-06-25 18:25:22 +0530 | [diff] [blame] | 248 | static char *event_cache_name(u8 cache_type, u8 cache_op, u8 cache_result) |
| 249 | { |
| 250 | static char name[50]; |
| 251 | |
| 252 | if (cache_result) { |
| 253 | sprintf(name, "%s-%s-%s", hw_cache[cache_type][0], |
| 254 | hw_cache_op[cache_op][0], |
| 255 | hw_cache_result[cache_result][0]); |
| 256 | } else { |
| 257 | sprintf(name, "%s-%s", hw_cache[cache_type][0], |
| 258 | hw_cache_op[cache_op][1]); |
| 259 | } |
| 260 | |
| 261 | return name; |
| 262 | } |
| 263 | |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 264 | const char *event_name(int counter) |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 265 | { |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 266 | u64 config = attrs[counter].config; |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 267 | int type = attrs[counter].type; |
Peter Zijlstra | 8f18aec | 2009-08-06 19:40:28 +0200 | [diff] [blame] | 268 | |
| 269 | return __event_name(type, config); |
| 270 | } |
| 271 | |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 272 | const char *__event_name(int type, u64 config) |
Peter Zijlstra | 8f18aec | 2009-08-06 19:40:28 +0200 | [diff] [blame] | 273 | { |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 274 | static char buf[32]; |
| 275 | |
Peter Zijlstra | 8f18aec | 2009-08-06 19:40:28 +0200 | [diff] [blame] | 276 | if (type == PERF_TYPE_RAW) { |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 277 | sprintf(buf, "raw 0x%llx", config); |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 278 | return buf; |
| 279 | } |
| 280 | |
| 281 | switch (type) { |
| 282 | case PERF_TYPE_HARDWARE: |
Peter Zijlstra | f4dbfa8 | 2009-06-11 14:06:28 +0200 | [diff] [blame] | 283 | if (config < PERF_COUNT_HW_MAX) |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 284 | return hw_event_names[config]; |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 285 | return "unknown-hardware"; |
| 286 | |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 287 | case PERF_TYPE_HW_CACHE: { |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 288 | u8 cache_type, cache_op, cache_result; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 289 | |
| 290 | cache_type = (config >> 0) & 0xff; |
| 291 | if (cache_type > PERF_COUNT_HW_CACHE_MAX) |
| 292 | return "unknown-ext-hardware-cache-type"; |
| 293 | |
| 294 | cache_op = (config >> 8) & 0xff; |
Ingo Molnar | 8faf3b5 | 2009-06-06 13:58:12 +0200 | [diff] [blame] | 295 | if (cache_op > PERF_COUNT_HW_CACHE_OP_MAX) |
| 296 | return "unknown-ext-hardware-cache-op"; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 297 | |
| 298 | cache_result = (config >> 16) & 0xff; |
Ingo Molnar | 8faf3b5 | 2009-06-06 13:58:12 +0200 | [diff] [blame] | 299 | if (cache_result > PERF_COUNT_HW_CACHE_RESULT_MAX) |
| 300 | return "unknown-ext-hardware-cache-result"; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 301 | |
Jaswinder Singh Rajput | 06813f6 | 2009-06-25 17:16:07 +0530 | [diff] [blame] | 302 | if (!is_cache_op_valid(cache_type, cache_op)) |
| 303 | return "invalid-cache"; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 304 | |
Jaswinder Singh Rajput | e5c5954 | 2009-06-25 18:25:22 +0530 | [diff] [blame] | 305 | return event_cache_name(cache_type, cache_op, cache_result); |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 306 | } |
| 307 | |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 308 | case PERF_TYPE_SOFTWARE: |
Peter Zijlstra | f4dbfa8 | 2009-06-11 14:06:28 +0200 | [diff] [blame] | 309 | if (config < PERF_COUNT_SW_MAX) |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 310 | return sw_event_names[config]; |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 311 | return "unknown-software"; |
| 312 | |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 313 | case PERF_TYPE_TRACEPOINT: |
| 314 | return tracepoint_id_to_name(config); |
| 315 | |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 316 | default: |
| 317 | break; |
| 318 | } |
| 319 | |
| 320 | return "unknown"; |
| 321 | } |
| 322 | |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 323 | 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] | 324 | { |
| 325 | int i, j; |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 326 | int n, longest = -1; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 327 | |
| 328 | for (i = 0; i < size; i++) { |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 329 | for (j = 0; j < MAX_ALIASES && names[i][j]; j++) { |
| 330 | n = strlen(names[i][j]); |
| 331 | if (n > longest && !strncasecmp(*str, names[i][j], n)) |
| 332 | longest = n; |
| 333 | } |
| 334 | if (longest > 0) { |
| 335 | *str += longest; |
| 336 | return i; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | |
Ingo Molnar | 8953645 | 2009-06-06 21:04:17 +0200 | [diff] [blame] | 340 | return -1; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 341 | } |
| 342 | |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 343 | static enum event_result |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 344 | parse_generic_hw_event(const char **str, struct perf_event_attr *attr) |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 345 | { |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 346 | const char *s = *str; |
| 347 | int cache_type = -1, cache_op = -1, cache_result = -1; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 348 | |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 349 | cache_type = parse_aliases(&s, hw_cache, PERF_COUNT_HW_CACHE_MAX); |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 350 | /* |
| 351 | * No fallback - if we cannot get a clear cache type |
| 352 | * then bail out: |
| 353 | */ |
| 354 | if (cache_type == -1) |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 355 | return EVT_FAILED; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 356 | |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 357 | while ((cache_op == -1 || cache_result == -1) && *s == '-') { |
| 358 | ++s; |
| 359 | |
| 360 | if (cache_op == -1) { |
| 361 | cache_op = parse_aliases(&s, hw_cache_op, |
| 362 | PERF_COUNT_HW_CACHE_OP_MAX); |
| 363 | if (cache_op >= 0) { |
| 364 | if (!is_cache_op_valid(cache_type, cache_op)) |
| 365 | return 0; |
| 366 | continue; |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | if (cache_result == -1) { |
| 371 | cache_result = parse_aliases(&s, hw_cache_result, |
| 372 | PERF_COUNT_HW_CACHE_RESULT_MAX); |
| 373 | if (cache_result >= 0) |
| 374 | continue; |
| 375 | } |
| 376 | |
| 377 | /* |
| 378 | * Can't parse this as a cache op or result, so back up |
| 379 | * to the '-'. |
| 380 | */ |
| 381 | --s; |
| 382 | break; |
| 383 | } |
| 384 | |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 385 | /* |
| 386 | * Fall back to reads: |
| 387 | */ |
Ingo Molnar | 8953645 | 2009-06-06 21:04:17 +0200 | [diff] [blame] | 388 | if (cache_op == -1) |
| 389 | cache_op = PERF_COUNT_HW_CACHE_OP_READ; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 390 | |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 391 | /* |
| 392 | * Fall back to accesses: |
| 393 | */ |
| 394 | if (cache_result == -1) |
| 395 | cache_result = PERF_COUNT_HW_CACHE_RESULT_ACCESS; |
| 396 | |
| 397 | attr->config = cache_type | (cache_op << 8) | (cache_result << 16); |
| 398 | attr->type = PERF_TYPE_HW_CACHE; |
| 399 | |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 400 | *str = s; |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 401 | return EVT_HANDLED; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 402 | } |
| 403 | |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 404 | static enum event_result |
| 405 | parse_single_tracepoint_event(char *sys_name, |
| 406 | const char *evt_name, |
| 407 | unsigned int evt_length, |
| 408 | char *flags, |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 409 | struct perf_event_attr *attr, |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 410 | const char **strp) |
| 411 | { |
| 412 | char evt_path[MAXPATHLEN]; |
| 413 | char id_buf[4]; |
| 414 | u64 id; |
| 415 | int fd; |
| 416 | |
| 417 | if (flags) { |
Li Zefan | 1281a49 | 2009-09-17 16:49:43 +0800 | [diff] [blame] | 418 | if (!strncmp(flags, "record", strlen(flags))) { |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 419 | attr->sample_type |= PERF_SAMPLE_RAW; |
Li Zefan | 1281a49 | 2009-09-17 16:49:43 +0800 | [diff] [blame] | 420 | attr->sample_type |= PERF_SAMPLE_TIME; |
| 421 | attr->sample_type |= PERF_SAMPLE_CPU; |
| 422 | } |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", debugfs_path, |
| 426 | sys_name, evt_name); |
| 427 | |
| 428 | fd = open(evt_path, O_RDONLY); |
| 429 | if (fd < 0) |
| 430 | return EVT_FAILED; |
| 431 | |
| 432 | if (read(fd, id_buf, sizeof(id_buf)) < 0) { |
| 433 | close(fd); |
| 434 | return EVT_FAILED; |
| 435 | } |
| 436 | |
| 437 | close(fd); |
| 438 | id = atoll(id_buf); |
| 439 | attr->config = id; |
| 440 | attr->type = PERF_TYPE_TRACEPOINT; |
| 441 | *strp = evt_name + evt_length; |
| 442 | |
| 443 | return EVT_HANDLED; |
| 444 | } |
| 445 | |
| 446 | /* sys + ':' + event + ':' + flags*/ |
| 447 | #define MAX_EVOPT_LEN (MAX_EVENT_LENGTH * 2 + 2 + 128) |
| 448 | static enum event_result |
| 449 | parse_subsystem_tracepoint_event(char *sys_name, char *flags) |
| 450 | { |
| 451 | char evt_path[MAXPATHLEN]; |
| 452 | struct dirent *evt_ent; |
| 453 | DIR *evt_dir; |
| 454 | |
| 455 | snprintf(evt_path, MAXPATHLEN, "%s/%s", debugfs_path, sys_name); |
| 456 | evt_dir = opendir(evt_path); |
| 457 | |
| 458 | if (!evt_dir) { |
| 459 | perror("Can't open event dir"); |
| 460 | return EVT_FAILED; |
| 461 | } |
| 462 | |
| 463 | while ((evt_ent = readdir(evt_dir))) { |
| 464 | char event_opt[MAX_EVOPT_LEN + 1]; |
| 465 | int len; |
| 466 | unsigned int rem = MAX_EVOPT_LEN; |
| 467 | |
| 468 | if (!strcmp(evt_ent->d_name, ".") |
| 469 | || !strcmp(evt_ent->d_name, "..") |
| 470 | || !strcmp(evt_ent->d_name, "enable") |
| 471 | || !strcmp(evt_ent->d_name, "filter")) |
| 472 | continue; |
| 473 | |
| 474 | len = snprintf(event_opt, MAX_EVOPT_LEN, "%s:%s", sys_name, |
| 475 | evt_ent->d_name); |
| 476 | if (len < 0) |
| 477 | return EVT_FAILED; |
| 478 | |
| 479 | rem -= len; |
| 480 | if (flags) { |
| 481 | if (rem < strlen(flags) + 1) |
| 482 | return EVT_FAILED; |
| 483 | |
| 484 | strcat(event_opt, ":"); |
| 485 | strcat(event_opt, flags); |
| 486 | } |
| 487 | |
| 488 | if (parse_events(NULL, event_opt, 0)) |
| 489 | return EVT_FAILED; |
| 490 | } |
| 491 | |
| 492 | return EVT_HANDLED_ALL; |
| 493 | } |
| 494 | |
| 495 | |
| 496 | static enum event_result parse_tracepoint_event(const char **strp, |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 497 | struct perf_event_attr *attr) |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 498 | { |
| 499 | const char *evt_name; |
Frederic Weisbecker | 3a9f131 | 2009-08-13 10:27:18 +0200 | [diff] [blame] | 500 | char *flags; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 501 | char sys_name[MAX_EVENT_LENGTH]; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 502 | unsigned int sys_length, evt_length; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 503 | |
Clark Williams | 549104f | 2009-11-08 09:03:07 -0600 | [diff] [blame^] | 504 | if (debugfs_valid_mountpoint(debugfs_path)) |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 505 | return 0; |
| 506 | |
| 507 | evt_name = strchr(*strp, ':'); |
| 508 | if (!evt_name) |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 509 | return EVT_FAILED; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 510 | |
| 511 | sys_length = evt_name - *strp; |
| 512 | if (sys_length >= MAX_EVENT_LENGTH) |
| 513 | return 0; |
| 514 | |
| 515 | strncpy(sys_name, *strp, sys_length); |
| 516 | sys_name[sys_length] = '\0'; |
| 517 | evt_name = evt_name + 1; |
Frederic Weisbecker | 3a9f131 | 2009-08-13 10:27:18 +0200 | [diff] [blame] | 518 | |
| 519 | flags = strchr(evt_name, ':'); |
| 520 | if (flags) { |
Ingo Molnar | 1fc35b2 | 2009-09-13 09:44:29 +0200 | [diff] [blame] | 521 | /* split it out: */ |
| 522 | evt_name = strndup(evt_name, flags - evt_name); |
Frederic Weisbecker | 3a9f131 | 2009-08-13 10:27:18 +0200 | [diff] [blame] | 523 | flags++; |
Frederic Weisbecker | 3a9f131 | 2009-08-13 10:27:18 +0200 | [diff] [blame] | 524 | } |
| 525 | |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 526 | evt_length = strlen(evt_name); |
| 527 | if (evt_length >= MAX_EVENT_LENGTH) |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 528 | return EVT_FAILED; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 529 | |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 530 | if (!strcmp(evt_name, "*")) { |
| 531 | *strp = evt_name + evt_length; |
| 532 | return parse_subsystem_tracepoint_event(sys_name, flags); |
| 533 | } else |
| 534 | return parse_single_tracepoint_event(sys_name, evt_name, |
| 535 | evt_length, flags, |
| 536 | attr, strp); |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 537 | } |
| 538 | |
Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 539 | static int check_events(const char *str, unsigned int i) |
| 540 | { |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 541 | int n; |
Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 542 | |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 543 | n = strlen(event_symbols[i].symbol); |
| 544 | if (!strncmp(str, event_symbols[i].symbol, n)) |
| 545 | return n; |
| 546 | |
| 547 | n = strlen(event_symbols[i].alias); |
| 548 | if (n) |
| 549 | if (!strncmp(str, event_symbols[i].alias, n)) |
| 550 | return n; |
| 551 | return 0; |
| 552 | } |
| 553 | |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 554 | static enum event_result |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 555 | parse_symbolic_event(const char **strp, struct perf_event_attr *attr) |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 556 | { |
| 557 | const char *str = *strp; |
| 558 | unsigned int i; |
| 559 | int n; |
| 560 | |
| 561 | for (i = 0; i < ARRAY_SIZE(event_symbols); i++) { |
| 562 | n = check_events(str, i); |
| 563 | if (n > 0) { |
| 564 | attr->type = event_symbols[i].type; |
| 565 | attr->config = event_symbols[i].config; |
| 566 | *strp = str + n; |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 567 | return EVT_HANDLED; |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 568 | } |
| 569 | } |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 570 | return EVT_FAILED; |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 571 | } |
| 572 | |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 573 | static enum event_result |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 574 | parse_raw_event(const char **strp, struct perf_event_attr *attr) |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 575 | { |
| 576 | const char *str = *strp; |
| 577 | u64 config; |
| 578 | int n; |
| 579 | |
| 580 | if (*str != 'r') |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 581 | return EVT_FAILED; |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 582 | n = hex2u64(str + 1, &config); |
| 583 | if (n > 0) { |
| 584 | *strp = str + n + 1; |
| 585 | attr->type = PERF_TYPE_RAW; |
| 586 | attr->config = config; |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 587 | return EVT_HANDLED; |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 588 | } |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 589 | return EVT_FAILED; |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 590 | } |
| 591 | |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 592 | static enum event_result |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 593 | parse_numeric_event(const char **strp, struct perf_event_attr *attr) |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 594 | { |
| 595 | const char *str = *strp; |
| 596 | char *endp; |
| 597 | unsigned long type; |
| 598 | u64 config; |
| 599 | |
| 600 | type = strtoul(str, &endp, 0); |
| 601 | if (endp > str && type < PERF_TYPE_MAX && *endp == ':') { |
| 602 | str = endp + 1; |
| 603 | config = strtoul(str, &endp, 0); |
| 604 | if (endp > str) { |
| 605 | attr->type = type; |
| 606 | attr->config = config; |
| 607 | *strp = endp; |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 608 | return EVT_HANDLED; |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 609 | } |
| 610 | } |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 611 | return EVT_FAILED; |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 612 | } |
| 613 | |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 614 | static enum event_result |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 615 | parse_event_modifier(const char **strp, struct perf_event_attr *attr) |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 616 | { |
| 617 | const char *str = *strp; |
| 618 | int eu = 1, ek = 1, eh = 1; |
| 619 | |
| 620 | if (*str++ != ':') |
| 621 | return 0; |
| 622 | while (*str) { |
| 623 | if (*str == 'u') |
| 624 | eu = 0; |
| 625 | else if (*str == 'k') |
| 626 | ek = 0; |
| 627 | else if (*str == 'h') |
| 628 | eh = 0; |
| 629 | else |
| 630 | break; |
| 631 | ++str; |
| 632 | } |
| 633 | if (str >= *strp + 2) { |
| 634 | *strp = str; |
| 635 | attr->exclude_user = eu; |
| 636 | attr->exclude_kernel = ek; |
| 637 | attr->exclude_hv = eh; |
| 638 | return 1; |
| 639 | } |
Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 640 | return 0; |
| 641 | } |
| 642 | |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 643 | /* |
| 644 | * Each event can have multiple symbolic names. |
| 645 | * Symbolic names are (almost) exactly matched. |
| 646 | */ |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 647 | static enum event_result |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 648 | parse_event_symbols(const char **str, struct perf_event_attr *attr) |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 649 | { |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 650 | enum event_result ret; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 651 | |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 652 | ret = parse_tracepoint_event(str, attr); |
| 653 | if (ret != EVT_FAILED) |
| 654 | goto modifier; |
| 655 | |
| 656 | ret = parse_raw_event(str, attr); |
| 657 | if (ret != EVT_FAILED) |
| 658 | goto modifier; |
| 659 | |
| 660 | ret = parse_numeric_event(str, attr); |
| 661 | if (ret != EVT_FAILED) |
| 662 | goto modifier; |
| 663 | |
| 664 | ret = parse_symbolic_event(str, attr); |
| 665 | if (ret != EVT_FAILED) |
| 666 | goto modifier; |
| 667 | |
| 668 | ret = parse_generic_hw_event(str, attr); |
| 669 | if (ret != EVT_FAILED) |
| 670 | goto modifier; |
| 671 | |
Marti Raudsepp | 85df6f6 | 2009-10-27 00:33:04 +0000 | [diff] [blame] | 672 | fprintf(stderr, "invalid or unsupported event: '%s'\n", *str); |
| 673 | fprintf(stderr, "Run 'perf list' for a list of valid events\n"); |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 674 | return EVT_FAILED; |
| 675 | |
| 676 | modifier: |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 677 | parse_event_modifier(str, attr); |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 678 | |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 679 | return ret; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 680 | } |
| 681 | |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 682 | static void store_event_type(const char *orgname) |
| 683 | { |
| 684 | char filename[PATH_MAX], *c; |
| 685 | FILE *file; |
| 686 | int id; |
| 687 | |
Ashwin Chaugule | 63c9e01 | 2009-10-04 15:49:34 -0700 | [diff] [blame] | 688 | sprintf(filename, "%s/", debugfs_path); |
| 689 | strncat(filename, orgname, strlen(orgname)); |
| 690 | strcat(filename, "/id"); |
| 691 | |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 692 | c = strchr(filename, ':'); |
| 693 | if (c) |
| 694 | *c = '/'; |
| 695 | |
| 696 | file = fopen(filename, "r"); |
| 697 | if (!file) |
| 698 | return; |
| 699 | if (fscanf(file, "%i", &id) < 1) |
| 700 | die("cannot store event ID"); |
| 701 | fclose(file); |
| 702 | perf_header__push_event(id, orgname); |
| 703 | } |
| 704 | |
Ingo Molnar | f37a291 | 2009-07-01 12:37:06 +0200 | [diff] [blame] | 705 | int parse_events(const struct option *opt __used, const char *str, int unset __used) |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 706 | { |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 707 | struct perf_event_attr attr; |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 708 | enum event_result ret; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 709 | |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 710 | if (strchr(str, ':')) |
| 711 | store_event_type(str); |
| 712 | |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 713 | for (;;) { |
| 714 | if (nr_counters == MAX_COUNTERS) |
| 715 | return -1; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 716 | |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 717 | memset(&attr, 0, sizeof(attr)); |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 718 | ret = parse_event_symbols(&str, &attr); |
| 719 | if (ret == EVT_FAILED) |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 720 | return -1; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 721 | |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 722 | if (!(*str == 0 || *str == ',' || isspace(*str))) |
| 723 | return -1; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 724 | |
Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 725 | if (ret != EVT_HANDLED_ALL) { |
| 726 | attrs[nr_counters] = attr; |
| 727 | nr_counters++; |
| 728 | } |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 729 | |
| 730 | if (*str == 0) |
| 731 | break; |
| 732 | if (*str == ',') |
| 733 | ++str; |
| 734 | while (isspace(*str)) |
| 735 | ++str; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | return 0; |
| 739 | } |
| 740 | |
Li Zefan | c171b55 | 2009-10-15 11:22:07 +0800 | [diff] [blame] | 741 | int parse_filter(const struct option *opt __used, const char *str, |
| 742 | int unset __used) |
| 743 | { |
| 744 | int i = nr_counters - 1; |
| 745 | int len = strlen(str); |
| 746 | |
| 747 | if (i < 0 || attrs[i].type != PERF_TYPE_TRACEPOINT) { |
| 748 | fprintf(stderr, |
| 749 | "-F option should follow a -e tracepoint option\n"); |
| 750 | return -1; |
| 751 | } |
| 752 | |
| 753 | filters[i] = malloc(len + 1); |
| 754 | if (!filters[i]) { |
| 755 | fprintf(stderr, "not enough memory to hold filter string\n"); |
| 756 | return -1; |
| 757 | } |
| 758 | strcpy(filters[i], str); |
| 759 | |
| 760 | return 0; |
| 761 | } |
| 762 | |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 763 | static const char * const event_type_descriptors[] = { |
| 764 | "", |
| 765 | "Hardware event", |
| 766 | "Software event", |
| 767 | "Tracepoint event", |
| 768 | "Hardware cache event", |
| 769 | }; |
| 770 | |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 771 | /* |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 772 | * Print the events from <debugfs_mount_point>/tracing/events |
| 773 | */ |
| 774 | |
| 775 | static void print_tracepoint_events(void) |
| 776 | { |
| 777 | DIR *sys_dir, *evt_dir; |
| 778 | struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 779 | char evt_path[MAXPATHLEN]; |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 780 | char dir_path[MAXPATHLEN]; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 781 | |
Clark Williams | 549104f | 2009-11-08 09:03:07 -0600 | [diff] [blame^] | 782 | if (debugfs_valid_mountpoint(debugfs_path)) |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 783 | return; |
| 784 | |
Jason Baron | 5beeded | 2009-07-21 14:16:29 -0400 | [diff] [blame] | 785 | sys_dir = opendir(debugfs_path); |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 786 | if (!sys_dir) |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 787 | return; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 788 | |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 789 | for_each_subsystem(sys_dir, sys_dirent, sys_next) { |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 790 | |
| 791 | snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path, |
| 792 | sys_dirent.d_name); |
| 793 | evt_dir = opendir(dir_path); |
| 794 | if (!evt_dir) |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 795 | continue; |
Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 796 | |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 797 | for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 798 | snprintf(evt_path, MAXPATHLEN, "%s:%s", |
| 799 | sys_dirent.d_name, evt_dirent.d_name); |
Marti Raudsepp | 689d301 | 2009-10-27 00:33:05 +0000 | [diff] [blame] | 800 | printf(" %-42s [%s]\n", evt_path, |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 801 | event_type_descriptors[PERF_TYPE_TRACEPOINT+1]); |
| 802 | } |
| 803 | closedir(evt_dir); |
| 804 | } |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 805 | closedir(sys_dir); |
| 806 | } |
| 807 | |
| 808 | /* |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 809 | * Print the help text for the event symbols: |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 810 | */ |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 811 | void print_events(void) |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 812 | { |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 813 | struct event_symbol *syms = event_symbols; |
Jaswinder Singh Rajput | 73c24cb | 2009-07-01 18:36:18 +0530 | [diff] [blame] | 814 | unsigned int i, type, op, prev_type = -1; |
Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 815 | char name[40]; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 816 | |
Marti Raudsepp | 689d301 | 2009-10-27 00:33:05 +0000 | [diff] [blame] | 817 | printf("\n"); |
| 818 | printf("List of pre-defined events (to be used in -e):\n"); |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 819 | |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 820 | for (i = 0; i < ARRAY_SIZE(event_symbols); i++, syms++) { |
| 821 | type = syms->type + 1; |
Roel Kluin | 23cdb5d | 2009-07-13 02:25:47 +0200 | [diff] [blame] | 822 | if (type >= ARRAY_SIZE(event_type_descriptors)) |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 823 | type = 0; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 824 | |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 825 | if (type != prev_type) |
Marti Raudsepp | 689d301 | 2009-10-27 00:33:05 +0000 | [diff] [blame] | 826 | printf("\n"); |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 827 | |
Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 828 | if (strlen(syms->alias)) |
| 829 | sprintf(name, "%s OR %s", syms->symbol, syms->alias); |
| 830 | else |
| 831 | strcpy(name, syms->symbol); |
Marti Raudsepp | 689d301 | 2009-10-27 00:33:05 +0000 | [diff] [blame] | 832 | printf(" %-42s [%s]\n", name, |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 833 | event_type_descriptors[type]); |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 834 | |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 835 | prev_type = type; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 836 | } |
| 837 | |
Marti Raudsepp | 689d301 | 2009-10-27 00:33:05 +0000 | [diff] [blame] | 838 | printf("\n"); |
Jaswinder Singh Rajput | 73c24cb | 2009-07-01 18:36:18 +0530 | [diff] [blame] | 839 | for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) { |
| 840 | for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) { |
| 841 | /* skip invalid cache type */ |
| 842 | if (!is_cache_op_valid(type, op)) |
| 843 | continue; |
| 844 | |
| 845 | for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) { |
Marti Raudsepp | 689d301 | 2009-10-27 00:33:05 +0000 | [diff] [blame] | 846 | printf(" %-42s [%s]\n", |
Jaswinder Singh Rajput | 73c24cb | 2009-07-01 18:36:18 +0530 | [diff] [blame] | 847 | event_cache_name(type, op, i), |
| 848 | event_type_descriptors[4]); |
| 849 | } |
| 850 | } |
| 851 | } |
| 852 | |
Marti Raudsepp | 689d301 | 2009-10-27 00:33:05 +0000 | [diff] [blame] | 853 | printf("\n"); |
| 854 | printf(" %-42s [raw hardware event descriptor]\n", |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 855 | "rNNN"); |
Marti Raudsepp | 689d301 | 2009-10-27 00:33:05 +0000 | [diff] [blame] | 856 | printf("\n"); |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 857 | |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 858 | print_tracepoint_events(); |
| 859 | |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 860 | exit(129); |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 861 | } |