perf tools: Update on filtered entries' percentage output
Namhyung Kim
maintainercover perf tools: Update on filtered entries' percentage output
Hello,
I added --percentage option to perf report to control display of percentage of filtered entries.
usage: perf report [<options>]
--percentage <relative|absolute>
how to display percentage of filtered entries
"relative" means it's relative to filtered entries only so that the sum of shown entries will be always 100%. "absolute" means it retains original value before and after the filter applied. In patch 5, I made the "absolute" as default since it makes more sense IMHO.
$ perf report -s comm
# Overhead Command
# ........ ............
#
74.19% cc1
7.61% gcc
6.11% as
4.35% sh
4.14% make
1.13% fixdep
... $ perf report -s comm -c cc1,gcc --percentage absolute
# Overhead Command
# ........ ............
#
74.19% cc1
7.61% gcc $ perf report -s comm -c cc1,gcc --percentage relative
# Overhead Command
# ........ ............
#
90.69% cc1
9.31% gccNote that it has zero effect if no filter was applied.
I only added the option to perf report for now. If it looks good to you I'll add it to perf top too.
Any comments are welcome, thanks
Namhyung
Namhyung Kim (5):
perf tools: Count filtered entries to total period also perf ui/tui: Add support for showing relative percentage perf report: Add --percentage option
perf report: Add report.percentage config option perf tools: Show absolute percentage by default
tools/perf/Documentation/perf-report.txt | 6 ++++++ tools/perf/builtin-report.c | 28 +++++++++++++++++++++++++++- tools/perf/util/event.c | 18 ++++++++---------- tools/perf/util/hist.c | 27 ++++++++++++++------------- tools/perf/util/hist.h | 7 +++++++ tools/perf/util/symbol.h | 5 +++-- 6 files changed, 65 insertions(+), 26 deletions(-)
Signature · 1 line
1.7.11.7
Namhyung Kim
maintainerPATCH 1/5 perf tools: Count filtered entries to total period also
Currently if a sample was filtered by command line option, it just dropped. But this affects final output in that the percentage can be different since the filtered entries were not included to the total.
But user might want to see the original percentages when filter applied so change the behavior depends on a new symbol_conf.filter_ relative value in order to be controlled by user later.
--- tools/perf/builtin-report.c | 2 +- tools/perf/util/event.c | 18 ++++++++---------- tools/perf/util/hist.c | 12 +++--------- tools/perf/util/hist.h | 7 +++++++ tools/perf/util/symbol.c | 1 + tools/perf/util/symbol.h | 5 +++-- 6 files changed, 23 insertions(+), 22 deletions(-)
tools/perf/builtin-report.c +1 -1
@@ -247,7 +247,7 @@ static int process_sample_event(struct perf_tool *tool,return -1 ; } -if (al.filtered || (rep->hide_unresolved && al.sym ==NULL )) +if (rep->hide_unresolved && al.sym ==NULL )return 0 ;if (rep->cpu_list && !test_bit (sample->cpu, rep->cpu_bitmap))
tools/perf/util/event.c +8 -10
@@ -3,6 +3,7 @@#include "debug.h" #include "machine.h" #include "sort.h" +#include "hist.h" #include "string.h" #include "strlist.h" #include "thread.h"
@@ -663,7 +664,7 @@ void thread__find_addr_map(struct thread *thread, al->thread = thread; al->addr = addr; al->cpumode = cpumode; - al->filtered = false; + al->filtered =0 ;if (machine ==NULL ) { al->map =NULL ;
@@ -750,9 +751,6 @@ int perf_event__preprocess_sample(const union perf_event *event,if (thread ==NULL )return -1 ; -if (thread__is_filtered (thread)) - goto out_filtered; -dump_printf (" ... thread: %s:%d\n" ,thread__comm_str (thread), thread->tid);/* * Have we already created the kernel maps for this machine?
@@ -767,6 +765,10 @@ int perf_event__preprocess_sample(const union perf_event *event,thread__find_addr_map (thread, machine, cpumode,MAP__FUNCTION , sample->ip, al); + +if (thread__is_filtered (thread)) + al->filtered |= (1 <<HIST_FILTER__THREAD ); +dump_printf (" ...... dso: %s\n" , al->map ? al->map->dso->long_name : al->level =='H' ?"[hypervisor]" :"<not found>" );
@@ -782,7 +784,7 @@ int perf_event__preprocess_sample(const union perf_event *event, (dso->short_name != dso->long_name &&strlist__has_entry (symbol_conf.dso_list, dso->long_name))))) - goto out_filtered; + al->filtered |= (1 << HIST_FILTER__DSO); al->sym =map__find_symbol (al->map, al->addr, machine->symbol_filter);
@@ -791,11 +793,7 @@ int perf_event__preprocess_sample(const union perf_event *event,if (symbol_conf.sym_list && (!al->sym || !strlist__has_entry (symbol_conf.sym_list, al->sym->name))) - goto out_filtered; - -return 0 ; + al->filtered |= (1 <<HIST_FILTER__SYMBOL ); -out_filtered: - al->filtered = true;return 0 ; }
tools/perf/util/hist.c +3 -9
@@ -13,13 +13,6 @@ static bool hists__filter_entry_by_thread(struct hists *hists,static bool hists__filter_entry_by_symbol (struct hists *hists,struct hist_entry *he); -enum hist_filter { -HIST_FILTER__DSO , -HIST_FILTER__THREAD , -HIST_FILTER__PARENT , -HIST_FILTER__SYMBOL , -}; -struct callchain_param callchain_param = { .mode =CHAIN_GRAPH_REL , .min_percent =0.5 ,
@@ -329,8 +322,9 @@ void hists__inc_nr_entries(struct hists *hists, struct hist_entry *h)if (!h->filtered) {hists__calc_col_len (hists, h); ++hists->nr_entries; - hists->stats.total_period += h->stat.period; } +if (!h->filtered || !symbol_conf.filter_relative) + hists->stats.total_period += h->stat.period; }static u8 symbol__parent_filter (const struct symbol *parent)
@@ -429,7 +423,7 @@ struct hist_entry *__hists__add_entry(struct hists *hists, .weight = weight, }, .parent = sym_parent, - .filtered = symbol__parent_filter(sym_parent), + .filtered = symbol__parent_filter(sym_parent) | al->filtered, .hists = hists, .branch_info = bi, .mem_info = mi,
tools/perf/util/hist.h +7 -0
@@ -14,6 +14,13 @@ struct hist_entry;struct addr_location ;struct symbol ; +enum hist_filter { +HIST_FILTER__DSO , +HIST_FILTER__THREAD , +HIST_FILTER__PARENT , +HIST_FILTER__SYMBOL , +}; +/* * The kernel collects the number of events it couldn't send in a stretch and * when possible sends this number in a PERF_RECORD_LOST event. The number of
tools/perf/util/symbol.c +1 -0
@@ -33,6 +33,7 @@ struct symbol_conf symbol_conf = { .try_vmlinux_path = true, .annotate_src = true, .demangle = true, + .filter_relative = true, .symfs = "", };
tools/perf/util/symbol.h +3 -2
@@ -99,7 +99,8 @@ struct symbol_conf { annotate_asm_raw, annotate_src, event_group, - demangle; + demangle, + filter_relative;const char *vmlinux_name, *kallsyms_name, *source_prefix,
@@ -170,7 +171,7 @@ struct addr_location {struct symbol *sym;u64 addr;char level; -bool filtered; +u8 filtered;u8 cpumode;s32 cpu; };
Signature · 1 line
1.7.11.7
Namhyung Kim
maintainerPATCH 2/5 perf ui/tui: Add support for showing relative percentage
In reply to Namhyung KimWhen filtering by thread, dso or symbol on TUI it also update total period so that the output shows different result than no filter - the percentage changed to relative to filtered entries only. Sometimes (always?) this is not desired since users might expect same results with filter.
So change this behavior depends on symbol_conf.filter_relative value.
--- tools/perf/util/hist.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
tools/perf/util/hist.c +11 -4
@@ -696,10 +696,11 @@ static void hists__remove_entry_filter(struct hists *hists, struct hist_entry *hreturn ; ++hists->nr_entries; +if (symbol_conf.filter_relative) + hists->stats.total_period += h->stat.period;if (h->ms.unfolded) hists->nr_entries += h->nr_rows; h->row_offset =0 ; - hists->stats.total_period += h->stat.period; hists->stats.nr_events[PERF_RECORD_SAMPLE ] += h->stat.nr_events;hists__calc_col_len (hists, h);
@@ -722,7 +723,9 @@ void hists__filter_by_dso(struct hists *hists) {struct rb_node *nd; - hists->nr_entries = hists->stats.total_period =0 ; + hists->nr_entries =0 ; +if (symbol_conf.filter_relative) + hists->stats.total_period =0 ; hists->stats.nr_events[PERF_RECORD_SAMPLE ] =0 ;hists__reset_col_len (hists);
@@ -755,7 +758,9 @@ void hists__filter_by_thread(struct hists *hists) {struct rb_node *nd; - hists->nr_entries = hists->stats.total_period =0 ; + hists->nr_entries =0 ; +if (symbol_conf.filter_relative) + hists->stats.total_period =0 ; hists->stats.nr_events[PERF_RECORD_SAMPLE ] =0 ;hists__reset_col_len (hists);
@@ -786,7 +791,9 @@ void hists__filter_by_symbol(struct hists *hists) {struct rb_node *nd; - hists->nr_entries = hists->stats.total_period =0 ; + hists->nr_entries =0 ; +if (symbol_conf.filter_relative) + hists->stats.total_period =0 ; hists->stats.nr_events[PERF_RECORD_SAMPLE ] =0 ;hists__reset_col_len (hists);
Signature · 1 line
1.7.11.7
Namhyung Kim
maintainerPATCH 3/5 perf report: Add --percentage option
In reply to Namhyung KimThe --percentage option is for controlling overhead percentage displayed. It can only receive either of "relative" or "absolute".
"relative" means it's relative to filtered entries only so that the sum of shown entries will be always 100%. "absolute" means it retains original value before and after the filter applied.
$ perf report -s comm
# Overhead Command
# ........ ............
#
74.19% cc1
7.61% gcc
6.11% as
4.35% sh
4.14% make
1.13% fixdep
... $ perf report -s comm -c cc1,gcc --percentage absolute
# Overhead Command
# ........ ............
#
74.19% cc1
7.61% gcc $ perf report -s comm -c cc1,gcc --percentage relative
# Overhead Command
# ........ ............
#
90.69% cc1
9.31% gccNote that it has zero effect if no filter was applied.
--- tools/perf/Documentation/perf-report.txt | 6 ++++++ tools/perf/builtin-report.c | 16 ++++++++++++++++ 2 files changed, 22 insertions(+)
tools/perf/Documentation/perf-report.txt +6 -0
@@ -237,6 +237,12 @@ OPTIONS Do not show entries which have an overhead under that percent. (Default: 0). +--percentage:: + Determine how to display the overhead percentage of filtered entries. + "relative" means it's relative to filtered entries only so that the + sum of shown entries will be always 100%. "absolute" means it retains + original value before and after the filter applied. + --header:: Show header information in the perf.data file. This includes various information like hostname, OS and perf version, cpu/mem
tools/perf/builtin-report.c +16 -0
@@ -717,6 +717,20 @@ parse_percent_limit(const struct option *opt, const char *str,return 0 ; } +static int +parse_percentage (const struct option *opt__maybe_unused ,const char *str, +int unset__maybe_unused ) +{ +if (!strcmp (str,"relative" )) + symbol_conf.filter_relative = true; +else if (!strcmp (str,"absolute" )) + symbol_conf.filter_relative = false; +else +return -1 ; + +return 0 ; +} +int cmd_report (int argc,const char **argv,const char *prefix__maybe_unused ) {struct perf_session *session;
@@ -839,6 +853,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)OPT_BOOLEAN (0 ,"mem-mode" , &report.mem_mode,"mem access profile" ),OPT_CALLBACK (0 ,"percent-limit" , &report,"percent" ,"Don't show entries under that percent" , parse_percent_limit), +OPT_CALLBACK (0 ,"percentage" ,NULL ,"relative|absolute" , +"how to display percentage of filtered entries" , parse_percentage),OPT_END () }; struct perf_data_file file = {
Signature · 1 line
1.7.11.7
Re: [PATCH 3/5] perf report: Add --percentage option
Quoted 4 lines · Namhyung Kim
+--percentage::
(quoted diff) +1
-0+ Determine how to display the overhead percentage of filteredentries.
This should describe also what a "filtered entry" exactly is. It's not clear even to me.
-Andi
Quoted 4 lines
tools/perf/Documentation/perf-report.txt +4
-0+ "relative" means it's relative to filtered entries only so that the + sum of shown entries will be always 100%. "absolute" means it retains + original value before and after the filter applied. +
Signature · 1 line
[email protected] -- Speaking for myself only
Re: [PATCH 3/5] perf report: Add --percentage option
Em Tue, Jan 14, 2014 at 01:07:00PM -0800, Andi Kleen escreveu:
Quoted 8 lines
Quoted 4 lines · Namhyung Kim
+--percentage::
(quoted diff) +1
-0+ Determine how to display the overhead percentage of filteredentries.
This should describe also what a "filtered entry" exactly is. It's not clear even to me.
Yeah, the text should give some context, mentioning the "Zoom" operations that can be done in the TUI (DSO, thread, etc) that allows applying what he is calling "filters".`
Quoted 9 lines
-Andi
Quoted 4 lines
tools/perf/Documentation/perf-report.txt +4
-0+ "relative" means it's relative to filtered entries only so that the + sum of shown entries will be always 100%. "absolute" means it retains + original value before and after the filter applied. +Signature · 1 line
[email protected] -- Speaking for myself only
Namhyung Kim
maintainerRe: [PATCH 3/5] perf report: Add --percentage option
Quoted 10 lines · Arnaldo Carvalho de Melo
Em Tue, Jan 14, 2014 at 01:07:00PM -0800, Andi Kleen escreveu:
Quoted 8 lines
Quoted 4 lines · Namhyung Kim
+--percentage::
(quoted diff) +1
-0+ Determine how to display the overhead percentage of filteredentries.
This should describe also what a "filtered entry" exactly is. It's not clear even to me.
Quoted 3 lines
Yeah, the text should give some context, mentioning the "Zoom" operations that can be done in the TUI (DSO, thread, etc) that allows applying what he is calling "filters".`
Ah, okay.
How about this:
-c::
--comms=::
Only consider symbols in these comms. CSV that understands file://filename entries. This option will affect the percentage of overhead column. See --percentage for more info.
-d::
--dsos=::
Only consider symbols in these dsos. CSV that understands file://filename entries. This option will affect the percentage of overhead column. See --percentage for more info.
-S::
--symbols=::
Only consider these symbols. CSV that understands file://filename entries. This option will affect the percentage of overhead column. See --percentage for more info.
--percentage::
Determine how to display the overhead percentage of filtered entries. Filters can be applied by --comms, --dsos and/or --symbols options and Zoom operations on the TUI (thread, dso, etc).
"relative" means it's relative to filtered entries only so that the sum of shown entries will be always 100%. "absolute" means it retains original value before and after the filter applied.
Thanks,
Namhyung
Re: [PATCH 3/5] perf report: Add --percentage option
Em Wed, Jan 15, 2014 at 11:18:23AM +0900, Namhyung Kim escreveu:
Quoted 11 lines · Arnaldo Carvalho de Melo
Quoted 10 lines
Em Tue, Jan 14, 2014 at 01:07:00PM -0800, Andi Kleen escreveu:
Quoted 8 lines
Quoted 4 lines · Namhyung Kim
+--percentage::
(quoted diff) +1
-0+ Determine how to display the overhead percentage of filteredentries.
This should describe also what a "filtered entry" exactly is. It's not clear even to me.
Quoted 7 lines
Quoted 3 lines
Yeah, the text should give some context, mentioning the "Zoom" operations that can be done in the TUI (DSO, thread, etc) that allows applying what he is calling "filters".`
Ah, okay.
How about this:
Ack, much clearer, minor things below:
Quoted 6 lines
-c::
--comms=::
Only consider symbols in these comms. CSV that understands file://filename entries. This option will affect the percentage of overhead column. See --percentage for more info.
the overhead column. ...
Quoted 5 lines
-d::
--dsos=::
Only consider symbols in these dsos. CSV that understands file://filename entries. This option will affect the percentage of overhead column. See --percentage for more info.
ditto
Quoted 5 lines
-S::
--symbols=::
Only consider these symbols. CSV that understands file://filename entries. This option will affect the percentage of overhead column. See --percentage for more info.
ditto
Quoted 9 lines
--percentage::
Determine how to display the overhead percentage of filtered entries. Filters can be applied by --comms, --dsos and/or --symbols options and Zoom operations on the TUI (thread, dso, etc)."relative" means it's relative to filtered entries only so that the sum of shown entries will be always 100%. "absolute" means it retains original value before and after the filter applied.
Another missing 'the': "... retains the original value ..." plus a missing 'is' just before 'applied'.
- Arnaldo
Namhyung Kim
maintainerRe: [PATCH 3/5] perf report: Add --percentage option
Quoted 16 lines · Arnaldo Carvalho de Melo
Em Wed, Jan 15, 2014 at 11:18:23AM +0900, Namhyung Kim escreveu:
Quoted 15 lines · Arnaldo Carvalho de Melo
Quoted 13 lines
Em Tue, Jan 14, 2014 at 01:07:00PM -0800, Andi Kleen escreveu:
Quoted 8 lines
Quoted 4 lines · Namhyung Kim
+--percentage::
(quoted diff) +1
-0+ Determine how to display the overhead percentage of filteredentries.
This should describe also what a "filtered entry" exactly is. It's not clear even to me.
Yeah, the text should give some context, mentioning the "Zoom" operations that can be done in the TUI (DSO, thread, etc) that allows applying what he is calling "filters".`
Quoted 5 lines
Quoted 3 lines
Ah, okay.
How about this:
Ack, much clearer, minor things below:
Here goes an update :)
Quoted 1 line
From
abd3ee476573087339794730bf8797913cf1a909Mon Sep 17 00:00:00 2001
From: Namhyung Kim <[email protected]>
Date: Tue, 14 Jan 2014 11:52:48 +0900
Subject: [PATCH] perf report: Add --percentage option
The --percentage option is for controlling overhead percentage displayed. It can only receive either of "relative" or "absolute".
"relative" means it's relative to filtered entries only so that the sum of shown entries will be always 100%. "absolute" means it retains the original value before and after the filter is applied.
$ perf report -s comm
# Overhead Command
# ........ ............
#
74.19% cc1
7.61% gcc
6.11% as
4.35% sh
4.14% make
1.13% fixdep
... $ perf report -s comm -c cc1,gcc --percentage absolute
# Overhead Command
# ........ ............
#
74.19% cc1
7.61% gcc $ perf report -s comm -c cc1,gcc --percentage relative
# Overhead Command
# ........ ............
#
90.69% cc1
9.31% gccNote that it has zero effect if no filter was applied.
--- tools/perf/Documentation/perf-report.txt | 24 ++++++++++++++++++------ tools/perf/builtin-report.c | 16 ++++++++++++++++ 2 files changed, 34 insertions(+), 6 deletions(-)
tools/perf/Documentation/perf-report.txt +18 -6
@@ -25,10 +25,6 @@ OPTIONS --verbose:: Be more verbose. (show symbol address, etc) --d:: ---dsos=:: - Only consider symbols in these dsos. CSV that understands - file://filename entries. -n:: --show-nr-samples:: Show the number of samples for each symbol
@@ -42,11 +38,18 @@ OPTIONS -c:: --comms=:: Only consider symbols in these comms. CSV that understands - file://filename entries. + file://filename entries. This option will affect the percentage of + the overhead column. See --percentage for more info. +-d:: +--dsos=:: + Only consider symbols in these dsos. CSV that understands + file://filename entries. This option will affect the percentage of + the overhead column. See --percentage for more info. -S:: --symbols=:: Only consider these symbols. CSV that understands - file://filename entries. + file://filename entries. This option will affect the percentage of + the overhead column. See --percentage for more info. --symbol-filter=:: Only show symbols that match (partially) with this filter.
@@ -237,6 +240,15 @@ OPTIONS Do not show entries which have an overhead under that percent. (Default: 0). +--percentage:: + Determine how to display the overhead percentage of filtered entries. + Filters can be applied by --comms, --dsos and/or --symbols options and + Zoom operations on the TUI (thread, dso, etc). + + "relative" means it's relative to filtered entries only so that the + sum of shown entries will be always 100%. "absolute" means it retains + the original value before and after the filter is applied. + --header:: Show header information in the perf.data file. This includes various information like hostname, OS and perf version, cpu/mem
tools/perf/builtin-report.c +16 -0
@@ -699,6 +699,20 @@ parse_percent_limit(const struct option *opt, const char *str,return 0 ; } +static int +parse_percentage (const struct option *opt__maybe_unused ,const char *str, +int unset__maybe_unused ) +{ +if (!strcmp (str,"relative" )) + symbol_conf.filter_relative = true; +else if (!strcmp (str,"absolute" )) + symbol_conf.filter_relative = false; +else +return -1 ; + +return 0 ; +} +int cmd_report (int argc,const char **argv,const char *prefix__maybe_unused ) {struct perf_session *session;
@@ -821,6 +835,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)OPT_BOOLEAN (0 ,"mem-mode" , &report.mem_mode,"mem access profile" ),OPT_CALLBACK (0 ,"percent-limit" , &report,"percent" ,"Don't show entries under that percent" , parse_percent_limit), +OPT_CALLBACK (0 ,"percentage" ,NULL ,"relative|absolute" , +"how to display percentage of filtered entries" , parse_percentage),OPT_END () }; struct perf_data_file file = {
Signature · 1 line
1.7.11.7
Namhyung Kim
maintainerPATCH 4/5 perf report: Add report.percentage config option
In reply to Namhyung KimAdd report.percentage option for setting default value of the symbol_conf.filter_relative. It affects the report output only if a filter applied.
An user can write .perfconfig file like below to show absolute percentage of filtered entries by default:
$ cat ~/.perfconfig [report] percentage = absolute
And it can be changed through command line:
$ perf report --percentage relative
--- tools/perf/builtin-report.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
tools/perf/builtin-report.c +10 -0
@@ -71,6 +71,16 @@ static int report__config(const char *var, const char *value, void *cb) rep->min_percent =strtof (value,NULL );return 0 ; } +if (!strcmp (var,"report.percentage" )) { +if (!strcmp (value,"relative" )) + symbol_conf.filter_relative = true; +else if (!strcmp (value,"absolute" )) + symbol_conf.filter_relative = false; +else +return -1 ; + +return 0 ; + }return perf_default_config (var, value, cb); }
Signature · 1 line
1.7.11.7
Namhyung Kim
maintainerPATCH 5/5 perf tools: Show absolute percentage by default
In reply to Namhyung KimNow perf report will show absolute percentage on filter entries by default.
--- tools/perf/util/symbol.c | 1 - 1 file changed, 1 deletion(-)
tools/perf/util/symbol.c +0 -1
@@ -33,7 +33,6 @@ struct symbol_conf symbol_conf = { .try_vmlinux_path = true, .annotate_src = true, .demangle = true, - .filter_relative = true, .symfs = "", };
Signature · 1 line
1.7.11.7