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,
	milian.wolff@kdab.com
Subject: [PATCH v3 4/5] perf report: Show inline stack in stdio mode
Date: Fri, 20 Jan 2017 17:39:25 +0800	[thread overview]
Message-ID: <1484905166-10609-5-git-send-email-yao.jin@linux.intel.com> (raw)
In-Reply-To: <1484905166-10609-1-git-send-email-yao.jin@linux.intel.com>

If the address belongs to an inlined function, the source information
back to the first non-inlined function will be printed.

For example:
perf report --stdio --inline-line

|--56.76%--_start
|          __libc_start_main
|          main
|
 --41.39%--main
           |
           ---/home/jinyao/skl-ws/perf-dev/lck-2867/test/inline.cpp:14 (inline)
              /usr/include/c++/5/bits/random.h:1809 (inline)
              /usr/include/c++/5/bits/random.h:1818 (inline)
              /usr/include/c++/5/bits/random.h:185 (inline)
              /usr/include/c++/5/bits/random.tcc:3328 (inline)
              /usr/include/c++/5/bits/random.h:332 (inline)
              /usr/include/c++/5/bits/random.h:151 (inline)
           __hypot
           |
            --40.09%--__hypot_finite

The tag "inline" indicates these items are the entries in inline stack.

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
---
 tools/perf/ui/stdio/hist.c | 75 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 74 insertions(+), 1 deletion(-)

diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
index 668f4ae..a2263d4 100644
--- a/tools/perf/ui/stdio/hist.c
+++ b/tools/perf/ui/stdio/hist.c
@@ -17,6 +17,56 @@ static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin)
 	return ret;
 }
 
+static size_t inline__fprintf(struct map *map, u64 ip,
+			      int left_margin, FILE *fp)
+{
+	struct dso *dso;
+	struct inline_node *node;
+	struct inline_list *ilist;
+	int ret = 0, i = 0;
+
+	if (map == NULL)
+		return 0;
+
+	dso = map->dso;
+	if (dso == NULL)
+		return 0;
+
+	if (dso->kernel != DSO_TYPE_USER)
+		return 0;
+
+	node = dso__parse_addr_inlines(dso,
+				       map__rip_2objdump(map, ip));
+	if (node == NULL)
+		return 0;
+
+	ret += callchain__fprintf_left_margin(fp, left_margin);
+	ret += fprintf(fp, "|\n");
+	ret += callchain__fprintf_left_margin(fp, left_margin);
+	ret += fprintf(fp, "---");
+	left_margin += 3;
+
+	list_for_each_entry(ilist, &node->val, list) {
+		if (ilist->filename != NULL) {
+			if (i++ > 0)
+				ret = callchain__fprintf_left_margin(fp,
+								left_margin);
+
+			if (symbol_conf.inline_name)
+				ret += fprintf(fp, "%s (inline)",
+					       ilist->funcname);
+			else
+				ret += fprintf(fp, "%s:%d (inline)",
+					       ilist->filename, ilist->line_nr);
+
+			ret += fprintf(fp, "\n");
+		}
+	}
+
+	inline_node__delete(node);
+	return ret;
+}
+
 static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask,
 					  int left_margin)
 {
@@ -78,6 +128,10 @@ static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_node *node,
 	fputs(str, fp);
 	fputc('\n', fp);
 	free(alloc_str);
+
+	if (symbol_conf.inline_line || symbol_conf.inline_name)
+		ret += inline__fprintf(chain->ms.map, chain->ip,
+				       left_margin + 11, fp);
 	return ret;
 }
 
@@ -229,6 +283,7 @@ static size_t callchain__fprintf_graph(FILE *fp, struct rb_root *root,
 			if (!i++ && field_order == NULL &&
 			    sort_order && !prefixcmp(sort_order, "sym"))
 				continue;
+
 			if (!printed) {
 				ret += callchain__fprintf_left_margin(fp, left_margin);
 				ret += fprintf(fp, "|\n");
@@ -251,6 +306,12 @@ static size_t callchain__fprintf_graph(FILE *fp, struct rb_root *root,
 
 			if (++entries_printed == callchain_param.print_limit)
 				break;
+
+			if (symbol_conf.inline_line || symbol_conf.inline_name)
+				ret += inline__fprintf(chain->ms.map,
+						       chain->ip,
+						       left_margin,
+						       fp);
 		}
 		root = &cnode->rb_root;
 	}
@@ -529,6 +590,8 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size,
 			       bool use_callchain)
 {
 	int ret;
+	int callchain_ret = 0;
+	int inline_ret = 0;
 	struct perf_hpp hpp = {
 		.buf		= bf,
 		.size		= size,
@@ -547,7 +610,17 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size,
 	ret = fprintf(fp, "%s\n", bf);
 
 	if (use_callchain)
-		ret += hist_entry_callchain__fprintf(he, total_period, 0, fp);
+		callchain_ret = hist_entry_callchain__fprintf(he, total_period,
+							      0, fp);
+
+	if ((callchain_ret == 0) &&
+	    (symbol_conf.inline_line || symbol_conf.inline_name)) {
+		inline_ret = inline__fprintf(he->ms.map, he->ip, 0, fp);
+		ret += inline_ret;
+		if (inline_ret > 0)
+			ret += fprintf(fp, "\n");
+	} else
+		ret += callchain_ret;
 
 	return ret;
 }
-- 
2.7.4

  parent reply	other threads:[~2017-01-20  1:41 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-20  9:39 [PATCH v3 0/5] perf report: Show inline stack Jin Yao
2017-01-20  9:39 ` [PATCH v3 1/5] perf report: Refactor common code in srcline.c Jin Yao
2017-01-20  9:39 ` [PATCH v3 2/5] perf report: Find the inline stack for a given address Jin Yao
2017-01-20  9:39 ` [PATCH v3 3/5] perf report: Create new inline options Jin Yao
2017-01-20  9:39 ` Jin Yao [this message]
2017-01-20  9:39 ` [PATCH v3 5/5] perf report: Show inline stack in browser mode Jin Yao
2017-02-21  0:28 ` [PATCH v3 0/5] perf report: Show inline stack Jin, Yao
2017-03-02 21:42   ` Milian Wolff
2017-03-03  2:38     ` 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=1484905166-10609-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 \
    --cc=milian.wolff@kdab.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