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