blob: 33b3b15fb014a873a59d764b6243e6b68cdf10a7 [file] [log] [blame]
Ingo Molnarbf9e1872009-06-02 23:37:05 +02001/*
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 */
Ingo Molnar16f762a2009-05-27 09:10:38 +02008#include "builtin.h"
Ingo Molnar53cb8bc2009-05-26 09:17:18 +02009
Ingo Molnarbf9e1872009-06-02 23:37:05 +020010#include "util/util.h"
11
Arnaldo Carvalho de Melo35a50c82009-05-18 16:24:49 -030012#include "util/list.h"
Ingo Molnara930d2c2009-05-27 09:50:13 +020013#include "util/cache.h"
Arnaldo Carvalho de Melo35a50c82009-05-18 16:24:49 -030014#include "util/rbtree.h"
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -030015#include "util/symbol.h"
Arnaldo Carvalho de Meloa0055ae2009-06-01 17:50:19 -030016#include "util/string.h"
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -030017
Ingo Molnar53cb8bc2009-05-26 09:17:18 +020018#include "perf.h"
19
20#include "util/parse-options.h"
21#include "util/parse-events.h"
22
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -030023#define SHOW_KERNEL 1
24#define SHOW_USER 2
25#define SHOW_HV 4
26
Ingo Molnar23ac9cb2009-05-27 09:33:18 +020027static char const *input_name = "perf.data";
Peter Zijlstra450aaa22009-05-27 20:20:23 +020028static char *vmlinux = NULL;
Peter Zijlstraf70e87d2009-06-02 14:13:24 +020029static char *sort_order = "comm,dso";
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -030030static int input;
31static int show_mask = SHOW_KERNEL | SHOW_USER | SHOW_HV;
32
Ingo Molnar97b07b62009-05-26 18:48:58 +020033static int dump_trace = 0;
Ingo Molnar35029732009-06-03 09:38:58 +020034#define dprintf(x...) do { if (dump_trace) printf(x); } while (0)
35
Ingo Molnar16f762a2009-05-27 09:10:38 +020036static int verbose;
Arnaldo Carvalho de Melob78c07d2009-05-29 13:48:59 -030037static int full_paths;
Ingo Molnar97b07b62009-05-26 18:48:58 +020038
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -030039static unsigned long page_size;
40static unsigned long mmap_window = 32;
41
Ingo Molnar53cb8bc2009-05-26 09:17:18 +020042const char *perf_event_names[] = {
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -030043 [PERF_EVENT_MMAP] = " PERF_EVENT_MMAP",
44 [PERF_EVENT_MUNMAP] = " PERF_EVENT_MUNMAP",
45 [PERF_EVENT_COMM] = " PERF_EVENT_COMM",
46};
47
48struct ip_event {
49 struct perf_event_header header;
50 __u64 ip;
51 __u32 pid, tid;
52};
53struct mmap_event {
54 struct perf_event_header header;
55 __u32 pid, tid;
56 __u64 start;
57 __u64 len;
58 __u64 pgoff;
59 char filename[PATH_MAX];
60};
61struct comm_event {
62 struct perf_event_header header;
63 __u32 pid,tid;
64 char comm[16];
65};
66
67typedef union event_union {
68 struct perf_event_header header;
69 struct ip_event ip;
70 struct mmap_event mmap;
71 struct comm_event comm;
72} event_t;
73
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -030074static LIST_HEAD(dsos);
75static struct dso *kernel_dso;
76
77static void dsos__add(struct dso *dso)
78{
79 list_add_tail(&dso->node, &dsos);
80}
81
82static struct dso *dsos__find(const char *name)
83{
84 struct dso *pos;
85
86 list_for_each_entry(pos, &dsos, node)
87 if (strcmp(pos->name, name) == 0)
88 return pos;
89 return NULL;
90}
91
92static struct dso *dsos__findnew(const char *name)
93{
94 struct dso *dso = dsos__find(name);
Peter Zijlstrab7a16ea2009-05-27 13:35:35 +020095 int nr;
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -030096
Ingo Molnar4593bba2009-06-02 15:34:25 +020097 if (dso)
98 return dso;
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -030099
Ingo Molnar4593bba2009-06-02 15:34:25 +0200100 dso = dso__new(name, 0);
101 if (!dso)
102 goto out_delete_dso;
Peter Zijlstrab7a16ea2009-05-27 13:35:35 +0200103
Ingo Molnar4593bba2009-06-02 15:34:25 +0200104 nr = dso__load(dso, NULL);
105 if (nr < 0) {
106 fprintf(stderr, "Failed to open: %s\n", name);
107 goto out_delete_dso;
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300108 }
Ingo Molnar4593bba2009-06-02 15:34:25 +0200109 if (!nr && verbose) {
110 fprintf(stderr,
111 "No symbols found in: %s, maybe install a debug package?\n",
112 name);
113 }
114
115 dsos__add(dso);
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300116
117 return dso;
118
119out_delete_dso:
120 dso__delete(dso);
121 return NULL;
122}
123
Ingo Molnar16f762a2009-05-27 09:10:38 +0200124static void dsos__fprintf(FILE *fp)
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300125{
126 struct dso *pos;
127
128 list_for_each_entry(pos, &dsos, node)
129 dso__fprintf(pos, fp);
130}
131
Peter Zijlstra450aaa22009-05-27 20:20:23 +0200132static int load_kernel(void)
133{
Arnaldo Carvalho de Meloa827c872009-05-28 14:55:19 -0300134 int err;
Peter Zijlstra450aaa22009-05-27 20:20:23 +0200135
Arnaldo Carvalho de Melo0085c952009-05-28 14:55:13 -0300136 kernel_dso = dso__new("[kernel]", 0);
Peter Zijlstra450aaa22009-05-27 20:20:23 +0200137 if (!kernel_dso)
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -0300138 return -1;
Peter Zijlstra450aaa22009-05-27 20:20:23 +0200139
Arnaldo Carvalho de Melo69ee69f2009-05-28 14:55:26 -0300140 err = dso__load_kernel(kernel_dso, vmlinux, NULL);
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -0300141 if (err) {
142 dso__delete(kernel_dso);
143 kernel_dso = NULL;
144 } else
145 dsos__add(kernel_dso);
Peter Zijlstra450aaa22009-05-27 20:20:23 +0200146
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -0300147 return err;
Peter Zijlstra450aaa22009-05-27 20:20:23 +0200148}
149
Arnaldo Carvalho de Melob78c07d2009-05-29 13:48:59 -0300150static int strcommon(const char *pathname, const char *cwd, int cwdlen)
151{
152 int n = 0;
153
154 while (pathname[n] == cwd[n] && n < cwdlen)
155 ++n;
156
157 return n;
158}
159
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300160struct map {
161 struct list_head node;
162 uint64_t start;
163 uint64_t end;
164 uint64_t pgoff;
165 struct dso *dso;
166};
167
Arnaldo Carvalho de Melob78c07d2009-05-29 13:48:59 -0300168static struct map *map__new(struct mmap_event *event, char *cwd, int cwdlen)
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300169{
170 struct map *self = malloc(sizeof(*self));
171
172 if (self != NULL) {
Arnaldo Carvalho de Melob78c07d2009-05-29 13:48:59 -0300173 const char *filename = event->filename;
174 char newfilename[PATH_MAX];
175
176 if (cwd) {
177 int n = strcommon(filename, cwd, cwdlen);
178 if (n == cwdlen) {
179 snprintf(newfilename, sizeof(newfilename),
180 ".%s", filename + n);
181 filename = newfilename;
182 }
183 }
184
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300185 self->start = event->start;
186 self->end = event->start + event->len;
187 self->pgoff = event->pgoff;
188
Arnaldo Carvalho de Melob78c07d2009-05-29 13:48:59 -0300189 self->dso = dsos__findnew(filename);
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300190 if (self->dso == NULL)
191 goto out_delete;
192 }
193 return self;
194out_delete:
195 free(self);
196 return NULL;
197}
198
Arnaldo Carvalho de Melo3a4b8cc2009-05-26 16:19:04 -0300199struct thread;
200
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300201struct thread {
Arnaldo Carvalho de Meloce7e4362009-05-19 09:30:23 -0300202 struct rb_node rb_node;
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300203 struct list_head maps;
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300204 pid_t pid;
205 char *comm;
206};
207
208static struct thread *thread__new(pid_t pid)
209{
210 struct thread *self = malloc(sizeof(*self));
211
212 if (self != NULL) {
213 self->pid = pid;
Peter Zijlstra82292892009-06-03 12:37:36 +0200214 self->comm = malloc(32);
Ingo Molnar0a520c62009-06-02 23:24:45 +0200215 if (self->comm)
Peter Zijlstra82292892009-06-03 12:37:36 +0200216 snprintf(self->comm, 32, ":%d", self->pid);
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300217 INIT_LIST_HEAD(&self->maps);
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300218 }
219
220 return self;
221}
222
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300223static int thread__set_comm(struct thread *self, const char *comm)
224{
Peter Zijlstra82292892009-06-03 12:37:36 +0200225 if (self->comm)
226 free(self->comm);
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300227 self->comm = strdup(comm);
228 return self->comm ? 0 : -ENOMEM;
229}
230
Ingo Molnar16f762a2009-05-27 09:10:38 +0200231static struct rb_root threads;
Ingo Molnareed4dcd2009-06-03 19:59:24 +0200232static struct thread *last_match;
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300233
234static struct thread *threads__findnew(pid_t pid)
235{
Arnaldo Carvalho de Meloce7e4362009-05-19 09:30:23 -0300236 struct rb_node **p = &threads.rb_node;
237 struct rb_node *parent = NULL;
238 struct thread *th;
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300239
Ingo Molnareed4dcd2009-06-03 19:59:24 +0200240 /*
241 * Font-end cache - PID lookups come in blocks,
242 * so most of the time we dont have to look up
243 * the full rbtree:
244 */
245 if (last_match && last_match->pid == pid)
246 return last_match;
247
Arnaldo Carvalho de Meloce7e4362009-05-19 09:30:23 -0300248 while (*p != NULL) {
249 parent = *p;
250 th = rb_entry(parent, struct thread, rb_node);
251
Ingo Molnareed4dcd2009-06-03 19:59:24 +0200252 if (th->pid == pid) {
253 last_match = th;
Arnaldo Carvalho de Meloce7e4362009-05-19 09:30:23 -0300254 return th;
Ingo Molnareed4dcd2009-06-03 19:59:24 +0200255 }
Arnaldo Carvalho de Meloce7e4362009-05-19 09:30:23 -0300256
257 if (pid < th->pid)
258 p = &(*p)->rb_left;
259 else
260 p = &(*p)->rb_right;
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300261 }
262
Arnaldo Carvalho de Meloce7e4362009-05-19 09:30:23 -0300263 th = thread__new(pid);
264 if (th != NULL) {
265 rb_link_node(&th->rb_node, parent, p);
266 rb_insert_color(&th->rb_node, &threads);
Ingo Molnareed4dcd2009-06-03 19:59:24 +0200267 last_match = th;
Arnaldo Carvalho de Meloce7e4362009-05-19 09:30:23 -0300268 }
Ingo Molnareed4dcd2009-06-03 19:59:24 +0200269
Arnaldo Carvalho de Meloce7e4362009-05-19 09:30:23 -0300270 return th;
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300271}
272
273static void thread__insert_map(struct thread *self, struct map *map)
274{
275 list_add_tail(&map->node, &self->maps);
276}
277
278static struct map *thread__find_map(struct thread *self, uint64_t ip)
279{
Ingo Molnar16f762a2009-05-27 09:10:38 +0200280 struct map *pos;
281
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300282 if (self == NULL)
283 return NULL;
284
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300285 list_for_each_entry(pos, &self->maps, node)
286 if (ip >= pos->start && ip <= pos->end)
287 return pos;
288
289 return NULL;
290}
291
Peter Zijlstrae7fb08b2009-05-27 20:20:24 +0200292/*
293 * histogram, sorted on item, collects counts
294 */
295
296static struct rb_root hist;
297
298struct hist_entry {
299 struct rb_node rb_node;
300
301 struct thread *thread;
302 struct map *map;
303 struct dso *dso;
304 struct symbol *sym;
305 uint64_t ip;
306 char level;
307
308 uint32_t count;
309};
310
Peter Zijlstra1aa16732009-05-27 20:20:25 +0200311/*
312 * configurable sorting bits
313 */
314
315struct sort_entry {
316 struct list_head list;
317
Peter Zijlstraca8cdee2009-05-28 11:08:33 +0200318 char *header;
319
Peter Zijlstra1aa16732009-05-27 20:20:25 +0200320 int64_t (*cmp)(struct hist_entry *, struct hist_entry *);
Peter Zijlstra82292892009-06-03 12:37:36 +0200321 int64_t (*collapse)(struct hist_entry *, struct hist_entry *);
Peter Zijlstra1aa16732009-05-27 20:20:25 +0200322 size_t (*print)(FILE *fp, struct hist_entry *);
323};
324
Peter Zijlstra82292892009-06-03 12:37:36 +0200325/* --sort pid */
326
Peter Zijlstrae7fb08b2009-05-27 20:20:24 +0200327static int64_t
Peter Zijlstra1aa16732009-05-27 20:20:25 +0200328sort__thread_cmp(struct hist_entry *left, struct hist_entry *right)
329{
330 return right->thread->pid - left->thread->pid;
331}
332
333static size_t
334sort__thread_print(FILE *fp, struct hist_entry *self)
335{
Ingo Molnarcf25c632009-06-02 22:12:14 +0200336 return fprintf(fp, " %16s:%5d", self->thread->comm ?: "", self->thread->pid);
Peter Zijlstra1aa16732009-05-27 20:20:25 +0200337}
338
339static struct sort_entry sort_thread = {
Ingo Molnarcf25c632009-06-02 22:12:14 +0200340 .header = " Command: Pid ",
Peter Zijlstra1aa16732009-05-27 20:20:25 +0200341 .cmp = sort__thread_cmp,
342 .print = sort__thread_print,
343};
344
Peter Zijlstra82292892009-06-03 12:37:36 +0200345/* --sort comm */
346
Peter Zijlstra1aa16732009-05-27 20:20:25 +0200347static int64_t
Peter Zijlstra992444b2009-05-27 20:20:27 +0200348sort__comm_cmp(struct hist_entry *left, struct hist_entry *right)
349{
Peter Zijlstra82292892009-06-03 12:37:36 +0200350 return right->thread->pid - left->thread->pid;
351}
352
353static int64_t
354sort__comm_collapse(struct hist_entry *left, struct hist_entry *right)
355{
Peter Zijlstra992444b2009-05-27 20:20:27 +0200356 char *comm_l = left->thread->comm;
357 char *comm_r = right->thread->comm;
358
359 if (!comm_l || !comm_r) {
360 if (!comm_l && !comm_r)
361 return 0;
362 else if (!comm_l)
363 return -1;
364 else
365 return 1;
366 }
367
368 return strcmp(comm_l, comm_r);
369}
370
371static size_t
372sort__comm_print(FILE *fp, struct hist_entry *self)
373{
Ingo Molnar0a520c62009-06-02 23:24:45 +0200374 return fprintf(fp, " %16s", self->thread->comm);
Peter Zijlstra992444b2009-05-27 20:20:27 +0200375}
376
377static struct sort_entry sort_comm = {
Peter Zijlstra82292892009-06-03 12:37:36 +0200378 .header = " Command",
379 .cmp = sort__comm_cmp,
380 .collapse = sort__comm_collapse,
381 .print = sort__comm_print,
Peter Zijlstra992444b2009-05-27 20:20:27 +0200382};
383
Peter Zijlstra82292892009-06-03 12:37:36 +0200384/* --sort dso */
385
Peter Zijlstra992444b2009-05-27 20:20:27 +0200386static int64_t
Peter Zijlstra55e5ec42009-05-27 20:20:28 +0200387sort__dso_cmp(struct hist_entry *left, struct hist_entry *right)
388{
389 struct dso *dso_l = left->dso;
390 struct dso *dso_r = right->dso;
391
392 if (!dso_l || !dso_r) {
393 if (!dso_l && !dso_r)
394 return 0;
395 else if (!dso_l)
396 return -1;
397 else
398 return 1;
399 }
400
401 return strcmp(dso_l->name, dso_r->name);
402}
403
404static size_t
405sort__dso_print(FILE *fp, struct hist_entry *self)
406{
Ingo Molnar0a520c62009-06-02 23:24:45 +0200407 if (self->dso)
408 return fprintf(fp, " %-25s", self->dso->name);
409
410 return fprintf(fp, " %016llx", (__u64)self->ip);
Peter Zijlstra55e5ec42009-05-27 20:20:28 +0200411}
412
413static struct sort_entry sort_dso = {
Ingo Molnarcf25c632009-06-02 22:12:14 +0200414 .header = " Shared Object ",
Peter Zijlstra55e5ec42009-05-27 20:20:28 +0200415 .cmp = sort__dso_cmp,
416 .print = sort__dso_print,
417};
418
Peter Zijlstra82292892009-06-03 12:37:36 +0200419/* --sort symbol */
420
Peter Zijlstra55e5ec42009-05-27 20:20:28 +0200421static int64_t
Peter Zijlstra1aa16732009-05-27 20:20:25 +0200422sort__sym_cmp(struct hist_entry *left, struct hist_entry *right)
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300423{
Peter Zijlstrae7fb08b2009-05-27 20:20:24 +0200424 uint64_t ip_l, ip_r;
Peter Zijlstrae7fb08b2009-05-27 20:20:24 +0200425
426 if (left->sym == right->sym)
427 return 0;
428
429 ip_l = left->sym ? left->sym->start : left->ip;
430 ip_r = right->sym ? right->sym->start : right->ip;
431
432 return (int64_t)(ip_r - ip_l);
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300433}
434
Peter Zijlstra1aa16732009-05-27 20:20:25 +0200435static size_t
436sort__sym_print(FILE *fp, struct hist_entry *self)
437{
438 size_t ret = 0;
439
Peter Zijlstra1aa16732009-05-27 20:20:25 +0200440 if (verbose)
Ingo Molnar0a520c62009-06-02 23:24:45 +0200441 ret += fprintf(fp, " %#018llx", (__u64)self->ip);
Peter Zijlstra1aa16732009-05-27 20:20:25 +0200442
Ingo Molnar0a520c62009-06-02 23:24:45 +0200443 if (self->dso)
444 ret += fprintf(fp, " %s: ", self->dso->name);
445 else
446 ret += fprintf(fp, " %#016llx: ", (__u64)self->ip);
447
448 if (self->sym)
449 ret += fprintf(fp, "%s", self->sym->name);
450 else
451 ret += fprintf(fp, "%#016llx", (__u64)self->ip);
Peter Zijlstra1aa16732009-05-27 20:20:25 +0200452
453 return ret;
454}
455
456static struct sort_entry sort_sym = {
Ingo Molnar4593bba2009-06-02 15:34:25 +0200457 .header = " Shared Object: Symbol",
Peter Zijlstraca8cdee2009-05-28 11:08:33 +0200458 .cmp = sort__sym_cmp,
459 .print = sort__sym_print,
Peter Zijlstra1aa16732009-05-27 20:20:25 +0200460};
461
Peter Zijlstra82292892009-06-03 12:37:36 +0200462static int sort__need_collapse = 0;
463
Peter Zijlstra37f440c2009-05-27 20:20:26 +0200464struct sort_dimension {
465 char *name;
466 struct sort_entry *entry;
467 int taken;
468};
469
470static struct sort_dimension sort_dimensions[] = {
471 { .name = "pid", .entry = &sort_thread, },
Peter Zijlstra992444b2009-05-27 20:20:27 +0200472 { .name = "comm", .entry = &sort_comm, },
Peter Zijlstra55e5ec42009-05-27 20:20:28 +0200473 { .name = "dso", .entry = &sort_dso, },
Peter Zijlstra37f440c2009-05-27 20:20:26 +0200474 { .name = "symbol", .entry = &sort_sym, },
475};
476
Peter Zijlstra1aa16732009-05-27 20:20:25 +0200477static LIST_HEAD(hist_entry__sort_list);
478
Peter Zijlstra37f440c2009-05-27 20:20:26 +0200479static int sort_dimension__add(char *tok)
480{
481 int i;
482
483 for (i = 0; i < ARRAY_SIZE(sort_dimensions); i++) {
484 struct sort_dimension *sd = &sort_dimensions[i];
485
486 if (sd->taken)
487 continue;
488
Ingo Molnar5352f352009-06-03 10:07:39 +0200489 if (strncasecmp(tok, sd->name, strlen(tok)))
Peter Zijlstra37f440c2009-05-27 20:20:26 +0200490 continue;
491
Peter Zijlstra82292892009-06-03 12:37:36 +0200492 if (sd->entry->collapse)
493 sort__need_collapse = 1;
494
Peter Zijlstra37f440c2009-05-27 20:20:26 +0200495 list_add_tail(&sd->entry->list, &hist_entry__sort_list);
496 sd->taken = 1;
Ingo Molnar5352f352009-06-03 10:07:39 +0200497
Peter Zijlstra37f440c2009-05-27 20:20:26 +0200498 return 0;
499 }
500
501 return -ESRCH;
502}
503
Peter Zijlstra1aa16732009-05-27 20:20:25 +0200504static int64_t
505hist_entry__cmp(struct hist_entry *left, struct hist_entry *right)
506{
507 struct sort_entry *se;
508 int64_t cmp = 0;
509
510 list_for_each_entry(se, &hist_entry__sort_list, list) {
511 cmp = se->cmp(left, right);
512 if (cmp)
513 break;
514 }
515
516 return cmp;
517}
518
Peter Zijlstra82292892009-06-03 12:37:36 +0200519static int64_t
520hist_entry__collapse(struct hist_entry *left, struct hist_entry *right)
521{
522 struct sort_entry *se;
523 int64_t cmp = 0;
524
525 list_for_each_entry(se, &hist_entry__sort_list, list) {
526 int64_t (*f)(struct hist_entry *, struct hist_entry *);
527
528 f = se->collapse ?: se->cmp;
529
530 cmp = f(left, right);
531 if (cmp)
532 break;
533 }
534
535 return cmp;
536}
537
Peter Zijlstra1aa16732009-05-27 20:20:25 +0200538static size_t
539hist_entry__fprintf(FILE *fp, struct hist_entry *self, uint64_t total_samples)
540{
541 struct sort_entry *se;
542 size_t ret;
543
544 if (total_samples) {
Ingo Molnare98e96f2009-06-03 19:30:38 +0200545 ret = fprintf(fp, " %6.2f%%",
Peter Zijlstra1aa16732009-05-27 20:20:25 +0200546 (self->count * 100.0) / total_samples);
547 } else
548 ret = fprintf(fp, "%12d ", self->count);
549
550 list_for_each_entry(se, &hist_entry__sort_list, list)
551 ret += se->print(fp, self);
552
553 ret += fprintf(fp, "\n");
554
555 return ret;
556}
557
558/*
559 * collect histogram counts
560 */
561
Peter Zijlstrae7fb08b2009-05-27 20:20:24 +0200562static int
563hist_entry__add(struct thread *thread, struct map *map, struct dso *dso,
564 struct symbol *sym, uint64_t ip, char level)
Arnaldo Carvalho de Melo3a4b8cc2009-05-26 16:19:04 -0300565{
Peter Zijlstrae7fb08b2009-05-27 20:20:24 +0200566 struct rb_node **p = &hist.rb_node;
Arnaldo Carvalho de Melo3a4b8cc2009-05-26 16:19:04 -0300567 struct rb_node *parent = NULL;
Peter Zijlstrae7fb08b2009-05-27 20:20:24 +0200568 struct hist_entry *he;
569 struct hist_entry entry = {
570 .thread = thread,
571 .map = map,
572 .dso = dso,
573 .sym = sym,
574 .ip = ip,
575 .level = level,
576 .count = 1,
577 };
578 int cmp;
Arnaldo Carvalho de Melo3a4b8cc2009-05-26 16:19:04 -0300579
580 while (*p != NULL) {
581 parent = *p;
Peter Zijlstrae7fb08b2009-05-27 20:20:24 +0200582 he = rb_entry(parent, struct hist_entry, rb_node);
Arnaldo Carvalho de Melo3a4b8cc2009-05-26 16:19:04 -0300583
Peter Zijlstrae7fb08b2009-05-27 20:20:24 +0200584 cmp = hist_entry__cmp(&entry, he);
585
586 if (!cmp) {
587 he->count++;
588 return 0;
589 }
590
591 if (cmp < 0)
Arnaldo Carvalho de Melo3a4b8cc2009-05-26 16:19:04 -0300592 p = &(*p)->rb_left;
593 else
594 p = &(*p)->rb_right;
595 }
596
Peter Zijlstrae7fb08b2009-05-27 20:20:24 +0200597 he = malloc(sizeof(*he));
598 if (!he)
599 return -ENOMEM;
600 *he = entry;
601 rb_link_node(&he->rb_node, parent, p);
602 rb_insert_color(&he->rb_node, &hist);
603
604 return 0;
Arnaldo Carvalho de Melo3a4b8cc2009-05-26 16:19:04 -0300605}
606
Peter Zijlstra82292892009-06-03 12:37:36 +0200607static void hist_entry__free(struct hist_entry *he)
608{
609 free(he);
610}
611
612/*
613 * collapse the histogram
614 */
615
616static struct rb_root collapse_hists;
617
618static void collapse__insert_entry(struct hist_entry *he)
619{
620 struct rb_node **p = &collapse_hists.rb_node;
621 struct rb_node *parent = NULL;
622 struct hist_entry *iter;
623 int64_t cmp;
624
625 while (*p != NULL) {
626 parent = *p;
627 iter = rb_entry(parent, struct hist_entry, rb_node);
628
629 cmp = hist_entry__collapse(iter, he);
630
631 if (!cmp) {
632 iter->count += he->count;
633 hist_entry__free(he);
634 return;
635 }
636
637 if (cmp < 0)
638 p = &(*p)->rb_left;
639 else
640 p = &(*p)->rb_right;
641 }
642
643 rb_link_node(&he->rb_node, parent, p);
644 rb_insert_color(&he->rb_node, &collapse_hists);
645}
646
647static void collapse__resort(void)
648{
649 struct rb_node *next;
650 struct hist_entry *n;
651
652 if (!sort__need_collapse)
653 return;
654
655 next = rb_first(&hist);
656 while (next) {
657 n = rb_entry(next, struct hist_entry, rb_node);
658 next = rb_next(&n->rb_node);
659
660 rb_erase(&n->rb_node, &hist);
661 collapse__insert_entry(n);
662 }
663}
664
Peter Zijlstrae7fb08b2009-05-27 20:20:24 +0200665/*
666 * reverse the map, sort on count.
667 */
668
669static struct rb_root output_hists;
670
671static void output__insert_entry(struct hist_entry *he)
672{
673 struct rb_node **p = &output_hists.rb_node;
674 struct rb_node *parent = NULL;
675 struct hist_entry *iter;
676
677 while (*p != NULL) {
678 parent = *p;
679 iter = rb_entry(parent, struct hist_entry, rb_node);
680
681 if (he->count > iter->count)
682 p = &(*p)->rb_left;
683 else
684 p = &(*p)->rb_right;
685 }
686
687 rb_link_node(&he->rb_node, parent, p);
688 rb_insert_color(&he->rb_node, &output_hists);
689}
690
691static void output__resort(void)
692{
Peter Zijlstra82292892009-06-03 12:37:36 +0200693 struct rb_node *next;
Peter Zijlstrae7fb08b2009-05-27 20:20:24 +0200694 struct hist_entry *n;
695
Peter Zijlstra82292892009-06-03 12:37:36 +0200696 if (sort__need_collapse)
697 next = rb_first(&collapse_hists);
698 else
699 next = rb_first(&hist);
700
Peter Zijlstrae7fb08b2009-05-27 20:20:24 +0200701 while (next) {
702 n = rb_entry(next, struct hist_entry, rb_node);
703 next = rb_next(&n->rb_node);
704
705 rb_erase(&n->rb_node, &hist);
706 output__insert_entry(n);
Arnaldo Carvalho de Melo3a4b8cc2009-05-26 16:19:04 -0300707 }
708}
709
Peter Zijlstrae7fb08b2009-05-27 20:20:24 +0200710static size_t output__fprintf(FILE *fp, uint64_t total_samples)
Arnaldo Carvalho de Melo3a4b8cc2009-05-26 16:19:04 -0300711{
Peter Zijlstrae7fb08b2009-05-27 20:20:24 +0200712 struct hist_entry *pos;
Ingo Molnar2d655372009-05-27 21:36:22 +0200713 struct sort_entry *se;
Arnaldo Carvalho de Melo3a4b8cc2009-05-26 16:19:04 -0300714 struct rb_node *nd;
715 size_t ret = 0;
716
Peter Zijlstraca8cdee2009-05-28 11:08:33 +0200717 fprintf(fp, "#\n");
718
719 fprintf(fp, "# Overhead");
720 list_for_each_entry(se, &hist_entry__sort_list, list)
721 fprintf(fp, " %s", se->header);
722 fprintf(fp, "\n");
723
724 fprintf(fp, "# ........");
Ingo Molnar2d655372009-05-27 21:36:22 +0200725 list_for_each_entry(se, &hist_entry__sort_list, list) {
Peter Zijlstraca8cdee2009-05-28 11:08:33 +0200726 int i;
727
Ingo Molnar4593bba2009-06-02 15:34:25 +0200728 fprintf(fp, " ");
729 for (i = 0; i < strlen(se->header)-1; i++)
Peter Zijlstraca8cdee2009-05-28 11:08:33 +0200730 fprintf(fp, ".");
Ingo Molnar2d655372009-05-27 21:36:22 +0200731 }
Peter Zijlstraca8cdee2009-05-28 11:08:33 +0200732 fprintf(fp, "\n");
733
734 fprintf(fp, "#\n");
Ingo Molnar2d655372009-05-27 21:36:22 +0200735
Peter Zijlstrae7fb08b2009-05-27 20:20:24 +0200736 for (nd = rb_first(&output_hists); nd; nd = rb_next(nd)) {
737 pos = rb_entry(nd, struct hist_entry, rb_node);
738 ret += hist_entry__fprintf(fp, pos, total_samples);
Arnaldo Carvalho de Melo3a4b8cc2009-05-26 16:19:04 -0300739 }
740
741 return ret;
742}
743
Peter Zijlstra436224a2009-06-02 21:02:36 +0200744static void register_idle_thread(void)
745{
746 struct thread *thread = threads__findnew(0);
747
748 if (thread == NULL ||
749 thread__set_comm(thread, "[idle]")) {
750 fprintf(stderr, "problem inserting idle task.\n");
751 exit(-1);
752 }
753}
754
Peter Zijlstrae7fb08b2009-05-27 20:20:24 +0200755
Ingo Molnar53cb8bc2009-05-26 09:17:18 +0200756static int __cmd_report(void)
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300757{
758 unsigned long offset = 0;
759 unsigned long head = 0;
760 struct stat stat;
761 char *buf;
762 event_t *event;
763 int ret, rc = EXIT_FAILURE;
Peter Zijlstra6142f9e2009-05-26 20:51:47 +0200764 uint32_t size;
Ingo Molnarf49515b2009-05-26 19:03:36 +0200765 unsigned long total = 0, total_mmap = 0, total_comm = 0, total_unknown = 0;
Arnaldo Carvalho de Melob78c07d2009-05-29 13:48:59 -0300766 char cwd[PATH_MAX], *cwdp = cwd;
767 int cwdlen;
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300768
Peter Zijlstra436224a2009-06-02 21:02:36 +0200769 register_idle_thread();
770
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300771 input = open(input_name, O_RDONLY);
772 if (input < 0) {
773 perror("failed to open file");
774 exit(-1);
775 }
776
777 ret = fstat(input, &stat);
778 if (ret < 0) {
779 perror("failed to stat file");
780 exit(-1);
781 }
782
783 if (!stat.st_size) {
784 fprintf(stderr, "zero-sized file, nothing to do!\n");
785 exit(0);
786 }
787
Peter Zijlstra450aaa22009-05-27 20:20:23 +0200788 if (load_kernel() < 0) {
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -0300789 perror("failed to load kernel symbols");
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300790 return EXIT_FAILURE;
791 }
792
Arnaldo Carvalho de Melob78c07d2009-05-29 13:48:59 -0300793 if (!full_paths) {
794 if (getcwd(cwd, sizeof(cwd)) == NULL) {
795 perror("failed to get the current directory");
796 return EXIT_FAILURE;
797 }
798 cwdlen = strlen(cwd);
Mike Galbraith10a28252009-06-02 11:04:44 +0200799 } else {
Arnaldo Carvalho de Melob78c07d2009-05-29 13:48:59 -0300800 cwdp = NULL;
Mike Galbraith10a28252009-06-02 11:04:44 +0200801 cwdlen = 0;
802 }
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300803remap:
804 buf = (char *)mmap(NULL, page_size * mmap_window, PROT_READ,
805 MAP_SHARED, input, offset);
806 if (buf == MAP_FAILED) {
807 perror("failed to mmap file");
808 exit(-1);
809 }
810
811more:
812 event = (event_t *)(buf + head);
813
Peter Zijlstra6142f9e2009-05-26 20:51:47 +0200814 size = event->header.size;
815 if (!size)
816 size = 8;
817
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300818 if (head + event->header.size >= page_size * mmap_window) {
819 unsigned long shift = page_size * (head / page_size);
820 int ret;
821
822 ret = munmap(buf, page_size * mmap_window);
823 assert(ret == 0);
824
825 offset += shift;
826 head -= shift;
827 goto remap;
828 }
829
Peter Zijlstra6142f9e2009-05-26 20:51:47 +0200830 size = event->header.size;
831 if (!size)
832 goto broken_event;
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300833
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300834 if (event->header.misc & PERF_EVENT_MISC_OVERFLOW) {
835 char level;
836 int show = 0;
837 struct dso *dso = NULL;
838 struct thread *thread = threads__findnew(event->ip.pid);
Peter Zijlstraf17e04a2009-05-26 15:30:22 +0200839 uint64_t ip = event->ip.ip;
Peter Zijlstrae7fb08b2009-05-27 20:20:24 +0200840 struct map *map = NULL;
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300841
Ingo Molnar35029732009-06-03 09:38:58 +0200842 dprintf("%p [%p]: PERF_EVENT (IP, %d): %d: %p\n",
843 (void *)(offset + head),
844 (void *)(long)(event->header.size),
845 event->header.misc,
846 event->ip.pid,
847 (void *)(long)ip);
Ingo Molnar97b07b62009-05-26 18:48:58 +0200848
Ingo Molnared966aa2009-06-03 10:39:26 +0200849 dprintf(" ... thread: %s:%d\n", thread->comm, thread->pid);
850
Arnaldo Carvalho de Meloce7e4362009-05-19 09:30:23 -0300851 if (thread == NULL) {
Ingo Molnar55717312009-05-27 22:13:17 +0200852 fprintf(stderr, "problem processing %d event, skipping it.\n",
Arnaldo Carvalho de Meloce7e4362009-05-19 09:30:23 -0300853 event->header.type);
Ingo Molnar55717312009-05-27 22:13:17 +0200854 goto broken_event;
Arnaldo Carvalho de Meloce7e4362009-05-19 09:30:23 -0300855 }
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300856
857 if (event->header.misc & PERF_EVENT_MISC_KERNEL) {
858 show = SHOW_KERNEL;
859 level = 'k';
Peter Zijlstrae7fb08b2009-05-27 20:20:24 +0200860
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300861 dso = kernel_dso;
Peter Zijlstrae7fb08b2009-05-27 20:20:24 +0200862
Ingo Molnared966aa2009-06-03 10:39:26 +0200863 dprintf(" ...... dso: %s\n", dso->name);
864
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300865 } else if (event->header.misc & PERF_EVENT_MISC_USER) {
Ingo Molnar16f762a2009-05-27 09:10:38 +0200866
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300867 show = SHOW_USER;
868 level = '.';
Ingo Molnar16f762a2009-05-27 09:10:38 +0200869
870 map = thread__find_map(thread, ip);
Peter Zijlstraf17e04a2009-05-26 15:30:22 +0200871 if (map != NULL) {
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300872 dso = map->dso;
Peter Zijlstraf17e04a2009-05-26 15:30:22 +0200873 ip -= map->start + map->pgoff;
Ingo Molnared966aa2009-06-03 10:39:26 +0200874 } else {
875 /*
876 * If this is outside of all known maps,
877 * and is a negative address, try to look it
878 * up in the kernel dso, as it might be a
879 * vsyscall (which executes in user-mode):
880 */
881 if ((long long)ip < 0)
882 dso = kernel_dso;
Peter Zijlstraf17e04a2009-05-26 15:30:22 +0200883 }
Ingo Molnared966aa2009-06-03 10:39:26 +0200884 dprintf(" ...... dso: %s\n", dso ? dso->name : "<not found>");
Peter Zijlstrae7fb08b2009-05-27 20:20:24 +0200885
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300886 } else {
887 show = SHOW_HV;
888 level = 'H';
Ingo Molnared966aa2009-06-03 10:39:26 +0200889 dprintf(" ...... dso: [hypervisor]\n");
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300890 }
891
892 if (show & show_mask) {
Peter Zijlstraf17e04a2009-05-26 15:30:22 +0200893 struct symbol *sym = dso__find_symbol(dso, ip);
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300894
Peter Zijlstrae7fb08b2009-05-27 20:20:24 +0200895 if (hist_entry__add(thread, map, dso, sym, ip, level)) {
896 fprintf(stderr,
Ingo Molnar55717312009-05-27 22:13:17 +0200897 "problem incrementing symbol count, skipping event\n");
898 goto broken_event;
Arnaldo Carvalho de Meloce7e4362009-05-19 09:30:23 -0300899 }
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300900 }
901 total++;
902 } else switch (event->header.type) {
903 case PERF_EVENT_MMAP: {
904 struct thread *thread = threads__findnew(event->mmap.pid);
Arnaldo Carvalho de Melob78c07d2009-05-29 13:48:59 -0300905 struct map *map = map__new(&event->mmap, cwdp, cwdlen);
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300906
Ingo Molnar35029732009-06-03 09:38:58 +0200907 dprintf("%p [%p]: PERF_EVENT_MMAP: [%p(%p) @ %p]: %s\n",
908 (void *)(offset + head),
909 (void *)(long)(event->header.size),
910 (void *)(long)event->mmap.start,
911 (void *)(long)event->mmap.len,
912 (void *)(long)event->mmap.pgoff,
913 event->mmap.filename);
914
Arnaldo Carvalho de Meloce7e4362009-05-19 09:30:23 -0300915 if (thread == NULL || map == NULL) {
Ingo Molnar0a520c62009-06-02 23:24:45 +0200916 if (verbose)
917 fprintf(stderr, "problem processing PERF_EVENT_MMAP, skipping event.\n");
Ingo Molnar55717312009-05-27 22:13:17 +0200918 goto broken_event;
Arnaldo Carvalho de Meloce7e4362009-05-19 09:30:23 -0300919 }
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300920 thread__insert_map(thread, map);
Ingo Molnar97b07b62009-05-26 18:48:58 +0200921 total_mmap++;
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300922 break;
923 }
924 case PERF_EVENT_COMM: {
925 struct thread *thread = threads__findnew(event->comm.pid);
926
Ingo Molnar35029732009-06-03 09:38:58 +0200927 dprintf("%p [%p]: PERF_EVENT_COMM: %s:%d\n",
928 (void *)(offset + head),
929 (void *)(long)(event->header.size),
930 event->comm.comm, event->comm.pid);
931
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300932 if (thread == NULL ||
Arnaldo Carvalho de Meloce7e4362009-05-19 09:30:23 -0300933 thread__set_comm(thread, event->comm.comm)) {
Ingo Molnar55717312009-05-27 22:13:17 +0200934 fprintf(stderr, "problem processing PERF_EVENT_COMM, skipping event.\n");
935 goto broken_event;
Arnaldo Carvalho de Meloce7e4362009-05-19 09:30:23 -0300936 }
Ingo Molnar97b07b62009-05-26 18:48:58 +0200937 total_comm++;
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300938 break;
939 }
Ingo Molnar97b07b62009-05-26 18:48:58 +0200940 default: {
Peter Zijlstra6142f9e2009-05-26 20:51:47 +0200941broken_event:
Ingo Molnar35029732009-06-03 09:38:58 +0200942 dprintf("%p [%p]: skipping unknown header type: %d\n",
943 (void *)(offset + head),
944 (void *)(long)(event->header.size),
945 event->header.type);
Peter Zijlstrab7a16ea2009-05-27 13:35:35 +0200946
Ingo Molnar3e706112009-05-26 18:53:17 +0200947 total_unknown++;
Peter Zijlstra6142f9e2009-05-26 20:51:47 +0200948
949 /*
950 * assume we lost track of the stream, check alignment, and
951 * increment a single u64 in the hope to catch on again 'soon'.
952 */
953
954 if (unlikely(head & 7))
955 head &= ~7ULL;
956
957 size = 8;
Ingo Molnar97b07b62009-05-26 18:48:58 +0200958 }
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300959 }
960
Peter Zijlstra6142f9e2009-05-26 20:51:47 +0200961 head += size;
Ingo Molnarf49515b2009-05-26 19:03:36 +0200962
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300963 if (offset + head < stat.st_size)
964 goto more;
965
966 rc = EXIT_SUCCESS;
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300967 close(input);
Ingo Molnar97b07b62009-05-26 18:48:58 +0200968
Ingo Molnar35029732009-06-03 09:38:58 +0200969 dprintf(" IP events: %10ld\n", total);
970 dprintf(" mmap events: %10ld\n", total_mmap);
971 dprintf(" comm events: %10ld\n", total_comm);
972 dprintf(" unknown events: %10ld\n", total_unknown);
Ingo Molnar97b07b62009-05-26 18:48:58 +0200973
Ingo Molnar35029732009-06-03 09:38:58 +0200974 if (dump_trace)
Ingo Molnar97b07b62009-05-26 18:48:58 +0200975 return 0;
Ingo Molnar97b07b62009-05-26 18:48:58 +0200976
Peter Zijlstrae7fb08b2009-05-27 20:20:24 +0200977 if (verbose >= 2)
Ingo Molnar16f762a2009-05-27 09:10:38 +0200978 dsos__fprintf(stdout);
Ingo Molnar16f762a2009-05-27 09:10:38 +0200979
Peter Zijlstra82292892009-06-03 12:37:36 +0200980 collapse__resort();
Peter Zijlstrae7fb08b2009-05-27 20:20:24 +0200981 output__resort();
982 output__fprintf(stdout, total);
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300983
Arnaldo Carvalho de Melo8fa66bd2009-05-18 12:45:42 -0300984 return rc;
985}
986
Ingo Molnar53cb8bc2009-05-26 09:17:18 +0200987static const char * const report_usage[] = {
988 "perf report [<options>] <command>",
989 NULL
990};
991
992static const struct option options[] = {
993 OPT_STRING('i', "input", &input_name, "file",
994 "input file name"),
Arnaldo Carvalho de Melo815e7772009-05-26 19:46:14 -0300995 OPT_BOOLEAN('v', "verbose", &verbose,
996 "be more verbose (show symbol address, etc)"),
Ingo Molnar97b07b62009-05-26 18:48:58 +0200997 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
998 "dump raw trace in ASCII"),
Peter Zijlstra450aaa22009-05-27 20:20:23 +0200999 OPT_STRING('k', "vmlinux", &vmlinux, "file", "vmlinux pathname"),
Ingo Molnar63299f02009-05-28 10:52:00 +02001000 OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
1001 "sort by key(s): pid, comm, dso, symbol. Default: pid,symbol"),
Arnaldo Carvalho de Melob78c07d2009-05-29 13:48:59 -03001002 OPT_BOOLEAN('P', "full-paths", &full_paths,
1003 "Don't shorten the pathnames taking into account the cwd"),
Ingo Molnar53cb8bc2009-05-26 09:17:18 +02001004 OPT_END()
1005};
1006
Ingo Molnar5352f352009-06-03 10:07:39 +02001007static void setup_sorting(void)
1008{
1009 char *tmp, *tok, *str = strdup(sort_order);
1010
1011 for (tok = strtok_r(str, ", ", &tmp);
1012 tok; tok = strtok_r(NULL, ", ", &tmp)) {
1013 if (sort_dimension__add(tok) < 0) {
1014 error("Unknown --sort key: `%s'", tok);
1015 usage_with_options(report_usage, options);
1016 }
1017 }
1018
1019 free(str);
1020}
1021
Ingo Molnar53cb8bc2009-05-26 09:17:18 +02001022int cmd_report(int argc, const char **argv, const char *prefix)
1023{
Arnaldo Carvalho de Meloa2928c42009-05-28 14:55:04 -03001024 symbol__init();
Ingo Molnar53cb8bc2009-05-26 09:17:18 +02001025
1026 page_size = getpagesize();
1027
1028 parse_options(argc, argv, options, report_usage, 0);
1029
Peter Zijlstra1aa16732009-05-27 20:20:25 +02001030 setup_sorting();
1031
Ingo Molnara930d2c2009-05-27 09:50:13 +02001032 setup_pager();
1033
Ingo Molnar53cb8bc2009-05-26 09:17:18 +02001034 return __cmd_report();
1035}