perf annotate: Add --percent-limit option

Like in 'perf report' and 'perf top', Add this option to limit the
number of functions it displays based on the overhead value in percent.

This affects only stdio and stdio2 output modes.  Without this, it
shows very long disassembly lines for every function in the data
file.  If users don't want this behavior, they can set a value in
percent to suppress that.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/20220502232015.697243-1-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Namhyung Kim 2022-05-02 16:20:15 -07:00 committed by Arnaldo Carvalho de Melo
parent 7df319e5b3
commit cad10ce366
2 changed files with 29 additions and 0 deletions

View File

@ -147,6 +147,11 @@ include::itrace.txt[]
The period/hits keywords set the base the percentage is computed The period/hits keywords set the base the percentage is computed
on - the samples period or the number of samples (hits). on - the samples period or the number of samples (hits).
--percent-limit::
Do not show functions which have an overhead under that percent on
stdio or stdio2 (Default: 0). Note that this is about selection of
functions to display, not about lines within the function.
SEE ALSO SEE ALSO
-------- --------
linkperf:perf-record[1], linkperf:perf-report[1] linkperf:perf-record[1], linkperf:perf-report[1]

View File

@ -54,6 +54,7 @@ struct perf_annotate {
bool skip_missing; bool skip_missing;
bool has_br_stack; bool has_br_stack;
bool group_set; bool group_set;
float min_percent;
const char *sym_hist_filter; const char *sym_hist_filter;
const char *cpu_list; const char *cpu_list;
DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
@ -324,6 +325,17 @@ static void hists__find_annotations(struct hists *hists,
(strcmp(he->ms.sym->name, ann->sym_hist_filter) != 0)) (strcmp(he->ms.sym->name, ann->sym_hist_filter) != 0))
goto find_next; goto find_next;
if (ann->min_percent) {
float percent = 0;
u64 total = hists__total_period(hists);
if (total)
percent = 100.0 * he->stat.period / total;
if (percent < ann->min_percent)
goto find_next;
}
notes = symbol__annotation(he->ms.sym); notes = symbol__annotation(he->ms.sym);
if (notes->src == NULL) { if (notes->src == NULL) {
find_next: find_next:
@ -457,6 +469,16 @@ static int __cmd_annotate(struct perf_annotate *ann)
return ret; return ret;
} }
static int parse_percent_limit(const struct option *opt, const char *str,
int unset __maybe_unused)
{
struct perf_annotate *ann = opt->value;
double pcnt = strtof(str, NULL);
ann->min_percent = pcnt;
return 0;
}
static const char * const annotate_usage[] = { static const char * const annotate_usage[] = {
"perf annotate [<options>]", "perf annotate [<options>]",
NULL NULL
@ -557,6 +579,8 @@ int cmd_annotate(int argc, const char **argv)
OPT_CALLBACK(0, "percent-type", &annotate.opts, "local-period", OPT_CALLBACK(0, "percent-type", &annotate.opts, "local-period",
"Set percent type local/global-period/hits", "Set percent type local/global-period/hits",
annotate_parse_percent_type), annotate_parse_percent_type),
OPT_CALLBACK(0, "percent-limit", &annotate, "percent",
"Don't show entries under that percent", parse_percent_limit),
OPT_CALLBACK_OPTARG(0, "itrace", &itrace_synth_opts, NULL, "opts", OPT_CALLBACK_OPTARG(0, "itrace", &itrace_synth_opts, NULL, "opts",
"Instruction Tracing options\n" ITRACE_HELP, "Instruction Tracing options\n" ITRACE_HELP,
itrace_parse_synth_opts), itrace_parse_synth_opts),