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