perf sort: Make column width code per hists instance
Commit-ID: 8a6c5b261c1188379469807d84bfb1365d0f6823 Gitweb: http://git.kernel.org/tip/8a6c5b261c1188379469807d84bfb1365d0f6823 Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Tue, 20 Jul 2010 14:42:52 -0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 23 Jul 2010 08:55:59 -0300
perf sort: Make column width code per hists instance
They were globals, and since we support multiple hists and sessions at the same time, it doesn't make sense to calculate those values considereing all symbols in all sessions.
Cc: Frederic Weisbecker <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
LKML-Reference: <new-submission>
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
--- tools/perf/util/event.c | 34 ++++++------- tools/perf/util/hist.c | 115 +++++++++++++++++++++++++++++++-------------- tools/perf/util/hist.h | 27 ++++++++-- tools/perf/util/newt.c | 9 ++-- tools/perf/util/sort.c | 17 +++---- tools/perf/util/sort.h | 6 +-- tools/perf/util/symbol.c | 9 ++++ tools/perf/util/symbol.h | 2 + 8 files changed, 140 insertions(+), 79 deletions(-)
tools/perf/util/event.c +16 -18
@@ -340,30 +340,29 @@ int event__synthesize_kernel_mmap(event__handler_t process,return process (&ev, session); } -static void thread__comm_adjust (struct thread *self) +static void thread__comm_adjust (struct thread *self,struct hists *hists) {char *comm = self->comm;if (!symbol_conf.col_width_list_str && !symbol_conf.field_sep && (!symbol_conf.comm_list ||strlist__has_entry (symbol_conf.comm_list, comm))) { -unsigned int slen =strlen (comm); +u16 slen =strlen (comm); -if (slen > comms__col_width) { - comms__col_width = slen; - threads__col_width = slen +6 ; - } +if (hists__new_col_len (hists,HISTC_COMM , slen)) +hists__set_col_len (hists,HISTC_THREAD , slen +6 ); } } -static int thread__set_comm_adjust (struct thread *self,const char *comm) +static int thread__set_comm_adjust (struct thread *self,const char *comm, +struct hists *hists) {int ret =thread__set_comm (self, comm);if (ret)return ret; -thread__comm_adjust (self); +thread__comm_adjust (self, hists);return 0 ; }
@@ -374,7 +373,8 @@ int event__process_comm(event_t *self, struct perf_session *session)dump_printf (": %s:%d\n" , self->comm.comm, self->comm.tid); -if (thread ==NULL ||thread__set_comm_adjust (thread, self->comm.comm)) { +if (thread ==NULL ||thread__set_comm_adjust (thread, self->comm.comm, + &session->hists)) {dump_printf ("problem processing PERF_RECORD_COMM, skipping event.\n" );return -1 ; }
@@ -641,16 +641,13 @@ void thread__find_addr_location(struct thread *self, al->sym =NULL ; } -static void dso__calc_col_width (struct dso *self) +static void dso__calc_col_width (struct dso *self,struct hists *hists) {if (!symbol_conf.col_width_list_str && !symbol_conf.field_sep && (!symbol_conf.dso_list ||strlist__has_entry (symbol_conf.dso_list, self->name))) { -u16 slen = self->short_name_len; -if (verbose) - slen = self->long_name_len; -if (dsos__col_width < slen) - dsos__col_width = slen; +u16 slen =dso__name_len (self); +hists__new_col_len (hists,HISTC_DSO , slen); } self->slen_calculated =1 ;
@@ -729,16 +726,17 @@ int event__preprocess_sample(const event_t *self, struct perf_session *session,* sampled. */ if (!sort_dso.elide && !al->map->dso->slen_calculated) -dso__calc_col_width (al->map->dso); +dso__calc_col_width (al->map->dso, &session->hists); al->sym =map__find_symbol (al->map, al->addr, filter); }else {const unsigned int unresolved_col_width =BITS_PER_LONG /4 ; -if (dsos__col_width < unresolved_col_width && +if (hists__col_len (&session->hists,HISTC_DSO ) < unresolved_col_width && !symbol_conf.col_width_list_str && !symbol_conf.field_sep && !symbol_conf.dso_list) - dsos__col_width = unresolved_col_width; +hists__set_col_len (&session->hists,HISTC_DSO , + unresolved_col_width); } if (symbol_conf.sym_list && al->sym &&
tools/perf/util/hist.c +79 -36
211 lines not on this page · raw message
tools/perf/util/hist.h +21 -6
@@ -56,6 +56,16 @@ struct events_stats {u32 nr_unknown_events; }; +enum hist_column { +HISTC_SYMBOL , +HISTC_DSO , +HISTC_THREAD , +HISTC_COMM , +HISTC_PARENT , +HISTC_CPU , +HISTC_NR_COLS ,/* Last entry */ +}; +struct hists {struct rb_node rb_node;struct rb_root entries;
@@ -64,7 +74,7 @@ struct hists {u64 config;u64 event_stream;u32 type; -u32 max_sym_namelen; +u16 col_len[HISTC_NR_COLS ]; }; struct hist_entry *__hists__add_entry(struct hists *self,
@@ -72,12 +82,13 @@ struct hist_entry *__hists__add_entry(struct hists *self, struct symbol *parent, u64 period);extern int64_t hist_entry__cmp (struct hist_entry *,struct hist_entry *);extern int64_t hist_entry__collapse (struct hist_entry *,struct hist_entry *); -int hist_entry__fprintf (struct hist_entry *self,struct hists *pair_hists, -bool show_displacement,long displacement,FILE *fp, -u64 total); +int hist_entry__fprintf (struct hist_entry *self,struct hists *hists, +struct hists *pair_hists,bool show_displacement, +long displacement,FILE *fp,u64 total);int hist_entry__snprintf (struct hist_entry *self,char *bf,size_t size, -struct hists *pair_hists,bool show_displacement, -long displacement,bool color,u64 total); +struct hists *hists,struct hists *pair_hists, +bool show_displacement,long displacement, +bool color,u64 total);void hist_entry__free (struct hist_entry *);void hists__output_resort (struct hists *self);
@@ -95,6 +106,10 @@ int hist_entry__annotate(struct hist_entry *self, struct list_head *head);void hists__filter_by_dso (struct hists *self,const struct dso *dso);void hists__filter_by_thread (struct hists *self,const struct thread *thread); +u16 hists__col_len (struct hists *self,enum hist_column col); +void hists__set_col_len (struct hists *self,enum hist_column col,u16 len); +bool hists__new_col_len (struct hists *self,enum hist_column col,u16 len); +#ifdef NO_NEWT_SUPPORT static inline int hists__browse(struct hists *self __used, const char *helpline __used,
tools/perf/util/newt.c +5 -4
@@ -692,7 +692,8 @@ static void hist_entry__append_callchain_browser(struct hist_entry *self, }static size_t hist_entry__append_browser (struct hist_entry *self, -newtComponent tree,u64 total) +newtComponent tree, +struct hists *hists) {char s[256 ];size_t ret;
@@ -700,8 +701,8 @@ static size_t hist_entry__append_browser(struct hist_entry *self,if (symbol_conf.exclude_other && !self->parent)return 0 ; - ret =hist_entry__snprintf (self, s,sizeof (s),NULL , - false,0 , false, total); + ret =hist_entry__snprintf (self, s,sizeof (s), hists,NULL , + false,0 , false, hists->stats.total_period);if (symbol_conf.use_callchain) {int indexes[2 ];
@@ -842,7 +843,7 @@ static int hist_browser__populate(struct hist_browser *self, struct hists *histsif (h->filtered)continue ; - len =hist_entry__append_browser (h, self->tree, hists->stats.total_period); + len =hist_entry__append_browser (h, self->tree, hists);if (len > max_len) max_len = len;if (symbol_conf.use_callchain)
tools/perf/util/sort.c +7 -10
@@ -1,4 +1,5 @@#include "sort.h" +#include "hist.h" regex_t parent_regex;const char default_parent_pattern[] ="^sys_|^do_page_fault" ;
@@ -10,11 +11,6 @@ int sort__has_parent = 0;enum sort_type sort__first_dimension; -unsigned int dsos__col_width; -unsigned int comms__col_width; -unsigned int threads__col_width; -unsigned int cpus__col_width; -static unsigned int parent_symbol__col_width;char * field_sep;LIST_HEAD (hist_entry__sort_list);
@@ -36,7 +32,7 @@ struct sort_entry sort_thread = { .se_header = "Command: Pid", .se_cmp = sort__thread_cmp, .se_snprintf = hist_entry__thread_snprintf, - .se_width = &threads__col_width, + .se_width_idx = HISTC_THREAD, };struct sort_entry sort_comm = {
@@ -44,34 +40,35 @@ struct sort_entry sort_comm = { .se_cmp = sort__comm_cmp, .se_collapse = sort__comm_collapse, .se_snprintf = hist_entry__comm_snprintf, - .se_width = &comms__col_width, + .se_width_idx = HISTC_COMM, };struct sort_entry sort_dso = { .se_header ="Shared Object" , .se_cmp = sort__dso_cmp, .se_snprintf = hist_entry__dso_snprintf, - .se_width = &dsos__col_width, + .se_width_idx =HISTC_DSO , };struct sort_entry sort_sym = { .se_header ="Symbol" , .se_cmp = sort__sym_cmp, .se_snprintf = hist_entry__sym_snprintf, + .se_width_idx =HISTC_SYMBOL , };struct sort_entry sort_parent = { .se_header ="Parent symbol" , .se_cmp = sort__parent_cmp, .se_snprintf = hist_entry__parent_snprintf, - .se_width = &parent_symbol__col_width, + .se_width_idx =HISTC_PARENT , };struct sort_entry sort_cpu = { .se_header ="CPU" , .se_cmp = sort__cpu_cmp, .se_snprintf = hist_entry__cpu_snprintf, - .se_width = &cpus__col_width, + .se_width_idx =HISTC_CPU , };struct sort_dimension {
tools/perf/util/sort.h +1 -5
@@ -36,10 +36,6 @@ extern struct sort_entry sort_comm;extern struct sort_entry sort_dso;extern struct sort_entry sort_sym;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 unsigned int cpus__col_width;extern enum sort_type sort__first_dimension;struct hist_entry {
@@ -87,7 +83,7 @@ struct sort_entry {int64_t (*se_collapse)(struct hist_entry *,struct hist_entry *);int (*se_snprintf)(struct hist_entry *self,char *bf,size_t size,unsigned int width); -unsigned int *se_width; +u8 se_width_idx;bool elide; };
tools/perf/util/symbol.c +9 -0
@@ -12,6 +12,7 @@#include <fcntl.h> #include <unistd.h> #include "build-id.h" +#include "debug.h" #include "symbol.h" #include "strlist.h"
@@ -40,6 +41,14 @@ struct symbol_conf symbol_conf = { .try_vmlinux_path = true, }; +int dso__name_len (const struct dso *self) +{ +if (verbose) +return self->long_name_len; + +return self->short_name_len; +} +bool dso__loaded (const struct dso *self,enum map_type type) {return self->loaded & (1 << type);
tools/perf/util/symbol.h +2 -0
@@ -146,6 +146,8 @@ struct dso *dso__new(const char *name);struct dso *dso__new_kernel (const char *name);void dso__delete (struct dso *self); +int dso__name_len (const struct dso *self); +bool dso__loaded (const struct dso *self,enum map_type type);bool dso__sorted_by_name (const struct dso *self,enum map_type type);