diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-12-02 11:10:21 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-12-04 20:05:19 -0500 |
commit | 640c03ce837fe8d4b56342aba376ea0da3960459 (patch) | |
tree | e954290ccacf032ab4d9052eac01710fda1b7fab /tools/perf/util | |
parent | c980d1091810df13f21aabbce545fd98f545bbf7 (diff) |
perf session: Parse sample earlier
At perf_session__process_event, so that we reduce the number of lines in eache
tool sample processing routine that now receives a sample_data pointer already
parsed.
This will also be useful in the next patch, where we'll allow sample the
identity fields in MMAP, FORK, EXIT, etc, when it will be possible to see (cpu,
timestamp) just after before every event.
Also validate callchains in perf_session__process_event, i.e. as early as
possible, and keep a counter of the number of events discarded due to invalid
callchains, warning the user about it if it happens.
There is an assumption that was kept that all events have the same sample_type,
that will be dealt with in the future, when this preexisting limitation will be
removed.
Tested-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Ian Munsie <imunsie@au1.ibm.com>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Ian Munsie <imunsie@au1.ibm.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Stephane Eranian <eranian@google.com>
LKML-Reference: <1291318772-30880-4-git-send-email-acme@infradead.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util')
-rw-r--r-- | tools/perf/util/build-id.c | 7 | ||||
-rw-r--r-- | tools/perf/util/event.c | 66 | ||||
-rw-r--r-- | tools/perf/util/event.h | 20 | ||||
-rw-r--r-- | tools/perf/util/header.c | 11 | ||||
-rw-r--r-- | tools/perf/util/hist.h | 2 | ||||
-rw-r--r-- | tools/perf/util/session.c | 103 | ||||
-rw-r--r-- | tools/perf/util/session.h | 9 |
7 files changed, 138 insertions, 80 deletions
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index e437edb72417..deffb8c96071 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c | |||
@@ -14,7 +14,9 @@ | |||
14 | #include <linux/kernel.h> | 14 | #include <linux/kernel.h> |
15 | #include "debug.h" | 15 | #include "debug.h" |
16 | 16 | ||
17 | static int build_id__mark_dso_hit(event_t *event, struct perf_session *session) | 17 | static int build_id__mark_dso_hit(event_t *event, |
18 | struct sample_data *sample __used, | ||
19 | struct perf_session *session) | ||
18 | { | 20 | { |
19 | struct addr_location al; | 21 | struct addr_location al; |
20 | u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; | 22 | u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; |
@@ -35,7 +37,8 @@ static int build_id__mark_dso_hit(event_t *event, struct perf_session *session) | |||
35 | return 0; | 37 | return 0; |
36 | } | 38 | } |
37 | 39 | ||
38 | static int event__exit_del_thread(event_t *self, struct perf_session *session) | 40 | static int event__exit_del_thread(event_t *self, struct sample_data *sample __used, |
41 | struct perf_session *session) | ||
39 | { | 42 | { |
40 | struct thread *thread = perf_session__findnew(session, self->fork.tid); | 43 | struct thread *thread = perf_session__findnew(session, self->fork.tid); |
41 | 44 | ||
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index 7260db75b93d..34510f441975 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c | |||
@@ -24,6 +24,15 @@ const char *event__name[] = { | |||
24 | [PERF_RECORD_HEADER_BUILD_ID] = "BUILD_ID", | 24 | [PERF_RECORD_HEADER_BUILD_ID] = "BUILD_ID", |
25 | }; | 25 | }; |
26 | 26 | ||
27 | static struct sample_data synth_sample = { | ||
28 | .pid = -1, | ||
29 | .tid = -1, | ||
30 | .time = -1, | ||
31 | .stream_id = -1, | ||
32 | .cpu = -1, | ||
33 | .period = 1, | ||
34 | }; | ||
35 | |||
27 | static pid_t event__synthesize_comm(pid_t pid, int full, | 36 | static pid_t event__synthesize_comm(pid_t pid, int full, |
28 | event__handler_t process, | 37 | event__handler_t process, |
29 | struct perf_session *session) | 38 | struct perf_session *session) |
@@ -75,7 +84,7 @@ out_race: | |||
75 | if (!full) { | 84 | if (!full) { |
76 | ev.comm.tid = pid; | 85 | ev.comm.tid = pid; |
77 | 86 | ||
78 | process(&ev, session); | 87 | process(&ev, &synth_sample, session); |
79 | goto out_fclose; | 88 | goto out_fclose; |
80 | } | 89 | } |
81 | 90 | ||
@@ -93,7 +102,7 @@ out_race: | |||
93 | 102 | ||
94 | ev.comm.tid = pid; | 103 | ev.comm.tid = pid; |
95 | 104 | ||
96 | process(&ev, session); | 105 | process(&ev, &synth_sample, session); |
97 | } | 106 | } |
98 | closedir(tasks); | 107 | closedir(tasks); |
99 | 108 | ||
@@ -173,7 +182,7 @@ static int event__synthesize_mmap_events(pid_t pid, pid_t tgid, | |||
173 | ev.mmap.pid = tgid; | 182 | ev.mmap.pid = tgid; |
174 | ev.mmap.tid = pid; | 183 | ev.mmap.tid = pid; |
175 | 184 | ||
176 | process(&ev, session); | 185 | process(&ev, &synth_sample, session); |
177 | } | 186 | } |
178 | } | 187 | } |
179 | 188 | ||
@@ -219,7 +228,7 @@ int event__synthesize_modules(event__handler_t process, | |||
219 | 228 | ||
220 | memcpy(ev.mmap.filename, pos->dso->long_name, | 229 | memcpy(ev.mmap.filename, pos->dso->long_name, |
221 | pos->dso->long_name_len + 1); | 230 | pos->dso->long_name_len + 1); |
222 | process(&ev, session); | 231 | process(&ev, &synth_sample, session); |
223 | } | 232 | } |
224 | 233 | ||
225 | return 0; | 234 | return 0; |
@@ -331,7 +340,7 @@ int event__synthesize_kernel_mmap(event__handler_t process, | |||
331 | ev.mmap.len = map->end - ev.mmap.start; | 340 | ev.mmap.len = map->end - ev.mmap.start; |
332 | ev.mmap.pid = machine->pid; | 341 | ev.mmap.pid = machine->pid; |
333 | 342 | ||
334 | return process(&ev, session); | 343 | return process(&ev, &synth_sample, session); |
335 | } | 344 | } |
336 | 345 | ||
337 | static void thread__comm_adjust(struct thread *self, struct hists *hists) | 346 | static void thread__comm_adjust(struct thread *self, struct hists *hists) |
@@ -361,7 +370,8 @@ static int thread__set_comm_adjust(struct thread *self, const char *comm, | |||
361 | return 0; | 370 | return 0; |
362 | } | 371 | } |
363 | 372 | ||
364 | int event__process_comm(event_t *self, struct perf_session *session) | 373 | int event__process_comm(event_t *self, struct sample_data *sample __used, |
374 | struct perf_session *session) | ||
365 | { | 375 | { |
366 | struct thread *thread = perf_session__findnew(session, self->comm.tid); | 376 | struct thread *thread = perf_session__findnew(session, self->comm.tid); |
367 | 377 | ||
@@ -376,7 +386,8 @@ int event__process_comm(event_t *self, struct perf_session *session) | |||
376 | return 0; | 386 | return 0; |
377 | } | 387 | } |
378 | 388 | ||
379 | int event__process_lost(event_t *self, struct perf_session *session) | 389 | int event__process_lost(event_t *self, struct sample_data *sample __used, |
390 | struct perf_session *session) | ||
380 | { | 391 | { |
381 | dump_printf(": id:%Ld: lost:%Ld\n", self->lost.id, self->lost.lost); | 392 | dump_printf(": id:%Ld: lost:%Ld\n", self->lost.id, self->lost.lost); |
382 | session->hists.stats.total_lost += self->lost.lost; | 393 | session->hists.stats.total_lost += self->lost.lost; |
@@ -485,7 +496,8 @@ out_problem: | |||
485 | return -1; | 496 | return -1; |
486 | } | 497 | } |
487 | 498 | ||
488 | int event__process_mmap(event_t *self, struct perf_session *session) | 499 | int event__process_mmap(event_t *self, struct sample_data *sample __used, |
500 | struct perf_session *session) | ||
489 | { | 501 | { |
490 | struct machine *machine; | 502 | struct machine *machine; |
491 | struct thread *thread; | 503 | struct thread *thread; |
@@ -526,7 +538,8 @@ out_problem: | |||
526 | return 0; | 538 | return 0; |
527 | } | 539 | } |
528 | 540 | ||
529 | int event__process_task(event_t *self, struct perf_session *session) | 541 | int event__process_task(event_t *self, struct sample_data *sample __used, |
542 | struct perf_session *session) | ||
530 | { | 543 | { |
531 | struct thread *thread = perf_session__findnew(session, self->fork.tid); | 544 | struct thread *thread = perf_session__findnew(session, self->fork.tid); |
532 | struct thread *parent = perf_session__findnew(session, self->fork.ptid); | 545 | struct thread *parent = perf_session__findnew(session, self->fork.ptid); |
@@ -548,18 +561,19 @@ int event__process_task(event_t *self, struct perf_session *session) | |||
548 | return 0; | 561 | return 0; |
549 | } | 562 | } |
550 | 563 | ||
551 | int event__process(event_t *event, struct perf_session *session) | 564 | int event__process(event_t *event, struct sample_data *sample, |
565 | struct perf_session *session) | ||
552 | { | 566 | { |
553 | switch (event->header.type) { | 567 | switch (event->header.type) { |
554 | case PERF_RECORD_COMM: | 568 | case PERF_RECORD_COMM: |
555 | event__process_comm(event, session); | 569 | event__process_comm(event, sample, session); |
556 | break; | 570 | break; |
557 | case PERF_RECORD_MMAP: | 571 | case PERF_RECORD_MMAP: |
558 | event__process_mmap(event, session); | 572 | event__process_mmap(event, sample, session); |
559 | break; | 573 | break; |
560 | case PERF_RECORD_FORK: | 574 | case PERF_RECORD_FORK: |
561 | case PERF_RECORD_EXIT: | 575 | case PERF_RECORD_EXIT: |
562 | event__process_task(event, session); | 576 | event__process_task(event, sample, session); |
563 | break; | 577 | break; |
564 | default: | 578 | default: |
565 | break; | 579 | break; |
@@ -674,32 +688,8 @@ int event__preprocess_sample(const event_t *self, struct perf_session *session, | |||
674 | symbol_filter_t filter) | 688 | symbol_filter_t filter) |
675 | { | 689 | { |
676 | u8 cpumode = self->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; | 690 | u8 cpumode = self->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; |
677 | struct thread *thread; | 691 | struct thread *thread = perf_session__findnew(session, self->ip.pid); |
678 | |||
679 | event__parse_sample(self, session->sample_type, data); | ||
680 | 692 | ||
681 | dump_printf("(IP, %d): %d/%d: %#Lx period: %Ld cpu:%d\n", | ||
682 | self->header.misc, data->pid, data->tid, data->ip, | ||
683 | data->period, data->cpu); | ||
684 | |||
685 | if (session->sample_type & PERF_SAMPLE_CALLCHAIN) { | ||
686 | unsigned int i; | ||
687 | |||
688 | dump_printf("... chain: nr:%Lu\n", data->callchain->nr); | ||
689 | |||
690 | if (!ip_callchain__valid(data->callchain, self)) { | ||
691 | pr_debug("call-chain problem with event, " | ||
692 | "skipping it.\n"); | ||
693 | goto out_filtered; | ||
694 | } | ||
695 | |||
696 | if (dump_trace) { | ||
697 | for (i = 0; i < data->callchain->nr; i++) | ||
698 | dump_printf("..... %2d: %016Lx\n", | ||
699 | i, data->callchain->ips[i]); | ||
700 | } | ||
701 | } | ||
702 | thread = perf_session__findnew(session, self->ip.pid); | ||
703 | if (thread == NULL) | 693 | if (thread == NULL) |
704 | return -1; | 694 | return -1; |
705 | 695 | ||
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h index 8e790dae7026..08c400b83d57 100644 --- a/tools/perf/util/event.h +++ b/tools/perf/util/event.h | |||
@@ -135,7 +135,10 @@ void event__print_totals(void); | |||
135 | 135 | ||
136 | struct perf_session; | 136 | struct perf_session; |
137 | 137 | ||
138 | typedef int (*event__handler_t)(event_t *event, struct perf_session *session); | 138 | typedef int (*event__handler_synth_t)(event_t *event, |
139 | struct perf_session *session); | ||
140 | typedef int (*event__handler_t)(event_t *event, struct sample_data *sample, | ||
141 | struct perf_session *session); | ||
139 | 142 | ||
140 | int event__synthesize_thread(pid_t pid, event__handler_t process, | 143 | int event__synthesize_thread(pid_t pid, event__handler_t process, |
141 | struct perf_session *session); | 144 | struct perf_session *session); |
@@ -150,11 +153,16 @@ int event__synthesize_modules(event__handler_t process, | |||
150 | struct perf_session *session, | 153 | struct perf_session *session, |
151 | struct machine *machine); | 154 | struct machine *machine); |
152 | 155 | ||
153 | int event__process_comm(event_t *self, struct perf_session *session); | 156 | int event__process_comm(event_t *self, struct sample_data *sample, |
154 | int event__process_lost(event_t *self, struct perf_session *session); | 157 | struct perf_session *session); |
155 | int event__process_mmap(event_t *self, struct perf_session *session); | 158 | int event__process_lost(event_t *self, struct sample_data *sample, |
156 | int event__process_task(event_t *self, struct perf_session *session); | 159 | struct perf_session *session); |
157 | int event__process(event_t *event, struct perf_session *session); | 160 | int event__process_mmap(event_t *self, struct sample_data *sample, |
161 | struct perf_session *session); | ||
162 | int event__process_task(event_t *self, struct sample_data *sample, | ||
163 | struct perf_session *session); | ||
164 | int event__process(event_t *event, struct sample_data *sample, | ||
165 | struct perf_session *session); | ||
158 | 166 | ||
159 | struct addr_location; | 167 | struct addr_location; |
160 | int event__preprocess_sample(const event_t *self, struct perf_session *session, | 168 | int event__preprocess_sample(const event_t *self, struct perf_session *session, |
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index f65d7dc127b6..fe652f3b0aa7 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
@@ -993,15 +993,14 @@ int event__synthesize_attr(struct perf_event_attr *attr, u16 ids, u64 *id, | |||
993 | ev->attr.header.type = PERF_RECORD_HEADER_ATTR; | 993 | ev->attr.header.type = PERF_RECORD_HEADER_ATTR; |
994 | ev->attr.header.size = size; | 994 | ev->attr.header.size = size; |
995 | 995 | ||
996 | err = process(ev, session); | 996 | err = process(ev, NULL, session); |
997 | 997 | ||
998 | free(ev); | 998 | free(ev); |
999 | 999 | ||
1000 | return err; | 1000 | return err; |
1001 | } | 1001 | } |
1002 | 1002 | ||
1003 | int event__synthesize_attrs(struct perf_header *self, | 1003 | int event__synthesize_attrs(struct perf_header *self, event__handler_t process, |
1004 | event__handler_t process, | ||
1005 | struct perf_session *session) | 1004 | struct perf_session *session) |
1006 | { | 1005 | { |
1007 | struct perf_header_attr *attr; | 1006 | struct perf_header_attr *attr; |
@@ -1071,7 +1070,7 @@ int event__synthesize_event_type(u64 event_id, char *name, | |||
1071 | ev.event_type.header.size = sizeof(ev.event_type) - | 1070 | ev.event_type.header.size = sizeof(ev.event_type) - |
1072 | (sizeof(ev.event_type.event_type.name) - size); | 1071 | (sizeof(ev.event_type.event_type.name) - size); |
1073 | 1072 | ||
1074 | err = process(&ev, session); | 1073 | err = process(&ev, NULL, session); |
1075 | 1074 | ||
1076 | return err; | 1075 | return err; |
1077 | } | 1076 | } |
@@ -1126,7 +1125,7 @@ int event__synthesize_tracing_data(int fd, struct perf_event_attr *pattrs, | |||
1126 | ev.tracing_data.header.size = sizeof(ev.tracing_data); | 1125 | ev.tracing_data.header.size = sizeof(ev.tracing_data); |
1127 | ev.tracing_data.size = aligned_size; | 1126 | ev.tracing_data.size = aligned_size; |
1128 | 1127 | ||
1129 | process(&ev, session); | 1128 | process(&ev, NULL, session); |
1130 | 1129 | ||
1131 | err = read_tracing_data(fd, pattrs, nb_events); | 1130 | err = read_tracing_data(fd, pattrs, nb_events); |
1132 | write_padded(fd, NULL, 0, padding); | 1131 | write_padded(fd, NULL, 0, padding); |
@@ -1186,7 +1185,7 @@ int event__synthesize_build_id(struct dso *pos, u16 misc, | |||
1186 | ev.build_id.header.size = sizeof(ev.build_id) + len; | 1185 | ev.build_id.header.size = sizeof(ev.build_id) + len; |
1187 | memcpy(&ev.build_id.filename, pos->long_name, pos->long_name_len); | 1186 | memcpy(&ev.build_id.filename, pos->long_name, pos->long_name_len); |
1188 | 1187 | ||
1189 | err = process(&ev, session); | 1188 | err = process(&ev, NULL, session); |
1190 | 1189 | ||
1191 | return err; | 1190 | return err; |
1192 | } | 1191 | } |
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index 587d375d3430..ee789856a8c9 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h | |||
@@ -52,8 +52,10 @@ struct sym_priv { | |||
52 | struct events_stats { | 52 | struct events_stats { |
53 | u64 total_period; | 53 | u64 total_period; |
54 | u64 total_lost; | 54 | u64 total_lost; |
55 | u64 total_invalid_chains; | ||
55 | u32 nr_events[PERF_RECORD_HEADER_MAX]; | 56 | u32 nr_events[PERF_RECORD_HEADER_MAX]; |
56 | u32 nr_unknown_events; | 57 | u32 nr_unknown_events; |
58 | u32 nr_invalid_chains; | ||
57 | }; | 59 | }; |
58 | 60 | ||
59 | enum hist_column { | 61 | enum hist_column { |
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 52672dad1fe9..08ec018966a8 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c | |||
@@ -70,6 +70,11 @@ void perf_session__update_sample_type(struct perf_session *self) | |||
70 | self->sample_type = perf_header__sample_type(&self->header); | 70 | self->sample_type = perf_header__sample_type(&self->header); |
71 | } | 71 | } |
72 | 72 | ||
73 | void perf_session__set_sample_type(struct perf_session *session, u64 type) | ||
74 | { | ||
75 | session->sample_type = type; | ||
76 | } | ||
77 | |||
73 | int perf_session__create_kernel_maps(struct perf_session *self) | 78 | int perf_session__create_kernel_maps(struct perf_session *self) |
74 | { | 79 | { |
75 | int ret = machine__create_kernel_maps(&self->host_machine); | 80 | int ret = machine__create_kernel_maps(&self->host_machine); |
@@ -240,7 +245,15 @@ struct map_symbol *perf_session__resolve_callchain(struct perf_session *self, | |||
240 | return syms; | 245 | return syms; |
241 | } | 246 | } |
242 | 247 | ||
248 | static int process_event_synth_stub(event_t *event __used, | ||
249 | struct perf_session *session __used) | ||
250 | { | ||
251 | dump_printf(": unhandled!\n"); | ||
252 | return 0; | ||
253 | } | ||
254 | |||
243 | static int process_event_stub(event_t *event __used, | 255 | static int process_event_stub(event_t *event __used, |
256 | struct sample_data *sample __used, | ||
244 | struct perf_session *session __used) | 257 | struct perf_session *session __used) |
245 | { | 258 | { |
246 | dump_printf(": unhandled!\n"); | 259 | dump_printf(": unhandled!\n"); |
@@ -280,13 +293,13 @@ static void perf_event_ops__fill_defaults(struct perf_event_ops *handler) | |||
280 | if (handler->unthrottle == NULL) | 293 | if (handler->unthrottle == NULL) |
281 | handler->unthrottle = process_event_stub; | 294 | handler->unthrottle = process_event_stub; |
282 | if (handler->attr == NULL) | 295 | if (handler->attr == NULL) |
283 | handler->attr = process_event_stub; | 296 | handler->attr = process_event_synth_stub; |
284 | if (handler->event_type == NULL) | 297 | if (handler->event_type == NULL) |
285 | handler->event_type = process_event_stub; | 298 | handler->event_type = process_event_synth_stub; |
286 | if (handler->tracing_data == NULL) | 299 | if (handler->tracing_data == NULL) |
287 | handler->tracing_data = process_event_stub; | 300 | handler->tracing_data = process_event_synth_stub; |
288 | if (handler->build_id == NULL) | 301 | if (handler->build_id == NULL) |
289 | handler->build_id = process_event_stub; | 302 | handler->build_id = process_event_synth_stub; |
290 | if (handler->finished_round == NULL) { | 303 | if (handler->finished_round == NULL) { |
291 | if (handler->ordered_samples) | 304 | if (handler->ordered_samples) |
292 | handler->finished_round = process_finished_round; | 305 | handler->finished_round = process_finished_round; |
@@ -419,6 +432,7 @@ static void flush_sample_queue(struct perf_session *s, | |||
419 | struct ordered_samples *os = &s->ordered_samples; | 432 | struct ordered_samples *os = &s->ordered_samples; |
420 | struct list_head *head = &os->samples; | 433 | struct list_head *head = &os->samples; |
421 | struct sample_queue *tmp, *iter; | 434 | struct sample_queue *tmp, *iter; |
435 | struct sample_data sample; | ||
422 | u64 limit = os->next_flush; | 436 | u64 limit = os->next_flush; |
423 | u64 last_ts = os->last_sample ? os->last_sample->timestamp : 0ULL; | 437 | u64 last_ts = os->last_sample ? os->last_sample->timestamp : 0ULL; |
424 | 438 | ||
@@ -429,7 +443,8 @@ static void flush_sample_queue(struct perf_session *s, | |||
429 | if (iter->timestamp > limit) | 443 | if (iter->timestamp > limit) |
430 | break; | 444 | break; |
431 | 445 | ||
432 | ops->sample(iter->event, s); | 446 | event__parse_sample(iter->event, s->sample_type, &sample); |
447 | ops->sample(iter->event, &sample, s); | ||
433 | 448 | ||
434 | os->last_flush = iter->timestamp; | 449 | os->last_flush = iter->timestamp; |
435 | list_del(&iter->list); | 450 | list_del(&iter->list); |
@@ -578,20 +593,29 @@ static int queue_sample_event(event_t *event, struct sample_data *data, | |||
578 | return 0; | 593 | return 0; |
579 | } | 594 | } |
580 | 595 | ||
581 | static int perf_session__process_sample(event_t *event, struct perf_session *s, | 596 | static int perf_session__process_sample(event_t *event, |
597 | struct sample_data *sample, | ||
598 | struct perf_session *s, | ||
582 | struct perf_event_ops *ops) | 599 | struct perf_event_ops *ops) |
583 | { | 600 | { |
584 | struct sample_data data; | ||
585 | |||
586 | if (!ops->ordered_samples) | 601 | if (!ops->ordered_samples) |
587 | return ops->sample(event, s); | 602 | return ops->sample(event, sample, s); |
603 | |||
604 | queue_sample_event(event, sample, s); | ||
605 | return 0; | ||
606 | } | ||
588 | 607 | ||
589 | bzero(&data, sizeof(struct sample_data)); | 608 | static void callchain__dump(struct sample_data *sample) |
590 | event__parse_sample(event, s->sample_type, &data); | 609 | { |
610 | unsigned int i; | ||
591 | 611 | ||
592 | queue_sample_event(event, &data, s); | 612 | if (!dump_trace) |
613 | return; | ||
593 | 614 | ||
594 | return 0; | 615 | printf("... chain: nr:%Lu\n", sample->callchain->nr); |
616 | |||
617 | for (i = 0; i < sample->callchain->nr; i++) | ||
618 | printf("..... %2d: %016Lx\n", i, sample->callchain->ips[i]); | ||
595 | } | 619 | } |
596 | 620 | ||
597 | static int perf_session__process_event(struct perf_session *self, | 621 | static int perf_session__process_event(struct perf_session *self, |
@@ -599,8 +623,16 @@ static int perf_session__process_event(struct perf_session *self, | |||
599 | struct perf_event_ops *ops, | 623 | struct perf_event_ops *ops, |
600 | u64 file_offset) | 624 | u64 file_offset) |
601 | { | 625 | { |
626 | struct sample_data sample; | ||
627 | |||
602 | trace_event(event); | 628 | trace_event(event); |
603 | 629 | ||
630 | if (self->header.needs_swap && event__swap_ops[event->header.type]) | ||
631 | event__swap_ops[event->header.type](event); | ||
632 | |||
633 | if (event->header.type == PERF_RECORD_SAMPLE) | ||
634 | event__parse_sample(event, self->sample_type, &sample); | ||
635 | |||
604 | if (event->header.type < PERF_RECORD_HEADER_MAX) { | 636 | if (event->header.type < PERF_RECORD_HEADER_MAX) { |
605 | dump_printf("%#Lx [%#x]: PERF_RECORD_%s", | 637 | dump_printf("%#Lx [%#x]: PERF_RECORD_%s", |
606 | file_offset, event->header.size, | 638 | file_offset, event->header.size, |
@@ -608,28 +640,41 @@ static int perf_session__process_event(struct perf_session *self, | |||
608 | hists__inc_nr_events(&self->hists, event->header.type); | 640 | hists__inc_nr_events(&self->hists, event->header.type); |
609 | } | 641 | } |
610 | 642 | ||
611 | if (self->header.needs_swap && event__swap_ops[event->header.type]) | ||
612 | event__swap_ops[event->header.type](event); | ||
613 | |||
614 | switch (event->header.type) { | 643 | switch (event->header.type) { |
615 | case PERF_RECORD_SAMPLE: | 644 | case PERF_RECORD_SAMPLE: |
616 | return perf_session__process_sample(event, self, ops); | 645 | dump_printf("(IP, %d): %d/%d: %#Lx period: %Ld\n", event->header.misc, |
646 | sample.pid, sample.tid, sample.ip, sample.period); | ||
647 | |||
648 | if (self->sample_type & PERF_SAMPLE_CALLCHAIN) { | ||
649 | if (!ip_callchain__valid(sample.callchain, event)) { | ||
650 | pr_debug("call-chain problem with event, " | ||
651 | "skipping it.\n"); | ||
652 | ++self->hists.stats.nr_invalid_chains; | ||
653 | self->hists.stats.total_invalid_chains += sample.period; | ||
654 | return 0; | ||
655 | } | ||
656 | |||
657 | callchain__dump(&sample); | ||
658 | } | ||
659 | |||
660 | return perf_session__process_sample(event, &sample, self, ops); | ||
661 | |||
617 | case PERF_RECORD_MMAP: | 662 | case PERF_RECORD_MMAP: |
618 | return ops->mmap(event, self); | 663 | return ops->mmap(event, &sample, self); |
619 | case PERF_RECORD_COMM: | 664 | case PERF_RECORD_COMM: |
620 | return ops->comm(event, self); | 665 | return ops->comm(event, &sample, self); |
621 | case PERF_RECORD_FORK: | 666 | case PERF_RECORD_FORK: |
622 | return ops->fork(event, self); | 667 | return ops->fork(event, &sample, self); |
623 | case PERF_RECORD_EXIT: | 668 | case PERF_RECORD_EXIT: |
624 | return ops->exit(event, self); | 669 | return ops->exit(event, &sample, self); |
625 | case PERF_RECORD_LOST: | 670 | case PERF_RECORD_LOST: |
626 | return ops->lost(event, self); | 671 | return ops->lost(event, &sample, self); |
627 | case PERF_RECORD_READ: | 672 | case PERF_RECORD_READ: |
628 | return ops->read(event, self); | 673 | return ops->read(event, &sample, self); |
629 | case PERF_RECORD_THROTTLE: | 674 | case PERF_RECORD_THROTTLE: |
630 | return ops->throttle(event, self); | 675 | return ops->throttle(event, &sample, self); |
631 | case PERF_RECORD_UNTHROTTLE: | 676 | case PERF_RECORD_UNTHROTTLE: |
632 | return ops->unthrottle(event, self); | 677 | return ops->unthrottle(event, &sample, self); |
633 | case PERF_RECORD_HEADER_ATTR: | 678 | case PERF_RECORD_HEADER_ATTR: |
634 | return ops->attr(event, self); | 679 | return ops->attr(event, self); |
635 | case PERF_RECORD_HEADER_EVENT_TYPE: | 680 | case PERF_RECORD_HEADER_EVENT_TYPE: |
@@ -894,6 +939,14 @@ out_err: | |||
894 | session->hists.stats.nr_unknown_events); | 939 | session->hists.stats.nr_unknown_events); |
895 | } | 940 | } |
896 | 941 | ||
942 | if (session->hists.stats.nr_invalid_chains != 0) { | ||
943 | ui__warning("Found invalid callchains!\n\n" | ||
944 | "%u out of %u events were discarded for this reason.\n\n" | ||
945 | "Consider reporting to linux-kernel@vger.kernel.org.\n\n", | ||
946 | session->hists.stats.nr_invalid_chains, | ||
947 | session->hists.stats.nr_events[PERF_RECORD_SAMPLE]); | ||
948 | } | ||
949 | |||
897 | perf_session_free_sample_buffers(session); | 950 | perf_session_free_sample_buffers(session); |
898 | return err; | 951 | return err; |
899 | } | 952 | } |
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index 5bf6efa3788a..4578f86a6209 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h | |||
@@ -54,7 +54,9 @@ struct perf_session { | |||
54 | 54 | ||
55 | struct perf_event_ops; | 55 | struct perf_event_ops; |
56 | 56 | ||
57 | typedef int (*event_op)(event_t *self, struct perf_session *session); | 57 | typedef int (*event_op)(event_t *self, struct sample_data *sample, |
58 | struct perf_session *session); | ||
59 | typedef int (*event_synth_op)(event_t *self, struct perf_session *session); | ||
58 | typedef int (*event_op2)(event_t *self, struct perf_session *session, | 60 | typedef int (*event_op2)(event_t *self, struct perf_session *session, |
59 | struct perf_event_ops *ops); | 61 | struct perf_event_ops *ops); |
60 | 62 | ||
@@ -67,8 +69,8 @@ struct perf_event_ops { | |||
67 | lost, | 69 | lost, |
68 | read, | 70 | read, |
69 | throttle, | 71 | throttle, |
70 | unthrottle, | 72 | unthrottle; |
71 | attr, | 73 | event_synth_op attr, |
72 | event_type, | 74 | event_type, |
73 | tracing_data, | 75 | tracing_data, |
74 | build_id; | 76 | build_id; |
@@ -104,6 +106,7 @@ int perf_session__create_kernel_maps(struct perf_session *self); | |||
104 | 106 | ||
105 | int do_read(int fd, void *buf, size_t size); | 107 | int do_read(int fd, void *buf, size_t size); |
106 | void perf_session__update_sample_type(struct perf_session *self); | 108 | void perf_session__update_sample_type(struct perf_session *self); |
109 | void perf_session__set_sample_type(struct perf_session *session, u64 type); | ||
107 | void perf_session__remove_thread(struct perf_session *self, struct thread *th); | 110 | void perf_session__remove_thread(struct perf_session *self, struct thread *th); |
108 | 111 | ||
109 | static inline | 112 | static inline |