aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2013-12-18 13:37:41 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-12-19 09:33:51 -0500
commitb66d8c0caa8f7925ae75fed243b0482a901f21e1 (patch)
treec16e7257c612d54a6ff7af9c29ef627884d984a1
parentbf19b82e7cf033319525a9eab12216b59c41c519 (diff)
perf annotate: Auto allocate symbol per addr hist buckets
Instead of open coding it in multiple places in 'report' and 'top'. Acked-by: Namhyung Kim <namhyung@kernel.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/n/tip-ay1ushp57qsva9aw59rha5ve@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/builtin-report.c59
-rw-r--r--tools/perf/builtin-top.c13
-rw-r--r--tools/perf/util/annotate.c26
3 files changed, 40 insertions, 58 deletions
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 3a14dbed387c..b75fc361b9bd 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -140,22 +140,11 @@ static int perf_report__add_mem_hist_entry(struct perf_tool *tool,
140 goto out; 140 goto out;
141 } 141 }
142 142
143 if (sort__has_sym && he->mem_info->daddr.sym && use_browser > 0) { 143 mx = he->mem_info;
144 struct annotation *notes; 144 err = symbol__inc_addr_samples(mx->daddr.sym, mx->daddr.map,
145 145 evsel->idx, mx->daddr.al_addr);
146 mx = he->mem_info; 146 if (err)
147 147 goto out;
148 notes = symbol__annotation(mx->daddr.sym);
149 if (notes->src == NULL && symbol__alloc_hist(mx->daddr.sym) < 0)
150 goto out;
151
152 err = symbol__inc_addr_samples(mx->daddr.sym,
153 mx->daddr.map,
154 evsel->idx,
155 mx->daddr.al_addr);
156 if (err)
157 goto out;
158 }
159 148
160 evsel->hists.stats.total_period += cost; 149 evsel->hists.stats.total_period += cost;
161 hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE); 150 hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE);
@@ -214,35 +203,19 @@ static int perf_report__add_branch_hist_entry(struct perf_tool *tool,
214 he = __hists__add_entry(&evsel->hists, al, parent, &bi[i], NULL, 203 he = __hists__add_entry(&evsel->hists, al, parent, &bi[i], NULL,
215 1, 1, 0); 204 1, 1, 0);
216 if (he) { 205 if (he) {
217 struct annotation *notes;
218 bx = he->branch_info; 206 bx = he->branch_info;
219 if (bx->from.sym && use_browser == 1 && sort__has_sym) { 207 err = symbol__inc_addr_samples(bx->from.sym,
220 notes = symbol__annotation(bx->from.sym); 208 bx->from.map, evsel->idx,
221 if (!notes->src 209 bx->from.al_addr);
222 && symbol__alloc_hist(bx->from.sym) < 0) 210 if (err)
223 goto out; 211 goto out;
224 212
225 err = symbol__inc_addr_samples(bx->from.sym, 213 err = symbol__inc_addr_samples(bx->to.sym,
226 bx->from.map, 214 bx->to.map, evsel->idx,
227 evsel->idx, 215 bx->to.al_addr);
228 bx->from.al_addr); 216 if (err)
229 if (err) 217 goto out;
230 goto out;
231 }
232 218
233 if (bx->to.sym && use_browser == 1 && sort__has_sym) {
234 notes = symbol__annotation(bx->to.sym);
235 if (!notes->src
236 && symbol__alloc_hist(bx->to.sym) < 0)
237 goto out;
238
239 err = symbol__inc_addr_samples(bx->to.sym,
240 bx->to.map,
241 evsel->idx,
242 bx->to.al_addr);
243 if (err)
244 goto out;
245 }
246 evsel->hists.stats.total_period += 1; 219 evsel->hists.stats.total_period += 1;
247 hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE); 220 hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE);
248 } else 221 } else
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 03d37a76c612..73df9c05bad9 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -189,14 +189,6 @@ static void perf_top__record_precise_ip(struct perf_top *top,
189 if (pthread_mutex_trylock(&notes->lock)) 189 if (pthread_mutex_trylock(&notes->lock))
190 return; 190 return;
191 191
192 if (notes->src == NULL && symbol__alloc_hist(sym) < 0) {
193 pthread_mutex_unlock(&notes->lock);
194 pr_err("Not enough memory for annotating '%s' symbol!\n",
195 sym->name);
196 sleep(1);
197 return;
198 }
199
200 ip = he->ms.map->map_ip(he->ms.map, ip); 192 ip = he->ms.map->map_ip(he->ms.map, ip);
201 err = symbol__inc_addr_samples(sym, he->ms.map, counter, ip); 193 err = symbol__inc_addr_samples(sym, he->ms.map, counter, ip);
202 194
@@ -204,6 +196,11 @@ static void perf_top__record_precise_ip(struct perf_top *top,
204 196
205 if (err == -ERANGE && !he->ms.map->erange_warned) 197 if (err == -ERANGE && !he->ms.map->erange_warned)
206 ui__warn_map_erange(he->ms.map, sym, ip); 198 ui__warn_map_erange(he->ms.map, sym, ip);
199 else if (err == -ENOMEM) {
200 pr_err("Not enough memory for annotating '%s' symbol!\n",
201 sym->name);
202 sleep(1);
203 }
207} 204}
208 205
209static void perf_top__show_details(struct perf_top *top) 206static void perf_top__show_details(struct perf_top *top)
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 0fcd81ea31ae..93614cd3948f 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -464,17 +464,12 @@ void symbol__annotate_zero_histograms(struct symbol *sym)
464 pthread_mutex_unlock(&notes->lock); 464 pthread_mutex_unlock(&notes->lock);
465} 465}
466 466
467int symbol__inc_addr_samples(struct symbol *sym, struct map *map, 467static int __symbol__inc_addr_samples(struct symbol *sym, struct map *map,
468 int evidx, u64 addr) 468 struct annotation *notes, int evidx, u64 addr)
469{ 469{
470 unsigned offset; 470 unsigned offset;
471 struct annotation *notes;
472 struct sym_hist *h; 471 struct sym_hist *h;
473 472
474 notes = symbol__annotation(sym);
475 if (notes->src == NULL)
476 return -ENOMEM;
477
478 pr_debug3("%s: addr=%#" PRIx64 "\n", __func__, map->unmap_ip(map, addr)); 473 pr_debug3("%s: addr=%#" PRIx64 "\n", __func__, map->unmap_ip(map, addr));
479 474
480 if (addr < sym->start || addr > sym->end) 475 if (addr < sym->start || addr > sym->end)
@@ -491,6 +486,23 @@ int symbol__inc_addr_samples(struct symbol *sym, struct map *map,
491 return 0; 486 return 0;
492} 487}
493 488
489int symbol__inc_addr_samples(struct symbol *sym, struct map *map,
490 int evidx, u64 addr)
491{
492 struct annotation *notes;
493
494 if (sym == NULL || use_browser != 1 || !sort__has_sym)
495 return 0;
496
497 notes = symbol__annotation(sym);
498 if (notes->src == NULL) {
499 if (symbol__alloc_hist(sym) < 0)
500 return -ENOMEM;
501 }
502
503 return __symbol__inc_addr_samples(sym, map, notes, evidx, addr);
504}
505
494static void disasm_line__init_ins(struct disasm_line *dl) 506static void disasm_line__init_ins(struct disasm_line *dl)
495{ 507{
496 dl->ins = ins__find(dl->name); 508 dl->ins = ins__find(dl->name);