perf annotate: Remove hist__account_cycles() from callback
authorJin Yao <yao.jin@linux.intel.com>
Fri, 15 Mar 2019 21:16:17 +0000 (05:16 +0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 15 May 2019 19:36:46 +0000 (16:36 -0300)
The hist__account_cycles() function is executed when the
hist_iter__branch_callback() is called.

But it looks it's not necessary.  In hist__account_cycles, it already
walks on all branch entries.

This patch moves the hist__account_cycles out of callback, now the data
processing is much faster than before.

Previous code has an issue that the ch[offset].num++ (in
__symbol__account_cycles) is executed repeatedly since
hist__account_cycles is called in each hist_iter__branch_callback, so
the counting of ch[offset].num is not correct (too big).

With this patch, the issue is fixed. And we don't need the code of
"ch->reset >= ch->num / 2" to check if there are too many overlaps (in
annotation__count_and_fill), otherwise some data would be hidden.

Now, we can try, for example:

  perf record -b ...
  perf annotate or perf report -s symbol

The before/after output should be no change.

 v3:
 ---
 Fix the crash in stdio mode.
 Like previous code, it needs the checking of ui__has_annotation()
 before hist__account_cycles()

 v2:
 ---
 1. Cover the similar perf report
 2. Remove the checking code "ch->reset >= ch->num / 2"

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1552684577-29041-1-git-send-email-yao.jin@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-annotate.c
tools/perf/builtin-report.c
tools/perf/util/annotate.c

index 67f9d9ffacfbb9cdfe9e56496a7c1c264b700c5f..77deb3a40596dc1d0bc54de75e08d5942a431639 100644 (file)
@@ -159,8 +159,6 @@ static int hist_iter__branch_callback(struct hist_entry_iter *iter,
        struct perf_evsel *evsel = iter->evsel;
        int err;
 
-       hist__account_cycles(sample->branch_stack, al, sample, false);
-
        bi = he->branch_info;
        err = addr_map_symbol__inc_samples(&bi->from, sample, evsel);
 
@@ -199,6 +197,8 @@ static int process_branch_callback(struct perf_evsel *evsel,
        if (a.map != NULL)
                a.map->dso->hit = 1;
 
+       hist__account_cycles(sample->branch_stack, al, sample, false);
+
        ret = hist_entry_iter__add(&iter, &a, PERF_MAX_STACK_DEPTH, ann);
        return ret;
 }
index 4054eb1f98ac19d956cf680dfb84dcf13d509db5..91e27ac297c226b7a3e8322c94dc102c0bed94ce 100644 (file)
@@ -136,9 +136,6 @@ static int hist_iter__report_callback(struct hist_entry_iter *iter,
        if (!ui__has_annotation() && !rep->symbol_ipc)
                return 0;
 
-       hist__account_cycles(sample->branch_stack, al, sample,
-                            rep->nonany_branch_mode);
-
        if (sort__mode == SORT_MODE__BRANCH) {
                bi = he->branch_info;
                err = addr_map_symbol__inc_samples(&bi->from, sample, evsel);
@@ -181,9 +178,6 @@ static int hist_iter__branch_callback(struct hist_entry_iter *iter,
        if (!ui__has_annotation() && !rep->symbol_ipc)
                return 0;
 
-       hist__account_cycles(sample->branch_stack, al, sample,
-                            rep->nonany_branch_mode);
-
        bi = he->branch_info;
        err = addr_map_symbol__inc_samples(&bi->from, sample, evsel);
        if (err)
@@ -282,6 +276,11 @@ static int process_sample_event(struct perf_tool *tool,
        if (al.map != NULL)
                al.map->dso->hit = 1;
 
+       if (ui__has_annotation() || rep->symbol_ipc) {
+               hist__account_cycles(sample->branch_stack, &al, sample,
+                                    rep->nonany_branch_mode);
+       }
+
        ret = hist_entry_iter__add(&iter, &al, rep->max_stack, rep);
        if (ret < 0)
                pr_debug("problem adding hist entry, skipping event\n");
index 09762985c7137c36e64b68046639f699477b37c0..0b8573fd9b05482528c80fd55151cc3e8969f8af 100644 (file)
@@ -1021,7 +1021,7 @@ static void annotation__count_and_fill(struct annotation *notes, u64 start, u64
                float ipc = n_insn / ((double)ch->cycles / (double)ch->num);
 
                /* Hide data when there are too many overlaps. */
-               if (ch->reset >= 0x7fff || ch->reset >= ch->num / 2)
+               if (ch->reset >= 0x7fff)
                        return;
 
                for (offset = start; offset <= end; offset++) {