public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Andi Kleen <andi@firstfloor.org>
Cc: jolsa@kernel.org, namhyung@kernel.org,
	linux-kernel@vger.kernel.org, Andi Kleen <ak@linux.intel.com>
Subject: Re: [PATCH] perf, tools, report: Add support for srcfile sort key
Date: Fri, 7 Aug 2015 20:51:45 -0300	[thread overview]
Message-ID: <20150807235145.GD3583@kernel.org> (raw)
In-Reply-To: <1438988064-21834-1-git-send-email-andi@firstfloor.org>

Em Fri, Aug 07, 2015 at 03:54:24PM -0700, Andi Kleen escreveu:
> From: Andi Kleen <ak@linux.intel.com>
> 
> In some cases it's useful to characterize samples by file. This is useful
> to get a higher level categorization, for example to map cost to
> subsystems.
> 
> Add a srcfile sort key to perf report. It builds on top of the existing
> srcline support.

Applied
 
> Signed-off-by: Andi Kleen <ak@linux.intel.com>
> ---
>  tools/perf/Documentation/perf-report.txt |  2 ++
>  tools/perf/util/hist.c                   |  2 ++
>  tools/perf/util/hist.h                   |  1 +
>  tools/perf/util/sort.c                   | 52 ++++++++++++++++++++++++++++++++
>  tools/perf/util/sort.h                   |  2 ++
>  5 files changed, 59 insertions(+)
> 
> diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
> index aabb1b4..724ab3f 100644
> --- a/tools/perf/Documentation/perf-report.txt
> +++ b/tools/perf/Documentation/perf-report.txt
> @@ -81,6 +81,8 @@ OPTIONS
>  	- cpu: cpu number the task ran at the time of sample
>  	- srcline: filename and line number executed at the time of sample.  The
>  	DWARF debugging info must be provided.
> +	- srcfile: file name of the source file of the same. Requires dwarf
> +	information.
>  	- weight: Event specific weight, e.g. memory latency or transaction
>  	abort cost. This is the global weight.
>  	- local_weight: Local weight version of the weight above.
> diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
> index 6f28d53..37dd8ae 100644
> --- a/tools/perf/util/hist.c
> +++ b/tools/perf/util/hist.c
> @@ -944,6 +944,8 @@ void hist_entry__delete(struct hist_entry *he)
>  
>  	zfree(&he->stat_acc);
>  	free_srcline(he->srcline);
> +	if (he->srcfile && he->srcfile[0])
> +		free(he->srcfile);
>  	free_callchain(he->callchain);
>  	free(he);
>  }
> diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
> index 5ed8d9c..3be8087 100644
> --- a/tools/perf/util/hist.h
> +++ b/tools/perf/util/hist.h
> @@ -30,6 +30,7 @@ enum hist_column {
>  	HISTC_PARENT,
>  	HISTC_CPU,
>  	HISTC_SRCLINE,
> +	HISTC_SRCFILE,
>  	HISTC_MISPREDICT,
>  	HISTC_IN_TX,
>  	HISTC_ABORT,
> diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
> index 4c65a14..e3e8b13 100644
> --- a/tools/perf/util/sort.c
> +++ b/tools/perf/util/sort.c
> @@ -319,6 +319,57 @@ struct sort_entry sort_srcline = {
>  	.se_width_idx	= HISTC_SRCLINE,
>  };
>  
> +/* --sort srcfile */
> +
> +static char no_srcfile[1];
> +
> +static char *get_srcfile(struct hist_entry *e)
> +{
> +	char *sf, *p;
> +	struct map *map = e->ms.map;
> +
> +	sf = get_srcline(map->dso, map__rip_2objdump(map, e->ip),
> +			 e->ms.sym, true);
> +	p = strchr(sf, ':');
> +	if (p && *sf) {
> +		*p = 0;
> +		return sf;
> +	}
> +	free(sf);
> +	return no_srcfile;
> +}
> +
> +static int64_t
> +sort__srcfile_cmp(struct hist_entry *left, struct hist_entry *right)
> +{
> +	if (!left->srcfile) {
> +		if (!left->ms.map)
> +			left->srcfile = no_srcfile;
> +		else
> +			left->srcfile = get_srcfile(left);
> +	}
> +	if (!right->srcfile) {
> +		if (!right->ms.map)
> +			right->srcfile = no_srcfile;
> +		else
> +			right->srcfile = get_srcfile(right);
> +	}
> +	return strcmp(right->srcfile, left->srcfile);
> +}
> +
> +static int hist_entry__srcfile_snprintf(struct hist_entry *he, char *bf,
> +					size_t size, unsigned int width)
> +{
> +	return repsep_snprintf(bf, size, "%-*.*s", width, width, he->srcfile);
> +}
> +
> +struct sort_entry sort_srcfile = {
> +	.se_header	= "Source File",
> +	.se_cmp		= sort__srcfile_cmp,
> +	.se_snprintf	= hist_entry__srcfile_snprintf,
> +	.se_width_idx	= HISTC_SRCFILE,
> +};
> +
>  /* --sort parent */
>  
>  static int64_t
> @@ -1173,6 +1224,7 @@ static struct sort_dimension common_sort_dimensions[] = {
>  	DIM(SORT_PARENT, "parent", sort_parent),
>  	DIM(SORT_CPU, "cpu", sort_cpu),
>  	DIM(SORT_SRCLINE, "srcline", sort_srcline),
> +	DIM(SORT_SRCFILE, "srcfile", sort_srcfile),
>  	DIM(SORT_LOCAL_WEIGHT, "local_weight", sort_local_weight),
>  	DIM(SORT_GLOBAL_WEIGHT, "weight", sort_global_weight),
>  	DIM(SORT_TRANSACTION, "transaction", sort_transaction),
> diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
> index e97cd47..13705b2 100644
> --- a/tools/perf/util/sort.h
> +++ b/tools/perf/util/sort.h
> @@ -114,6 +114,7 @@ struct hist_entry {
>  		};
>  	};
>  	char			*srcline;
> +	char			*srcfile;
>  	struct symbol		*parent;
>  	struct rb_root		sorted_chain;
>  	struct branch_info	*branch_info;
> @@ -172,6 +173,7 @@ enum sort_type {
>  	SORT_PARENT,
>  	SORT_CPU,
>  	SORT_SRCLINE,
> +	SORT_SRCFILE,
>  	SORT_LOCAL_WEIGHT,
>  	SORT_GLOBAL_WEIGHT,
>  	SORT_TRANSACTION,
> -- 
> 2.4.3

  reply	other threads:[~2015-08-07 23:51 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-07 22:54 [PATCH] perf, tools, report: Add support for srcfile sort key Andi Kleen
2015-08-07 23:51 ` Arnaldo Carvalho de Melo [this message]
2015-08-08  0:02   ` Arnaldo Carvalho de Melo
2015-08-08  2:27     ` Andi Kleen
2015-08-08 17:28       ` Arnaldo Carvalho de Melo
2015-08-09  3:30       ` Namhyung Kim
2015-08-09 16:03         ` Andi Kleen
2015-08-10 14:51           ` Arnaldo Carvalho de Melo
2015-08-10 16:12         ` Arnaldo Carvalho de Melo
2015-08-10 18:32           ` Arnaldo Carvalho de Melo
2015-08-10 20:37             ` Arnaldo Carvalho de Melo
2015-08-11  2:28               ` Namhyung Kim
2015-08-12 12:30 ` [tip:perf/core] perf " tip-bot for Andi Kleen

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=20150807235145.GD3583@kernel.org \
    --to=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=andi@firstfloor.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.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