]>
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" |
35a50c8a | 13 | #include "util/list.h" |
a930d2c0 | 14 | #include "util/cache.h" |
35a50c8a | 15 | #include "util/rbtree.h" |
a2928c42 | 16 | #include "util/symbol.h" |
a0055ae2 | 17 | #include "util/string.h" |
8fa66bdc | 18 | |
53cb8bc2 IM |
19 | #include "perf.h" |
20 | ||
21 | #include "util/parse-options.h" | |
22 | #include "util/parse-events.h" | |
23 | ||
8fa66bdc ACM |
24 | #define SHOW_KERNEL 1 |
25 | #define SHOW_USER 2 | |
26 | #define SHOW_HV 4 | |
27 | ||
23ac9cbe | 28 | static char const *input_name = "perf.data"; |
450aaa2b | 29 | static char *vmlinux = NULL; |
bd74137e IM |
30 | |
31 | static char default_sort_order[] = "comm,dso"; | |
32 | static char *sort_order = default_sort_order; | |
33 | ||
8fa66bdc ACM |
34 | static int input; |
35 | static int show_mask = SHOW_KERNEL | SHOW_USER | SHOW_HV; | |
36 | ||
97b07b69 | 37 | static int dump_trace = 0; |
3502973d IM |
38 | #define dprintf(x...) do { if (dump_trace) printf(x); } while (0) |
39 | ||
16f762a2 | 40 | static int verbose; |
b78c07d4 | 41 | static int full_paths; |
97b07b69 | 42 | |
8fa66bdc ACM |
43 | static unsigned long page_size; |
44 | static unsigned long mmap_window = 32; | |
45 | ||
8fa66bdc ACM |
46 | struct ip_event { |
47 | struct perf_event_header header; | |
48 | __u64 ip; | |
49 | __u32 pid, tid; | |
50 | }; | |
75051724 | 51 | |
8fa66bdc ACM |
52 | struct mmap_event { |
53 | struct perf_event_header header; | |
54 | __u32 pid, tid; | |
55 | __u64 start; | |
56 | __u64 len; | |
57 | __u64 pgoff; | |
58 | char filename[PATH_MAX]; | |
59 | }; | |
75051724 | 60 | |
8fa66bdc ACM |
61 | struct comm_event { |
62 | struct perf_event_header header; | |
75051724 | 63 | __u32 pid, tid; |
8fa66bdc ACM |
64 | char comm[16]; |
65 | }; | |
66 | ||
62fc4453 PZ |
67 | struct fork_event { |
68 | struct perf_event_header header; | |
69 | __u32 pid, ppid; | |
70 | }; | |
71 | ||
8fa66bdc ACM |
72 | typedef union event_union { |
73 | struct perf_event_header header; | |
74 | struct ip_event ip; | |
75 | struct mmap_event mmap; | |
76 | struct comm_event comm; | |
62fc4453 | 77 | struct fork_event fork; |
8fa66bdc ACM |
78 | } event_t; |
79 | ||
8fa66bdc ACM |
80 | static LIST_HEAD(dsos); |
81 | static struct dso *kernel_dso; | |
fc54db51 | 82 | static struct dso *vdso; |
8fa66bdc ACM |
83 | |
84 | static void dsos__add(struct dso *dso) | |
85 | { | |
86 | list_add_tail(&dso->node, &dsos); | |
87 | } | |
88 | ||
89 | static struct dso *dsos__find(const char *name) | |
90 | { | |
91 | struct dso *pos; | |
92 | ||
93 | list_for_each_entry(pos, &dsos, node) | |
94 | if (strcmp(pos->name, name) == 0) | |
95 | return pos; | |
96 | return NULL; | |
97 | } | |
98 | ||
99 | static struct dso *dsos__findnew(const char *name) | |
100 | { | |
101 | struct dso *dso = dsos__find(name); | |
b7a16eac | 102 | int nr; |
8fa66bdc | 103 | |
4593bba8 IM |
104 | if (dso) |
105 | return dso; | |
106 | ||
107 | dso = dso__new(name, 0); | |
108 | if (!dso) | |
109 | goto out_delete_dso; | |
8fa66bdc | 110 | |
bd74137e | 111 | nr = dso__load(dso, NULL, verbose); |
4593bba8 | 112 | if (nr < 0) { |
bd74137e IM |
113 | if (verbose) |
114 | fprintf(stderr, "Failed to open: %s\n", name); | |
4593bba8 | 115 | goto out_delete_dso; |
8fa66bdc | 116 | } |
4593bba8 IM |
117 | if (!nr && verbose) { |
118 | fprintf(stderr, | |
119 | "No symbols found in: %s, maybe install a debug package?\n", | |
120 | name); | |
121 | } | |
122 | ||
123 | dsos__add(dso); | |
8fa66bdc ACM |
124 | |
125 | return dso; | |
126 | ||
127 | out_delete_dso: | |
128 | dso__delete(dso); | |
129 | return NULL; | |
130 | } | |
131 | ||
16f762a2 | 132 | static void dsos__fprintf(FILE *fp) |
8fa66bdc ACM |
133 | { |
134 | struct dso *pos; | |
135 | ||
136 | list_for_each_entry(pos, &dsos, node) | |
137 | dso__fprintf(pos, fp); | |
138 | } | |
139 | ||
fc54db51 PZ |
140 | static struct symbol *vdso__find_symbol(struct dso *dso, uint64_t ip) |
141 | { | |
142 | return dso__find_symbol(kernel_dso, ip); | |
143 | } | |
144 | ||
450aaa2b PZ |
145 | static int load_kernel(void) |
146 | { | |
a827c875 | 147 | int err; |
450aaa2b | 148 | |
0085c954 | 149 | kernel_dso = dso__new("[kernel]", 0); |
450aaa2b | 150 | if (!kernel_dso) |
a2928c42 | 151 | return -1; |
450aaa2b | 152 | |
bd74137e | 153 | err = dso__load_kernel(kernel_dso, vmlinux, NULL, verbose); |
a2928c42 ACM |
154 | if (err) { |
155 | dso__delete(kernel_dso); | |
156 | kernel_dso = NULL; | |
157 | } else | |
158 | dsos__add(kernel_dso); | |
450aaa2b | 159 | |
fc54db51 PZ |
160 | vdso = dso__new("[vdso]", 0); |
161 | if (!vdso) | |
162 | return -1; | |
163 | ||
164 | vdso->find_symbol = vdso__find_symbol; | |
165 | ||
166 | dsos__add(vdso); | |
167 | ||
a2928c42 | 168 | return err; |
450aaa2b PZ |
169 | } |
170 | ||
d80d338d IM |
171 | static char __cwd[PATH_MAX]; |
172 | static char *cwd = __cwd; | |
173 | static int cwdlen; | |
174 | ||
175 | static int strcommon(const char *pathname) | |
b78c07d4 ACM |
176 | { |
177 | int n = 0; | |
178 | ||
179 | while (pathname[n] == cwd[n] && n < cwdlen) | |
180 | ++n; | |
181 | ||
182 | return n; | |
183 | } | |
184 | ||
8fa66bdc ACM |
185 | struct map { |
186 | struct list_head node; | |
187 | uint64_t start; | |
188 | uint64_t end; | |
189 | uint64_t pgoff; | |
fc54db51 | 190 | uint64_t (*map_ip)(struct map *, uint64_t); |
8fa66bdc ACM |
191 | struct dso *dso; |
192 | }; | |
193 | ||
fc54db51 PZ |
194 | static uint64_t map__map_ip(struct map *map, uint64_t ip) |
195 | { | |
196 | return ip - map->start + map->pgoff; | |
197 | } | |
198 | ||
199 | static uint64_t vdso__map_ip(struct map *map, uint64_t ip) | |
200 | { | |
201 | return ip; | |
202 | } | |
203 | ||
d80d338d | 204 | static struct map *map__new(struct mmap_event *event) |
8fa66bdc ACM |
205 | { |
206 | struct map *self = malloc(sizeof(*self)); | |
207 | ||
208 | if (self != NULL) { | |
b78c07d4 ACM |
209 | const char *filename = event->filename; |
210 | char newfilename[PATH_MAX]; | |
211 | ||
212 | if (cwd) { | |
d80d338d IM |
213 | int n = strcommon(filename); |
214 | ||
b78c07d4 ACM |
215 | if (n == cwdlen) { |
216 | snprintf(newfilename, sizeof(newfilename), | |
217 | ".%s", filename + n); | |
218 | filename = newfilename; | |
219 | } | |
220 | } | |
221 | ||
8fa66bdc ACM |
222 | self->start = event->start; |
223 | self->end = event->start + event->len; | |
224 | self->pgoff = event->pgoff; | |
225 | ||
b78c07d4 | 226 | self->dso = dsos__findnew(filename); |
8fa66bdc ACM |
227 | if (self->dso == NULL) |
228 | goto out_delete; | |
fc54db51 PZ |
229 | |
230 | if (self->dso == vdso) | |
231 | self->map_ip = vdso__map_ip; | |
232 | else | |
233 | self->map_ip = map__map_ip; | |
8fa66bdc ACM |
234 | } |
235 | return self; | |
236 | out_delete: | |
237 | free(self); | |
238 | return NULL; | |
239 | } | |
240 | ||
62fc4453 PZ |
241 | static struct map *map__clone(struct map *self) |
242 | { | |
243 | struct map *map = malloc(sizeof(*self)); | |
244 | ||
245 | if (!map) | |
246 | return NULL; | |
247 | ||
248 | memcpy(map, self, sizeof(*self)); | |
249 | ||
250 | return map; | |
251 | } | |
252 | ||
253 | static int map__overlap(struct map *l, struct map *r) | |
254 | { | |
255 | if (l->start > r->start) { | |
256 | struct map *t = l; | |
257 | l = r; | |
258 | r = t; | |
259 | } | |
260 | ||
261 | if (l->end > r->start) | |
262 | return 1; | |
263 | ||
264 | return 0; | |
265 | } | |
3a4b8cc7 | 266 | |
9ac99545 ACM |
267 | static size_t map__fprintf(struct map *self, FILE *fp) |
268 | { | |
ee7b31fe | 269 | return fprintf(fp, " %"PRIx64"-%"PRIx64" %"PRIx64" %s\n", |
9ac99545 ACM |
270 | self->start, self->end, self->pgoff, self->dso->name); |
271 | } | |
272 | ||
273 | ||
8fa66bdc | 274 | struct thread { |
ce7e4365 | 275 | struct rb_node rb_node; |
8fa66bdc | 276 | struct list_head maps; |
8fa66bdc ACM |
277 | pid_t pid; |
278 | char *comm; | |
279 | }; | |
280 | ||
281 | static struct thread *thread__new(pid_t pid) | |
282 | { | |
283 | struct thread *self = malloc(sizeof(*self)); | |
284 | ||
285 | if (self != NULL) { | |
286 | self->pid = pid; | |
8229289b | 287 | self->comm = malloc(32); |
0a520c63 | 288 | if (self->comm) |
8229289b | 289 | snprintf(self->comm, 32, ":%d", self->pid); |
8fa66bdc | 290 | INIT_LIST_HEAD(&self->maps); |
8fa66bdc ACM |
291 | } |
292 | ||
293 | return self; | |
294 | } | |
295 | ||
8fa66bdc ACM |
296 | static int thread__set_comm(struct thread *self, const char *comm) |
297 | { | |
8229289b PZ |
298 | if (self->comm) |
299 | free(self->comm); | |
8fa66bdc ACM |
300 | self->comm = strdup(comm); |
301 | return self->comm ? 0 : -ENOMEM; | |
302 | } | |
303 | ||
9ac99545 ACM |
304 | static size_t thread__fprintf(struct thread *self, FILE *fp) |
305 | { | |
306 | struct map *pos; | |
307 | size_t ret = fprintf(fp, "Thread %d %s\n", self->pid, self->comm); | |
308 | ||
309 | list_for_each_entry(pos, &self->maps, node) | |
310 | ret += map__fprintf(pos, fp); | |
311 | ||
312 | return ret; | |
313 | } | |
314 | ||
315 | ||
16f762a2 | 316 | static struct rb_root threads; |
eed4dcd4 | 317 | static struct thread *last_match; |
8fa66bdc | 318 | |
ce7e4365 | 319 | static struct thread *threads__findnew(pid_t pid) |
8fa66bdc | 320 | { |
ce7e4365 ACM |
321 | struct rb_node **p = &threads.rb_node; |
322 | struct rb_node *parent = NULL; | |
323 | struct thread *th; | |
8fa66bdc | 324 | |
eed4dcd4 IM |
325 | /* |
326 | * Font-end cache - PID lookups come in blocks, | |
327 | * so most of the time we dont have to look up | |
328 | * the full rbtree: | |
329 | */ | |
330 | if (last_match && last_match->pid == pid) | |
331 | return last_match; | |
332 | ||
ce7e4365 ACM |
333 | while (*p != NULL) { |
334 | parent = *p; | |
335 | th = rb_entry(parent, struct thread, rb_node); | |
8fa66bdc | 336 | |
eed4dcd4 IM |
337 | if (th->pid == pid) { |
338 | last_match = th; | |
ce7e4365 | 339 | return th; |
eed4dcd4 | 340 | } |
8fa66bdc | 341 | |
ce7e4365 ACM |
342 | if (pid < th->pid) |
343 | p = &(*p)->rb_left; | |
344 | else | |
345 | p = &(*p)->rb_right; | |
8fa66bdc ACM |
346 | } |
347 | ||
ce7e4365 ACM |
348 | th = thread__new(pid); |
349 | if (th != NULL) { | |
350 | rb_link_node(&th->rb_node, parent, p); | |
351 | rb_insert_color(&th->rb_node, &threads); | |
eed4dcd4 | 352 | last_match = th; |
ce7e4365 | 353 | } |
eed4dcd4 | 354 | |
ce7e4365 | 355 | return th; |
8fa66bdc ACM |
356 | } |
357 | ||
358 | static void thread__insert_map(struct thread *self, struct map *map) | |
359 | { | |
62fc4453 PZ |
360 | struct map *pos, *tmp; |
361 | ||
362 | list_for_each_entry_safe(pos, tmp, &self->maps, node) { | |
363 | if (map__overlap(pos, map)) { | |
364 | list_del_init(&pos->node); | |
365 | /* XXX leaks dsos */ | |
366 | free(pos); | |
367 | } | |
368 | } | |
369 | ||
8fa66bdc ACM |
370 | list_add_tail(&map->node, &self->maps); |
371 | } | |
372 | ||
62fc4453 PZ |
373 | static int thread__fork(struct thread *self, struct thread *parent) |
374 | { | |
375 | struct map *map; | |
376 | ||
377 | if (self->comm) | |
378 | free(self->comm); | |
379 | self->comm = strdup(parent->comm); | |
380 | if (!self->comm) | |
381 | return -ENOMEM; | |
382 | ||
383 | list_for_each_entry(map, &parent->maps, node) { | |
384 | struct map *new = map__clone(map); | |
385 | if (!new) | |
386 | return -ENOMEM; | |
387 | thread__insert_map(self, new); | |
388 | } | |
389 | ||
390 | return 0; | |
391 | } | |
392 | ||
8fa66bdc ACM |
393 | static struct map *thread__find_map(struct thread *self, uint64_t ip) |
394 | { | |
16f762a2 IM |
395 | struct map *pos; |
396 | ||
8fa66bdc ACM |
397 | if (self == NULL) |
398 | return NULL; | |
399 | ||
8fa66bdc ACM |
400 | list_for_each_entry(pos, &self->maps, node) |
401 | if (ip >= pos->start && ip <= pos->end) | |
402 | return pos; | |
403 | ||
404 | return NULL; | |
405 | } | |
406 | ||
9ac99545 ACM |
407 | static size_t threads__fprintf(FILE *fp) |
408 | { | |
409 | size_t ret = 0; | |
410 | struct rb_node *nd; | |
411 | ||
412 | for (nd = rb_first(&threads); nd; nd = rb_next(nd)) { | |
413 | struct thread *pos = rb_entry(nd, struct thread, rb_node); | |
414 | ||
415 | ret += thread__fprintf(pos, fp); | |
416 | } | |
417 | ||
418 | return ret; | |
419 | } | |
420 | ||
e7fb08b1 PZ |
421 | /* |
422 | * histogram, sorted on item, collects counts | |
423 | */ | |
424 | ||
425 | static struct rb_root hist; | |
426 | ||
427 | struct hist_entry { | |
428 | struct rb_node rb_node; | |
429 | ||
430 | struct thread *thread; | |
431 | struct map *map; | |
432 | struct dso *dso; | |
433 | struct symbol *sym; | |
434 | uint64_t ip; | |
435 | char level; | |
436 | ||
437 | uint32_t count; | |
438 | }; | |
439 | ||
1aa16738 PZ |
440 | /* |
441 | * configurable sorting bits | |
442 | */ | |
443 | ||
444 | struct sort_entry { | |
445 | struct list_head list; | |
446 | ||
ca8cdeef PZ |
447 | char *header; |
448 | ||
1aa16738 | 449 | int64_t (*cmp)(struct hist_entry *, struct hist_entry *); |
8229289b | 450 | int64_t (*collapse)(struct hist_entry *, struct hist_entry *); |
1aa16738 PZ |
451 | size_t (*print)(FILE *fp, struct hist_entry *); |
452 | }; | |
453 | ||
8229289b PZ |
454 | /* --sort pid */ |
455 | ||
e7fb08b1 | 456 | static int64_t |
1aa16738 | 457 | sort__thread_cmp(struct hist_entry *left, struct hist_entry *right) |
e7fb08b1 | 458 | { |
1aa16738 PZ |
459 | return right->thread->pid - left->thread->pid; |
460 | } | |
461 | ||
462 | static size_t | |
463 | sort__thread_print(FILE *fp, struct hist_entry *self) | |
464 | { | |
71dd8945 | 465 | return fprintf(fp, "%16s:%5d", self->thread->comm ?: "", self->thread->pid); |
1aa16738 | 466 | } |
e7fb08b1 | 467 | |
1aa16738 | 468 | static struct sort_entry sort_thread = { |
71dd8945 | 469 | .header = " Command: Pid", |
1aa16738 PZ |
470 | .cmp = sort__thread_cmp, |
471 | .print = sort__thread_print, | |
472 | }; | |
473 | ||
8229289b PZ |
474 | /* --sort comm */ |
475 | ||
992444b1 PZ |
476 | static int64_t |
477 | sort__comm_cmp(struct hist_entry *left, struct hist_entry *right) | |
8229289b PZ |
478 | { |
479 | return right->thread->pid - left->thread->pid; | |
480 | } | |
481 | ||
482 | static int64_t | |
483 | sort__comm_collapse(struct hist_entry *left, struct hist_entry *right) | |
992444b1 PZ |
484 | { |
485 | char *comm_l = left->thread->comm; | |
486 | char *comm_r = right->thread->comm; | |
487 | ||
488 | if (!comm_l || !comm_r) { | |
489 | if (!comm_l && !comm_r) | |
490 | return 0; | |
491 | else if (!comm_l) | |
492 | return -1; | |
493 | else | |
494 | return 1; | |
495 | } | |
496 | ||
497 | return strcmp(comm_l, comm_r); | |
498 | } | |
499 | ||
500 | static size_t | |
501 | sort__comm_print(FILE *fp, struct hist_entry *self) | |
502 | { | |
71dd8945 | 503 | return fprintf(fp, "%16s", self->thread->comm); |
992444b1 PZ |
504 | } |
505 | ||
506 | static struct sort_entry sort_comm = { | |
71dd8945 | 507 | .header = " Command", |
8229289b PZ |
508 | .cmp = sort__comm_cmp, |
509 | .collapse = sort__comm_collapse, | |
510 | .print = sort__comm_print, | |
992444b1 PZ |
511 | }; |
512 | ||
8229289b PZ |
513 | /* --sort dso */ |
514 | ||
55e5ec41 PZ |
515 | static int64_t |
516 | sort__dso_cmp(struct hist_entry *left, struct hist_entry *right) | |
517 | { | |
518 | struct dso *dso_l = left->dso; | |
519 | struct dso *dso_r = right->dso; | |
520 | ||
521 | if (!dso_l || !dso_r) { | |
522 | if (!dso_l && !dso_r) | |
523 | return 0; | |
524 | else if (!dso_l) | |
525 | return -1; | |
526 | else | |
527 | return 1; | |
528 | } | |
529 | ||
530 | return strcmp(dso_l->name, dso_r->name); | |
531 | } | |
532 | ||
533 | static size_t | |
534 | sort__dso_print(FILE *fp, struct hist_entry *self) | |
535 | { | |
0a520c63 | 536 | if (self->dso) |
71dd8945 | 537 | return fprintf(fp, "%-25s", self->dso->name); |
0a520c63 | 538 | |
71dd8945 | 539 | return fprintf(fp, "%016llx ", (__u64)self->ip); |
55e5ec41 PZ |
540 | } |
541 | ||
542 | static struct sort_entry sort_dso = { | |
71dd8945 | 543 | .header = "Shared Object ", |
55e5ec41 PZ |
544 | .cmp = sort__dso_cmp, |
545 | .print = sort__dso_print, | |
546 | }; | |
547 | ||
8229289b PZ |
548 | /* --sort symbol */ |
549 | ||
1aa16738 PZ |
550 | static int64_t |
551 | sort__sym_cmp(struct hist_entry *left, struct hist_entry *right) | |
552 | { | |
553 | uint64_t ip_l, ip_r; | |
e7fb08b1 PZ |
554 | |
555 | if (left->sym == right->sym) | |
556 | return 0; | |
557 | ||
558 | ip_l = left->sym ? left->sym->start : left->ip; | |
559 | ip_r = right->sym ? right->sym->start : right->ip; | |
560 | ||
561 | return (int64_t)(ip_r - ip_l); | |
562 | } | |
563 | ||
1aa16738 PZ |
564 | static size_t |
565 | sort__sym_print(FILE *fp, struct hist_entry *self) | |
566 | { | |
567 | size_t ret = 0; | |
568 | ||
1aa16738 | 569 | if (verbose) |
71dd8945 | 570 | ret += fprintf(fp, "%#018llx ", (__u64)self->ip); |
0a520c63 | 571 | |
0a520c63 | 572 | if (self->sym) |
71dd8945 | 573 | ret += fprintf(fp, "%s", self->sym->name); |
0a520c63 | 574 | else |
71dd8945 | 575 | ret += fprintf(fp, "%#016llx", (__u64)self->ip); |
1aa16738 PZ |
576 | |
577 | return ret; | |
578 | } | |
579 | ||
580 | static struct sort_entry sort_sym = { | |
71dd8945 | 581 | .header = "Symbol", |
ca8cdeef PZ |
582 | .cmp = sort__sym_cmp, |
583 | .print = sort__sym_print, | |
1aa16738 PZ |
584 | }; |
585 | ||
8229289b PZ |
586 | static int sort__need_collapse = 0; |
587 | ||
37f440cb PZ |
588 | struct sort_dimension { |
589 | char *name; | |
590 | struct sort_entry *entry; | |
591 | int taken; | |
592 | }; | |
593 | ||
594 | static struct sort_dimension sort_dimensions[] = { | |
595 | { .name = "pid", .entry = &sort_thread, }, | |
992444b1 | 596 | { .name = "comm", .entry = &sort_comm, }, |
55e5ec41 | 597 | { .name = "dso", .entry = &sort_dso, }, |
37f440cb PZ |
598 | { .name = "symbol", .entry = &sort_sym, }, |
599 | }; | |
600 | ||
1aa16738 PZ |
601 | static LIST_HEAD(hist_entry__sort_list); |
602 | ||
37f440cb PZ |
603 | static int sort_dimension__add(char *tok) |
604 | { | |
605 | int i; | |
606 | ||
607 | for (i = 0; i < ARRAY_SIZE(sort_dimensions); i++) { | |
608 | struct sort_dimension *sd = &sort_dimensions[i]; | |
609 | ||
610 | if (sd->taken) | |
611 | continue; | |
612 | ||
5352f35d | 613 | if (strncasecmp(tok, sd->name, strlen(tok))) |
37f440cb PZ |
614 | continue; |
615 | ||
8229289b PZ |
616 | if (sd->entry->collapse) |
617 | sort__need_collapse = 1; | |
618 | ||
37f440cb PZ |
619 | list_add_tail(&sd->entry->list, &hist_entry__sort_list); |
620 | sd->taken = 1; | |
5352f35d | 621 | |
37f440cb PZ |
622 | return 0; |
623 | } | |
624 | ||
625 | return -ESRCH; | |
626 | } | |
627 | ||
1aa16738 PZ |
628 | static int64_t |
629 | hist_entry__cmp(struct hist_entry *left, struct hist_entry *right) | |
630 | { | |
631 | struct sort_entry *se; | |
632 | int64_t cmp = 0; | |
633 | ||
634 | list_for_each_entry(se, &hist_entry__sort_list, list) { | |
635 | cmp = se->cmp(left, right); | |
636 | if (cmp) | |
637 | break; | |
638 | } | |
639 | ||
640 | return cmp; | |
641 | } | |
642 | ||
8229289b PZ |
643 | static int64_t |
644 | hist_entry__collapse(struct hist_entry *left, struct hist_entry *right) | |
645 | { | |
646 | struct sort_entry *se; | |
647 | int64_t cmp = 0; | |
648 | ||
649 | list_for_each_entry(se, &hist_entry__sort_list, list) { | |
650 | int64_t (*f)(struct hist_entry *, struct hist_entry *); | |
651 | ||
652 | f = se->collapse ?: se->cmp; | |
653 | ||
654 | cmp = f(left, right); | |
655 | if (cmp) | |
656 | break; | |
657 | } | |
658 | ||
659 | return cmp; | |
660 | } | |
661 | ||
1aa16738 PZ |
662 | static size_t |
663 | hist_entry__fprintf(FILE *fp, struct hist_entry *self, uint64_t total_samples) | |
664 | { | |
665 | struct sort_entry *se; | |
666 | size_t ret; | |
667 | ||
668 | if (total_samples) { | |
8fc0321f IM |
669 | double percent = self->count * 100.0 / total_samples; |
670 | char *color = PERF_COLOR_NORMAL; | |
671 | ||
672 | /* | |
673 | * We color high-overhead entries in red, low-overhead | |
674 | * entries in green - and keep the middle ground normal: | |
675 | */ | |
676 | if (percent >= 5.0) | |
677 | color = PERF_COLOR_RED; | |
678 | if (percent < 0.5) | |
679 | color = PERF_COLOR_GREEN; | |
680 | ||
681 | ret = color_fprintf(fp, color, " %6.2f%%", | |
1aa16738 PZ |
682 | (self->count * 100.0) / total_samples); |
683 | } else | |
684 | ret = fprintf(fp, "%12d ", self->count); | |
685 | ||
71dd8945 PZ |
686 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
687 | fprintf(fp, " "); | |
1aa16738 | 688 | ret += se->print(fp, self); |
71dd8945 | 689 | } |
1aa16738 PZ |
690 | |
691 | ret += fprintf(fp, "\n"); | |
692 | ||
693 | return ret; | |
694 | } | |
695 | ||
696 | /* | |
697 | * collect histogram counts | |
698 | */ | |
699 | ||
e7fb08b1 PZ |
700 | static int |
701 | hist_entry__add(struct thread *thread, struct map *map, struct dso *dso, | |
702 | struct symbol *sym, uint64_t ip, char level) | |
8fa66bdc | 703 | { |
e7fb08b1 PZ |
704 | struct rb_node **p = &hist.rb_node; |
705 | struct rb_node *parent = NULL; | |
706 | struct hist_entry *he; | |
707 | struct hist_entry entry = { | |
708 | .thread = thread, | |
709 | .map = map, | |
710 | .dso = dso, | |
711 | .sym = sym, | |
712 | .ip = ip, | |
713 | .level = level, | |
714 | .count = 1, | |
715 | }; | |
716 | int cmp; | |
717 | ||
718 | while (*p != NULL) { | |
719 | parent = *p; | |
720 | he = rb_entry(parent, struct hist_entry, rb_node); | |
721 | ||
722 | cmp = hist_entry__cmp(&entry, he); | |
723 | ||
724 | if (!cmp) { | |
725 | he->count++; | |
726 | return 0; | |
727 | } | |
728 | ||
729 | if (cmp < 0) | |
730 | p = &(*p)->rb_left; | |
731 | else | |
732 | p = &(*p)->rb_right; | |
ce7e4365 | 733 | } |
e7fb08b1 PZ |
734 | |
735 | he = malloc(sizeof(*he)); | |
736 | if (!he) | |
737 | return -ENOMEM; | |
738 | *he = entry; | |
739 | rb_link_node(&he->rb_node, parent, p); | |
740 | rb_insert_color(&he->rb_node, &hist); | |
741 | ||
742 | return 0; | |
8fa66bdc ACM |
743 | } |
744 | ||
8229289b PZ |
745 | static void hist_entry__free(struct hist_entry *he) |
746 | { | |
747 | free(he); | |
748 | } | |
749 | ||
750 | /* | |
751 | * collapse the histogram | |
752 | */ | |
753 | ||
754 | static struct rb_root collapse_hists; | |
755 | ||
756 | static void collapse__insert_entry(struct hist_entry *he) | |
757 | { | |
758 | struct rb_node **p = &collapse_hists.rb_node; | |
759 | struct rb_node *parent = NULL; | |
760 | struct hist_entry *iter; | |
761 | int64_t cmp; | |
762 | ||
763 | while (*p != NULL) { | |
764 | parent = *p; | |
765 | iter = rb_entry(parent, struct hist_entry, rb_node); | |
766 | ||
767 | cmp = hist_entry__collapse(iter, he); | |
768 | ||
769 | if (!cmp) { | |
770 | iter->count += he->count; | |
771 | hist_entry__free(he); | |
772 | return; | |
773 | } | |
774 | ||
775 | if (cmp < 0) | |
776 | p = &(*p)->rb_left; | |
777 | else | |
778 | p = &(*p)->rb_right; | |
779 | } | |
780 | ||
781 | rb_link_node(&he->rb_node, parent, p); | |
782 | rb_insert_color(&he->rb_node, &collapse_hists); | |
783 | } | |
784 | ||
785 | static void collapse__resort(void) | |
786 | { | |
787 | struct rb_node *next; | |
788 | struct hist_entry *n; | |
789 | ||
790 | if (!sort__need_collapse) | |
791 | return; | |
792 | ||
793 | next = rb_first(&hist); | |
794 | while (next) { | |
795 | n = rb_entry(next, struct hist_entry, rb_node); | |
796 | next = rb_next(&n->rb_node); | |
797 | ||
798 | rb_erase(&n->rb_node, &hist); | |
799 | collapse__insert_entry(n); | |
800 | } | |
801 | } | |
802 | ||
e7fb08b1 PZ |
803 | /* |
804 | * reverse the map, sort on count. | |
805 | */ | |
806 | ||
807 | static struct rb_root output_hists; | |
808 | ||
809 | static void output__insert_entry(struct hist_entry *he) | |
3a4b8cc7 | 810 | { |
e7fb08b1 | 811 | struct rb_node **p = &output_hists.rb_node; |
3a4b8cc7 | 812 | struct rb_node *parent = NULL; |
e7fb08b1 | 813 | struct hist_entry *iter; |
3a4b8cc7 ACM |
814 | |
815 | while (*p != NULL) { | |
816 | parent = *p; | |
e7fb08b1 | 817 | iter = rb_entry(parent, struct hist_entry, rb_node); |
3a4b8cc7 | 818 | |
e7fb08b1 | 819 | if (he->count > iter->count) |
3a4b8cc7 ACM |
820 | p = &(*p)->rb_left; |
821 | else | |
822 | p = &(*p)->rb_right; | |
823 | } | |
824 | ||
e7fb08b1 PZ |
825 | rb_link_node(&he->rb_node, parent, p); |
826 | rb_insert_color(&he->rb_node, &output_hists); | |
3a4b8cc7 ACM |
827 | } |
828 | ||
e7fb08b1 | 829 | static void output__resort(void) |
3a4b8cc7 | 830 | { |
8229289b | 831 | struct rb_node *next; |
e7fb08b1 | 832 | struct hist_entry *n; |
a4c43bea | 833 | struct rb_root *tree = &hist; |
3a4b8cc7 | 834 | |
8229289b | 835 | if (sort__need_collapse) |
a4c43bea ACM |
836 | tree = &collapse_hists; |
837 | ||
838 | next = rb_first(tree); | |
8229289b | 839 | |
e7fb08b1 PZ |
840 | while (next) { |
841 | n = rb_entry(next, struct hist_entry, rb_node); | |
842 | next = rb_next(&n->rb_node); | |
3a4b8cc7 | 843 | |
a4c43bea | 844 | rb_erase(&n->rb_node, tree); |
e7fb08b1 | 845 | output__insert_entry(n); |
3a4b8cc7 ACM |
846 | } |
847 | } | |
848 | ||
e7fb08b1 | 849 | static size_t output__fprintf(FILE *fp, uint64_t total_samples) |
3a4b8cc7 | 850 | { |
e7fb08b1 | 851 | struct hist_entry *pos; |
2d65537e | 852 | struct sort_entry *se; |
3a4b8cc7 ACM |
853 | struct rb_node *nd; |
854 | size_t ret = 0; | |
855 | ||
71dd8945 | 856 | fprintf(fp, "\n"); |
05ca061e IM |
857 | fprintf(fp, "#\n"); |
858 | fprintf(fp, "# (%Ld profiler events)\n", (__u64)total_samples); | |
ca8cdeef PZ |
859 | fprintf(fp, "#\n"); |
860 | ||
861 | fprintf(fp, "# Overhead"); | |
862 | list_for_each_entry(se, &hist_entry__sort_list, list) | |
71dd8945 | 863 | fprintf(fp, " %s", se->header); |
ca8cdeef PZ |
864 | fprintf(fp, "\n"); |
865 | ||
866 | fprintf(fp, "# ........"); | |
2d65537e | 867 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
ca8cdeef PZ |
868 | int i; |
869 | ||
4593bba8 | 870 | fprintf(fp, " "); |
71dd8945 | 871 | for (i = 0; i < strlen(se->header); i++) |
ca8cdeef | 872 | fprintf(fp, "."); |
2d65537e | 873 | } |
ca8cdeef PZ |
874 | fprintf(fp, "\n"); |
875 | ||
876 | fprintf(fp, "#\n"); | |
2d65537e | 877 | |
e7fb08b1 PZ |
878 | for (nd = rb_first(&output_hists); nd; nd = rb_next(nd)) { |
879 | pos = rb_entry(nd, struct hist_entry, rb_node); | |
880 | ret += hist_entry__fprintf(fp, pos, total_samples); | |
3a4b8cc7 ACM |
881 | } |
882 | ||
bd74137e IM |
883 | if (!strcmp(sort_order, default_sort_order)) { |
884 | fprintf(fp, "#\n"); | |
71dd8945 | 885 | fprintf(fp, "# (For more details, try: perf report --sort comm,dso,symbol)\n"); |
bd74137e IM |
886 | fprintf(fp, "#\n"); |
887 | } | |
71dd8945 | 888 | fprintf(fp, "\n"); |
bd74137e | 889 | |
3a4b8cc7 ACM |
890 | return ret; |
891 | } | |
892 | ||
436224a6 PZ |
893 | static void register_idle_thread(void) |
894 | { | |
895 | struct thread *thread = threads__findnew(0); | |
896 | ||
897 | if (thread == NULL || | |
898 | thread__set_comm(thread, "[idle]")) { | |
899 | fprintf(stderr, "problem inserting idle task.\n"); | |
900 | exit(-1); | |
901 | } | |
902 | } | |
903 | ||
62fc4453 PZ |
904 | static unsigned long total = 0, |
905 | total_mmap = 0, | |
906 | total_comm = 0, | |
907 | total_fork = 0, | |
908 | total_unknown = 0; | |
e7fb08b1 | 909 | |
d80d338d | 910 | static int |
75051724 IM |
911 | process_overflow_event(event_t *event, unsigned long offset, unsigned long head) |
912 | { | |
913 | char level; | |
914 | int show = 0; | |
915 | struct dso *dso = NULL; | |
916 | struct thread *thread = threads__findnew(event->ip.pid); | |
917 | uint64_t ip = event->ip.ip; | |
918 | struct map *map = NULL; | |
919 | ||
920 | dprintf("%p [%p]: PERF_EVENT (IP, %d): %d: %p\n", | |
921 | (void *)(offset + head), | |
922 | (void *)(long)(event->header.size), | |
923 | event->header.misc, | |
924 | event->ip.pid, | |
925 | (void *)(long)ip); | |
926 | ||
927 | dprintf(" ... thread: %s:%d\n", thread->comm, thread->pid); | |
928 | ||
929 | if (thread == NULL) { | |
930 | fprintf(stderr, "problem processing %d event, skipping it.\n", | |
931 | event->header.type); | |
932 | return -1; | |
933 | } | |
e7fb08b1 | 934 | |
75051724 IM |
935 | if (event->header.misc & PERF_EVENT_MISC_KERNEL) { |
936 | show = SHOW_KERNEL; | |
937 | level = 'k'; | |
e7fb08b1 | 938 | |
75051724 | 939 | dso = kernel_dso; |
ed966aac | 940 | |
75051724 | 941 | dprintf(" ...... dso: %s\n", dso->name); |
16f762a2 | 942 | |
75051724 | 943 | } else if (event->header.misc & PERF_EVENT_MISC_USER) { |
16f762a2 | 944 | |
75051724 IM |
945 | show = SHOW_USER; |
946 | level = '.'; | |
e7fb08b1 | 947 | |
75051724 IM |
948 | map = thread__find_map(thread, ip); |
949 | if (map != NULL) { | |
fc54db51 | 950 | ip = map->map_ip(map, ip); |
75051724 | 951 | dso = map->dso; |
8fa66bdc | 952 | } else { |
75051724 IM |
953 | /* |
954 | * If this is outside of all known maps, | |
955 | * and is a negative address, try to look it | |
956 | * up in the kernel dso, as it might be a | |
957 | * vsyscall (which executes in user-mode): | |
958 | */ | |
959 | if ((long long)ip < 0) | |
960 | dso = kernel_dso; | |
8fa66bdc | 961 | } |
75051724 IM |
962 | dprintf(" ...... dso: %s\n", dso ? dso->name : "<not found>"); |
963 | ||
964 | } else { | |
965 | show = SHOW_HV; | |
966 | level = 'H'; | |
967 | dprintf(" ...... dso: [hypervisor]\n"); | |
968 | } | |
8fa66bdc | 969 | |
75051724 | 970 | if (show & show_mask) { |
fc54db51 PZ |
971 | struct symbol *sym = NULL; |
972 | ||
973 | if (dso) | |
974 | sym = dso->find_symbol(dso, ip); | |
8fa66bdc | 975 | |
75051724 IM |
976 | if (hist_entry__add(thread, map, dso, sym, ip, level)) { |
977 | fprintf(stderr, | |
55717314 | 978 | "problem incrementing symbol count, skipping event\n"); |
d80d338d | 979 | return -1; |
ce7e4365 | 980 | } |
8fa66bdc | 981 | } |
75051724 | 982 | total++; |
8fa66bdc | 983 | |
75051724 IM |
984 | return 0; |
985 | } | |
3502973d | 986 | |
75051724 IM |
987 | static int |
988 | process_mmap_event(event_t *event, unsigned long offset, unsigned long head) | |
989 | { | |
990 | struct thread *thread = threads__findnew(event->mmap.pid); | |
991 | struct map *map = map__new(&event->mmap); | |
992 | ||
62fc4453 | 993 | dprintf("%p [%p]: PERF_EVENT_MMAP %d: [%p(%p) @ %p]: %s\n", |
75051724 IM |
994 | (void *)(offset + head), |
995 | (void *)(long)(event->header.size), | |
62fc4453 | 996 | event->mmap.pid, |
75051724 IM |
997 | (void *)(long)event->mmap.start, |
998 | (void *)(long)event->mmap.len, | |
999 | (void *)(long)event->mmap.pgoff, | |
1000 | event->mmap.filename); | |
1001 | ||
1002 | if (thread == NULL || map == NULL) { | |
1003 | dprintf("problem processing PERF_EVENT_MMAP, skipping event.\n"); | |
df97992c | 1004 | return 0; |
75051724 IM |
1005 | } |
1006 | ||
1007 | thread__insert_map(thread, map); | |
1008 | total_mmap++; | |
1009 | ||
1010 | return 0; | |
1011 | } | |
1012 | ||
1013 | static int | |
1014 | process_comm_event(event_t *event, unsigned long offset, unsigned long head) | |
1015 | { | |
1016 | struct thread *thread = threads__findnew(event->comm.pid); | |
1017 | ||
1018 | dprintf("%p [%p]: PERF_EVENT_COMM: %s:%d\n", | |
1019 | (void *)(offset + head), | |
1020 | (void *)(long)(event->header.size), | |
1021 | event->comm.comm, event->comm.pid); | |
1022 | ||
1023 | if (thread == NULL || | |
1024 | thread__set_comm(thread, event->comm.comm)) { | |
1025 | dprintf("problem processing PERF_EVENT_COMM, skipping event.\n"); | |
1026 | return -1; | |
8fa66bdc | 1027 | } |
75051724 IM |
1028 | total_comm++; |
1029 | ||
1030 | return 0; | |
1031 | } | |
1032 | ||
62fc4453 PZ |
1033 | static int |
1034 | process_fork_event(event_t *event, unsigned long offset, unsigned long head) | |
1035 | { | |
1036 | struct thread *thread = threads__findnew(event->fork.pid); | |
1037 | struct thread *parent = threads__findnew(event->fork.ppid); | |
1038 | ||
1039 | dprintf("%p [%p]: PERF_EVENT_FORK: %d:%d\n", | |
1040 | (void *)(offset + head), | |
1041 | (void *)(long)(event->header.size), | |
1042 | event->fork.pid, event->fork.ppid); | |
1043 | ||
1044 | if (!thread || !parent || thread__fork(thread, parent)) { | |
1045 | dprintf("problem processing PERF_EVENT_FORK, skipping event.\n"); | |
1046 | return -1; | |
1047 | } | |
1048 | total_fork++; | |
1049 | ||
1050 | return 0; | |
1051 | } | |
1052 | ||
75051724 IM |
1053 | static int |
1054 | process_event(event_t *event, unsigned long offset, unsigned long head) | |
1055 | { | |
1056 | if (event->header.misc & PERF_EVENT_MISC_OVERFLOW) | |
1057 | return process_overflow_event(event, offset, head); | |
1058 | ||
1059 | switch (event->header.type) { | |
1060 | case PERF_EVENT_MMAP: | |
1061 | return process_mmap_event(event, offset, head); | |
1062 | ||
1063 | case PERF_EVENT_COMM: | |
1064 | return process_comm_event(event, offset, head); | |
1065 | ||
62fc4453 PZ |
1066 | case PERF_EVENT_FORK: |
1067 | return process_fork_event(event, offset, head); | |
1068 | ||
d11444df IM |
1069 | /* |
1070 | * We dont process them right now but they are fine: | |
1071 | */ | |
62fc4453 | 1072 | |
d11444df IM |
1073 | case PERF_EVENT_PERIOD: |
1074 | case PERF_EVENT_THROTTLE: | |
1075 | case PERF_EVENT_UNTHROTTLE: | |
1076 | return 0; | |
1077 | ||
d80d338d IM |
1078 | default: |
1079 | return -1; | |
1080 | } | |
1081 | ||
1082 | return 0; | |
1083 | } | |
1084 | ||
1085 | static int __cmd_report(void) | |
1086 | { | |
75051724 | 1087 | int ret, rc = EXIT_FAILURE; |
d80d338d IM |
1088 | unsigned long offset = 0; |
1089 | unsigned long head = 0; | |
1090 | struct stat stat; | |
d80d338d | 1091 | event_t *event; |
d80d338d | 1092 | uint32_t size; |
75051724 | 1093 | char *buf; |
d80d338d IM |
1094 | |
1095 | register_idle_thread(); | |
1096 | ||
1097 | input = open(input_name, O_RDONLY); | |
1098 | if (input < 0) { | |
1099 | perror("failed to open file"); | |
1100 | exit(-1); | |
1101 | } | |
1102 | ||
1103 | ret = fstat(input, &stat); | |
1104 | if (ret < 0) { | |
1105 | perror("failed to stat file"); | |
1106 | exit(-1); | |
1107 | } | |
1108 | ||
1109 | if (!stat.st_size) { | |
1110 | fprintf(stderr, "zero-sized file, nothing to do!\n"); | |
1111 | exit(0); | |
1112 | } | |
1113 | ||
1114 | if (load_kernel() < 0) { | |
1115 | perror("failed to load kernel symbols"); | |
1116 | return EXIT_FAILURE; | |
1117 | } | |
1118 | ||
1119 | if (!full_paths) { | |
1120 | if (getcwd(__cwd, sizeof(__cwd)) == NULL) { | |
1121 | perror("failed to get the current directory"); | |
1122 | return EXIT_FAILURE; | |
1123 | } | |
1124 | cwdlen = strlen(cwd); | |
1125 | } else { | |
1126 | cwd = NULL; | |
1127 | cwdlen = 0; | |
1128 | } | |
1129 | remap: | |
1130 | buf = (char *)mmap(NULL, page_size * mmap_window, PROT_READ, | |
1131 | MAP_SHARED, input, offset); | |
1132 | if (buf == MAP_FAILED) { | |
1133 | perror("failed to mmap file"); | |
1134 | exit(-1); | |
1135 | } | |
1136 | ||
1137 | more: | |
1138 | event = (event_t *)(buf + head); | |
1139 | ||
1140 | size = event->header.size; | |
1141 | if (!size) | |
1142 | size = 8; | |
1143 | ||
1144 | if (head + event->header.size >= page_size * mmap_window) { | |
1145 | unsigned long shift = page_size * (head / page_size); | |
1146 | int ret; | |
1147 | ||
1148 | ret = munmap(buf, page_size * mmap_window); | |
1149 | assert(ret == 0); | |
1150 | ||
1151 | offset += shift; | |
1152 | head -= shift; | |
1153 | goto remap; | |
1154 | } | |
1155 | ||
1156 | size = event->header.size; | |
1157 | ||
1158 | if (!size || process_event(event, offset, head) < 0) { | |
1159 | ||
3502973d IM |
1160 | dprintf("%p [%p]: skipping unknown header type: %d\n", |
1161 | (void *)(offset + head), | |
1162 | (void *)(long)(event->header.size), | |
1163 | event->header.type); | |
b7a16eac | 1164 | |
3e706114 | 1165 | total_unknown++; |
6142f9ec PZ |
1166 | |
1167 | /* | |
1168 | * assume we lost track of the stream, check alignment, and | |
1169 | * increment a single u64 in the hope to catch on again 'soon'. | |
1170 | */ | |
1171 | ||
1172 | if (unlikely(head & 7)) | |
1173 | head &= ~7ULL; | |
1174 | ||
1175 | size = 8; | |
97b07b69 | 1176 | } |
8fa66bdc | 1177 | |
6142f9ec | 1178 | head += size; |
f49515b1 | 1179 | |
8fa66bdc ACM |
1180 | if (offset + head < stat.st_size) |
1181 | goto more; | |
1182 | ||
1183 | rc = EXIT_SUCCESS; | |
8fa66bdc | 1184 | close(input); |
97b07b69 | 1185 | |
3502973d IM |
1186 | dprintf(" IP events: %10ld\n", total); |
1187 | dprintf(" mmap events: %10ld\n", total_mmap); | |
1188 | dprintf(" comm events: %10ld\n", total_comm); | |
62fc4453 | 1189 | dprintf(" fork events: %10ld\n", total_fork); |
3502973d | 1190 | dprintf(" unknown events: %10ld\n", total_unknown); |
97b07b69 | 1191 | |
3502973d | 1192 | if (dump_trace) |
97b07b69 | 1193 | return 0; |
97b07b69 | 1194 | |
9ac99545 ACM |
1195 | if (verbose >= 3) |
1196 | threads__fprintf(stdout); | |
1197 | ||
e7fb08b1 | 1198 | if (verbose >= 2) |
16f762a2 | 1199 | dsos__fprintf(stdout); |
16f762a2 | 1200 | |
8229289b | 1201 | collapse__resort(); |
e7fb08b1 PZ |
1202 | output__resort(); |
1203 | output__fprintf(stdout, total); | |
8fa66bdc | 1204 | |
8fa66bdc ACM |
1205 | return rc; |
1206 | } | |
1207 | ||
53cb8bc2 IM |
1208 | static const char * const report_usage[] = { |
1209 | "perf report [<options>] <command>", | |
1210 | NULL | |
1211 | }; | |
1212 | ||
1213 | static const struct option options[] = { | |
1214 | OPT_STRING('i', "input", &input_name, "file", | |
1215 | "input file name"), | |
815e777f ACM |
1216 | OPT_BOOLEAN('v', "verbose", &verbose, |
1217 | "be more verbose (show symbol address, etc)"), | |
97b07b69 IM |
1218 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, |
1219 | "dump raw trace in ASCII"), | |
450aaa2b | 1220 | OPT_STRING('k', "vmlinux", &vmlinux, "file", "vmlinux pathname"), |
63299f05 IM |
1221 | OPT_STRING('s', "sort", &sort_order, "key[,key2...]", |
1222 | "sort by key(s): pid, comm, dso, symbol. Default: pid,symbol"), | |
b78c07d4 ACM |
1223 | OPT_BOOLEAN('P', "full-paths", &full_paths, |
1224 | "Don't shorten the pathnames taking into account the cwd"), | |
53cb8bc2 IM |
1225 | OPT_END() |
1226 | }; | |
1227 | ||
5352f35d IM |
1228 | static void setup_sorting(void) |
1229 | { | |
1230 | char *tmp, *tok, *str = strdup(sort_order); | |
1231 | ||
1232 | for (tok = strtok_r(str, ", ", &tmp); | |
1233 | tok; tok = strtok_r(NULL, ", ", &tmp)) { | |
1234 | if (sort_dimension__add(tok) < 0) { | |
1235 | error("Unknown --sort key: `%s'", tok); | |
1236 | usage_with_options(report_usage, options); | |
1237 | } | |
1238 | } | |
1239 | ||
1240 | free(str); | |
1241 | } | |
1242 | ||
53cb8bc2 IM |
1243 | int cmd_report(int argc, const char **argv, const char *prefix) |
1244 | { | |
a2928c42 | 1245 | symbol__init(); |
53cb8bc2 IM |
1246 | |
1247 | page_size = getpagesize(); | |
1248 | ||
edc52dea | 1249 | argc = parse_options(argc, argv, options, report_usage, 0); |
53cb8bc2 | 1250 | |
1aa16738 PZ |
1251 | setup_sorting(); |
1252 | ||
edc52dea IM |
1253 | /* |
1254 | * Any (unrecognized) arguments left? | |
1255 | */ | |
1256 | if (argc) | |
1257 | usage_with_options(report_usage, options); | |
1258 | ||
a930d2c0 IM |
1259 | setup_pager(); |
1260 | ||
53cb8bc2 IM |
1261 | return __cmd_report(); |
1262 | } |