diff options
Diffstat (limited to 'tools/perf/util/parse-events.c')
-rw-r--r-- | tools/perf/util/parse-events.c | 153 |
1 files changed, 105 insertions, 48 deletions
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 35d04da38d6a..4d042f104cdc 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c | |||
@@ -16,32 +16,28 @@ struct event_symbol { | |||
16 | u8 type; | 16 | u8 type; |
17 | u64 config; | 17 | u64 config; |
18 | char *symbol; | 18 | char *symbol; |
19 | char *alias; | ||
19 | }; | 20 | }; |
20 | 21 | ||
21 | #define C(x, y) .type = PERF_TYPE_##x, .config = PERF_COUNT_##y | 22 | #define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x |
22 | #define CR(x, y) .type = PERF_TYPE_##x, .config = y | 23 | #define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x |
23 | 24 | ||
24 | static struct event_symbol event_symbols[] = { | 25 | static struct event_symbol event_symbols[] = { |
25 | { C(HARDWARE, HW_CPU_CYCLES), "cpu-cycles", }, | 26 | { CHW(CPU_CYCLES), "cpu-cycles", "cycles" }, |
26 | { C(HARDWARE, HW_CPU_CYCLES), "cycles", }, | 27 | { CHW(INSTRUCTIONS), "instructions", "" }, |
27 | { C(HARDWARE, HW_INSTRUCTIONS), "instructions", }, | 28 | { CHW(CACHE_REFERENCES), "cache-references", "" }, |
28 | { C(HARDWARE, HW_CACHE_REFERENCES), "cache-references", }, | 29 | { CHW(CACHE_MISSES), "cache-misses", "" }, |
29 | { C(HARDWARE, HW_CACHE_MISSES), "cache-misses", }, | 30 | { CHW(BRANCH_INSTRUCTIONS), "branch-instructions", "branches" }, |
30 | { C(HARDWARE, HW_BRANCH_INSTRUCTIONS),"branch-instructions", }, | 31 | { CHW(BRANCH_MISSES), "branch-misses", "" }, |
31 | { C(HARDWARE, HW_BRANCH_INSTRUCTIONS),"branches", }, | 32 | { CHW(BUS_CYCLES), "bus-cycles", "" }, |
32 | { C(HARDWARE, HW_BRANCH_MISSES), "branch-misses", }, | 33 | |
33 | { C(HARDWARE, HW_BUS_CYCLES), "bus-cycles", }, | 34 | { CSW(CPU_CLOCK), "cpu-clock", "" }, |
34 | 35 | { CSW(TASK_CLOCK), "task-clock", "" }, | |
35 | { C(SOFTWARE, SW_CPU_CLOCK), "cpu-clock", }, | 36 | { CSW(PAGE_FAULTS), "page-faults", "faults" }, |
36 | { C(SOFTWARE, SW_TASK_CLOCK), "task-clock", }, | 37 | { CSW(PAGE_FAULTS_MIN), "minor-faults", "" }, |
37 | { C(SOFTWARE, SW_PAGE_FAULTS), "page-faults", }, | 38 | { CSW(PAGE_FAULTS_MAJ), "major-faults", "" }, |
38 | { C(SOFTWARE, SW_PAGE_FAULTS), "faults", }, | 39 | { CSW(CONTEXT_SWITCHES), "context-switches", "cs" }, |
39 | { C(SOFTWARE, SW_PAGE_FAULTS_MIN), "minor-faults", }, | 40 | { CSW(CPU_MIGRATIONS), "cpu-migrations", "migrations" }, |
40 | { C(SOFTWARE, SW_PAGE_FAULTS_MAJ), "major-faults", }, | ||
41 | { C(SOFTWARE, SW_CONTEXT_SWITCHES), "context-switches", }, | ||
42 | { C(SOFTWARE, SW_CONTEXT_SWITCHES), "cs", }, | ||
43 | { C(SOFTWARE, SW_CPU_MIGRATIONS), "cpu-migrations", }, | ||
44 | { C(SOFTWARE, SW_CPU_MIGRATIONS), "migrations", }, | ||
45 | }; | 41 | }; |
46 | 42 | ||
47 | #define __PERF_COUNTER_FIELD(config, name) \ | 43 | #define __PERF_COUNTER_FIELD(config, name) \ |
@@ -74,26 +70,70 @@ static char *sw_event_names[] = { | |||
74 | 70 | ||
75 | #define MAX_ALIASES 8 | 71 | #define MAX_ALIASES 8 |
76 | 72 | ||
77 | static char *hw_cache [][MAX_ALIASES] = { | 73 | static char *hw_cache[][MAX_ALIASES] = { |
78 | { "L1-data" , "l1-d", "l1d" }, | 74 | { "L1-d$", "l1-d", "l1d", "L1-data", }, |
79 | { "L1-instruction" , "l1-i", "l1i" }, | 75 | { "L1-i$", "l1-i", "l1i", "L1-instruction", }, |
80 | { "L2" , "l2" }, | 76 | { "LLC", "L2" }, |
81 | { "Data-TLB" , "dtlb", "d-tlb" }, | 77 | { "dTLB", "d-tlb", "Data-TLB", }, |
82 | { "Instruction-TLB" , "itlb", "i-tlb" }, | 78 | { "iTLB", "i-tlb", "Instruction-TLB", }, |
83 | { "Branch" , "bpu" , "btb", "bpc" }, | 79 | { "branch", "branches", "bpu", "btb", "bpc", }, |
84 | }; | 80 | }; |
85 | 81 | ||
86 | static char *hw_cache_op [][MAX_ALIASES] = { | 82 | static char *hw_cache_op[][MAX_ALIASES] = { |
87 | { "Load" , "read" }, | 83 | { "load", "loads", "read", }, |
88 | { "Store" , "write" }, | 84 | { "store", "stores", "write", }, |
89 | { "Prefetch" , "speculative-read", "speculative-load" }, | 85 | { "prefetch", "prefetches", "speculative-read", "speculative-load", }, |
90 | }; | 86 | }; |
91 | 87 | ||
92 | static char *hw_cache_result [][MAX_ALIASES] = { | 88 | static char *hw_cache_result[][MAX_ALIASES] = { |
93 | { "Reference" , "ops", "access" }, | 89 | { "refs", "Reference", "ops", "access", }, |
94 | { "Miss" }, | 90 | { "misses", "miss", }, |
95 | }; | 91 | }; |
96 | 92 | ||
93 | #define C(x) PERF_COUNT_HW_CACHE_##x | ||
94 | #define CACHE_READ (1 << C(OP_READ)) | ||
95 | #define CACHE_WRITE (1 << C(OP_WRITE)) | ||
96 | #define CACHE_PREFETCH (1 << C(OP_PREFETCH)) | ||
97 | #define COP(x) (1 << x) | ||
98 | |||
99 | /* | ||
100 | * cache operartion stat | ||
101 | * L1I : Read and prefetch only | ||
102 | * ITLB and BPU : Read-only | ||
103 | */ | ||
104 | static unsigned long hw_cache_stat[C(MAX)] = { | ||
105 | [C(L1D)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), | ||
106 | [C(L1I)] = (CACHE_READ | CACHE_PREFETCH), | ||
107 | [C(LL)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), | ||
108 | [C(DTLB)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), | ||
109 | [C(ITLB)] = (CACHE_READ), | ||
110 | [C(BPU)] = (CACHE_READ), | ||
111 | }; | ||
112 | |||
113 | static int is_cache_op_valid(u8 cache_type, u8 cache_op) | ||
114 | { | ||
115 | if (hw_cache_stat[cache_type] & COP(cache_op)) | ||
116 | return 1; /* valid */ | ||
117 | else | ||
118 | return 0; /* invalid */ | ||
119 | } | ||
120 | |||
121 | static char *event_cache_name(u8 cache_type, u8 cache_op, u8 cache_result) | ||
122 | { | ||
123 | static char name[50]; | ||
124 | |||
125 | if (cache_result) { | ||
126 | sprintf(name, "%s-%s-%s", hw_cache[cache_type][0], | ||
127 | hw_cache_op[cache_op][0], | ||
128 | hw_cache_result[cache_result][0]); | ||
129 | } else { | ||
130 | sprintf(name, "%s-%s", hw_cache[cache_type][0], | ||
131 | hw_cache_op[cache_op][1]); | ||
132 | } | ||
133 | |||
134 | return name; | ||
135 | } | ||
136 | |||
97 | char *event_name(int counter) | 137 | char *event_name(int counter) |
98 | { | 138 | { |
99 | u64 config = attrs[counter].config; | 139 | u64 config = attrs[counter].config; |
@@ -113,7 +153,6 @@ char *event_name(int counter) | |||
113 | 153 | ||
114 | case PERF_TYPE_HW_CACHE: { | 154 | case PERF_TYPE_HW_CACHE: { |
115 | u8 cache_type, cache_op, cache_result; | 155 | u8 cache_type, cache_op, cache_result; |
116 | static char name[100]; | ||
117 | 156 | ||
118 | cache_type = (config >> 0) & 0xff; | 157 | cache_type = (config >> 0) & 0xff; |
119 | if (cache_type > PERF_COUNT_HW_CACHE_MAX) | 158 | if (cache_type > PERF_COUNT_HW_CACHE_MAX) |
@@ -127,12 +166,10 @@ char *event_name(int counter) | |||
127 | if (cache_result > PERF_COUNT_HW_CACHE_RESULT_MAX) | 166 | if (cache_result > PERF_COUNT_HW_CACHE_RESULT_MAX) |
128 | return "unknown-ext-hardware-cache-result"; | 167 | return "unknown-ext-hardware-cache-result"; |
129 | 168 | ||
130 | sprintf(name, "%s-Cache-%s-%ses", | 169 | if (!is_cache_op_valid(cache_type, cache_op)) |
131 | hw_cache[cache_type][0], | 170 | return "invalid-cache"; |
132 | hw_cache_op[cache_op][0], | ||
133 | hw_cache_result[cache_result][0]); | ||
134 | 171 | ||
135 | return name; | 172 | return event_cache_name(cache_type, cache_op, cache_result); |
136 | } | 173 | } |
137 | 174 | ||
138 | case PERF_TYPE_SOFTWARE: | 175 | case PERF_TYPE_SOFTWARE: |
@@ -163,7 +200,8 @@ static int parse_aliases(const char *str, char *names[][MAX_ALIASES], int size) | |||
163 | return -1; | 200 | return -1; |
164 | } | 201 | } |
165 | 202 | ||
166 | static int parse_generic_hw_symbols(const char *str, struct perf_counter_attr *attr) | 203 | static int |
204 | parse_generic_hw_symbols(const char *str, struct perf_counter_attr *attr) | ||
167 | { | 205 | { |
168 | int cache_type = -1, cache_op = 0, cache_result = 0; | 206 | int cache_type = -1, cache_op = 0, cache_result = 0; |
169 | 207 | ||
@@ -182,6 +220,9 @@ static int parse_generic_hw_symbols(const char *str, struct perf_counter_attr *a | |||
182 | if (cache_op == -1) | 220 | if (cache_op == -1) |
183 | cache_op = PERF_COUNT_HW_CACHE_OP_READ; | 221 | cache_op = PERF_COUNT_HW_CACHE_OP_READ; |
184 | 222 | ||
223 | if (!is_cache_op_valid(cache_type, cache_op)) | ||
224 | return -EINVAL; | ||
225 | |||
185 | cache_result = parse_aliases(str, hw_cache_result, | 226 | cache_result = parse_aliases(str, hw_cache_result, |
186 | PERF_COUNT_HW_CACHE_RESULT_MAX); | 227 | PERF_COUNT_HW_CACHE_RESULT_MAX); |
187 | /* | 228 | /* |
@@ -196,6 +237,19 @@ static int parse_generic_hw_symbols(const char *str, struct perf_counter_attr *a | |||
196 | return 0; | 237 | return 0; |
197 | } | 238 | } |
198 | 239 | ||
240 | static int check_events(const char *str, unsigned int i) | ||
241 | { | ||
242 | if (!strncmp(str, event_symbols[i].symbol, | ||
243 | strlen(event_symbols[i].symbol))) | ||
244 | return 1; | ||
245 | |||
246 | if (strlen(event_symbols[i].alias)) | ||
247 | if (!strncmp(str, event_symbols[i].alias, | ||
248 | strlen(event_symbols[i].alias))) | ||
249 | return 1; | ||
250 | return 0; | ||
251 | } | ||
252 | |||
199 | /* | 253 | /* |
200 | * Each event can have multiple symbolic names. | 254 | * Each event can have multiple symbolic names. |
201 | * Symbolic names are (almost) exactly matched. | 255 | * Symbolic names are (almost) exactly matched. |
@@ -235,9 +289,7 @@ static int parse_event_symbols(const char *str, struct perf_counter_attr *attr) | |||
235 | } | 289 | } |
236 | 290 | ||
237 | for (i = 0; i < ARRAY_SIZE(event_symbols); i++) { | 291 | for (i = 0; i < ARRAY_SIZE(event_symbols); i++) { |
238 | if (!strncmp(str, event_symbols[i].symbol, | 292 | if (check_events(str, i)) { |
239 | strlen(event_symbols[i].symbol))) { | ||
240 | |||
241 | attr->type = event_symbols[i].type; | 293 | attr->type = event_symbols[i].type; |
242 | attr->config = event_symbols[i].config; | 294 | attr->config = event_symbols[i].config; |
243 | 295 | ||
@@ -289,6 +341,7 @@ void print_events(void) | |||
289 | { | 341 | { |
290 | struct event_symbol *syms = event_symbols; | 342 | struct event_symbol *syms = event_symbols; |
291 | unsigned int i, type, prev_type = -1; | 343 | unsigned int i, type, prev_type = -1; |
344 | char name[40]; | ||
292 | 345 | ||
293 | fprintf(stderr, "\n"); | 346 | fprintf(stderr, "\n"); |
294 | fprintf(stderr, "List of pre-defined events (to be used in -e):\n"); | 347 | fprintf(stderr, "List of pre-defined events (to be used in -e):\n"); |
@@ -301,14 +354,18 @@ void print_events(void) | |||
301 | if (type != prev_type) | 354 | if (type != prev_type) |
302 | fprintf(stderr, "\n"); | 355 | fprintf(stderr, "\n"); |
303 | 356 | ||
304 | fprintf(stderr, " %-30s [%s]\n", syms->symbol, | 357 | if (strlen(syms->alias)) |
358 | sprintf(name, "%s OR %s", syms->symbol, syms->alias); | ||
359 | else | ||
360 | strcpy(name, syms->symbol); | ||
361 | fprintf(stderr, " %-40s [%s]\n", name, | ||
305 | event_type_descriptors[type]); | 362 | event_type_descriptors[type]); |
306 | 363 | ||
307 | prev_type = type; | 364 | prev_type = type; |
308 | } | 365 | } |
309 | 366 | ||
310 | fprintf(stderr, "\n"); | 367 | fprintf(stderr, "\n"); |
311 | fprintf(stderr, " %-30s [raw hardware event descriptor]\n", | 368 | fprintf(stderr, " %-40s [raw hardware event descriptor]\n", |
312 | "rNNN"); | 369 | "rNNN"); |
313 | fprintf(stderr, "\n"); | 370 | fprintf(stderr, "\n"); |
314 | 371 | ||