perf tools: Fixup for the --percentage change (v2)
Namhyung Kim
maintainercover perf tools: Fixup for the --percentage change (v2)
Hello,
This patchset tries to fix bugs in percentage handling which is recently changed. The perf top with symbol filter could cause a segfault (NULL pointer dereference) if the filter found no entry.
In this patchset, I moved accounting of various histogram stats to be calculated at the time it actually shown to users. Although I tested it on my system for a while, it needs more testing since it'll affect behaviors of many commands/usages.
There're three main fields in the hists->stats to affect the output:
number of samples, number of hist entries and total periods.
Also there're three stages to process samples: at first, samples are converted to a hist entry and added to the input tree, and then they are moved to the collapsed tree if needed, and finally they're moved to the output tree to be shown to user.
The (part of) stats are accounted when samples are added to the input tree and then reset before moving to the output tree, and re-counted during insertion to the output tree.
I can see some reason to do it this way but it's basically not necessary and could make a problem in multi-threaded programs like perf top.
The perf report does all these passes sequentially in a single thread so it seems no problem. But perf top uses two threads - one for gathering samples (in the input tree) and another for (collapsing and) moving them to the output tree. Thus accounting stat in parallel can result in an inaccurate stats and the output.
So I'd like to get rid of the accounting on the input stage as you can see it just gets dropped before doing output resort. I originally make the all three stats are accounted when doing output resort but changed mind to account number of samples in the input stage and others in the output stage. Because it'd make more sense accounting number of events (sample event) in the input stage (as all other events are also accounted in the input stage) and it'd make less changes in code.
So yes, it has a same problem of inaccurate number of samples, but its impact should be smaller than other stats - seeing increasing sample count (could be slightly inaccurate) without new entries in the browser.
You can get this on the 'perf/percentage-v11' branch (yes, v11 - as it's continued from my previous series) in my tree
git://git.kenrel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git
Any comments, review and testing are welcomed.
Thanks,
Namhyung
Namhyung Kim (7):
perf report: Count number of entries separately
perf tools: Account entry stats when it's added to the output tree perf hists: Add missing update on filtered stats in
hists__decay_entries()
perf ui/tui: Fix off-by-one in hist_browser__update_nr_entries() perf ui/tui: Rename hist_browser__update_nr_entries() perf top/tui: Update nr_entries properly after a filter is applied perf hists/tui: Count callchain rows separately
tools/perf/builtin-annotate.c | 3 +- tools/perf/builtin-diff.c | 23 ++++++----- tools/perf/builtin-report.c | 58 ++++++++++++--------------- tools/perf/ui/browsers/hists.c | 86 ++++++++++++++++++++++++++-------------- tools/perf/util/hist.c | 89 +++++++++++++++++++++++++++--------------- tools/perf/util/hist.h | 9 ++++- 6 files changed, 162 insertions(+), 106 deletions(-)
Signature · 1 line
1.9.2
Namhyung Kim
maintainerPATCH 1/7 perf report: Count number of entries separately
The hists->nr_entries is counted in multiple places so that they can confuse readers of the code. This is a preparation of later change and do not intend any functional difference.
Note that report__collapse_hists() now changed to return nothing since its return value (nr_samples) is only for checking if there's any data in the input file and this can be acheived by checking ->nr_entries.
--- tools/perf/builtin-report.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-)
tools/perf/builtin-report.c +22 -20
@@ -57,6 +57,7 @@ struct report {const char *cpu_list;const char *symbol_filter_str;float min_percent; +u64 nr_entries;DECLARE_BITMAP (cpu_bitmap,MAX_NR_CPUS ); };
@@ -75,6 +76,17 @@ static int report__config(const char *var, const char *value, void *cb)return perf_default_config (var, value, cb); } +static void report__inc_stats (struct report *rep,struct hist_entry *he) +{ +/* +* The @he is either of a newly created one or an existing one +* merging current sample. We only want to count a new one so +* checking ->nr_events being 1. +*/ +if (he->stat.nr_events ==1 ) + rep->nr_entries++; +} +static int report__add_mem_hist_entry (struct report *rep,struct addr_location *al,struct perf_sample *sample,struct perf_evsel *evsel) {
@@ -121,6 +133,8 @@ static int report__add_mem_hist_entry(struct report *rep, struct addr_location * goto out; } +report__inc_stats (rep, he); + evsel->hists.stats.total_period += cost;hists__inc_nr_events (&evsel->hists,PERF_RECORD_SAMPLE );if (!he->filtered)
@@ -176,6 +190,8 @@ static int report__add_branch_hist_entry(struct report *rep, struct addr_locatio goto out; } +report__inc_stats (rep, he); + evsel->hists.stats.total_period +=1 ;hists__inc_nr_events (&evsel->hists,PERF_RECORD_SAMPLE );if (!he->filtered)
@@ -212,6 +228,8 @@ static int report__add_hist_entry(struct report *rep, struct perf_evsel *evsel,if (ui__has_annotation ()) err =hist_entry__inc_addr_samples (he, evsel->idx, al->addr); +report__inc_stats (rep, he); + evsel->hists.stats.total_period += sample->period;if (!he->filtered) evsel->hists.stats.nr_non_filtered_samples++;
@@ -486,24 +504,12 @@ static int report__browse_hists(struct report *rep)return ret; } -static u64 report__collapse_hists (struct report *rep) +static void report__collapse_hists (struct report *rep) {struct ui_progress prog;struct perf_evsel *pos; -u64 nr_samples =0 ; -/* -* Count number of histogram entries to use when showing progress, -* reusing nr_samples variable. -*/ -evlist__for_each (rep->session->evlist, pos) - nr_samples += pos->hists.nr_entries; -ui_progress__init (&prog, nr_samples,"Merging related events..." ); -/* -* Count total number of samples, will be used to check if this -* session had any. -*/ - nr_samples =0 ; +ui_progress__init (&prog, rep->nr_entries,"Merging related events..." );evlist__for_each (rep->session->evlist, pos) {struct hists *hists = &pos->hists;
@@ -512,7 +518,6 @@ static u64 report__collapse_hists(struct report *rep) hists->symbol_filter_str = rep->symbol_filter_str;hists__collapse_resort (hists, &prog); - nr_samples += hists->stats.nr_events[PERF_RECORD_SAMPLE ];/* Non-group events are considered as leader */ if (symbol_conf.event_group &&
@@ -525,14 +530,11 @@ static u64 report__collapse_hists(struct report *rep) }ui_progress__finish (); - -return nr_samples; }static int __cmd_report (struct report *rep) {int ret; -u64 nr_samples;struct perf_session *session = rep->session;struct perf_evsel *pos;struct perf_data_file *file = session->file;
@@ -572,12 +574,12 @@ static int __cmd_report(struct report *rep) } } - nr_samples =report__collapse_hists (rep); +report__collapse_hists (rep);if (session_done ())return 0 ; -if (nr_samples ==0 ) { +if (rep->nr_entries ==0 ) {ui__error ("The %s file has no samples!\n" , file->path);return 0 ; }
Signature · 1 line
1.9.2
Namhyung Kim
maintainerPATCH 2/7 perf tools: Account entry stats when it's added to the output tree
In reply to Namhyung KimCurrently, accounting each sample is done in multiple places - once when adding them to the input tree, other when adding them to the output tree. It's not only confusing but also can cause a subtle problem since concurrent processing like in perf top might see the updated stats before adding entries into the output tree - like seeing more (blank) lines at the end and/or slight inaccurate percentage.
To fix this, only account the entries when it's moved into the output tree so that they cannot be seen prematurely. There're some exceptional cases here and there - they should be addressed separately with comments.
--- tools/perf/builtin-annotate.c | 3 +- tools/perf/builtin-diff.c | 23 ++++++++----- tools/perf/builtin-report.c | 18 +++------- tools/perf/util/hist.c | 78 ++++++++++++++++++++++++++----------------- tools/perf/util/hist.h | 3 +- 5 files changed, 69 insertions(+), 56 deletions(-)
tools/perf/builtin-annotate.c +1 -2
@@ -46,7 +46,7 @@ struct perf_annotate { };static int perf_evsel__add_sample (struct perf_evsel *evsel, -struct perf_sample *sample, +struct perf_sample *sample__maybe_unused ,struct addr_location *al,struct perf_annotate *ann) {
@@ -70,7 +70,6 @@ static int perf_evsel__add_sample(struct perf_evsel *evsel,return -ENOMEM ; ret =hist_entry__inc_addr_samples (he, evsel->idx, al->addr); - evsel->hists.stats.total_period += sample->period;hists__inc_nr_events (&evsel->hists,PERF_RECORD_SAMPLE );return ret; }
tools/perf/builtin-diff.c +14 -9
@@ -341,11 +341,16 @@ static int diff__process_sample_event(struct perf_tool *tool __maybe_unused,return -1 ; } -if (al.filtered ==0 ) { - evsel->hists.stats.total_non_filtered_period += sample->period; - evsel->hists.nr_non_filtered_entries++; - } +/* +* The total_period is updated here before going to the output +* tree since normally only the baseline hists will call +* hists__output_resort() and precompute needs the total +* period in order to sort entries by percentage delta. +*/ evsel->hists.stats.total_period += sample->period; +if (!al.filtered) + evsel->hists.stats.total_non_filtered_period += sample->period; +return 0 ; }
@@ -573,10 +578,7 @@ static void hists__compute_resort(struct hists *hists) hists->entries =RB_ROOT ; next =rb_first (root); - hists->nr_entries =0 ; - hists->nr_non_filtered_entries =0 ; - hists->stats.total_period =0 ; - hists->stats.total_non_filtered_period =0 ; +hists__reset_stats (hists);hists__reset_col_len (hists);while (next !=NULL ) {
@@ -586,7 +588,10 @@ static void hists__compute_resort(struct hists *hists) next =rb_next (&he->rb_node_in);insert_hist_entry_by_compute (&hists->entries, he, compute); -hists__inc_nr_entries (hists, he); +hists__inc_stats (hists, he); + +if (!he->filtered) +hists__calc_col_len (hists, he); } }
tools/perf/builtin-report.c +4 -14
@@ -85,6 +85,10 @@ static void report__inc_stats(struct report *rep, struct hist_entry *he)*/ if (he->stat.nr_events ==1 ) rep->nr_entries++; + +hists__inc_nr_events (he->hists,PERF_RECORD_SAMPLE ); +if (!he->filtered) + he->hists->stats.nr_non_filtered_samples++; } static int report__add_mem_hist_entry(struct report *rep, struct addr_location *al,
@@ -135,10 +139,6 @@ static int report__add_mem_hist_entry(struct report *rep, struct addr_location *report__inc_stats (rep, he); - evsel->hists.stats.total_period += cost; -hists__inc_nr_events (&evsel->hists,PERF_RECORD_SAMPLE ); -if (!he->filtered) - evsel->hists.stats.nr_non_filtered_samples++; err =hist_entry__append_callchain (he, sample); out:return err;
@@ -189,13 +189,7 @@ static int report__add_branch_hist_entry(struct report *rep, struct addr_locatioif (err) goto out; } -report__inc_stats (rep, he); - - evsel->hists.stats.total_period +=1 ; -hists__inc_nr_events (&evsel->hists,PERF_RECORD_SAMPLE ); -if (!he->filtered) - evsel->hists.stats.nr_non_filtered_samples++; }else goto out; }
@@ -230,10 +224,6 @@ static int report__add_hist_entry(struct report *rep, struct perf_evsel *evsel,report__inc_stats (rep, he); - evsel->hists.stats.total_period += sample->period; -if (!he->filtered) - evsel->hists.stats.nr_non_filtered_samples++; -hists__inc_nr_events (&evsel->hists,PERF_RECORD_SAMPLE ); out:return err; }
tools/perf/util/hist.c +48 -30
147 lines not on this page · raw message
tools/perf/util/hist.h +2 -1
@@ -116,7 +116,8 @@ void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel);void hists__output_recalc_col_len (struct hists *hists,int max_rows);u64 hists__total_period (struct hists *hists); -void hists__inc_nr_entries (struct hists *hists,struct hist_entry *h); +void hists__reset_stats (struct hists *hists); +void hists__inc_stats (struct hists *hists,struct hist_entry *h);void hists__inc_nr_events (struct hists *hists,u32 type);void events_stats__inc (struct events_stats *stats,u32 type);size_t events_stats__fprintf (struct events_stats *stats,FILE *fp);
Signature · 1 line
1.9.2
Re: [PATCH 2/7] perf tools: Account entry stats when it's added to the output tree
Quoted 11 lines · Namhyung Kim
Currently, accounting each sample is done in multiple places - once when adding them to the input tree, other when adding them to the output tree. It's not only confusing but also can cause a subtle problem since concurrent processing like in perf top might see the updated stats before adding entries into the output tree - like seeing more (blank) lines at the end and/or slight inaccurate percentage.
To fix this, only account the entries when it's moved into the output tree so that they cannot be seen prematurely. There're some exceptional cases here and there - they should be addressed separately with comments.
sry to be PITA, but need to ask you to split the patch, otherwise I'd get beaten for that ;-)
I can see several separated changes here:
* remove stats for input tree (as stated in changelog)
* hists__inc_nr_entries -> hists__inc_stats rename
* add hists__reset_stats function
* move hists__calc_col_len out of hists__inc_nr_entries
Quoted 3 lines
Signed-off-by Namhyung Kim <[email protected]>---
SNIP
tools/perf/builtin-report.c static void report__inc_stats(struct report *rep, struct hist_entry *he) · line 91
Quoted 13 lines
tools/perf/builtin-report.c +4
-0@@ -85,6 +85,10 @@ static void report__inc_stats(struct report *rep, struct hist_entry *he)*/ if (he->stat.nr_events ==1 ) rep->nr_entries++; + +hists__inc_nr_events (he->hists,PERF_RECORD_SAMPLE ); +if (!he->filtered) + he->hists->stats.nr_non_filtered_samples++;
could you put here some comments as for the diff command I mean why is this exception in stats counting for input tree
thanks,
jirka
Namhyung Kim
maintainerRe: [PATCH 2/7] perf tools: Account entry stats when it's added to the output tree
Hi Jiri,
2014-04-23 (수), 15:35 +0200, Jiri Olsa:
Quoted 8 lines · Namhyung Kim
Quoted 7 lines
Currently, accounting each sample is done in multiple places - once when adding them to the input tree, other when adding them to the output tree. It's not only confusing but also can cause a subtle problem since concurrent processing like in perf top might see the updated stats before adding entries into the output tree - like seeing more (blank) lines at the end and/or slight inaccurate percentage.
Quoted 7 lines
Quoted 4 lines
To fix this, only account the entries when it's moved into the output tree so that they cannot be seen prematurely. There're some exceptional cases here and there - they should be addressed separately with comments.
sry to be PITA, but need to ask you to split the patch, otherwise I'd get beaten for that ;-)
No problem. I'll split it in the next spin.
Quoted 15 lines
I can see several separated changes here:
* remove stats for input tree (as stated in changelog)
*hists__inc_nr_entries->hists__inc_statsrename
* addhists__reset_statsfunction
* movehists__calc_col_lenout ofhists__inc_nr_entriesQuoted 3 lines
Signed-off-by Namhyung Kim <[email protected]>---
SNIP
Quoted 1 line
Quoted 15 lines
tools/perf/builtin-report.c static void report__inc_stats(struct report *rep, struct hist_entry *he) · line 91
Quoted 12 lines
tools/perf/builtin-report.c +4
-0@@ -85,6 +85,10 @@ static void report__inc_stats(struct report *rep, struct hist_entry *he)*/ if (he->stat.nr_events ==1 ) rep->nr_entries++; + +hists__inc_nr_events (he->hists,PERF_RECORD_SAMPLE ); +if (!he->filtered) + he->hists->stats.nr_non_filtered_samples++;could you put here some comments as for the diff command I mean why is this exception in stats counting for input tree
Will do as well.
Thanks,
Namhyung
Namhyung Kim
maintainerPATCH 3/7 perf hists: Add missing update on filtered stats in hists__decay_entries()
In reply to Namhyung KimWhen a filter is used for perf top, its hists->nr_non_filtered_entries was not updated after it removed an entry in hists__decay_entries(). Also hists->stats.total_non_filtered_period was missed too.
--- tools/perf/util/hist.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
tools/perf/util/hist.c +9 -2
@@ -225,14 +225,18 @@ static void he_stat__decay(struct he_stat *he_stat)static bool hists__decay_entry (struct hists *hists,struct hist_entry *he) {u64 prev_period = he->stat.period; +u64 diff;if (prev_period ==0 )return true;he_stat__decay (&he->stat); + diff = prev_period - he->stat.period; + + hists->stats.total_period -= diff;if (!he->filtered) - hists->stats.total_period -= prev_period - he->stat.period; + hists->stats.total_non_filtered_period -= diff;return he->stat.period ==0 ; }
@@ -259,8 +263,11 @@ void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel)if (sort__need_collapse)rb_erase (&n->rb_node_in, &hists->entries_collapsed); -hist_entry__free (n); --hists->nr_entries; +if (!n->filtered) + --hists->nr_non_filtered_entries; + +hist_entry__free (n); } } }
Signature · 1 line
1.9.2
Namhyung Kim
maintainerPATCH 4/7 perf ui/tui: Fix off-by-one in hist_browser__update_nr_entries()
In reply to Namhyung KimThe nr_entries variable is increased inside the loop in the function but it always count the first entry regardless of it's filtered or not; caused an off-by-one error.
It'd become a problem especially there's no entry at all - it'd get a segfault during referencing a NULL pointer.
--- tools/perf/ui/browsers/hists.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/perf/ui/browsers/hists.c +3 -3
@@ -1348,10 +1348,10 @@ static void hist_browser__update_pcnt_entries(struct hist_browser *hb)u64 nr_entries =0 ;struct rb_node *nd =rb_first (&hb->hists->entries); -while (nd) { +while ((nd =hists__filter_entries (nd, hb->hists, + hb->min_pcnt)) !=NULL ) { nr_entries++; - nd =hists__filter_entries (rb_next (nd), hb->hists, - hb->min_pcnt); + nd =rb_next (nd); } hb->nr_pcnt_entries = nr_entries;
Signature · 1 line
1.9.2
Namhyung Kim
maintainerPATCH 5/7 perf ui/tui: Rename hist_browser__update_nr_entries()
In reply to Namhyung KimRename ->nr_pcnt_entries and hist_browser__update_pcnt_entries() to ->nr_non_filtered_entries and hist_browser__update_nr_entries() since it's now used for filtering as well.
--- tools/perf/ui/browsers/hists.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
tools/perf/ui/browsers/hists.c +8 -9
@@ -26,13 +26,14 @@ struct hist_browser {int print_seq;bool show_dso;float min_pcnt; -u64 nr_pcnt_entries; +u64 nr_non_filtered_entries; };extern void hist_browser__init_hpp (void );static int hists__browser_title (struct hists *hists,char *bf,size_t size,const char *ev_name); +static void hist_browser__update_nr_entries (struct hist_browser *hb);static void hist_browser__refresh_dimensions (struct hist_browser *browser) {
@@ -310,8 +311,6 @@ static void ui_browser__warn_lost_events(struct ui_browser *browser) "Or reduce the sampling frequency."); } -static void hist_browser__update_pcnt_entries (struct hist_browser *hb); -static int hist_browser__run (struct hist_browser *browser,const char *ev_name,struct hist_browser_timer *hbt) {
@@ -322,7 +321,7 @@ static int hist_browser__run(struct hist_browser *browser, const char *ev_name, browser->b.entries = &browser->hists->entries; browser->b.nr_entries = browser->hists->nr_entries;if (browser->min_pcnt) - browser->b.nr_entries = browser->nr_pcnt_entries; + browser->b.nr_entries = browser->nr_non_filtered_entries;hist_browser__refresh_dimensions (browser);hists__browser_title (browser->hists, title,sizeof (title), ev_name);
@@ -340,8 +339,8 @@ static int hist_browser__run(struct hist_browser *browser, const char *ev_name, hbt->timer (hbt->arg);if (browser->min_pcnt) { -hist_browser__update_pcnt_entries (browser); - nr_entries = browser->nr_pcnt_entries; +hist_browser__update_nr_entries (browser); + nr_entries = browser->nr_non_filtered_entries; }else { nr_entries = browser->hists->nr_entries; }
@@ -1343,7 +1342,7 @@ close_file_and_continue:return ret; } -static void hist_browser__update_pcnt_entries (struct hist_browser *hb) +static void hist_browser__update_nr_entries (struct hist_browser *hb) {u64 nr_entries =0 ;struct rb_node *nd =rb_first (&hb->hists->entries);
@@ -1354,7 +1353,7 @@ static void hist_browser__update_pcnt_entries(struct hist_browser *hb) nd =rb_next (nd); } - hb->nr_pcnt_entries = nr_entries; + hb->nr_non_filtered_entries = nr_entries; } static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
@@ -1411,7 +1410,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,if (min_pcnt) { browser->min_pcnt = min_pcnt; -hist_browser__update_pcnt_entries (browser); +hist_browser__update_nr_entries (browser); } fstack =pstack__new (2 );
Signature · 1 line
1.9.2
Namhyung Kim
maintainerPATCH 6/7 perf top/tui: Update nr_entries properly after a filter is applied
In reply to Namhyung KimThe hist_browser__reset() is only called right after a filter is applied so it needs to udpate browser->nr_entries properly. We cannot use hists->nr_non_filtered_entreis directly since it's possible that such entries are also filtered out by minimum percentage limit.
In addition when a filter is used for perf top, hist browser's nr_entries field was not updated after applying the filter. But it needs to be updated as new samples are coming.
--- tools/perf/ui/browsers/hists.c | 20 ++++++++++++++++---- tools/perf/util/hist.h | 6 ++++++ 2 files changed, 22 insertions(+), 4 deletions(-)
tools/perf/ui/browsers/hists.c +16 -4
@@ -35,6 +35,11 @@ static int hists__browser_title(struct hists *hists, char *bf, size_t size, const char *ev_name);static void hist_browser__update_nr_entries (struct hist_browser *hb); +static bool hist_browser__has_filter (struct hist_browser *hb) +{ +return hists__has_filter (hb->hists) || hb->min_pcnt; +} +static void hist_browser__refresh_dimensions (struct hist_browser *browser) {/* 3 == +/- toggle symbol before actual hist_entry rendering */
@@ -44,7 +49,8 @@ static void hist_browser__refresh_dimensions(struct hist_browser *browser)static void hist_browser__reset (struct hist_browser *browser) { - browser->b.nr_entries = browser->hists->nr_entries; +hist_browser__update_nr_entries (browser); + browser->b.nr_entries = browser->nr_non_filtered_entries;hist_browser__refresh_dimensions (browser);ui_browser__reset_index (&browser->b); }
@@ -319,9 +325,10 @@ static int hist_browser__run(struct hist_browser *browser, const char *ev_name,int delay_secs = hbt ? hbt->refresh :0 ; browser->b.entries = &browser->hists->entries; - browser->b.nr_entries = browser->hists->nr_entries; -if (browser->min_pcnt) +if (hist_browser__has_filter (browser)) browser->b.nr_entries = browser->nr_non_filtered_entries; +else + browser->b.nr_entries = browser->hists->nr_entries;hist_browser__refresh_dimensions (browser);hists__browser_title (browser->hists, title,sizeof (title), ev_name);
@@ -338,7 +345,7 @@ static int hist_browser__run(struct hist_browser *browser, const char *ev_name,u64 nr_entries; hbt->timer (hbt->arg); -if (browser->min_pcnt) { +if (hist_browser__has_filter (browser)) {hist_browser__update_nr_entries (browser); nr_entries = browser->nr_non_filtered_entries; }else {
@@ -1347,6 +1354,11 @@ static void hist_browser__update_nr_entries(struct hist_browser *hb)u64 nr_entries =0 ;struct rb_node *nd =rb_first (&hb->hists->entries); +if (hb->min_pcnt ==0 ) { + hb->nr_non_filtered_entries = hb->hists->nr_non_filtered_entries; +return ; + } +while ((nd =hists__filter_entries (nd, hb->hists, hb->min_pcnt)) !=NULL ) { nr_entries++;
tools/perf/util/hist.h +6 -0
@@ -129,6 +129,12 @@ void hists__filter_by_dso(struct hists *hists);void hists__filter_by_thread (struct hists *hists);void hists__filter_by_symbol (struct hists *hists); +static inline bool hists__has_filter (struct hists *hists) +{ +return hists->thread_filter || hists->dso_filter || + hists->symbol_filter_str; +} +u16 hists__col_len (struct hists *hists,enum hist_column col);void hists__set_col_len (struct hists *hists,enum hist_column col,u16 len);bool hists__new_col_len (struct hists *hists,enum hist_column col,u16 len);
Signature · 1 line
1.9.2
Namhyung Kim
maintainerPATCH 7/7 perf hists/tui: Count callchain rows separately
In reply to Namhyung KimWhen TUI hist browser expands/collapses callchains it accounted number of callchain nodes into total entries to show. However this code ignores filtering so that it can make the cursor go to out of screen.
--- tools/perf/ui/browsers/hists.c | 57 +++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 20 deletions(-)
tools/perf/ui/browsers/hists.c +37 -20
@@ -27,6 +27,7 @@ struct hist_browser {bool show_dso;float min_pcnt;u64 nr_non_filtered_entries; +u64 nr_callchain_rows; };extern void hist_browser__init_hpp (void );
@@ -35,11 +36,27 @@ static int hists__browser_title(struct hists *hists, char *bf, size_t size, const char *ev_name);static void hist_browser__update_nr_entries (struct hist_browser *hb); +static struct rb_node *hists__filter_entries (struct rb_node *nd, +struct hists *hists, +float min_pcnt); +static bool hist_browser__has_filter (struct hist_browser *hb) {return hists__has_filter (hb->hists) || hb->min_pcnt; } +static u32 hist_browser__nr_entries (struct hist_browser *hb) +{ +u32 nr_entries; + +if (hist_browser__has_filter (hb)) + nr_entries = hb->nr_non_filtered_entries; +else + nr_entries = hb->hists->nr_entries; + +return nr_entries + hb->nr_callchain_rows; +} +static void hist_browser__refresh_dimensions (struct hist_browser *browser) {/* 3 == +/- toggle symbol before actual hist_entry rendering */
@@ -50,7 +67,7 @@ static void hist_browser__refresh_dimensions(struct hist_browser *browser)static void hist_browser__reset (struct hist_browser *browser) {hist_browser__update_nr_entries (browser); - browser->b.nr_entries = browser->nr_non_filtered_entries; + browser->b.nr_entries =hist_browser__nr_entries (browser);hist_browser__refresh_dimensions (browser);ui_browser__reset_index (&browser->b); }
@@ -205,14 +222,16 @@ static bool hist_browser__toggle_fold(struct hist_browser *browser)struct hist_entry *he = browser->he_selection;hist_entry__init_have_children (he); - browser->hists->nr_entries -= he->nr_rows; + browser->b.nr_entries -= he->nr_rows; + browser->nr_callchain_rows -= he->nr_rows;if (he->ms.unfolded) he->nr_rows =callchain__count_rows (&he->sorted_chain);else he->nr_rows =0 ; - browser->hists->nr_entries += he->nr_rows; - browser->b.nr_entries = browser->hists->nr_entries; + + browser->b.nr_entries += he->nr_rows; + browser->nr_callchain_rows += he->nr_rows;return true; }
@@ -287,23 +306,27 @@ static void hist_entry__set_folding(struct hist_entry *he, bool unfold) he->nr_rows =0 ; } -static void hists__set_folding (struct hists *hists,bool unfold) +static void +__hist_browser__set_folding (struct hist_browser *browser,bool unfold) {struct rb_node *nd; +struct hists *hists = browser->hists; - hists->nr_entries =0 ; - -for (nd =rb_first (&hists->entries); nd; nd =rb_next (nd)) { +for (nd =rb_first (&hists->entries); + (nd =hists__filter_entries (nd, hists, browser->min_pcnt)) !=NULL ; + nd =rb_next (nd)) { struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node);hist_entry__set_folding (he, unfold); - hists->nr_entries +=1 + he->nr_rows; + browser->nr_callchain_rows += he->nr_rows; } }static void hist_browser__set_folding (struct hist_browser *browser,bool unfold) { -hists__set_folding (browser->hists, unfold); - browser->b.nr_entries = browser->hists->nr_entries; + browser->nr_callchain_rows =0 ; +__hist_browser__set_folding (browser, unfold); + + browser->b.nr_entries =hist_browser__nr_entries (browser);/* Go to the start, we may be way after valid entries after a collapse */ ui_browser__reset_index (&browser->b); }
@@ -325,10 +348,7 @@ static int hist_browser__run(struct hist_browser *browser, const char *ev_name,int delay_secs = hbt ? hbt->refresh :0 ; browser->b.entries = &browser->hists->entries; -if (hist_browser__has_filter (browser)) - browser->b.nr_entries = browser->nr_non_filtered_entries; -else - browser->b.nr_entries = browser->hists->nr_entries; + browser->b.nr_entries =hist_browser__nr_entries (browser);hist_browser__refresh_dimensions (browser);hists__browser_title (browser->hists, title,sizeof (title), ev_name);
@@ -345,13 +365,10 @@ static int hist_browser__run(struct hist_browser *browser, const char *ev_name,u64 nr_entries; hbt->timer (hbt->arg); -if (hist_browser__has_filter (browser)) { +if (hist_browser__has_filter (browser))hist_browser__update_nr_entries (browser); - nr_entries = browser->nr_non_filtered_entries; - }else { - nr_entries = browser->hists->nr_entries; - } + nr_entries =hist_browser__nr_entries (browser);ui_browser__update_nr_entries (&browser->b, nr_entries); if (browser->hists->stats.nr_lost_warned !=
Signature · 1 line
1.9.2
Re: [PATCH 7/7] perf hists/tui: Count callchain rows separately
Quoted 3 lines · Namhyung Kim
When TUI hist browser expands/collapses callchains it accounted number of callchain nodes into total entries to show. However this code ignores filtering so that it can make the cursor go to out of screen.
SNIP
hi,
I needed following patch, otherwise following test case would segfault
- record with -g
- report - unfold one symbol
- search for nonsense
the reason is that after unfolding the symbol the nr_callchain_rows will get some number, which will cause the hist_browser__nr_entries function return (entries != 0) actually (entries == nr_callchain_rows) even if there's no entry passing the filter
fixing that by unfolding everything after the filter and reseting the nr_callchain_rows number
feel free to merge this with your change if you agree ;-)
thanks,
jirka
---
tools/perf/ui/browsers/hists.c +3 -1
@@ -312,6 +312,8 @@ __hist_browser__set_folding(struct hist_browser *browser, bool unfold)struct rb_node *nd;struct hists *hists = browser->hists; + browser->nr_callchain_rows =0 ; +for (nd =rb_first (&hists->entries); (nd =hists__filter_entries (nd, hists, browser->min_pcnt)) !=NULL ; nd =rb_next (nd)) {
@@ -323,7 +325,6 @@ __hist_browser__set_folding(struct hist_browser *browser, bool unfold)static void hist_browser__set_folding (struct hist_browser *browser,bool unfold) { - browser->nr_callchain_rows =0 ;__hist_browser__set_folding (browser, unfold); browser->b.nr_entries =hist_browser__nr_entries (browser);
@@ -1507,6 +1508,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, delay_secs * 2) == K_ENTER) { hists->symbol_filter_str = *buf ? buf :NULL ;hists__filter_by_symbol (hists); +__hist_browser__set_folding (browser, false);hist_browser__reset (browser); }continue ;
Namhyung Kim
maintainerRe: [PATCH 7/7] perf hists/tui: Count callchain rows separately
2014-04-23 (수), 16:29 +0200, Jiri Olsa:
Quoted 10 lines · Namhyung Kim
Quoted 3 lines
When TUI hist browser expands/collapses callchains it accounted number of callchain nodes into total entries to show. However this code ignores filtering so that it can make the cursor go to out of screen.
SNIP
hi,
I needed following patch, otherwise following test case would segfault
Quoted 8 lines
- record with -g
- report - unfold one symbol
- search for nonsensethe reason is that after unfolding the symbol the
nr_callchain_rowswill get some number, which will cause thehist_browser__nr_entriesfunction return (entries != 0) actually (entries ==nr_callchain_rows) even if there's no entry passing the filter
Argh, right.. Thanks for spotting this. I guess other filters (thread, dso) have same problem.
Quoted 3 lines
fixing that by unfolding everything after the filter and reseting the
nr_callchain_rowsnumber
Hmm.. I think hists__remove_entry_filter() already folds them so how about just setting ->nr_callchain_rows to 0 in hist_browser__reset() instead?
Thanks,
Namhyung
Quoted 37 lines
feel free to merge this with your change if you agree ;-)
thanks,
jirka---
tools/perf/ui/browsers/hists.c +3
-1@@ -312,6 +312,8 @@ __hist_browser__set_folding(struct hist_browser *browser, bool unfold)struct rb_node *nd;struct hists *hists = browser->hists; + browser->nr_callchain_rows =0 ; +for (nd =rb_first (&hists->entries); (nd =hists__filter_entries (nd, hists, browser->min_pcnt)) !=NULL ; nd =rb_next (nd)) {@@ -323,7 +325,6 @@ __hist_browser__set_folding(struct hist_browser *browser, bool unfold)static void hist_browser__set_folding (struct hist_browser *browser,bool unfold) { - browser->nr_callchain_rows =0 ;__hist_browser__set_folding (browser, unfold); browser->b.nr_entries =hist_browser__nr_entries (browser);@@ -1507,6 +1508,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, delay_secs * 2) == K_ENTER) { hists->symbol_filter_str = *buf ? buf :NULL ;hists__filter_by_symbol (hists); +__hist_browser__set_folding (browser, false);hist_browser__reset (browser); }continue ;
Re: [PATCH 7/7] perf hists/tui: Count callchain rows separately
Quoted 24 lines · Namhyung Kim
2014-04-23 (수), 16:29 +0200, Jiri Olsa:
Quoted 10 lines · Namhyung Kim
Quoted 3 lines
When TUI hist browser expands/collapses callchains it accounted number of callchain nodes into total entries to show. However this code ignores filtering so that it can make the cursor go to out of screen.
SNIP
hi,
I needed following patch, otherwise following test case would segfaultQuoted 8 lines
- record with -g
- report - unfold one symbol
- search for nonsensethe reason is that after unfolding the symbol the
nr_callchain_rowswill get some number, which will cause thehist_browser__nr_entriesfunction return (entries != 0) actually (entries ==nr_callchain_rows) even if there's no entry passing the filterArgh, right.. Thanks for spotting this. I guess other filters (thread, dso) have same problem.
Quoted 1 line
Quoted 6 lines
Quoted 2 lines
fixing that by unfolding everything after the filter and reseting the
nr_callchain_rowsnumberHmm.. I think
hists__remove_entry_filter()already folds them so how about just setting ->nr_callchain_rows to 0 inhist_browser__reset()instead?
ok, sounds good
thanks,
jirka