linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Jiri Olsa <jolsa@redhat.com>, LKML <linux-kernel@vger.kernel.org>,
	Brendan Gregg <brendan.d.gregg@gmail.com>,
	David Ahern <dsahern@gmail.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Andi Kleen <andi@firstfloor.org>, Kan Liang <kan.liang@intel.com>
Subject: Re: [PATCH v5 7/9] perf hists browser: Support folded callchains
Date: Thu, 19 Nov 2015 11:19:38 -0300	[thread overview]
Message-ID: <20151119141938.GC29361@kernel.org> (raw)
In-Reply-To: <1447047946-1691-9-git-send-email-namhyung@kernel.org>

Em Mon, Nov 09, 2015 at 02:45:44PM +0900, Namhyung Kim escreveu:
> The folded callchain mode is to print all chains in a single line.
> Currently perf report --tui doesn't support folded callchains.  Like
> flat callchains, only leaf nodes are added to the final rbtree so it
> should show entries in parent nodes.  To do that, add flat_val list to
> struct callchain_node and show them along with the (normal) val list.
> 
> For example, folded callchain looks like below:
> 
>   $ perf report -g folded --tui
>   Samples: 234  of event 'cycles:pp', Event count (approx.): 32605268
>     Overhead  Command  Shared Object     Symbol
>   -   39.93%  swapper  [kernel.vmlinux]  [k] intel_idle
>      + 28.63% intel_idle; cpuidle_enter_state; cpuidle_enter; ...
>      + 11.30% intel_idle; cpuidle_enter_state; cpuidle_enter; ...

The +/- before the folded callchains continue toggling, but with no, a
further polishment is to elide them altogether, since they have no use.

Applied, that can be done on top.

- Arnaldo
 
> Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
>  tools/perf/ui/browsers/hists.c | 126 ++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 125 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
> index f4216d92282d..3efe7c74f47d 100644
> --- a/tools/perf/ui/browsers/hists.c
> +++ b/tools/perf/ui/browsers/hists.c
> @@ -207,6 +207,11 @@ static int callchain_node__count_flat_rows(struct callchain_node *node)
>  	return n;
>  }
>  
> +static int callchain_node__count_folded_rows(struct callchain_node *node __maybe_unused)
> +{
> +	return 1;
> +}
> +
>  static int callchain_node__count_rows(struct callchain_node *node)
>  {
>  	struct callchain_list *chain;
> @@ -215,6 +220,8 @@ static int callchain_node__count_rows(struct callchain_node *node)
>  
>  	if (callchain_param.mode == CHAIN_FLAT)
>  		return callchain_node__count_flat_rows(node);
> +	else if (callchain_param.mode == CHAIN_FOLDED)
> +		return callchain_node__count_folded_rows(node);
>  
>  	list_for_each_entry(chain, &node->val, list) {
>  		++n;
> @@ -311,7 +318,8 @@ static void callchain__init_have_children(struct rb_root *root)
>  	for (nd = rb_first(root); nd; nd = rb_next(nd)) {
>  		struct callchain_node *node = rb_entry(nd, struct callchain_node, rb_node);
>  		callchain_node__init_have_children(node, has_sibling);
> -		if (callchain_param.mode == CHAIN_FLAT)
> +		if (callchain_param.mode == CHAIN_FLAT ||
> +		    callchain_param.mode == CHAIN_FOLDED)
>  			callchain_node__make_parent_list(node);
>  	}
>  }
> @@ -723,6 +731,117 @@ static int hist_browser__show_callchain_flat(struct hist_browser *browser,
>  	return row - first_row;
>  }
>  
> +static char *hist_browser__folded_callchain_str(struct hist_browser *browser,
> +						struct callchain_list *chain,
> +						char *value_str, char *old_str)
> +{
> +	char bf[1024];
> +	const char *str;
> +	char *new;
> +
> +	str = callchain_list__sym_name(chain, bf, sizeof(bf),
> +				       browser->show_dso);
> +	if (old_str) {
> +		if (asprintf(&new, "%s%s%s", old_str,
> +			     symbol_conf.field_sep ?: ";", str) < 0)
> +			new = NULL;
> +	} else {
> +		if (value_str) {
> +			if (asprintf(&new, "%s %s", value_str, str) < 0)
> +				new = NULL;
> +		} else {
> +			if (asprintf(&new, "%s", str) < 0)
> +				new = NULL;
> +		}
> +	}
> +	return new;
> +}
> +
> +static int hist_browser__show_callchain_folded(struct hist_browser *browser,
> +					       struct rb_root *root,
> +					       unsigned short row, u64 total,
> +					       print_callchain_entry_fn print,
> +					       struct callchain_print_arg *arg,
> +					       check_output_full_fn is_output_full)
> +{
> +	struct rb_node *node;
> +	int first_row = row, offset = LEVEL_OFFSET_STEP;
> +	bool need_percent;
> +
> +	node = rb_first(root);
> +	need_percent = node && rb_next(node);
> +
> +	while (node) {
> +		struct callchain_node *child = rb_entry(node, struct callchain_node, rb_node);
> +		struct rb_node *next = rb_next(node);
> +		struct callchain_list *chain, *first_chain = NULL;
> +		int first = true;
> +		char *value_str = NULL, *value_str_alloc = NULL;
> +		char *chain_str = NULL, *chain_str_alloc = NULL;
> +
> +		if (arg->row_offset != 0) {
> +			arg->row_offset--;
> +			goto next;
> +		}
> +
> +		if (need_percent) {
> +			char buf[64];
> +
> +			callchain_node__sprintf_value(child, buf, sizeof(buf),
> +						      total);
> +			if (asprintf(&value_str, "%s", buf) < 0) {
> +				value_str = (char *)"<...>";
> +				goto do_print;
> +			}
> +			value_str_alloc = value_str;
> +		}
> +
> +		list_for_each_entry(chain, &child->parent_val, list) {
> +			chain_str = hist_browser__folded_callchain_str(browser,
> +						chain, value_str, chain_str);
> +			if (first) {
> +				first = false;
> +				first_chain = chain;
> +			}
> +
> +			if (chain_str == NULL) {
> +				chain_str = (char *)"Not enough memory!";
> +				goto do_print;
> +			}
> +
> +			chain_str_alloc = chain_str;
> +		}
> +
> +		list_for_each_entry(chain, &child->val, list) {
> +			chain_str = hist_browser__folded_callchain_str(browser,
> +						chain, value_str, chain_str);
> +			if (first) {
> +				first = false;
> +				first_chain = chain;
> +			}
> +
> +			if (chain_str == NULL) {
> +				chain_str = (char *)"Not enough memory!";
> +				goto do_print;
> +			}
> +
> +			chain_str_alloc = chain_str;
> +		}
> +
> +do_print:
> +		print(browser, first_chain, chain_str, offset, row++, arg);
> +		free(value_str_alloc);
> +		free(chain_str_alloc);
> +
> +next:
> +		if (is_output_full(browser, row))
> +			break;
> +		node = next;
> +	}
> +
> +	return row - first_row;
> +}
> +
>  static int hist_browser__show_callchain(struct hist_browser *browser,
>  					struct rb_root *root, int level,
>  					unsigned short row, u64 total,
> @@ -980,6 +1099,11 @@ static int hist_browser__show_entry(struct hist_browser *browser,
>  					&entry->sorted_chain, row, total,
>  					hist_browser__show_callchain_entry, &arg,
>  					hist_browser__check_output_full);
> +		} else if (callchain_param.mode == CHAIN_FOLDED) {
> +			printed += hist_browser__show_callchain_folded(browser,
> +					&entry->sorted_chain, row, total,
> +					hist_browser__show_callchain_entry, &arg,
> +					hist_browser__check_output_full);
>  		} else {
>  			printed += hist_browser__show_callchain(browser,
>  					&entry->sorted_chain, 1, row, total,
> -- 
> 2.6.2

  reply	other threads:[~2015-11-19 14:19 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-09  5:45 [PATCHSET 0/9] perf report: Support folded callchain output (v5) Namhyung Kim
2015-11-09  5:45 ` [PATCH v5 1/9] perf report: Support folded callchain mode on --stdio Namhyung Kim
2015-11-23 16:13   ` [tip:perf/core] " tip-bot for Namhyung Kim
2015-11-09  5:45 ` [PATCH] perf report: [WIP] Support '-F none' option to hide hist lines Namhyung Kim
2015-11-19 14:33   ` Arnaldo Carvalho de Melo
2015-11-20  1:43     ` Namhyung Kim
2015-11-09  5:45 ` [PATCH v5 2/9] perf callchain: Abstract callchain print function Namhyung Kim
2015-11-19 13:41   ` Arnaldo Carvalho de Melo
2015-11-20  1:33     ` Namhyung Kim
2015-11-23 16:13   ` [tip:perf/core] " tip-bot for Namhyung Kim
2015-11-09  5:45 ` [PATCH v5 3/9] perf callchain: Add count fields to struct callchain_node Namhyung Kim
2015-11-23 16:14   ` [tip:perf/core] " tip-bot for Namhyung Kim
2015-11-09  5:45 ` [PATCH v5 4/9] perf report: Add callchain value option Namhyung Kim
2015-11-19 13:59   ` Arnaldo Carvalho de Melo
2015-11-20  1:39     ` Namhyung Kim
2015-11-20 12:06       ` Arnaldo Carvalho de Melo
2015-11-23 16:14   ` [tip:perf/core] " tip-bot for Namhyung Kim
2015-11-09  5:45 ` [PATCH v5 5/9] perf hists browser: Factor out hist_browser__show_callchain_list() Namhyung Kim
2015-11-23 16:14   ` [tip:perf/core] " tip-bot for Namhyung Kim
2015-11-09  5:45 ` [PATCH v5 6/9] perf hists browser: Support flat callchains Namhyung Kim
2015-11-23 16:15   ` [tip:perf/core] " tip-bot for Namhyung Kim
2015-11-09  5:45 ` [PATCH v5 7/9] perf hists browser: Support folded callchains Namhyung Kim
2015-11-19 14:19   ` Arnaldo Carvalho de Melo [this message]
2015-11-20  1:40     ` Namhyung Kim
2015-11-23 16:15   ` [tip:perf/core] " tip-bot for Namhyung Kim
2015-11-09  5:45 ` [PATCH v5 8/9] perf ui/gtk: Support flat callchains Namhyung Kim
2015-11-23 16:15   ` [tip:perf/core] " tip-bot for Namhyung Kim
2015-11-09  5:45 ` [PATCH v5 9/9] perf ui/gtk: Support folded callchains Namhyung Kim
2015-11-23 16:16   ` [tip:perf/core] " tip-bot for Namhyung Kim
2015-11-12 17:50 ` [PATCHSET 0/9] perf report: Support folded callchain output (v5) Brendan Gregg
2015-11-16 23:09   ` Namhyung Kim
2015-11-17  0:09     ` Arnaldo Carvalho de Melo
2015-11-17  0:22       ` Namhyung Kim
2015-11-17  1:32         ` Arnaldo Carvalho de Melo

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=20151119141938.GC29361@kernel.org \
    --to=acme@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=andi@firstfloor.org \
    --cc=brendan.d.gregg@gmail.com \
    --cc=dsahern@gmail.com \
    --cc=fweisbec@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=kan.liang@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).