]>
Commit | Line | Data |
---|---|---|
bf9e1876 IM |
1 | /* |
2 | * builtin-report.c | |
3 | * | |
4 | * Builtin report command: Analyze the perf.data input file, | |
5 | * look up and read DSOs and symbol information and display | |
6 | * a histogram of results, along various sorting keys. | |
7 | */ | |
16f762a2 | 8 | #include "builtin.h" |
53cb8bc2 | 9 | |
bf9e1876 IM |
10 | #include "util/util.h" |
11 | ||
8fc0321f | 12 | #include "util/color.h" |
5da50258 | 13 | #include <linux/list.h> |
a930d2c0 | 14 | #include "util/cache.h" |
43cbcd8a | 15 | #include <linux/rbtree.h> |
a2928c42 | 16 | #include "util/symbol.h" |
a0055ae2 | 17 | #include "util/string.h" |
f55c5552 | 18 | #include "util/callchain.h" |
25903407 | 19 | #include "util/strlist.h" |
8d513270 | 20 | #include "util/values.h" |
8fa66bdc | 21 | |
53cb8bc2 | 22 | #include "perf.h" |
8f28827a | 23 | #include "util/debug.h" |
7c6a1c65 | 24 | #include "util/header.h" |
53cb8bc2 IM |
25 | |
26 | #include "util/parse-options.h" | |
27 | #include "util/parse-events.h" | |
28 | ||
016e92fb | 29 | #include "util/data_map.h" |
6baa0a5a | 30 | #include "util/thread.h" |
dd68ada2 | 31 | #include "util/sort.h" |
3d1d07ec | 32 | #include "util/hist.h" |
6baa0a5a | 33 | |
23ac9cbe | 34 | static char const *input_name = "perf.data"; |
bd74137e | 35 | |
52d422de ACM |
36 | static char *dso_list_str, *comm_list_str, *sym_list_str, |
37 | *col_width_list_str; | |
7bec7a91 | 38 | static struct strlist *dso_list, *comm_list, *sym_list; |
bd74137e | 39 | |
fa6963b2 | 40 | static int force; |
6671cb16 | 41 | static bool use_modules; |
8fa66bdc | 42 | |
b78c07d4 | 43 | static int full_paths; |
e3d7e183 | 44 | static int show_nr_samples; |
97b07b69 | 45 | |
8d513270 BG |
46 | static int show_threads; |
47 | static struct perf_read_values show_threads_values; | |
48 | ||
9f866697 BG |
49 | static char default_pretty_printing_style[] = "normal"; |
50 | static char *pretty_printing_style = default_pretty_printing_style; | |
51 | ||
b8e6d829 | 52 | static int exclude_other = 1; |
be903885 | 53 | |
805d127d FW |
54 | static char callchain_default_opt[] = "fractal,0.5"; |
55 | ||
016e92fb | 56 | static char *cwd; |
66e274f3 FW |
57 | static int cwdlen; |
58 | ||
0d3a5c88 FW |
59 | static struct perf_header *header; |
60 | ||
e6e18ec7 PZ |
61 | static u64 sample_type; |
62 | ||
a4fb581b FW |
63 | |
64 | static size_t | |
65 | callchain__fprintf_left_margin(FILE *fp, int left_margin) | |
66 | { | |
67 | int i; | |
68 | int ret; | |
69 | ||
70 | ret = fprintf(fp, " "); | |
71 | ||
72 | for (i = 0; i < left_margin; i++) | |
73 | ret += fprintf(fp, " "); | |
74 | ||
75 | return ret; | |
76 | } | |
77 | ||
78 | static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask, | |
79 | int left_margin) | |
4eb3e478 FW |
80 | { |
81 | int i; | |
82 | size_t ret = 0; | |
83 | ||
a4fb581b | 84 | ret += callchain__fprintf_left_margin(fp, left_margin); |
4eb3e478 FW |
85 | |
86 | for (i = 0; i < depth; i++) | |
87 | if (depth_mask & (1 << i)) | |
88 | ret += fprintf(fp, "| "); | |
89 | else | |
90 | ret += fprintf(fp, " "); | |
91 | ||
92 | ret += fprintf(fp, "\n"); | |
93 | ||
94 | return ret; | |
95 | } | |
f55c5552 | 96 | static size_t |
4eb3e478 FW |
97 | ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain, int depth, |
98 | int depth_mask, int count, u64 total_samples, | |
a4fb581b | 99 | int hits, int left_margin) |
4eb3e478 FW |
100 | { |
101 | int i; | |
102 | size_t ret = 0; | |
103 | ||
a4fb581b | 104 | ret += callchain__fprintf_left_margin(fp, left_margin); |
4eb3e478 FW |
105 | for (i = 0; i < depth; i++) { |
106 | if (depth_mask & (1 << i)) | |
107 | ret += fprintf(fp, "|"); | |
108 | else | |
109 | ret += fprintf(fp, " "); | |
110 | if (!count && i == depth - 1) { | |
111 | double percent; | |
112 | ||
113 | percent = hits * 100.0 / total_samples; | |
24b57c69 | 114 | ret += percent_color_fprintf(fp, "--%2.2f%%-- ", percent); |
4eb3e478 FW |
115 | } else |
116 | ret += fprintf(fp, "%s", " "); | |
117 | } | |
118 | if (chain->sym) | |
119 | ret += fprintf(fp, "%s\n", chain->sym->name); | |
120 | else | |
121 | ret += fprintf(fp, "%p\n", (void *)(long)chain->ip); | |
122 | ||
123 | return ret; | |
124 | } | |
125 | ||
25446036 FW |
126 | static struct symbol *rem_sq_bracket; |
127 | static struct callchain_list rem_hits; | |
128 | ||
129 | static void init_rem_hits(void) | |
130 | { | |
131 | rem_sq_bracket = malloc(sizeof(*rem_sq_bracket) + 6); | |
132 | if (!rem_sq_bracket) { | |
133 | fprintf(stderr, "Not enough memory to display remaining hits\n"); | |
134 | return; | |
135 | } | |
136 | ||
137 | strcpy(rem_sq_bracket->name, "[...]"); | |
138 | rem_hits.sym = rem_sq_bracket; | |
139 | } | |
140 | ||
4eb3e478 | 141 | static size_t |
af0a6fa4 | 142 | __callchain__fprintf_graph(FILE *fp, struct callchain_node *self, |
a4fb581b FW |
143 | u64 total_samples, int depth, int depth_mask, |
144 | int left_margin) | |
4eb3e478 FW |
145 | { |
146 | struct rb_node *node, *next; | |
147 | struct callchain_node *child; | |
148 | struct callchain_list *chain; | |
149 | int new_depth_mask = depth_mask; | |
805d127d | 150 | u64 new_total; |
25446036 | 151 | u64 remaining; |
4eb3e478 FW |
152 | size_t ret = 0; |
153 | int i; | |
154 | ||
805d127d | 155 | if (callchain_param.mode == CHAIN_GRAPH_REL) |
1953287b | 156 | new_total = self->children_hit; |
805d127d FW |
157 | else |
158 | new_total = total_samples; | |
159 | ||
25446036 FW |
160 | remaining = new_total; |
161 | ||
4eb3e478 FW |
162 | node = rb_first(&self->rb_root); |
163 | while (node) { | |
25446036 FW |
164 | u64 cumul; |
165 | ||
4eb3e478 | 166 | child = rb_entry(node, struct callchain_node, rb_node); |
25446036 FW |
167 | cumul = cumul_hits(child); |
168 | remaining -= cumul; | |
4eb3e478 FW |
169 | |
170 | /* | |
171 | * The depth mask manages the output of pipes that show | |
172 | * the depth. We don't want to keep the pipes of the current | |
25446036 FW |
173 | * level for the last child of this depth. |
174 | * Except if we have remaining filtered hits. They will | |
175 | * supersede the last child | |
4eb3e478 FW |
176 | */ |
177 | next = rb_next(node); | |
25446036 | 178 | if (!next && (callchain_param.mode != CHAIN_GRAPH_REL || !remaining)) |
4eb3e478 FW |
179 | new_depth_mask &= ~(1 << (depth - 1)); |
180 | ||
181 | /* | |
182 | * But we keep the older depth mask for the line seperator | |
183 | * to keep the level link until we reach the last child | |
184 | */ | |
a4fb581b FW |
185 | ret += ipchain__fprintf_graph_line(fp, depth, depth_mask, |
186 | left_margin); | |
4eb3e478 FW |
187 | i = 0; |
188 | list_for_each_entry(chain, &child->val, list) { | |
189 | if (chain->ip >= PERF_CONTEXT_MAX) | |
190 | continue; | |
191 | ret += ipchain__fprintf_graph(fp, chain, depth, | |
192 | new_depth_mask, i++, | |
805d127d | 193 | new_total, |
a4fb581b FW |
194 | cumul, |
195 | left_margin); | |
4eb3e478 | 196 | } |
af0a6fa4 FW |
197 | ret += __callchain__fprintf_graph(fp, child, new_total, |
198 | depth + 1, | |
a4fb581b FW |
199 | new_depth_mask | (1 << depth), |
200 | left_margin); | |
4eb3e478 FW |
201 | node = next; |
202 | } | |
203 | ||
25446036 FW |
204 | if (callchain_param.mode == CHAIN_GRAPH_REL && |
205 | remaining && remaining != new_total) { | |
206 | ||
207 | if (!rem_sq_bracket) | |
208 | return ret; | |
209 | ||
210 | new_depth_mask &= ~(1 << (depth - 1)); | |
211 | ||
212 | ret += ipchain__fprintf_graph(fp, &rem_hits, depth, | |
213 | new_depth_mask, 0, new_total, | |
a4fb581b | 214 | remaining, left_margin); |
25446036 FW |
215 | } |
216 | ||
4eb3e478 FW |
217 | return ret; |
218 | } | |
219 | ||
a4fb581b | 220 | |
af0a6fa4 FW |
221 | static size_t |
222 | callchain__fprintf_graph(FILE *fp, struct callchain_node *self, | |
a4fb581b | 223 | u64 total_samples, int left_margin) |
af0a6fa4 FW |
224 | { |
225 | struct callchain_list *chain; | |
a4fb581b | 226 | bool printed = false; |
af0a6fa4 FW |
227 | int i = 0; |
228 | int ret = 0; | |
229 | ||
230 | list_for_each_entry(chain, &self->val, list) { | |
231 | if (chain->ip >= PERF_CONTEXT_MAX) | |
232 | continue; | |
233 | ||
a4fb581b | 234 | if (!i++ && sort__first_dimension == SORT_SYM) |
af0a6fa4 FW |
235 | continue; |
236 | ||
a4fb581b FW |
237 | if (!printed) { |
238 | ret += callchain__fprintf_left_margin(fp, left_margin); | |
239 | ret += fprintf(fp, "|\n"); | |
240 | ret += callchain__fprintf_left_margin(fp, left_margin); | |
241 | ret += fprintf(fp, "---"); | |
242 | ||
243 | left_margin += 3; | |
244 | printed = true; | |
245 | } else | |
246 | ret += callchain__fprintf_left_margin(fp, left_margin); | |
247 | ||
af0a6fa4 | 248 | if (chain->sym) |
a4fb581b | 249 | ret += fprintf(fp, " %s\n", chain->sym->name); |
af0a6fa4 | 250 | else |
a4fb581b | 251 | ret += fprintf(fp, " %p\n", (void *)(long)chain->ip); |
af0a6fa4 FW |
252 | } |
253 | ||
a4fb581b | 254 | ret += __callchain__fprintf_graph(fp, self, total_samples, 1, 1, left_margin); |
af0a6fa4 FW |
255 | |
256 | return ret; | |
257 | } | |
258 | ||
4eb3e478 FW |
259 | static size_t |
260 | callchain__fprintf_flat(FILE *fp, struct callchain_node *self, | |
261 | u64 total_samples) | |
f55c5552 FW |
262 | { |
263 | struct callchain_list *chain; | |
264 | size_t ret = 0; | |
265 | ||
266 | if (!self) | |
267 | return 0; | |
268 | ||
4eb3e478 | 269 | ret += callchain__fprintf_flat(fp, self->parent, total_samples); |
f55c5552 FW |
270 | |
271 | ||
4424961a FW |
272 | list_for_each_entry(chain, &self->val, list) { |
273 | if (chain->ip >= PERF_CONTEXT_MAX) | |
274 | continue; | |
275 | if (chain->sym) | |
276 | ret += fprintf(fp, " %s\n", chain->sym->name); | |
277 | else | |
278 | ret += fprintf(fp, " %p\n", | |
f37a291c | 279 | (void *)(long)chain->ip); |
4424961a | 280 | } |
f55c5552 FW |
281 | |
282 | return ret; | |
283 | } | |
284 | ||
285 | static size_t | |
286 | hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self, | |
a4fb581b | 287 | u64 total_samples, int left_margin) |
f55c5552 FW |
288 | { |
289 | struct rb_node *rb_node; | |
290 | struct callchain_node *chain; | |
291 | size_t ret = 0; | |
292 | ||
293 | rb_node = rb_first(&self->sorted_chain); | |
294 | while (rb_node) { | |
295 | double percent; | |
296 | ||
297 | chain = rb_entry(rb_node, struct callchain_node, rb_node); | |
298 | percent = chain->hit * 100.0 / total_samples; | |
805d127d FW |
299 | switch (callchain_param.mode) { |
300 | case CHAIN_FLAT: | |
24b57c69 FW |
301 | ret += percent_color_fprintf(fp, " %6.2f%%\n", |
302 | percent); | |
4eb3e478 | 303 | ret += callchain__fprintf_flat(fp, chain, total_samples); |
805d127d FW |
304 | break; |
305 | case CHAIN_GRAPH_ABS: /* Falldown */ | |
306 | case CHAIN_GRAPH_REL: | |
a4fb581b FW |
307 | ret += callchain__fprintf_graph(fp, chain, total_samples, |
308 | left_margin); | |
83a0944f | 309 | case CHAIN_NONE: |
805d127d FW |
310 | default: |
311 | break; | |
4eb3e478 | 312 | } |
f55c5552 FW |
313 | ret += fprintf(fp, "\n"); |
314 | rb_node = rb_next(rb_node); | |
315 | } | |
316 | ||
317 | return ret; | |
318 | } | |
319 | ||
1aa16738 | 320 | static size_t |
9cffa8d5 | 321 | hist_entry__fprintf(FILE *fp, struct hist_entry *self, u64 total_samples) |
1aa16738 PZ |
322 | { |
323 | struct sort_entry *se; | |
324 | size_t ret; | |
325 | ||
b8e6d829 IM |
326 | if (exclude_other && !self->parent) |
327 | return 0; | |
328 | ||
1e11fd82 | 329 | if (total_samples) |
52d422de ACM |
330 | ret = percent_color_fprintf(fp, |
331 | field_sep ? "%.2f" : " %6.2f%%", | |
332 | (self->count * 100.0) / total_samples); | |
1e11fd82 | 333 | else |
52d422de | 334 | ret = fprintf(fp, field_sep ? "%lld" : "%12lld ", self->count); |
1aa16738 | 335 | |
e3d7e183 ACM |
336 | if (show_nr_samples) { |
337 | if (field_sep) | |
338 | fprintf(fp, "%c%lld", *field_sep, self->count); | |
339 | else | |
340 | fprintf(fp, "%11lld", self->count); | |
341 | } | |
1aa16738 | 342 | |
71dd8945 | 343 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
021191b3 | 344 | if (se->elide) |
b8e6d829 IM |
345 | continue; |
346 | ||
52d422de ACM |
347 | fprintf(fp, "%s", field_sep ?: " "); |
348 | ret += se->print(fp, self, se->width ? *se->width : 0); | |
71dd8945 | 349 | } |
1aa16738 PZ |
350 | |
351 | ret += fprintf(fp, "\n"); | |
352 | ||
a4fb581b FW |
353 | if (callchain) { |
354 | int left_margin = 0; | |
355 | ||
356 | if (sort__first_dimension == SORT_COMM) { | |
357 | se = list_first_entry(&hist_entry__sort_list, typeof(*se), | |
358 | list); | |
359 | left_margin = se->width ? *se->width : 0; | |
360 | left_margin -= thread__comm_len(self->thread); | |
361 | } | |
362 | ||
363 | hist_entry_callchain__fprintf(fp, self, total_samples, | |
364 | left_margin); | |
365 | } | |
f55c5552 | 366 | |
1aa16738 PZ |
367 | return ret; |
368 | } | |
369 | ||
6e7d6fdc PZ |
370 | /* |
371 | * | |
372 | */ | |
373 | ||
52d422de ACM |
374 | static void dso__calc_col_width(struct dso *self) |
375 | { | |
376 | if (!col_width_list_str && !field_sep && | |
377 | (!dso_list || strlist__has_entry(dso_list, self->name))) { | |
378 | unsigned int slen = strlen(self->name); | |
379 | if (slen > dsos__col_width) | |
380 | dsos__col_width = slen; | |
381 | } | |
382 | ||
383 | self->slen_calculated = 1; | |
384 | } | |
385 | ||
5b447a6a | 386 | static void thread__comm_adjust(struct thread *self) |
4273b005 | 387 | { |
5b447a6a | 388 | char *comm = self->comm; |
4273b005 FW |
389 | |
390 | if (!col_width_list_str && !field_sep && | |
391 | (!comm_list || strlist__has_entry(comm_list, comm))) { | |
392 | unsigned int slen = strlen(comm); | |
393 | ||
394 | if (slen > comms__col_width) { | |
395 | comms__col_width = slen; | |
396 | threads__col_width = slen + 6; | |
397 | } | |
398 | } | |
5b447a6a FW |
399 | } |
400 | ||
401 | static int thread__set_comm_adjust(struct thread *self, const char *comm) | |
402 | { | |
403 | int ret = thread__set_comm(self, comm); | |
404 | ||
405 | if (ret) | |
406 | return ret; | |
407 | ||
408 | thread__comm_adjust(self); | |
4273b005 FW |
409 | |
410 | return 0; | |
411 | } | |
412 | ||
413 | ||
6e7d6fdc | 414 | static struct symbol * |
439d473b | 415 | resolve_symbol(struct thread *thread, struct map **mapp, u64 *ipp) |
6e7d6fdc | 416 | { |
6e7d6fdc | 417 | struct map *map = mapp ? *mapp : NULL; |
520f2c34 | 418 | u64 ip = *ipp; |
6e7d6fdc | 419 | |
6e7d6fdc PZ |
420 | if (map) |
421 | goto got_map; | |
422 | ||
439d473b ACM |
423 | if (!thread) |
424 | return NULL; | |
425 | ||
6e7d6fdc PZ |
426 | map = thread__find_map(thread, ip); |
427 | if (map != NULL) { | |
52d422de ACM |
428 | /* |
429 | * We have to do this here as we may have a dso | |
430 | * with no symbol hit that has a name longer than | |
431 | * the ones with symbols sampled. | |
432 | */ | |
021191b3 | 433 | if (!sort_dso.elide && !map->dso->slen_calculated) |
52d422de ACM |
434 | dso__calc_col_width(map->dso); |
435 | ||
6e7d6fdc PZ |
436 | if (mapp) |
437 | *mapp = map; | |
438 | got_map: | |
439 | ip = map->map_ip(map, ip); | |
6e7d6fdc PZ |
440 | } else { |
441 | /* | |
442 | * If this is outside of all known maps, | |
443 | * and is a negative address, try to look it | |
444 | * up in the kernel dso, as it might be a | |
439d473b ACM |
445 | * vsyscall or vdso (which executes in user-mode). |
446 | * | |
447 | * XXX This is nasty, we should have a symbol list in | |
448 | * the "[vdso]" dso, but for now lets use the old | |
449 | * trick of looking in the whole kernel symbol list. | |
6e7d6fdc | 450 | */ |
c3b32fcb | 451 | if ((long long)ip < 0) |
c338aee8 | 452 | return kernel_maps__find_symbol(ip, mapp, NULL); |
6e7d6fdc | 453 | } |
439d473b ACM |
454 | dump_printf(" ...... dso: %s\n", |
455 | map ? map->dso->long_name : "<not found>"); | |
2cec19d9 | 456 | dump_printf(" ...... map: %Lx -> %Lx\n", *ipp, ip); |
520f2c34 | 457 | *ipp = ip; |
6e7d6fdc | 458 | |
66bd8424 | 459 | return map ? map__find_symbol(map, ip, NULL) : NULL; |
6e7d6fdc PZ |
460 | } |
461 | ||
2a0a50fe | 462 | static int call__match(struct symbol *sym) |
6e7d6fdc | 463 | { |
b25bcf2f | 464 | if (sym->name && !regexec(&parent_regex, sym->name, 0, NULL, 0)) |
2a0a50fe | 465 | return 1; |
6e7d6fdc | 466 | |
2a0a50fe | 467 | return 0; |
6e7d6fdc PZ |
468 | } |
469 | ||
9735abf1 ACM |
470 | static struct symbol **resolve_callchain(struct thread *thread, struct map *map, |
471 | struct ip_callchain *chain, | |
472 | struct symbol **parent) | |
4424961a | 473 | { |
4424961a | 474 | u64 context = PERF_CONTEXT_MAX; |
029e5b16 | 475 | struct symbol **syms = NULL; |
f37a291c | 476 | unsigned int i; |
4424961a FW |
477 | |
478 | if (callchain) { | |
479 | syms = calloc(chain->nr, sizeof(*syms)); | |
480 | if (!syms) { | |
481 | fprintf(stderr, "Can't allocate memory for symbols\n"); | |
482 | exit(-1); | |
483 | } | |
484 | } | |
485 | ||
486 | for (i = 0; i < chain->nr; i++) { | |
487 | u64 ip = chain->ips[i]; | |
439d473b | 488 | struct symbol *sym = NULL; |
4424961a FW |
489 | |
490 | if (ip >= PERF_CONTEXT_MAX) { | |
491 | context = ip; | |
492 | continue; | |
493 | } | |
494 | ||
495 | switch (context) { | |
88a69dfb | 496 | case PERF_CONTEXT_HV: |
88a69dfb | 497 | break; |
4424961a | 498 | case PERF_CONTEXT_KERNEL: |
c338aee8 | 499 | sym = kernel_maps__find_symbol(ip, &map, NULL); |
4424961a FW |
500 | break; |
501 | default: | |
439d473b | 502 | sym = resolve_symbol(thread, &map, &ip); |
4424961a FW |
503 | break; |
504 | } | |
505 | ||
4424961a | 506 | if (sym) { |
9735abf1 ACM |
507 | if (sort__has_parent && !*parent && call__match(sym)) |
508 | *parent = sym; | |
4424961a FW |
509 | if (!callchain) |
510 | break; | |
511 | syms[i] = sym; | |
512 | } | |
513 | } | |
514 | ||
515 | return syms; | |
516 | } | |
517 | ||
1aa16738 PZ |
518 | /* |
519 | * collect histogram counts | |
520 | */ | |
521 | ||
e7fb08b1 | 522 | static int |
439d473b | 523 | hist_entry__add(struct thread *thread, struct map *map, |
9cffa8d5 PM |
524 | struct symbol *sym, u64 ip, struct ip_callchain *chain, |
525 | char level, u64 count) | |
8fa66bdc | 526 | { |
9735abf1 ACM |
527 | struct symbol **syms = NULL, *parent = NULL; |
528 | bool hit; | |
e7fb08b1 | 529 | struct hist_entry *he; |
e7fb08b1 | 530 | |
4424961a | 531 | if ((sort__has_parent || callchain) && chain) |
9735abf1 | 532 | syms = resolve_callchain(thread, map, chain, &parent); |
e7fb08b1 | 533 | |
9735abf1 ACM |
534 | he = __hist_entry__add(thread, map, sym, parent, |
535 | ip, count, level, &hit); | |
536 | if (he == NULL) | |
537 | return -ENOMEM; | |
e7fb08b1 | 538 | |
9735abf1 ACM |
539 | if (hit) |
540 | he->count += count; | |
e7fb08b1 | 541 | |
f55c5552 | 542 | if (callchain) { |
9735abf1 ACM |
543 | if (!hit) |
544 | callchain_init(&he->callchain); | |
4424961a FW |
545 | append_chain(&he->callchain, chain, syms); |
546 | free(syms); | |
f55c5552 | 547 | } |
e7fb08b1 PZ |
548 | |
549 | return 0; | |
8fa66bdc ACM |
550 | } |
551 | ||
9cffa8d5 | 552 | static size_t output__fprintf(FILE *fp, u64 total_samples) |
3a4b8cc7 | 553 | { |
e7fb08b1 | 554 | struct hist_entry *pos; |
2d65537e | 555 | struct sort_entry *se; |
3a4b8cc7 ACM |
556 | struct rb_node *nd; |
557 | size_t ret = 0; | |
52d422de ACM |
558 | unsigned int width; |
559 | char *col_width = col_width_list_str; | |
9f866697 BG |
560 | int raw_printing_style; |
561 | ||
562 | raw_printing_style = !strcmp(pretty_printing_style, "raw"); | |
3a4b8cc7 | 563 | |
25446036 FW |
564 | init_rem_hits(); |
565 | ||
021191b3 | 566 | fprintf(fp, "# Samples: %Ld\n", (u64)total_samples); |
ca8cdeef PZ |
567 | fprintf(fp, "#\n"); |
568 | ||
569 | fprintf(fp, "# Overhead"); | |
e3d7e183 ACM |
570 | if (show_nr_samples) { |
571 | if (field_sep) | |
572 | fprintf(fp, "%cSamples", *field_sep); | |
573 | else | |
574 | fputs(" Samples ", fp); | |
575 | } | |
b8e6d829 | 576 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
021191b3 | 577 | if (se->elide) |
b8e6d829 | 578 | continue; |
52d422de ACM |
579 | if (field_sep) { |
580 | fprintf(fp, "%c%s", *field_sep, se->header); | |
b8e6d829 | 581 | continue; |
52d422de ACM |
582 | } |
583 | width = strlen(se->header); | |
584 | if (se->width) { | |
585 | if (col_width_list_str) { | |
586 | if (col_width) { | |
587 | *se->width = atoi(col_width); | |
588 | col_width = strchr(col_width, ','); | |
589 | if (col_width) | |
590 | ++col_width; | |
591 | } | |
592 | } | |
593 | width = *se->width = max(*se->width, width); | |
594 | } | |
595 | fprintf(fp, " %*s", width, se->header); | |
b8e6d829 | 596 | } |
ca8cdeef PZ |
597 | fprintf(fp, "\n"); |
598 | ||
52d422de ACM |
599 | if (field_sep) |
600 | goto print_entries; | |
601 | ||
ca8cdeef | 602 | fprintf(fp, "# ........"); |
e3d7e183 ACM |
603 | if (show_nr_samples) |
604 | fprintf(fp, " .........."); | |
2d65537e | 605 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
f37a291c | 606 | unsigned int i; |
ca8cdeef | 607 | |
021191b3 | 608 | if (se->elide) |
b8e6d829 IM |
609 | continue; |
610 | ||
4593bba8 | 611 | fprintf(fp, " "); |
52d422de ACM |
612 | if (se->width) |
613 | width = *se->width; | |
614 | else | |
615 | width = strlen(se->header); | |
616 | for (i = 0; i < width; i++) | |
ca8cdeef | 617 | fprintf(fp, "."); |
2d65537e | 618 | } |
ca8cdeef PZ |
619 | fprintf(fp, "\n"); |
620 | ||
621 | fprintf(fp, "#\n"); | |
2d65537e | 622 | |
52d422de | 623 | print_entries: |
e7fb08b1 PZ |
624 | for (nd = rb_first(&output_hists); nd; nd = rb_next(nd)) { |
625 | pos = rb_entry(nd, struct hist_entry, rb_node); | |
626 | ret += hist_entry__fprintf(fp, pos, total_samples); | |
3a4b8cc7 ACM |
627 | } |
628 | ||
b8e6d829 IM |
629 | if (sort_order == default_sort_order && |
630 | parent_pattern == default_parent_pattern) { | |
bd74137e | 631 | fprintf(fp, "#\n"); |
114cfab2 | 632 | fprintf(fp, "# (For a higher level overview, try: perf report --sort comm,dso)\n"); |
bd74137e IM |
633 | fprintf(fp, "#\n"); |
634 | } | |
71dd8945 | 635 | fprintf(fp, "\n"); |
bd74137e | 636 | |
25446036 FW |
637 | free(rem_sq_bracket); |
638 | ||
8d513270 | 639 | if (show_threads) |
9f866697 BG |
640 | perf_read_values_display(fp, &show_threads_values, |
641 | raw_printing_style); | |
8d513270 | 642 | |
3a4b8cc7 ACM |
643 | return ret; |
644 | } | |
645 | ||
2a0a50fe | 646 | static int validate_chain(struct ip_callchain *chain, event_t *event) |
7522060c IM |
647 | { |
648 | unsigned int chain_size; | |
649 | ||
7522060c IM |
650 | chain_size = event->header.size; |
651 | chain_size -= (unsigned long)&event->ip.__more_data - (unsigned long)event; | |
652 | ||
9cffa8d5 | 653 | if (chain->nr*sizeof(u64) > chain_size) |
7522060c IM |
654 | return -1; |
655 | ||
656 | return 0; | |
657 | } | |
658 | ||
d80d338d | 659 | static int |
e6e18ec7 | 660 | process_sample_event(event_t *event, unsigned long offset, unsigned long head) |
75051724 IM |
661 | { |
662 | char level; | |
439d473b | 663 | struct symbol *sym = NULL; |
9cffa8d5 PM |
664 | u64 ip = event->ip.ip; |
665 | u64 period = 1; | |
75051724 | 666 | struct map *map = NULL; |
3efa1cc9 | 667 | void *more_data = event->ip.__more_data; |
2a0a50fe | 668 | struct ip_callchain *chain = NULL; |
d8db1b57 | 669 | int cpumode; |
d5b889f2 | 670 | struct thread *thread = threads__findnew(event->ip.pid); |
6baa0a5a | 671 | |
e6e18ec7 | 672 | if (sample_type & PERF_SAMPLE_PERIOD) { |
9cffa8d5 PM |
673 | period = *(u64 *)more_data; |
674 | more_data += sizeof(u64); | |
3efa1cc9 | 675 | } |
ea1900e5 | 676 | |
cdd6c482 | 677 | dump_printf("%p [%p]: PERF_RECORD_SAMPLE (IP, %d): %d/%d: %p period: %Ld\n", |
75051724 IM |
678 | (void *)(offset + head), |
679 | (void *)(long)(event->header.size), | |
680 | event->header.misc, | |
94a24752 | 681 | event->ip.pid, event->ip.tid, |
4502d77c | 682 | (void *)(long)ip, |
ea1900e5 | 683 | (long long)period); |
75051724 | 684 | |
e6e18ec7 | 685 | if (sample_type & PERF_SAMPLE_CALLCHAIN) { |
f37a291c | 686 | unsigned int i; |
3efa1cc9 IM |
687 | |
688 | chain = (void *)more_data; | |
689 | ||
2cec19d9 | 690 | dump_printf("... chain: nr:%Lu\n", chain->nr); |
3efa1cc9 | 691 | |
7522060c | 692 | if (validate_chain(chain, event) < 0) { |
6beba7ad ACM |
693 | pr_debug("call-chain problem with event, " |
694 | "skipping it.\n"); | |
7522060c IM |
695 | return 0; |
696 | } | |
697 | ||
698 | if (dump_trace) { | |
3efa1cc9 | 699 | for (i = 0; i < chain->nr; i++) |
2cec19d9 | 700 | dump_printf("..... %2d: %016Lx\n", i, chain->ips[i]); |
3efa1cc9 IM |
701 | } |
702 | } | |
703 | ||
75051724 | 704 | if (thread == NULL) { |
6beba7ad | 705 | pr_debug("problem processing %d event, skipping it.\n", |
75051724 IM |
706 | event->header.type); |
707 | return -1; | |
708 | } | |
e7fb08b1 | 709 | |
f39cdf25 JL |
710 | dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid); |
711 | ||
cc8b88b1 ACM |
712 | if (comm_list && !strlist__has_entry(comm_list, thread->comm)) |
713 | return 0; | |
714 | ||
cdd6c482 | 715 | cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; |
d8db1b57 | 716 | |
cdd6c482 | 717 | if (cpumode == PERF_RECORD_MISC_KERNEL) { |
75051724 | 718 | level = 'k'; |
c338aee8 | 719 | sym = kernel_maps__find_symbol(ip, &map, NULL); |
439d473b ACM |
720 | dump_printf(" ...... dso: %s\n", |
721 | map ? map->dso->long_name : "<not found>"); | |
cdd6c482 | 722 | } else if (cpumode == PERF_RECORD_MISC_USER) { |
75051724 | 723 | level = '.'; |
439d473b | 724 | sym = resolve_symbol(thread, &map, &ip); |
e7fb08b1 | 725 | |
75051724 | 726 | } else { |
75051724 | 727 | level = 'H'; |
2cec19d9 | 728 | dump_printf(" ...... dso: [hypervisor]\n"); |
75051724 | 729 | } |
8fa66bdc | 730 | |
ec218fc4 ACM |
731 | if (dso_list && |
732 | (!map || !map->dso || | |
733 | !(strlist__has_entry(dso_list, map->dso->short_name) || | |
734 | (map->dso->short_name != map->dso->long_name && | |
735 | strlist__has_entry(dso_list, map->dso->long_name))))) | |
736 | return 0; | |
25903407 | 737 | |
ec218fc4 ACM |
738 | if (sym_list && sym && !strlist__has_entry(sym_list, sym->name)) |
739 | return 0; | |
7bec7a91 | 740 | |
ec218fc4 ACM |
741 | if (hist_entry__add(thread, map, sym, ip, |
742 | chain, level, period)) { | |
6beba7ad | 743 | pr_debug("problem incrementing symbol count, skipping event\n"); |
ec218fc4 | 744 | return -1; |
8fa66bdc | 745 | } |
ec218fc4 | 746 | |
ea1900e5 | 747 | total += period; |
8fa66bdc | 748 | |
75051724 IM |
749 | return 0; |
750 | } | |
3502973d | 751 | |
75051724 IM |
752 | static int |
753 | process_mmap_event(event_t *event, unsigned long offset, unsigned long head) | |
754 | { | |
00a192b3 | 755 | struct map *map = map__new(&event->mmap, cwd, cwdlen); |
d5b889f2 | 756 | struct thread *thread = threads__findnew(event->mmap.pid); |
6baa0a5a | 757 | |
cdd6c482 | 758 | dump_printf("%p [%p]: PERF_RECORD_MMAP %d/%d: [%p(%p) @ %p]: %s\n", |
75051724 IM |
759 | (void *)(offset + head), |
760 | (void *)(long)(event->header.size), | |
62fc4453 | 761 | event->mmap.pid, |
94a24752 | 762 | event->mmap.tid, |
75051724 IM |
763 | (void *)(long)event->mmap.start, |
764 | (void *)(long)event->mmap.len, | |
765 | (void *)(long)event->mmap.pgoff, | |
766 | event->mmap.filename); | |
767 | ||
768 | if (thread == NULL || map == NULL) { | |
cdd6c482 | 769 | dump_printf("problem processing PERF_RECORD_MMAP, skipping event.\n"); |
df97992c | 770 | return 0; |
75051724 IM |
771 | } |
772 | ||
773 | thread__insert_map(thread, map); | |
774 | total_mmap++; | |
775 | ||
776 | return 0; | |
777 | } | |
778 | ||
779 | static int | |
780 | process_comm_event(event_t *event, unsigned long offset, unsigned long head) | |
781 | { | |
d5b889f2 | 782 | struct thread *thread = threads__findnew(event->comm.pid); |
75051724 | 783 | |
cdd6c482 | 784 | dump_printf("%p [%p]: PERF_RECORD_COMM: %s:%d\n", |
75051724 IM |
785 | (void *)(offset + head), |
786 | (void *)(long)(event->header.size), | |
787 | event->comm.comm, event->comm.pid); | |
788 | ||
789 | if (thread == NULL || | |
4273b005 | 790 | thread__set_comm_adjust(thread, event->comm.comm)) { |
cdd6c482 | 791 | dump_printf("problem processing PERF_RECORD_COMM, skipping event.\n"); |
75051724 | 792 | return -1; |
8fa66bdc | 793 | } |
75051724 IM |
794 | total_comm++; |
795 | ||
796 | return 0; | |
797 | } | |
798 | ||
62fc4453 | 799 | static int |
27d028de | 800 | process_task_event(event_t *event, unsigned long offset, unsigned long head) |
62fc4453 | 801 | { |
d5b889f2 ACM |
802 | struct thread *thread = threads__findnew(event->fork.pid); |
803 | struct thread *parent = threads__findnew(event->fork.ppid); | |
62fc4453 | 804 | |
cdd6c482 | 805 | dump_printf("%p [%p]: PERF_RECORD_%s: (%d:%d):(%d:%d)\n", |
62fc4453 PZ |
806 | (void *)(offset + head), |
807 | (void *)(long)(event->header.size), | |
cdd6c482 | 808 | event->header.type == PERF_RECORD_FORK ? "FORK" : "EXIT", |
27d028de PZ |
809 | event->fork.pid, event->fork.tid, |
810 | event->fork.ppid, event->fork.ptid); | |
811 | ||
812 | /* | |
813 | * A thread clone will have the same PID for both | |
814 | * parent and child. | |
815 | */ | |
816 | if (thread == parent) | |
817 | return 0; | |
818 | ||
cdd6c482 | 819 | if (event->header.type == PERF_RECORD_EXIT) |
27d028de | 820 | return 0; |
62fc4453 PZ |
821 | |
822 | if (!thread || !parent || thread__fork(thread, parent)) { | |
cdd6c482 | 823 | dump_printf("problem processing PERF_RECORD_FORK, skipping event.\n"); |
62fc4453 PZ |
824 | return -1; |
825 | } | |
826 | total_fork++; | |
827 | ||
828 | return 0; | |
829 | } | |
830 | ||
9d91a6f7 PZ |
831 | static int |
832 | process_lost_event(event_t *event, unsigned long offset, unsigned long head) | |
833 | { | |
cdd6c482 | 834 | dump_printf("%p [%p]: PERF_RECORD_LOST: id:%Ld: lost:%Ld\n", |
9d91a6f7 PZ |
835 | (void *)(offset + head), |
836 | (void *)(long)(event->header.size), | |
837 | event->lost.id, | |
838 | event->lost.lost); | |
839 | ||
840 | total_lost += event->lost.lost; | |
841 | ||
842 | return 0; | |
843 | } | |
844 | ||
e9ea2fde PZ |
845 | static int |
846 | process_read_event(event_t *event, unsigned long offset, unsigned long head) | |
847 | { | |
cdd6c482 | 848 | struct perf_event_attr *attr; |
0d3a5c88 FW |
849 | |
850 | attr = perf_header__find_attr(event->read.id, header); | |
8f18aec5 | 851 | |
8d513270 | 852 | if (show_threads) { |
83a0944f | 853 | const char *name = attr ? __event_name(attr->type, attr->config) |
8d513270 BG |
854 | : "unknown"; |
855 | perf_read_values_add_value(&show_threads_values, | |
856 | event->read.pid, event->read.tid, | |
857 | event->read.id, | |
858 | name, | |
859 | event->read.value); | |
860 | } | |
861 | ||
cdd6c482 | 862 | dump_printf("%p [%p]: PERF_RECORD_READ: %d %d %s %Lu\n", |
e9ea2fde PZ |
863 | (void *)(offset + head), |
864 | (void *)(long)(event->header.size), | |
865 | event->read.pid, | |
866 | event->read.tid, | |
8f18aec5 PZ |
867 | attr ? __event_name(attr->type, attr->config) |
868 | : "FAIL", | |
e9ea2fde PZ |
869 | event->read.value); |
870 | ||
871 | return 0; | |
872 | } | |
873 | ||
016e92fb | 874 | static int sample_type_check(u64 type) |
d80d338d | 875 | { |
016e92fb | 876 | sample_type = type; |
e6e18ec7 | 877 | |
91b4eaea FW |
878 | if (!(sample_type & PERF_SAMPLE_CALLCHAIN)) { |
879 | if (sort__has_parent) { | |
880 | fprintf(stderr, "selected --sort parent, but no" | |
881 | " callchain data. Did you call" | |
882 | " perf record without -g?\n"); | |
016e92fb | 883 | return -1; |
91b4eaea FW |
884 | } |
885 | if (callchain) { | |
6ede59c4 | 886 | fprintf(stderr, "selected -g but no callchain data." |
91b4eaea FW |
887 | " Did you call perf record without" |
888 | " -g?\n"); | |
016e92fb | 889 | return -1; |
91b4eaea | 890 | } |
b1a88349 FW |
891 | } else if (callchain_param.mode != CHAIN_NONE && !callchain) { |
892 | callchain = 1; | |
893 | if (register_callchain_param(&callchain_param) < 0) { | |
894 | fprintf(stderr, "Can't register callchain" | |
895 | " params\n"); | |
016e92fb | 896 | return -1; |
b1a88349 | 897 | } |
f5970550 PZ |
898 | } |
899 | ||
016e92fb FW |
900 | return 0; |
901 | } | |
6142f9ec | 902 | |
016e92fb FW |
903 | static struct perf_file_handler file_handler = { |
904 | .process_sample_event = process_sample_event, | |
905 | .process_mmap_event = process_mmap_event, | |
906 | .process_comm_event = process_comm_event, | |
907 | .process_exit_event = process_task_event, | |
908 | .process_fork_event = process_task_event, | |
909 | .process_lost_event = process_lost_event, | |
910 | .process_read_event = process_read_event, | |
911 | .sample_type_check = sample_type_check, | |
912 | }; | |
6142f9ec | 913 | |
6142f9ec | 914 | |
016e92fb FW |
915 | static int __cmd_report(void) |
916 | { | |
917 | struct thread *idle; | |
918 | int ret; | |
8fa66bdc | 919 | |
d5b889f2 | 920 | idle = register_idle_thread(); |
016e92fb | 921 | thread__comm_adjust(idle); |
f49515b1 | 922 | |
016e92fb FW |
923 | if (show_threads) |
924 | perf_read_values_init(&show_threads_values); | |
f5970550 | 925 | |
016e92fb | 926 | register_perf_file_handler(&file_handler); |
8fa66bdc | 927 | |
016e92fb FW |
928 | ret = mmap_dispatch_perf_file(&header, input_name, force, full_paths, |
929 | &cwdlen, &cwd); | |
930 | if (ret) | |
931 | return ret; | |
97b07b69 | 932 | |
2cec19d9 FW |
933 | dump_printf(" IP events: %10ld\n", total); |
934 | dump_printf(" mmap events: %10ld\n", total_mmap); | |
935 | dump_printf(" comm events: %10ld\n", total_comm); | |
936 | dump_printf(" fork events: %10ld\n", total_fork); | |
937 | dump_printf(" lost events: %10ld\n", total_lost); | |
016e92fb | 938 | dump_printf(" unknown events: %10ld\n", file_handler.total_unknown); |
97b07b69 | 939 | |
3502973d | 940 | if (dump_trace) |
97b07b69 | 941 | return 0; |
97b07b69 | 942 | |
da21d1b5 | 943 | if (verbose > 3) |
d5b889f2 | 944 | threads__fprintf(stdout); |
9ac99545 | 945 | |
da21d1b5 | 946 | if (verbose > 2) |
16f762a2 | 947 | dsos__fprintf(stdout); |
16f762a2 | 948 | |
8229289b | 949 | collapse__resort(); |
c20ab37e | 950 | output__resort(total); |
e7fb08b1 | 951 | output__fprintf(stdout, total); |
8fa66bdc | 952 | |
8d513270 BG |
953 | if (show_threads) |
954 | perf_read_values_destroy(&show_threads_values); | |
955 | ||
016e92fb | 956 | return ret; |
8fa66bdc ACM |
957 | } |
958 | ||
4eb3e478 FW |
959 | static int |
960 | parse_callchain_opt(const struct option *opt __used, const char *arg, | |
961 | int unset __used) | |
962 | { | |
c20ab37e FW |
963 | char *tok; |
964 | char *endptr; | |
965 | ||
4eb3e478 FW |
966 | callchain = 1; |
967 | ||
968 | if (!arg) | |
969 | return 0; | |
970 | ||
c20ab37e FW |
971 | tok = strtok((char *)arg, ","); |
972 | if (!tok) | |
973 | return -1; | |
974 | ||
975 | /* get the output mode */ | |
976 | if (!strncmp(tok, "graph", strlen(arg))) | |
805d127d | 977 | callchain_param.mode = CHAIN_GRAPH_ABS; |
4eb3e478 | 978 | |
c20ab37e | 979 | else if (!strncmp(tok, "flat", strlen(arg))) |
805d127d FW |
980 | callchain_param.mode = CHAIN_FLAT; |
981 | ||
982 | else if (!strncmp(tok, "fractal", strlen(arg))) | |
983 | callchain_param.mode = CHAIN_GRAPH_REL; | |
984 | ||
b1a88349 FW |
985 | else if (!strncmp(tok, "none", strlen(arg))) { |
986 | callchain_param.mode = CHAIN_NONE; | |
987 | callchain = 0; | |
988 | ||
989 | return 0; | |
990 | } | |
991 | ||
4eb3e478 FW |
992 | else |
993 | return -1; | |
994 | ||
c20ab37e FW |
995 | /* get the min percentage */ |
996 | tok = strtok(NULL, ","); | |
997 | if (!tok) | |
805d127d | 998 | goto setup; |
c20ab37e | 999 | |
805d127d | 1000 | callchain_param.min_percent = strtod(tok, &endptr); |
c20ab37e FW |
1001 | if (tok == endptr) |
1002 | return -1; | |
1003 | ||
805d127d FW |
1004 | setup: |
1005 | if (register_callchain_param(&callchain_param) < 0) { | |
1006 | fprintf(stderr, "Can't register callchain params\n"); | |
1007 | return -1; | |
1008 | } | |
4eb3e478 FW |
1009 | return 0; |
1010 | } | |
1011 | ||
dd68ada2 JK |
1012 | //static const char * const report_usage[] = { |
1013 | const char * const report_usage[] = { | |
53cb8bc2 IM |
1014 | "perf report [<options>] <command>", |
1015 | NULL | |
1016 | }; | |
1017 | ||
1018 | static const struct option options[] = { | |
1019 | OPT_STRING('i', "input", &input_name, "file", | |
1020 | "input file name"), | |
815e777f ACM |
1021 | OPT_BOOLEAN('v', "verbose", &verbose, |
1022 | "be more verbose (show symbol address, etc)"), | |
97b07b69 IM |
1023 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, |
1024 | "dump raw trace in ASCII"), | |
83a0944f | 1025 | OPT_STRING('k', "vmlinux", &vmlinux_name, "file", "vmlinux pathname"), |
fa6963b2 | 1026 | OPT_BOOLEAN('f', "force", &force, "don't complain, do it"), |
6671cb16 | 1027 | OPT_BOOLEAN('m', "modules", &use_modules, |
42976487 | 1028 | "load module symbols - WARNING: use only with -k and LIVE kernel"), |
e3d7e183 ACM |
1029 | OPT_BOOLEAN('n', "show-nr-samples", &show_nr_samples, |
1030 | "Show a column with the number of samples"), | |
8d513270 BG |
1031 | OPT_BOOLEAN('T', "threads", &show_threads, |
1032 | "Show per-thread event counters"), | |
9f866697 BG |
1033 | OPT_STRING(0, "pretty", &pretty_printing_style, "key", |
1034 | "pretty printing style key: normal raw"), | |
63299f05 | 1035 | OPT_STRING('s', "sort", &sort_order, "key[,key2...]", |
b25bcf2f | 1036 | "sort by key(s): pid, comm, dso, symbol, parent"), |
b78c07d4 ACM |
1037 | OPT_BOOLEAN('P', "full-paths", &full_paths, |
1038 | "Don't shorten the pathnames taking into account the cwd"), | |
b25bcf2f IM |
1039 | OPT_STRING('p', "parent", &parent_pattern, "regex", |
1040 | "regex filter to identify parent, see: '--sort parent'"), | |
b8e6d829 IM |
1041 | OPT_BOOLEAN('x', "exclude-other", &exclude_other, |
1042 | "Only display entries with parent-match"), | |
1483b19f | 1043 | OPT_CALLBACK_DEFAULT('g', "call-graph", NULL, "output_type,min_percent", |
c20ab37e | 1044 | "Display callchains using output_type and min percent threshold. " |
1483b19f | 1045 | "Default: fractal,0.5", &parse_callchain_opt, callchain_default_opt), |
25903407 ACM |
1046 | OPT_STRING('d', "dsos", &dso_list_str, "dso[,dso...]", |
1047 | "only consider symbols in these dsos"), | |
cc8b88b1 ACM |
1048 | OPT_STRING('C', "comms", &comm_list_str, "comm[,comm...]", |
1049 | "only consider symbols in these comms"), | |
7bec7a91 ACM |
1050 | OPT_STRING('S', "symbols", &sym_list_str, "symbol[,symbol...]", |
1051 | "only consider these symbols"), | |
52d422de ACM |
1052 | OPT_STRING('w', "column-widths", &col_width_list_str, |
1053 | "width[,width...]", | |
1054 | "don't try to adjust column width, use these fixed values"), | |
1055 | OPT_STRING('t', "field-separator", &field_sep, "separator", | |
1056 | "separator for columns, no spaces will be added between " | |
1057 | "columns '.' is reserved."), | |
53cb8bc2 IM |
1058 | OPT_END() |
1059 | }; | |
1060 | ||
5352f35d IM |
1061 | static void setup_sorting(void) |
1062 | { | |
1063 | char *tmp, *tok, *str = strdup(sort_order); | |
1064 | ||
1065 | for (tok = strtok_r(str, ", ", &tmp); | |
1066 | tok; tok = strtok_r(NULL, ", ", &tmp)) { | |
1067 | if (sort_dimension__add(tok) < 0) { | |
1068 | error("Unknown --sort key: `%s'", tok); | |
1069 | usage_with_options(report_usage, options); | |
1070 | } | |
1071 | } | |
1072 | ||
1073 | free(str); | |
1074 | } | |
1075 | ||
cc8b88b1 | 1076 | static void setup_list(struct strlist **list, const char *list_str, |
021191b3 ACM |
1077 | struct sort_entry *se, const char *list_name, |
1078 | FILE *fp) | |
cc8b88b1 ACM |
1079 | { |
1080 | if (list_str) { | |
1081 | *list = strlist__new(true, list_str); | |
1082 | if (!*list) { | |
1083 | fprintf(stderr, "problems parsing %s list\n", | |
1084 | list_name); | |
1085 | exit(129); | |
1086 | } | |
021191b3 ACM |
1087 | if (strlist__nr_entries(*list) == 1) { |
1088 | fprintf(fp, "# %s: %s\n", list_name, | |
1089 | strlist__entry(*list, 0)->s); | |
1090 | se->elide = true; | |
1091 | } | |
cc8b88b1 ACM |
1092 | } |
1093 | } | |
1094 | ||
f37a291c | 1095 | int cmd_report(int argc, const char **argv, const char *prefix __used) |
53cb8bc2 | 1096 | { |
00a192b3 | 1097 | symbol__init(0); |
53cb8bc2 | 1098 | |
edc52dea | 1099 | argc = parse_options(argc, argv, options, report_usage, 0); |
53cb8bc2 | 1100 | |
1aa16738 PZ |
1101 | setup_sorting(); |
1102 | ||
021191b3 | 1103 | if (parent_pattern != default_parent_pattern) { |
b8e6d829 | 1104 | sort_dimension__add("parent"); |
021191b3 ACM |
1105 | sort_parent.elide = 1; |
1106 | } else | |
b8e6d829 IM |
1107 | exclude_other = 0; |
1108 | ||
edc52dea IM |
1109 | /* |
1110 | * Any (unrecognized) arguments left? | |
1111 | */ | |
1112 | if (argc) | |
1113 | usage_with_options(report_usage, options); | |
1114 | ||
a930d2c0 IM |
1115 | setup_pager(); |
1116 | ||
021191b3 ACM |
1117 | setup_list(&dso_list, dso_list_str, &sort_dso, "dso", stdout); |
1118 | setup_list(&comm_list, comm_list_str, &sort_comm, "comm", stdout); | |
1119 | setup_list(&sym_list, sym_list_str, &sort_sym, "symbol", stdout); | |
25903407 | 1120 | |
52d422de ACM |
1121 | if (field_sep && *field_sep == '.') { |
1122 | fputs("'.' is the only non valid --field-separator argument\n", | |
1123 | stderr); | |
1124 | exit(129); | |
1125 | } | |
1126 | ||
53cb8bc2 IM |
1127 | return __cmd_report(); |
1128 | } |