diff options
author | Steven Rostedt <srostedt@redhat.com> | 2010-05-17 22:26:53 -0400 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2010-05-18 00:35:23 -0400 |
commit | f0218b3e9974f06014b61be8987159f4a20e011e (patch) | |
tree | 29a593c4d71ab18cb0c450a34e79bf6bea66877e /tools/perf/util/session.c | |
parent | 1eaa4787a774c4896518c81f24e8bccaa2244924 (diff) | |
parent | 9d192e118a094087494997ea1c8a2faf39af38c5 (diff) |
Merge branch 'perf/core' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip into trace/tip/tracing/core-6
Conflicts:
include/trace/ftrace.h
kernel/trace/trace_kprobe.c
Acked-by: Masami Hiramatsu <mhiramat@redhat.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'tools/perf/util/session.c')
-rw-r--r-- | tools/perf/util/session.c | 568 |
1 files changed, 445 insertions, 123 deletions
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index eed1cb889008..25bfca4f10f0 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c | |||
@@ -14,6 +14,16 @@ static int perf_session__open(struct perf_session *self, bool force) | |||
14 | { | 14 | { |
15 | struct stat input_stat; | 15 | struct stat input_stat; |
16 | 16 | ||
17 | if (!strcmp(self->filename, "-")) { | ||
18 | self->fd_pipe = true; | ||
19 | self->fd = STDIN_FILENO; | ||
20 | |||
21 | if (perf_header__read(self, self->fd) < 0) | ||
22 | pr_err("incompatible file format"); | ||
23 | |||
24 | return 0; | ||
25 | } | ||
26 | |||
17 | self->fd = open(self->filename, O_RDONLY); | 27 | self->fd = open(self->filename, O_RDONLY); |
18 | if (self->fd < 0) { | 28 | if (self->fd < 0) { |
19 | pr_err("failed to open file: %s", self->filename); | 29 | pr_err("failed to open file: %s", self->filename); |
@@ -38,7 +48,7 @@ static int perf_session__open(struct perf_session *self, bool force) | |||
38 | goto out_close; | 48 | goto out_close; |
39 | } | 49 | } |
40 | 50 | ||
41 | if (perf_header__read(&self->header, self->fd) < 0) { | 51 | if (perf_header__read(self, self->fd) < 0) { |
42 | pr_err("incompatible file format"); | 52 | pr_err("incompatible file format"); |
43 | goto out_close; | 53 | goto out_close; |
44 | } | 54 | } |
@@ -52,12 +62,21 @@ out_close: | |||
52 | return -1; | 62 | return -1; |
53 | } | 63 | } |
54 | 64 | ||
55 | static inline int perf_session__create_kernel_maps(struct perf_session *self) | 65 | void perf_session__update_sample_type(struct perf_session *self) |
66 | { | ||
67 | self->sample_type = perf_header__sample_type(&self->header); | ||
68 | } | ||
69 | |||
70 | int perf_session__create_kernel_maps(struct perf_session *self) | ||
56 | { | 71 | { |
57 | return map_groups__create_kernel_maps(&self->kmaps, self->vmlinux_maps); | 72 | int ret = machine__create_kernel_maps(&self->host_machine); |
73 | |||
74 | if (ret >= 0) | ||
75 | ret = machines__create_guest_kernel_maps(&self->machines); | ||
76 | return ret; | ||
58 | } | 77 | } |
59 | 78 | ||
60 | struct perf_session *perf_session__new(const char *filename, int mode, bool force) | 79 | struct perf_session *perf_session__new(const char *filename, int mode, bool force, bool repipe) |
61 | { | 80 | { |
62 | size_t len = filename ? strlen(filename) + 1 : 0; | 81 | size_t len = filename ? strlen(filename) + 1 : 0; |
63 | struct perf_session *self = zalloc(sizeof(*self) + len); | 82 | struct perf_session *self = zalloc(sizeof(*self) + len); |
@@ -70,13 +89,15 @@ struct perf_session *perf_session__new(const char *filename, int mode, bool forc | |||
70 | 89 | ||
71 | memcpy(self->filename, filename, len); | 90 | memcpy(self->filename, filename, len); |
72 | self->threads = RB_ROOT; | 91 | self->threads = RB_ROOT; |
73 | self->stats_by_id = RB_ROOT; | 92 | self->hists_tree = RB_ROOT; |
74 | self->last_match = NULL; | 93 | self->last_match = NULL; |
75 | self->mmap_window = 32; | 94 | self->mmap_window = 32; |
76 | self->cwd = NULL; | 95 | self->cwd = NULL; |
77 | self->cwdlen = 0; | 96 | self->cwdlen = 0; |
78 | self->unknown_events = 0; | 97 | self->machines = RB_ROOT; |
79 | map_groups__init(&self->kmaps); | 98 | self->repipe = repipe; |
99 | INIT_LIST_HEAD(&self->ordered_samples.samples_head); | ||
100 | machine__init(&self->host_machine, "", HOST_KERNEL_ID); | ||
80 | 101 | ||
81 | if (mode == O_RDONLY) { | 102 | if (mode == O_RDONLY) { |
82 | if (perf_session__open(self, force) < 0) | 103 | if (perf_session__open(self, force) < 0) |
@@ -90,7 +111,7 @@ struct perf_session *perf_session__new(const char *filename, int mode, bool forc | |||
90 | goto out_delete; | 111 | goto out_delete; |
91 | } | 112 | } |
92 | 113 | ||
93 | self->sample_type = perf_header__sample_type(&self->header); | 114 | perf_session__update_sample_type(self); |
94 | out: | 115 | out: |
95 | return self; | 116 | return self; |
96 | out_free: | 117 | out_free: |
@@ -117,22 +138,17 @@ static bool symbol__match_parent_regex(struct symbol *sym) | |||
117 | return 0; | 138 | return 0; |
118 | } | 139 | } |
119 | 140 | ||
120 | struct symbol **perf_session__resolve_callchain(struct perf_session *self, | 141 | struct map_symbol *perf_session__resolve_callchain(struct perf_session *self, |
121 | struct thread *thread, | 142 | struct thread *thread, |
122 | struct ip_callchain *chain, | 143 | struct ip_callchain *chain, |
123 | struct symbol **parent) | 144 | struct symbol **parent) |
124 | { | 145 | { |
125 | u8 cpumode = PERF_RECORD_MISC_USER; | 146 | u8 cpumode = PERF_RECORD_MISC_USER; |
126 | struct symbol **syms = NULL; | ||
127 | unsigned int i; | 147 | unsigned int i; |
148 | struct map_symbol *syms = calloc(chain->nr, sizeof(*syms)); | ||
128 | 149 | ||
129 | if (symbol_conf.use_callchain) { | 150 | if (!syms) |
130 | syms = calloc(chain->nr, sizeof(*syms)); | 151 | return NULL; |
131 | if (!syms) { | ||
132 | fprintf(stderr, "Can't allocate memory for symbols\n"); | ||
133 | exit(-1); | ||
134 | } | ||
135 | } | ||
136 | 152 | ||
137 | for (i = 0; i < chain->nr; i++) { | 153 | for (i = 0; i < chain->nr; i++) { |
138 | u64 ip = chain->ips[i]; | 154 | u64 ip = chain->ips[i]; |
@@ -152,15 +168,17 @@ struct symbol **perf_session__resolve_callchain(struct perf_session *self, | |||
152 | continue; | 168 | continue; |
153 | } | 169 | } |
154 | 170 | ||
171 | al.filtered = false; | ||
155 | thread__find_addr_location(thread, self, cpumode, | 172 | thread__find_addr_location(thread, self, cpumode, |
156 | MAP__FUNCTION, ip, &al, NULL); | 173 | MAP__FUNCTION, thread->pid, ip, &al, NULL); |
157 | if (al.sym != NULL) { | 174 | if (al.sym != NULL) { |
158 | if (sort__has_parent && !*parent && | 175 | if (sort__has_parent && !*parent && |
159 | symbol__match_parent_regex(al.sym)) | 176 | symbol__match_parent_regex(al.sym)) |
160 | *parent = al.sym; | 177 | *parent = al.sym; |
161 | if (!symbol_conf.use_callchain) | 178 | if (!symbol_conf.use_callchain) |
162 | break; | 179 | break; |
163 | syms[i] = al.sym; | 180 | syms[i].map = al.map; |
181 | syms[i].sym = al.sym; | ||
164 | } | 182 | } |
165 | } | 183 | } |
166 | 184 | ||
@@ -174,6 +192,18 @@ static int process_event_stub(event_t *event __used, | |||
174 | return 0; | 192 | return 0; |
175 | } | 193 | } |
176 | 194 | ||
195 | static int process_finished_round_stub(event_t *event __used, | ||
196 | struct perf_session *session __used, | ||
197 | struct perf_event_ops *ops __used) | ||
198 | { | ||
199 | dump_printf(": unhandled!\n"); | ||
200 | return 0; | ||
201 | } | ||
202 | |||
203 | static int process_finished_round(event_t *event, | ||
204 | struct perf_session *session, | ||
205 | struct perf_event_ops *ops); | ||
206 | |||
177 | static void perf_event_ops__fill_defaults(struct perf_event_ops *handler) | 207 | static void perf_event_ops__fill_defaults(struct perf_event_ops *handler) |
178 | { | 208 | { |
179 | if (handler->sample == NULL) | 209 | if (handler->sample == NULL) |
@@ -194,29 +224,20 @@ static void perf_event_ops__fill_defaults(struct perf_event_ops *handler) | |||
194 | handler->throttle = process_event_stub; | 224 | handler->throttle = process_event_stub; |
195 | if (handler->unthrottle == NULL) | 225 | if (handler->unthrottle == NULL) |
196 | handler->unthrottle = process_event_stub; | 226 | handler->unthrottle = process_event_stub; |
197 | } | 227 | if (handler->attr == NULL) |
198 | 228 | handler->attr = process_event_stub; | |
199 | static const char *event__name[] = { | 229 | if (handler->event_type == NULL) |
200 | [0] = "TOTAL", | 230 | handler->event_type = process_event_stub; |
201 | [PERF_RECORD_MMAP] = "MMAP", | 231 | if (handler->tracing_data == NULL) |
202 | [PERF_RECORD_LOST] = "LOST", | 232 | handler->tracing_data = process_event_stub; |
203 | [PERF_RECORD_COMM] = "COMM", | 233 | if (handler->build_id == NULL) |
204 | [PERF_RECORD_EXIT] = "EXIT", | 234 | handler->build_id = process_event_stub; |
205 | [PERF_RECORD_THROTTLE] = "THROTTLE", | 235 | if (handler->finished_round == NULL) { |
206 | [PERF_RECORD_UNTHROTTLE] = "UNTHROTTLE", | 236 | if (handler->ordered_samples) |
207 | [PERF_RECORD_FORK] = "FORK", | 237 | handler->finished_round = process_finished_round; |
208 | [PERF_RECORD_READ] = "READ", | 238 | else |
209 | [PERF_RECORD_SAMPLE] = "SAMPLE", | 239 | handler->finished_round = process_finished_round_stub; |
210 | }; | 240 | } |
211 | |||
212 | unsigned long event__total[PERF_RECORD_MAX]; | ||
213 | |||
214 | void event__print_totals(void) | ||
215 | { | ||
216 | int i; | ||
217 | for (i = 0; i < PERF_RECORD_MAX; ++i) | ||
218 | pr_info("%10s events: %10ld\n", | ||
219 | event__name[i], event__total[i]); | ||
220 | } | 241 | } |
221 | 242 | ||
222 | void mem_bswap_64(void *src, int byte_size) | 243 | void mem_bswap_64(void *src, int byte_size) |
@@ -270,6 +291,37 @@ static void event__read_swap(event_t *self) | |||
270 | self->read.id = bswap_64(self->read.id); | 291 | self->read.id = bswap_64(self->read.id); |
271 | } | 292 | } |
272 | 293 | ||
294 | static void event__attr_swap(event_t *self) | ||
295 | { | ||
296 | size_t size; | ||
297 | |||
298 | self->attr.attr.type = bswap_32(self->attr.attr.type); | ||
299 | self->attr.attr.size = bswap_32(self->attr.attr.size); | ||
300 | self->attr.attr.config = bswap_64(self->attr.attr.config); | ||
301 | self->attr.attr.sample_period = bswap_64(self->attr.attr.sample_period); | ||
302 | self->attr.attr.sample_type = bswap_64(self->attr.attr.sample_type); | ||
303 | self->attr.attr.read_format = bswap_64(self->attr.attr.read_format); | ||
304 | self->attr.attr.wakeup_events = bswap_32(self->attr.attr.wakeup_events); | ||
305 | self->attr.attr.bp_type = bswap_32(self->attr.attr.bp_type); | ||
306 | self->attr.attr.bp_addr = bswap_64(self->attr.attr.bp_addr); | ||
307 | self->attr.attr.bp_len = bswap_64(self->attr.attr.bp_len); | ||
308 | |||
309 | size = self->header.size; | ||
310 | size -= (void *)&self->attr.id - (void *)self; | ||
311 | mem_bswap_64(self->attr.id, size); | ||
312 | } | ||
313 | |||
314 | static void event__event_type_swap(event_t *self) | ||
315 | { | ||
316 | self->event_type.event_type.event_id = | ||
317 | bswap_64(self->event_type.event_type.event_id); | ||
318 | } | ||
319 | |||
320 | static void event__tracing_data_swap(event_t *self) | ||
321 | { | ||
322 | self->tracing_data.size = bswap_32(self->tracing_data.size); | ||
323 | } | ||
324 | |||
273 | typedef void (*event__swap_op)(event_t *self); | 325 | typedef void (*event__swap_op)(event_t *self); |
274 | 326 | ||
275 | static event__swap_op event__swap_ops[] = { | 327 | static event__swap_op event__swap_ops[] = { |
@@ -280,9 +332,212 @@ static event__swap_op event__swap_ops[] = { | |||
280 | [PERF_RECORD_LOST] = event__all64_swap, | 332 | [PERF_RECORD_LOST] = event__all64_swap, |
281 | [PERF_RECORD_READ] = event__read_swap, | 333 | [PERF_RECORD_READ] = event__read_swap, |
282 | [PERF_RECORD_SAMPLE] = event__all64_swap, | 334 | [PERF_RECORD_SAMPLE] = event__all64_swap, |
283 | [PERF_RECORD_MAX] = NULL, | 335 | [PERF_RECORD_HEADER_ATTR] = event__attr_swap, |
336 | [PERF_RECORD_HEADER_EVENT_TYPE] = event__event_type_swap, | ||
337 | [PERF_RECORD_HEADER_TRACING_DATA] = event__tracing_data_swap, | ||
338 | [PERF_RECORD_HEADER_BUILD_ID] = NULL, | ||
339 | [PERF_RECORD_HEADER_MAX] = NULL, | ||
284 | }; | 340 | }; |
285 | 341 | ||
342 | struct sample_queue { | ||
343 | u64 timestamp; | ||
344 | struct sample_event *event; | ||
345 | struct list_head list; | ||
346 | }; | ||
347 | |||
348 | static void flush_sample_queue(struct perf_session *s, | ||
349 | struct perf_event_ops *ops) | ||
350 | { | ||
351 | struct list_head *head = &s->ordered_samples.samples_head; | ||
352 | u64 limit = s->ordered_samples.next_flush; | ||
353 | struct sample_queue *tmp, *iter; | ||
354 | |||
355 | if (!ops->ordered_samples || !limit) | ||
356 | return; | ||
357 | |||
358 | list_for_each_entry_safe(iter, tmp, head, list) { | ||
359 | if (iter->timestamp > limit) | ||
360 | return; | ||
361 | |||
362 | if (iter == s->ordered_samples.last_inserted) | ||
363 | s->ordered_samples.last_inserted = NULL; | ||
364 | |||
365 | ops->sample((event_t *)iter->event, s); | ||
366 | |||
367 | s->ordered_samples.last_flush = iter->timestamp; | ||
368 | list_del(&iter->list); | ||
369 | free(iter->event); | ||
370 | free(iter); | ||
371 | } | ||
372 | } | ||
373 | |||
374 | /* | ||
375 | * When perf record finishes a pass on every buffers, it records this pseudo | ||
376 | * event. | ||
377 | * We record the max timestamp t found in the pass n. | ||
378 | * Assuming these timestamps are monotonic across cpus, we know that if | ||
379 | * a buffer still has events with timestamps below t, they will be all | ||
380 | * available and then read in the pass n + 1. | ||
381 | * Hence when we start to read the pass n + 2, we can safely flush every | ||
382 | * events with timestamps below t. | ||
383 | * | ||
384 | * ============ PASS n ================= | ||
385 | * CPU 0 | CPU 1 | ||
386 | * | | ||
387 | * cnt1 timestamps | cnt2 timestamps | ||
388 | * 1 | 2 | ||
389 | * 2 | 3 | ||
390 | * - | 4 <--- max recorded | ||
391 | * | ||
392 | * ============ PASS n + 1 ============== | ||
393 | * CPU 0 | CPU 1 | ||
394 | * | | ||
395 | * cnt1 timestamps | cnt2 timestamps | ||
396 | * 3 | 5 | ||
397 | * 4 | 6 | ||
398 | * 5 | 7 <---- max recorded | ||
399 | * | ||
400 | * Flush every events below timestamp 4 | ||
401 | * | ||
402 | * ============ PASS n + 2 ============== | ||
403 | * CPU 0 | CPU 1 | ||
404 | * | | ||
405 | * cnt1 timestamps | cnt2 timestamps | ||
406 | * 6 | 8 | ||
407 | * 7 | 9 | ||
408 | * - | 10 | ||
409 | * | ||
410 | * Flush every events below timestamp 7 | ||
411 | * etc... | ||
412 | */ | ||
413 | static int process_finished_round(event_t *event __used, | ||
414 | struct perf_session *session, | ||
415 | struct perf_event_ops *ops) | ||
416 | { | ||
417 | flush_sample_queue(session, ops); | ||
418 | session->ordered_samples.next_flush = session->ordered_samples.max_timestamp; | ||
419 | |||
420 | return 0; | ||
421 | } | ||
422 | |||
423 | static void __queue_sample_end(struct sample_queue *new, struct list_head *head) | ||
424 | { | ||
425 | struct sample_queue *iter; | ||
426 | |||
427 | list_for_each_entry_reverse(iter, head, list) { | ||
428 | if (iter->timestamp < new->timestamp) { | ||
429 | list_add(&new->list, &iter->list); | ||
430 | return; | ||
431 | } | ||
432 | } | ||
433 | |||
434 | list_add(&new->list, head); | ||
435 | } | ||
436 | |||
437 | static void __queue_sample_before(struct sample_queue *new, | ||
438 | struct sample_queue *iter, | ||
439 | struct list_head *head) | ||
440 | { | ||
441 | list_for_each_entry_continue_reverse(iter, head, list) { | ||
442 | if (iter->timestamp < new->timestamp) { | ||
443 | list_add(&new->list, &iter->list); | ||
444 | return; | ||
445 | } | ||
446 | } | ||
447 | |||
448 | list_add(&new->list, head); | ||
449 | } | ||
450 | |||
451 | static void __queue_sample_after(struct sample_queue *new, | ||
452 | struct sample_queue *iter, | ||
453 | struct list_head *head) | ||
454 | { | ||
455 | list_for_each_entry_continue(iter, head, list) { | ||
456 | if (iter->timestamp > new->timestamp) { | ||
457 | list_add_tail(&new->list, &iter->list); | ||
458 | return; | ||
459 | } | ||
460 | } | ||
461 | list_add_tail(&new->list, head); | ||
462 | } | ||
463 | |||
464 | /* The queue is ordered by time */ | ||
465 | static void __queue_sample_event(struct sample_queue *new, | ||
466 | struct perf_session *s) | ||
467 | { | ||
468 | struct sample_queue *last_inserted = s->ordered_samples.last_inserted; | ||
469 | struct list_head *head = &s->ordered_samples.samples_head; | ||
470 | |||
471 | |||
472 | if (!last_inserted) { | ||
473 | __queue_sample_end(new, head); | ||
474 | return; | ||
475 | } | ||
476 | |||
477 | /* | ||
478 | * Most of the time the current event has a timestamp | ||
479 | * very close to the last event inserted, unless we just switched | ||
480 | * to another event buffer. Having a sorting based on a list and | ||
481 | * on the last inserted event that is close to the current one is | ||
482 | * probably more efficient than an rbtree based sorting. | ||
483 | */ | ||
484 | if (last_inserted->timestamp >= new->timestamp) | ||
485 | __queue_sample_before(new, last_inserted, head); | ||
486 | else | ||
487 | __queue_sample_after(new, last_inserted, head); | ||
488 | } | ||
489 | |||
490 | static int queue_sample_event(event_t *event, struct sample_data *data, | ||
491 | struct perf_session *s) | ||
492 | { | ||
493 | u64 timestamp = data->time; | ||
494 | struct sample_queue *new; | ||
495 | |||
496 | |||
497 | if (timestamp < s->ordered_samples.last_flush) { | ||
498 | printf("Warning: Timestamp below last timeslice flush\n"); | ||
499 | return -EINVAL; | ||
500 | } | ||
501 | |||
502 | new = malloc(sizeof(*new)); | ||
503 | if (!new) | ||
504 | return -ENOMEM; | ||
505 | |||
506 | new->timestamp = timestamp; | ||
507 | |||
508 | new->event = malloc(event->header.size); | ||
509 | if (!new->event) { | ||
510 | free(new); | ||
511 | return -ENOMEM; | ||
512 | } | ||
513 | |||
514 | memcpy(new->event, event, event->header.size); | ||
515 | |||
516 | __queue_sample_event(new, s); | ||
517 | s->ordered_samples.last_inserted = new; | ||
518 | |||
519 | if (new->timestamp > s->ordered_samples.max_timestamp) | ||
520 | s->ordered_samples.max_timestamp = new->timestamp; | ||
521 | |||
522 | return 0; | ||
523 | } | ||
524 | |||
525 | static int perf_session__process_sample(event_t *event, struct perf_session *s, | ||
526 | struct perf_event_ops *ops) | ||
527 | { | ||
528 | struct sample_data data; | ||
529 | |||
530 | if (!ops->ordered_samples) | ||
531 | return ops->sample(event, s); | ||
532 | |||
533 | bzero(&data, sizeof(struct sample_data)); | ||
534 | event__parse_sample(event, s->sample_type, &data); | ||
535 | |||
536 | queue_sample_event(event, &data, s); | ||
537 | |||
538 | return 0; | ||
539 | } | ||
540 | |||
286 | static int perf_session__process_event(struct perf_session *self, | 541 | static int perf_session__process_event(struct perf_session *self, |
287 | event_t *event, | 542 | event_t *event, |
288 | struct perf_event_ops *ops, | 543 | struct perf_event_ops *ops, |
@@ -290,12 +545,11 @@ static int perf_session__process_event(struct perf_session *self, | |||
290 | { | 545 | { |
291 | trace_event(event); | 546 | trace_event(event); |
292 | 547 | ||
293 | if (event->header.type < PERF_RECORD_MAX) { | 548 | if (event->header.type < PERF_RECORD_HEADER_MAX) { |
294 | dump_printf("%#Lx [%#x]: PERF_RECORD_%s", | 549 | dump_printf("%#Lx [%#x]: PERF_RECORD_%s", |
295 | offset + head, event->header.size, | 550 | offset + head, event->header.size, |
296 | event__name[event->header.type]); | 551 | event__name[event->header.type]); |
297 | ++event__total[0]; | 552 | hists__inc_nr_events(&self->hists, event->header.type); |
298 | ++event__total[event->header.type]; | ||
299 | } | 553 | } |
300 | 554 | ||
301 | if (self->header.needs_swap && event__swap_ops[event->header.type]) | 555 | if (self->header.needs_swap && event__swap_ops[event->header.type]) |
@@ -303,7 +557,7 @@ static int perf_session__process_event(struct perf_session *self, | |||
303 | 557 | ||
304 | switch (event->header.type) { | 558 | switch (event->header.type) { |
305 | case PERF_RECORD_SAMPLE: | 559 | case PERF_RECORD_SAMPLE: |
306 | return ops->sample(event, self); | 560 | return perf_session__process_sample(event, self, ops); |
307 | case PERF_RECORD_MMAP: | 561 | case PERF_RECORD_MMAP: |
308 | return ops->mmap(event, self); | 562 | return ops->mmap(event, self); |
309 | case PERF_RECORD_COMM: | 563 | case PERF_RECORD_COMM: |
@@ -320,8 +574,20 @@ static int perf_session__process_event(struct perf_session *self, | |||
320 | return ops->throttle(event, self); | 574 | return ops->throttle(event, self); |
321 | case PERF_RECORD_UNTHROTTLE: | 575 | case PERF_RECORD_UNTHROTTLE: |
322 | return ops->unthrottle(event, self); | 576 | return ops->unthrottle(event, self); |
577 | case PERF_RECORD_HEADER_ATTR: | ||
578 | return ops->attr(event, self); | ||
579 | case PERF_RECORD_HEADER_EVENT_TYPE: | ||
580 | return ops->event_type(event, self); | ||
581 | case PERF_RECORD_HEADER_TRACING_DATA: | ||
582 | /* setup for reading amidst mmap */ | ||
583 | lseek(self->fd, offset + head, SEEK_SET); | ||
584 | return ops->tracing_data(event, self); | ||
585 | case PERF_RECORD_HEADER_BUILD_ID: | ||
586 | return ops->build_id(event, self); | ||
587 | case PERF_RECORD_FINISHED_ROUND: | ||
588 | return ops->finished_round(event, self, ops); | ||
323 | default: | 589 | default: |
324 | self->unknown_events++; | 590 | ++self->hists.stats.nr_unknown_events; |
325 | return -1; | 591 | return -1; |
326 | } | 592 | } |
327 | } | 593 | } |
@@ -333,56 +599,114 @@ void perf_event_header__bswap(struct perf_event_header *self) | |||
333 | self->size = bswap_16(self->size); | 599 | self->size = bswap_16(self->size); |
334 | } | 600 | } |
335 | 601 | ||
336 | int perf_header__read_build_ids(struct perf_header *self, | 602 | static struct thread *perf_session__register_idle_thread(struct perf_session *self) |
337 | int input, u64 offset, u64 size) | ||
338 | { | 603 | { |
339 | struct build_id_event bev; | 604 | struct thread *thread = perf_session__findnew(self, 0); |
340 | char filename[PATH_MAX]; | ||
341 | u64 limit = offset + size; | ||
342 | int err = -1; | ||
343 | |||
344 | while (offset < limit) { | ||
345 | struct dso *dso; | ||
346 | ssize_t len; | ||
347 | struct list_head *head = &dsos__user; | ||
348 | 605 | ||
349 | if (read(input, &bev, sizeof(bev)) != sizeof(bev)) | 606 | if (thread == NULL || thread__set_comm(thread, "swapper")) { |
350 | goto out; | 607 | pr_err("problem inserting idle task.\n"); |
608 | thread = NULL; | ||
609 | } | ||
351 | 610 | ||
352 | if (self->needs_swap) | 611 | return thread; |
353 | perf_event_header__bswap(&bev.header); | 612 | } |
354 | 613 | ||
355 | len = bev.header.size - sizeof(bev); | 614 | int do_read(int fd, void *buf, size_t size) |
356 | if (read(input, filename, len) != len) | 615 | { |
357 | goto out; | 616 | void *buf_start = buf; |
358 | 617 | ||
359 | if (bev.header.misc & PERF_RECORD_MISC_KERNEL) | 618 | while (size) { |
360 | head = &dsos__kernel; | 619 | int ret = read(fd, buf, size); |
361 | 620 | ||
362 | dso = __dsos__findnew(head, filename); | 621 | if (ret <= 0) |
363 | if (dso != NULL) { | 622 | return ret; |
364 | dso__set_build_id(dso, &bev.build_id); | ||
365 | if (head == &dsos__kernel && filename[0] == '[') | ||
366 | dso->kernel = 1; | ||
367 | } | ||
368 | 623 | ||
369 | offset += bev.header.size; | 624 | size -= ret; |
625 | buf += ret; | ||
370 | } | 626 | } |
371 | err = 0; | 627 | |
372 | out: | 628 | return buf - buf_start; |
373 | return err; | ||
374 | } | 629 | } |
375 | 630 | ||
376 | static struct thread *perf_session__register_idle_thread(struct perf_session *self) | 631 | #define session_done() (*(volatile int *)(&session_done)) |
632 | volatile int session_done; | ||
633 | |||
634 | static int __perf_session__process_pipe_events(struct perf_session *self, | ||
635 | struct perf_event_ops *ops) | ||
377 | { | 636 | { |
378 | struct thread *thread = perf_session__findnew(self, 0); | 637 | event_t event; |
638 | uint32_t size; | ||
639 | int skip = 0; | ||
640 | u64 head; | ||
641 | int err; | ||
642 | void *p; | ||
379 | 643 | ||
380 | if (thread == NULL || thread__set_comm(thread, "swapper")) { | 644 | perf_event_ops__fill_defaults(ops); |
381 | pr_err("problem inserting idle task.\n"); | 645 | |
382 | thread = NULL; | 646 | head = 0; |
647 | more: | ||
648 | err = do_read(self->fd, &event, sizeof(struct perf_event_header)); | ||
649 | if (err <= 0) { | ||
650 | if (err == 0) | ||
651 | goto done; | ||
652 | |||
653 | pr_err("failed to read event header\n"); | ||
654 | goto out_err; | ||
383 | } | 655 | } |
384 | 656 | ||
385 | return thread; | 657 | if (self->header.needs_swap) |
658 | perf_event_header__bswap(&event.header); | ||
659 | |||
660 | size = event.header.size; | ||
661 | if (size == 0) | ||
662 | size = 8; | ||
663 | |||
664 | p = &event; | ||
665 | p += sizeof(struct perf_event_header); | ||
666 | |||
667 | if (size - sizeof(struct perf_event_header)) { | ||
668 | err = do_read(self->fd, p, | ||
669 | size - sizeof(struct perf_event_header)); | ||
670 | if (err <= 0) { | ||
671 | if (err == 0) { | ||
672 | pr_err("unexpected end of event stream\n"); | ||
673 | goto done; | ||
674 | } | ||
675 | |||
676 | pr_err("failed to read event data\n"); | ||
677 | goto out_err; | ||
678 | } | ||
679 | } | ||
680 | |||
681 | if (size == 0 || | ||
682 | (skip = perf_session__process_event(self, &event, ops, | ||
683 | 0, head)) < 0) { | ||
684 | dump_printf("%#Lx [%#x]: skipping unknown header type: %d\n", | ||
685 | head, event.header.size, event.header.type); | ||
686 | /* | ||
687 | * assume we lost track of the stream, check alignment, and | ||
688 | * increment a single u64 in the hope to catch on again 'soon'. | ||
689 | */ | ||
690 | if (unlikely(head & 7)) | ||
691 | head &= ~7ULL; | ||
692 | |||
693 | size = 8; | ||
694 | } | ||
695 | |||
696 | head += size; | ||
697 | |||
698 | dump_printf("\n%#Lx [%#x]: event: %d\n", | ||
699 | head, event.header.size, event.header.type); | ||
700 | |||
701 | if (skip > 0) | ||
702 | head += skip; | ||
703 | |||
704 | if (!session_done()) | ||
705 | goto more; | ||
706 | done: | ||
707 | err = 0; | ||
708 | out_err: | ||
709 | return err; | ||
386 | } | 710 | } |
387 | 711 | ||
388 | int __perf_session__process_events(struct perf_session *self, | 712 | int __perf_session__process_events(struct perf_session *self, |
@@ -396,6 +720,10 @@ int __perf_session__process_events(struct perf_session *self, | |||
396 | event_t *event; | 720 | event_t *event; |
397 | uint32_t size; | 721 | uint32_t size; |
398 | char *buf; | 722 | char *buf; |
723 | struct ui_progress *progress = ui_progress__new("Processing events...", | ||
724 | self->size); | ||
725 | if (progress == NULL) | ||
726 | return -1; | ||
399 | 727 | ||
400 | perf_event_ops__fill_defaults(ops); | 728 | perf_event_ops__fill_defaults(ops); |
401 | 729 | ||
@@ -424,6 +752,7 @@ remap: | |||
424 | 752 | ||
425 | more: | 753 | more: |
426 | event = (event_t *)(buf + head); | 754 | event = (event_t *)(buf + head); |
755 | ui_progress__update(progress, offset); | ||
427 | 756 | ||
428 | if (self->header.needs_swap) | 757 | if (self->header.needs_swap) |
429 | perf_event_header__bswap(&event->header); | 758 | perf_event_header__bswap(&event->header); |
@@ -473,7 +802,11 @@ more: | |||
473 | goto more; | 802 | goto more; |
474 | done: | 803 | done: |
475 | err = 0; | 804 | err = 0; |
805 | /* do the final flush for ordered samples */ | ||
806 | self->ordered_samples.next_flush = ULLONG_MAX; | ||
807 | flush_sample_queue(self, ops); | ||
476 | out_err: | 808 | out_err: |
809 | ui_progress__delete(progress); | ||
477 | return err; | 810 | return err; |
478 | } | 811 | } |
479 | 812 | ||
@@ -502,9 +835,13 @@ out_getcwd_err: | |||
502 | self->cwdlen = strlen(self->cwd); | 835 | self->cwdlen = strlen(self->cwd); |
503 | } | 836 | } |
504 | 837 | ||
505 | err = __perf_session__process_events(self, self->header.data_offset, | 838 | if (!self->fd_pipe) |
506 | self->header.data_size, | 839 | err = __perf_session__process_events(self, |
507 | self->size, ops); | 840 | self->header.data_offset, |
841 | self->header.data_size, | ||
842 | self->size, ops); | ||
843 | else | ||
844 | err = __perf_session__process_pipe_events(self, ops); | ||
508 | out_err: | 845 | out_err: |
509 | return err; | 846 | return err; |
510 | } | 847 | } |
@@ -519,56 +856,41 @@ bool perf_session__has_traces(struct perf_session *self, const char *msg) | |||
519 | return true; | 856 | return true; |
520 | } | 857 | } |
521 | 858 | ||
522 | int perf_session__set_kallsyms_ref_reloc_sym(struct perf_session *self, | 859 | int perf_session__set_kallsyms_ref_reloc_sym(struct map **maps, |
523 | const char *symbol_name, | 860 | const char *symbol_name, |
524 | u64 addr) | 861 | u64 addr) |
525 | { | 862 | { |
526 | char *bracket; | 863 | char *bracket; |
527 | enum map_type i; | 864 | enum map_type i; |
865 | struct ref_reloc_sym *ref; | ||
528 | 866 | ||
529 | self->ref_reloc_sym.name = strdup(symbol_name); | 867 | ref = zalloc(sizeof(struct ref_reloc_sym)); |
530 | if (self->ref_reloc_sym.name == NULL) | 868 | if (ref == NULL) |
531 | return -ENOMEM; | 869 | return -ENOMEM; |
532 | 870 | ||
533 | bracket = strchr(self->ref_reloc_sym.name, ']'); | 871 | ref->name = strdup(symbol_name); |
872 | if (ref->name == NULL) { | ||
873 | free(ref); | ||
874 | return -ENOMEM; | ||
875 | } | ||
876 | |||
877 | bracket = strchr(ref->name, ']'); | ||
534 | if (bracket) | 878 | if (bracket) |
535 | *bracket = '\0'; | 879 | *bracket = '\0'; |
536 | 880 | ||
537 | self->ref_reloc_sym.addr = addr; | 881 | ref->addr = addr; |
538 | 882 | ||
539 | for (i = 0; i < MAP__NR_TYPES; ++i) { | 883 | for (i = 0; i < MAP__NR_TYPES; ++i) { |
540 | struct kmap *kmap = map__kmap(self->vmlinux_maps[i]); | 884 | struct kmap *kmap = map__kmap(maps[i]); |
541 | kmap->ref_reloc_sym = &self->ref_reloc_sym; | 885 | kmap->ref_reloc_sym = ref; |
542 | } | 886 | } |
543 | 887 | ||
544 | return 0; | 888 | return 0; |
545 | } | 889 | } |
546 | 890 | ||
547 | static u64 map__reloc_map_ip(struct map *map, u64 ip) | 891 | size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp) |
548 | { | ||
549 | return ip + (s64)map->pgoff; | ||
550 | } | ||
551 | |||
552 | static u64 map__reloc_unmap_ip(struct map *map, u64 ip) | ||
553 | { | ||
554 | return ip - (s64)map->pgoff; | ||
555 | } | ||
556 | |||
557 | void map__reloc_vmlinux(struct map *self) | ||
558 | { | 892 | { |
559 | struct kmap *kmap = map__kmap(self); | 893 | return __dsos__fprintf(&self->host_machine.kernel_dsos, fp) + |
560 | s64 reloc; | 894 | __dsos__fprintf(&self->host_machine.user_dsos, fp) + |
561 | 895 | machines__fprintf_dsos(&self->machines, fp); | |
562 | if (!kmap->ref_reloc_sym || !kmap->ref_reloc_sym->unrelocated_addr) | ||
563 | return; | ||
564 | |||
565 | reloc = (kmap->ref_reloc_sym->unrelocated_addr - | ||
566 | kmap->ref_reloc_sym->addr); | ||
567 | |||
568 | if (!reloc) | ||
569 | return; | ||
570 | |||
571 | self->map_ip = map__reloc_map_ip; | ||
572 | self->unmap_ip = map__reloc_unmap_ip; | ||
573 | self->pgoff = reloc; | ||
574 | } | 896 | } |