Commit e64aa75bf5559be3ce72e53ae28b76a2f633ca06

Authored by Namhyung Kim
Committed by Arnaldo Carvalho de Melo
1 parent ab77df672c

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>

Showing 3 changed files with 20 additions and 38 deletions Side-by-side Diff

tools/perf/ui/browsers/annotate.c
... ... @@ -240,40 +240,6 @@
240 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(&notes->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 243 static void disasm_rb_tree__insert(struct rb_root *root, struct browser_disasm_line *bdl)
278 244 {
279 245 struct rb_node **p = &root->rb_node;
... ... @@ -337,7 +303,8 @@
337 303 struct map_symbol *ms = browser->b.priv;
338 304 struct symbol *sym = ms->sym;
339 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 309 browser->entries = RB_ROOT;
343 310  
... ... @@ -345,7 +312,18 @@
345 312  
346 313 list_for_each_entry(pos, &notes->src->source, node) {
347 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(&notes->src->source, pos);
  323 + bpos->percent[0] = disasm__calc_percent(notes, evsel->idx,
  324 + pos->offset, next ? next->offset : len,
  325 + &path);
  326 +
349 327 if (bpos->percent[0] < 0.01) {
350 328 RB_CLEAR_NODE(&bpos->rb_node);
351 329 continue;
tools/perf/util/annotate.c
... ... @@ -603,8 +603,8 @@
603 603 return NULL;
604 604 }
605 605  
606   -static double disasm__calc_percent(struct annotation *notes, int evidx,
607   - s64 offset, s64 end, const char **path)
  606 +double disasm__calc_percent(struct annotation *notes, int evidx, s64 offset,
  607 + s64 end, const char **path)
608 608 {
609 609 struct source_line *src_line = notes->src->lines;
610 610 double percent = 0.0;
tools/perf/util/annotate.h
... ... @@ -50,6 +50,8 @@
50 50 bool ins__is_call(const struct ins *ins);
51 51 int ins__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands *ops);
52 52  
  53 +struct annotation;
  54 +
53 55 struct disasm_line {
54 56 struct list_head node;
55 57 s64 offset;
... ... @@ -68,6 +70,8 @@
68 70 struct disasm_line *disasm__get_next_ip_line(struct list_head *head, struct disasm_line *pos);
69 71 int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw);
70 72 size_t disasm__fprintf(struct list_head *head, FILE *fp);
  73 +double disasm__calc_percent(struct annotation *notes, int evidx, s64 offset,
  74 + s64 end, const char **path);
71 75  
72 76 struct sym_hist {
73 77 u64 sum;