Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1265384

[PATCH v5 5/9] perf hists browser: Factor out hist_browser__show_callchain_list()

From Namhyung Kim <namhyung@kernel.org>
Newsgroups linux.kernel
Subject [PATCH v5 5/9] perf hists browser: Factor out hist_browser__show_callchain_list()
Date 2015-11-09 06:50 +0100
Message-ID <qsNv6-2fT-37@gated-at.bofh.it> (permalink)
References <qsNv3-2fT-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


This function is to print a single callchain list entry.  As this
function will be used by other function, factor out to a separate
function.

Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/ui/browsers/hists.c | 72 ++++++++++++++++++++++++++----------------
 1 file changed, 45 insertions(+), 27 deletions(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index a8897aab4c4a..b5c2d073c6b6 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -574,6 +574,44 @@ static bool hist_browser__check_dump_full(struct hist_browser *browser __maybe_u
 
 #define LEVEL_OFFSET_STEP 3
 
+static int hist_browser__show_callchain_list(struct hist_browser *browser,
+					     struct callchain_node *node,
+					     struct callchain_list *chain,
+					     unsigned short row, u64 total,
+					     bool need_percent, int offset,
+					     print_callchain_entry_fn print,
+					     struct callchain_print_arg *arg)
+{
+	char bf[1024], *alloc_str;
+	const char *str;
+
+	if (arg->row_offset != 0) {
+		arg->row_offset--;
+		return 0;
+	}
+
+	alloc_str = NULL;
+	str = callchain_list__sym_name(chain, bf, sizeof(bf),
+				       browser->show_dso);
+
+	if (need_percent) {
+		char buf[64];
+
+		callchain_node__sprintf_value(node, buf, sizeof(buf),
+					      total);
+
+		if (asprintf(&alloc_str, "%s %s", buf, str) < 0)
+			str = "Not enough memory!";
+		else
+			str = alloc_str;
+	}
+
+	print(browser, chain, str, offset, row, arg);
+
+	free(alloc_str);
+	return 1;
+}
+
 static int hist_browser__show_callchain(struct hist_browser *browser,
 					struct rb_root *root, int level,
 					unsigned short row, u64 total,
@@ -598,8 +636,6 @@ static int hist_browser__show_callchain(struct hist_browser *browser,
 		int extra_offset = 0;
 
 		list_for_each_entry(chain, &child->val, list) {
-			char bf[1024], *alloc_str;
-			const char *str;
 			bool was_first = first;
 
 			if (first)
@@ -608,34 +644,16 @@ static int hist_browser__show_callchain(struct hist_browser *browser,
 				extra_offset = LEVEL_OFFSET_STEP;
 
 			folded_sign = callchain_list__folded(chain);
-			if (arg->row_offset != 0) {
-				arg->row_offset--;
-				goto do_next;
-			}
 
-			alloc_str = NULL;
-			str = callchain_list__sym_name(chain, bf, sizeof(bf),
-						       browser->show_dso);
+			row += hist_browser__show_callchain_list(browser, child,
+							chain, row, total,
+							was_first && need_percent,
+							offset + extra_offset,
+							print, arg);
 
-			if (was_first && need_percent) {
-				char buf[64];
-
-				callchain_node__sprintf_value(child, buf, sizeof(buf),
-							      total);
-
-				if (asprintf(&alloc_str, "%s %s", buf, str) < 0)
-					str = "Not enough memory!";
-				else
-					str = alloc_str;
-			}
-
-			print(browser, chain, str, offset + extra_offset, row, arg);
-
-			free(alloc_str);
-
-			if (is_output_full(browser, ++row))
+			if (is_output_full(browser, row))
 				goto out;
-do_next:
+
 			if (folded_sign == '+')
 				break;
 		}
-- 
2.6.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCHSET 0/9] perf report: Support folded callchain output (v5) Namhyung Kim <namhyung@kernel.org> - 2015-11-09 06:50 +0100
  [PATCH v5 6/9] perf hists browser: Support flat callchains Namhyung Kim <namhyung@kernel.org> - 2015-11-09 06:50 +0100
  [PATCH v5 8/9] perf ui/gtk: Support flat callchains Namhyung Kim <namhyung@kernel.org> - 2015-11-09 06:50 +0100
  [PATCH v5 7/9] perf hists browser: Support folded callchains Namhyung Kim <namhyung@kernel.org> - 2015-11-09 06:50 +0100
  [PATCH v5 4/9] perf report: Add callchain value option Namhyung Kim <namhyung@kernel.org> - 2015-11-09 06:50 +0100
  [PATCH v5 5/9] perf hists browser: Factor out hist_browser__show_callchain_list() Namhyung Kim <namhyung@kernel.org> - 2015-11-09 06:50 +0100
  Re: [PATCHSET 0/9] perf report: Support folded callchain output (v5) Brendan Gregg <brendan.d.gregg@gmail.com> - 2015-11-12 19:00 +0100

csiph-web