lkml.org 
[lkml]   [2017]   [Feb]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH] perf report: Allow sorting by symbol size.
Em Fri, Feb 24, 2017 at 01:32:56PM +0000, charles.baylis@linaro.org escreveu:
> From: Charles Baylis <charles.baylis@linaro.org>
>
> Add new sort key 'symbol_size' to allow user to sort by
> symbol size, or (more usefully) display the symbol size
> using --fields=...,symbol_size.

Hey, really nice, will test and apply, and this opens the door for many
other keys, and to combine symbol_size with other keys :-)

- Arnaldo

> Signed-off-by: Charles Baylis <charles.baylis@linaro.org>
> ---
> tools/perf/Documentation/perf-report.txt | 1 +
> tools/perf/util/hist.h | 1 +
> tools/perf/util/sort.c | 46 ++++++++++++++++++++++++++++++++
> tools/perf/util/sort.h | 1 +
> 4 files changed, 49 insertions(+)
>
> diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
> index f2914f0..d2a8c15 100644
> --- a/tools/perf/Documentation/perf-report.txt
> +++ b/tools/perf/Documentation/perf-report.txt
> @@ -76,6 +76,7 @@ OPTIONS
> - pid: command and tid of the task
> - dso: name of library or module executed at the time of sample
> - symbol: name of function executed at the time of sample
> + - symbol_size: size of function executed at the time of sample
> - parent: name of function matched to the parent regex filter. Unmatched
> entries are displayed as "[other]".
> - cpu: cpu number the task ran at the time of sample
> diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
> index 28c216e..2e839bf 100644
> --- a/tools/perf/util/hist.h
> +++ b/tools/perf/util/hist.h
> @@ -57,6 +57,7 @@ enum hist_column {
> HISTC_SRCLINE_FROM,
> HISTC_SRCLINE_TO,
> HISTC_TRACE,
> + HISTC_SYM_SIZE,
> HISTC_NR_COLS, /* Last entry */
> };
>
> diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
> index df622f4..0ad397c 100644
> --- a/tools/perf/util/sort.c
> +++ b/tools/perf/util/sort.c
> @@ -1396,6 +1396,51 @@ struct sort_entry sort_transaction = {
> .se_width_idx = HISTC_TRANSACTION,
> };
>
> +/* --sort symbol_size */
> +
> +static int64_t _sort__sym_size_cmp(struct symbol *sym_l, struct symbol *sym_r)
> +{
> + int64_t size_l = sym_l != NULL ? sym_l->end - sym_l->start : 0;
> + int64_t size_r = sym_r != NULL ? sym_r->end - sym_r->start : 0;
> +
> + return size_l < size_r ? -1 :
> + size_l == size_r ? 0 : 1;
> +}
> +
> +static int64_t
> +sort__sym_size_cmp(struct hist_entry *left, struct hist_entry *right)
> +{
> + return _sort__sym_size_cmp(right->ms.sym, left->ms.sym);
> +}
> +
> +static int _hist_entry__sym_size_snprintf(struct symbol *sym, char *bf,
> + size_t bf_size, unsigned int width)
> +{
> + if (sym) {
> + int64_t sym_size = sym->end - sym->start;
> +
> + return repsep_snprintf(bf, bf_size, "%*lld", width,
> + (long long)sym_size);
> + } else {
> + return repsep_snprintf(bf, bf_size, "%*s", width,
> + "unknown");
> + }
> +}
> +
> +static int hist_entry__sym_size_snprintf(struct hist_entry *he, char *bf,
> + size_t size, unsigned int width)
> +{
> + return _hist_entry__sym_size_snprintf(he->ms.sym, bf, size, width);
> +}
> +
> +struct sort_entry sort_sym_size = {
> + .se_header = "Symbol size",
> + .se_cmp = sort__sym_size_cmp,
> + .se_snprintf = hist_entry__sym_size_snprintf,
> + .se_width_idx = HISTC_SYM_SIZE,
> +};
> +
> +
> struct sort_dimension {
> const char *name;
> struct sort_entry *entry;
> @@ -1418,6 +1463,7 @@ static struct sort_dimension common_sort_dimensions[] = {
> DIM(SORT_GLOBAL_WEIGHT, "weight", sort_global_weight),
> DIM(SORT_TRANSACTION, "transaction", sort_transaction),
> DIM(SORT_TRACE, "trace", sort_trace),
> + DIM(SORT_SYM_SIZE, "symbol_size", sort_sym_size),
> };
>
> #undef DIM
> diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
> index 7aff317..acb2c57 100644
> --- a/tools/perf/util/sort.h
> +++ b/tools/perf/util/sort.h
> @@ -211,6 +211,7 @@ enum sort_type {
> SORT_GLOBAL_WEIGHT,
> SORT_TRANSACTION,
> SORT_TRACE,
> + SORT_SYM_SIZE,
>
> /* branch stack specific sort keys */
> __SORT_BRANCH_STACK,
> --
> 2.7.4

\
 
 \ /
  Last update: 2017-02-24 14:48    [W:0.059 / U:0.284 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site