perf tools: Add support to accumulate hist periods (v9)
Namhyung Kim
maintainercover perf tools: Add support to accumulate hist periods (v9)
Hello,
This is a new attempt to implement cumulative hist period report. This work begins from Arun's SORT_INCLUSIVE patch [1] but I completely rewrote it from scratch.
This version depends on my previous percentage patchset [2] and output field patchset[3]. So please test this again although there's not much change in the series itself.
This patchset basically adds period in a sample to every node in the callchain. A hist_entry now has an additional fields to keep the cumulative period if --children option is given on perf report.
I changed the option as a separate --children and added a new "Children" column (and renamed the default "Overhead" column into "Self"). The output will be sorted by children (cumulative) overhead for now. It also adds 'overhead_children' field to -F/--fields option to be selected by user and it'll show you "N/A" if the cumulation is not supported (due to missing callchain).
* changes in v9:
- support output field option
- add Acked-by tags from Jiri
* changes in v8:
- not depends on --percentage patchkit
- fix callchain resolving bug (Jiri)
- convert to sample__resolve_{mem,bstack}
- eliminate 'event' field from hist_entry_iter
* changes in v7:
- add Tested-by tags from Arun
- rebase onto current acme/perf/core
* changes in v6:
- separate struct hist_iter_ops (Jiri)
- check iter->he before calling ->add_entry_cb (Jiri)
- fix locking issue on perf top (Jiri)
* changes in v5:
- support both of --children and --call-graph (Arun)
- refactor hist_entry_iter to share with perf top (Jiri)
- various cleanups and fixes (Jiri)
- add ack's from Jiri
* changes in v4:
- change to --children option (Ingo)
- rebased on new annotation change (Arnaldo)
- support perf top also
- enable --children option by default (Ingo)
* changes in v3:
- change to --cumulate option
- fix a couple of bugs (Jiri, Rodrigo)
- rename some help functions (Arnaldo)
- cache previous hist entries rathen than just symbol and dso
- add some preparatory cleanups
- add report.cumulate config option
Let me show you an example:
$ cat abc.c
#define barrier() asm volatile("" ::: "memory") void a(void)
{
int i;
for (i = 0; i < 1000000; i++)
barrier();
}
void b(void)
{
a();
}
void c(void)
{
b();
}
int main(void)
{
c();
return 0;
}With this simple program I ran perf record and report:
$ perf record -g -e cycles:u ./abc
Case 1.
$ perf report --stdio --no-call-graph --no-children
# Overhead Command Shared Object Symbol
# ........ ....... ................. ..............
#
91.50% abc abc [.] a
8.18% abc ld-2.17.so [.] strlen
0.31% abc [kernel.kallsyms] [k] page_fault
0.01% abc ld-2.17.so [.] _start Case 2. (current default behavior)
$ perf report --stdio --call-graph --no-children
# Overhead Command Shared Object Symbol
# ........ ....... ................. ..............
#
91.50% abc abc [.] a
|
--- a
b
c
main
__libc_start_main 8.18% abc ld-2.17.so [.] strlen
|
--- strlen
_dl_sysdep_start
0.31% abc [kernel.kallsyms] [k] page_fault
|
--- page_fault
_start
0.01% abc ld-2.17.so [.] _start
|
--- _startCase 3.
$ perf report --no-call-graph --children --stdio
# Self Children Command Shared Object Symbol
# ........ ........ ....... ................. .....................
#
0.00% 91.50% abc libc-2.17.so [.] __libc_start_main
0.00% 91.50% abc abc [.] main
0.00% 91.50% abc abc [.] c
0.00% 91.50% abc abc [.] b
91.50% 91.50% abc abc [.] a
0.00% 8.18% abc ld-2.17.so [.] _dl_sysdep_start
8.18% 8.18% abc ld-2.17.so [.] strlen
0.01% 0.33% abc ld-2.17.so [.] _start
0.31% 0.31% abc [kernel.kallsyms] [k] page_fault As you can see __libc_start_main -> main -> c -> b -> a callchain show up in the output.
Finally, it looks like below with both option enabled:
Case 4. (default behavior?)
$ perf report --call-graph --children --stdio
# Self Children Command Shared Object Symbol
# ........ ........ ....... ................. .....................
#
0.00% 91.50% abc libc-2.17.so [.] __libc_start_main
|
--- __libc_start_main
0.00% 91.50% abc abc [.] main
|
--- main
__libc_start_main
0.00% 91.50% abc abc [.] c
|
--- c
main
__libc_start_main
0.00% 91.50% abc abc [.] b
|
--- b
c
main
__libc_start_main
91.50% 91.50% abc abc [.] a
|
--- a
b
c
main
__libc_start_main...
Currently the perf enables both of --call-graph and --children when it finds callchains in the samples. While this is useful for TUI or GTK, I'm not sure for stdio as it'd consume so much lines.
It does not handle all kind of cases like event annotation yet, but I really want to release it and get reviews.
You can also get this series on 'perf/cumulate-v9' branch in my tree at:
git://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git
Any comments are welcome, thanks.
Namhyung
[1] https://lkml.org/lkml/2012/3/31/6
[2] https://lkml.org/lkml/2014/3/10/48
[3] https://lkml.org/lkml/2014/3/19/689
Namhyung Kim (21):
perf tools: Introduce struct hist_entry_iter
perf hists: Add support for accumulated stat of hist entry perf hists: Check if accumulated when adding a hist entry perf hists: Accumulate hist entry stat based on the callchain perf tools: Update cpumode for each cumulative entry perf report: Cache cumulative callchains
perf callchain: Add callchain_cursor_snapshot()
perf tools: Save callchain info for each cumulative entry perf ui/hist: Add support to accumulated hist stat perf ui/browser: Add support to accumulated hist stat perf ui/gtk: Add support to accumulated hist stat perf tools: Apply percent-limit to cumulative percentage perf tools: Add more hpp helper functions
perf report: Add --children option
perf report: Add report.children config option
perf tools: Do not auto-remove Children column if --fields given perf tools: Add callback function to hist_entry_iter perf top: Convert to hist_entry_iter
perf top: Add --children option
perf top: Add top.children config option
perf tools: Enable --children option by default
tools/perf/Documentation/perf-report.txt | 7 +- tools/perf/Documentation/perf-top.txt | 8 +- tools/perf/builtin-annotate.c | 3 +- tools/perf/builtin-diff.c | 2 +- tools/perf/builtin-report.c | 193 +++--------- tools/perf/builtin-top.c | 95 +++--- tools/perf/tests/hists_link.c | 4 +- tools/perf/ui/browsers/hists.c | 68 +++-- tools/perf/ui/gtk/hists.c | 23 +- tools/perf/ui/hist.c | 119 ++++++++ tools/perf/ui/stdio/hist.c | 4 +- tools/perf/util/callchain.c | 45 ++- tools/perf/util/callchain.h | 11 + tools/perf/util/hist.c | 495 ++++++++++++++++++++++++++++++- tools/perf/util/hist.h | 49 ++- tools/perf/util/sort.c | 1 + tools/perf/util/sort.h | 18 +- tools/perf/util/symbol.c | 11 +- tools/perf/util/symbol.h | 1 + 19 files changed, 910 insertions(+), 247 deletions(-)
Signature · 1 line
1.7.11.7
Namhyung Kim
maintainerPATCH 1/21 perf tools: Introduce struct hist_entry_iter
There're some duplicate code when adding hist entries. They are different in that some have branch info or mem info but generally do same thing. So introduce new struct hist_entry_iter and add callbacks to customize each case in general way.
The new perf_evsel__add_entry() function will look like:
iter->prepare_entry();
iter->add_single_entry();
while (iter->next_entry())
iter->add_next_entry();
iter->finish_entry();This will help further work like the cumulative callchain patchset.
--- tools/perf/builtin-report.c | 179 +++---------------------- tools/perf/util/hist.c | 310 ++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/hist.h | 33 +++++ 3 files changed, 360 insertions(+), 162 deletions(-)
tools/perf/builtin-report.c +17 -162
@@ -75,152 +75,6 @@ static int report__config(const char *var, const char *value, void *cb)return perf_default_config (var, value, cb); } -static int report__add_mem_hist_entry (struct report *rep,struct addr_location *al, -struct perf_sample *sample,struct perf_evsel *evsel) -{ -struct symbol *parent =NULL ; -struct hist_entry *he; -struct mem_info *mi, *mx; -uint64_t cost; -int err =sample__resolve_callchain (sample, &parent, evsel, al, rep->max_stack); - -if (err) -return err; - - mi =sample__resolve_mem (sample, al); -if (!mi) -return -ENOMEM ; - -if (rep->hide_unresolved && !al->sym) -return 0 ; - - cost = sample->weight; -if (!cost) - cost =1 ; - -/* -* must pass period=weight in order to get the correct -* sorting from hists__collapse_resort() which is solely -* based on periods. We want sorting be done on nr_events * weight -* and this is indirectly achieved by passing period=weight here -* and the he_stat__add_period() function. -*/ - he =__hists__add_entry (&evsel->hists, al, parent,NULL , mi, - cost, cost,0 ); -if (!he) -return -ENOMEM ; - -if (ui__has_annotation ()) { - err =hist_entry__inc_addr_samples (he, evsel->idx, al->addr); -if (err) - goto out; - - mx = he->mem_info; - err =addr_map_symbol__inc_samples (&mx->daddr, evsel->idx); -if (err) - goto out; - } - - 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; -} - -static int report__add_branch_hist_entry (struct report *rep,struct addr_location *al, -struct perf_sample *sample,struct perf_evsel *evsel) -{ -struct symbol *parent =NULL ; -unsigned i; -struct hist_entry *he; -struct branch_info *bi, *bx; -int err =sample__resolve_callchain (sample, &parent, evsel, al, rep->max_stack); - -if (err) -return err; - - bi =sample__resolve_bstack (sample, al); -if (!bi) -return -ENOMEM ; - -for (i =0 ; i < sample->branch_stack->nr; i++) { -if (rep->hide_unresolved && !(bi[i].from.sym && bi[i].to.sym)) -continue ; - - err = -ENOMEM ; - -/* overwrite the 'al' to branch-to info */ - al->map = bi[i].to.map; - al->sym = bi[i].to.sym; - al->addr = bi[i].to.addr; -/* -* The report shows the percentage of total branches captured -* and not events sampled. Thus we use a pseudo period of 1. -*/ - he =__hists__add_entry (&evsel->hists, al, parent, &bi[i],NULL , -1 ,1 ,0 ); -if (he) { -if (ui__has_annotation ()) { - bx = he->branch_info; - err =addr_map_symbol__inc_samples (&bx->from, - evsel->idx); -if (err) - goto out; - - err =addr_map_symbol__inc_samples (&bx->to, - evsel->idx); -if (err) - goto out; - } - - 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; - } - err =0 ; -out: -free (bi); -return err; -} - -static int report__add_hist_entry (struct report *rep,struct perf_evsel *evsel, -struct addr_location *al,struct perf_sample *sample) -{ -struct symbol *parent =NULL ; -struct hist_entry *he; -int err =sample__resolve_callchain (sample, &parent, evsel, al, rep->max_stack); - -if (err) -return err; - - he =__hists__add_entry (&evsel->hists, al, parent,NULL ,NULL , - sample->period, sample->weight, - sample->transaction); -if (he ==NULL ) -return -ENOMEM ; - - err =hist_entry__append_callchain (he, sample); -if (err) - goto out; - -if (ui__has_annotation ()) - err =hist_entry__inc_addr_samples (he, evsel->idx, al->addr); - - 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; -} - - static int process_sample_event(struct perf_tool *tool, union perf_event *event, struct perf_sample *sample,
@@ -229,6 +83,9 @@ static int process_sample_event(struct perf_tool *tool, { struct report *rep = container_of(tool, struct report, tool);struct addr_location al; +struct hist_entry_iter iter = { + .hide_unresolved = rep->hide_unresolved, + };int ret;if (perf_event__preprocess_sample (event, machine, &al, sample) <0 ) {
@@ -243,22 +100,20 @@ static int process_sample_event(struct perf_tool *tool,if (rep->cpu_list && !test_bit (sample->cpu, rep->cpu_bitmap))return 0 ; -if (sort__mode ==SORT_MODE__BRANCH ) { - ret =report__add_branch_hist_entry (rep, &al, sample, evsel); -if (ret <0 ) -pr_debug ("problem adding lbr entry, skipping event\n" ); - }else if (rep->mem_mode ==1 ) { - ret =report__add_mem_hist_entry (rep, &al, sample, evsel); -if (ret <0 ) -pr_debug ("problem adding mem entry, skipping event\n" ); - }else { -if (al.map !=NULL ) - al.map->dso->hit =1 ; - - ret =report__add_hist_entry (rep, evsel, &al, sample); -if (ret <0 ) -pr_debug ("problem incrementing symbol period, skipping event\n" ); - } +if (sort__mode ==SORT_MODE__BRANCH ) + iter.ops = &hist_iter_branch; +else if (rep->mem_mode) + iter.ops = &hist_iter_mem; +else + iter.ops = &hist_iter_normal; + +if (al.map !=NULL ) + al.map->dso->hit =1 ; + + ret =hist_entry_iter__add (&iter, &al, evsel, sample, rep->max_stack); +if (ret <0 ) +pr_debug ("problem adding hist entry, skipping event\n" ); +return ret; }
tools/perf/util/hist.c +310 -0
322 lines not on this page · raw message
tools/perf/util/hist.h +33 -0
@@ -96,12 +96,45 @@ struct hists {u16 col_len[HISTC_NR_COLS ]; }; +struct hist_entry_iter ; + +struct hist_iter_ops { +int (*prepare_entry)(struct hist_entry_iter *,struct addr_location *); +int (*add_single_entry)(struct hist_entry_iter *,struct addr_location *); +int (*next_entry)(struct hist_entry_iter *,struct addr_location *); +int (*add_next_entry)(struct hist_entry_iter *,struct addr_location *); +int (*finish_entry)(struct hist_entry_iter *,struct addr_location *); +}; + +struct hist_entry_iter { +int total; +int curr; + +bool hide_unresolved; + +struct perf_evsel *evsel; +struct perf_sample *sample; +struct hist_entry *he; +struct symbol *parent; +void *priv; + +const struct hist_iter_ops *ops; +}; + +extern const struct hist_iter_ops hist_iter_normal; +extern const struct hist_iter_ops hist_iter_branch; +extern const struct hist_iter_ops hist_iter_mem; +struct hist_entry *__hists__add_entry (struct hists *hists,struct addr_location *al,struct symbol *parent,struct branch_info *bi,struct mem_info *mi,u64 period,u64 weight,u64 transaction); +int hist_entry_iter__add (struct hist_entry_iter *iter,struct addr_location *al, +struct perf_evsel *evsel,struct perf_sample *sample, +int max_stack_depth); +int64_t hist_entry__cmp (struct hist_entry *left,struct hist_entry *right);int64_t hist_entry__collapse (struct hist_entry *left,struct hist_entry *right);int hist_entry__transaction_len (void );
Signature · 1 line
1.7.11.7
Namhyung Kim
maintainerPATCH 2/21 perf hists: Add support for accumulated stat of hist entry
In reply to Namhyung KimMaintain accumulated stat information in hist_entry->stat_acc if symbol_conf.cumulate_callchain is set. Fields in ->stat_acc have same vaules initially, and will be updated as callchain is processed later.
--- tools/perf/util/hist.c | 28 ++++++++++++++++++++++++++-- tools/perf/util/sort.h | 1 + tools/perf/util/symbol.h | 1 + 3 files changed, 28 insertions(+), 2 deletions(-)
tools/perf/util/hist.c +26 -2
@@ -231,6 +231,8 @@ static bool hists__decay_entry(struct hists *hists, struct hist_entry *he)return true;he_stat__decay (&he->stat); +if (symbol_conf.cumulate_callchain) +he_stat__decay (he->stat_acc);if (!he->filtered) hists->stats.total_period -= prev_period - he->stat.period;
@@ -272,12 +274,26 @@ void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel)static struct hist_entry *hist_entry__new (struct hist_entry *template) { -size_t callchain_size = symbol_conf.use_callchain ?sizeof (struct callchain_root ) :0 ; -struct hist_entry *he =zalloc (sizeof (*he) + callchain_size); +size_t callchain_size =0 ; +struct hist_entry *he; + +if (symbol_conf.use_callchain || symbol_conf.cumulate_callchain) + callchain_size =sizeof (struct callchain_root ); + + he =zalloc (sizeof (*he) + callchain_size);if (he !=NULL ) { *he = *template; +if (symbol_conf.cumulate_callchain) { + he->stat_acc =malloc (sizeof (he->stat)); +if (he->stat_acc ==NULL ) { +free (he); +return NULL ; + } +memcpy (he->stat_acc, &he->stat,sizeof (he->stat)); + } +if (he->ms.map) he->ms.map->referenced = true;
@@ -289,6 +305,7 @@ static struct hist_entry *hist_entry__new(struct hist_entry *template)*/ he->branch_info =malloc (sizeof (*he->branch_info));if (he->branch_info ==NULL ) { +free (he->stat_acc);free (he);return NULL ; }
@@ -363,6 +380,8 @@ static struct hist_entry *add_hist_entry(struct hists *hists,if (!cmp) {he_stat__add_period (&he->stat, period, weight); +if (symbol_conf.cumulate_callchain) +he_stat__add_period (he->stat_acc, period, weight);/* * This mem info was allocated from sample__resolve_mem
@@ -399,6 +418,8 @@ static struct hist_entry *add_hist_entry(struct hists *hists,rb_insert_color (&he->rb_node_in, hists->entries_in); out:he_stat__add_cpumode_period (&he->stat, al->cpumode, period); +if (symbol_conf.cumulate_callchain) +he_stat__add_cpumode_period (he->stat_acc, al->cpumode, period);return he; }
@@ -784,6 +805,7 @@ void hist_entry__free(struct hist_entry *he) {zfree (&he->branch_info);zfree (&he->mem_info); +zfree (&he->stat_acc);free_srcline (he->srcline);free (he); }
@@ -809,6 +831,8 @@ static bool hists__collapse_insert_entry(struct hists *hists __maybe_unused,if (!cmp) {he_stat__add_stat (&iter->stat, &he->stat); +if (symbol_conf.cumulate_callchain) +he_stat__add_stat (iter->stat_acc, he->stat_acc);if (symbol_conf.use_callchain) {callchain_cursor_reset (&callchain_cursor);
tools/perf/util/sort.h +1 -0
@@ -82,6 +82,7 @@ struct hist_entry {struct list_head head; } pairs;struct he_stat stat; +struct he_stat *stat_acc;struct map_symbol ms;struct thread *thread;struct comm *comm;
tools/perf/util/symbol.h +1 -0
@@ -108,6 +108,7 @@ struct symbol_conf { show_nr_samples, show_total_period, use_callchain, + cumulate_callchain, exclude_other, show_cpu_utilization, initialized,
Signature · 1 line
1.7.11.7
Namhyung Kim
maintainerPATCH 3/21 perf hists: Check if accumulated when adding a hist entry
In reply to Namhyung KimTo support callchain accumulation, @entry should be recognized if it's accumulated or not when add_hist_entry() called. The period of an accumulated entry should be added to ->stat_acc but not ->stat. Add @sample_self arg for that.
--- tools/perf/builtin-annotate.c | 3 ++- tools/perf/builtin-diff.c | 2 +- tools/perf/builtin-top.c | 2 +- tools/perf/tests/hists_link.c | 4 ++-- tools/perf/util/hist.c | 29 ++++++++++++++++++----------- tools/perf/util/hist.h | 3 ++- 6 files changed, 26 insertions(+), 17 deletions(-)
tools/perf/builtin-annotate.c +2 -1
@@ -65,7 +65,8 @@ static int perf_evsel__add_sample(struct perf_evsel *evsel,return 0 ; } - he =__hists__add_entry (&evsel->hists, al,NULL ,NULL ,NULL ,1 ,1 ,0 ); + he =__hists__add_entry (&evsel->hists, al,NULL ,NULL ,NULL ,1 ,1 ,0 , + true);if (he ==NULL )return -ENOMEM ;
tools/perf/builtin-diff.c +1 -1
@@ -316,7 +316,7 @@ static int hists__add_entry(struct hists *hists, u64 weight, u64 transaction) { if (__hists__add_entry(hists, al, NULL, NULL, NULL, period, weight, - transaction) != NULL) + transaction, true) != NULL) return 0;return -ENOMEM ; }
tools/perf/builtin-top.c +1 -1
@@ -247,7 +247,7 @@ static struct hist_entry *perf_evsel__add_hist_entry(struct perf_evsel *evsel,pthread_mutex_lock (&evsel->hists.lock); he =__hists__add_entry (&evsel->hists, al,NULL ,NULL ,NULL , sample->period, sample->weight, - sample->transaction); + sample->transaction, true);pthread_mutex_unlock (&evsel->hists.lock);if (he ==NULL )return NULL ;
tools/perf/tests/hists_link.c +2 -2
@@ -224,7 +224,7 @@ static int add_hist_entries(struct perf_evlist *evlist, struct machine *machine) goto out; he =__hists__add_entry (&evsel->hists, &al,NULL , -NULL ,NULL ,1 ,1 ,0 ); +NULL ,NULL ,1 ,1 ,0 , true);if (he ==NULL ) goto out;
@@ -247,7 +247,7 @@ static int add_hist_entries(struct perf_evlist *evlist, struct machine *machine) goto out; he =__hists__add_entry (&evsel->hists, &al,NULL , -NULL ,NULL ,1 ,1 ,0 ); +NULL ,NULL ,1 ,1 ,0 , true);if (he ==NULL ) goto out;
tools/perf/util/hist.c +18 -11
@@ -272,7 +272,8 @@ void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel)* histogram, sorted on item, collects periods */ -static struct hist_entry *hist_entry__new (struct hist_entry *template) +static struct hist_entry *hist_entry__new (struct hist_entry *template, +bool sample_self) {size_t callchain_size =0 ;struct hist_entry *he;
@@ -292,6 +293,8 @@ static struct hist_entry *hist_entry__new(struct hist_entry *template)return NULL ; }memcpy (he->stat_acc, &he->stat,sizeof (he->stat)); +if (!sample_self) +memset (&he->stat,0 ,sizeof (he->stat)); }if (he->ms.map)
@@ -355,7 +358,8 @@ static u8 symbol__parent_filter(const struct symbol *parent)static struct hist_entry *add_hist_entry (struct hists *hists,struct hist_entry *entry, -struct addr_location *al) +struct addr_location *al, +bool sample_self) {struct rb_node **p;struct rb_node *parent =NULL ;
@@ -379,7 +383,8 @@ static struct hist_entry *add_hist_entry(struct hists *hists, cmp =hist_entry__cmp (he, entry);if (!cmp) { -he_stat__add_period (&he->stat, period, weight); +if (sample_self) +he_stat__add_period (&he->stat, period, weight);if (symbol_conf.cumulate_callchain)he_stat__add_period (he->stat_acc, period, weight);
@@ -409,7 +414,7 @@ static struct hist_entry *add_hist_entry(struct hists *hists, p = &(*p)->rb_right; } - he =hist_entry__new (entry); + he =hist_entry__new (entry, sample_self);if (!he)return NULL ;
@@ -417,7 +422,8 @@ static struct hist_entry *add_hist_entry(struct hists *hists,rb_link_node (&he->rb_node_in, parent, p);rb_insert_color (&he->rb_node_in, hists->entries_in); out: -he_stat__add_cpumode_period (&he->stat, al->cpumode, period); +if (sample_self) +he_stat__add_cpumode_period (&he->stat, al->cpumode, period);if (symbol_conf.cumulate_callchain)he_stat__add_cpumode_period (he->stat_acc, al->cpumode, period);return he;
@@ -428,7 +434,8 @@ struct hist_entry *__hists__add_entry(struct hists *hists, struct symbol *sym_parent, struct branch_info *bi, struct mem_info *mi, - u64 period, u64 weight, u64 transaction) + u64 period, u64 weight, u64 transaction, + bool sample_self) { struct hist_entry entry = { .thread = al->thread,
@@ -453,7 +460,7 @@ struct hist_entry *__hists__add_entry(struct hists *hists, .transaction = transaction, }; -return add_hist_entry (hists, &entry, al); +return add_hist_entry (hists, &entry, al, sample_self); } static int
@@ -506,7 +513,7 @@ iter_add_single_mem_entry(struct hist_entry_iter *iter, struct addr_location *al* and the he_stat__add_period() function. */ he =__hists__add_entry (&iter->evsel->hists, al, iter->parent,NULL , mi, - cost, cost,0 ); + cost, cost,0 , true);if (!he)return -ENOMEM ;
@@ -621,7 +628,7 @@ iter_add_next_branch_entry(struct hist_entry_iter *iter, struct addr_location *a* and not events sampled. Thus we use a pseudo period of 1. */ he =__hists__add_entry (&evsel->hists, al, iter->parent, &bi[i],NULL , -1 ,1 ,0 ); +1 ,1 ,0 , true);if (he ==NULL )return -ENOMEM ;
@@ -671,7 +678,7 @@ iter_add_single_normal_entry(struct hist_entry_iter *iter, struct addr_location he =__hists__add_entry (&evsel->hists, al, iter->parent,NULL ,NULL , sample->period, sample->weight, - sample->transaction); + sample->transaction, true);if (he ==NULL )return -ENOMEM ;
@@ -1140,7 +1147,7 @@ static struct hist_entry *hists__add_dummy_entry(struct hists *hists, p = &(*p)->rb_right; } - he =hist_entry__new (pair); + he =hist_entry__new (pair, true);if (he) {memset (&he->stat,0 ,sizeof (he->stat)); he->hists = hists;
tools/perf/util/hist.h +2 -1
@@ -130,7 +130,8 @@ struct hist_entry *__hists__add_entry(struct hists *hists,struct symbol *parent, struct branch_info *bi, struct mem_info *mi, u64 period, - u64 weight, u64 transaction); + u64 weight, u64 transaction, + bool sample_self);int hist_entry_iter__add (struct hist_entry_iter *iter,struct addr_location *al,struct perf_evsel *evsel,struct perf_sample *sample,int max_stack_depth);
Signature · 1 line
1.7.11.7
Namhyung Kim
maintainerPATCH 4/21 perf hists: Accumulate hist entry stat based on the callchain
In reply to Namhyung KimCall __hists__add_entry() for each callchain node to get an accumulated stat for an entry. Introduce new cumulative_iter ops to process them properly.
--- tools/perf/builtin-report.c | 2 ++ tools/perf/util/callchain.c | 3 +- tools/perf/util/hist.c | 87 +++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/hist.h | 1 + 4 files changed, 92 insertions(+), 1 deletion(-)
tools/perf/builtin-report.c +2 -0
@@ -104,6 +104,8 @@ static int process_sample_event(struct perf_tool *tool, iter.ops = &hist_iter_branch; else if (rep->mem_mode) iter.ops = &hist_iter_mem; + else if (symbol_conf.cumulate_callchain) + iter.ops = &hist_iter_cumulative; else iter.ops = &hist_iter_normal;
tools/perf/util/callchain.c +2 -1
@@ -538,7 +538,8 @@ int sample__resolve_callchain(struct perf_sample *sample, struct symbol **parentif (sample->callchain ==NULL )return 0 ; -if (symbol_conf.use_callchain || sort__has_parent) { +if (symbol_conf.use_callchain || symbol_conf.cumulate_callchain || + sort__has_parent) {return machine__resolve_callchain (al->machine, evsel, al->thread, sample, parent, al, max_stack); }
tools/perf/util/hist.c +87 -0
99 lines not on this page · raw message
tools/perf/util/hist.h +1 -0
@@ -124,6 +124,7 @@ struct hist_entry_iter {extern const struct hist_iter_ops hist_iter_normal;extern const struct hist_iter_ops hist_iter_branch;extern const struct hist_iter_ops hist_iter_mem; +extern const struct hist_iter_ops hist_iter_cumulative; struct hist_entry *__hists__add_entry(struct hists *hists, struct addr_location *al,
Signature · 1 line
1.7.11.7
Namhyung Kim
maintainerPATCH 5/21 perf tools: Update cpumode for each cumulative entry
In reply to Namhyung KimThe cpumode and level in struct addr_localtion was set for a sample and but updated as cumulative callchains were added. This led to have non-matching symbol and cpumode in the output.
Update it accordingly based on the fact whether the map is a part of the kernel or not. This is a reverse of what thread__find_addr_map() does.
--- tools/perf/util/callchain.c | 42 ++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/callchain.h | 2 ++ tools/perf/util/hist.c | 13 ++----------- 3 files changed, 46 insertions(+), 11 deletions(-)
tools/perf/util/callchain.c +42 -0
@@ -552,3 +552,45 @@ int hist_entry__append_callchain(struct hist_entry *he, struct perf_sample *sampreturn 0 ;return callchain_append (he->callchain, &callchain_cursor, sample->period); } + +int fill_callchain_info (struct addr_location *al,struct callchain_cursor_node *node, +bool hide_unresolved) +{ + al->map = node->map; + al->sym = node->sym; +if (node->map) + al->addr = node->map->map_ip (node->map, node->ip); +else + al->addr = node->ip; + +if (al->sym ==NULL ) { +if (hide_unresolved) +return 0 ; +if (al->map ==NULL ) + goto out; + } + +if (al->map->groups == &al->machine->kmaps) { +if (machine__is_host (al->machine)) { + al->cpumode =PERF_RECORD_MISC_KERNEL ; + al->level ='k' ; + }else { + al->cpumode =PERF_RECORD_MISC_GUEST_KERNEL ; + al->level ='g' ; + } + }else { +if (machine__is_host (al->machine)) { + al->cpumode =PERF_RECORD_MISC_USER ; + al->level ='.' ; + }else if (perf_guest) { + al->cpumode =PERF_RECORD_MISC_GUEST_USER ; + al->level ='u' ; + }else { + al->cpumode =PERF_RECORD_MISC_HYPERVISOR ; + al->level ='H' ; + } + } + +out: +return 1 ; +}
tools/perf/util/callchain.h +2 -0
@@ -155,6 +155,8 @@ int sample__resolve_callchain(struct perf_sample *sample, struct symbol **parent struct perf_evsel *evsel, struct addr_location *al, int max_stack);int hist_entry__append_callchain (struct hist_entry *he,struct perf_sample *sample); +int fill_callchain_info (struct addr_location *al,struct callchain_cursor_node *node, +bool hide_unresolved);extern const char record_callchain_help[];#endif /* __PERF_CALLCHAIN_H */
tools/perf/util/hist.c +2 -11
@@ -747,18 +747,9 @@ iter_next_cumulative_entry(struct hist_entry_iter *iter,if (node ==NULL )return 0 ; - al->map = node->map; - al->sym = node->sym; -if (node->map) - al->addr = node->map->map_ip (node->map, node->ip); -else - al->addr = node->ip; - -if (iter->hide_unresolved && al->sym ==NULL ) -return 0 ; -callchain_cursor_advance (&callchain_cursor); -return 1 ; + +return fill_callchain_info (al, node, iter->hide_unresolved); } static int
Signature · 1 line
1.7.11.7
Namhyung Kim
maintainerPATCH 6/21 perf report: Cache cumulative callchains
In reply to Namhyung KimIt is possble that a callchain has cycles or recursive calls. In that case it'll end up having entries more than 100% overhead in the output. In order to prevent such entries, cache each callchain node and skip if same entry already cumulated.
--- tools/perf/util/hist.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)
tools/perf/util/hist.c +43 -0
@@ -716,7 +716,22 @@ static int iter_prepare_cumulative_entry(struct hist_entry_iter *iter __maybe_unused, struct addr_location *al __maybe_unused) { + struct hist_entry **he_cache; +callchain_cursor_commit (&callchain_cursor); + +/* +* This is for detecting cycles or recursions so that they're +* cumulated only one time to prevent entries more than 100% +* overhead. +*/ + he_cache =malloc (sizeof (*he_cache) * (PERF_MAX_STACK_DEPTH +1 )); +if (he_cache ==NULL ) +return -ENOMEM ; + + iter->priv = he_cache; + iter->curr =0 ; +return 0 ; }
@@ -726,6 +741,7 @@ iter_add_single_cumulative_entry(struct hist_entry_iter *iter, {struct perf_evsel *evsel = iter->evsel;struct perf_sample *sample = iter->sample; +struct hist_entry **he_cache = iter->priv;struct hist_entry *he; he = __hists__add_entry(&evsel->hists, al, iter->parent, NULL, NULL,
@@ -734,6 +750,8 @@ iter_add_single_cumulative_entry(struct hist_entry_iter *iter,if (he ==NULL )return -ENOMEM ; + he_cache[iter->curr++] = he; +return hist_entry__inc_addr_samples (he, evsel->idx, al->addr); }
@@ -758,7 +776,29 @@ iter_add_next_cumulative_entry(struct hist_entry_iter *iter, {struct perf_evsel *evsel = iter->evsel;struct perf_sample *sample = iter->sample; +struct hist_entry **he_cache = iter->priv;struct hist_entry *he; +struct hist_entry he_tmp = { + .cpu = al->cpu, + .thread = al->thread, + .comm =thread__comm (al->thread), + .ip = al->addr, + .ms = { + .map = al->map, + .sym = al->sym, + }, + .parent = iter->parent, + }; +int i; + +/* +* Check if there's duplicate entries in the callchain. +* It's possible that it has cycles or recursive calls. +*/ +for (i =0 ; i < iter->curr; i++) { +if (hist_entry__cmp (he_cache[i], &he_tmp) ==0 ) +return 0 ; + } he = __hists__add_entry(&evsel->hists, al, iter->parent, NULL, NULL, sample->period, sample->weight,
@@ -766,6 +806,8 @@ iter_add_next_cumulative_entry(struct hist_entry_iter *iter,if (he ==NULL )return -ENOMEM ; + he_cache[iter->curr++] = he; +return hist_entry__inc_addr_samples (he, evsel->idx, al->addr); }
@@ -779,6 +821,7 @@ iter_finish_cumulative_entry(struct hist_entry_iter *iter, evsel->hists.stats.total_period += sample->period;hists__inc_nr_events (&evsel->hists,PERF_RECORD_SAMPLE ); +zfree (&iter->priv);return 0 ; }
Signature · 1 line
1.7.11.7
Namhyung Kim
maintainerPATCH 7/21 perf callchain: Add callchain_cursor_snapshot()
In reply to Namhyung KimThe callchain_cursor_snapshot() is for saving current status of the callchain. It'll be used to accumulate callchain information for each node.
--- tools/perf/util/callchain.h | 9 +++++++++ 1 file changed, 9 insertions(+)
tools/perf/util/callchain.h +9 -0
@@ -159,4 +159,13 @@ int fill_callchain_info(struct addr_location *al, struct callchain_cursor_node * bool hide_unresolved);extern const char record_callchain_help[]; + +static inline void callchain_cursor_snapshot (struct callchain_cursor *dest, +struct callchain_cursor *src) +{ + *dest = *src; + + dest->first = src->curr; + dest->nr -= src->pos; +}#endif /* __PERF_CALLCHAIN_H */
Signature · 1 line
1.7.11.7
Namhyung Kim
maintainerPATCH 8/21 perf tools: Save callchain info for each cumulative entry
In reply to Namhyung KimWhen accumulating callchain entry, also save current snapshot of the chain so that it can show the rest of the chain.
--- tools/perf/util/hist.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
tools/perf/util/hist.c +15 -2
@@ -752,6 +752,14 @@ iter_add_single_cumulative_entry(struct hist_entry_iter *iter, he_cache[iter->curr++] = he; +callchain_append (he->callchain, &callchain_cursor, sample->period); + +/* +* We need to re-initialize the cursor since callchain_append() +* advanced the cursor to the end. +*/ +callchain_cursor_commit (&callchain_cursor); +return hist_entry__inc_addr_samples (he, evsel->idx, al->addr); }
@@ -765,8 +773,6 @@ iter_next_cumulative_entry(struct hist_entry_iter *iter,if (node ==NULL )return 0 ; -callchain_cursor_advance (&callchain_cursor); -return fill_callchain_info (al, node, iter->hide_unresolved); }
@@ -790,6 +796,11 @@ iter_add_next_cumulative_entry(struct hist_entry_iter *iter, .parent = iter->parent, };int i; +struct callchain_cursor cursor; + +callchain_cursor_snapshot (&cursor, &callchain_cursor); + +callchain_cursor_advance (&callchain_cursor);/* * Check if there's duplicate entries in the callchain.
@@ -808,6 +819,8 @@ iter_add_next_cumulative_entry(struct hist_entry_iter *iter, he_cache[iter->curr++] = he; +callchain_append (he->callchain, &cursor, sample->period); +return hist_entry__inc_addr_samples (he, evsel->idx, al->addr); }
Signature · 1 line
1.7.11.7
Namhyung Kim
maintainerPATCH 9/21 perf ui/hist: Add support to accumulated hist stat
In reply to Namhyung KimPrint accumulated stat of a hist entry if requested.
To do that, add new HPP_PERCENT_ACC_FNS macro and generate a perf_hpp_fmt using it. The __hpp__sort_acc() function sorts entries by accumulated period value. When accumulated periods of two entries are same (i.e. single path callchain) put the caller above since accumulation tends to put callers on higher position for obvious reason.
Also add "overhead_children" output field to be selected by user.
--- tools/perf/ui/hist.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/hist.h | 4 ++ tools/perf/util/sort.c | 1 + 3 files changed, 104 insertions(+)
tools/perf/ui/hist.c +99 -0
@@ -104,6 +104,18 @@ int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,return ret; } +int __hpp__fmt_acc (struct perf_hpp *hpp,struct hist_entry *he, +hpp_field_fn get_field,const char *fmt, +hpp_snprint_fn print_fn,bool fmt_percent) +{ +if (!symbol_conf.cumulate_callchain) { +return snprintf (hpp->buf, hpp->size,"%*s" , + fmt_percent ?8 :12 ,"N/A" ); + } + +return __hpp__fmt (hpp, he, get_field, fmt, print_fn, fmt_percent); +} +static int field_cmp (u64 field_a,u64 field_b) {if (field_a > field_b)
@@ -160,6 +172,24 @@ out:return ret; } +static int __hpp__sort_acc (struct hist_entry *a,struct hist_entry *b, +hpp_field_fn get_field) +{ +s64 ret =0 ; + +if (symbol_conf.cumulate_callchain) { +/* +* Put caller above callee when they have equal period. +*/ + ret =field_cmp (get_field (a),get_field (b)); +if (ret) +return ret; + + ret = b->callchain->max_depth - a->callchain->max_depth; + } +return ret; +} +#define __HPP_HEADER_FN (_type, _str, _min_width, _unit_width) \ static int hpp__header_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \ struct perf_hpp *hpp, \
@@ -242,6 +272,34 @@ static int64_t hpp__sort_##_type(struct hist_entry *a, struct hist_entry *b) \ return __hpp__sort(a, b, he_get_##_field); \ } +#define __HPP_COLOR_ACC_PERCENT_FN (_type, _field) \ +static u64 he_get_acc_##_field(struct hist_entry *he) \ +{ \ + return he->stat_acc->_field; \ +} \ + \ +static int hpp__color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \ + struct perf_hpp *hpp, struct hist_entry *he) \ +{ \ + return __hpp__fmt_acc(hpp, he, he_get_acc_##_field, " %6.2f%%", \ + hpp_color_scnprintf, true); \ +} + +#define __HPP_ENTRY_ACC_PERCENT_FN (_type, _field) \ +static int hpp__entry_##_type(struct perf_hpp_fmt *_fmt __maybe_unused, \ + struct perf_hpp *hpp, struct hist_entry *he) \ +{ \ + const char *fmt = symbol_conf.field_sep ? " %.2f" : " %6.2f%%"; \ + return __hpp__fmt_acc(hpp, he, he_get_acc_##_field, fmt, \ + hpp_entry_scnprintf, true); \ +} + +#define __HPP_SORT_ACC_FN (_type, _field) \ +static int64_t hpp__sort_##_type(struct hist_entry *a, struct hist_entry *b) \ +{ \ + return __hpp__sort_acc(a, b, he_get_acc_##_field); \ +} +#define __HPP_ENTRY_RAW_FN (_type, _field) \ static u64 he_get_raw_##_field(struct hist_entry *he) \ { \
@@ -270,18 +328,27 @@ __HPP_COLOR_PERCENT_FN(_type, _field) \ __HPP_ENTRY_PERCENT_FN(_type, _field) \ __HPP_SORT_FN(_type, _field) +#define HPP_PERCENT_ACC_FNS (_type, _str, _field, _min_width, _unit_width)\ +__HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \ +__HPP_WIDTH_FN(_type, _min_width, _unit_width) \ +__HPP_COLOR_ACC_PERCENT_FN(_type, _field) \ +__HPP_ENTRY_ACC_PERCENT_FN(_type, _field) \ +__HPP_SORT_ACC_FN(_type, _field) +#define HPP_RAW_FNS (_type, _str, _field, _min_width, _unit_width) \ __HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \ __HPP_WIDTH_FN(_type, _min_width, _unit_width) \ __HPP_ENTRY_RAW_FN(_type, _field) \ __HPP_SORT_RAW_FN(_type, _field) +__HPP_HEADER_FN(overhead_self, "Self", 8, 8) HPP_PERCENT_FNS(overhead, "Overhead", period, 8, 8) HPP_PERCENT_FNS(overhead_sys, "sys", period_sys, 8, 8) HPP_PERCENT_FNS(overhead_us, "usr", period_us, 8, 8) HPP_PERCENT_FNS(overhead_guest_sys, "guest sys", period_guest_sys, 9, 8) HPP_PERCENT_FNS(overhead_guest_us, "guest usr", period_guest_us, 9, 8) +HPP_PERCENT_ACC_FNS(overhead_acc, "Children", period, 8, 8) HPP_RAW_FNS(samples, "Samples", nr_events, 12, 12)HPP_RAW_FNS (period,"Period" , period,12 ,12 )
@@ -303,6 +370,17 @@ static int64_t hpp__nop_cmp(struct hist_entry *a __maybe_unused, .sort = hpp__sort_ ## _name, \ } +#define HPP__COLOR_ACC_PRINT_FNS (_name) \ + { \ + .header = hpp__header_ ## _name, \ + .width = hpp__width_ ## _name, \ + .color = hpp__color_ ## _name, \ + .entry = hpp__entry_ ## _name, \ + .cmp = hpp__nop_cmp, \ + .collapse = hpp__nop_cmp, \ + .sort = hpp__sort_ ## _name, \ + } +#define HPP__PRINT_FNS (_name) \ { \ .header = hpp__header_ ## _name, \
@@ -319,6 +397,7 @@ struct perf_hpp_fmt perf_hpp__format[] = {HPP__COLOR_PRINT_FNS (overhead_us),HPP__COLOR_PRINT_FNS (overhead_guest_sys),HPP__COLOR_PRINT_FNS (overhead_guest_us), +HPP__COLOR_ACC_PRINT_FNS (overhead_acc),HPP__PRINT_FNS (samples), HPP__PRINT_FNS(period) };
@@ -328,16 +407,23 @@ LIST_HEAD(perf_hpp__sort_list);#undef HPP__COLOR_PRINT_FNS +#undef HPP__COLOR_ACC_PRINT_FNS#undef HPP__PRINT_FNS#undef HPP_PERCENT_FNS +#undef HPP_PERCENT_ACC_FNS#undef HPP_RAW_FNS#undef __HPP_HEADER_FN#undef __HPP_WIDTH_FN#undef __HPP_COLOR_PERCENT_FN#undef __HPP_ENTRY_PERCENT_FN +#undef __HPP_COLOR_ACC_PERCENT_FN +#undef __HPP_ENTRY_ACC_PERCENT_FN#undef __HPP_ENTRY_RAW_FN +#undef __HPP_SORT_FN +#undef __HPP_SORT_ACC_FN +#undef __HPP_SORT_RAW_FNvoid perf_hpp__init (void )
@@ -361,6 +447,13 @@ void perf_hpp__init(void)if (field_order)return ; +if (symbol_conf.cumulate_callchain) { +perf_hpp__column_enable (PERF_HPP__OVERHEAD_ACC ); + + perf_hpp__format[PERF_HPP__OVERHEAD ].header = + hpp__header_overhead_self; + } +perf_hpp__column_enable (PERF_HPP__OVERHEAD );if (symbol_conf.show_cpu_utilization) {
@@ -383,6 +476,12 @@ void perf_hpp__init(void) list = &perf_hpp__format[PERF_HPP__OVERHEAD ].sort_list;if (list_empty (list))list_add (list, &perf_hpp__sort_list); + +if (symbol_conf.cumulate_callchain) { + list = &perf_hpp__format[PERF_HPP__OVERHEAD_ACC ].sort_list; +if (list_empty (list)) +list_add (list, &perf_hpp__sort_list); + } }void perf_hpp__column_register (struct perf_hpp_fmt *format)
tools/perf/util/hist.h +4 -0
@@ -214,6 +214,7 @@ enum {PERF_HPP__OVERHEAD_US ,PERF_HPP__OVERHEAD_GUEST_SYS ,PERF_HPP__OVERHEAD_GUEST_US , +PERF_HPP__OVERHEAD_ACC ,PERF_HPP__SAMPLES , PERF_HPP__PERIOD,
@@ -239,6 +240,9 @@ typedef int (*hpp_snprint_fn)(struct perf_hpp *hpp, const char *fmt, ...);int __hpp__fmt (struct perf_hpp *hpp,struct hist_entry *he,hpp_field_fn get_field,const char *fmt,hpp_snprint_fn print_fn,bool fmt_percent); +int __hpp__fmt_acc (struct perf_hpp *hpp,struct hist_entry *he, +hpp_field_fn get_field,const char *fmt, +hpp_snprint_fn print_fn,bool fmt_percent);static inline void advance_hpp (struct perf_hpp *hpp,int inc) {
tools/perf/util/sort.c +1 -0
@@ -1063,6 +1063,7 @@ static struct hpp_dimension hpp_sort_dimensions[] = {DIM (PERF_HPP__OVERHEAD_US ,"overhead_us" ),DIM (PERF_HPP__OVERHEAD_GUEST_SYS ,"overhead_guest_sys" ),DIM (PERF_HPP__OVERHEAD_GUEST_US ,"overhead_guest_us" ), +DIM (PERF_HPP__OVERHEAD_ACC ,"overhead_children" ),DIM (PERF_HPP__SAMPLES ,"sample" ), DIM(PERF_HPP__PERIOD, "period"), };
Signature · 1 line
1.7.11.7
Namhyung Kim
maintainerPATCH 10/21 perf ui/browser: Add support to accumulated hist stat
In reply to Namhyung KimPrint accumulated stat of a hist entry if requested.
--- tools/perf/ui/browsers/hists.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-)
tools/perf/ui/browsers/hists.c +25 -1
@@ -603,7 +603,6 @@ static int __hpp__slsmg_color_printf(struct perf_hpp *hpp, const char *fmt, ...) ret =scnprintf (hpp->buf, hpp->size, fmt, percent);slsmg_printf ("%s" , hpp->buf); -advance_hpp (hpp, ret);return ret; }
@@ -622,13 +621,36 @@ hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused,\ __hpp__slsmg_color_printf, true); \ } +#define __HPP_COLOR_ACC_PERCENT_FN (_type, _field) \ +static u64 __hpp_get_acc_##_field(struct hist_entry *he) \ +{ \ + return he->stat_acc->_field; \ +} \ + \ +static int \ +hist_browser__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused,\ + struct perf_hpp *hpp, \ + struct hist_entry *he) \ +{ \ + if (!symbol_conf.cumulate_callchain) { \ + int ret = scnprintf(hpp->buf, hpp->size, "%8s", "N/A"); \ + slsmg_printf("%s", hpp->buf); \ + \ + return ret; \ + } \ + return __hpp__fmt(hpp, he, __hpp_get_acc_##_field, " %6.2f%%", \ + __hpp__slsmg_color_printf, true); \ +} + __HPP_COLOR_PERCENT_FN(overhead, period) __HPP_COLOR_PERCENT_FN(overhead_sys, period_sys) __HPP_COLOR_PERCENT_FN(overhead_us, period_us) __HPP_COLOR_PERCENT_FN(overhead_guest_sys, period_guest_sys) __HPP_COLOR_PERCENT_FN(overhead_guest_us, period_guest_us) +__HPP_COLOR_ACC_PERCENT_FN(overhead_acc, period)#undef __HPP_COLOR_PERCENT_FN +#undef __HPP_COLOR_ACC_PERCENT_FNvoid hist_browser__init_hpp (void ) {
@@ -644,6 +666,8 @@ void hist_browser__init_hpp(void) hist_browser__hpp_color_overhead_guest_sys; perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_US ].color = hist_browser__hpp_color_overhead_guest_us; + perf_hpp__format[PERF_HPP__OVERHEAD_ACC ].color = + hist_browser__hpp_color_overhead_acc; } static int hist_browser__show_entry(struct hist_browser *browser,
Signature · 1 line
1.7.11.7
Namhyung Kim
maintainerPATCH 11/21 perf ui/gtk: Add support to accumulated hist stat
In reply to Namhyung KimPrint accumulated stat of a hist entry if requested.
--- tools/perf/ui/gtk/hists.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
tools/perf/ui/gtk/hists.c +17 -0
@@ -47,11 +47,26 @@ static int perf_gtk__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, __percent_color_snprintf, true); \ } +#define __HPP_COLOR_ACC_PERCENT_FN (_type, _field) \ +static u64 he_get_acc_##_field(struct hist_entry *he) \ +{ \ + return he->stat_acc->_field; \ +} \ + \ +static int perf_gtk__hpp_color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \ + struct perf_hpp *hpp, \ + struct hist_entry *he) \ +{ \ + return __hpp__fmt_acc(hpp, he, he_get_acc_##_field, " %6.2f%%", \ + __percent_color_snprintf, true); \ +} + __HPP_COLOR_PERCENT_FN(overhead, period) __HPP_COLOR_PERCENT_FN(overhead_sys, period_sys) __HPP_COLOR_PERCENT_FN(overhead_us, period_us) __HPP_COLOR_PERCENT_FN(overhead_guest_sys, period_guest_sys) __HPP_COLOR_PERCENT_FN(overhead_guest_us, period_guest_us) +__HPP_COLOR_ACC_PERCENT_FN(overhead_acc, period)#undef __HPP_COLOR_PERCENT_FN
@@ -70,6 +85,8 @@ void perf_gtk__init_hpp(void) perf_gtk__hpp_color_overhead_guest_sys; perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_US ].color = perf_gtk__hpp_color_overhead_guest_us; + perf_hpp__format[PERF_HPP__OVERHEAD_ACC ].color = + perf_gtk__hpp_color_overhead_acc; } static void callchain_list__sym_name(struct callchain_list *cl,
Signature · 1 line
1.7.11.7
Namhyung Kim
maintainerPATCH 12/21 perf tools: Apply percent-limit to cumulative percentage
In reply to Namhyung KimIf -g cumulative option is given, it needs to show entries which don't have self overhead. So apply percent-limit to accumulated overhead percentage in this case.
--- tools/perf/ui/browsers/hists.c | 42 +++++++++++------------------------------- tools/perf/ui/gtk/hists.c | 6 ++---- tools/perf/ui/stdio/hist.c | 4 ++-- tools/perf/util/hist.h | 1 + tools/perf/util/sort.h | 17 ++++++++++++++++- 5 files changed, 32 insertions(+), 38 deletions(-)
tools/perf/ui/browsers/hists.c +11 -31
@@ -780,15 +780,12 @@ static unsigned int hist_browser__refresh(struct ui_browser *browser)for (nd = browser->top; nd; nd =rb_next (nd)) { struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); -u64 total =hists__total_period (h->hists); -float percent =0.0 ; +float percent;if (h->filtered)continue ; -if (total) - percent = h->stat.period *100.0 / total; - + percent =hist_entry__get_percent_limit (h);if (percent < hb->min_pcnt)continue ;
@@ -801,21 +798,13 @@ static unsigned int hist_browser__refresh(struct ui_browser *browser) }static struct rb_node *hists__filter_entries (struct rb_node *nd, -struct hists *hists,float min_pcnt) {while (nd !=NULL ) { struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); -u64 total =hists__total_period (hists); -float percent =0.0 ; - -if (total) - percent = h->stat.period *100.0 / total; +float percent =hist_entry__get_percent_limit (h); -if (percent < min_pcnt) -return NULL ; - -if (!h->filtered) +if (!h->filtered && percent >= min_pcnt)return nd; nd =rb_next (nd);
@@ -825,16 +814,11 @@ static struct rb_node *hists__filter_entries(struct rb_node *nd, }static struct rb_node *hists__filter_prev_entries (struct rb_node *nd, -struct hists *hists,float min_pcnt) {while (nd !=NULL ) { struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); -u64 total =hists__total_period (hists); -float percent =0.0 ; - -if (total) - percent = h->stat.period *100.0 / total; +float percent =hist_entry__get_percent_limit (h);if (!h->filtered && percent >= min_pcnt)return nd;
@@ -863,14 +847,14 @@ static void ui_browser__hists_seek(struct ui_browser *browser,switch (whence) {case SEEK_SET : nd =hists__filter_entries (rb_first (browser->entries), - hb->hists, hb->min_pcnt); + hb->min_pcnt);break ;case SEEK_CUR : nd = browser->top; goto do_offset;case SEEK_END : nd =hists__filter_prev_entries (rb_last (browser->entries), - hb->hists, hb->min_pcnt); + hb->min_pcnt); first = false;break ;default :
@@ -913,8 +897,7 @@ do_offset:break ; } } - nd =hists__filter_entries (rb_next (nd), hb->hists, - hb->min_pcnt); + nd =hists__filter_entries (rb_next (nd), hb->min_pcnt);if (nd ==NULL )break ; --offset;
@@ -947,7 +930,7 @@ do_offset: } } - nd =hists__filter_prev_entries (rb_prev (nd), hb->hists, + nd =hists__filter_prev_entries (rb_prev (nd), hb->min_pcnt);if (nd ==NULL )break ;
@@ -1118,7 +1101,6 @@ static int hist_browser__fprintf_entry(struct hist_browser *browser,static int hist_browser__fprintf (struct hist_browser *browser,FILE *fp) {struct rb_node *nd =hists__filter_entries (rb_first (browser->b.entries), - browser->hists, browser->min_pcnt);int printed =0 ;
@@ -1126,8 +1108,7 @@ static int hist_browser__fprintf(struct hist_browser *browser, FILE *fp) struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); printed +=hist_browser__fprintf_entry (browser, h, fp); - nd =hists__filter_entries (rb_next (nd), browser->hists, - browser->min_pcnt); + nd =hists__filter_entries (rb_next (nd), browser->min_pcnt); }return printed;
@@ -1361,8 +1342,7 @@ static void hist_browser__update_pcnt_entries(struct hist_browser *hb)while (nd) { nr_entries++; - nd =hists__filter_entries (rb_next (nd), hb->hists, - hb->min_pcnt); + nd =hists__filter_entries (rb_next (nd), hb->min_pcnt); } hb->nr_pcnt_entries = nr_entries;
tools/perf/ui/gtk/hists.c +2 -4
@@ -228,14 +228,12 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists, struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);GtkTreeIter iter;u64 total =hists__total_period (h->hists); -float percent =0.0 ; +float percent;if (h->filtered)continue ; -if (total) - percent = h->stat.period *100.0 / total; - + percent =hist_entry__get_percent_limit (h);if (percent < min_pcnt)continue ;
tools/perf/ui/stdio/hist.c +2 -2
@@ -454,12 +454,12 @@ print_entries:for (nd =rb_first (&hists->entries); nd; nd =rb_next (nd)) { struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); -float percent = h->stat.period *100.0 / - hists->stats.total_period; +float percent;if (h->filtered)continue ; + percent =hist_entry__get_percent_limit (h);if (percent < min_pcnt)continue ;
tools/perf/util/hist.h +1 -0
@@ -144,6 +144,7 @@ int hist_entry__sort_snprintf(struct hist_entry *he, char *bf, size_t size, struct hists *hists);void hist_entry__free (struct hist_entry *); +void hists__output_resort (struct hists *hists);void hists__collapse_resort (struct hists *hists,struct ui_progress *prog);
tools/perf/util/sort.h +16 -1
@@ -20,7 +20,7 @@#include "parse-options.h" #include "parse-events.h" - +#include "hist.h" #include "thread.h" extern regex_t parent_regex;
@@ -131,6 +131,21 @@ static inline void hist_entry__add_pair(struct hist_entry *pair,list_add_tail (&pair->pairs.node, &he->pairs.head); } +static inline float hist_entry__get_percent_limit (struct hist_entry *he) +{ +u64 period = he->stat.period; +u64 total_period =hists__total_period (he->hists); + +if (unlikely (total_period ==0 )) +return 0 ; + +if (symbol_conf.cumulate_callchain) + period = he->stat_acc->period; + +return period *100.0 / total_period; +} + +enum sort_mode {SORT_MODE__NORMAL ,SORT_MODE__BRANCH ,
Signature · 1 line
1.7.11.7
Namhyung Kim
maintainerPATCH 13/21 perf tools: Add more hpp helper functions
In reply to Namhyung KimSometimes it needs to disable some columns at runtime. Add help functions to support that.
--- tools/perf/ui/hist.c | 17 +++++++++++++++++ tools/perf/util/hist.h | 4 ++++ 2 files changed, 21 insertions(+)
tools/perf/ui/hist.c +17 -0
@@ -489,6 +489,11 @@ void perf_hpp__column_register(struct perf_hpp_fmt *format)list_add_tail (&format->list, &perf_hpp__list); } +void perf_hpp__column_unregister (struct perf_hpp_fmt *format) +{ +list_del (&format->list); +} +void perf_hpp__register_sort_field (struct perf_hpp_fmt *format) {list_add_tail (&format->sort_list, &perf_hpp__sort_list);
@@ -500,6 +505,18 @@ void perf_hpp__column_enable(unsigned col)perf_hpp__column_register (&perf_hpp__format[col]); } +void perf_hpp__column_disable (unsigned col) +{ +BUG_ON (col >=PERF_HPP__MAX_INDEX ); +perf_hpp__column_unregister (&perf_hpp__format[col]); +} + +void perf_hpp__cancel_cumulate (void ) +{ +perf_hpp__column_disable (PERF_HPP__OVERHEAD_ACC ); + perf_hpp__format[PERF_HPP__OVERHEAD ].header = hpp__header_overhead; +} +void perf_hpp__setup_output_field (void ) {struct perf_hpp_fmt *fmt;
tools/perf/util/hist.h +4 -0
@@ -224,7 +224,11 @@ enum {void perf_hpp__init (void );void perf_hpp__column_register (struct perf_hpp_fmt *format); +void perf_hpp__column_unregister (struct perf_hpp_fmt *format);void perf_hpp__column_enable (unsigned col); +void perf_hpp__column_disable (unsigned col); +void perf_hpp__cancel_cumulate (void ); +void perf_hpp__register_sort_field (struct perf_hpp_fmt *format);void perf_hpp__setup_output_field (void );void perf_hpp__append_sort_keys (void );
Signature · 1 line
1.7.11.7
Namhyung Kim
maintainerPATCH 14/21 perf report: Add --children option
In reply to Namhyung KimThe --children option is for showing accumulated overhead (period) value as well as self overhead.
--- tools/perf/Documentation/perf-report.txt | 7 ++++++- tools/perf/builtin-report.c | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-report.txt +6 -1
@@ -102,7 +102,7 @@ OPTIONS --fields=:: Specify output field - multiple keys can be specified in CSV format. Following fields are available: - overhead, overhead_sys, overhead_us, sample and period. + overhead, overhead_sys, overhead_us, overhead_children, sample and period. Also it can contain any sort key(s). By default, every sort keys not specified in -F will be appended
@@ -154,6 +154,11 @@ OPTIONS Default: fractal,0.5,callee,function. +--children:: + Accumulate callchain of children to parent entry so that then can + show up in the output. The output will have a new "Children" column + and will be sorted on the data. It requires callchains are recorded. + --max-stack:: Set the stack depth limit when parsing the callchain, anything beyond the specified depth will be ignored. This is a trade-off
tools/perf/builtin-report.c +10 -0
@@ -172,6 +172,14 @@ static int report__setup_sample_type(struct report *rep) } } +if (symbol_conf.cumulate_callchain) { +/* Silently ignore if callchain is missing */ +if (!(sample_type &PERF_SAMPLE_CALLCHAIN )) { + symbol_conf.cumulate_callchain = false; +perf_hpp__cancel_cumulate (); + } + } +if (sort__mode ==SORT_MODE__BRANCH ) {if (!is_pipe && !(sample_type &PERF_SAMPLE_BRANCH_STACK )) {
@@ -648,6 +656,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)OPT_CALLBACK_DEFAULT ('g' ,"call-graph" , &report,"output_type,min_percent[,print_limit],call_order" ,"Display callchains using output_type (graph, flat, fractal, or none) , min percent threshold, optional print limit, callchain order, key (function or address). " "Default: fractal,0.5,callee,function" , &parse_callchain_opt, callchain_default_opt), +OPT_BOOLEAN (0 ,"children" , &symbol_conf.cumulate_callchain, +"Accumulate callchains of children and show total overhead as well" ),OPT_INTEGER (0 ,"max-stack" , &report.max_stack,"Set the maximum stack depth when parsing the callchain, " "anything beyond the specified depth will be ignored. "
Signature · 1 line
1.7.11.7
Namhyung Kim
maintainerPATCH 15/21 perf report: Add report.children config option
In reply to Namhyung KimAdd report.children config option for setting default value of callchain accumulation. It affects the report output only if perf.data contains callchain info.
A user can write .perfconfig file like below to enable accumulation by default:
$ cat ~/.perfconfig [report] children = true
And it can be disabled through command line:
$ perf report --no-children
--- tools/perf/builtin-report.c | 4 ++++ 1 file changed, 4 insertions(+)
tools/perf/builtin-report.c +4 -0
@@ -71,6 +71,10 @@ static int report__config(const char *var, const char *value, void *cb) rep->min_percent =strtof (value,NULL );return 0 ; } +if (!strcmp (var,"report.children" )) { + symbol_conf.cumulate_callchain =perf_config_bool (var, value); +return 0 ; + }return perf_default_config (var, value, cb); }
Signature · 1 line
1.7.11.7
Namhyung Kim
maintainerPATCH 16/21 perf tools: Do not auto-remove Children column if --fields given
In reply to Namhyung KimDepending on the configuration perf inserts/removes the Children column in the output automatically. But it might not be what user wants if [s]he give --fields option explicitly.
--- tools/perf/ui/hist.c | 3 +++ 1 file changed, 3 insertions(+)
tools/perf/ui/hist.c +3 -0
@@ -513,6 +513,9 @@ void perf_hpp__column_disable(unsigned col)void perf_hpp__cancel_cumulate (void ) { +if (field_order) +return ; +perf_hpp__column_disable (PERF_HPP__OVERHEAD_ACC ); perf_hpp__format[PERF_HPP__OVERHEAD ].header = hpp__header_overhead; }
Signature · 1 line
1.7.11.7
Namhyung Kim
maintainerPATCH 17/21 perf tools: Add callback function to hist_entry_iter
In reply to Namhyung KimThe new ->add_entry_cb() will be called after an entry was added to the histogram. It's used for code sharing between perf report and perf top. Note that ops->add_*_entry() should set iter->he properly in order to call the ->add_entry_cb.
Also pass @arg to the callback function. It'll be used by perf top later.
--- tools/perf/builtin-report.c | 34 +++++++++++++++++++++++++++++--- tools/perf/util/hist.c | 48 ++++++++++++++++++++++----------------------- tools/perf/util/hist.h | 5 ++++- 3 files changed, 59 insertions(+), 28 deletions(-)
tools/perf/builtin-report.c +31 -3
@@ -79,6 +79,30 @@ static int report__config(const char *var, const char *value, void *cb)return perf_default_config (var, value, cb); } +static int hist_iter_cb (struct hist_entry_iter *iter, +struct addr_location *al,bool single, +void *arg__maybe_unused ) +{ +int err =0 ; +struct hist_entry *he = iter->he; +struct perf_evsel *evsel = iter->evsel; +struct perf_sample *sample = iter->sample; + +if (ui__has_annotation ()) + err =hist_entry__inc_addr_samples (he, evsel->idx, al->addr); + +if (!single) + goto out; + + evsel->hists.stats.total_period += sample->period; +hists__inc_nr_events (&evsel->hists,PERF_RECORD_SAMPLE ); +if (!he->filtered) + evsel->hists.stats.nr_non_filtered_samples++; + +out: +return err; +} + static int process_sample_event(struct perf_tool *tool, union perf_event *event, struct perf_sample *sample,
@@ -108,15 +132,19 @@ static int process_sample_event(struct perf_tool *tool, iter.ops = &hist_iter_branch; else if (rep->mem_mode) iter.ops = &hist_iter_mem; - else if (symbol_conf.cumulate_callchain) + else if (symbol_conf.cumulate_callchain) { iter.ops = &hist_iter_cumulative; - else + iter.add_entry_cb = hist_iter_cb; + } else { iter.ops = &hist_iter_normal; + iter.add_entry_cb = hist_iter_cb; + }if (al.map !=NULL ) al.map->dso->hit =1 ; - ret =hist_entry_iter__add (&iter, &al, evsel, sample, rep->max_stack); + ret =hist_entry_iter__add (&iter, &al, evsel, sample, rep->max_stack, +NULL );if (ret <0 )pr_debug ("problem adding hist entry, skipping event\n" );
tools/perf/util/hist.c +24 -24
114 lines not on this page · raw message
tools/perf/util/hist.h +4 -1
@@ -119,6 +119,9 @@ struct hist_entry_iter {void *priv;const struct hist_iter_ops *ops; +/* user-defined callback function (optional) */ +int (*add_entry_cb)(struct hist_entry_iter *iter, +struct addr_location *al,bool single,void *arg); };extern const struct hist_iter_ops hist_iter_normal;
@@ -135,7 +138,7 @@ struct hist_entry *__hists__add_entry(struct hists *hists, bool sample_self);int hist_entry_iter__add (struct hist_entry_iter *iter,struct addr_location *al,struct perf_evsel *evsel,struct perf_sample *sample, -int max_stack_depth); +int max_stack_depth,void *arg);int64_t hist_entry__cmp (struct hist_entry *left,struct hist_entry *right);int64_t hist_entry__collapse (struct hist_entry *left,struct hist_entry *right);
Signature · 1 line
1.7.11.7
Namhyung Kim
maintainerPATCH 18/21 perf top: Convert to hist_entry_iter
In reply to Namhyung KimReuse hist_entry_iter__add() function to share the similar code with perf report. Note that it needs to be called with hists.lock so tweak some internal functions not to deadlock or hold the lock too long.
--- tools/perf/builtin-top.c | 84 ++++++++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 38 deletions(-)
tools/perf/builtin-top.c +46 -38
@@ -196,6 +196,12 @@ static void perf_top__record_precise_ip(struct perf_top *top,pthread_mutex_unlock (¬es->lock); +/* +* This function is now called with he->hists->lock held. +* Release it before going to sleep. +*/ +pthread_mutex_unlock (&he->hists->lock); +if (err == -ERANGE && !he->ms.map->erange_warned)ui__warn_map_erange (he->ms.map, sym, ip);else if (err == -ENOMEM ) {
@@ -203,6 +209,8 @@ static void perf_top__record_precise_ip(struct perf_top *top, sym->name);sleep (1 ); } + +pthread_mutex_lock (&he->hists->lock); }static void perf_top__show_details (struct perf_top *top)
@@ -238,27 +246,6 @@ out_unlock:pthread_mutex_unlock (¬es->lock); } -static struct hist_entry *perf_evsel__add_hist_entry (struct perf_evsel *evsel, -struct addr_location *al, -struct perf_sample *sample) -{ -struct hist_entry *he; - -pthread_mutex_lock (&evsel->hists.lock); - he =__hists__add_entry (&evsel->hists, al,NULL ,NULL ,NULL , - sample->period, sample->weight, - sample->transaction, true); -pthread_mutex_unlock (&evsel->hists.lock); -if (he ==NULL ) -return NULL ; - -hists__inc_nr_events (&evsel->hists,PERF_RECORD_SAMPLE ); -if (!he->filtered) - evsel->hists.stats.nr_non_filtered_samples++; - -return he; -} -static void perf_top__print_sym_table (struct perf_top *top) {char bf[160 ];
@@ -662,6 +649,31 @@ static int symbol_filter(struct map *map __maybe_unused, struct symbol *sym)return 0 ; } +static int hist_iter_cb (struct hist_entry_iter *iter,struct addr_location *al, +bool single,void *arg) +{ +struct perf_top *top = arg; +struct hist_entry *he = iter->he; +struct perf_evsel *evsel = iter->evsel; + +if (single) { +hists__inc_nr_events (&evsel->hists,PERF_RECORD_SAMPLE ); +if (!he->filtered) + evsel->hists.stats.nr_non_filtered_samples++; + } + +if (sort__has_sym) { +u64 ip = al->addr; + +if (al->map) + ip = al->map->unmap_ip (al->map, ip); + +perf_top__record_precise_ip (top, he, evsel->idx, ip); + } + +return 0 ; +} + static void perf_event__process_sample(struct perf_tool *tool, const union perf_event *event, struct perf_evsel *evsel,
@@ -669,8 +681,6 @@ static void perf_event__process_sample(struct perf_tool *tool, struct machine *machine) { struct perf_top *top = container_of(tool, struct perf_top, tool); -struct symbol *parent =NULL ; -u64 ip = sample->ip;struct addr_location al;int err;
@@ -745,25 +755,23 @@ static void perf_event__process_sample(struct perf_tool *tool, }if (al.sym ==NULL || !al.sym->ignore) { -struct hist_entry *he; +struct hist_entry_iter iter = { + .add_entry_cb = hist_iter_cb, + }; - err =sample__resolve_callchain (sample, &parent, evsel, &al, - top->max_stack); -if (err) -return ; +if (symbol_conf.cumulate_callchain) + iter.ops = &hist_iter_cumulative; +else + iter.ops = &hist_iter_normal; - he =perf_evsel__add_hist_entry (evsel, &al, sample); -if (he ==NULL ) { -pr_err ("Problem incrementing symbol period, skipping event\n" ); -return ; - } +pthread_mutex_lock (&evsel->hists.lock); - err =hist_entry__append_callchain (he, sample); -if (err) -return ; + err =hist_entry_iter__add (&iter, &al, evsel, sample, + top->max_stack, top); +if (err <0 ) +pr_err ("Problem incrementing symbol period, skipping event\n" ); -if (sort__has_sym) -perf_top__record_precise_ip (top, he, evsel->idx, ip); +pthread_mutex_unlock (&evsel->hists.lock); }return ;
Signature · 1 line
1.7.11.7
Namhyung Kim
maintainerPATCH 19/21 perf top: Add --children option
In reply to Namhyung KimThe --children option is for showing accumulated overhead (period) value as well as self overhead. It should be used with one of -g or --call-graph option.
--- tools/perf/Documentation/perf-top.txt | 8 +++++++- tools/perf/builtin-top.c | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-top.txt +7 -1
@@ -119,7 +119,7 @@ Default is to monitor all CPUS. --fields=:: Specify output field - multiple keys can be specified in CSV format. Following fields are available: - overhead, overhead_sys, overhead_us, sample and period. + overhead, overhead_sys, overhead_us, overhead_children, sample and period. Also it can contain any sort key(s). By default, every sort keys not specified in --field will be appended
@@ -161,6 +161,12 @@ Default is to monitor all CPUS. Setup and enable call-graph (stack chain/backtrace) recording, implies -g. +--children:: + Accumulate callchain of children to parent entry so that then can + show up in the output. The output will have a new "Children" column + and will be sorted on the data. It requires -g/--call-graph option + enabled. + --max-stack:: Set the stack depth limit when parsing the callchain, anything beyond the specified depth will be ignored. This is a trade-off
tools/perf/builtin-top.c +7 -0
@@ -1103,6 +1103,8 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)OPT_CALLBACK (0 ,"call-graph" , &top.record_opts,"mode[,dump_size]" , record_callchain_help, &parse_callchain_opt), +OPT_BOOLEAN (0 ,"children" , &symbol_conf.cumulate_callchain, +"Accumulate callchains of children and show total overhead as well" ),OPT_INTEGER (0 ,"max-stack" , &top.max_stack,"Set the maximum stack depth when parsing the callchain. " "Default: " __stringify(PERF_MAX_STACK_DEPTH)),
@@ -1205,6 +1207,11 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused) top.sym_evsel =perf_evlist__first (top.evlist); +if (!symbol_conf.use_callchain) { + symbol_conf.cumulate_callchain = false; +perf_hpp__cancel_cumulate (); + } + symbol_conf.priv_size =sizeof (struct annotation ); symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name ==NULL );
Signature · 1 line
1.7.11.7
Namhyung Kim
maintainerPATCH 20/21 perf top: Add top.children config option
In reply to Namhyung KimAdd top.children config option for setting default value of callchain accumulation. It affects the output only if one of -g or --call-graph option is given as well.
A user can write .perfconfig file like below to enable accumulation by default:
$ cat ~/.perfconfig [top] children = true
And it can be disabled through command line:
$ perf top --no-children
--- tools/perf/builtin-top.c | 4 ++++ 1 file changed, 4 insertions(+)
tools/perf/builtin-top.c +4 -0
@@ -1009,6 +1009,10 @@ static int perf_top_config(const char *var, const char *value, void *cb)if (!strcmp (var,"top.call-graph" ))return record_parse_callchain (value, &top->record_opts); +if (!strcmp (var,"top.children" )) { + symbol_conf.cumulate_callchain =perf_config_bool (var, value); +return 0 ; + }return perf_default_config (var, value, cb); }
Signature · 1 line
1.7.11.7
Namhyung Kim
maintainerPATCH 21/21 perf tools: Enable --children option by default
In reply to Namhyung KimNow perf top and perf report will show children column by default if it has callchain information.
--- tools/perf/util/symbol.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
tools/perf/util/symbol.c +6 -5
@@ -29,11 +29,12 @@ int vmlinux_path__nr_entries;char **vmlinux_path;struct symbol_conf symbol_conf = { - .use_modules = true, - .try_vmlinux_path = true, - .annotate_src = true, - .demangle = true, - .symfs ="" , + .use_modules = true, + .try_vmlinux_path = true, + .annotate_src = true, + .demangle = true, + .cumulate_callchain = true, + .symfs ="" , };static enum dso_binary_type binary_type_symtab[] = {
Signature · 1 line
1.7.11.7
Quoted 5 lines · Namhyung Kim
Hello,
This is a new attempt to implement cumulative hist period report. This work begins from Arun's
SORT_INCLUSIVEpatch [1] but I completely rewrote it from scratch.
While testing this patch series, we found error messages which look like this:
Out of bounds address found:
Addr: 10370 DSO: /usr/local/lib/libgcc_s.so.1 d Map: 7f1b0c953000-7f1b0c968000 Symbol: 102d0-102e9 g _Unwind_DeleteException Arch: x86_64 Kernel: 3.10.23+ Tools: 3.13.rc1.g374a4d
Not all samples will be on the annotation output.
Please report to [email protected]
I first suspected it to be caused by this patch series, but I'm able to reproduce without these patches as of this commit:
a51e87c perf tools: Remove unused simple_strtoul() function
gdb attributes 0x10370 to a different/known symbol.
(gdb) x /i 0x10370
0x10370 <get_cie_encoding+160>: cmp $0x4c,%dl
Is this known? Could this possibly be caused by stale histogram entries from unmapped/remapped shared libs?
-Arun
Namhyung Kim
maintainerHi Arun,
Quoted 22 lines · Arun Sharma
Quoted 6 lines · Namhyung Kim
Hello,
This is a new attempt to implement cumulative hist period report. This work begins from Arun's
SORT_INCLUSIVEpatch [1] but I completely rewrote it from scratch.While testing this patch series, we found error messages which look like this:
Out of bounds address found:
Addr: 10370 DSO: /usr/local/lib/libgcc_s.so.1 d Map: 7f1b0c953000-7f1b0c968000 Symbol: 102d0-102e9 g _Unwind_DeleteException Arch: x86_64 Kernel: 3.10.23+ Tools: 3.13.rc1.g374a4d
Quoted 3 lines
Not all samples will be on the annotation output.
Please report to [email protected]
Hmm.. interesting. is it perf top right?
Quoted 5 lines
I first suspected it to be caused by this patch series, but I'm able to reproduce without these patches as of this commit:
a51e87c perf tools: Remove unused
simple_strtoul()function
Ah, it's good to know :)
Quoted 8 lines
gdb attributes
0x10370to a different/known symbol.(gdb) x /i
0x10370
0x10370<get_cie_encoding+160>: cmp $0x4c,%dlIs this known? Could this possibly be caused by stale histogram entries from unmapped/remapped shared libs?
Possibly.
Anyway the addr which perf reported is a mapped address so that it's pointless to use the addr directly - it's 7f1b0c963370 in fact.
What was the exact command line though - did you use any filter (--comms, --dsos, --symbols) or event modifiers? Those are another possible culprits since map searching code touched by recent changes.
I'm not able to reproduce the problem on my machine. It'd be great if you could bisect or let me know how to reproduce it easily.
Thanks,
Namhyung
Quoted 6 lines · Namhyung Kim
Quoted 6 lines
gdb attributes
0x10370to a different/known symbol.(gdb) x /i
0x103700x10370 <get_cie_encoding+160>: cmp $0x4c,%dl
Quoted 8 lines
Quoted 2 lines
Is this known? Could this possibly be caused by stale histogram entries from unmapped/remapped shared libs?
Possibly.
Anyway the addr which perf reported is a mapped address so that it's pointless to use the addr directly - it's
7f1b0c963370in fact.
Right - that's the address I'd use if the process in question is still running. But gdb <dso name> followed by relative addresses could still tell us what the right symbol was?
Quoted 3 lines
What was the exact command line though - did you use any filter (--comms, --dsos, --symbols) or event modifiers? Those are another possible culprits since map searching code touched by recent changes.
There were no other filters. The command used was just "perf top".
Quoted 4 lines
I'm not able to reproduce the problem on my machine. It'd be great if you could bisect or let me know how to reproduce it easily.
I don't have a solid repro either. Involves building a binary, running "perf top" and waiting for a few mins until that warning popup appears.
Will try to git bisect and figure out potential culprits.
-Arun
Quoted 14 lines · Namhyung Kim
Hello,
This is a new attempt to implement cumulative hist period report. This work begins from Arun's
SORT_INCLUSIVEpatch [1] but I completely rewrote it from scratch.This version depends on my previous percentage patchset [2] and output field patchset[3]. So please test this again although there's not much change in the series itself.
This patchset basically adds period in a sample to every node in the callchain. A
hist_entrynow has an additional fields to keep the cumulative period if --children option is given on perf report.
Quoted 6 lines
I changed the option as a separate --children and added a new "Children" column (and renamed the default "Overhead" column into "Self"). The output will be sorted by children (cumulative) overhead for now. It also adds '
overhead_children' field to -F/--fields option to be selected by user and it'll show you "N/A" if the cumulation is not supported (due to missing callchain).
Is there something I can help to have this merged ? As far as I tested, this works fine here. Or is this ok, just waiting on the "perf report: Add -F option for specifying output fields" patchset ?
Thanks a lot,
Rodrigo
Namhyung Kim
maintainerHi Rodrigo,
Quoted 3 lines · Rodrigo Campos
Is there something I can help to have this merged ? As far as I tested, this works fine here. Or is this ok, just waiting on the "perf report: Add -F option for specifying output fields" patchset ?
Thanks for testing!! As I never got (negative) feedbacks or reviews so far, I'd assume it's ok. :) But as you said, it should wait for the output field option merged which I hope to be done soon. I'll update and report this once it's done.
Thanks,
Namhyung
Quoted 11 lines · Namhyung Kim
Hi Rodrigo,
Quoted 3 lines · Rodrigo Campos
Is there something I can help to have this merged ? As far as I tested, this works fine here. Or is this ok, just waiting on the "perf report: Add -F option for specifying output fields" patchset ?
Thanks for testing!! As I never got (negative) feedbacks or reviews so far, I'd assume it's ok. :) But as you said, it should wait for the output field option merged which I hope to be done soon. I'll update and report this once it's done.
Great, thanks a lot! :-)
Quoted 7 lines · Rodrigo Campos
Quoted 6 lines · Namhyung Kim
Hi Rodrigo,
Quoted 3 lines · Rodrigo Campos
Is there something I can help to have this merged ? As far as I tested, this works fine here. Or is this ok, just waiting on the "perf report: Add -F option for specifying output fields" patchset ?
I plan to do it today, can I use your Tested-by ?
thanks,
jirka
Quoted 7 lines
Quoted 5 lines
Thanks for testing!! As I never got (negative) feedbacks or reviews so far, I'd assume it's ok. :) But as you said, it should wait for the output field option merged which I hope to be done soon. I'll update and report this once it's done.
Great, thanks a lot! :-)
Quoted 10 lines · Jiri Olsa
Quoted 7 lines · Rodrigo Campos
Quoted 6 lines · Namhyung Kim
Hi Rodrigo,
Quoted 3 lines · Rodrigo Campos
Is there something I can help to have this merged ? As far as I tested, this works fine here. Or is this ok, just waiting on the "perf report: Add -F option for specifying output fields" patchset ?
I plan to do it today, can I use your Tested-by ?
Sure :-)
Thanks a lot,
Rodrigo
Quoted 5 lines · Rodrigo Campos
Quoted 4 lines · Jiri Olsa
Quoted 3 lines · Rodrigo Campos
Quoted 2 lines · Namhyung Kim
Hi Rodrigo,
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines · Rodrigo Campos
Quoted 3 lines
Is there something I can help to have this merged ? As far as I tested, this works fine here. Or is this ok, just waiting on the "perf report: Add -F option for specifying output fields" patchset ?
I plan to do it today, can I use your Tested-by ?
Sure :-)
ugh.. I meant the other patchset:
perf report: Add -F option for specifying output fields
this one will come later ;-) sry for confusion
jirka
Quoted 11 lines · Jiri Olsa
Quoted 10 lines · Rodrigo Campos
Quoted 9 lines · Jiri Olsa
Quoted 7 lines · Rodrigo Campos
Quoted 6 lines · Namhyung Kim
Hi Rodrigo,
Quoted 3 lines · Rodrigo Campos
Is there something I can help to have this merged ? As far as I tested, this works fine here. Or is this ok, just waiting on the "perf report: Add -F option for specifying output fields" patchset ?
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
I plan to do it today, can I use your Tested-by ?
Sure :-)
ugh.. I meant the other patchset:
perf report: Add -F option for specifying output fields
I just played with it for a while and worked fine. So, if that is enough, yes :-)
Quoted 2 lines
this one will come later ;-) sry for confusion
Ohh, I'm really interested in this patchset =)
Thanks a lot,
Rodrigo