aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util')
-rw-r--r--tools/perf/util/annotate.c76
-rw-r--r--tools/perf/util/annotate.h11
-rw-r--r--tools/perf/util/top.h11
3 files changed, 75 insertions, 23 deletions
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 10cdbad76058..297337649c21 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -22,9 +22,19 @@ int symbol__alloc_hist(struct symbol *sym, int nevents)
22 notes->sizeof_sym_hist = (sizeof(*notes->histograms) + 22 notes->sizeof_sym_hist = (sizeof(*notes->histograms) +
23 (sym->end - sym->start) * sizeof(u64)); 23 (sym->end - sym->start) * sizeof(u64));
24 notes->histograms = calloc(nevents, notes->sizeof_sym_hist); 24 notes->histograms = calloc(nevents, notes->sizeof_sym_hist);
25 notes->nr_histograms = nevents;
25 return notes->histograms == NULL ? -1 : 0; 26 return notes->histograms == NULL ? -1 : 0;
26} 27}
27 28
29void symbol__annotate_zero_histograms(struct symbol *sym)
30{
31 struct annotation *notes = symbol__annotation(sym);
32
33 if (notes->histograms != NULL)
34 memset(notes->histograms, 0,
35 notes->nr_histograms * notes->sizeof_sym_hist);
36}
37
28int symbol__inc_addr_samples(struct symbol *sym, struct map *map, 38int symbol__inc_addr_samples(struct symbol *sym, struct map *map,
29 int evidx, u64 addr) 39 int evidx, u64 addr)
30{ 40{
@@ -85,9 +95,10 @@ struct objdump_line *objdump__get_next_ip_line(struct list_head *head,
85 return NULL; 95 return NULL;
86} 96}
87 97
88static void objdump_line__print(struct objdump_line *oline, 98static int objdump_line__print(struct objdump_line *oline,
89 struct list_head *head, struct symbol *sym, 99 struct list_head *head, struct symbol *sym,
90 int evidx, u64 len, int min_pcnt) 100 int evidx, u64 len, int min_pcnt,
101 int printed, int max_lines)
91{ 102{
92 static const char *prev_line; 103 static const char *prev_line;
93 static const char *prev_color; 104 static const char *prev_color;
@@ -119,7 +130,10 @@ static void objdump_line__print(struct objdump_line *oline,
119 percent = 100.0 * hits / h->sum; 130 percent = 100.0 * hits / h->sum;
120 131
121 if (percent < min_pcnt) 132 if (percent < min_pcnt)
122 return; 133 return -1;
134
135 if (printed >= max_lines)
136 return 1;
123 137
124 color = get_percent_color(percent); 138 color = get_percent_color(percent);
125 139
@@ -140,12 +154,16 @@ static void objdump_line__print(struct objdump_line *oline,
140 color_fprintf(stdout, color, " %7.2f", percent); 154 color_fprintf(stdout, color, " %7.2f", percent);
141 printf(" : "); 155 printf(" : ");
142 color_fprintf(stdout, PERF_COLOR_BLUE, "%s\n", oline->line); 156 color_fprintf(stdout, PERF_COLOR_BLUE, "%s\n", oline->line);
143 } else { 157 } else if (printed >= max_lines)
158 return 1;
159 else {
144 if (!*oline->line) 160 if (!*oline->line)
145 printf(" :\n"); 161 printf(" :\n");
146 else 162 else
147 printf(" : %s\n", oline->line); 163 printf(" : %s\n", oline->line);
148 } 164 }
165
166 return 0;
149} 167}
150 168
151static int symbol__parse_objdump_line(struct symbol *sym, struct map *map, FILE *file, 169static int symbol__parse_objdump_line(struct symbol *sym, struct map *map, FILE *file,
@@ -421,14 +439,15 @@ static void symbol__annotate_hits(struct symbol *sym, int evidx)
421 printf("%*s: %" PRIu64 "\n", BITS_PER_LONG / 2, "h->sum", h->sum); 439 printf("%*s: %" PRIu64 "\n", BITS_PER_LONG / 2, "h->sum", h->sum);
422} 440}
423 441
424void symbol__annotate_printf(struct symbol *sym, struct map *map, 442int symbol__annotate_printf(struct symbol *sym, struct map *map,
425 struct list_head *head, int evidx, bool full_paths, 443 struct list_head *head, int evidx, bool full_paths,
426 int min_pcnt, int max_lines) 444 int min_pcnt, int max_lines)
427{ 445{
428 struct dso *dso = map->dso; 446 struct dso *dso = map->dso;
429 const char *filename = dso->long_name, *d_filename; 447 const char *filename = dso->long_name, *d_filename;
430 struct objdump_line *pos; 448 struct objdump_line *pos;
431 int printed = 2; 449 int printed = 2;
450 int more = 0;
432 u64 len; 451 u64 len;
433 452
434 if (full_paths) 453 if (full_paths)
@@ -445,10 +464,47 @@ void symbol__annotate_printf(struct symbol *sym, struct map *map,
445 symbol__annotate_hits(sym, evidx); 464 symbol__annotate_hits(sym, evidx);
446 465
447 list_for_each_entry(pos, head, node) { 466 list_for_each_entry(pos, head, node) {
448 objdump_line__print(pos, head, sym, evidx, len, min_pcnt); 467 switch (objdump_line__print(pos, head, sym, evidx, len, min_pcnt,
449 if (max_lines && ++printed >= max_lines) 468 printed, max_lines)) {
469 case 0:
470 ++printed;
471 break;
472 case 1:
473 /* filtered by max_lines */
474 ++more;
450 break; 475 break;
476 case -1:
477 default:
478 /* filtered by min_pcnt */
479 break;
480 }
481 }
482
483 return more;
484}
451 485
486void symbol__annotate_zero_histogram(struct symbol *sym, int evidx)
487{
488 struct annotation *notes = symbol__annotation(sym);
489 struct sym_hist *h = annotation__histogram(notes, evidx);
490
491 memset(h, 0, notes->sizeof_sym_hist);
492}
493
494void symbol__annotate_decay_histogram(struct symbol *sym,
495 struct list_head *head, int evidx)
496{
497 struct annotation *notes = symbol__annotation(sym);
498 struct sym_hist *h = annotation__histogram(notes, evidx);
499 struct objdump_line *pos;
500
501 h->sum = 0;
502
503 list_for_each_entry(pos, head, node) {
504 if (pos->offset != -1) {
505 h->addr[pos->offset] = h->addr[pos->offset] * 7 / 8;
506 h->sum += h->addr[pos->offset];
507 }
452 } 508 }
453} 509}
454 510
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 53dd92de2615..b1253aadf340 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -42,6 +42,7 @@ struct source_line {
42struct annotation { 42struct annotation {
43 struct source_line *src_line; 43 struct source_line *src_line;
44 struct sym_hist *histograms; 44 struct sym_hist *histograms;
45 int nr_histograms;
45 int sizeof_sym_hist; 46 int sizeof_sym_hist;
46}; 47};
47 48
@@ -64,12 +65,16 @@ static inline struct annotation *symbol__annotation(struct symbol *sym)
64int symbol__inc_addr_samples(struct symbol *sym, struct map *map, 65int symbol__inc_addr_samples(struct symbol *sym, struct map *map,
65 int evidx, u64 addr); 66 int evidx, u64 addr);
66int symbol__alloc_hist(struct symbol *sym, int nevents); 67int symbol__alloc_hist(struct symbol *sym, int nevents);
68void symbol__annotate_zero_histograms(struct symbol *sym);
67 69
68int symbol__annotate(struct symbol *sym, struct map *map, 70int symbol__annotate(struct symbol *sym, struct map *map,
69 struct list_head *head, size_t privsize); 71 struct list_head *head, size_t privsize);
70void symbol__annotate_printf(struct symbol *sym, struct map *map, 72int symbol__annotate_printf(struct symbol *sym, struct map *map,
71 struct list_head *head, int evidx, bool full_paths, 73 struct list_head *head, int evidx, bool full_paths,
72 int min_pcnt, int max_lines); 74 int min_pcnt, int max_lines);
75void symbol__annotate_zero_histogram(struct symbol *sym, int evidx);
76void symbol__annotate_decay_histogram(struct symbol *sym,
77 struct list_head *head, int evidx);
73void objdump_line_list__purge(struct list_head *head); 78void objdump_line_list__purge(struct list_head *head);
74 79
75int symbol__tty_annotate(struct symbol *sym, struct map *map, int evidx, 80int symbol__tty_annotate(struct symbol *sym, struct map *map, int evidx,
diff --git a/tools/perf/util/top.h b/tools/perf/util/top.h
index 500950818d2f..fe44afb69985 100644
--- a/tools/perf/util/top.h
+++ b/tools/perf/util/top.h
@@ -11,17 +11,8 @@
11struct perf_evlist; 11struct perf_evlist;
12struct perf_evsel; 12struct perf_evsel;
13 13
14struct source_line {
15 u64 eip;
16 unsigned long count[MAX_COUNTERS]; /* FIXME */
17 char *line;
18 struct source_line *next;
19};
20
21struct sym_entry_source { 14struct sym_entry_source {
22 struct source_line *source; 15 struct list_head head;
23 struct source_line *lines;
24 struct source_line **lines_tail;
25 pthread_mutex_t lock; 16 pthread_mutex_t lock;
26}; 17};
27 18