perf report: Support folded callchain output (v3)
Namhyung Kim
maintainercover perf report: Support folded callchain output (v3)
Hello,
This is what Brendan requested on the perf-users mailing list [1] to support FlameGraphs [2] more efficiently. This patchset adds a few more callchain options to adjust the output for it.
* changes in v3)
- put the value before callchains
- fix compile error
At first, 'folded' output mode was added. The folded output puts the value, a space and all calchain nodes separated by semicolons. Now it only supports --stdio as other UI provides some way of folding and/or expanding callchains dynamically.
The value is now can be one of 'percent', 'period', or 'count'. The percent is current default output and the period is the raw number of sample periods. The count is the number of samples for each callchain.
Here's an example:
$ perf report --no-children --show-nr-samples --stdio -g folded,count
...
39.93% 80 swapper [kernel.vmlinux] [k] intel_idel
57 intel_idle;cpuidle_enter_state;cpuidle_enter;call_cpuidle;cpu_startup_entry;start_secondary
23 intel_idle;cpuidle_enter_state;cpuidle_enter;call_cpuidle;cpu_startup_entry;rest_init;... $ perf report --no-children --stdio -g percent
...
39.93% swapper [kernel.vmlinux] [k] intel_idel
|
---intel_idle
cpuidle_enter_state
cpuidle_enter
call_cpuidle
cpu_startup_entry
|
|--28.63%-- start_secondary
|
--11.30%-- rest_init $ perf report --no-children --stdio --show-total-period -g period
...
39.93% 13018705 swapper [kernel.vmlinux] [k] intel_idel
|
---intel_idle
cpuidle_enter_state
cpuidle_enter
call_cpuidle
cpu_startup_entry
|
|--9334403-- start_secondary
|
--3684302-- rest_init $ perf report --no-children --stdio --show-nr-samples -g count
...
39.93% 80 swapper [kernel.vmlinux] [k] intel_idel
|
---intel_idle
cpuidle_enter_state
cpuidle_enter
call_cpuidle
cpu_startup_entry
|
|--57-- start_secondary
|
--23-- rest_initYou can get it from 'perf/callchain-fold-v3' branch on my tree:
git://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git
Any comments are welcome, thanks
Namhyung
[1] http://www.spinics.net/lists/linux-perf-users/msg02498.html
[2] http://www.brendangregg.com/FlameGraphs/cpuflamegraphs.html
Namhyung Kim (4):
perf report: Support folded callchain mode on --stdio perf callchain: Abstract callchain print function perf callchain: Add count fields to struct callchain_node perf report: Add callchain value option
tools/perf/Documentation/perf-report.txt | 13 +++-- tools/perf/builtin-report.c | 4 +- tools/perf/ui/browsers/hists.c | 8 +-- tools/perf/ui/gtk/hists.c | 8 +-- tools/perf/ui/stdio/hist.c | 93 ++++++++++++++++++++++++++------ tools/perf/util/callchain.c | 87 +++++++++++++++++++++++++++++- tools/perf/util/callchain.h | 24 ++++++++- tools/perf/util/util.c | 3 +- 8 files changed, 205 insertions(+), 35 deletions(-)
Signature · 1 line
2.6.2
Namhyung Kim
maintainerPATCH v3 1/4 perf report: Support folded callchain mode on --stdio
Add new call chain option (-g) 'folded' to print callchains in a line. The callchains are separated by semicolons, and preceded by (absolute) percent values and a space.
For example, following 20 lines can be printed in 3 lines with the folded output mode;
$ perf report -g flat --no-children | grep -v ^# | head -20
60.48% swapper [kernel.vmlinux] [k] intel_idle
54.60%
intel_idle
cpuidle_enter_state
cpuidle_enter
call_cpuidle
cpu_startup_entry
start_secondary 5.88%
intel_idle
cpuidle_enter_state
cpuidle_enter
call_cpuidle
cpu_startup_entry
rest_init
start_kernel
x86_64_start_reservations
x86_64_start_kernel $ perf report -g folded --no-children | grep -v ^# | head -3
60.48% swapper [kernel.vmlinux] [k] intel_idle
54.60% intel_idle;cpuidle_enter_state;cpuidle_enter;call_cpuidle;cpu_startup_entry;start_secondary
5.88% intel_idle;cpuidle_enter_state;cpuidle_enter;call_cpuidle;cpu_startup_entry;rest_init;start_kernel;x86_64_start_reservations;x86_64_start_kernelThis mode is supported only for --stdio now and intended to be used by some scripts like in FlameGraphs[1]. Support for other UI might be added later.
[1] http://www.brendangregg.com/FlameGraphs/cpuflamegraphs.html
--- tools/perf/ui/stdio/hist.c | 54 +++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/callchain.c | 6 +++++ tools/perf/util/callchain.h | 3 ++- 3 files changed, 62 insertions(+), 1 deletion(-)
tools/perf/ui/stdio/hist.c +54 -0
@@ -260,6 +260,57 @@ static size_t callchain__fprintf_flat(FILE *fp, struct rb_root *tree,return ret; } +static size_t __callchain__fprintf_folded (FILE *fp,struct callchain_node *node) +{ +struct callchain_list *chain; +size_t ret =0 ; +char bf[1024 ]; +bool first; + +if (!node) +return 0 ; + + ret +=__callchain__fprintf_folded (fp, node->parent); + + first = (ret ==0 ); +list_for_each_entry (chain, &node->val, list) { +if (chain->ip >=PERF_CONTEXT_MAX ) +continue ; + ret +=fprintf (fp,"%s%s" , first ?"" :";" , +callchain_list__sym_name (chain, + bf,sizeof (bf), false)); + first = false; + } + +return ret; +} + +static size_t callchain__fprintf_folded (FILE *fp,struct rb_root *tree, +u64 total_samples) +{ +size_t ret =0 ; +u32 entries_printed =0 ; +struct callchain_node *chain; +struct rb_node *rb_node =rb_first (tree); + +while (rb_node) { +double percent; + + chain = rb_entry(rb_node, struct callchain_node, rb_node); + percent = chain->hit *100.0 / total_samples; + + ret +=fprintf (fp,"%.2f%% " , percent); + ret +=__callchain__fprintf_folded (fp, chain); + ret +=fprintf (fp,"\n" ); +if (++entries_printed == callchain_param.print_limit) +break ; + + rb_node =rb_next (rb_node); + } + +return ret; +} +static size_t hist_entry_callchain__fprintf (struct hist_entry *he,u64 total_samples,int left_margin,FILE *fp)
@@ -278,6 +329,9 @@ static size_t hist_entry_callchain__fprintf(struct hist_entry *he,case CHAIN_FLAT :return callchain__fprintf_flat (fp, &he->sorted_chain, total_samples);break ; +case CHAIN_FOLDED : +return callchain__fprintf_folded (fp, &he->sorted_chain, total_samples); +break ;case CHAIN_NONE :break ;default :
tools/perf/util/callchain.c +6 -0
@@ -44,6 +44,10 @@ static int parse_callchain_mode(const char *value) callchain_param.mode =CHAIN_GRAPH_REL ;return 0 ; } +if (!strncmp (value,"folded" ,strlen (value))) { + callchain_param.mode =CHAIN_FOLDED ; +return 0 ; + }return -1 ; }
@@ -218,6 +222,7 @@ rb_insert_callchain(struct rb_root *root, struct callchain_node *chain,switch (mode) {case CHAIN_FLAT : +case CHAIN_FOLDED :if (rnode->hit < chain->hit) p = &(*p)->rb_left;else
@@ -338,6 +343,7 @@ int callchain_register_param(struct callchain_param *param) param->sort = sort_chain_graph_rel;break ;case CHAIN_FLAT : +case CHAIN_FOLDED : param->sort = sort_chain_flat;break ;case CHAIN_NONE :
tools/perf/util/callchain.h +2 -1
@@ -43,7 +43,8 @@ enum chain_mode {CHAIN_NONE ,CHAIN_FLAT ,CHAIN_GRAPH_ABS , -CHAIN_GRAPH_REL +CHAIN_GRAPH_REL , + CHAIN_FOLDED, }; enum chain_order {
Signature · 1 line
2.6.2
Re: [PATCH v3 1/4] perf report: Support folded callchain mode on --stdio
Quoted 39 lines · Namhyung Kim
Add new call chain option (-g) 'folded' to print callchains in a line. The callchains are separated by semicolons, and preceded by (absolute) percent values and a space.
For example, following 20 lines can be printed in 3 lines with the folded output mode;
$ perf report -g flat --no-children | grep -v ^# | head -20 60.48% swapper [kernel.vmlinux] [k] intel_idle 54.60% intel_idle cpuidle_enter_state cpuidle_enter call_cpuidle cpu_startup_entry start_secondary5.88% intel_idle cpuidle_enter_state cpuidle_enter call_cpuidle cpu_startup_entry rest_init start_kernel x86_64_start_reservations x86_64_start_kernel$ perf report -g folded --no-children | grep -v ^# | head -3 60.48% swapper [kernel.vmlinux] [k] intel_idle 54.60% intel_idle;cpuidle_enter_state;cpuidle_enter;call_cpuidle;cpu_startup_entry;start_secondary 5.88% intel_idle;cpuidle_enter_state;cpuidle_enter;call_cpuidle;cpu_startup_entry;rest_init;start_kernel;x86_64_start_reservations;x86_64_start_kernelThis mode is supported only for --stdio now and intended to be used by some scripts like in FlameGraphs[1]. Support for other UI might be added later.
[1] http://www.brendangregg.com/FlameGraphs/cpuflamegraphs.html
Quoted 7 lines
Requested-by Brendan Gregg <[email protected]>Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/ui/stdio/hist.c | 54 +++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/callchain.c | 6 +++++ tools/perf/util/callchain.h | 3 ++- 3 files changed, 62 insertions(+), 1 deletion(-)
missing doc update, otherwise
thanks,
jirka
Namhyung Kim
maintainerPATCH v3 2/4 perf callchain: Abstract callchain print function
In reply to Namhyung KimThis is a preparation to support for printing other type of callchain value like count or period.
--- tools/perf/ui/browsers/hists.c | 8 +++++--- tools/perf/ui/gtk/hists.c | 8 ++------ tools/perf/ui/stdio/hist.c | 35 +++++++++++++++++------------------ tools/perf/util/callchain.c | 25 +++++++++++++++++++++++++ tools/perf/util/callchain.h | 4 ++++ 5 files changed, 53 insertions(+), 27 deletions(-)
tools/perf/ui/browsers/hists.c +5 -3
@@ -592,7 +592,6 @@ static int hist_browser__show_callchain(struct hist_browser *browser,while (node) { struct callchain_node *child = rb_entry(node, struct callchain_node, rb_node);struct rb_node *next =rb_next (node); -u64 cumul =callchain_cumul_hits (child);struct callchain_list *chain;char folded_sign =' ' ;int first = true;
@@ -619,9 +618,12 @@ static int hist_browser__show_callchain(struct hist_browser *browser, browser->show_dso);if (was_first && need_percent) { -double percent = cumul *100.0 / total; +char buf[64 ]; -if (asprintf (&alloc_str,"%2.2f%% %s" , percent, str) <0 ) +callchain_node__sprintf_value (child, buf,sizeof (buf), + total); + +if (asprintf (&alloc_str,"%s %s" , buf, str) <0 ) str ="Not enough memory!" ;else str = alloc_str;
tools/perf/ui/gtk/hists.c +2 -6
@@ -100,14 +100,10 @@ static void perf_gtk__add_callchain(struct rb_root *root, GtkTreeStore *store,struct callchain_list *chain;GtkTreeIter iter, new_parent;bool need_new_parent; -double percent; -u64 hits, child_total; +u64 child_total; node = rb_entry(nd, struct callchain_node, rb_node); - hits =callchain_cumul_hits (node); - percent =100.0 * hits / total; - new_parent = *parent; need_new_parent = !has_single_node && (node->val_nr >1 );
@@ -116,7 +112,7 @@ static void perf_gtk__add_callchain(struct rb_root *root, GtkTreeStore *store,gtk_tree_store_append (store, &iter, &new_parent); -scnprintf (buf,sizeof (buf),"%5.2f%%" , percent); +callchain_node__sprintf_value (node, buf,sizeof (buf), total);gtk_tree_store_set (store, &iter,0 , buf,-1 );callchain_list__sym_name (chain, buf,sizeof (buf), false);
tools/perf/ui/stdio/hist.c +17 -18
@@ -34,10 +34,10 @@ static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask,return ret; } -static size_t ipchain__fprintf_graph (FILE *fp,struct callchain_list *chain, +static size_t ipchain__fprintf_graph (FILE *fp,struct callchain_node *node, +struct callchain_list *chain,int depth,int depth_mask,int period, -u64 total_samples,u64 hits, -int left_margin) +u64 total_samples,int left_margin) {int i;size_t ret =0 ;
@@ -50,10 +50,9 @@ static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain,else ret +=fprintf (fp," " );if (!period && i == depth -1 ) { -double percent; - - percent = hits *100.0 / total_samples; - ret +=percent_color_fprintf (fp,"--%2.2f%%-- " , percent); + ret +=fprintf (fp,"--" ); + ret +=callchain_node__fprintf_value (node, fp, total_samples); + ret +=fprintf (fp,"--" ); }else ret +=fprintf (fp,"%s" ," " ); }
@@ -120,10 +119,9 @@ static size_t __callchain__fprintf_graph(FILE *fp, struct rb_root *root, left_margin); i =0 ;list_for_each_entry (chain, &child->val, list) { - ret +=ipchain__fprintf_graph (fp, chain, depth, + ret +=ipchain__fprintf_graph (fp, child, chain, depth, new_depth_mask, i++, total_samples, - cumul, left_margin); }
@@ -143,14 +141,17 @@ static size_t __callchain__fprintf_graph(FILE *fp, struct rb_root *root,if (callchain_param.mode ==CHAIN_GRAPH_REL && remaining && remaining != total_samples) { +struct callchain_node rem_node = { + .hit = remaining, + };if (!rem_sq_bracket)return ret; new_depth_mask &= ~(1 << (depth -1 )); - ret +=ipchain__fprintf_graph (fp, &rem_hits, depth, + ret +=ipchain__fprintf_graph (fp, &rem_node, &rem_hits, depth, new_depth_mask,0 , total_samples, - remaining, left_margin); + left_margin); }return ret;
@@ -243,12 +244,11 @@ static size_t callchain__fprintf_flat(FILE *fp, struct rb_root *tree,struct rb_node *rb_node =rb_first (tree);while (rb_node) { -double percent; - chain = rb_entry(rb_node, struct callchain_node, rb_node); - percent = chain->hit *100.0 / total_samples; - ret =percent_color_fprintf (fp," %6.2f%%\n" , percent); + ret +=fprintf (fp," " ); + ret +=callchain_node__fprintf_value (chain, fp, total_samples); + ret +=fprintf (fp,"\n" ); ret +=__callchain__fprintf_flat (fp, chain, total_samples); ret +=fprintf (fp,"\n" );if (++entries_printed == callchain_param.print_limit)
@@ -294,12 +294,11 @@ static size_t callchain__fprintf_folded(FILE *fp, struct rb_root *tree,struct rb_node *rb_node =rb_first (tree);while (rb_node) { -double percent; chain = rb_entry(rb_node, struct callchain_node, rb_node); - percent = chain->hit *100.0 / total_samples; - ret +=fprintf (fp,"%.2f%% " , percent); + ret +=callchain_node__fprintf_value (chain, fp, total_samples); + ret +=fprintf (fp," " ); ret +=__callchain__fprintf_folded (fp, chain); ret +=fprintf (fp,"\n" );if (++entries_printed == callchain_param.print_limit)
tools/perf/util/callchain.c +25 -0
@@ -805,6 +805,31 @@ char *callchain_list__sym_name(struct callchain_list *cl,return bf; } +char *callchain_node__sprintf_value (struct callchain_node *node, +char *bf,size_t bfsize,u64 total) +{ +double percent =0.0 ; +u64 cumul =callchain_cumul_hits (node); + +if (total) + percent = cumul *100.0 / total; + +scnprintf (bf, bfsize,"%6.2f%%" , percent); +return bf; +} + +int callchain_node__fprintf_value (struct callchain_node *node, +FILE *fp,u64 total) +{ +double percent =0.0 ; +u64 cumul =callchain_cumul_hits (node); + +if (total) + percent = cumul *100.0 / total; + +return percent_color_fprintf (fp,"%.2f%%" , percent); +} +static void free_callchain_node (struct callchain_node *node) {struct callchain_list *list, *tmp;
tools/perf/util/callchain.h +4 -0
@@ -230,6 +230,10 @@ static inline int arch_skip_callchain_idx(struct thread *thread __maybe_unused,char *callchain_list__sym_name (struct callchain_list *cl,char *bf,size_t bfsize,bool show_dso); +char *callchain_node__sprintf_value (struct callchain_node *node, +char *bf,size_t bfsize,u64 total); +int callchain_node__fprintf_value (struct callchain_node *node, +FILE *fp,u64 total);void free_callchain (struct callchain_root *root);
Signature · 1 line
2.6.2
Re: [PATCH v3 2/4] perf callchain: Abstract callchain print function
On Tue, Nov 03, 2015 at 04:18:29PM +0900, Namhyung Kim wrote:
SNIP
Quoted 15 lines
tools/perf/ui/stdio/hist.c +3
-4while (rb_node) { -double percent; - chain = rb_entry(rb_node, struct callchain_node, rb_node); - percent = chain->hit *100.0 / total_samples; - ret =percent_color_fprintf (fp," %6.2f%%\n" , percent); + ret +=fprintf (fp," " ); + ret +=callchain_node__fprintf_value (chain, fp, total_samples); + ret +=fprintf (fp,"\n" ); ret +=__callchain__fprintf_flat (fp, chain, total_samples); ret +=fprintf (fp,"\n" );if (++entries_printed == callchain_param.print_limit)@@ -294,12 +294,11 @@ static size_t callchain__fprintf_folded(FILE *fp, struct rb_root *tree,struct rb_node *rb_node =rb_first (tree);
tools/perf/ui/stdio/hist.c static size_t callchain__fprintf_folded(FILE *fp, struct rb_root *tree, · line 301
Quoted 10 lines
tools/perf/ui/stdio/hist.c +2
-3while (rb_node) { -double percent; chain = rb_entry(rb_node, struct callchain_node, rb_node); - percent = chain->hit *100.0 / total_samples; - ret +=fprintf (fp,"%.2f%% " , percent); + ret +=callchain_node__fprintf_value (chain, fp, total_samples); + ret +=fprintf (fp," " );
hum, the callchain_node__fprintf_value gets hits as callchain_cumul_hits(node) which is 'node->hit + node->children_hit'
while the replaced code took only 'chain->hit'
not sure now which one we actualy want here..
jirka
Quoted 35 lines
tools/perf/ui/stdio/hist.c +0
-0ret +=__callchain__fprintf_folded (fp, chain); ret +=fprintf (fp,"\n" );if (++entries_printed == callchain_param.print_limit)tools/perf/util/callchain.c +24
-0@@ -805,6 +805,31 @@ char *callchain_list__sym_name(struct callchain_list *cl,return bf; } +char *callchain_node__sprintf_value (struct callchain_node *node, +char *bf,size_t bfsize,u64 total) +{ +double percent =0.0 ; +u64 cumul =callchain_cumul_hits (node); + +if (total) + percent = cumul *100.0 / total; + +scnprintf (bf, bfsize,"%6.2f%%" , percent); +return bf; +} + +int callchain_node__fprintf_value (struct callchain_node *node, +FILE *fp,u64 total) +{ +double percent =0.0 ; +u64 cumul =callchain_cumul_hits (node); + +if (total) + percent = cumul *100.0 / total; + +return percent_color_fprintf (fp,"%.2f%%" , percent); +}
SNIP
Namhyung Kim
maintainerRe: [PATCH v3 2/4] perf callchain: Abstract callchain print function
Hi Jiri,
Quoted 33 lines · Jiri Olsa
On Tue, Nov 03, 2015 at 04:18:29PM +0900, Namhyung Kim wrote:
SNIP
Quoted 15 lines
tools/perf/ui/stdio/hist.c +3
-4while (rb_node) { -double percent; - chain = rb_entry(rb_node, struct callchain_node, rb_node); - percent = chain->hit *100.0 / total_samples; - ret =percent_color_fprintf (fp," %6.2f%%\n" , percent); + ret +=fprintf (fp," " ); + ret +=callchain_node__fprintf_value (chain, fp, total_samples); + ret +=fprintf (fp,"\n" ); ret +=__callchain__fprintf_flat (fp, chain, total_samples); ret +=fprintf (fp,"\n" );if (++entries_printed == callchain_param.print_limit)@@ -294,12 +294,11 @@ static size_t callchain__fprintf_folded(FILE *fp, struct rb_root *tree,struct rb_node *rb_node =rb_first (tree);tools/perf/ui/stdio/hist.c static size_t callchain__fprintf_folded(FILE *fp, struct rb_root *tree, · line 301
Quoted 10 lines
tools/perf/ui/stdio/hist.c +2
-3while (rb_node) { -double percent; chain = rb_entry(rb_node, struct callchain_node, rb_node); - percent = chain->hit *100.0 / total_samples; - ret +=fprintf (fp,"%.2f%% " , percent); + ret +=callchain_node__fprintf_value (chain, fp, total_samples); + ret +=fprintf (fp," " );hum, the
callchain_node__fprintf_valuegets hits ascallchain_cumul_hits(node)which is 'node->hit+node->children_hit'
Quoted 3 lines
while the replaced code took only '
chain->hit'not sure now which one we actualy want here..
Right, this is somewhat confusing..
AFAICS cumul_hits is used for other output mode, but for folded output we should use hit without children_hit.
I added the check to use count in patch 4/4 but missed to use hit. Will update.
Thanks,
Namhyung
Quoted 38 lines
Quoted 36 lines
tools/perf/ui/stdio/hist.c +0
-0ret +=__callchain__fprintf_folded (fp, chain); ret +=fprintf (fp,"\n" );if (++entries_printed == callchain_param.print_limit)tools/perf/util/callchain.c +24
-0@@ -805,6 +805,31 @@ char *callchain_list__sym_name(struct callchain_list *cl,return bf; } +char *callchain_node__sprintf_value (struct callchain_node *node, +char *bf,size_t bfsize,u64 total) +{ +double percent =0.0 ; +u64 cumul =callchain_cumul_hits (node); + +if (total) + percent = cumul *100.0 / total; + +scnprintf (bf, bfsize,"%6.2f%%" , percent); +return bf; +} + +int callchain_node__fprintf_value (struct callchain_node *node, +FILE *fp,u64 total) +{ +double percent =0.0 ; +u64 cumul =callchain_cumul_hits (node); + +if (total) + percent = cumul *100.0 / total; + +return percent_color_fprintf (fp,"%.2f%%" , percent); +}SNIP
Namhyung Kim
maintainerPATCH v3 3/4 perf callchain: Add count fields to struct callchain_node
In reply to Namhyung KimIt's to track the count of occurrences of the callchains.
--- tools/perf/util/callchain.c | 10 ++++++++++ tools/perf/util/callchain.h | 7 +++++++ 2 files changed, 17 insertions(+)
tools/perf/util/callchain.c +10 -0
@@ -437,6 +437,8 @@ add_child(struct callchain_node *parent, new->children_hit =0 ; new->hit = period; + new->children_count =0 ; + new->count =1 ;return new; }
@@ -484,6 +486,9 @@ split_add_child(struct callchain_node *parent, parent->children_hit =callchain_cumul_hits (new); new->val_nr = parent->val_nr - idx_local; parent->val_nr = idx_local; + new->count = parent->count; + new->children_count = parent->children_count; + parent->children_count =callchain_cumul_counts (new);/* create a new child for the new branch if any */ if (idx_total < cursor->nr) {
@@ -494,6 +499,8 @@ split_add_child(struct callchain_node *parent, parent->hit =0 ; parent->children_hit += period; + parent->count =0 ; + parent->children_count +=1 ; node =callchain_cursor_current (cursor); new =add_child (parent, cursor, period);
@@ -516,6 +523,7 @@ split_add_child(struct callchain_node *parent,rb_insert_color (&new->rb_node_in, &parent->rb_root_in); }else { parent->hit = period; + parent->count =1 ; } }
@@ -562,6 +570,7 @@ append_chain_children(struct callchain_node *root, inc_children_hit: root->children_hit += period; + root->children_count++; } static int
@@ -614,6 +623,7 @@ append_chain(struct callchain_node *root,/* we match 100% of the path, increment the hit */ if (matches == root->val_nr && cursor->pos == cursor->nr) { root->hit += period; + root->count++;return 0 ; }
tools/perf/util/callchain.h +7 -0
@@ -60,6 +60,8 @@ struct callchain_node {struct rb_root rb_root_in;/* input tree of children */ struct rb_root rb_root;/* sorted output tree of children */ unsigned int val_nr; +unsigned int count; +unsigned int children_count;u64 hit;u64 children_hit; };
@@ -145,6 +147,11 @@ static inline u64 callchain_cumul_hits(struct callchain_node *node)return node->hit + node->children_hit; } +static inline int callchain_cumul_counts (struct callchain_node *node) +{ +return node->count + node->children_count; +} +int callchain_register_param (struct callchain_param *param); int callchain_append(struct callchain_root *root, struct callchain_cursor *cursor,
Signature · 1 line
2.6.2
Re: [PATCH v3 3/4] perf callchain: Add count fields to struct callchain_node
Quoted 4 lines · Namhyung Kim
It's to track the count of occurrences of the callchains.
Cc Brendan Gregg <[email protected]>Signed-off-by Namhyung Kim <[email protected]>
thanks,
jirka
Namhyung Kim
maintainerPATCH v3 4/4 perf report: Add callchain value option
In reply to Namhyung KimNow -g/--call-graph option supports how to display callchain values. Possible values are 'percent', 'period' and 'count'. The percent is same as before and it's the default behavior. The period displays the raw period value rather than the percentage. The count displays the number of occurrences.
$ perf report --no-children --stdio -g percent
...
39.93% swapper [kernel.vmlinux] [k] intel_idel
|
---intel_idle
cpuidle_enter_state
cpuidle_enter
call_cpuidle
cpu_startup_entry
|
|--28.63%-- start_secondary
|
--11.30%-- rest_init $ perf report --no-children --show-total-period --stdio -g period
...
39.93% 13018705 swapper [kernel.vmlinux] [k] intel_idel
|
---intel_idle
cpuidle_enter_state
cpuidle_enter
call_cpuidle
cpu_startup_entry
|
|--9334403-- start_secondary
|
--3684302-- rest_init $ perf report --no-children --show-nr-samples --stdio -g count
...
39.93% 80 swapper [kernel.vmlinux] [k] intel_idel
|
---intel_idle
cpuidle_enter_state
cpuidle_enter
call_cpuidle
cpu_startup_entry
|
|--57-- start_secondary
|
--23-- rest_init--- tools/perf/Documentation/perf-report.txt | 13 ++++--- tools/perf/builtin-report.c | 4 +-- tools/perf/ui/stdio/hist.c | 10 +++++- tools/perf/util/callchain.c | 60 +++++++++++++++++++++++++++----- tools/perf/util/callchain.h | 10 +++++- tools/perf/util/util.c | 3 +- 6 files changed, 83 insertions(+), 17 deletions(-)
tools/perf/Documentation/perf-report.txt +9 -4
@@ -170,11 +170,11 @@ OPTIONS Dump raw trace in ASCII. -g:: ---call-graph=<print_type,threshold[,print_limit],order,sort_key,branch>:: +--call-graph=<print_type,threshold[,print_limit],order,sort_key[,branch],value>:: Display call chains using type, min percent threshold, print limit, - call order, sort key and branch. Note that ordering of parameters is not - fixed so any parement can be given in an arbitraty order. One exception - is the print_limit which should be preceded by threshold. + call order, sort key, optional branch and value. Note that ordering of + parameters is not fixed so any parement can be given in an arbitraty order. + One exception is the print_limit which should be preceded by threshold. print_type can be either: - flat: single column, linear exposure of call chains.
@@ -204,6 +204,11 @@ OPTIONS - branch: include last branch information in callgraph when available. Usually more convenient to use --branch-history for this. + value can be: + - percent: diplay overhead percent (default) + - period: display event period + - count: display evnt count + --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
tools/perf/builtin-report.c +2 -2
@@ -625,7 +625,7 @@ parse_percent_limit(const struct option *opt, const char *str,return 0 ; } -#define CALLCHAIN_DEFAULT_OPT "graph,0.5,caller,function" +#define CALLCHAIN_DEFAULT_OPT "graph,0.5,caller,function,percent"const char report_callchain_help[] ="Display call graph (stack chain/backtrace):\n\n" CALLCHAIN_REPORT_HELP
@@ -708,7 +708,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)OPT_BOOLEAN ('x' ,"exclude-other" , &symbol_conf.exclude_other,"Only display entries with parent-match" ),OPT_CALLBACK_DEFAULT ('g' ,"call-graph" , &report, -"print_type,threshold[,print_limit],order,sort_key[,branch]" , +"print_type,threshold[,print_limit],order,sort_key[,branch],value" , report_callchain_help, &report_parse_callchain_opt, callchain_default_opt), OPT_BOOLEAN(0, "children", &symbol_conf.cumulate_callchain,
tools/perf/ui/stdio/hist.c +9 -1
@@ -81,13 +81,14 @@ static size_t __callchain__fprintf_graph(FILE *fp, struct rb_root *root, int depth_mask, int left_margin) {struct rb_node *node, *next; -struct callchain_node *child; +struct callchain_node *child =NULL ;struct callchain_list *chain;int new_depth_mask = depth_mask;u64 remaining;size_t ret =0 ;int i;uint entries_printed =0 ; +int cumul_count =0 ; remaining = total_samples;
@@ -99,6 +100,7 @@ static size_t __callchain__fprintf_graph(FILE *fp, struct rb_root *root, child = rb_entry(node, struct callchain_node, rb_node); cumul =callchain_cumul_hits (child); remaining -= cumul; + cumul_count +=callchain_cumul_counts (child);/* * The depth mask manages the output of pipes that show
@@ -148,6 +150,12 @@ static size_t __callchain__fprintf_graph(FILE *fp, struct rb_root *root,if (!rem_sq_bracket)return ret; +if (callchain_param.value ==CCVAL_COUNT && child && child->parent) { + rem_node.count = child->parent->children_count - cumul_count; +if (rem_node.count <=0 ) +return ret; + } + new_depth_mask &= ~(1 << (depth -1 )); ret += ipchain__fprintf_graph(fp, &rem_node, &rem_hits, depth, new_depth_mask, 0, total_samples,
tools/perf/util/callchain.c +52 -8
89 lines not on this page · raw message
tools/perf/util/callchain.h +9 -1
@@ -29,7 +29,8 @@HELP_PAD "print_limit:\tmaximum number of call graph entry (<number>)\n" \HELP_PAD "order:\t\tcall graph order (caller|callee)\n" \HELP_PAD "sort_key:\tcall graph sort key (function|address)\n" \ -HELP_PAD "branch:\t\tinclude last branch info to call graph (branch)\n" +HELP_PAD "branch:\t\tinclude last branch info to call graph (branch)\n" \ +HELP_PAD "value:\t\tcall graph value (percent|period|count)\n" enum perf_call_graph_mode { CALLCHAIN_NONE,
@@ -81,6 +82,12 @@ enum chain_key {CCKEY_ADDRESS }; +enum chain_value { +CCVAL_PERCENT , +CCVAL_PERIOD , +CCVAL_COUNT , +}; +struct callchain_param {bool enabled;enum perf_call_graph_mode record_mode;
@@ -93,6 +100,7 @@ struct callchain_param {bool order_set;enum chain_key key;bool branch_callstack; +enum chain_value value; };extern struct callchain_param callchain_param;
tools/perf/util/util.c +2 -1
@@ -20,7 +20,8 @@ struct callchain_param callchain_param = { .mode = CHAIN_GRAPH_ABS, .min_percent = 0.5, .order = ORDER_CALLEE, - .key = CCKEY_FUNCTION + .key = CCKEY_FUNCTION, + .value = CCVAL_PERCENT, };/*
Signature · 1 line
2.6.2
Re: [PATCH v3 4/4] perf report: Add callchain value option
Quoted 80 lines · Namhyung Kim
Now -g/--call-graph option supports how to display callchain values. Possible values are 'percent', 'period' and 'count'. The percent is same as before and it's the default behavior. The period displays the raw period value rather than the percentage. The count displays the number of occurrences.
$ perf report --no-children --stdio -g percent ... 39.93% swapper [kernel.vmlinux] [k] intel_idel | ---intel_idle cpuidle_enter_state cpuidle_enter call_cpuidle cpu_startup_entry | |--28.63%-- start_secondary | --11.30%-- rest_init$ perf report --no-children --show-total-period --stdio -g period ... 39.93% 13018705 swapper [kernel.vmlinux] [k] intel_idel | ---intel_idle cpuidle_enter_state cpuidle_enter call_cpuidle cpu_startup_entry | |--9334403-- start_secondary | --3684302-- rest_init$ perf report --no-children --show-nr-samples --stdio -g count ... 39.93% 80 swapper [kernel.vmlinux] [k] intel_idel | ---intel_idle cpuidle_enter_state cpuidle_enter call_cpuidle cpu_startup_entry | |--57-- start_secondary | --23-- rest_initCc Brendan Gregg <[email protected]>Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/Documentation/perf-report.txt | 13 ++++--- tools/perf/builtin-report.c | 4 +-- tools/perf/ui/stdio/hist.c | 10 +++++- tools/perf/util/callchain.c | 60 +++++++++++++++++++++++++++----- tools/perf/util/callchain.h | 10 +++++- tools/perf/util/util.c | 3 +- 6 files changed, 83 insertions(+), 17 deletions(-)tools/perf/Documentation/perf-report.txt +4
-4@@ -170,11 +170,11 @@ OPTIONS Dump raw trace in ASCII. -g:: ---call-graph=<print_type,threshold[,print_limit],order,sort_key,branch>:: +--call-graph=<print_type,threshold[,print_limit],order,sort_key[,branch],value>:: Display call chains using type, min percent threshold, print limit, - call order, sort key and branch. Note that ordering of parameters is not - fixed so any parement can be given in an arbitraty order. One exception - is the print_limit which should be preceded by threshold. + call order, sort key, optional branch and value. Note that ordering of + parameters is not fixed so any parement can be given in an arbitraty order. + One exception is the print_limit which should be preceded by threshold. print_type can be either: - flat: single column, linear exposure of call chains.
tools/perf/Documentation/perf-report.txt OPTIONS · line 210
Quoted 7 lines
tools/perf/Documentation/perf-report.txt +4
-0@@ -204,6 +204,11 @@ OPTIONS - branch: include last branch information in callgraph when available. Usually more convenient to use --branch-history for this. + value can be: + - percent: diplay overhead percent (default) + - period: display event period + - count: display evnt count
s/evnt/event/ ^^^^
jirka
Re: [PATCH v3 4/4] perf report: Add callchain value option
In reply to Namhyung KimOn Tue, Nov 03, 2015 at 04:18:31PM +0900, Namhyung Kim wrote:
SNIP
tools/perf/util/callchain.c char *callchain_node__sprintf_value(struct callchain_node *node, · line 846
Quoted 13 lines
tools/perf/util/callchain.c +5
-2@@ -819,12 +837,26 @@ char *callchain_node__sprintf_value(struct callchain_node *node, char *bf, size_t bfsize, u64 total) { double percent = 0.0; -u64 cumul =callchain_cumul_hits (node); +u64 period =callchain_cumul_hits (node); +int count =callchain_cumul_counts (node);if (total) - percent = cumul *100.0 / total; + percent = period *100.0 / total; +if (callchain_param.mode ==CHAIN_FOLDED ) + count = node->count;
this could be set/computed below in respective cases
Quoted 23 lines
tools/perf/util/callchain.c +13
-2-scnprintf (bf, bfsize,"%6.2f%%" , percent); +switch (callchain_param.value) { +case CCVAL_PERIOD : +scnprintf (bf, bfsize,"%" PRIu64, period); +break ; +case CCVAL_COUNT : +scnprintf (bf, bfsize,"%u" , count); +break ; +case CCVAL_PERCENT : +default : +scnprintf (bf, bfsize,"%.2f%%" , percent); +break ; + }return bf; }@@ -832,12 +864,24 @@ int callchain_node__fprintf_value(struct callchain_node *node, FILE *fp, u64 total) {double percent =0.0 ; -u64 cumul =callchain_cumul_hits (node); +u64 period =callchain_cumul_hits (node);
tools/perf/util/callchain.c int callchain_node__fprintf_value(struct callchain_node *node, · line 874
Quoted 10 lines
tools/perf/util/callchain.c +5
-3+int count =callchain_cumul_counts (node);if (total) - percent = cumul *100.0 / total; - -return percent_color_fprintf (fp,"%.2f%%" , percent); + percent = period *100.0 / total; +if (callchain_param.mode ==CHAIN_FOLDED ) + count = node->count; +
ditto
jirka
Quoted 12 lines
tools/perf/util/callchain.c +10
-0+switch (callchain_param.value) { +case CCVAL_PERIOD : +return fprintf (fp,"%" PRIu64, period); +case CCVAL_COUNT : +return fprintf (fp,"%u" , count); +case CCVAL_PERCENT : +default : +return percent_color_fprintf (fp,"%.2f%%" , percent); + } +return 0 ; }
SNIP
Namhyung Kim
maintainerRe: [PATCH v3 4/4] perf report: Add callchain value option
Quoted 12 lines · Jiri Olsa
On Tue, Nov 03, 2015 at 04:18:31PM +0900, Namhyung Kim wrote:
SNIP
Quoted 8 lines
tools/perf/util/callchain.c +2
-1@@ -819,12 +837,26 @@ char *callchain_node__sprintf_value(struct callchain_node *node, char *bf, size_t bfsize, u64 total) { double percent = 0.0; -u64 cumul =callchain_cumul_hits (node); +u64 period =callchain_cumul_hits (node); +int count =callchain_cumul_counts (node);
Quoted 7 lines
tools/perf/util/callchain.c char *callchain_node__sprintf_value(struct callchain_node *node, · line 846
Quoted 5 lines
tools/perf/util/callchain.c +3
-1if (total) - percent = cumul *100.0 / total; + percent = period *100.0 / total; +if (callchain_param.mode ==CHAIN_FOLDED ) + count = node->count;this could be set/computed below in respective cases
As you said, I need to check it for node->hit too. So I ended up having like following, does it look good to you?
double percent = 0.0;
u64 period = callchain_cumul_hits(node);
unsigned count = callchain_cumul_counts(node);
if (callchain_param.mode == CHAIN_FOLDED) {
period = node->hit;
count = node->count;
}
switch (callchain_param.value) {
case CCVAL_PERIOD:
scnprintf(bf, bfsize, "%"PRIu64, period);
break;
case CCVAL_COUNT:
scnprintf(bf, bfsize, "%u", count);
break;
case CCVAL_PERCENT:
default:
if (total)
percent = period * 100.0 / total;
scnprintf(bf, bfsize, "%.2f%%", percent);
break;
}
return bf;Thanks,
Namhyung
Quoted 53 lines
Quoted 24 lines
tools/perf/util/callchain.c +13
-2-scnprintf (bf, bfsize,"%6.2f%%" , percent); +switch (callchain_param.value) { +case CCVAL_PERIOD : +scnprintf (bf, bfsize,"%" PRIu64, period); +break ; +case CCVAL_COUNT : +scnprintf (bf, bfsize,"%u" , count); +break ; +case CCVAL_PERCENT : +default : +scnprintf (bf, bfsize,"%.2f%%" , percent); +break ; + }return bf; }@@ -832,12 +864,24 @@ int callchain_node__fprintf_value(struct callchain_node *node, FILE *fp, u64 total) {double percent =0.0 ; -u64 cumul =callchain_cumul_hits (node); +u64 period =callchain_cumul_hits (node);tools/perf/util/callchain.c int callchain_node__fprintf_value(struct callchain_node *node, · line 874
Quoted 10 lines
tools/perf/util/callchain.c +5
-3+int count =callchain_cumul_counts (node);if (total) - percent = cumul *100.0 / total; - -return percent_color_fprintf (fp,"%.2f%%" , percent); + percent = period *100.0 / total; +if (callchain_param.mode ==CHAIN_FOLDED ) + count = node->count; +ditto
jirka
Quoted 12 lines
tools/perf/util/callchain.c +10
-0+switch (callchain_param.value) { +case CCVAL_PERIOD : +return fprintf (fp,"%" PRIu64, period); +case CCVAL_COUNT : +return fprintf (fp,"%u" , count); +case CCVAL_PERCENT : +default : +return percent_color_fprintf (fp,"%.2f%%" , percent); + } +return 0 ; }SNIP
Re: [PATCH v3 4/4] perf report: Add callchain value option
Quoted 40 lines · Namhyung Kim
Quoted 12 lines · Jiri Olsa
On Tue, Nov 03, 2015 at 04:18:31PM +0900, Namhyung Kim wrote:
SNIP
Quoted 8 lines
tools/perf/util/callchain.c +2
-1@@ -819,12 +837,26 @@ char *callchain_node__sprintf_value(struct callchain_node *node, char *bf, size_t bfsize, u64 total) { double percent = 0.0; -u64 cumul =callchain_cumul_hits (node); +u64 period =callchain_cumul_hits (node); +int count =callchain_cumul_counts (node);Quoted 7 lines
tools/perf/util/callchain.c char *callchain_node__sprintf_value(struct callchain_node *node, · line 846
Quoted 5 lines
tools/perf/util/callchain.c +3
-1if (total) - percent = cumul *100.0 / total; + percent = period *100.0 / total; +if (callchain_param.mode ==CHAIN_FOLDED ) + count = node->count;this could be set/computed below in respective cases
As you said, I need to check it for
node->hittoo. So I ended up having like following, does it look good to you?double percent = 0.0; u64 period = callchain_cumul_hits(node); unsigned count = callchain_cumul_counts(node); if (callchain_param.mode == CHAIN_FOLDED) { period = node->hit; count = node->count; } switch (callchain_param.value) { case CCVAL_PERIOD: scnprintf(bf, bfsize, "%"PRIu64, period); break; case CCVAL_COUNT: scnprintf(bf, bfsize, "%u", count); break;
Quoted 8 lines
case CCVAL_PERCENT:
default:
if (total)
percent = period * 100.0 / total;
scnprintf(bf, bfsize, "%.2f%%", percent);
break;
}
return bf;seems ok, thanks
jirka