diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2009-10-03 09:42:45 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-10-03 10:01:59 -0400 |
commit | 9735abf11bec48bfbbb1b54772a02deb2ae0c403 (patch) | |
tree | 9bb3c292419443619311b0eedb121149d33e7f59 /tools/perf/builtin-report.c | |
parent | 439d473b4777de510e1322168ac6f2f377ecd5bc (diff) |
perf tools: Move hist_entry__add common code to hist.c
Now perf report and annotate do the callgraph/hit processing in
their specialized hist_entry__add functions.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Mike Galbraith <efault@gmx.de>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/builtin-report.c')
-rw-r--r-- | tools/perf/builtin-report.c | 63 |
1 files changed, 16 insertions, 47 deletions
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 3ed3baf96ffb..0e83ffcbe55a 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c | |||
@@ -407,9 +407,9 @@ static int call__match(struct symbol *sym) | |||
407 | return 0; | 407 | return 0; |
408 | } | 408 | } |
409 | 409 | ||
410 | static struct symbol ** | 410 | static struct symbol **resolve_callchain(struct thread *thread, struct map *map, |
411 | resolve_callchain(struct thread *thread, struct map *map, | 411 | struct ip_callchain *chain, |
412 | struct ip_callchain *chain, struct hist_entry *entry) | 412 | struct symbol **parent) |
413 | { | 413 | { |
414 | u64 context = PERF_CONTEXT_MAX; | 414 | u64 context = PERF_CONTEXT_MAX; |
415 | struct symbol **syms = NULL; | 415 | struct symbol **syms = NULL; |
@@ -444,9 +444,8 @@ resolve_callchain(struct thread *thread, struct map *map, | |||
444 | } | 444 | } |
445 | 445 | ||
446 | if (sym) { | 446 | if (sym) { |
447 | if (sort__has_parent && call__match(sym) && | 447 | if (sort__has_parent && !*parent && call__match(sym)) |
448 | !entry->parent) | 448 | *parent = sym; |
449 | entry->parent = sym; | ||
450 | if (!callchain) | 449 | if (!callchain) |
451 | break; | 450 | break; |
452 | syms[i] = sym; | 451 | syms[i] = sym; |
@@ -465,57 +464,27 @@ hist_entry__add(struct thread *thread, struct map *map, | |||
465 | struct symbol *sym, u64 ip, struct ip_callchain *chain, | 464 | struct symbol *sym, u64 ip, struct ip_callchain *chain, |
466 | char level, u64 count) | 465 | char level, u64 count) |
467 | { | 466 | { |
468 | struct rb_node **p = &hist.rb_node; | 467 | struct symbol **syms = NULL, *parent = NULL; |
469 | struct rb_node *parent = NULL; | 468 | bool hit; |
470 | struct hist_entry *he; | 469 | struct hist_entry *he; |
471 | struct symbol **syms = NULL; | ||
472 | struct hist_entry entry = { | ||
473 | .thread = thread, | ||
474 | .map = map, | ||
475 | .sym = sym, | ||
476 | .ip = ip, | ||
477 | .level = level, | ||
478 | .count = count, | ||
479 | .parent = NULL, | ||
480 | .sorted_chain = RB_ROOT | ||
481 | }; | ||
482 | int cmp; | ||
483 | 470 | ||
484 | if ((sort__has_parent || callchain) && chain) | 471 | if ((sort__has_parent || callchain) && chain) |
485 | syms = resolve_callchain(thread, map, chain, &entry); | 472 | syms = resolve_callchain(thread, map, chain, &parent); |
486 | |||
487 | while (*p != NULL) { | ||
488 | parent = *p; | ||
489 | he = rb_entry(parent, struct hist_entry, rb_node); | ||
490 | |||
491 | cmp = hist_entry__cmp(&entry, he); | ||
492 | 473 | ||
493 | if (!cmp) { | 474 | he = __hist_entry__add(thread, map, sym, parent, |
494 | he->count += count; | 475 | ip, count, level, &hit); |
495 | if (callchain) { | 476 | if (he == NULL) |
496 | append_chain(&he->callchain, chain, syms); | 477 | return -ENOMEM; |
497 | free(syms); | ||
498 | } | ||
499 | return 0; | ||
500 | } | ||
501 | 478 | ||
502 | if (cmp < 0) | 479 | if (hit) |
503 | p = &(*p)->rb_left; | 480 | he->count += count; |
504 | else | ||
505 | p = &(*p)->rb_right; | ||
506 | } | ||
507 | 481 | ||
508 | he = malloc(sizeof(*he)); | ||
509 | if (!he) | ||
510 | return -ENOMEM; | ||
511 | *he = entry; | ||
512 | if (callchain) { | 482 | if (callchain) { |
513 | callchain_init(&he->callchain); | 483 | if (!hit) |
484 | callchain_init(&he->callchain); | ||
514 | append_chain(&he->callchain, chain, syms); | 485 | append_chain(&he->callchain, chain, syms); |
515 | free(syms); | 486 | free(syms); |
516 | } | 487 | } |
517 | rb_link_node(&he->rb_node, parent, p); | ||
518 | rb_insert_color(&he->rb_node, &hist); | ||
519 | 488 | ||
520 | return 0; | 489 | return 0; |
521 | } | 490 | } |