aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung@kernel.org>2013-10-30 21:05:29 -0400
committerJiri Olsa <jolsa@kernel.org>2014-06-01 08:34:58 -0400
commitb4d3c8bd86c4eda08456691121f83b4e1db46866 (patch)
treee2d7d9cd824fd91a97b4ade66d11098290ccd656 /tools
parentc7405d85d7a354b8ba49e2db7c4b027e6cb997c1 (diff)
perf report: Cache cumulative callchains
It is possble that a callchain has cycles or recursive calls. In that case it'll end up having entries more than 100% overhead in the output. In order to prevent such entries, cache each callchain node and skip if same entry already cumulated. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Tested-by: Arun Sharma <asharma@fb.com> Tested-by: Rodrigo Campos <rodrigo@sdfg.com.ar> Cc: Frederic Weisbecker <fweisbec@gmail.com> Link: http://lkml.kernel.org/r/1401335910-16832-8-git-send-email-namhyung@kernel.org Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/util/hist.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 37c28fc13dc3..bf03db528db6 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -700,7 +700,22 @@ static int
700iter_prepare_cumulative_entry(struct hist_entry_iter *iter __maybe_unused, 700iter_prepare_cumulative_entry(struct hist_entry_iter *iter __maybe_unused,
701 struct addr_location *al __maybe_unused) 701 struct addr_location *al __maybe_unused)
702{ 702{
703 struct hist_entry **he_cache;
704
703 callchain_cursor_commit(&callchain_cursor); 705 callchain_cursor_commit(&callchain_cursor);
706
707 /*
708 * This is for detecting cycles or recursions so that they're
709 * cumulated only one time to prevent entries more than 100%
710 * overhead.
711 */
712 he_cache = malloc(sizeof(*he_cache) * (PERF_MAX_STACK_DEPTH + 1));
713 if (he_cache == NULL)
714 return -ENOMEM;
715
716 iter->priv = he_cache;
717 iter->curr = 0;
718
704 return 0; 719 return 0;
705} 720}
706 721
@@ -710,6 +725,7 @@ iter_add_single_cumulative_entry(struct hist_entry_iter *iter,
710{ 725{
711 struct perf_evsel *evsel = iter->evsel; 726 struct perf_evsel *evsel = iter->evsel;
712 struct perf_sample *sample = iter->sample; 727 struct perf_sample *sample = iter->sample;
728 struct hist_entry **he_cache = iter->priv;
713 struct hist_entry *he; 729 struct hist_entry *he;
714 int err = 0; 730 int err = 0;
715 731
@@ -720,6 +736,7 @@ iter_add_single_cumulative_entry(struct hist_entry_iter *iter,
720 return -ENOMEM; 736 return -ENOMEM;
721 737
722 iter->he = he; 738 iter->he = he;
739 he_cache[iter->curr++] = he;
723 740
724 /* 741 /*
725 * The iter->he will be over-written after ->add_next_entry() 742 * The iter->he will be over-written after ->add_next_entry()
@@ -754,7 +771,29 @@ iter_add_next_cumulative_entry(struct hist_entry_iter *iter,
754{ 771{
755 struct perf_evsel *evsel = iter->evsel; 772 struct perf_evsel *evsel = iter->evsel;
756 struct perf_sample *sample = iter->sample; 773 struct perf_sample *sample = iter->sample;
774 struct hist_entry **he_cache = iter->priv;
757 struct hist_entry *he; 775 struct hist_entry *he;
776 struct hist_entry he_tmp = {
777 .cpu = al->cpu,
778 .thread = al->thread,
779 .comm = thread__comm(al->thread),
780 .ip = al->addr,
781 .ms = {
782 .map = al->map,
783 .sym = al->sym,
784 },
785 .parent = iter->parent,
786 };
787 int i;
788
789 /*
790 * Check if there's duplicate entries in the callchain.
791 * It's possible that it has cycles or recursive calls.
792 */
793 for (i = 0; i < iter->curr; i++) {
794 if (hist_entry__cmp(he_cache[i], &he_tmp) == 0)
795 return 0;
796 }
758 797
759 he = __hists__add_entry(&evsel->hists, al, iter->parent, NULL, NULL, 798 he = __hists__add_entry(&evsel->hists, al, iter->parent, NULL, NULL,
760 sample->period, sample->weight, 799 sample->period, sample->weight,
@@ -763,6 +802,7 @@ iter_add_next_cumulative_entry(struct hist_entry_iter *iter,
763 return -ENOMEM; 802 return -ENOMEM;
764 803
765 iter->he = he; 804 iter->he = he;
805 he_cache[iter->curr++] = he;
766 806
767 return 0; 807 return 0;
768} 808}
@@ -771,7 +811,9 @@ static int
771iter_finish_cumulative_entry(struct hist_entry_iter *iter, 811iter_finish_cumulative_entry(struct hist_entry_iter *iter,
772 struct addr_location *al __maybe_unused) 812 struct addr_location *al __maybe_unused)
773{ 813{
814 zfree(&iter->priv);
774 iter->he = NULL; 815 iter->he = NULL;
816
775 return 0; 817 return 0;
776} 818}
777 819