Re: [PATCH v3 1/5] perf annotate stdio: Support --show-nr-samples option

From: Arnaldo Carvalho de Melo
Date: Fri Aug 18 2017 - 09:34:42 EST


Em Fri, Aug 18, 2017 at 05:46:48PM +0900, Taeung Song escreveu:
> Add --show-nr-samples option to perf-annotate
> so that it corresponds with perf-report.

So, at this point I tried to test it and forgot this was just about
--stdio, which confused me, so I added the following patch, that I'll
lift when adding the browser support, which may not happen at this time
if there are problems there.

@@ -473,6 +474,11 @@ int cmd_annotate(int argc, const char **argv)
annotate.sym_hist_filter = argv[0];
}

+ if (symbol_conf.show_nr_samples && !annotate.use_stdio) {
+ pr_err("--show-nr-samples is only available in --stdio mode at this time\n");
+ return ret;
+ }
+

- Arnaldo

> Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
> Cc: Milian Wolff <milian.wolff@xxxxxxxx>
> Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
> Signed-off-by: Taeung Song <treeze.taeung@xxxxxxxxx>
> ---
> tools/perf/Documentation/perf-annotate.txt | 4 ++++
> tools/perf/builtin-annotate.c | 2 ++
> tools/perf/util/annotate.c | 6 +++++-
> 3 files changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/Documentation/perf-annotate.txt b/tools/perf/Documentation/perf-annotate.txt
> index a89273d..2a5975c 100644
> --- a/tools/perf/Documentation/perf-annotate.txt
> +++ b/tools/perf/Documentation/perf-annotate.txt
> @@ -43,6 +43,10 @@ OPTIONS
> --quiet::
> Do not show any message. (Suppress -v)
>
> +-n::
> +--show-nr-samples::
> + Show the number of samples for each symbol
> +
> -D::
> --dump-raw-trace::
> Dump raw trace in ASCII.
> diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
> index 658c920..acde4cc 100644
> --- a/tools/perf/builtin-annotate.c
> +++ b/tools/perf/builtin-annotate.c
> @@ -445,6 +445,8 @@ int cmd_annotate(int argc, const char **argv)
> "Show event group information together"),
> OPT_BOOLEAN(0, "show-total-period", &symbol_conf.show_total_period,
> "Show a column with the sum of periods"),
> + OPT_BOOLEAN('n', "show-nr-samples", &symbol_conf.show_nr_samples,
> + "Show a column with the number of samples"),
> OPT_CALLBACK_DEFAULT(0, "stdio-color", NULL, "mode",
> "'always' (default), 'never' or 'auto' only applicable to --stdio mode",
> stdio__config_color, "always"),
> diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
> index 2dab0e5..4397a8b 100644
> --- a/tools/perf/util/annotate.c
> +++ b/tools/perf/util/annotate.c
> @@ -1145,6 +1145,9 @@ static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 st
> if (symbol_conf.show_total_period)
> color_fprintf(stdout, color, " %11" PRIu64,
> sample.period);
> + else if (symbol_conf.show_nr_samples)
> + color_fprintf(stdout, color, " %7" PRIu64,
> + sample.nr_samples);
> else
> color_fprintf(stdout, color, " %7.2f", percent);
> }
> @@ -1825,7 +1828,8 @@ int symbol__annotate_printf(struct symbol *sym, struct map *map,
> width *= evsel->nr_members;
>
> graph_dotted_len = printf(" %-*.*s| Source code & Disassembly of %s for %s (%" PRIu64 " samples)\n",
> - width, width, symbol_conf.show_total_period ? "Event count" : "Percent",
> + width, width, symbol_conf.show_total_period ? "Period" :
> + symbol_conf.show_nr_samples ? "Samples" : "Percent",
> d_filename, evsel_name, h->nr_samples);
>
> printf("%-*.*s----\n",
> --
> 2.7.4