public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jin Yao <yao.jin@linux.intel.com>
To: acme@kernel.org, jolsa@kernel.org
Cc: Linux-kernel@vger.kernel.org, ak@linux.intel.com,
	kan.liang@intel.com, yao.jin@linux.intel.com
Subject: [PATCH v1 4/4] perf report: Show inline stack in browser mode
Date: Tue, 29 Nov 2016 22:55:44 +0800	[thread overview]
Message-ID: <1480431344-1644-5-git-send-email-yao.jin@linux.intel.com> (raw)
In-Reply-To: <1480431344-1644-1-git-send-email-yao.jin@linux.intel.com>

For example:

-    0.05%  test2    test2              [.] main
     /home/jinyao/perf-dev/test/test2.c:27 (inline)
     /home/jinyao/perf-dev/test/test2.c:35 (inline)
     /home/jinyao/perf-dev/test/test2.c:45 (inline)
     /home/jinyao/perf-dev/test/test2.c:61 (inline)

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
---
 tools/perf/ui/browsers/hists.c | 98 ++++++++++++++++++++++++++++++++++++++++--
 tools/perf/util/hist.c         |  5 +++
 tools/perf/util/sort.h         |  1 +
 3 files changed, 100 insertions(+), 4 deletions(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 641b402..c8c3cae 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -362,6 +362,46 @@ static void hist_entry__init_have_children(struct hist_entry *he)
 	he->init_have_children = true;
 }
 
+static void hist_entry_init_inline_node(struct hist_entry *he)
+{
+	struct dso *dso;
+
+	if (he->inline_node)
+		return;
+
+	if (he->ms.map == NULL)
+		return;
+
+	dso = he->ms.map->dso;
+	if (dso == NULL)
+		return;
+
+	if (dso->kernel != DSO_TYPE_USER)
+		return;
+
+	he->inline_node = get_inline_node(dso,
+		map__rip_2objdump(he->ms.map, he->ip));
+
+	if (he->inline_node == NULL)
+		return;
+
+	he->has_children = true;
+}
+
+static int inline__count_rows(struct hist_entry *he)
+{
+	struct inline_node *node = he->inline_node;
+	struct inline_list *ilist;
+	int i = 0;
+
+	list_for_each_entry(ilist, &node->val, list) {
+		if (ilist->filename != NULL)
+			i++;
+	}
+
+	return i;
+}
+
 static bool hist_browser__toggle_fold(struct hist_browser *browser)
 {
 	struct hist_entry *he = browser->he_selection;
@@ -393,7 +433,11 @@ static bool hist_browser__toggle_fold(struct hist_browser *browser)
 
 		if (he->unfolded) {
 			if (he->leaf)
-				he->nr_rows = callchain__count_rows(&he->sorted_chain);
+				if (he->inline_node)
+					he->nr_rows = inline__count_rows(he);
+				else
+					he->nr_rows = callchain__count_rows(
+						&he->sorted_chain);
 			else
 				he->nr_rows = hierarchy_count_rows(browser, he, false);
 
@@ -1091,6 +1135,40 @@ static int hist_browser__show_callchain(struct hist_browser *browser,
 	return printed;
 }
 
+static int hist_browser__show_inline(struct hist_browser *browser,
+				     struct hist_entry *entry,
+				     unsigned short row)
+{
+	struct inline_node *node;
+	struct inline_list *ilist;
+	char buf[1024];
+	int color, width, first_row;
+
+	first_row = row;
+	node = entry->inline_node;
+	width = browser->b.width - (LEVEL_OFFSET_STEP + 2);
+
+	list_for_each_entry(ilist, &node->val, list) {
+		if (ilist->filename != NULL) {
+			color = HE_COLORSET_NORMAL;
+			if (ui_browser__is_current_entry(&browser->b, row))
+				color = HE_COLORSET_SELECTED;
+
+			scnprintf(buf, sizeof(buf), "%s:%d (inline)",
+				ilist->filename, ilist->line_nr);
+
+			ui_browser__set_color(&browser->b, color);
+			hist_browser__gotorc(browser, row, 0);
+			ui_browser__write_nstring(&browser->b, " ",
+				LEVEL_OFFSET_STEP + 2);
+			ui_browser__write_nstring(&browser->b, buf, width);
+			row++;
+		}
+	}
+
+	return row - first_row;
+}
+
 struct hpp_arg {
 	struct ui_browser *b;
 	char folded_sign;
@@ -1204,6 +1282,11 @@ static int hist_browser__show_entry(struct hist_browser *browser,
 		folded_sign = hist_entry__folded(entry);
 	}
 
+	if (symbol_conf.show_inline && (!entry->has_children)) {
+		hist_entry_init_inline_node(entry);
+		folded_sign = hist_entry__folded(entry);
+	}
+
 	if (row_offset == 0) {
 		struct hpp_arg arg = {
 			.b		= &browser->b,
@@ -1235,7 +1318,8 @@ static int hist_browser__show_entry(struct hist_browser *browser,
 			}
 
 			if (first) {
-				if (symbol_conf.use_callchain) {
+				if (symbol_conf.use_callchain ||
+					symbol_conf.show_inline) {
 					ui_browser__printf(&browser->b, "%c ", folded_sign);
 					width -= 2;
 				}
@@ -1277,8 +1361,14 @@ static int hist_browser__show_entry(struct hist_browser *browser,
 			.is_current_entry = current_entry,
 		};
 
-		printed += hist_browser__show_callchain(browser, entry, 1, row,
-					hist_browser__show_callchain_entry, &arg,
+		if (entry->inline_node)
+			printed += hist_browser__show_inline(browser,
+					entry, row);
+		else
+			printed += hist_browser__show_callchain(browser,
+					entry, 1, row,
+					hist_browser__show_callchain_entry,
+					&arg,
 					hist_browser__check_output_full);
 	}
 
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 6770a96..c18af42 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -1122,6 +1122,11 @@ void hist_entry__delete(struct hist_entry *he)
 		zfree(&he->mem_info);
 	}
 
+	if (he->inline_node) {
+		free_inline_node(he->inline_node);
+		he->inline_node = NULL;
+	}
+
 	zfree(&he->stat_acc);
 	free_srcline(he->srcline);
 	if (he->srcfile && he->srcfile[0])
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index 7aff317..5dbfdc7 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -122,6 +122,7 @@ struct hist_entry {
 	};
 	char			*srcline;
 	char			*srcfile;
+	struct inline_node	*inline_node;
 	struct symbol		*parent;
 	struct branch_info	*branch_info;
 	struct hists		*hists;
-- 
2.7.4

  parent reply	other threads:[~2016-11-29  6:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-29 14:55 [PATCH v1 0/4] perf report: Show inline stack Jin Yao
2016-11-29 14:55 ` [PATCH v1 1/4] perf report: Find the inline stack for a given address Jin Yao
2016-12-06 20:02   ` Arnaldo Carvalho de Melo
2016-11-29 14:55 ` [PATCH v1 2/4] perf report: Create a new option "--inline" Jin Yao
2016-11-29 14:55 ` [PATCH v1 3/4] perf report: Show inline stack in stdio mode Jin Yao
2016-11-29 14:55 ` Jin Yao [this message]
2016-12-06  0:35 ` [PATCH v1 0/4] perf report: Show inline stack Jin, Yao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1480431344-1644-5-git-send-email-yao.jin@linux.intel.com \
    --to=yao.jin@linux.intel.com \
    --cc=Linux-kernel@vger.kernel.org \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox