perf annotate: Move locking to struct annotation
Commit-ID: ce6f4fab4059cd72638a0cfa596a8ee2c79c1c8e Gitweb: http://git.kernel.org/tip/ce6f4fab4059cd72638a0cfa596a8ee2c79c1c8e Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Tue, 8 Feb 2011 13:27:39 -0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 8 Feb 2011 15:03:36 -0200
perf annotate: Move locking to struct annotation
Since we'll need it when implementing the live annotate TUI browser.
This also simplifies things a bit by having the list head for the source code to be in the dynamicly allocated part of struct annotation, that way we don't have to pass it around, it can be found from the struct symbol that is passed everywhere.
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Cc: Tom Zanussi <[email protected]>
LKML-Reference: <new-submission>
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
--- tools/perf/builtin-annotate.c | 14 +++-- tools/perf/builtin-report.c | 5 +- tools/perf/builtin-top.c | 67 +++++++++++++------------ tools/perf/util/annotate.c | 85 ++++++++++++++++++------------- tools/perf/util/annotate.h | 34 ++++++++----- tools/perf/util/hist.c | 5 +- tools/perf/util/hist.h | 3 +- tools/perf/util/top.h | 6 -- tools/perf/util/ui/browsers/annotate.c | 18 +++--- 9 files changed, 126 insertions(+), 111 deletions(-)
tools/perf/builtin-annotate.c +8 -6
@@ -62,7 +62,8 @@ static int hists__add_entry(struct hists *self, struct addr_location *al)* All aggregated on the first sym_hist. */ struct annotation *notes =symbol__annotation (he->ms.sym); -if (notes->histograms ==NULL &&symbol__alloc_hist (he->ms.sym,1 ) <0 ) +if (notes->src ==NULL && +symbol__alloc_hist (he->ms.sym,1 ) <0 )return -ENOMEM ;return hist_entry__inc_addr_samples (he,0 , al->addr);
@@ -77,7 +78,8 @@ static int process_sample_event(union perf_event *event, {struct addr_location al; -if (perf_event__preprocess_sample (event, session, &al, sample,NULL ) <0 ) { +if (perf_event__preprocess_sample (event, session, &al, sample, + symbol__annotate_init) <0 ) {pr_warning ("problem processing %d event, skipping it.\n" , event->header.type);return -1 ;
@@ -111,7 +113,7 @@ static void hists__find_annotations(struct hists *self) goto find_next; notes =symbol__annotation (he->ms.sym); -if (notes->histograms ==NULL ) { +if (notes->src ==NULL ) { find_next:if (key ==KEY_LEFT ) nd =rb_prev (nd);
@@ -142,11 +144,11 @@ find_next: nd =rb_next (nd);/* * Since we have a hist_entry per IP for the same -* symbol, free he->ms.sym->histogram to signal we already +* symbol, free he->ms.sym->src to signal we already * processed this symbol. */ -free (notes->histograms); - notes->histograms =NULL ; +free (notes->src); + notes->src =NULL ; } } }
tools/perf/builtin-report.c +3 -2
@@ -123,7 +123,7 @@ static int perf_session__add_hist_entry(struct perf_session *session,* All aggregated on the first sym_hist. */ struct annotation *notes =symbol__annotation (he->ms.sym); -if (notes->histograms ==NULL && +if (notes->src ==NULL &&symbol__alloc_hist (he->ms.sym,1 ) <0 ) err = -ENOMEM ;else
@@ -166,7 +166,8 @@ static int process_sample_event(union perf_event *event,struct addr_location al;struct perf_event_attr *attr; -if (perf_event__preprocess_sample (event, session, &al, sample,NULL ) <0 ) { +if (perf_event__preprocess_sample (event, session, &al, sample, + symbol__annotate_init) <0 ) {fprintf (stderr,"problem processing %d event, skipping it.\n" , event->header.type);return -1 ;
tools/perf/builtin-top.c +34 -33
151 lines not on this page · raw message
tools/perf/util/annotate.c +49 -36
210 lines not on this page · raw message
tools/perf/util/annotate.h +20 -14
@@ -28,22 +28,29 @@ struct source_line {char *path; }; -/** struct annotation - symbols with hits have this attached as in sannotation +/** struct annotated_source - symbols with hits have this attached as in sannotation * * @histogram: Array of addr hit histograms per event being monitored -* @src_line: If 'print_lines' is specified, per source code line percentages +* @lines: If 'print_lines' is specified, per source code line percentages +* @source: source parsed from objdump -dS * -* src_line is allocated, percentages calculated and all sorted by percentage +* lines is allocated, percentages calculated and all sorted by percentage * when the annotation is about to be presented, so the percentages are for * one of the entries in the histogram array, i.e. for the event/counter being * presented. It is deallocated right after symbol__{tui,tty,etc}_annotate * returns. */ -struct annotation { -struct source_line *src_line; -struct sym_hist *histograms; +struct annotated_source { +struct list_head source; +struct source_line *lines;int nr_histograms;int sizeof_sym_hist; +struct sym_hist histograms[0 ]; +}; + +struct annotation { +pthread_mutex_t lock; +struct annotated_source *src; };struct sannotation {
@@ -53,7 +60,8 @@ struct sannotation {static inline struct sym_hist *annotation__histogram (struct annotation *notes,int idx) { -return ((void *)notes->histograms) + (notes->sizeof_sym_hist * idx); +return (((void *)¬es->src->histograms) + + (notes->src->sizeof_sym_hist * idx)); }static inline struct annotation *symbol__annotation (struct symbol *sym)
@@ -67,14 +75,12 @@ int symbol__inc_addr_samples(struct symbol *sym, struct map *map,int symbol__alloc_hist (struct symbol *sym,int nevents);void symbol__annotate_zero_histograms (struct symbol *sym); -int symbol__annotate (struct symbol *sym,struct map *map, -struct list_head *head,size_t privsize); -int symbol__annotate_printf (struct symbol *sym,struct map *map, -struct list_head *head,int evidx,bool full_paths, -int min_pcnt,int max_lines); +int symbol__annotate (struct symbol *sym,struct map *map,size_t privsize); +int symbol__annotate_init (struct map *map__used ,struct symbol *sym); +int symbol__annotate_printf (struct symbol *sym,struct map *map,int evidx, +bool full_paths,int min_pcnt,int max_lines);void symbol__annotate_zero_histogram (struct symbol *sym,int evidx); -void symbol__annotate_decay_histogram (struct symbol *sym, -struct list_head *head,int evidx); +void symbol__annotate_decay_histogram (struct symbol *sym,int evidx);void objdump_line_list__purge (struct list_head *head); int symbol__tty_annotate(struct symbol *sym, struct map *map, int evidx,
tools/perf/util/hist.c +2 -3
@@ -955,10 +955,9 @@ int hist_entry__inc_addr_samples(struct hist_entry *he, int evidx, u64 ip)return symbol__inc_addr_samples (he->ms.sym, he->ms.map, evidx, ip); } -int hist_entry__annotate (struct hist_entry *he,struct list_head *head, -size_t privsize) +int hist_entry__annotate (struct hist_entry *he,size_t privsize) { -return symbol__annotate (he->ms.sym, he->ms.map, head, privsize); +return symbol__annotate (he->ms.sym, he->ms.map, privsize); }void hists__inc_nr_events (struct hists *self,u32 type)
tools/perf/util/hist.h +1 -2
@@ -78,8 +78,7 @@ size_t hists__fprintf(struct hists *self, struct hists *pair, bool show_displacement, FILE *fp);int hist_entry__inc_addr_samples (struct hist_entry *self,int evidx,u64 addr); -int hist_entry__annotate (struct hist_entry *self,struct list_head *head, -size_t privsize); +int hist_entry__annotate (struct hist_entry *self,size_t privsize);void hists__filter_by_dso (struct hists *self,const struct dso *dso);void hists__filter_by_thread (struct hists *self,const struct thread *thread);
tools/perf/util/top.h +0 -6
@@ -11,11 +11,6 @@struct perf_evlist ;struct perf_evsel ; -struct sym_entry_source { -struct list_head head; -pthread_mutex_t lock; -}; -struct sym_entry {struct rb_node rb_node;struct list_head node;
@@ -24,7 +19,6 @@ struct sym_entry {int skip;u8 origin;struct map *map; -struct sym_entry_source *src;unsigned long count[0 ]; };
tools/perf/util/ui/browsers/annotate.c +9 -9
@@ -60,7 +60,6 @@ static void annotate_browser__write(struct ui_browser *self, void *entry, int ro }static double objdump_line__calc_percent (struct objdump_line *self, -struct list_head *head,struct symbol *sym,int evidx) {double percent =0.0 ;
@@ -69,11 +68,12 @@ static double objdump_line__calc_percent(struct objdump_line *self,int len = sym->end - sym->start;unsigned int hits =0 ;struct annotation *notes =symbol__annotation (sym); -struct source_line *src_line = notes->src_line; +struct source_line *src_line = notes->src->lines;struct sym_hist *h =annotation__histogram (notes, evidx);s64 offset = self->offset; -struct objdump_line *next =objdump__get_next_ip_line (head, self); +struct objdump_line *next; + next =objdump__get_next_ip_line (¬es->src->source, self);while (offset < (s64 )len && (next ==NULL || offset < next->offset)) {if (src_line) {
@@ -192,10 +192,10 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx) {struct objdump_line *pos, *n;struct objdump_line_rb_node *rbpos; -LIST_HEAD (head); +struct annotation *notes =symbol__annotation (sym);struct annotate_browser browser = { .b = { - .entries = &head, + .entries = ¬es->src->source, .refresh = ui_browser__list_head_refresh, .seek = ui_browser__list_head_seek, .write = annotate_browser__write,
@@ -210,20 +210,20 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx)if (map->dso->annotate_warned)return -1 ; -if (symbol__annotate (sym, map, &head,sizeof (*rbpos)) <0 ) { +if (symbol__annotate (sym, map,sizeof (*rbpos)) <0 ) {ui__error_window (ui_helpline__last_msg);return -1 ; }ui_helpline__push ("Press <- or ESC to exit" ); -list_for_each_entry (pos, &head, node) { +list_for_each_entry (pos, ¬es->src->source, node) {size_t line_len =strlen (pos->line);if (browser.b.width < line_len) browser.b.width = line_len; rbpos =objdump_line__rb (pos); rbpos->idx = browser.b.nr_entries++; - rbpos->percent =objdump_line__calc_percent (pos, &head, sym, evidx); + rbpos->percent =objdump_line__calc_percent (pos, sym, evidx);if (rbpos->percent <0.01 )continue ;objdump__insert_line (&browser.entries, rbpos);
@@ -238,7 +238,7 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx) browser.b.width +=18 ;/* Percentage */ ret =annotate_browser__run (&browser); -list_for_each_entry_safe (pos, n, &head, node) { +list_for_each_entry_safe (pos, n, ¬es->src->source, node) {list_del (&pos->node);objdump_line__free (pos); }