Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf annotate: Check availability of annotate when processing samples

The TUI of perf report and top support annotation, but stdio and GTK
don't. So it should be checked before calling hist_entry__inc_addr_
samples() to avoid wasting resources that will never be used.

perf annotate need it regardless of UI and sort keys, so the check
of whether to allocate resources should be on the tools that have
annotate as an option in the TUI, 'report' and 'top', not on the
function called by all of them.

It caused perf annotate on ppc64 to produce zero output, since the
buckets were not being allocated.

Reported-by: Anton Blanchard <anton@samba.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Anton Blanchard <anton@samba.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Namhyung Kim <namhyung.kim@lge.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1392859976-32760-1-git-send-email-namhyung@kernel.org
[ Renamed (report,top)__needs_annotate() to ui__has_annotation() ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
48c65bda a9d3f94e

+37 -18
+23 -15
tools/perf/builtin-report.c
··· 113 113 if (!he) 114 114 return -ENOMEM; 115 115 116 - err = hist_entry__inc_addr_samples(he, evsel->idx, al->addr); 117 - if (err) 118 - goto out; 116 + if (ui__has_annotation()) { 117 + err = hist_entry__inc_addr_samples(he, evsel->idx, al->addr); 118 + if (err) 119 + goto out; 119 120 120 - mx = he->mem_info; 121 - err = addr_map_symbol__inc_samples(&mx->daddr, evsel->idx); 122 - if (err) 123 - goto out; 121 + mx = he->mem_info; 122 + err = addr_map_symbol__inc_samples(&mx->daddr, evsel->idx); 123 + if (err) 124 + goto out; 125 + } 124 126 125 127 evsel->hists.stats.total_period += cost; 126 128 hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE); ··· 166 164 he = __hists__add_entry(&evsel->hists, al, parent, &bi[i], NULL, 167 165 1, 1, 0); 168 166 if (he) { 169 - bx = he->branch_info; 170 - err = addr_map_symbol__inc_samples(&bx->from, evsel->idx); 171 - if (err) 172 - goto out; 167 + if (ui__has_annotation()) { 168 + bx = he->branch_info; 169 + err = addr_map_symbol__inc_samples(&bx->from, 170 + evsel->idx); 171 + if (err) 172 + goto out; 173 173 174 - err = addr_map_symbol__inc_samples(&bx->to, evsel->idx); 175 - if (err) 176 - goto out; 174 + err = addr_map_symbol__inc_samples(&bx->to, 175 + evsel->idx); 176 + if (err) 177 + goto out; 178 + } 177 179 178 180 evsel->hists.stats.total_period += 1; 179 181 hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE); ··· 211 205 if (err) 212 206 goto out; 213 207 214 - err = hist_entry__inc_addr_samples(he, evsel->idx, al->addr); 208 + if (ui__has_annotation()) 209 + err = hist_entry__inc_addr_samples(he, evsel->idx, al->addr); 210 + 215 211 evsel->hists.stats.total_period += sample->period; 216 212 hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE); 217 213 out:
+4 -2
tools/perf/builtin-top.c
··· 176 176 { 177 177 struct annotation *notes; 178 178 struct symbol *sym; 179 - int err; 179 + int err = 0; 180 180 181 181 if (he == NULL || he->ms.sym == NULL || 182 182 ((top->sym_filter_entry == NULL || ··· 190 190 return; 191 191 192 192 ip = he->ms.map->map_ip(he->ms.map, ip); 193 - err = hist_entry__inc_addr_samples(he, counter, ip); 193 + 194 + if (ui__has_annotation()) 195 + err = hist_entry__inc_addr_samples(he, counter, ip); 194 196 195 197 pthread_mutex_unlock(&notes->lock); 196 198
+8 -1
tools/perf/util/annotate.c
··· 8 8 */ 9 9 10 10 #include "util.h" 11 + #include "ui/ui.h" 12 + #include "sort.h" 11 13 #include "build-id.h" 12 14 #include "color.h" 13 15 #include "cache.h" ··· 491 489 { 492 490 struct annotation *notes; 493 491 494 - if (sym == NULL || use_browser != 1 || !sort__has_sym) 492 + if (sym == NULL) 495 493 return 0; 496 494 497 495 notes = symbol__annotation(sym); ··· 1400 1398 int hist_entry__annotate(struct hist_entry *he, size_t privsize) 1401 1399 { 1402 1400 return symbol__annotate(he->ms.sym, he->ms.map, privsize); 1401 + } 1402 + 1403 + bool ui__has_annotation(void) 1404 + { 1405 + return use_browser == 1 && sort__has_sym; 1403 1406 }
+2
tools/perf/util/annotate.h
··· 151 151 void symbol__annotate_decay_histogram(struct symbol *sym, int evidx); 152 152 void disasm__purge(struct list_head *head); 153 153 154 + bool ui__has_annotation(void); 155 + 154 156 int symbol__tty_annotate(struct symbol *sym, struct map *map, 155 157 struct perf_evsel *evsel, bool print_lines, 156 158 bool full_paths, int min_pcnt, int max_lines);