From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753627AbdHPCWO (ORCPT ); Tue, 15 Aug 2017 22:22:14 -0400 Received: from mga01.intel.com ([192.55.52.88]:49608 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753576AbdHPCWL (ORCPT ); Tue, 15 Aug 2017 22:22:11 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,380,1498546800"; d="scan'208";a="119442543" From: Jin Yao To: acme@kernel.org, jolsa@kernel.org, peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com Cc: Linux-kernel@vger.kernel.org, ak@linux.intel.com, kan.liang@intel.com, yao.jin@intel.com, Jin Yao Subject: [PATCH v1 3/4] perf annotate: Display multiple events for tui mode Date: Wed, 16 Aug 2017 18:18:35 +0800 Message-Id: <1502878716-30817-4-git-send-email-yao.jin@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502878716-30817-1-git-send-email-yao.jin@linux.intel.com> References: <1502878716-30817-1-git-send-email-yao.jin@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For example: perf record -e cycles,branches ./div perf annotate main │ for (i = 0; i < 2000000000; i++) { │ flag = compute_flag(); 5.77 4.85 │38: xor %eax,%eax 0.01 0.01 │ → callq compute_flag │ │ count++; 2.38 4.38 │ mov count,%edx 0.00 0.00 │ add $0x1,%edx │ │ if (flag) │ test %eax,%eax │ srand(s_randseed); │ │ for (i = 0; i < 2000000000; i++) { │ flag = compute_flag(); │ │ count++; 0.60 0.44 │ mov %edx,count │ │ if (flag) 3.99 4.32 │ ↓ je 82 Signed-off-by: Jin Yao --- tools/perf/ui/browsers/annotate.c | 49 ++++++++++++++++++++++++++++----------- tools/perf/ui/browsers/hists.c | 2 +- tools/perf/util/annotate.h | 6 +++-- tools/perf/util/hist.h | 8 ++++--- 4 files changed, 45 insertions(+), 20 deletions(-) diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c index 80f38da..b76c238 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -428,13 +428,15 @@ static void annotate_browser__set_rb_top(struct annotate_browser *browser, } static void annotate_browser__calc_percent(struct annotate_browser *browser, - struct perf_evsel *evsel) + struct perf_evsel *evsel, + struct hist_entry *he) { struct map_symbol *ms = browser->b.priv; struct symbol *sym = ms->sym; struct annotation *notes = symbol__annotation(sym); struct disasm_line *pos, *next; s64 len = symbol__size(sym); + struct hist_event *hevt; browser->entries = RB_ROOT; @@ -455,13 +457,25 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser, for (i = 0; i < browser->nr_events; i++) { struct sym_hist_entry sample; - - bpos->samples[i].percent = disasm__calc_percent(notes, + if (evsel) { + bpos->samples[i].percent = + disasm__calc_percent(notes, evsel->idx + i, pos->offset, next ? next->offset : len, &path, &sample); - bpos->samples[i].he = sample; + bpos->samples[i].he = sample; + } else if (he) { + hevt = &he->events[i]; + notes = symbol__annotation(hevt->ms.sym); + bpos->samples[i].percent = + disasm__calc_percent(notes, + hevt->idx, + pos->offset, + next ? next->offset : len, + &path, &sample); + bpos->samples[i].he = sample; + } if (max_percent < bpos->samples[i].percent) max_percent = bpos->samples[i].percent; @@ -567,7 +581,7 @@ static bool annotate_browser__callq(struct annotate_browser *browser, } pthread_mutex_unlock(¬es->lock); - symbol__tui_annotate(target.sym, target.map, evsel, hbt); + symbol__tui_annotate(target.sym, target.map, evsel, hbt, NULL); sym_title(ms->sym, ms->map, title, sizeof(title)); ui_browser__show_title(&browser->b, title); return true; @@ -755,7 +769,8 @@ static void annotate_browser__update_addr_width(struct annotate_browser *browser static int annotate_browser__run(struct annotate_browser *browser, struct perf_evsel *evsel, - struct hist_browser_timer *hbt) + struct hist_browser_timer *hbt, + struct hist_entry *he) { struct rb_node *nd = NULL; struct map_symbol *ms = browser->b.priv; @@ -769,7 +784,7 @@ static int annotate_browser__run(struct annotate_browser *browser, if (ui_browser__show(&browser->b, title, help) < 0) return -1; - annotate_browser__calc_percent(browser, evsel); + annotate_browser__calc_percent(browser, evsel, he); if (browser->curr_hot) { annotate_browser__set_rb_top(browser, browser->curr_hot); @@ -782,7 +797,7 @@ static int annotate_browser__run(struct annotate_browser *browser, key = ui_browser__run(&browser->b, delay_secs); if (delay_secs != 0) { - annotate_browser__calc_percent(browser, evsel); + annotate_browser__calc_percent(browser, evsel, he); /* * Current line focus got out of the list of most active * lines, NULL it so that if TAB|UNTAB is pressed, we @@ -929,13 +944,14 @@ static int annotate_browser__run(struct annotate_browser *browser, } int map_symbol__tui_annotate(struct map_symbol *ms, struct perf_evsel *evsel, - struct hist_browser_timer *hbt) + struct hist_browser_timer *hbt, + struct hist_entry *he) { /* Set default value for show_total_period. */ annotate_browser__opts.show_total_period = symbol_conf.show_total_period; - return symbol__tui_annotate(ms->sym, ms->map, evsel, hbt); + return symbol__tui_annotate(ms->sym, ms->map, evsel, hbt, he); } int hist_entry__tui_annotate(struct hist_entry *he, struct perf_evsel *evsel, @@ -945,7 +961,7 @@ int hist_entry__tui_annotate(struct hist_entry *he, struct perf_evsel *evsel, SLang_reset_tty(); SLang_init_tty(0, 0, 0); - return map_symbol__tui_annotate(&he->ms, evsel, hbt); + return map_symbol__tui_annotate(&he->ms, evsel, hbt, he); } @@ -1062,7 +1078,8 @@ static inline int width_jumps(int n) int symbol__tui_annotate(struct symbol *sym, struct map *map, struct perf_evsel *evsel, - struct hist_browser_timer *hbt) + struct hist_browser_timer *hbt, + struct hist_entry *he) { struct disasm_line *pos, *n; struct annotation *notes; @@ -1099,10 +1116,14 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, return -1; } - if (perf_evsel__is_group_event(evsel)) { + if (evsel && perf_evsel__is_group_event(evsel)) { nr_pcnt = evsel->nr_members; sizeof_bdl += sizeof(struct disasm_line_samples) * (nr_pcnt - 1); + } else if (he) { + nr_pcnt = he->event_nr; + sizeof_bdl += sizeof(struct disasm_line_samples) * + (nr_pcnt - 1); } err = symbol__disassemble(sym, map, perf_evsel__env_arch(evsel), @@ -1159,7 +1180,7 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, annotate_browser__update_addr_width(&browser); - ret = annotate_browser__run(&browser, evsel, hbt); + ret = annotate_browser__run(&browser, evsel, hbt, he); list_for_each_entry_safe(pos, n, ¬es->src->source, node) { list_del(&pos->node); disasm_line__free(pos); diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index f4bc246..b37458d 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -2570,7 +2570,7 @@ do_annotate(struct hist_browser *browser, struct popup_action *act) return 0; evsel = hists_to_evsel(browser->hists); - err = map_symbol__tui_annotate(&act->ms, evsel, browser->hbt); + err = map_symbol__tui_annotate(&act->ms, evsel, browser->hbt, NULL); he = hist_browser__selected_entry(browser); /* * offer option to annotate the other branch source or target diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 83b78ff..1b9ef1d 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -214,13 +214,15 @@ int symbol__tty_annotate(struct symbol *sym, struct map *map, #ifdef HAVE_SLANG_SUPPORT int symbol__tui_annotate(struct symbol *sym, struct map *map, struct perf_evsel *evsel, - struct hist_browser_timer *hbt); + struct hist_browser_timer *hbt, + struct hist_entry *he); #else static inline int symbol__tui_annotate(struct symbol *sym __maybe_unused, struct map *map __maybe_unused, struct perf_evsel *evsel __maybe_unused, struct hist_browser_timer *hbt - __maybe_unused) + __maybe_unused, + struct hist_entry *he __maybe_unused) { return 0; } diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index ee3670a..ece79a1 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h @@ -420,7 +420,8 @@ struct hist_browser_timer { #ifdef HAVE_SLANG_SUPPORT #include "../ui/keysyms.h" int map_symbol__tui_annotate(struct map_symbol *ms, struct perf_evsel *evsel, - struct hist_browser_timer *hbt); + struct hist_browser_timer *hbt, + struct hist_entry *he); int hist_entry__tui_annotate(struct hist_entry *he, struct perf_evsel *evsel, struct hist_browser_timer *hbt); @@ -441,8 +442,9 @@ int perf_evlist__tui_browse_hists(struct perf_evlist *evlist __maybe_unused, return 0; } static inline int map_symbol__tui_annotate(struct map_symbol *ms __maybe_unused, - struct perf_evsel *evsel __maybe_unused, - struct hist_browser_timer *hbt __maybe_unused) + struct perf_evsel *evsel __maybe_unused, + struct hist_browser_timer *hbt __maybe_unused, + struct hist_entry *he __maybe_unused) { return 0; } -- 2.7.4