diff options
author | Namhyung Kim <namhyung@kernel.org> | 2013-03-05 00:53:30 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-03-15 12:06:06 -0400 |
commit | e64aa75bf5559be3ce72e53ae28b76a2f633ca06 (patch) | |
tree | b53c653ae78ae7dd2f038bf39edfec9a84fe1dee /tools/perf/ui | |
parent | ab77df672cdbf7a0235a9de3289c173e2fce68e5 (diff) |
perf annotate browser: Use disasm__calc_percent()
The disasm_line__calc_percent() which was used by annotate browser code
almost duplicates disasm__calc_percent. Let's get rid of the code
duplication.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung.kim@lge.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1362462812-30885-11-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/ui')
-rw-r--r-- | tools/perf/ui/browsers/annotate.c | 50 |
1 files changed, 14 insertions, 36 deletions
diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c index 62369f0b6608..8b16926dd56e 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c | |||
@@ -240,40 +240,6 @@ static unsigned int annotate_browser__refresh(struct ui_browser *browser) | |||
240 | return ret; | 240 | return ret; |
241 | } | 241 | } |
242 | 242 | ||
243 | static double disasm_line__calc_percent(struct disasm_line *dl, struct symbol *sym, int evidx) | ||
244 | { | ||
245 | double percent = 0.0; | ||
246 | |||
247 | if (dl->offset != -1) { | ||
248 | int len = sym->end - sym->start; | ||
249 | unsigned int hits = 0; | ||
250 | struct annotation *notes = symbol__annotation(sym); | ||
251 | struct source_line *src_line = notes->src->lines; | ||
252 | struct sym_hist *h = annotation__histogram(notes, evidx); | ||
253 | s64 offset = dl->offset; | ||
254 | struct disasm_line *next; | ||
255 | |||
256 | next = disasm__get_next_ip_line(¬es->src->source, dl); | ||
257 | while (offset < (s64)len && | ||
258 | (next == NULL || offset < next->offset)) { | ||
259 | if (src_line) { | ||
260 | percent += src_line[offset].p[0].percent; | ||
261 | } else | ||
262 | hits += h->addr[offset]; | ||
263 | |||
264 | ++offset; | ||
265 | } | ||
266 | /* | ||
267 | * If the percentage wasn't already calculated in | ||
268 | * symbol__get_source_line, do it now: | ||
269 | */ | ||
270 | if (src_line == NULL && h->sum) | ||
271 | percent = 100.0 * hits / h->sum; | ||
272 | } | ||
273 | |||
274 | return percent; | ||
275 | } | ||
276 | |||
277 | static void disasm_rb_tree__insert(struct rb_root *root, struct browser_disasm_line *bdl) | 243 | static void disasm_rb_tree__insert(struct rb_root *root, struct browser_disasm_line *bdl) |
278 | { | 244 | { |
279 | struct rb_node **p = &root->rb_node; | 245 | struct rb_node **p = &root->rb_node; |
@@ -337,7 +303,8 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser, | |||
337 | struct map_symbol *ms = browser->b.priv; | 303 | struct map_symbol *ms = browser->b.priv; |
338 | struct symbol *sym = ms->sym; | 304 | struct symbol *sym = ms->sym; |
339 | struct annotation *notes = symbol__annotation(sym); | 305 | struct annotation *notes = symbol__annotation(sym); |
340 | struct disasm_line *pos; | 306 | struct disasm_line *pos, *next; |
307 | s64 len = symbol__size(sym); | ||
341 | 308 | ||
342 | browser->entries = RB_ROOT; | 309 | browser->entries = RB_ROOT; |
343 | 310 | ||
@@ -345,7 +312,18 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser, | |||
345 | 312 | ||
346 | list_for_each_entry(pos, ¬es->src->source, node) { | 313 | list_for_each_entry(pos, ¬es->src->source, node) { |
347 | struct browser_disasm_line *bpos = disasm_line__browser(pos); | 314 | struct browser_disasm_line *bpos = disasm_line__browser(pos); |
348 | bpos->percent[0] = disasm_line__calc_percent(pos, sym, evsel->idx); | 315 | const char *path = NULL; |
316 | |||
317 | if (pos->offset == -1) { | ||
318 | RB_CLEAR_NODE(&bpos->rb_node); | ||
319 | continue; | ||
320 | } | ||
321 | |||
322 | next = disasm__get_next_ip_line(¬es->src->source, pos); | ||
323 | bpos->percent[0] = disasm__calc_percent(notes, evsel->idx, | ||
324 | pos->offset, next ? next->offset : len, | ||
325 | &path); | ||
326 | |||
349 | if (bpos->percent[0] < 0.01) { | 327 | if (bpos->percent[0] < 0.01) { |
350 | RB_CLEAR_NODE(&bpos->rb_node); | 328 | RB_CLEAR_NODE(&bpos->rb_node); |
351 | continue; | 329 | continue; |