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.c63
1 files changed, 15 insertions, 48 deletions
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 3ebd70b1ef93..7d39bd2b19b8 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -19,12 +19,12 @@
19#include "perf.h" 19#include "perf.h"
20#include "util/debug.h" 20#include "util/debug.h"
21 21
22#include "util/event.h"
22#include "util/parse-options.h" 23#include "util/parse-options.h"
23#include "util/parse-events.h" 24#include "util/parse-events.h"
24#include "util/thread.h" 25#include "util/thread.h"
25#include "util/sort.h" 26#include "util/sort.h"
26#include "util/hist.h" 27#include "util/hist.h"
27#include "util/process_events.h"
28 28
29static char const *input_name = "perf.data"; 29static char const *input_name = "perf.data";
30 30
@@ -136,8 +136,7 @@ static int hist_entry__add(struct thread *thread, struct map *map,
136 return 0; 136 return 0;
137} 137}
138 138
139static int 139static int process_sample_event(event_t *event)
140process_sample_event(event_t *event, unsigned long offset, unsigned long head)
141{ 140{
142 char level; 141 char level;
143 u64 ip = event->ip.ip; 142 u64 ip = event->ip.ip;
@@ -145,12 +144,8 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head)
145 struct symbol *sym = NULL; 144 struct symbol *sym = NULL;
146 struct thread *thread = threads__findnew(event->ip.pid); 145 struct thread *thread = threads__findnew(event->ip.pid);
147 146
148 dump_printf("%p [%p]: PERF_EVENT (IP, %d): %d: %p\n", 147 dump_printf("(IP, %d): %d: %p\n", event->header.misc,
149 (void *)(offset + head), 148 event->ip.pid, (void *)(long)ip);
150 (void *)(long)(event->header.size),
151 event->header.misc,
152 event->ip.pid,
153 (void *)(long)ip);
154 149
155 if (thread == NULL) { 150 if (thread == NULL) {
156 fprintf(stderr, "problem processing %d event, skipping it.\n", 151 fprintf(stderr, "problem processing %d event, skipping it.\n",
@@ -198,46 +193,24 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head)
198 "skipping event\n"); 193 "skipping event\n");
199 return -1; 194 return -1;
200 } 195 }
201 total++;
202 196
203 return 0; 197 return 0;
204} 198}
205 199
206static int 200static int event__process(event_t *self)
207process_comm_event(event_t *event, unsigned long offset, unsigned long head)
208{ 201{
209 struct thread *thread = threads__findnew(event->comm.pid); 202 switch (self->header.type) {
210
211 dump_printf("%p [%p]: PERF_RECORD_COMM: %s:%d\n",
212 (void *)(offset + head),
213 (void *)(long)(event->header.size),
214 event->comm.comm, event->comm.pid);
215
216 if (thread == NULL ||
217 thread__set_comm(thread, event->comm.comm)) {
218 dump_printf("problem processing PERF_RECORD_COMM, skipping event.\n");
219 return -1;
220 }
221 total_comm++;
222
223 return 0;
224}
225
226static int
227process_event(event_t *event, unsigned long offset, unsigned long head)
228{
229 switch (event->header.type) {
230 case PERF_RECORD_SAMPLE: 203 case PERF_RECORD_SAMPLE:
231 return process_sample_event(event, offset, head); 204 return process_sample_event(self);
232 205
233 case PERF_RECORD_MMAP: 206 case PERF_RECORD_MMAP:
234 return process_mmap_event(event, offset, head); 207 return event__process_mmap(self);
235 208
236 case PERF_RECORD_COMM: 209 case PERF_RECORD_COMM:
237 return process_comm_event(event, offset, head); 210 return event__process_comm(self);
238 211
239 case PERF_RECORD_FORK: 212 case PERF_RECORD_FORK:
240 return process_task_event(event, offset, head); 213 return event__process_task(self);
241 /* 214 /*
242 * We dont process them right now but they are fine: 215 * We dont process them right now but they are fine:
243 */ 216 */
@@ -621,15 +594,12 @@ more:
621 (void *)(long)event->header.size, 594 (void *)(long)event->header.size,
622 event->header.type); 595 event->header.type);
623 596
624 if (!size || process_event(event, offset, head) < 0) { 597 if (!size || event__process(event) < 0) {
625 598
626 dump_printf("%p [%p]: skipping unknown header type: %d\n", 599 dump_printf("%p [%p]: skipping unknown header type: %d\n",
627 (void *)(offset + head), 600 (void *)(offset + head),
628 (void *)(long)(event->header.size), 601 (void *)(long)(event->header.size),
629 event->header.type); 602 event->header.type);
630
631 total_unknown++;
632
633 /* 603 /*
634 * assume we lost track of the stream, check alignment, and 604 * assume we lost track of the stream, check alignment, and
635 * increment a single u64 in the hope to catch on again 'soon'. 605 * increment a single u64 in the hope to catch on again 'soon'.
@@ -649,14 +619,11 @@ more:
649 rc = EXIT_SUCCESS; 619 rc = EXIT_SUCCESS;
650 close(input); 620 close(input);
651 621
652 dump_printf(" IP events: %10ld\n", total);
653 dump_printf(" mmap events: %10ld\n", total_mmap);
654 dump_printf(" comm events: %10ld\n", total_comm);
655 dump_printf(" fork events: %10ld\n", total_fork);
656 dump_printf(" unknown events: %10ld\n", total_unknown);
657 622
658 if (dump_trace) 623 if (dump_trace) {
624 event__print_totals();
659 return 0; 625 return 0;
626 }
660 627
661 if (verbose > 3) 628 if (verbose > 3)
662 threads__fprintf(stdout); 629 threads__fprintf(stdout);
@@ -665,7 +632,7 @@ more:
665 dsos__fprintf(stdout); 632 dsos__fprintf(stdout);
666 633
667 collapse__resort(); 634 collapse__resort();
668 output__resort(total); 635 output__resort(event__total[0]);
669 636
670 find_annotations(); 637 find_annotations();
671 638