aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-annotate.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/builtin-annotate.c')
-rw-r--r--tools/perf/builtin-annotate.c482
1 files changed, 67 insertions, 415 deletions
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 1dba568e1941..043d85b7e254 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -17,30 +17,21 @@
17#include "util/string.h" 17#include "util/string.h"
18 18
19#include "perf.h" 19#include "perf.h"
20#include "util/debug.h"
20 21
21#include "util/parse-options.h" 22#include "util/parse-options.h"
22#include "util/parse-events.h" 23#include "util/parse-events.h"
23 24#include "util/thread.h"
24#define SHOW_KERNEL 1
25#define SHOW_USER 2
26#define SHOW_HV 4
27 25
28static char const *input_name = "perf.data"; 26static char const *input_name = "perf.data";
29static char *vmlinux = "vmlinux";
30 27
31static char default_sort_order[] = "comm,symbol"; 28static char default_sort_order[] = "comm,symbol";
32static char *sort_order = default_sort_order; 29static char *sort_order = default_sort_order;
33 30
31static int force;
34static int input; 32static int input;
35static int show_mask = SHOW_KERNEL | SHOW_USER | SHOW_HV; 33static int show_mask = SHOW_KERNEL | SHOW_USER | SHOW_HV;
36 34
37static int dump_trace = 0;
38#define dprintf(x...) do { if (dump_trace) printf(x); } while (0)
39
40static int verbose;
41
42static int modules;
43
44static int full_paths; 35static int full_paths;
45 36
46static int print_line; 37static int print_line;
@@ -48,39 +39,8 @@ static int print_line;
48static unsigned long page_size; 39static unsigned long page_size;
49static unsigned long mmap_window = 32; 40static unsigned long mmap_window = 32;
50 41
51struct ip_event { 42static struct rb_root threads;
52 struct perf_event_header header; 43static struct thread *last_match;
53 u64 ip;
54 u32 pid, tid;
55};
56
57struct mmap_event {
58 struct perf_event_header header;
59 u32 pid, tid;
60 u64 start;
61 u64 len;
62 u64 pgoff;
63 char filename[PATH_MAX];
64};
65
66struct comm_event {
67 struct perf_event_header header;
68 u32 pid, tid;
69 char comm[16];
70};
71
72struct fork_event {
73 struct perf_event_header header;
74 u32 pid, ppid;
75};
76
77typedef union event_union {
78 struct perf_event_header header;
79 struct ip_event ip;
80 struct mmap_event mmap;
81 struct comm_event comm;
82 struct fork_event fork;
83} event_t;
84 44
85 45
86struct sym_ext { 46struct sym_ext {
@@ -89,323 +49,6 @@ struct sym_ext {
89 char *path; 49 char *path;
90}; 50};
91 51
92static LIST_HEAD(dsos);
93static struct dso *kernel_dso;
94static struct dso *vdso;
95
96
97static void dsos__add(struct dso *dso)
98{
99 list_add_tail(&dso->node, &dsos);
100}
101
102static struct dso *dsos__find(const char *name)
103{
104 struct dso *pos;
105
106 list_for_each_entry(pos, &dsos, node)
107 if (strcmp(pos->name, name) == 0)
108 return pos;
109 return NULL;
110}
111
112static struct dso *dsos__findnew(const char *name)
113{
114 struct dso *dso = dsos__find(name);
115 int nr;
116
117 if (dso)
118 return dso;
119
120 dso = dso__new(name, 0);
121 if (!dso)
122 goto out_delete_dso;
123
124 nr = dso__load(dso, NULL, verbose);
125 if (nr < 0) {
126 if (verbose)
127 fprintf(stderr, "Failed to open: %s\n", name);
128 goto out_delete_dso;
129 }
130 if (!nr && verbose) {
131 fprintf(stderr,
132 "No symbols found in: %s, maybe install a debug package?\n",
133 name);
134 }
135
136 dsos__add(dso);
137
138 return dso;
139
140out_delete_dso:
141 dso__delete(dso);
142 return NULL;
143}
144
145static void dsos__fprintf(FILE *fp)
146{
147 struct dso *pos;
148
149 list_for_each_entry(pos, &dsos, node)
150 dso__fprintf(pos, fp);
151}
152
153static struct symbol *vdso__find_symbol(struct dso *dso, u64 ip)
154{
155 return dso__find_symbol(dso, ip);
156}
157
158static int load_kernel(void)
159{
160 int err;
161
162 kernel_dso = dso__new("[kernel]", 0);
163 if (!kernel_dso)
164 return -1;
165
166 err = dso__load_kernel(kernel_dso, vmlinux, NULL, verbose, modules);
167 if (err <= 0) {
168 dso__delete(kernel_dso);
169 kernel_dso = NULL;
170 } else
171 dsos__add(kernel_dso);
172
173 vdso = dso__new("[vdso]", 0);
174 if (!vdso)
175 return -1;
176
177 vdso->find_symbol = vdso__find_symbol;
178
179 dsos__add(vdso);
180
181 return err;
182}
183
184struct map {
185 struct list_head node;
186 u64 start;
187 u64 end;
188 u64 pgoff;
189 u64 (*map_ip)(struct map *, u64);
190 struct dso *dso;
191};
192
193static u64 map__map_ip(struct map *map, u64 ip)
194{
195 return ip - map->start + map->pgoff;
196}
197
198static u64 vdso__map_ip(struct map *map __used, u64 ip)
199{
200 return ip;
201}
202
203static struct map *map__new(struct mmap_event *event)
204{
205 struct map *self = malloc(sizeof(*self));
206
207 if (self != NULL) {
208 const char *filename = event->filename;
209
210 self->start = event->start;
211 self->end = event->start + event->len;
212 self->pgoff = event->pgoff;
213
214 self->dso = dsos__findnew(filename);
215 if (self->dso == NULL)
216 goto out_delete;
217
218 if (self->dso == vdso)
219 self->map_ip = vdso__map_ip;
220 else
221 self->map_ip = map__map_ip;
222 }
223 return self;
224out_delete:
225 free(self);
226 return NULL;
227}
228
229static struct map *map__clone(struct map *self)
230{
231 struct map *map = malloc(sizeof(*self));
232
233 if (!map)
234 return NULL;
235
236 memcpy(map, self, sizeof(*self));
237
238 return map;
239}
240
241static int map__overlap(struct map *l, struct map *r)
242{
243 if (l->start > r->start) {
244 struct map *t = l;
245 l = r;
246 r = t;
247 }
248
249 if (l->end > r->start)
250 return 1;
251
252 return 0;
253}
254
255static size_t map__fprintf(struct map *self, FILE *fp)
256{
257 return fprintf(fp, " %Lx-%Lx %Lx %s\n",
258 self->start, self->end, self->pgoff, self->dso->name);
259}
260
261
262struct thread {
263 struct rb_node rb_node;
264 struct list_head maps;
265 pid_t pid;
266 char *comm;
267};
268
269static struct thread *thread__new(pid_t pid)
270{
271 struct thread *self = malloc(sizeof(*self));
272
273 if (self != NULL) {
274 self->pid = pid;
275 self->comm = malloc(32);
276 if (self->comm)
277 snprintf(self->comm, 32, ":%d", self->pid);
278 INIT_LIST_HEAD(&self->maps);
279 }
280
281 return self;
282}
283
284static int thread__set_comm(struct thread *self, const char *comm)
285{
286 if (self->comm)
287 free(self->comm);
288 self->comm = strdup(comm);
289 return self->comm ? 0 : -ENOMEM;
290}
291
292static size_t thread__fprintf(struct thread *self, FILE *fp)
293{
294 struct map *pos;
295 size_t ret = fprintf(fp, "Thread %d %s\n", self->pid, self->comm);
296
297 list_for_each_entry(pos, &self->maps, node)
298 ret += map__fprintf(pos, fp);
299
300 return ret;
301}
302
303
304static struct rb_root threads;
305static struct thread *last_match;
306
307static struct thread *threads__findnew(pid_t pid)
308{
309 struct rb_node **p = &threads.rb_node;
310 struct rb_node *parent = NULL;
311 struct thread *th;
312
313 /*
314 * Font-end cache - PID lookups come in blocks,
315 * so most of the time we dont have to look up
316 * the full rbtree:
317 */
318 if (last_match && last_match->pid == pid)
319 return last_match;
320
321 while (*p != NULL) {
322 parent = *p;
323 th = rb_entry(parent, struct thread, rb_node);
324
325 if (th->pid == pid) {
326 last_match = th;
327 return th;
328 }
329
330 if (pid < th->pid)
331 p = &(*p)->rb_left;
332 else
333 p = &(*p)->rb_right;
334 }
335
336 th = thread__new(pid);
337 if (th != NULL) {
338 rb_link_node(&th->rb_node, parent, p);
339 rb_insert_color(&th->rb_node, &threads);
340 last_match = th;
341 }
342
343 return th;
344}
345
346static void thread__insert_map(struct thread *self, struct map *map)
347{
348 struct map *pos, *tmp;
349
350 list_for_each_entry_safe(pos, tmp, &self->maps, node) {
351 if (map__overlap(pos, map)) {
352 list_del_init(&pos->node);
353 /* XXX leaks dsos */
354 free(pos);
355 }
356 }
357
358 list_add_tail(&map->node, &self->maps);
359}
360
361static int thread__fork(struct thread *self, struct thread *parent)
362{
363 struct map *map;
364
365 if (self->comm)
366 free(self->comm);
367 self->comm = strdup(parent->comm);
368 if (!self->comm)
369 return -ENOMEM;
370
371 list_for_each_entry(map, &parent->maps, node) {
372 struct map *new = map__clone(map);
373 if (!new)
374 return -ENOMEM;
375 thread__insert_map(self, new);
376 }
377
378 return 0;
379}
380
381static struct map *thread__find_map(struct thread *self, u64 ip)
382{
383 struct map *pos;
384
385 if (self == NULL)
386 return NULL;
387
388 list_for_each_entry(pos, &self->maps, node)
389 if (ip >= pos->start && ip <= pos->end)
390 return pos;
391
392 return NULL;
393}
394
395static size_t threads__fprintf(FILE *fp)
396{
397 size_t ret = 0;
398 struct rb_node *nd;
399
400 for (nd = rb_first(&threads); nd; nd = rb_next(nd)) {
401 struct thread *pos = rb_entry(nd, struct thread, rb_node);
402
403 ret += thread__fprintf(pos, fp);
404 }
405
406 return ret;
407}
408
409/* 52/*
410 * histogram, sorted on item, collects counts 53 * histogram, sorted on item, collects counts
411 */ 54 */
@@ -432,7 +75,7 @@ struct hist_entry {
432struct sort_entry { 75struct sort_entry {
433 struct list_head list; 76 struct list_head list;
434 77
435 char *header; 78 const char *header;
436 79
437 int64_t (*cmp)(struct hist_entry *, struct hist_entry *); 80 int64_t (*cmp)(struct hist_entry *, struct hist_entry *);
438 int64_t (*collapse)(struct hist_entry *, struct hist_entry *); 81 int64_t (*collapse)(struct hist_entry *, struct hist_entry *);
@@ -576,7 +219,7 @@ static struct sort_entry sort_sym = {
576static int sort__need_collapse = 0; 219static int sort__need_collapse = 0;
577 220
578struct sort_dimension { 221struct sort_dimension {
579 char *name; 222 const char *name;
580 struct sort_entry *entry; 223 struct sort_entry *entry;
581 int taken; 224 int taken;
582}; 225};
@@ -829,17 +472,6 @@ static void output__resort(void)
829 } 472 }
830} 473}
831 474
832static void register_idle_thread(void)
833{
834 struct thread *thread = threads__findnew(0);
835
836 if (thread == NULL ||
837 thread__set_comm(thread, "[idle]")) {
838 fprintf(stderr, "problem inserting idle task.\n");
839 exit(-1);
840 }
841}
842
843static unsigned long total = 0, 475static unsigned long total = 0,
844 total_mmap = 0, 476 total_mmap = 0,
845 total_comm = 0, 477 total_comm = 0,
@@ -852,18 +484,20 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head)
852 char level; 484 char level;
853 int show = 0; 485 int show = 0;
854 struct dso *dso = NULL; 486 struct dso *dso = NULL;
855 struct thread *thread = threads__findnew(event->ip.pid); 487 struct thread *thread;
856 u64 ip = event->ip.ip; 488 u64 ip = event->ip.ip;
857 struct map *map = NULL; 489 struct map *map = NULL;
858 490
859 dprintf("%p [%p]: PERF_EVENT (IP, %d): %d: %p\n", 491 thread = threads__findnew(event->ip.pid, &threads, &last_match);
492
493 dump_printf("%p [%p]: PERF_EVENT (IP, %d): %d: %p\n",
860 (void *)(offset + head), 494 (void *)(offset + head),
861 (void *)(long)(event->header.size), 495 (void *)(long)(event->header.size),
862 event->header.misc, 496 event->header.misc,
863 event->ip.pid, 497 event->ip.pid,
864 (void *)(long)ip); 498 (void *)(long)ip);
865 499
866 dprintf(" ... thread: %s:%d\n", thread->comm, thread->pid); 500 dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid);
867 501
868 if (thread == NULL) { 502 if (thread == NULL) {
869 fprintf(stderr, "problem processing %d event, skipping it.\n", 503 fprintf(stderr, "problem processing %d event, skipping it.\n",
@@ -877,7 +511,7 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head)
877 511
878 dso = kernel_dso; 512 dso = kernel_dso;
879 513
880 dprintf(" ...... dso: %s\n", dso->name); 514 dump_printf(" ...... dso: %s\n", dso->name);
881 515
882 } else if (event->header.misc & PERF_EVENT_MISC_USER) { 516 } else if (event->header.misc & PERF_EVENT_MISC_USER) {
883 517
@@ -898,12 +532,12 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head)
898 if ((long long)ip < 0) 532 if ((long long)ip < 0)
899 dso = kernel_dso; 533 dso = kernel_dso;
900 } 534 }
901 dprintf(" ...... dso: %s\n", dso ? dso->name : "<not found>"); 535 dump_printf(" ...... dso: %s\n", dso ? dso->name : "<not found>");
902 536
903 } else { 537 } else {
904 show = SHOW_HV; 538 show = SHOW_HV;
905 level = 'H'; 539 level = 'H';
906 dprintf(" ...... dso: [hypervisor]\n"); 540 dump_printf(" ...... dso: [hypervisor]\n");
907 } 541 }
908 542
909 if (show & show_mask) { 543 if (show & show_mask) {
@@ -926,10 +560,12 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head)
926static int 560static int
927process_mmap_event(event_t *event, unsigned long offset, unsigned long head) 561process_mmap_event(event_t *event, unsigned long offset, unsigned long head)
928{ 562{
929 struct thread *thread = threads__findnew(event->mmap.pid); 563 struct thread *thread;
930 struct map *map = map__new(&event->mmap); 564 struct map *map = map__new(&event->mmap, NULL, 0);
565
566 thread = threads__findnew(event->mmap.pid, &threads, &last_match);
931 567
932 dprintf("%p [%p]: PERF_EVENT_MMAP %d: [%p(%p) @ %p]: %s\n", 568 dump_printf("%p [%p]: PERF_EVENT_MMAP %d: [%p(%p) @ %p]: %s\n",
933 (void *)(offset + head), 569 (void *)(offset + head),
934 (void *)(long)(event->header.size), 570 (void *)(long)(event->header.size),
935 event->mmap.pid, 571 event->mmap.pid,
@@ -939,7 +575,7 @@ process_mmap_event(event_t *event, unsigned long offset, unsigned long head)
939 event->mmap.filename); 575 event->mmap.filename);
940 576
941 if (thread == NULL || map == NULL) { 577 if (thread == NULL || map == NULL) {
942 dprintf("problem processing PERF_EVENT_MMAP, skipping event.\n"); 578 dump_printf("problem processing PERF_EVENT_MMAP, skipping event.\n");
943 return 0; 579 return 0;
944 } 580 }
945 581
@@ -952,16 +588,17 @@ process_mmap_event(event_t *event, unsigned long offset, unsigned long head)
952static int 588static int
953process_comm_event(event_t *event, unsigned long offset, unsigned long head) 589process_comm_event(event_t *event, unsigned long offset, unsigned long head)
954{ 590{
955 struct thread *thread = threads__findnew(event->comm.pid); 591 struct thread *thread;
956 592
957 dprintf("%p [%p]: PERF_EVENT_COMM: %s:%d\n", 593 thread = threads__findnew(event->comm.pid, &threads, &last_match);
594 dump_printf("%p [%p]: PERF_EVENT_COMM: %s:%d\n",
958 (void *)(offset + head), 595 (void *)(offset + head),
959 (void *)(long)(event->header.size), 596 (void *)(long)(event->header.size),
960 event->comm.comm, event->comm.pid); 597 event->comm.comm, event->comm.pid);
961 598
962 if (thread == NULL || 599 if (thread == NULL ||
963 thread__set_comm(thread, event->comm.comm)) { 600 thread__set_comm(thread, event->comm.comm)) {
964 dprintf("problem processing PERF_EVENT_COMM, skipping event.\n"); 601 dump_printf("problem processing PERF_EVENT_COMM, skipping event.\n");
965 return -1; 602 return -1;
966 } 603 }
967 total_comm++; 604 total_comm++;
@@ -972,16 +609,25 @@ process_comm_event(event_t *event, unsigned long offset, unsigned long head)
972static int 609static int
973process_fork_event(event_t *event, unsigned long offset, unsigned long head) 610process_fork_event(event_t *event, unsigned long offset, unsigned long head)
974{ 611{
975 struct thread *thread = threads__findnew(event->fork.pid); 612 struct thread *thread;
976 struct thread *parent = threads__findnew(event->fork.ppid); 613 struct thread *parent;
977 614
978 dprintf("%p [%p]: PERF_EVENT_FORK: %d:%d\n", 615 thread = threads__findnew(event->fork.pid, &threads, &last_match);
616 parent = threads__findnew(event->fork.ppid, &threads, &last_match);
617 dump_printf("%p [%p]: PERF_EVENT_FORK: %d:%d\n",
979 (void *)(offset + head), 618 (void *)(offset + head),
980 (void *)(long)(event->header.size), 619 (void *)(long)(event->header.size),
981 event->fork.pid, event->fork.ppid); 620 event->fork.pid, event->fork.ppid);
982 621
622 /*
623 * A thread clone will have the same PID for both
624 * parent and child.
625 */
626 if (thread == parent)
627 return 0;
628
983 if (!thread || !parent || thread__fork(thread, parent)) { 629 if (!thread || !parent || thread__fork(thread, parent)) {
984 dprintf("problem processing PERF_EVENT_FORK, skipping event.\n"); 630 dump_printf("problem processing PERF_EVENT_FORK, skipping event.\n");
985 return -1; 631 return -1;
986 } 632 }
987 total_fork++; 633 total_fork++;
@@ -1067,7 +713,7 @@ parse_line(FILE *file, struct symbol *sym, u64 start, u64 len)
1067 const char *path = NULL; 713 const char *path = NULL;
1068 unsigned int hits = 0; 714 unsigned int hits = 0;
1069 double percent = 0.0; 715 double percent = 0.0;
1070 char *color; 716 const char *color;
1071 struct sym_ext *sym_ext = sym->priv; 717 struct sym_ext *sym_ext = sym->priv;
1072 718
1073 offset = line_ip - start; 719 offset = line_ip - start;
@@ -1149,7 +795,7 @@ static void free_source_line(struct symbol *sym, int len)
1149 795
1150/* Get the filename:line for the colored entries */ 796/* Get the filename:line for the colored entries */
1151static void 797static void
1152get_source_line(struct symbol *sym, u64 start, int len, char *filename) 798get_source_line(struct symbol *sym, u64 start, int len, const char *filename)
1153{ 799{
1154 int i; 800 int i;
1155 char cmd[PATH_MAX * 2]; 801 char cmd[PATH_MAX * 2];
@@ -1195,7 +841,7 @@ get_source_line(struct symbol *sym, u64 start, int len, char *filename)
1195 } 841 }
1196} 842}
1197 843
1198static void print_summary(char *filename) 844static void print_summary(const char *filename)
1199{ 845{
1200 struct sym_ext *sym_ext; 846 struct sym_ext *sym_ext;
1201 struct rb_node *node; 847 struct rb_node *node;
@@ -1211,7 +857,7 @@ static void print_summary(char *filename)
1211 node = rb_first(&root_sym_ext); 857 node = rb_first(&root_sym_ext);
1212 while (node) { 858 while (node) {
1213 double percent; 859 double percent;
1214 char *color; 860 const char *color;
1215 char *path; 861 char *path;
1216 862
1217 sym_ext = rb_entry(node, struct sym_ext, node); 863 sym_ext = rb_entry(node, struct sym_ext, node);
@@ -1226,7 +872,7 @@ static void print_summary(char *filename)
1226 872
1227static void annotate_sym(struct dso *dso, struct symbol *sym) 873static void annotate_sym(struct dso *dso, struct symbol *sym)
1228{ 874{
1229 char *filename = dso->name, *d_filename; 875 const char *filename = dso->name, *d_filename;
1230 u64 start, end, len; 876 u64 start, end, len;
1231 char command[PATH_MAX*2]; 877 char command[PATH_MAX*2];
1232 FILE *file; 878 FILE *file;
@@ -1236,7 +882,7 @@ static void annotate_sym(struct dso *dso, struct symbol *sym)
1236 if (sym->module) 882 if (sym->module)
1237 filename = sym->module->path; 883 filename = sym->module->path;
1238 else if (dso == kernel_dso) 884 else if (dso == kernel_dso)
1239 filename = vmlinux; 885 filename = vmlinux_name;
1240 886
1241 start = sym->obj_start; 887 start = sym->obj_start;
1242 if (!start) 888 if (!start)
@@ -1308,12 +954,12 @@ static int __cmd_annotate(void)
1308 int ret, rc = EXIT_FAILURE; 954 int ret, rc = EXIT_FAILURE;
1309 unsigned long offset = 0; 955 unsigned long offset = 0;
1310 unsigned long head = 0; 956 unsigned long head = 0;
1311 struct stat stat; 957 struct stat input_stat;
1312 event_t *event; 958 event_t *event;
1313 uint32_t size; 959 uint32_t size;
1314 char *buf; 960 char *buf;
1315 961
1316 register_idle_thread(); 962 register_idle_thread(&threads, &last_match);
1317 963
1318 input = open(input_name, O_RDONLY); 964 input = open(input_name, O_RDONLY);
1319 if (input < 0) { 965 if (input < 0) {
@@ -1321,13 +967,18 @@ static int __cmd_annotate(void)
1321 exit(-1); 967 exit(-1);
1322 } 968 }
1323 969
1324 ret = fstat(input, &stat); 970 ret = fstat(input, &input_stat);
1325 if (ret < 0) { 971 if (ret < 0) {
1326 perror("failed to stat file"); 972 perror("failed to stat file");
1327 exit(-1); 973 exit(-1);
1328 } 974 }
1329 975
1330 if (!stat.st_size) { 976 if (!force && input_stat.st_uid && (input_stat.st_uid != geteuid())) {
977 fprintf(stderr, "file: %s not owned by current user or root\n", input_name);
978 exit(-1);
979 }
980
981 if (!input_stat.st_size) {
1331 fprintf(stderr, "zero-sized file, nothing to do!\n"); 982 fprintf(stderr, "zero-sized file, nothing to do!\n");
1332 exit(0); 983 exit(0);
1333 } 984 }
@@ -1354,10 +1005,10 @@ more:
1354 1005
1355 if (head + event->header.size >= page_size * mmap_window) { 1006 if (head + event->header.size >= page_size * mmap_window) {
1356 unsigned long shift = page_size * (head / page_size); 1007 unsigned long shift = page_size * (head / page_size);
1357 int ret; 1008 int munmap_ret;
1358 1009
1359 ret = munmap(buf, page_size * mmap_window); 1010 munmap_ret = munmap(buf, page_size * mmap_window);
1360 assert(ret == 0); 1011 assert(munmap_ret == 0);
1361 1012
1362 offset += shift; 1013 offset += shift;
1363 head -= shift; 1014 head -= shift;
@@ -1366,14 +1017,14 @@ more:
1366 1017
1367 size = event->header.size; 1018 size = event->header.size;
1368 1019
1369 dprintf("%p [%p]: event: %d\n", 1020 dump_printf("%p [%p]: event: %d\n",
1370 (void *)(offset + head), 1021 (void *)(offset + head),
1371 (void *)(long)event->header.size, 1022 (void *)(long)event->header.size,
1372 event->header.type); 1023 event->header.type);
1373 1024
1374 if (!size || process_event(event, offset, head) < 0) { 1025 if (!size || process_event(event, offset, head) < 0) {
1375 1026
1376 dprintf("%p [%p]: skipping unknown header type: %d\n", 1027 dump_printf("%p [%p]: skipping unknown header type: %d\n",
1377 (void *)(offset + head), 1028 (void *)(offset + head),
1378 (void *)(long)(event->header.size), 1029 (void *)(long)(event->header.size),
1379 event->header.type); 1030 event->header.type);
@@ -1393,23 +1044,23 @@ more:
1393 1044
1394 head += size; 1045 head += size;
1395 1046
1396 if (offset + head < (unsigned long)stat.st_size) 1047 if (offset + head < (unsigned long)input_stat.st_size)
1397 goto more; 1048 goto more;
1398 1049
1399 rc = EXIT_SUCCESS; 1050 rc = EXIT_SUCCESS;
1400 close(input); 1051 close(input);
1401 1052
1402 dprintf(" IP events: %10ld\n", total); 1053 dump_printf(" IP events: %10ld\n", total);
1403 dprintf(" mmap events: %10ld\n", total_mmap); 1054 dump_printf(" mmap events: %10ld\n", total_mmap);
1404 dprintf(" comm events: %10ld\n", total_comm); 1055 dump_printf(" comm events: %10ld\n", total_comm);
1405 dprintf(" fork events: %10ld\n", total_fork); 1056 dump_printf(" fork events: %10ld\n", total_fork);
1406 dprintf(" unknown events: %10ld\n", total_unknown); 1057 dump_printf(" unknown events: %10ld\n", total_unknown);
1407 1058
1408 if (dump_trace) 1059 if (dump_trace)
1409 return 0; 1060 return 0;
1410 1061
1411 if (verbose >= 3) 1062 if (verbose >= 3)
1412 threads__fprintf(stdout); 1063 threads__fprintf(stdout, &threads);
1413 1064
1414 if (verbose >= 2) 1065 if (verbose >= 2)
1415 dsos__fprintf(stdout); 1066 dsos__fprintf(stdout);
@@ -1432,11 +1083,12 @@ static const struct option options[] = {
1432 "input file name"), 1083 "input file name"),
1433 OPT_STRING('s', "symbol", &sym_hist_filter, "symbol", 1084 OPT_STRING('s', "symbol", &sym_hist_filter, "symbol",
1434 "symbol to annotate"), 1085 "symbol to annotate"),
1086 OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
1435 OPT_BOOLEAN('v', "verbose", &verbose, 1087 OPT_BOOLEAN('v', "verbose", &verbose,
1436 "be more verbose (show symbol address, etc)"), 1088 "be more verbose (show symbol address, etc)"),
1437 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, 1089 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
1438 "dump raw trace in ASCII"), 1090 "dump raw trace in ASCII"),
1439 OPT_STRING('k', "vmlinux", &vmlinux, "file", "vmlinux pathname"), 1091 OPT_STRING('k', "vmlinux", &vmlinux_name, "file", "vmlinux pathname"),
1440 OPT_BOOLEAN('m', "modules", &modules, 1092 OPT_BOOLEAN('m', "modules", &modules,
1441 "load module symbols - WARNING: use only with -k and LIVE kernel"), 1093 "load module symbols - WARNING: use only with -k and LIVE kernel"),
1442 OPT_BOOLEAN('l', "print-line", &print_line, 1094 OPT_BOOLEAN('l', "print-line", &print_line,