perf tools: Fix missing top level callchain
PATCH 1/3 perf tools: Fix missing top level callchain
While recursively printing the branches of each callchains, we forget to display the root. It is never printed.
Say we have:
symbol
f1
f2
|
-------- f3
| f4
|
---------f5
f6Actually we never see that, instead it displays:
symbol
|
--------- f3
| f4
|
--------- f5
f6However f1 is always the same than "symbol" and if we are sorting by symbols first then "symbol", f1 and f2 will be well aligned like in the above example, so displaying f1 looks redundant here.
But if we are sorting by something else first (dso, comm, etc...), displaying f1 doesn't look redundant but rather necessary because the symbol is not well aligned anymore with its callchain:
comm dso symbol
f1
f2
|
--------- [...]And we want the callchain to be obvious.
So we fix the bug by printing the root branch, but we also filter its first entry if we are sorting by symbols first.
--- tools/perf/builtin-report.c | 40 +++++++++++++++++++++++++++++++++------- tools/perf/util/sort.c | 10 +++++++--- tools/perf/util/sort.h | 1 + 3 files changed, 41 insertions(+), 10 deletions(-)
tools/perf/builtin-report.c +33 -7
@@ -122,8 +122,8 @@ static void init_rem_hits(void) }static size_t -callchain__fprintf_graph (FILE *fp,struct callchain_node *self, -u64 total_samples,int depth,int depth_mask) +__callchain__fprintf_graph (FILE *fp,struct callchain_node *self, +u64 total_samples,int depth,int depth_mask) {struct rb_node *node, *next;struct callchain_node *child;
@@ -174,9 +174,9 @@ callchain__fprintf_graph(FILE *fp, struct callchain_node *self, new_total, cumul); } - ret +=callchain__fprintf_graph (fp, child, new_total, - depth +1 , - new_depth_mask | (1 << depth)); + ret +=__callchain__fprintf_graph (fp, child, new_total, + depth +1 , + new_depth_mask | (1 << depth)); node = next; }
@@ -197,6 +197,33 @@ callchain__fprintf_graph(FILE *fp, struct callchain_node *self, }static size_t +callchain__fprintf_graph (FILE *fp,struct callchain_node *self, +u64 total_samples) +{ +struct callchain_list *chain; +int i =0 ; +int ret =0 ; + +list_for_each_entry (chain, &self->val, list) { +if (chain->ip >=PERF_CONTEXT_MAX ) +continue ; + +if (!i++ && sort_by_sym_first) +continue ; + +if (chain->sym) + ret +=fprintf (fp," %s\n" , chain->sym->name); +else + ret +=fprintf (fp," %p\n" , + (void *)(long )chain->ip); + } + + ret +=__callchain__fprintf_graph (fp, self, total_samples,1 ,1 ); + +return ret; +} + +static size_t callchain__fprintf_flat (FILE *fp,struct callchain_node *self,u64 total_samples) {
@@ -244,8 +271,7 @@ hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self,break ;case CHAIN_GRAPH_ABS :/* Falldown */ case CHAIN_GRAPH_REL : - ret +=callchain__fprintf_graph (fp, chain, - total_samples,1 ,1 ); + ret +=callchain__fprintf_graph (fp, chain, total_samples);case CHAIN_NONE :default :break ;
tools/perf/util/sort.c +7 -3
@@ -5,8 +5,9 @@ char default_parent_pattern[] = "^sys_|^do_page_fault";char *parent_pattern = default_parent_pattern;char default_sort_order[] ="comm,dso,symbol" ;char *sort_order = default_sort_order; -int sort__need_collapse =0 ; -int sort__has_parent =0 ; +int sort__need_collapse =0 ; +int sort__has_parent =0 ; +int sort_by_sym_first;unsigned int dsos__col_width;unsigned int comms__col_width;
@@ -265,6 +266,10 @@ int sort_dimension__add(const char *tok) sort__has_parent =1 ; } +if (list_empty (&hist_entry__sort_list) && + !strcmp (sd->name,"symbol" )) + sort_by_sym_first = true; +list_add_tail (&sd->entry->list, &hist_entry__sort_list); sd->taken =1 ;
@@ -273,4 +278,3 @@ int sort_dimension__add(const char *tok)return -ESRCH ; } -
tools/perf/util/sort.h +1 -0
@@ -39,6 +39,7 @@ extern struct sort_entry sort_parent;extern unsigned int dsos__col_width;extern unsigned int comms__col_width;extern unsigned int threads__col_width; +extern int sort_by_sym_first;struct hist_entry {struct rb_node rb_node;
Signature · 1 line
1.6.2.3
PATCH 2/3 perf tools: Bind callchains to the first sort dimension column
Currently, the callchains are displayed using a constant left margin. So depending on the current sort dimension configuration, callchains may appear to be well attached to the first sort dimension column field which is mostly the case, except when the first dimension of sorting is done by comm, because these are right aligned.
This patch binds the callchain to the first letter in the first column, whatever type of column it is (dso, comm, symbol).
Before:
0.80% perf [k] __lock_acquire
__lock_acquire
lock_acquire
|
|--58.33%-- _spin_lock
| |
| |--28.57%-- inotify_should_send_event
| | fsnotify
| | __fsnotify_parent
After:
0.80% perf [k] __lock_acquire
__lock_acquire
lock_acquire
|
|--58.33%-- _spin_lock
| |
| |--28.57%-- inotify_should_send_event
| | fsnotify
| | __fsnotify_parent
Also, for clarity, we don't put anymore the callchain as is but:
- If we have a top level ancestor in the callchain, start it with a first ascii hook.
Before:
0.80% perf [kernel] [k] __lock_acquire
__lock_acquire
lock_acquire
|
|--58.33%-- _spin_lock
| |
| |--28.57%-- inotify_should_send_event
| | fsnotify
[..] [..]After:
0.80% perf [kernel] [k] __lock_acquire
|
--- __lock_acquire
lock_acquire
|
|--58.33%-- _spin_lock
| |
| |--28.57%-- inotify_should_send_event
| | fsnotify
[..] [..]- Otherwise, if we have several top level ancestors, then display these like we did before:
1.69% Xorg
|
|--21.21%-- vread_hpet
| 0x7fffd85b46fc
| 0x7fffd85b494d
| 0x7f4fafb4e54d
|
|--15.15%-- exaOffscreenAlloc
|
|--9.09%-- I830WaitLpRing--- tools/perf/builtin-report.c | 82 +++++++++++++++++++++++++++++++++---------- tools/perf/util/sort.c | 18 +++++++-- tools/perf/util/sort.h | 10 +++++- tools/perf/util/thread.c | 11 ++++++ tools/perf/util/thread.h | 2 + 5 files changed, 99 insertions(+), 24 deletions(-)
tools/perf/builtin-report.c +63 -19
@@ -59,12 +59,28 @@ static struct perf_header *header;static u64 sample_type; -static size_t ipchain__fprintf_graph_line (FILE *fp,int depth,int depth_mask) + +static size_t +callchain__fprintf_left_margin (FILE *fp,int left_margin) +{ +int i; +int ret; + + ret =fprintf (fp," " ); + +for (i =0 ; i < left_margin; i++) + ret +=fprintf (fp," " ); + +return ret; +} + +static size_t ipchain__fprintf_graph_line (FILE *fp,int depth,int depth_mask, +int left_margin) {int i;size_t ret =0 ; - ret +=fprintf (fp,"%s" ," " ); + ret +=callchain__fprintf_left_margin (fp, left_margin);for (i =0 ; i < depth; i++)if (depth_mask & (1 << i))
@@ -79,12 +95,12 @@ static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask)static size_t ipchain__fprintf_graph (FILE *fp,struct callchain_list *chain,int depth,int depth_mask,int count,u64 total_samples, -int hits) +int hits,int left_margin) {int i;size_t ret =0 ; - ret +=fprintf (fp,"%s" ," " ); + ret +=callchain__fprintf_left_margin (fp, left_margin);for (i =0 ; i < depth; i++) {if (depth_mask & (1 << i)) ret +=fprintf (fp,"|" );
@@ -123,7 +139,8 @@ static void init_rem_hits(void)static size_t __callchain__fprintf_graph (FILE *fp,struct callchain_node *self, -u64 total_samples,int depth,int depth_mask) +u64 total_samples,int depth,int depth_mask, +int left_margin) {struct rb_node *node, *next;struct callchain_node *child;
@@ -164,7 +181,8 @@ __callchain__fprintf_graph(FILE *fp, struct callchain_node *self,* But we keep the older depth mask for the line seperator * to keep the level link until we reach the last child */ - ret +=ipchain__fprintf_graph_line (fp, depth, depth_mask); + ret +=ipchain__fprintf_graph_line (fp, depth, depth_mask, + left_margin); i =0 ;list_for_each_entry (chain, &child->val, list) {if (chain->ip >=PERF_CONTEXT_MAX )
@@ -172,11 +190,13 @@ __callchain__fprintf_graph(FILE *fp, struct callchain_node *self, ret +=ipchain__fprintf_graph (fp, chain, depth, new_depth_mask, i++, new_total, - cumul); + cumul, + left_margin); } ret +=__callchain__fprintf_graph (fp, child, new_total, depth +1 , - new_depth_mask | (1 << depth)); + new_depth_mask | (1 << depth), + left_margin); node = next; }
@@ -190,17 +210,19 @@ __callchain__fprintf_graph(FILE *fp, struct callchain_node *self, ret +=ipchain__fprintf_graph (fp, &rem_hits, depth, new_depth_mask,0 , new_total, - remaining); + remaining, left_margin); }return ret; } +static size_t callchain__fprintf_graph (FILE *fp,struct callchain_node *self, -u64 total_samples) +u64 total_samples,int left_margin) {struct callchain_list *chain; +bool printed = false;int i =0 ;int ret =0 ;
@@ -208,17 +230,27 @@ callchain__fprintf_graph(FILE *fp, struct callchain_node *self,if (chain->ip >=PERF_CONTEXT_MAX )continue ; -if (!i++ && sort_by_sym_first) +if (!i++ && sort__first_dimension ==SORT_SYM )continue ; +if (!printed) { + ret +=callchain__fprintf_left_margin (fp, left_margin); + ret +=fprintf (fp,"|\n" ); + ret +=callchain__fprintf_left_margin (fp, left_margin); + ret +=fprintf (fp,"---" ); + + left_margin +=3 ; + printed = true; + }else + ret +=callchain__fprintf_left_margin (fp, left_margin); +if (chain->sym) - ret +=fprintf (fp," %s\n" , chain->sym->name); + ret +=fprintf (fp," %s\n" , chain->sym->name);else - ret +=fprintf (fp," %p\n" , - (void *)(long )chain->ip); + ret +=fprintf (fp," %p\n" , (void *)(long )chain->ip); } - ret +=__callchain__fprintf_graph (fp, self, total_samples,1 ,1 ); + ret +=__callchain__fprintf_graph (fp, self, total_samples,1 ,1 , left_margin);return ret; }
@@ -251,7 +283,7 @@ callchain__fprintf_flat(FILE *fp, struct callchain_node *self,static size_t hist_entry_callchain__fprintf (FILE *fp,struct hist_entry *self, -u64 total_samples) +u64 total_samples,int left_margin) {struct rb_node *rb_node;struct callchain_node *chain;
@@ -271,7 +303,8 @@ hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self,break ;case CHAIN_GRAPH_ABS :/* Falldown */ case CHAIN_GRAPH_REL : - ret +=callchain__fprintf_graph (fp, chain, total_samples); + ret +=callchain__fprintf_graph (fp, chain, total_samples, + left_margin);case CHAIN_NONE :default :break ;
@@ -316,8 +349,19 @@ hist_entry__fprintf(FILE *fp, struct hist_entry *self, u64 total_samples) ret +=fprintf (fp,"\n" ); -if (callchain) -hist_entry_callchain__fprintf (fp, self, total_samples); +if (callchain) { +int left_margin =0 ; + +if (sort__first_dimension ==SORT_COMM ) { + se =list_first_entry (&hist_entry__sort_list,typeof (*se), + list); + left_margin = se->width ? *se->width :0 ; + left_margin -=thread__comm_len (self->thread); + } + +hist_entry_callchain__fprintf (fp, self, total_samples, + left_margin); + }return ret; }
tools/perf/util/sort.c +14 -4
@@ -7,7 +7,8 @@ char default_sort_order[] = "comm,dso,symbol";char *sort_order = default_sort_order;int sort__need_collapse =0 ;int sort__has_parent =0 ; -int sort_by_sym_first; + +enum sort_type sort__first_dimension;unsigned int dsos__col_width;unsigned int comms__col_width;
@@ -266,9 +267,18 @@ int sort_dimension__add(const char *tok) sort__has_parent =1 ; } -if (list_empty (&hist_entry__sort_list) && - !strcmp (sd->name,"symbol" )) - sort_by_sym_first = true; +if (list_empty (&hist_entry__sort_list)) { +if (!strcmp (sd->name,"pid" )) + sort__first_dimension =SORT_PID ; +else if (!strcmp (sd->name,"comm" )) + sort__first_dimension =SORT_COMM ; +else if (!strcmp (sd->name,"dso" )) + sort__first_dimension =SORT_DSO ; +else if (!strcmp (sd->name,"symbol" )) + sort__first_dimension =SORT_SYM ; +else if (!strcmp (sd->name,"parent" )) + sort__first_dimension =SORT_PARENT ; + }list_add_tail (&sd->entry->list, &hist_entry__sort_list); sd->taken =1 ;
tools/perf/util/sort.h +9 -1
@@ -39,7 +39,7 @@ extern struct sort_entry sort_parent;extern unsigned int dsos__col_width;extern unsigned int comms__col_width;extern unsigned int threads__col_width; -extern int sort_by_sym_first; +extern enum sort_type sort__first_dimension;struct hist_entry {struct rb_node rb_node;
@@ -54,6 +54,14 @@ struct hist_entry {struct rb_root sorted_chain; }; +enum sort_type { +SORT_PID , +SORT_COMM , +SORT_DSO , +SORT_SYM , +SORT_PARENT +}; +/* * configurable sorting bits */
tools/perf/util/thread.c +11 -0
@@ -33,6 +33,17 @@ int thread__set_comm(struct thread *self, const char *comm)return self->comm ?0 : -ENOMEM ; } +int thread__comm_len (struct thread *self) +{ +if (!self->comm_len) { +if (!self->comm) +return 0 ; + self->comm_len =strlen (self->comm); + } + +return self->comm_len; +} +static size_t thread__fprintf (struct thread *self,FILE *fp) {struct rb_node *nd;
tools/perf/util/thread.h +2 -0
@@ -12,9 +12,11 @@ struct thread {pid_t pid;char shortname[3 ];char *comm; +int comm_len; };int thread__set_comm (struct thread *self,const char *comm); +int thread__comm_len (struct thread *self);struct thread *threads__findnew (pid_t pid);struct thread *register_idle_thread (void );void thread__insert_map (struct thread *self,struct map *map);
Signature · 1 line
1.6.2.3
[tip:branch?] perf tools: Bind callchains to the first sort dimension column
Commit-ID: a4fb581b15949cfd10b64c8af37bc106e95307f3 Gitweb: http://git.kernel.org/tip/a4fb581b15949cfd10b64c8af37bc106e95307f3 Author: Frederic Weisbecker <[email protected]> AuthorDate: Thu, 22 Oct 2009 23:23:23 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Fri, 23 Oct 2009 07:55:18 +0200
perf tools: Bind callchains to the first sort dimension column
Currently, the callchains are displayed using a constant left margin. So depending on the current sort dimension configuration, callchains may appear to be well attached to the first sort dimension column field which is mostly the case, except when the first dimension of sorting is done by comm, because these are right aligned.
This patch binds the callchain to the first letter in the first column, whatever type of column it is (dso, comm, symbol). Before:
0.80% perf [k] __lock_acquire
__lock_acquire
lock_acquire
|
|--58.33%-- _spin_lock
| |
| |--28.57%-- inotify_should_send_event
| | fsnotify
| | __fsnotify_parent
After:
0.80% perf [k] __lock_acquire
__lock_acquire
lock_acquire
|
|--58.33%-- _spin_lock
| |
| |--28.57%-- inotify_should_send_event
| | fsnotify
| | __fsnotify_parent
Also, for clarity, we don't put anymore the callchain as is but:
- If we have a top level ancestor in the callchain, start it with a first ascii hook.
Before:
0.80% perf [kernel] [k] __lock_acquire
__lock_acquire
lock_acquire
|
|--58.33%-- _spin_lock
| |
| |--28.57%-- inotify_should_send_event
| | fsnotify
[..] [..]After:
0.80% perf [kernel] [k] __lock_acquire
|
--- __lock_acquire
lock_acquire
|
|--58.33%-- _spin_lock
| |
| |--28.57%-- inotify_should_send_event
| | fsnotify
[..] [..]- Otherwise, if we have several top level ancestors, then display these like we did before:
1.69% Xorg
|
|--21.21%-- vread_hpet
| 0x7fffd85b46fc
| 0x7fffd85b494d
| 0x7f4fafb4e54d
|
|--15.15%-- exaOffscreenAlloc
|
|--9.09%-- I830WaitLpRingLKML-Reference: <[email protected]>
--- tools/perf/builtin-report.c | 82 +++++++++++++++++++++++++++++++++---------- tools/perf/util/sort.c | 18 +++++++-- tools/perf/util/sort.h | 10 +++++- tools/perf/util/thread.c | 11 ++++++ tools/perf/util/thread.h | 2 + 5 files changed, 99 insertions(+), 24 deletions(-)
tools/perf/builtin-report.c +63 -19
@@ -59,12 +59,28 @@ static struct perf_header *header;static u64 sample_type; -static size_t ipchain__fprintf_graph_line (FILE *fp,int depth,int depth_mask) + +static size_t +callchain__fprintf_left_margin (FILE *fp,int left_margin) +{ +int i; +int ret; + + ret =fprintf (fp," " ); + +for (i =0 ; i < left_margin; i++) + ret +=fprintf (fp," " ); + +return ret; +} + +static size_t ipchain__fprintf_graph_line (FILE *fp,int depth,int depth_mask, +int left_margin) {int i;size_t ret =0 ; - ret +=fprintf (fp,"%s" ," " ); + ret +=callchain__fprintf_left_margin (fp, left_margin);for (i =0 ; i < depth; i++)if (depth_mask & (1 << i))
@@ -79,12 +95,12 @@ static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask)static size_t ipchain__fprintf_graph (FILE *fp,struct callchain_list *chain,int depth,int depth_mask,int count,u64 total_samples, -int hits) +int hits,int left_margin) {int i;size_t ret =0 ; - ret +=fprintf (fp,"%s" ," " ); + ret +=callchain__fprintf_left_margin (fp, left_margin);for (i =0 ; i < depth; i++) {if (depth_mask & (1 << i)) ret +=fprintf (fp,"|" );
@@ -123,7 +139,8 @@ static void init_rem_hits(void)static size_t __callchain__fprintf_graph (FILE *fp,struct callchain_node *self, -u64 total_samples,int depth,int depth_mask) +u64 total_samples,int depth,int depth_mask, +int left_margin) {struct rb_node *node, *next;struct callchain_node *child;
@@ -164,7 +181,8 @@ __callchain__fprintf_graph(FILE *fp, struct callchain_node *self,* But we keep the older depth mask for the line seperator * to keep the level link until we reach the last child */ - ret +=ipchain__fprintf_graph_line (fp, depth, depth_mask); + ret +=ipchain__fprintf_graph_line (fp, depth, depth_mask, + left_margin); i =0 ;list_for_each_entry (chain, &child->val, list) {if (chain->ip >=PERF_CONTEXT_MAX )
@@ -172,11 +190,13 @@ __callchain__fprintf_graph(FILE *fp, struct callchain_node *self, ret +=ipchain__fprintf_graph (fp, chain, depth, new_depth_mask, i++, new_total, - cumul); + cumul, + left_margin); } ret +=__callchain__fprintf_graph (fp, child, new_total, depth +1 , - new_depth_mask | (1 << depth)); + new_depth_mask | (1 << depth), + left_margin); node = next; }
@@ -190,17 +210,19 @@ __callchain__fprintf_graph(FILE *fp, struct callchain_node *self, ret +=ipchain__fprintf_graph (fp, &rem_hits, depth, new_depth_mask,0 , new_total, - remaining); + remaining, left_margin); }return ret; } +static size_t callchain__fprintf_graph (FILE *fp,struct callchain_node *self, -u64 total_samples) +u64 total_samples,int left_margin) {struct callchain_list *chain; +bool printed = false;int i =0 ;int ret =0 ;
@@ -208,17 +230,27 @@ callchain__fprintf_graph(FILE *fp, struct callchain_node *self,if (chain->ip >=PERF_CONTEXT_MAX )continue ; -if (!i++ && sort_by_sym_first) +if (!i++ && sort__first_dimension ==SORT_SYM )continue ; +if (!printed) { + ret +=callchain__fprintf_left_margin (fp, left_margin); + ret +=fprintf (fp,"|\n" ); + ret +=callchain__fprintf_left_margin (fp, left_margin); + ret +=fprintf (fp,"---" ); + + left_margin +=3 ; + printed = true; + }else + ret +=callchain__fprintf_left_margin (fp, left_margin); +if (chain->sym) - ret +=fprintf (fp," %s\n" , chain->sym->name); + ret +=fprintf (fp," %s\n" , chain->sym->name);else - ret +=fprintf (fp," %p\n" , - (void *)(long )chain->ip); + ret +=fprintf (fp," %p\n" , (void *)(long )chain->ip); } - ret +=__callchain__fprintf_graph (fp, self, total_samples,1 ,1 ); + ret +=__callchain__fprintf_graph (fp, self, total_samples,1 ,1 , left_margin);return ret; }
@@ -251,7 +283,7 @@ callchain__fprintf_flat(FILE *fp, struct callchain_node *self,static size_t hist_entry_callchain__fprintf (FILE *fp,struct hist_entry *self, -u64 total_samples) +u64 total_samples,int left_margin) {struct rb_node *rb_node;struct callchain_node *chain;
@@ -271,7 +303,8 @@ hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self,break ;case CHAIN_GRAPH_ABS :/* Falldown */ case CHAIN_GRAPH_REL : - ret +=callchain__fprintf_graph (fp, chain, total_samples); + ret +=callchain__fprintf_graph (fp, chain, total_samples, + left_margin);case CHAIN_NONE :default :break ;
@@ -316,8 +349,19 @@ hist_entry__fprintf(FILE *fp, struct hist_entry *self, u64 total_samples) ret +=fprintf (fp,"\n" ); -if (callchain) -hist_entry_callchain__fprintf (fp, self, total_samples); +if (callchain) { +int left_margin =0 ; + +if (sort__first_dimension ==SORT_COMM ) { + se =list_first_entry (&hist_entry__sort_list,typeof (*se), + list); + left_margin = se->width ? *se->width :0 ; + left_margin -=thread__comm_len (self->thread); + } + +hist_entry_callchain__fprintf (fp, self, total_samples, + left_margin); + }return ret; }
tools/perf/util/sort.c +14 -4
@@ -7,7 +7,8 @@ char default_sort_order[] = "comm,dso,symbol";char *sort_order = default_sort_order;int sort__need_collapse =0 ;int sort__has_parent =0 ; -int sort_by_sym_first; + +enum sort_type sort__first_dimension;unsigned int dsos__col_width;unsigned int comms__col_width;
@@ -266,9 +267,18 @@ int sort_dimension__add(const char *tok) sort__has_parent =1 ; } -if (list_empty (&hist_entry__sort_list) && - !strcmp (sd->name,"symbol" )) - sort_by_sym_first = true; +if (list_empty (&hist_entry__sort_list)) { +if (!strcmp (sd->name,"pid" )) + sort__first_dimension =SORT_PID ; +else if (!strcmp (sd->name,"comm" )) + sort__first_dimension =SORT_COMM ; +else if (!strcmp (sd->name,"dso" )) + sort__first_dimension =SORT_DSO ; +else if (!strcmp (sd->name,"symbol" )) + sort__first_dimension =SORT_SYM ; +else if (!strcmp (sd->name,"parent" )) + sort__first_dimension =SORT_PARENT ; + }list_add_tail (&sd->entry->list, &hist_entry__sort_list); sd->taken =1 ;
tools/perf/util/sort.h +9 -1
@@ -39,7 +39,7 @@ extern struct sort_entry sort_parent;extern unsigned int dsos__col_width;extern unsigned int comms__col_width;extern unsigned int threads__col_width; -extern int sort_by_sym_first; +extern enum sort_type sort__first_dimension;struct hist_entry {struct rb_node rb_node;
@@ -54,6 +54,14 @@ struct hist_entry {struct rb_root sorted_chain; }; +enum sort_type { +SORT_PID , +SORT_COMM , +SORT_DSO , +SORT_SYM , +SORT_PARENT +}; +/* * configurable sorting bits */
tools/perf/util/thread.c +11 -0
@@ -33,6 +33,17 @@ int thread__set_comm(struct thread *self, const char *comm)return self->comm ?0 : -ENOMEM ; } +int thread__comm_len (struct thread *self) +{ +if (!self->comm_len) { +if (!self->comm) +return 0 ; + self->comm_len =strlen (self->comm); + } + +return self->comm_len; +} +static size_t thread__fprintf (struct thread *self,FILE *fp) {struct rb_node *nd;
tools/perf/util/thread.h +2 -0
@@ -12,9 +12,11 @@ struct thread {pid_t pid;char shortname[3 ];char *comm; +int comm_len; };int thread__set_comm (struct thread *self,const char *comm); +int thread__comm_len (struct thread *self);struct thread *threads__findnew (pid_t pid);struct thread *register_idle_thread (void );void thread__insert_map (struct thread *self,struct map *map);
PATCH 3/3 perf tools: Drop asm/tytes.h wrapper
In reply to Frederic WeisbeckerWrapping the kernel headers is dangerous when it comes to arch headers. Once we wrap asm/tytes.h, it will also replace the glibc asm/tytes.h, not only the kernel one.
This results in build errors on some machines.
Drop this wrapper and do its work from linux/types.h wrapper, also the glibc asm/types.h can already handle most of the type definition it was doing (typedef __u64, __u32, etc...).
Todo: Check the others asm/*.h wrappers to prevent from other conflicts.
--- tools/perf/Makefile | 1 - tools/perf/util/include/asm/bitops.h | 12 ++++++++++++ tools/perf/util/include/asm/byteorder.h | 2 +- tools/perf/util/include/asm/types.h | 17 ----------------- tools/perf/util/include/linux/types.h | 2 ++ 5 files changed, 15 insertions(+), 19 deletions(-) delete mode 100644 tools/perf/util/include/asm/types.h
tools/perf/Makefile +0 -1
@@ -353,7 +353,6 @@ LIB_H += util/include/asm/bitops.h LIB_H += util/include/asm/byteorder.h LIB_H += util/include/asm/swab.h LIB_H += util/include/asm/system.h -LIB_H += util/include/asm/types.h LIB_H += util/include/asm/uaccess.h LIB_H += perf.h LIB_H += util/event.h
tools/perf/util/include/asm/bitops.h +12 -0
@@ -1,6 +1,18 @@ +#ifndef _PERF_ASM_BITOPS_H_ +#define _PERF_ASM_BITOPS_H_ + +#include <sys/types.h> +#include "../../types.h" +#include <linux/compiler.h> + +/* CHECKME: Not sure both always match */ +#define BITS_PER_LONG __WORDSIZE +#include "../../../../include/asm-generic/bitops/__fls.h" #include "../../../../include/asm-generic/bitops/fls.h" #include "../../../../include/asm-generic/bitops/fls64.h" #include "../../../../include/asm-generic/bitops/__ffs.h" #include "../../../../include/asm-generic/bitops/ffz.h" #include "../../../../include/asm-generic/bitops/hweight.h" + +#endif
tools/perf/util/include/asm/byteorder.h +1 -1
@@ -1,2 +1,2 @@ -#include "../asm/types.h" +#include <asm/types.h> #include "../../../../include/linux/swab.h"
tools/perf/util/include/asm/types.h deleted +0 -17
@@ -1,17 +0,0 @@ -#ifndef PERF_ASM_TYPES_H_ -#define PERF_ASM_TYPES_H_ - -#include <linux/compiler.h> -#include "../../types.h" -#include <sys/types.h> - -/* CHECKME: Not sure both always match */ -#define BITS_PER_LONG __WORDSIZE - -typedef u64 __u64 ; -typedef u32 __u32 ; -typedef u16 __u16 ; -typedef u8 __u8 ; -typedef s64 __s64 ; - -#endif /* PERF_ASM_TYPES_H_ */
tools/perf/util/include/linux/types.h +2 -0
@@ -1,6 +1,8 @@#ifndef _PERF_LINUX_TYPES_H_#define _PERF_LINUX_TYPES_H_ +#include <asm/types.h> +#define DECLARE_BITMAP (name,bits) \ unsigned long name[BITS_TO_LONGS(bits)]
Signature · 1 line
1.6.2.3
[tip:branch?] perf tools: Drop asm/types.h wrapper
Commit-ID: 802da5f2289bbe363acef084805195c11f453c48 Gitweb: http://git.kernel.org/tip/802da5f2289bbe363acef084805195c11f453c48 Author: Frederic Weisbecker <[email protected]> AuthorDate: Thu, 22 Oct 2009 23:23:24 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Fri, 23 Oct 2009 07:55:19 +0200
perf tools: Drop asm/types.h wrapper
Wrapping the kernel headers is dangerous when it comes to arch headers. Once we wrap asm/types.h, it will also replace the glibc asm/types.h, not only the kernel one.
This results in build errors on some machines.
Drop this wrapper and do its work from linux/types.h wrapper, also the glibc asm/types.h can already handle most of the type definition it was doing (typedef __u64, __u32, etc...).
Todo: Check the others asm/*.h wrappers to prevent from other conflicts.
LKML-Reference: <[email protected]>
--- tools/perf/Makefile | 1 - tools/perf/util/include/asm/bitops.h | 12 ++++++++++++ tools/perf/util/include/asm/byteorder.h | 2 +- tools/perf/util/include/asm/types.h | 17 ----------------- tools/perf/util/include/linux/types.h | 2 ++ 5 files changed, 15 insertions(+), 19 deletions(-)
tools/perf/Makefile +0 -1
@@ -352,7 +352,6 @@ LIB_H += util/include/asm/bitops.h LIB_H += util/include/asm/byteorder.h LIB_H += util/include/asm/swab.h LIB_H += util/include/asm/system.h -LIB_H += util/include/asm/types.h LIB_H += util/include/asm/uaccess.h LIB_H += perf.h LIB_H += util/event.h
tools/perf/util/include/asm/bitops.h +12 -0
@@ -1,6 +1,18 @@ +#ifndef _PERF_ASM_BITOPS_H_ +#define _PERF_ASM_BITOPS_H_ + +#include <sys/types.h> +#include "../../types.h" +#include <linux/compiler.h> + +/* CHECKME: Not sure both always match */ +#define BITS_PER_LONG __WORDSIZE +#include "../../../../include/asm-generic/bitops/__fls.h" #include "../../../../include/asm-generic/bitops/fls.h" #include "../../../../include/asm-generic/bitops/fls64.h" #include "../../../../include/asm-generic/bitops/__ffs.h" #include "../../../../include/asm-generic/bitops/ffz.h" #include "../../../../include/asm-generic/bitops/hweight.h" + +#endif
tools/perf/util/include/asm/byteorder.h +1 -1
@@ -1,2 +1,2 @@ -#include "../asm/types.h" +#include <asm/types.h> #include "../../../../include/linux/swab.h"
tools/perf/util/include/asm/types.h deleted +0 -17
@@ -1,17 +0,0 @@ -#ifndef PERF_ASM_TYPES_H_ -#define PERF_ASM_TYPES_H_ - -#include <linux/compiler.h> -#include "../../types.h" -#include <sys/types.h> - -/* CHECKME: Not sure both always match */ -#define BITS_PER_LONG __WORDSIZE - -typedef u64 __u64 ; -typedef u32 __u32 ; -typedef u16 __u16 ; -typedef u8 __u8 ; -typedef s64 __s64 ; - -#endif /* PERF_ASM_TYPES_H_ */
tools/perf/util/include/linux/types.h +2 -0
@@ -1,6 +1,8 @@#ifndef _PERF_LINUX_TYPES_H_#define _PERF_LINUX_TYPES_H_ +#include <asm/types.h> +#define DECLARE_BITMAP (name,bits) \ unsigned long name[BITS_TO_LONGS(bits)]
Commit-ID: af0a6fa46388e1e0c2d1a672aad84f8f6ef0b20b Gitweb: http://git.kernel.org/tip/af0a6fa46388e1e0c2d1a672aad84f8f6ef0b20b Author: Frederic Weisbecker <[email protected]> AuthorDate: Thu, 22 Oct 2009 23:23:22 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Fri, 23 Oct 2009 07:55:16 +0200
perf tools: Fix missing top level callchain
While recursively printing the branches of each callchains, we forget to display the root. It is never printed.
Say we have:
symbol
f1
f2
|
-------- f3
| f4
|
---------f5
f6Actually we never see that, instead it displays:
symbol
|
--------- f3
| f4
|
--------- f5
f6However f1 is always the same than "symbol" and if we are sorting by symbols first then "symbol", f1 and f2 will be well aligned like in the above example, so displaying f1 looks redundant here.
But if we are sorting by something else first (dso, comm, etc...), displaying f1 doesn't look redundant but rather necessary because the symbol is not well aligned anymore with its callchain:
comm dso symbol
f1
f2
|
--------- [...]And we want the callchain to be obvious.
So we fix the bug by printing the root branch, but we also filter its first entry if we are sorting by symbols first.
LKML-Reference: <[email protected]>
--- tools/perf/builtin-report.c | 40 +++++++++++++++++++++++++++++++++------- tools/perf/util/sort.c | 10 +++++++--- tools/perf/util/sort.h | 1 + 3 files changed, 41 insertions(+), 10 deletions(-)
tools/perf/builtin-report.c +33 -7
@@ -122,8 +122,8 @@ static void init_rem_hits(void) }static size_t -callchain__fprintf_graph (FILE *fp,struct callchain_node *self, -u64 total_samples,int depth,int depth_mask) +__callchain__fprintf_graph (FILE *fp,struct callchain_node *self, +u64 total_samples,int depth,int depth_mask) {struct rb_node *node, *next;struct callchain_node *child;
@@ -174,9 +174,9 @@ callchain__fprintf_graph(FILE *fp, struct callchain_node *self, new_total, cumul); } - ret +=callchain__fprintf_graph (fp, child, new_total, - depth +1 , - new_depth_mask | (1 << depth)); + ret +=__callchain__fprintf_graph (fp, child, new_total, + depth +1 , + new_depth_mask | (1 << depth)); node = next; }
@@ -197,6 +197,33 @@ callchain__fprintf_graph(FILE *fp, struct callchain_node *self, }static size_t +callchain__fprintf_graph (FILE *fp,struct callchain_node *self, +u64 total_samples) +{ +struct callchain_list *chain; +int i =0 ; +int ret =0 ; + +list_for_each_entry (chain, &self->val, list) { +if (chain->ip >=PERF_CONTEXT_MAX ) +continue ; + +if (!i++ && sort_by_sym_first) +continue ; + +if (chain->sym) + ret +=fprintf (fp," %s\n" , chain->sym->name); +else + ret +=fprintf (fp," %p\n" , + (void *)(long )chain->ip); + } + + ret +=__callchain__fprintf_graph (fp, self, total_samples,1 ,1 ); + +return ret; +} + +static size_t callchain__fprintf_flat (FILE *fp,struct callchain_node *self,u64 total_samples) {
@@ -244,8 +271,7 @@ hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self,break ;case CHAIN_GRAPH_ABS :/* Falldown */ case CHAIN_GRAPH_REL : - ret +=callchain__fprintf_graph (fp, chain, - total_samples,1 ,1 ); + ret +=callchain__fprintf_graph (fp, chain, total_samples);case CHAIN_NONE :default :break ;
tools/perf/util/sort.c +7 -3
@@ -5,8 +5,9 @@ char default_parent_pattern[] = "^sys_|^do_page_fault";char *parent_pattern = default_parent_pattern;char default_sort_order[] ="comm,dso,symbol" ;char *sort_order = default_sort_order; -int sort__need_collapse =0 ; -int sort__has_parent =0 ; +int sort__need_collapse =0 ; +int sort__has_parent =0 ; +int sort_by_sym_first;unsigned int dsos__col_width;unsigned int comms__col_width;
@@ -265,6 +266,10 @@ int sort_dimension__add(const char *tok) sort__has_parent =1 ; } +if (list_empty (&hist_entry__sort_list) && + !strcmp (sd->name,"symbol" )) + sort_by_sym_first = true; +list_add_tail (&sd->entry->list, &hist_entry__sort_list); sd->taken =1 ;
@@ -273,4 +278,3 @@ int sort_dimension__add(const char *tok)return -ESRCH ; } -
tools/perf/util/sort.h +1 -0
@@ -39,6 +39,7 @@ extern struct sort_entry sort_parent;extern unsigned int dsos__col_width;extern unsigned int comms__col_width;extern unsigned int threads__col_width; +extern int sort_by_sym_first;struct hist_entry {struct rb_node rb_node;