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" |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 9 | |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 10 | int nr_counters; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 11 | |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 12 | struct perf_counter_attr attrs[MAX_COUNTERS]; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 13 | |
| 14 | struct event_symbol { |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 15 | u8 type; |
| 16 | u64 config; |
| 17 | const char *symbol; |
| 18 | const char *alias; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 19 | }; |
| 20 | |
Jason Baron | 5beeded | 2009-07-21 14:16:29 -0400 | [diff] [blame] | 21 | char debugfs_path[MAXPATHLEN]; |
| 22 | |
Jaswinder Singh Rajput | 51e2684 | 2009-06-22 16:43:14 +0530 | [diff] [blame] | 23 | #define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x |
| 24 | #define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 25 | |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 26 | static struct event_symbol event_symbols[] = { |
Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 27 | { CHW(CPU_CYCLES), "cpu-cycles", "cycles" }, |
| 28 | { CHW(INSTRUCTIONS), "instructions", "" }, |
| 29 | { CHW(CACHE_REFERENCES), "cache-references", "" }, |
| 30 | { CHW(CACHE_MISSES), "cache-misses", "" }, |
| 31 | { CHW(BRANCH_INSTRUCTIONS), "branch-instructions", "branches" }, |
| 32 | { CHW(BRANCH_MISSES), "branch-misses", "" }, |
| 33 | { CHW(BUS_CYCLES), "bus-cycles", "" }, |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 34 | |
Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 35 | { CSW(CPU_CLOCK), "cpu-clock", "" }, |
| 36 | { CSW(TASK_CLOCK), "task-clock", "" }, |
Jaswinder Singh Rajput | c0c22db | 2009-06-22 20:47:26 +0530 | [diff] [blame] | 37 | { CSW(PAGE_FAULTS), "page-faults", "faults" }, |
Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 38 | { CSW(PAGE_FAULTS_MIN), "minor-faults", "" }, |
| 39 | { CSW(PAGE_FAULTS_MAJ), "major-faults", "" }, |
| 40 | { CSW(CONTEXT_SWITCHES), "context-switches", "cs" }, |
| 41 | { CSW(CPU_MIGRATIONS), "cpu-migrations", "migrations" }, |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 42 | }; |
| 43 | |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 44 | #define __PERF_COUNTER_FIELD(config, name) \ |
| 45 | ((config & PERF_COUNTER_##name##_MASK) >> PERF_COUNTER_##name##_SHIFT) |
| 46 | |
| 47 | #define PERF_COUNTER_RAW(config) __PERF_COUNTER_FIELD(config, RAW) |
| 48 | #define PERF_COUNTER_CONFIG(config) __PERF_COUNTER_FIELD(config, CONFIG) |
| 49 | #define PERF_COUNTER_TYPE(config) __PERF_COUNTER_FIELD(config, TYPE) |
| 50 | #define PERF_COUNTER_ID(config) __PERF_COUNTER_FIELD(config, EVENT) |
| 51 | |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 52 | static const char *hw_event_names[] = { |
Ingo Molnar | 8faf3b5 | 2009-06-06 13:58:12 +0200 | [diff] [blame] | 53 | "cycles", |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 54 | "instructions", |
Ingo Molnar | 8faf3b5 | 2009-06-06 13:58:12 +0200 | [diff] [blame] | 55 | "cache-references", |
| 56 | "cache-misses", |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 57 | "branches", |
Ingo Molnar | 8faf3b5 | 2009-06-06 13:58:12 +0200 | [diff] [blame] | 58 | "branch-misses", |
| 59 | "bus-cycles", |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 60 | }; |
| 61 | |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 62 | static const char *sw_event_names[] = { |
Ingo Molnar | 44175b6 | 2009-06-13 13:35:00 +0200 | [diff] [blame] | 63 | "cpu-clock-msecs", |
| 64 | "task-clock-msecs", |
Ingo Molnar | 8faf3b5 | 2009-06-06 13:58:12 +0200 | [diff] [blame] | 65 | "page-faults", |
| 66 | "context-switches", |
| 67 | "CPU-migrations", |
| 68 | "minor-faults", |
| 69 | "major-faults", |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 70 | }; |
| 71 | |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 72 | #define MAX_ALIASES 8 |
| 73 | |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 74 | static const char *hw_cache[][MAX_ALIASES] = { |
Anton Blanchard | 9590b7b | 2009-07-06 22:01:31 +1000 | [diff] [blame] | 75 | { "L1-dcache", "l1-d", "l1d", "L1-data", }, |
| 76 | { "L1-icache", "l1-i", "l1i", "L1-instruction", }, |
Jaswinder Singh Rajput | e5c5954 | 2009-06-25 18:25:22 +0530 | [diff] [blame] | 77 | { "LLC", "L2" }, |
| 78 | { "dTLB", "d-tlb", "Data-TLB", }, |
| 79 | { "iTLB", "i-tlb", "Instruction-TLB", }, |
| 80 | { "branch", "branches", "bpu", "btb", "bpc", }, |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 81 | }; |
| 82 | |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 83 | static const char *hw_cache_op[][MAX_ALIASES] = { |
Jaswinder Singh Rajput | e5c5954 | 2009-06-25 18:25:22 +0530 | [diff] [blame] | 84 | { "load", "loads", "read", }, |
| 85 | { "store", "stores", "write", }, |
| 86 | { "prefetch", "prefetches", "speculative-read", "speculative-load", }, |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 87 | }; |
| 88 | |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 89 | static const char *hw_cache_result[][MAX_ALIASES] = { |
Jaswinder Singh Rajput | e5c5954 | 2009-06-25 18:25:22 +0530 | [diff] [blame] | 90 | { "refs", "Reference", "ops", "access", }, |
| 91 | { "misses", "miss", }, |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 92 | }; |
| 93 | |
Jaswinder Singh Rajput | 06813f6 | 2009-06-25 17:16:07 +0530 | [diff] [blame] | 94 | #define C(x) PERF_COUNT_HW_CACHE_##x |
| 95 | #define CACHE_READ (1 << C(OP_READ)) |
| 96 | #define CACHE_WRITE (1 << C(OP_WRITE)) |
| 97 | #define CACHE_PREFETCH (1 << C(OP_PREFETCH)) |
| 98 | #define COP(x) (1 << x) |
| 99 | |
| 100 | /* |
| 101 | * cache operartion stat |
| 102 | * L1I : Read and prefetch only |
| 103 | * ITLB and BPU : Read-only |
| 104 | */ |
| 105 | static unsigned long hw_cache_stat[C(MAX)] = { |
| 106 | [C(L1D)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), |
| 107 | [C(L1I)] = (CACHE_READ | CACHE_PREFETCH), |
| 108 | [C(LL)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), |
| 109 | [C(DTLB)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), |
| 110 | [C(ITLB)] = (CACHE_READ), |
| 111 | [C(BPU)] = (CACHE_READ), |
| 112 | }; |
| 113 | |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame^] | 114 | #define for_each_subsystem(sys_dir, sys_dirent, sys_next) \ |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 115 | while (!readdir_r(sys_dir, &sys_dirent, &sys_next) && sys_next) \ |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame^] | 116 | if (sys_dirent.d_type == DT_DIR && \ |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 117 | (strcmp(sys_dirent.d_name, ".")) && \ |
| 118 | (strcmp(sys_dirent.d_name, ".."))) |
| 119 | |
Peter Zijlstra | ae07b63 | 2009-08-06 16:48:54 +0200 | [diff] [blame] | 120 | static int tp_event_has_id(struct dirent *sys_dir, struct dirent *evt_dir) |
| 121 | { |
| 122 | char evt_path[MAXPATHLEN]; |
| 123 | int fd; |
| 124 | |
| 125 | snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", debugfs_path, |
| 126 | sys_dir->d_name, evt_dir->d_name); |
| 127 | fd = open(evt_path, O_RDONLY); |
| 128 | if (fd < 0) |
| 129 | return -EINVAL; |
| 130 | close(fd); |
| 131 | |
| 132 | return 0; |
| 133 | } |
| 134 | |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame^] | 135 | #define for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) \ |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 136 | while (!readdir_r(evt_dir, &evt_dirent, &evt_next) && evt_next) \ |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame^] | 137 | if (evt_dirent.d_type == DT_DIR && \ |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 138 | (strcmp(evt_dirent.d_name, ".")) && \ |
Peter Zijlstra | ae07b63 | 2009-08-06 16:48:54 +0200 | [diff] [blame] | 139 | (strcmp(evt_dirent.d_name, "..")) && \ |
| 140 | (!tp_event_has_id(&sys_dirent, &evt_dirent))) |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 141 | |
| 142 | #define MAX_EVENT_LENGTH 30 |
| 143 | |
Jason Baron | 5beeded | 2009-07-21 14:16:29 -0400 | [diff] [blame] | 144 | int valid_debugfs_mount(const char *debugfs) |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 145 | { |
| 146 | struct statfs st_fs; |
| 147 | |
Jason Baron | 5beeded | 2009-07-21 14:16:29 -0400 | [diff] [blame] | 148 | if (statfs(debugfs, &st_fs) < 0) |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 149 | return -ENOENT; |
| 150 | else if (st_fs.f_type != (long) DEBUGFS_MAGIC) |
| 151 | return -ENOENT; |
| 152 | return 0; |
| 153 | } |
| 154 | |
Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 155 | struct tracepoint_path *tracepoint_id_to_path(u64 config) |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 156 | { |
Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 157 | struct tracepoint_path *path = NULL; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 158 | DIR *sys_dir, *evt_dir; |
| 159 | struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 160 | char id_buf[4]; |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame^] | 161 | int sys_dir_fd, fd; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 162 | u64 id; |
| 163 | char evt_path[MAXPATHLEN]; |
| 164 | |
Jason Baron | 5beeded | 2009-07-21 14:16:29 -0400 | [diff] [blame] | 165 | if (valid_debugfs_mount(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) |
| 170 | goto cleanup; |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame^] | 171 | sys_dir_fd = dirfd(sys_dir); |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 172 | |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame^] | 173 | for_each_subsystem(sys_dir, sys_dirent, sys_next) { |
| 174 | int dfd = openat(sys_dir_fd, sys_dirent.d_name, |
| 175 | O_RDONLY|O_DIRECTORY), evt_dir_fd; |
| 176 | if (dfd == -1) |
| 177 | continue; |
| 178 | evt_dir = fdopendir(dfd); |
| 179 | if (!evt_dir) { |
| 180 | close(dfd); |
| 181 | continue; |
| 182 | } |
| 183 | evt_dir_fd = dirfd(evt_dir); |
| 184 | for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { |
| 185 | snprintf(evt_path, MAXPATHLEN, "%s/id", |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 186 | evt_dirent.d_name); |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame^] | 187 | fd = openat(evt_dir_fd, evt_path, O_RDONLY); |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 188 | if (fd < 0) |
| 189 | continue; |
| 190 | if (read(fd, id_buf, sizeof(id_buf)) < 0) { |
| 191 | close(fd); |
| 192 | continue; |
| 193 | } |
| 194 | close(fd); |
| 195 | id = atoll(id_buf); |
| 196 | if (id == config) { |
| 197 | closedir(evt_dir); |
| 198 | closedir(sys_dir); |
Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 199 | path = calloc(1, sizeof(path)); |
| 200 | path->system = malloc(MAX_EVENT_LENGTH); |
| 201 | if (!path->system) { |
| 202 | free(path); |
| 203 | return NULL; |
| 204 | } |
| 205 | path->name = malloc(MAX_EVENT_LENGTH); |
| 206 | if (!path->name) { |
| 207 | free(path->system); |
| 208 | free(path); |
| 209 | return NULL; |
| 210 | } |
| 211 | strncpy(path->system, sys_dirent.d_name, |
| 212 | MAX_EVENT_LENGTH); |
| 213 | strncpy(path->name, evt_dirent.d_name, |
| 214 | MAX_EVENT_LENGTH); |
| 215 | return path; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | closedir(evt_dir); |
| 219 | } |
| 220 | |
| 221 | cleanup: |
| 222 | closedir(sys_dir); |
Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 223 | return NULL; |
| 224 | } |
| 225 | |
| 226 | #define TP_PATH_LEN (MAX_EVENT_LENGTH * 2 + 1) |
| 227 | static const char *tracepoint_id_to_name(u64 config) |
| 228 | { |
| 229 | static char buf[TP_PATH_LEN]; |
| 230 | struct tracepoint_path *path; |
| 231 | |
| 232 | path = tracepoint_id_to_path(config); |
| 233 | if (path) { |
| 234 | snprintf(buf, TP_PATH_LEN, "%s:%s", path->system, path->name); |
| 235 | free(path->name); |
| 236 | free(path->system); |
| 237 | free(path); |
| 238 | } else |
| 239 | snprintf(buf, TP_PATH_LEN, "%s:%s", "unknown", "unknown"); |
| 240 | |
| 241 | return buf; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 242 | } |
| 243 | |
Jaswinder Singh Rajput | 06813f6 | 2009-06-25 17:16:07 +0530 | [diff] [blame] | 244 | static int is_cache_op_valid(u8 cache_type, u8 cache_op) |
| 245 | { |
| 246 | if (hw_cache_stat[cache_type] & COP(cache_op)) |
| 247 | return 1; /* valid */ |
| 248 | else |
| 249 | return 0; /* invalid */ |
| 250 | } |
| 251 | |
Jaswinder Singh Rajput | e5c5954 | 2009-06-25 18:25:22 +0530 | [diff] [blame] | 252 | static char *event_cache_name(u8 cache_type, u8 cache_op, u8 cache_result) |
| 253 | { |
| 254 | static char name[50]; |
| 255 | |
| 256 | if (cache_result) { |
| 257 | sprintf(name, "%s-%s-%s", hw_cache[cache_type][0], |
| 258 | hw_cache_op[cache_op][0], |
| 259 | hw_cache_result[cache_result][0]); |
| 260 | } else { |
| 261 | sprintf(name, "%s-%s", hw_cache[cache_type][0], |
| 262 | hw_cache_op[cache_op][1]); |
| 263 | } |
| 264 | |
| 265 | return name; |
| 266 | } |
| 267 | |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 268 | const char *event_name(int counter) |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 269 | { |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 270 | u64 config = attrs[counter].config; |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 271 | int type = attrs[counter].type; |
Peter Zijlstra | 8f18aec | 2009-08-06 19:40:28 +0200 | [diff] [blame] | 272 | |
| 273 | return __event_name(type, config); |
| 274 | } |
| 275 | |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 276 | const char *__event_name(int type, u64 config) |
Peter Zijlstra | 8f18aec | 2009-08-06 19:40:28 +0200 | [diff] [blame] | 277 | { |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 278 | static char buf[32]; |
| 279 | |
Peter Zijlstra | 8f18aec | 2009-08-06 19:40:28 +0200 | [diff] [blame] | 280 | if (type == PERF_TYPE_RAW) { |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 281 | sprintf(buf, "raw 0x%llx", config); |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 282 | return buf; |
| 283 | } |
| 284 | |
| 285 | switch (type) { |
| 286 | case PERF_TYPE_HARDWARE: |
Peter Zijlstra | f4dbfa8 | 2009-06-11 14:06:28 +0200 | [diff] [blame] | 287 | if (config < PERF_COUNT_HW_MAX) |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 288 | return hw_event_names[config]; |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 289 | return "unknown-hardware"; |
| 290 | |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 291 | case PERF_TYPE_HW_CACHE: { |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 292 | u8 cache_type, cache_op, cache_result; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 293 | |
| 294 | cache_type = (config >> 0) & 0xff; |
| 295 | if (cache_type > PERF_COUNT_HW_CACHE_MAX) |
| 296 | return "unknown-ext-hardware-cache-type"; |
| 297 | |
| 298 | cache_op = (config >> 8) & 0xff; |
Ingo Molnar | 8faf3b5 | 2009-06-06 13:58:12 +0200 | [diff] [blame] | 299 | if (cache_op > PERF_COUNT_HW_CACHE_OP_MAX) |
| 300 | return "unknown-ext-hardware-cache-op"; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 301 | |
| 302 | cache_result = (config >> 16) & 0xff; |
Ingo Molnar | 8faf3b5 | 2009-06-06 13:58:12 +0200 | [diff] [blame] | 303 | if (cache_result > PERF_COUNT_HW_CACHE_RESULT_MAX) |
| 304 | return "unknown-ext-hardware-cache-result"; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 305 | |
Jaswinder Singh Rajput | 06813f6 | 2009-06-25 17:16:07 +0530 | [diff] [blame] | 306 | if (!is_cache_op_valid(cache_type, cache_op)) |
| 307 | return "invalid-cache"; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 308 | |
Jaswinder Singh Rajput | e5c5954 | 2009-06-25 18:25:22 +0530 | [diff] [blame] | 309 | return event_cache_name(cache_type, cache_op, cache_result); |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 310 | } |
| 311 | |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 312 | case PERF_TYPE_SOFTWARE: |
Peter Zijlstra | f4dbfa8 | 2009-06-11 14:06:28 +0200 | [diff] [blame] | 313 | if (config < PERF_COUNT_SW_MAX) |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 314 | return sw_event_names[config]; |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 315 | return "unknown-software"; |
| 316 | |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 317 | case PERF_TYPE_TRACEPOINT: |
| 318 | return tracepoint_id_to_name(config); |
| 319 | |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 320 | default: |
| 321 | break; |
| 322 | } |
| 323 | |
| 324 | return "unknown"; |
| 325 | } |
| 326 | |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 327 | 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] | 328 | { |
| 329 | int i, j; |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 330 | int n, longest = -1; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 331 | |
| 332 | for (i = 0; i < size; i++) { |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 333 | for (j = 0; j < MAX_ALIASES && names[i][j]; j++) { |
| 334 | n = strlen(names[i][j]); |
| 335 | if (n > longest && !strncasecmp(*str, names[i][j], n)) |
| 336 | longest = n; |
| 337 | } |
| 338 | if (longest > 0) { |
| 339 | *str += longest; |
| 340 | return i; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | |
Ingo Molnar | 8953645 | 2009-06-06 21:04:17 +0200 | [diff] [blame] | 344 | return -1; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 345 | } |
| 346 | |
Jaswinder Singh Rajput | c0c22db | 2009-06-22 20:47:26 +0530 | [diff] [blame] | 347 | static int |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 348 | parse_generic_hw_event(const char **str, struct perf_counter_attr *attr) |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 349 | { |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 350 | const char *s = *str; |
| 351 | int cache_type = -1, cache_op = -1, cache_result = -1; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 352 | |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 353 | cache_type = parse_aliases(&s, hw_cache, PERF_COUNT_HW_CACHE_MAX); |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 354 | /* |
| 355 | * No fallback - if we cannot get a clear cache type |
| 356 | * then bail out: |
| 357 | */ |
| 358 | if (cache_type == -1) |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 359 | return 0; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 360 | |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 361 | while ((cache_op == -1 || cache_result == -1) && *s == '-') { |
| 362 | ++s; |
| 363 | |
| 364 | if (cache_op == -1) { |
| 365 | cache_op = parse_aliases(&s, hw_cache_op, |
| 366 | PERF_COUNT_HW_CACHE_OP_MAX); |
| 367 | if (cache_op >= 0) { |
| 368 | if (!is_cache_op_valid(cache_type, cache_op)) |
| 369 | return 0; |
| 370 | continue; |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | if (cache_result == -1) { |
| 375 | cache_result = parse_aliases(&s, hw_cache_result, |
| 376 | PERF_COUNT_HW_CACHE_RESULT_MAX); |
| 377 | if (cache_result >= 0) |
| 378 | continue; |
| 379 | } |
| 380 | |
| 381 | /* |
| 382 | * Can't parse this as a cache op or result, so back up |
| 383 | * to the '-'. |
| 384 | */ |
| 385 | --s; |
| 386 | break; |
| 387 | } |
| 388 | |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 389 | /* |
| 390 | * Fall back to reads: |
| 391 | */ |
Ingo Molnar | 8953645 | 2009-06-06 21:04:17 +0200 | [diff] [blame] | 392 | if (cache_op == -1) |
| 393 | cache_op = PERF_COUNT_HW_CACHE_OP_READ; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 394 | |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 395 | /* |
| 396 | * Fall back to accesses: |
| 397 | */ |
| 398 | if (cache_result == -1) |
| 399 | cache_result = PERF_COUNT_HW_CACHE_RESULT_ACCESS; |
| 400 | |
| 401 | attr->config = cache_type | (cache_op << 8) | (cache_result << 16); |
| 402 | attr->type = PERF_TYPE_HW_CACHE; |
| 403 | |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 404 | *str = s; |
| 405 | return 1; |
Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 406 | } |
| 407 | |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 408 | static int parse_tracepoint_event(const char **strp, |
| 409 | struct perf_counter_attr *attr) |
| 410 | { |
| 411 | const char *evt_name; |
Frederic Weisbecker | 3a9f131 | 2009-08-13 10:27:18 +0200 | [diff] [blame] | 412 | char *flags; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 413 | char sys_name[MAX_EVENT_LENGTH]; |
| 414 | char id_buf[4]; |
| 415 | int fd; |
| 416 | unsigned int sys_length, evt_length; |
| 417 | u64 id; |
| 418 | char evt_path[MAXPATHLEN]; |
| 419 | |
Jason Baron | 5beeded | 2009-07-21 14:16:29 -0400 | [diff] [blame] | 420 | if (valid_debugfs_mount(debugfs_path)) |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 421 | return 0; |
| 422 | |
| 423 | evt_name = strchr(*strp, ':'); |
| 424 | if (!evt_name) |
| 425 | return 0; |
| 426 | |
| 427 | sys_length = evt_name - *strp; |
| 428 | if (sys_length >= MAX_EVENT_LENGTH) |
| 429 | return 0; |
| 430 | |
| 431 | strncpy(sys_name, *strp, sys_length); |
| 432 | sys_name[sys_length] = '\0'; |
| 433 | evt_name = evt_name + 1; |
Frederic Weisbecker | 3a9f131 | 2009-08-13 10:27:18 +0200 | [diff] [blame] | 434 | |
| 435 | flags = strchr(evt_name, ':'); |
| 436 | if (flags) { |
| 437 | *flags = '\0'; |
| 438 | flags++; |
| 439 | if (!strncmp(flags, "record", strlen(flags))) |
| 440 | attr->sample_type |= PERF_SAMPLE_RAW; |
| 441 | } |
| 442 | |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 443 | evt_length = strlen(evt_name); |
| 444 | if (evt_length >= MAX_EVENT_LENGTH) |
| 445 | return 0; |
| 446 | |
Jason Baron | 5beeded | 2009-07-21 14:16:29 -0400 | [diff] [blame] | 447 | snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", debugfs_path, |
| 448 | sys_name, evt_name); |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 449 | fd = open(evt_path, O_RDONLY); |
| 450 | if (fd < 0) |
| 451 | return 0; |
| 452 | |
| 453 | if (read(fd, id_buf, sizeof(id_buf)) < 0) { |
| 454 | close(fd); |
| 455 | return 0; |
| 456 | } |
| 457 | close(fd); |
| 458 | id = atoll(id_buf); |
| 459 | attr->config = id; |
| 460 | attr->type = PERF_TYPE_TRACEPOINT; |
| 461 | *strp = evt_name + evt_length; |
| 462 | return 1; |
| 463 | } |
| 464 | |
Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 465 | static int check_events(const char *str, unsigned int i) |
| 466 | { |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 467 | int n; |
Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 468 | |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 469 | n = strlen(event_symbols[i].symbol); |
| 470 | if (!strncmp(str, event_symbols[i].symbol, n)) |
| 471 | return n; |
| 472 | |
| 473 | n = strlen(event_symbols[i].alias); |
| 474 | if (n) |
| 475 | if (!strncmp(str, event_symbols[i].alias, n)) |
| 476 | return n; |
| 477 | return 0; |
| 478 | } |
| 479 | |
| 480 | static int |
| 481 | parse_symbolic_event(const char **strp, struct perf_counter_attr *attr) |
| 482 | { |
| 483 | const char *str = *strp; |
| 484 | unsigned int i; |
| 485 | int n; |
| 486 | |
| 487 | for (i = 0; i < ARRAY_SIZE(event_symbols); i++) { |
| 488 | n = check_events(str, i); |
| 489 | if (n > 0) { |
| 490 | attr->type = event_symbols[i].type; |
| 491 | attr->config = event_symbols[i].config; |
| 492 | *strp = str + n; |
Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 493 | return 1; |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 494 | } |
| 495 | } |
| 496 | return 0; |
| 497 | } |
| 498 | |
| 499 | static int parse_raw_event(const char **strp, struct perf_counter_attr *attr) |
| 500 | { |
| 501 | const char *str = *strp; |
| 502 | u64 config; |
| 503 | int n; |
| 504 | |
| 505 | if (*str != 'r') |
| 506 | return 0; |
| 507 | n = hex2u64(str + 1, &config); |
| 508 | if (n > 0) { |
| 509 | *strp = str + n + 1; |
| 510 | attr->type = PERF_TYPE_RAW; |
| 511 | attr->config = config; |
| 512 | return 1; |
| 513 | } |
| 514 | return 0; |
| 515 | } |
| 516 | |
| 517 | static int |
| 518 | parse_numeric_event(const char **strp, struct perf_counter_attr *attr) |
| 519 | { |
| 520 | const char *str = *strp; |
| 521 | char *endp; |
| 522 | unsigned long type; |
| 523 | u64 config; |
| 524 | |
| 525 | type = strtoul(str, &endp, 0); |
| 526 | if (endp > str && type < PERF_TYPE_MAX && *endp == ':') { |
| 527 | str = endp + 1; |
| 528 | config = strtoul(str, &endp, 0); |
| 529 | if (endp > str) { |
| 530 | attr->type = type; |
| 531 | attr->config = config; |
| 532 | *strp = endp; |
| 533 | return 1; |
| 534 | } |
| 535 | } |
| 536 | return 0; |
| 537 | } |
| 538 | |
| 539 | static int |
| 540 | parse_event_modifier(const char **strp, struct perf_counter_attr *attr) |
| 541 | { |
| 542 | const char *str = *strp; |
| 543 | int eu = 1, ek = 1, eh = 1; |
| 544 | |
| 545 | if (*str++ != ':') |
| 546 | return 0; |
| 547 | while (*str) { |
| 548 | if (*str == 'u') |
| 549 | eu = 0; |
| 550 | else if (*str == 'k') |
| 551 | ek = 0; |
| 552 | else if (*str == 'h') |
| 553 | eh = 0; |
| 554 | else |
| 555 | break; |
| 556 | ++str; |
| 557 | } |
| 558 | if (str >= *strp + 2) { |
| 559 | *strp = str; |
| 560 | attr->exclude_user = eu; |
| 561 | attr->exclude_kernel = ek; |
| 562 | attr->exclude_hv = eh; |
| 563 | return 1; |
| 564 | } |
Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 565 | return 0; |
| 566 | } |
| 567 | |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 568 | /* |
| 569 | * Each event can have multiple symbolic names. |
| 570 | * Symbolic names are (almost) exactly matched. |
| 571 | */ |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 572 | static int parse_event_symbols(const char **str, struct perf_counter_attr *attr) |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 573 | { |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 574 | if (!(parse_tracepoint_event(str, attr) || |
| 575 | parse_raw_event(str, attr) || |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 576 | parse_numeric_event(str, attr) || |
| 577 | parse_symbolic_event(str, attr) || |
| 578 | parse_generic_hw_event(str, attr))) |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 579 | return 0; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 580 | |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 581 | parse_event_modifier(str, attr); |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 582 | |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 583 | return 1; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 584 | } |
| 585 | |
Ingo Molnar | f37a291 | 2009-07-01 12:37:06 +0200 | [diff] [blame] | 586 | 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] | 587 | { |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 588 | struct perf_counter_attr attr; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 589 | |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 590 | for (;;) { |
| 591 | if (nr_counters == MAX_COUNTERS) |
| 592 | return -1; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 593 | |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 594 | memset(&attr, 0, sizeof(attr)); |
| 595 | if (!parse_event_symbols(&str, &attr)) |
| 596 | return -1; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 597 | |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 598 | if (!(*str == 0 || *str == ',' || isspace(*str))) |
| 599 | return -1; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 600 | |
Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 601 | attrs[nr_counters] = attr; |
| 602 | nr_counters++; |
| 603 | |
| 604 | if (*str == 0) |
| 605 | break; |
| 606 | if (*str == ',') |
| 607 | ++str; |
| 608 | while (isspace(*str)) |
| 609 | ++str; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | return 0; |
| 613 | } |
| 614 | |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 615 | static const char * const event_type_descriptors[] = { |
| 616 | "", |
| 617 | "Hardware event", |
| 618 | "Software event", |
| 619 | "Tracepoint event", |
| 620 | "Hardware cache event", |
| 621 | }; |
| 622 | |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 623 | /* |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 624 | * Print the events from <debugfs_mount_point>/tracing/events |
| 625 | */ |
| 626 | |
| 627 | static void print_tracepoint_events(void) |
| 628 | { |
| 629 | DIR *sys_dir, *evt_dir; |
| 630 | struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame^] | 631 | int sys_dir_fd; |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 632 | char evt_path[MAXPATHLEN]; |
| 633 | |
Jason Baron | 5beeded | 2009-07-21 14:16:29 -0400 | [diff] [blame] | 634 | if (valid_debugfs_mount(debugfs_path)) |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 635 | return; |
| 636 | |
Jason Baron | 5beeded | 2009-07-21 14:16:29 -0400 | [diff] [blame] | 637 | sys_dir = opendir(debugfs_path); |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 638 | if (!sys_dir) |
| 639 | goto cleanup; |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame^] | 640 | sys_dir_fd = dirfd(sys_dir); |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 641 | |
Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame^] | 642 | for_each_subsystem(sys_dir, sys_dirent, sys_next) { |
| 643 | int dfd = openat(sys_dir_fd, sys_dirent.d_name, |
| 644 | O_RDONLY|O_DIRECTORY), evt_dir_fd; |
| 645 | if (dfd == -1) |
| 646 | continue; |
| 647 | evt_dir = fdopendir(dfd); |
| 648 | if (!evt_dir) { |
| 649 | close(dfd); |
| 650 | continue; |
| 651 | } |
| 652 | evt_dir_fd = dirfd(evt_dir); |
| 653 | for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 654 | snprintf(evt_path, MAXPATHLEN, "%s:%s", |
| 655 | sys_dirent.d_name, evt_dirent.d_name); |
| 656 | fprintf(stderr, " %-40s [%s]\n", evt_path, |
| 657 | event_type_descriptors[PERF_TYPE_TRACEPOINT+1]); |
| 658 | } |
| 659 | closedir(evt_dir); |
| 660 | } |
| 661 | |
| 662 | cleanup: |
| 663 | closedir(sys_dir); |
| 664 | } |
| 665 | |
| 666 | /* |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 667 | * Print the help text for the event symbols: |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 668 | */ |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 669 | void print_events(void) |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 670 | { |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 671 | struct event_symbol *syms = event_symbols; |
Jaswinder Singh Rajput | 73c24cb | 2009-07-01 18:36:18 +0530 | [diff] [blame] | 672 | unsigned int i, type, op, prev_type = -1; |
Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 673 | char name[40]; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 674 | |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 675 | fprintf(stderr, "\n"); |
| 676 | fprintf(stderr, "List of pre-defined events (to be used in -e):\n"); |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 677 | |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 678 | for (i = 0; i < ARRAY_SIZE(event_symbols); i++, syms++) { |
| 679 | type = syms->type + 1; |
Roel Kluin | 23cdb5d | 2009-07-13 02:25:47 +0200 | [diff] [blame] | 680 | if (type >= ARRAY_SIZE(event_type_descriptors)) |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 681 | type = 0; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 682 | |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 683 | if (type != prev_type) |
| 684 | fprintf(stderr, "\n"); |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 685 | |
Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 686 | if (strlen(syms->alias)) |
| 687 | sprintf(name, "%s OR %s", syms->symbol, syms->alias); |
| 688 | else |
| 689 | strcpy(name, syms->symbol); |
| 690 | fprintf(stderr, " %-40s [%s]\n", name, |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 691 | event_type_descriptors[type]); |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 692 | |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 693 | prev_type = type; |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 694 | } |
| 695 | |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 696 | fprintf(stderr, "\n"); |
Jaswinder Singh Rajput | 73c24cb | 2009-07-01 18:36:18 +0530 | [diff] [blame] | 697 | for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) { |
| 698 | for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) { |
| 699 | /* skip invalid cache type */ |
| 700 | if (!is_cache_op_valid(type, op)) |
| 701 | continue; |
| 702 | |
| 703 | for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) { |
| 704 | fprintf(stderr, " %-40s [%s]\n", |
| 705 | event_cache_name(type, op, i), |
| 706 | event_type_descriptors[4]); |
| 707 | } |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | fprintf(stderr, "\n"); |
Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 712 | fprintf(stderr, " %-40s [raw hardware event descriptor]\n", |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 713 | "rNNN"); |
| 714 | fprintf(stderr, "\n"); |
| 715 | |
Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 716 | print_tracepoint_events(); |
| 717 | |
Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 718 | exit(129); |
Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 719 | } |