Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1 | #include "annotate.h" |
Frederic Weisbecker | 8a0ecfb | 2010-05-13 19:47:16 +0200 | [diff] [blame] | 2 | #include "util.h" |
Frederic Weisbecker | 598357e | 2010-05-21 12:48:39 +0200 | [diff] [blame] | 3 | #include "build-id.h" |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 4 | #include "hist.h" |
Arnaldo Carvalho de Melo | 4e4f06e | 2009-12-14 13:10:39 -0200 | [diff] [blame] | 5 | #include "session.h" |
| 6 | #include "sort.h" |
Arnaldo Carvalho de Melo | 9b33827 | 2009-12-16 14:31:49 -0200 | [diff] [blame] | 7 | #include <math.h> |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 8 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 9 | static bool hists__filter_entry_by_dso(struct hists *hists, |
| 10 | struct hist_entry *he); |
| 11 | static bool hists__filter_entry_by_thread(struct hists *hists, |
| 12 | struct hist_entry *he); |
| 13 | |
Arnaldo Carvalho de Melo | 7a007ca | 2010-07-21 09:19:41 -0300 | [diff] [blame] | 14 | enum hist_filter { |
| 15 | HIST_FILTER__DSO, |
| 16 | HIST_FILTER__THREAD, |
| 17 | HIST_FILTER__PARENT, |
| 18 | }; |
| 19 | |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 20 | struct callchain_param callchain_param = { |
| 21 | .mode = CHAIN_GRAPH_REL, |
Sam Liao | d797fdc | 2011-06-07 23:49:46 +0800 | [diff] [blame] | 22 | .min_percent = 0.5, |
| 23 | .order = ORDER_CALLEE |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 24 | }; |
| 25 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 26 | u16 hists__col_len(struct hists *hists, enum hist_column col) |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 27 | { |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 28 | return hists->col_len[col]; |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 29 | } |
| 30 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 31 | void hists__set_col_len(struct hists *hists, enum hist_column col, u16 len) |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 32 | { |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 33 | hists->col_len[col] = len; |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 34 | } |
| 35 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 36 | bool hists__new_col_len(struct hists *hists, enum hist_column col, u16 len) |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 37 | { |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 38 | if (len > hists__col_len(hists, col)) { |
| 39 | hists__set_col_len(hists, col, len); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 40 | return true; |
| 41 | } |
| 42 | return false; |
| 43 | } |
| 44 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 45 | static void hists__reset_col_len(struct hists *hists) |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 46 | { |
| 47 | enum hist_column col; |
| 48 | |
| 49 | for (col = 0; col < HISTC_NR_COLS; ++col) |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 50 | hists__set_col_len(hists, col, 0); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 51 | } |
| 52 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 53 | static void hists__calc_col_len(struct hists *hists, struct hist_entry *h) |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 54 | { |
| 55 | u16 len; |
| 56 | |
| 57 | if (h->ms.sym) |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 58 | hists__new_col_len(hists, HISTC_SYMBOL, h->ms.sym->namelen); |
Arnaldo Carvalho de Melo | d7603d5 | 2011-03-04 14:51:33 -0300 | [diff] [blame] | 59 | else { |
| 60 | const unsigned int unresolved_col_width = BITS_PER_LONG / 4; |
| 61 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 62 | if (hists__col_len(hists, HISTC_DSO) < unresolved_col_width && |
Arnaldo Carvalho de Melo | d7603d5 | 2011-03-04 14:51:33 -0300 | [diff] [blame] | 63 | !symbol_conf.col_width_list_str && !symbol_conf.field_sep && |
| 64 | !symbol_conf.dso_list) |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 65 | hists__set_col_len(hists, HISTC_DSO, |
Arnaldo Carvalho de Melo | d7603d5 | 2011-03-04 14:51:33 -0300 | [diff] [blame] | 66 | unresolved_col_width); |
| 67 | } |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 68 | |
| 69 | len = thread__comm_len(h->thread); |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 70 | if (hists__new_col_len(hists, HISTC_COMM, len)) |
| 71 | hists__set_col_len(hists, HISTC_THREAD, len + 6); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 72 | |
| 73 | if (h->ms.map) { |
| 74 | len = dso__name_len(h->ms.map->dso); |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 75 | hists__new_col_len(hists, HISTC_DSO, len); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 76 | } |
| 77 | } |
| 78 | |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 79 | static void hist_entry__add_cpumode_period(struct hist_entry *self, |
| 80 | unsigned int cpumode, u64 period) |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 81 | { |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 82 | switch (cpumode) { |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 83 | case PERF_RECORD_MISC_KERNEL: |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 84 | self->period_sys += period; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 85 | break; |
| 86 | case PERF_RECORD_MISC_USER: |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 87 | self->period_us += period; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 88 | break; |
| 89 | case PERF_RECORD_MISC_GUEST_KERNEL: |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 90 | self->period_guest_sys += period; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 91 | break; |
| 92 | case PERF_RECORD_MISC_GUEST_USER: |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 93 | self->period_guest_us += period; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 94 | break; |
| 95 | default: |
| 96 | break; |
| 97 | } |
| 98 | } |
| 99 | |
Arnaldo Carvalho de Melo | ab81f3fd | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 100 | static void hist_entry__decay(struct hist_entry *he) |
| 101 | { |
| 102 | he->period = (he->period * 7) / 8; |
| 103 | he->nr_events = (he->nr_events * 7) / 8; |
| 104 | } |
| 105 | |
| 106 | static bool hists__decay_entry(struct hists *hists, struct hist_entry *he) |
| 107 | { |
Arnaldo Carvalho de Melo | c64550c | 2011-10-20 06:45:44 -0200 | [diff] [blame^] | 108 | u64 prev_period = he->period; |
| 109 | |
| 110 | if (prev_period == 0) |
Arnaldo Carvalho de Melo | df71d95 | 2011-10-13 08:01:33 -0300 | [diff] [blame] | 111 | return true; |
Arnaldo Carvalho de Melo | c64550c | 2011-10-20 06:45:44 -0200 | [diff] [blame^] | 112 | |
Arnaldo Carvalho de Melo | ab81f3fd | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 113 | hist_entry__decay(he); |
Arnaldo Carvalho de Melo | c64550c | 2011-10-20 06:45:44 -0200 | [diff] [blame^] | 114 | |
| 115 | if (!he->filtered) |
| 116 | hists->stats.total_period -= prev_period - he->period; |
| 117 | |
Arnaldo Carvalho de Melo | ab81f3fd | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 118 | return he->period == 0; |
| 119 | } |
| 120 | |
Arnaldo Carvalho de Melo | b079d4e | 2011-10-17 09:05:04 -0200 | [diff] [blame] | 121 | static void __hists__decay_entries(struct hists *hists, bool zap_user, |
| 122 | bool zap_kernel, bool threaded) |
Arnaldo Carvalho de Melo | ab81f3fd | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 123 | { |
| 124 | struct rb_node *next = rb_first(&hists->entries); |
| 125 | struct hist_entry *n; |
| 126 | |
| 127 | while (next) { |
| 128 | n = rb_entry(next, struct hist_entry, rb_node); |
| 129 | next = rb_next(&n->rb_node); |
Arnaldo Carvalho de Melo | df71d95 | 2011-10-13 08:01:33 -0300 | [diff] [blame] | 130 | /* |
| 131 | * We may be annotating this, for instance, so keep it here in |
| 132 | * case some it gets new samples, we'll eventually free it when |
| 133 | * the user stops browsing and it agains gets fully decayed. |
| 134 | */ |
Arnaldo Carvalho de Melo | b079d4e | 2011-10-17 09:05:04 -0200 | [diff] [blame] | 135 | if (((zap_user && n->level == '.') || |
| 136 | (zap_kernel && n->level != '.') || |
| 137 | hists__decay_entry(hists, n)) && |
| 138 | !n->used) { |
Arnaldo Carvalho de Melo | ab81f3fd | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 139 | rb_erase(&n->rb_node, &hists->entries); |
| 140 | |
Arnaldo Carvalho de Melo | e345fa1 | 2011-10-13 09:06:54 -0300 | [diff] [blame] | 141 | if (sort__need_collapse || threaded) |
Arnaldo Carvalho de Melo | ab81f3fd | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 142 | rb_erase(&n->rb_node_in, &hists->entries_collapsed); |
| 143 | |
| 144 | hist_entry__free(n); |
| 145 | --hists->nr_entries; |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | |
Arnaldo Carvalho de Melo | b079d4e | 2011-10-17 09:05:04 -0200 | [diff] [blame] | 150 | void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel) |
Arnaldo Carvalho de Melo | e345fa1 | 2011-10-13 09:06:54 -0300 | [diff] [blame] | 151 | { |
Arnaldo Carvalho de Melo | b079d4e | 2011-10-17 09:05:04 -0200 | [diff] [blame] | 152 | return __hists__decay_entries(hists, zap_user, zap_kernel, false); |
Arnaldo Carvalho de Melo | e345fa1 | 2011-10-13 09:06:54 -0300 | [diff] [blame] | 153 | } |
| 154 | |
Arnaldo Carvalho de Melo | b079d4e | 2011-10-17 09:05:04 -0200 | [diff] [blame] | 155 | void hists__decay_entries_threaded(struct hists *hists, |
| 156 | bool zap_user, bool zap_kernel) |
Arnaldo Carvalho de Melo | e345fa1 | 2011-10-13 09:06:54 -0300 | [diff] [blame] | 157 | { |
Arnaldo Carvalho de Melo | b079d4e | 2011-10-17 09:05:04 -0200 | [diff] [blame] | 158 | return __hists__decay_entries(hists, zap_user, zap_kernel, true); |
Arnaldo Carvalho de Melo | e345fa1 | 2011-10-13 09:06:54 -0300 | [diff] [blame] | 159 | } |
| 160 | |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 161 | /* |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 162 | * histogram, sorted on item, collects periods |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 163 | */ |
| 164 | |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 165 | static struct hist_entry *hist_entry__new(struct hist_entry *template) |
| 166 | { |
Frederic Weisbecker | d2009c5 | 2010-08-22 20:05:22 +0200 | [diff] [blame] | 167 | size_t callchain_size = symbol_conf.use_callchain ? sizeof(struct callchain_root) : 0; |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 168 | struct hist_entry *self = malloc(sizeof(*self) + callchain_size); |
| 169 | |
| 170 | if (self != NULL) { |
| 171 | *self = *template; |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 172 | self->nr_events = 1; |
Arnaldo Carvalho de Melo | 0a1eae3 | 2010-08-02 19:45:23 -0300 | [diff] [blame] | 173 | if (self->ms.map) |
| 174 | self->ms.map->referenced = true; |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 175 | if (symbol_conf.use_callchain) |
| 176 | callchain_init(self->callchain); |
| 177 | } |
| 178 | |
| 179 | return self; |
| 180 | } |
| 181 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 182 | static void hists__inc_nr_entries(struct hists *hists, struct hist_entry *h) |
Arnaldo Carvalho de Melo | fefb0b9 | 2010-05-10 13:57:51 -0300 | [diff] [blame] | 183 | { |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 184 | if (!h->filtered) { |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 185 | hists__calc_col_len(hists, h); |
| 186 | ++hists->nr_entries; |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 187 | hists->stats.total_period += h->period; |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 188 | } |
Arnaldo Carvalho de Melo | fefb0b9 | 2010-05-10 13:57:51 -0300 | [diff] [blame] | 189 | } |
| 190 | |
Arnaldo Carvalho de Melo | 7a007ca | 2010-07-21 09:19:41 -0300 | [diff] [blame] | 191 | static u8 symbol__parent_filter(const struct symbol *parent) |
| 192 | { |
| 193 | if (symbol_conf.exclude_other && parent == NULL) |
| 194 | return 1 << HIST_FILTER__PARENT; |
| 195 | return 0; |
| 196 | } |
| 197 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 198 | struct hist_entry *__hists__add_entry(struct hists *hists, |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 199 | struct addr_location *al, |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 200 | struct symbol *sym_parent, u64 period) |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 201 | { |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 202 | struct rb_node **p; |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 203 | struct rb_node *parent = NULL; |
| 204 | struct hist_entry *he; |
| 205 | struct hist_entry entry = { |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 206 | .thread = al->thread, |
Arnaldo Carvalho de Melo | 59fd530 | 2010-03-24 16:40:17 -0300 | [diff] [blame] | 207 | .ms = { |
| 208 | .map = al->map, |
| 209 | .sym = al->sym, |
| 210 | }, |
Arun Sharma | f60f359 | 2010-06-04 11:27:10 -0300 | [diff] [blame] | 211 | .cpu = al->cpu, |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 212 | .ip = al->addr, |
| 213 | .level = al->level, |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 214 | .period = period, |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 215 | .parent = sym_parent, |
Arnaldo Carvalho de Melo | 7a007ca | 2010-07-21 09:19:41 -0300 | [diff] [blame] | 216 | .filtered = symbol__parent_filter(sym_parent), |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 217 | }; |
| 218 | int cmp; |
| 219 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 220 | pthread_mutex_lock(&hists->lock); |
| 221 | |
| 222 | p = &hists->entries_in->rb_node; |
| 223 | |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 224 | while (*p != NULL) { |
| 225 | parent = *p; |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 226 | he = rb_entry(parent, struct hist_entry, rb_node_in); |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 227 | |
| 228 | cmp = hist_entry__cmp(&entry, he); |
| 229 | |
| 230 | if (!cmp) { |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 231 | he->period += period; |
| 232 | ++he->nr_events; |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 233 | goto out; |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | if (cmp < 0) |
| 237 | p = &(*p)->rb_left; |
| 238 | else |
| 239 | p = &(*p)->rb_right; |
| 240 | } |
| 241 | |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 242 | he = hist_entry__new(&entry); |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 243 | if (!he) |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 244 | goto out_unlock; |
| 245 | |
| 246 | rb_link_node(&he->rb_node_in, parent, p); |
| 247 | rb_insert_color(&he->rb_node_in, hists->entries_in); |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 248 | out: |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 249 | hist_entry__add_cpumode_period(he, al->cpumode, period); |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 250 | out_unlock: |
| 251 | pthread_mutex_unlock(&hists->lock); |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 252 | return he; |
| 253 | } |
| 254 | |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 255 | int64_t |
| 256 | hist_entry__cmp(struct hist_entry *left, struct hist_entry *right) |
| 257 | { |
| 258 | struct sort_entry *se; |
| 259 | int64_t cmp = 0; |
| 260 | |
| 261 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
Frederic Weisbecker | fcd1498 | 2010-04-14 19:11:29 +0200 | [diff] [blame] | 262 | cmp = se->se_cmp(left, right); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 263 | if (cmp) |
| 264 | break; |
| 265 | } |
| 266 | |
| 267 | return cmp; |
| 268 | } |
| 269 | |
| 270 | int64_t |
| 271 | hist_entry__collapse(struct hist_entry *left, struct hist_entry *right) |
| 272 | { |
| 273 | struct sort_entry *se; |
| 274 | int64_t cmp = 0; |
| 275 | |
| 276 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
| 277 | int64_t (*f)(struct hist_entry *, struct hist_entry *); |
| 278 | |
Frederic Weisbecker | fcd1498 | 2010-04-14 19:11:29 +0200 | [diff] [blame] | 279 | f = se->se_collapse ?: se->se_cmp; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 280 | |
| 281 | cmp = f(left, right); |
| 282 | if (cmp) |
| 283 | break; |
| 284 | } |
| 285 | |
| 286 | return cmp; |
| 287 | } |
| 288 | |
| 289 | void hist_entry__free(struct hist_entry *he) |
| 290 | { |
| 291 | free(he); |
| 292 | } |
| 293 | |
| 294 | /* |
| 295 | * collapse the histogram |
| 296 | */ |
| 297 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 298 | static bool hists__collapse_insert_entry(struct hists *hists, |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 299 | struct rb_root *root, |
| 300 | struct hist_entry *he) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 301 | { |
Arnaldo Carvalho de Melo | b9bf089 | 2009-12-14 11:37:11 -0200 | [diff] [blame] | 302 | struct rb_node **p = &root->rb_node; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 303 | struct rb_node *parent = NULL; |
| 304 | struct hist_entry *iter; |
| 305 | int64_t cmp; |
| 306 | |
| 307 | while (*p != NULL) { |
| 308 | parent = *p; |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 309 | iter = rb_entry(parent, struct hist_entry, rb_node_in); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 310 | |
| 311 | cmp = hist_entry__collapse(iter, he); |
| 312 | |
| 313 | if (!cmp) { |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 314 | iter->period += he->period; |
Stephane Eranian | e39622c | 2011-10-03 11:38:15 +0200 | [diff] [blame] | 315 | iter->nr_events += he->nr_events; |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 316 | if (symbol_conf.use_callchain) { |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 317 | callchain_cursor_reset(&hists->callchain_cursor); |
| 318 | callchain_merge(&hists->callchain_cursor, iter->callchain, |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 319 | he->callchain); |
| 320 | } |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 321 | hist_entry__free(he); |
Arnaldo Carvalho de Melo | fefb0b9 | 2010-05-10 13:57:51 -0300 | [diff] [blame] | 322 | return false; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | if (cmp < 0) |
| 326 | p = &(*p)->rb_left; |
| 327 | else |
| 328 | p = &(*p)->rb_right; |
| 329 | } |
| 330 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 331 | rb_link_node(&he->rb_node_in, parent, p); |
| 332 | rb_insert_color(&he->rb_node_in, root); |
Arnaldo Carvalho de Melo | fefb0b9 | 2010-05-10 13:57:51 -0300 | [diff] [blame] | 333 | return true; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 334 | } |
| 335 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 336 | static struct rb_root *hists__get_rotate_entries_in(struct hists *hists) |
| 337 | { |
| 338 | struct rb_root *root; |
| 339 | |
| 340 | pthread_mutex_lock(&hists->lock); |
| 341 | |
| 342 | root = hists->entries_in; |
| 343 | if (++hists->entries_in > &hists->entries_in_array[1]) |
| 344 | hists->entries_in = &hists->entries_in_array[0]; |
| 345 | |
| 346 | pthread_mutex_unlock(&hists->lock); |
| 347 | |
| 348 | return root; |
| 349 | } |
| 350 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 351 | static void hists__apply_filters(struct hists *hists, struct hist_entry *he) |
| 352 | { |
| 353 | hists__filter_entry_by_dso(hists, he); |
| 354 | hists__filter_entry_by_thread(hists, he); |
| 355 | } |
| 356 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 357 | static void __hists__collapse_resort(struct hists *hists, bool threaded) |
| 358 | { |
| 359 | struct rb_root *root; |
| 360 | struct rb_node *next; |
| 361 | struct hist_entry *n; |
| 362 | |
| 363 | if (!sort__need_collapse && !threaded) |
| 364 | return; |
| 365 | |
| 366 | root = hists__get_rotate_entries_in(hists); |
| 367 | next = rb_first(root); |
| 368 | hists->stats.total_period = 0; |
| 369 | |
| 370 | while (next) { |
| 371 | n = rb_entry(next, struct hist_entry, rb_node_in); |
| 372 | next = rb_next(&n->rb_node_in); |
| 373 | |
| 374 | rb_erase(&n->rb_node_in, root); |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 375 | if (hists__collapse_insert_entry(hists, &hists->entries_collapsed, n)) { |
| 376 | /* |
| 377 | * If it wasn't combined with one of the entries already |
| 378 | * collapsed, we need to apply the filters that may have |
| 379 | * been set by, say, the hist_browser. |
| 380 | */ |
| 381 | hists__apply_filters(hists, n); |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 382 | hists__inc_nr_entries(hists, n); |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 383 | } |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 384 | } |
| 385 | } |
| 386 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 387 | void hists__collapse_resort(struct hists *hists) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 388 | { |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 389 | return __hists__collapse_resort(hists, false); |
| 390 | } |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 391 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 392 | void hists__collapse_resort_threaded(struct hists *hists) |
| 393 | { |
| 394 | return __hists__collapse_resort(hists, true); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | /* |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 398 | * reverse the map, sort on period. |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 399 | */ |
| 400 | |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 401 | static void __hists__insert_output_entry(struct rb_root *entries, |
| 402 | struct hist_entry *he, |
| 403 | u64 min_callchain_hits) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 404 | { |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 405 | struct rb_node **p = &entries->rb_node; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 406 | struct rb_node *parent = NULL; |
| 407 | struct hist_entry *iter; |
| 408 | |
Arnaldo Carvalho de Melo | d599db3 | 2009-12-15 20:04:42 -0200 | [diff] [blame] | 409 | if (symbol_conf.use_callchain) |
Arnaldo Carvalho de Melo | b9fb930 | 2010-04-02 09:50:42 -0300 | [diff] [blame] | 410 | callchain_param.sort(&he->sorted_chain, he->callchain, |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 411 | min_callchain_hits, &callchain_param); |
| 412 | |
| 413 | while (*p != NULL) { |
| 414 | parent = *p; |
| 415 | iter = rb_entry(parent, struct hist_entry, rb_node); |
| 416 | |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 417 | if (he->period > iter->period) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 418 | p = &(*p)->rb_left; |
| 419 | else |
| 420 | p = &(*p)->rb_right; |
| 421 | } |
| 422 | |
| 423 | rb_link_node(&he->rb_node, parent, p); |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 424 | rb_insert_color(&he->rb_node, entries); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 425 | } |
| 426 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 427 | static void __hists__output_resort(struct hists *hists, bool threaded) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 428 | { |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 429 | struct rb_root *root; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 430 | struct rb_node *next; |
| 431 | struct hist_entry *n; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 432 | u64 min_callchain_hits; |
| 433 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 434 | min_callchain_hits = hists->stats.total_period * (callchain_param.min_percent / 100); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 435 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 436 | if (sort__need_collapse || threaded) |
| 437 | root = &hists->entries_collapsed; |
| 438 | else |
| 439 | root = hists->entries_in; |
| 440 | |
| 441 | next = rb_first(root); |
| 442 | hists->entries = RB_ROOT; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 443 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 444 | hists->nr_entries = 0; |
| 445 | hists__reset_col_len(hists); |
Arnaldo Carvalho de Melo | fefb0b9 | 2010-05-10 13:57:51 -0300 | [diff] [blame] | 446 | |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 447 | while (next) { |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 448 | n = rb_entry(next, struct hist_entry, rb_node_in); |
| 449 | next = rb_next(&n->rb_node_in); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 450 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 451 | __hists__insert_output_entry(&hists->entries, n, min_callchain_hits); |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 452 | hists__inc_nr_entries(hists, n); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 453 | } |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 454 | } |
Arnaldo Carvalho de Melo | b9bf089 | 2009-12-14 11:37:11 -0200 | [diff] [blame] | 455 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 456 | void hists__output_resort(struct hists *hists) |
| 457 | { |
| 458 | return __hists__output_resort(hists, false); |
| 459 | } |
| 460 | |
| 461 | void hists__output_resort_threaded(struct hists *hists) |
| 462 | { |
| 463 | return __hists__output_resort(hists, true); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 464 | } |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 465 | |
| 466 | static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin) |
| 467 | { |
| 468 | int i; |
| 469 | int ret = fprintf(fp, " "); |
| 470 | |
| 471 | for (i = 0; i < left_margin; i++) |
| 472 | ret += fprintf(fp, " "); |
| 473 | |
| 474 | return ret; |
| 475 | } |
| 476 | |
| 477 | static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask, |
| 478 | int left_margin) |
| 479 | { |
| 480 | int i; |
| 481 | size_t ret = callchain__fprintf_left_margin(fp, left_margin); |
| 482 | |
| 483 | for (i = 0; i < depth; i++) |
| 484 | if (depth_mask & (1 << i)) |
| 485 | ret += fprintf(fp, "| "); |
| 486 | else |
| 487 | ret += fprintf(fp, " "); |
| 488 | |
| 489 | ret += fprintf(fp, "\n"); |
| 490 | |
| 491 | return ret; |
| 492 | } |
| 493 | |
| 494 | static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain, |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 495 | int depth, int depth_mask, int period, |
Frederic Weisbecker | d425de5 | 2011-01-03 16:13:11 +0100 | [diff] [blame] | 496 | u64 total_samples, u64 hits, |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 497 | int left_margin) |
| 498 | { |
| 499 | int i; |
| 500 | size_t ret = 0; |
| 501 | |
| 502 | ret += callchain__fprintf_left_margin(fp, left_margin); |
| 503 | for (i = 0; i < depth; i++) { |
| 504 | if (depth_mask & (1 << i)) |
| 505 | ret += fprintf(fp, "|"); |
| 506 | else |
| 507 | ret += fprintf(fp, " "); |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 508 | if (!period && i == depth - 1) { |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 509 | double percent; |
| 510 | |
| 511 | percent = hits * 100.0 / total_samples; |
| 512 | ret += percent_color_fprintf(fp, "--%2.2f%%-- ", percent); |
| 513 | } else |
| 514 | ret += fprintf(fp, "%s", " "); |
| 515 | } |
Arnaldo Carvalho de Melo | b3c9ac0 | 2010-03-24 16:40:18 -0300 | [diff] [blame] | 516 | if (chain->ms.sym) |
| 517 | ret += fprintf(fp, "%s\n", chain->ms.sym->name); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 518 | else |
| 519 | ret += fprintf(fp, "%p\n", (void *)(long)chain->ip); |
| 520 | |
| 521 | return ret; |
| 522 | } |
| 523 | |
| 524 | static struct symbol *rem_sq_bracket; |
| 525 | static struct callchain_list rem_hits; |
| 526 | |
| 527 | static void init_rem_hits(void) |
| 528 | { |
| 529 | rem_sq_bracket = malloc(sizeof(*rem_sq_bracket) + 6); |
| 530 | if (!rem_sq_bracket) { |
| 531 | fprintf(stderr, "Not enough memory to display remaining hits\n"); |
| 532 | return; |
| 533 | } |
| 534 | |
| 535 | strcpy(rem_sq_bracket->name, "[...]"); |
Arnaldo Carvalho de Melo | b3c9ac0 | 2010-03-24 16:40:18 -0300 | [diff] [blame] | 536 | rem_hits.ms.sym = rem_sq_bracket; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | static size_t __callchain__fprintf_graph(FILE *fp, struct callchain_node *self, |
| 540 | u64 total_samples, int depth, |
| 541 | int depth_mask, int left_margin) |
| 542 | { |
| 543 | struct rb_node *node, *next; |
| 544 | struct callchain_node *child; |
| 545 | struct callchain_list *chain; |
| 546 | int new_depth_mask = depth_mask; |
| 547 | u64 new_total; |
| 548 | u64 remaining; |
| 549 | size_t ret = 0; |
| 550 | int i; |
Arnaldo Carvalho de Melo | 232a5c9 | 2010-05-09 20:28:10 -0300 | [diff] [blame] | 551 | uint entries_printed = 0; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 552 | |
| 553 | if (callchain_param.mode == CHAIN_GRAPH_REL) |
| 554 | new_total = self->children_hit; |
| 555 | else |
| 556 | new_total = total_samples; |
| 557 | |
| 558 | remaining = new_total; |
| 559 | |
| 560 | node = rb_first(&self->rb_root); |
| 561 | while (node) { |
| 562 | u64 cumul; |
| 563 | |
| 564 | child = rb_entry(node, struct callchain_node, rb_node); |
Frederic Weisbecker | f08c315 | 2011-01-14 04:51:59 +0100 | [diff] [blame] | 565 | cumul = callchain_cumul_hits(child); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 566 | remaining -= cumul; |
| 567 | |
| 568 | /* |
| 569 | * The depth mask manages the output of pipes that show |
| 570 | * the depth. We don't want to keep the pipes of the current |
| 571 | * level for the last child of this depth. |
| 572 | * Except if we have remaining filtered hits. They will |
| 573 | * supersede the last child |
| 574 | */ |
| 575 | next = rb_next(node); |
| 576 | if (!next && (callchain_param.mode != CHAIN_GRAPH_REL || !remaining)) |
| 577 | new_depth_mask &= ~(1 << (depth - 1)); |
| 578 | |
| 579 | /* |
Daniel Mack | 3ad2f3fb | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 580 | * But we keep the older depth mask for the line separator |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 581 | * to keep the level link until we reach the last child |
| 582 | */ |
| 583 | ret += ipchain__fprintf_graph_line(fp, depth, depth_mask, |
| 584 | left_margin); |
| 585 | i = 0; |
| 586 | list_for_each_entry(chain, &child->val, list) { |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 587 | ret += ipchain__fprintf_graph(fp, chain, depth, |
| 588 | new_depth_mask, i++, |
| 589 | new_total, |
| 590 | cumul, |
| 591 | left_margin); |
| 592 | } |
| 593 | ret += __callchain__fprintf_graph(fp, child, new_total, |
| 594 | depth + 1, |
| 595 | new_depth_mask | (1 << depth), |
| 596 | left_margin); |
| 597 | node = next; |
Arnaldo Carvalho de Melo | 232a5c9 | 2010-05-09 20:28:10 -0300 | [diff] [blame] | 598 | if (++entries_printed == callchain_param.print_limit) |
| 599 | break; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | if (callchain_param.mode == CHAIN_GRAPH_REL && |
| 603 | remaining && remaining != new_total) { |
| 604 | |
| 605 | if (!rem_sq_bracket) |
| 606 | return ret; |
| 607 | |
| 608 | new_depth_mask &= ~(1 << (depth - 1)); |
| 609 | |
| 610 | ret += ipchain__fprintf_graph(fp, &rem_hits, depth, |
| 611 | new_depth_mask, 0, new_total, |
| 612 | remaining, left_margin); |
| 613 | } |
| 614 | |
| 615 | return ret; |
| 616 | } |
| 617 | |
| 618 | static size_t callchain__fprintf_graph(FILE *fp, struct callchain_node *self, |
| 619 | u64 total_samples, int left_margin) |
| 620 | { |
| 621 | struct callchain_list *chain; |
| 622 | bool printed = false; |
| 623 | int i = 0; |
| 624 | int ret = 0; |
Arnaldo Carvalho de Melo | 232a5c9 | 2010-05-09 20:28:10 -0300 | [diff] [blame] | 625 | u32 entries_printed = 0; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 626 | |
| 627 | list_for_each_entry(chain, &self->val, list) { |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 628 | if (!i++ && sort__first_dimension == SORT_SYM) |
| 629 | continue; |
| 630 | |
| 631 | if (!printed) { |
| 632 | ret += callchain__fprintf_left_margin(fp, left_margin); |
| 633 | ret += fprintf(fp, "|\n"); |
| 634 | ret += callchain__fprintf_left_margin(fp, left_margin); |
| 635 | ret += fprintf(fp, "---"); |
| 636 | |
| 637 | left_margin += 3; |
| 638 | printed = true; |
| 639 | } else |
| 640 | ret += callchain__fprintf_left_margin(fp, left_margin); |
| 641 | |
Arnaldo Carvalho de Melo | b3c9ac0 | 2010-03-24 16:40:18 -0300 | [diff] [blame] | 642 | if (chain->ms.sym) |
| 643 | ret += fprintf(fp, " %s\n", chain->ms.sym->name); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 644 | else |
| 645 | ret += fprintf(fp, " %p\n", (void *)(long)chain->ip); |
Arnaldo Carvalho de Melo | 232a5c9 | 2010-05-09 20:28:10 -0300 | [diff] [blame] | 646 | |
| 647 | if (++entries_printed == callchain_param.print_limit) |
| 648 | break; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | ret += __callchain__fprintf_graph(fp, self, total_samples, 1, 1, left_margin); |
| 652 | |
| 653 | return ret; |
| 654 | } |
| 655 | |
| 656 | static size_t callchain__fprintf_flat(FILE *fp, struct callchain_node *self, |
| 657 | u64 total_samples) |
| 658 | { |
| 659 | struct callchain_list *chain; |
| 660 | size_t ret = 0; |
| 661 | |
| 662 | if (!self) |
| 663 | return 0; |
| 664 | |
| 665 | ret += callchain__fprintf_flat(fp, self->parent, total_samples); |
| 666 | |
| 667 | |
| 668 | list_for_each_entry(chain, &self->val, list) { |
| 669 | if (chain->ip >= PERF_CONTEXT_MAX) |
| 670 | continue; |
Arnaldo Carvalho de Melo | b3c9ac0 | 2010-03-24 16:40:18 -0300 | [diff] [blame] | 671 | if (chain->ms.sym) |
| 672 | ret += fprintf(fp, " %s\n", chain->ms.sym->name); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 673 | else |
| 674 | ret += fprintf(fp, " %p\n", |
| 675 | (void *)(long)chain->ip); |
| 676 | } |
| 677 | |
| 678 | return ret; |
| 679 | } |
| 680 | |
| 681 | static size_t hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self, |
| 682 | u64 total_samples, int left_margin) |
| 683 | { |
| 684 | struct rb_node *rb_node; |
| 685 | struct callchain_node *chain; |
| 686 | size_t ret = 0; |
Arnaldo Carvalho de Melo | 232a5c9 | 2010-05-09 20:28:10 -0300 | [diff] [blame] | 687 | u32 entries_printed = 0; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 688 | |
| 689 | rb_node = rb_first(&self->sorted_chain); |
| 690 | while (rb_node) { |
| 691 | double percent; |
| 692 | |
| 693 | chain = rb_entry(rb_node, struct callchain_node, rb_node); |
| 694 | percent = chain->hit * 100.0 / total_samples; |
| 695 | switch (callchain_param.mode) { |
| 696 | case CHAIN_FLAT: |
| 697 | ret += percent_color_fprintf(fp, " %6.2f%%\n", |
| 698 | percent); |
| 699 | ret += callchain__fprintf_flat(fp, chain, total_samples); |
| 700 | break; |
| 701 | case CHAIN_GRAPH_ABS: /* Falldown */ |
| 702 | case CHAIN_GRAPH_REL: |
| 703 | ret += callchain__fprintf_graph(fp, chain, total_samples, |
| 704 | left_margin); |
| 705 | case CHAIN_NONE: |
| 706 | default: |
| 707 | break; |
| 708 | } |
| 709 | ret += fprintf(fp, "\n"); |
Arnaldo Carvalho de Melo | 232a5c9 | 2010-05-09 20:28:10 -0300 | [diff] [blame] | 710 | if (++entries_printed == callchain_param.print_limit) |
| 711 | break; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 712 | rb_node = rb_next(rb_node); |
| 713 | } |
| 714 | |
| 715 | return ret; |
| 716 | } |
| 717 | |
Arnaldo Carvalho de Melo | ab81f3fd | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 718 | void hists__output_recalc_col_len(struct hists *hists, int max_rows) |
| 719 | { |
| 720 | struct rb_node *next = rb_first(&hists->entries); |
| 721 | struct hist_entry *n; |
| 722 | int row = 0; |
| 723 | |
| 724 | hists__reset_col_len(hists); |
| 725 | |
| 726 | while (next && row++ < max_rows) { |
| 727 | n = rb_entry(next, struct hist_entry, rb_node); |
| 728 | hists__calc_col_len(hists, n); |
| 729 | next = rb_next(&n->rb_node); |
| 730 | } |
| 731 | } |
| 732 | |
Arnaldo Carvalho de Melo | f1cf602 | 2011-10-18 14:37:34 -0200 | [diff] [blame] | 733 | static int hist_entry__pcnt_snprintf(struct hist_entry *self, char *s, |
| 734 | size_t size, struct hists *pair_hists, |
| 735 | bool show_displacement, long displacement, |
| 736 | bool color, u64 session_total) |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 737 | { |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 738 | u64 period, total, period_sys, period_us, period_guest_sys, period_guest_us; |
Arnaldo Carvalho de Melo | fec9cbd | 2011-02-17 10:37:23 -0200 | [diff] [blame] | 739 | u64 nr_events; |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 740 | const char *sep = symbol_conf.field_sep; |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 741 | int ret; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 742 | |
| 743 | if (symbol_conf.exclude_other && !self->parent) |
| 744 | return 0; |
| 745 | |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 746 | if (pair_hists) { |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 747 | period = self->pair ? self->pair->period : 0; |
Arnaldo Carvalho de Melo | fec9cbd | 2011-02-17 10:37:23 -0200 | [diff] [blame] | 748 | nr_events = self->pair ? self->pair->nr_events : 0; |
Arnaldo Carvalho de Melo | cee75ac | 2010-05-14 13:16:55 -0300 | [diff] [blame] | 749 | total = pair_hists->stats.total_period; |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 750 | period_sys = self->pair ? self->pair->period_sys : 0; |
| 751 | period_us = self->pair ? self->pair->period_us : 0; |
| 752 | period_guest_sys = self->pair ? self->pair->period_guest_sys : 0; |
| 753 | period_guest_us = self->pair ? self->pair->period_guest_us : 0; |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 754 | } else { |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 755 | period = self->period; |
Arnaldo Carvalho de Melo | fec9cbd | 2011-02-17 10:37:23 -0200 | [diff] [blame] | 756 | nr_events = self->nr_events; |
Eric B Munson | eefc465 | 2010-03-05 12:51:08 -0300 | [diff] [blame] | 757 | total = session_total; |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 758 | period_sys = self->period_sys; |
| 759 | period_us = self->period_us; |
| 760 | period_guest_sys = self->period_guest_sys; |
| 761 | period_guest_us = self->period_guest_us; |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 762 | } |
| 763 | |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 764 | if (total) { |
| 765 | if (color) |
| 766 | ret = percent_color_snprintf(s, size, |
| 767 | sep ? "%.2f" : " %6.2f%%", |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 768 | (period * 100.0) / total); |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 769 | else |
| 770 | ret = snprintf(s, size, sep ? "%.2f" : " %6.2f%%", |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 771 | (period * 100.0) / total); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 772 | if (symbol_conf.show_cpu_utilization) { |
| 773 | ret += percent_color_snprintf(s + ret, size - ret, |
| 774 | sep ? "%.2f" : " %6.2f%%", |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 775 | (period_sys * 100.0) / total); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 776 | ret += percent_color_snprintf(s + ret, size - ret, |
| 777 | sep ? "%.2f" : " %6.2f%%", |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 778 | (period_us * 100.0) / total); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 779 | if (perf_guest) { |
| 780 | ret += percent_color_snprintf(s + ret, |
| 781 | size - ret, |
| 782 | sep ? "%.2f" : " %6.2f%%", |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 783 | (period_guest_sys * 100.0) / |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 784 | total); |
| 785 | ret += percent_color_snprintf(s + ret, |
| 786 | size - ret, |
| 787 | sep ? "%.2f" : " %6.2f%%", |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 788 | (period_guest_us * 100.0) / |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 789 | total); |
| 790 | } |
| 791 | } |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 792 | } else |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 793 | ret = snprintf(s, size, sep ? "%" PRIu64 : "%12" PRIu64 " ", period); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 794 | |
| 795 | if (symbol_conf.show_nr_samples) { |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 796 | if (sep) |
Arnaldo Carvalho de Melo | fec9cbd | 2011-02-17 10:37:23 -0200 | [diff] [blame] | 797 | ret += snprintf(s + ret, size - ret, "%c%" PRIu64, *sep, nr_events); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 798 | else |
Arnaldo Carvalho de Melo | fec9cbd | 2011-02-17 10:37:23 -0200 | [diff] [blame] | 799 | ret += snprintf(s + ret, size - ret, "%11" PRIu64, nr_events); |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 800 | } |
| 801 | |
Arnaldo Carvalho de Melo | 3f2728b | 2011-10-05 16:10:06 -0300 | [diff] [blame] | 802 | if (symbol_conf.show_total_period) { |
| 803 | if (sep) |
| 804 | ret += snprintf(s + ret, size - ret, "%c%" PRIu64, *sep, period); |
| 805 | else |
| 806 | ret += snprintf(s + ret, size - ret, " %12" PRIu64, period); |
| 807 | } |
| 808 | |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 809 | if (pair_hists) { |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 810 | char bf[32]; |
| 811 | double old_percent = 0, new_percent = 0, diff; |
| 812 | |
| 813 | if (total > 0) |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 814 | old_percent = (period * 100.0) / total; |
Eric B Munson | eefc465 | 2010-03-05 12:51:08 -0300 | [diff] [blame] | 815 | if (session_total > 0) |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 816 | new_percent = (self->period * 100.0) / session_total; |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 817 | |
Arnaldo Carvalho de Melo | 9b33827 | 2009-12-16 14:31:49 -0200 | [diff] [blame] | 818 | diff = new_percent - old_percent; |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 819 | |
Arnaldo Carvalho de Melo | 9b33827 | 2009-12-16 14:31:49 -0200 | [diff] [blame] | 820 | if (fabs(diff) >= 0.01) |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 821 | snprintf(bf, sizeof(bf), "%+4.2F%%", diff); |
| 822 | else |
| 823 | snprintf(bf, sizeof(bf), " "); |
| 824 | |
| 825 | if (sep) |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 826 | ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf); |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 827 | else |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 828 | ret += snprintf(s + ret, size - ret, "%11.11s", bf); |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 829 | |
| 830 | if (show_displacement) { |
| 831 | if (displacement) |
| 832 | snprintf(bf, sizeof(bf), "%+4ld", displacement); |
| 833 | else |
| 834 | snprintf(bf, sizeof(bf), " "); |
| 835 | |
| 836 | if (sep) |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 837 | ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf); |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 838 | else |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 839 | ret += snprintf(s + ret, size - ret, "%6.6s", bf); |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 840 | } |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 841 | } |
| 842 | |
Arnaldo Carvalho de Melo | f1cf602 | 2011-10-18 14:37:34 -0200 | [diff] [blame] | 843 | return ret; |
| 844 | } |
| 845 | |
| 846 | int hist_entry__snprintf(struct hist_entry *he, char *s, size_t size, |
| 847 | struct hists *hists) |
| 848 | { |
| 849 | const char *sep = symbol_conf.field_sep; |
| 850 | struct sort_entry *se; |
| 851 | int ret = 0; |
| 852 | |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 853 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
| 854 | if (se->elide) |
| 855 | continue; |
| 856 | |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 857 | ret += snprintf(s + ret, size - ret, "%s", sep ?: " "); |
Arnaldo Carvalho de Melo | f1cf602 | 2011-10-18 14:37:34 -0200 | [diff] [blame] | 858 | ret += se->se_snprintf(he, s + ret, size - ret, |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 859 | hists__col_len(hists, se->se_width_idx)); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 860 | } |
| 861 | |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 862 | return ret; |
| 863 | } |
| 864 | |
Arnaldo Carvalho de Melo | ef9dfe6 | 2011-09-26 12:46:11 -0300 | [diff] [blame] | 865 | int hist_entry__fprintf(struct hist_entry *he, size_t size, struct hists *hists, |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 866 | struct hists *pair_hists, bool show_displacement, |
| 867 | long displacement, FILE *fp, u64 session_total) |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 868 | { |
| 869 | char bf[512]; |
Arnaldo Carvalho de Melo | f1cf602 | 2011-10-18 14:37:34 -0200 | [diff] [blame] | 870 | int ret; |
Arnaldo Carvalho de Melo | ef9dfe6 | 2011-09-26 12:46:11 -0300 | [diff] [blame] | 871 | |
| 872 | if (size == 0 || size > sizeof(bf)) |
| 873 | size = sizeof(bf); |
| 874 | |
Arnaldo Carvalho de Melo | f1cf602 | 2011-10-18 14:37:34 -0200 | [diff] [blame] | 875 | ret = hist_entry__pcnt_snprintf(he, bf, size, pair_hists, |
| 876 | show_displacement, displacement, |
| 877 | true, session_total); |
| 878 | hist_entry__snprintf(he, bf + ret, size - ret, hists); |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 879 | return fprintf(fp, "%s\n", bf); |
Arnaldo Carvalho de Melo | 3997d37 | 2010-03-12 12:46:48 -0300 | [diff] [blame] | 880 | } |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 881 | |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 882 | static size_t hist_entry__fprintf_callchain(struct hist_entry *self, |
| 883 | struct hists *hists, FILE *fp, |
Arnaldo Carvalho de Melo | 3997d37 | 2010-03-12 12:46:48 -0300 | [diff] [blame] | 884 | u64 session_total) |
| 885 | { |
| 886 | int left_margin = 0; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 887 | |
Arnaldo Carvalho de Melo | 3997d37 | 2010-03-12 12:46:48 -0300 | [diff] [blame] | 888 | if (sort__first_dimension == SORT_COMM) { |
| 889 | struct sort_entry *se = list_first_entry(&hist_entry__sort_list, |
| 890 | typeof(*se), list); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 891 | left_margin = hists__col_len(hists, se->se_width_idx); |
Arnaldo Carvalho de Melo | 3997d37 | 2010-03-12 12:46:48 -0300 | [diff] [blame] | 892 | left_margin -= thread__comm_len(self->thread); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 893 | } |
| 894 | |
Arnaldo Carvalho de Melo | 3997d37 | 2010-03-12 12:46:48 -0300 | [diff] [blame] | 895 | return hist_entry_callchain__fprintf(fp, self, session_total, |
| 896 | left_margin); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 897 | } |
| 898 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 899 | size_t hists__fprintf(struct hists *hists, struct hists *pair, |
Arnaldo Carvalho de Melo | ef9dfe6 | 2011-09-26 12:46:11 -0300 | [diff] [blame] | 900 | bool show_displacement, bool show_header, int max_rows, |
| 901 | int max_cols, FILE *fp) |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 902 | { |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 903 | struct sort_entry *se; |
| 904 | struct rb_node *nd; |
| 905 | size_t ret = 0; |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 906 | unsigned long position = 1; |
| 907 | long displacement = 0; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 908 | unsigned int width; |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 909 | const char *sep = symbol_conf.field_sep; |
Arnaldo Carvalho de Melo | edb7c60 | 2010-05-17 16:22:41 -0300 | [diff] [blame] | 910 | const char *col_width = symbol_conf.col_width_list_str; |
Arnaldo Carvalho de Melo | ef9dfe6 | 2011-09-26 12:46:11 -0300 | [diff] [blame] | 911 | int nr_rows = 0; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 912 | |
| 913 | init_rem_hits(); |
| 914 | |
Arnaldo Carvalho de Melo | ef9dfe6 | 2011-09-26 12:46:11 -0300 | [diff] [blame] | 915 | if (!show_header) |
| 916 | goto print_entries; |
| 917 | |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 918 | fprintf(fp, "# %s", pair ? "Baseline" : "Overhead"); |
| 919 | |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 920 | if (symbol_conf.show_nr_samples) { |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 921 | if (sep) |
| 922 | fprintf(fp, "%cSamples", *sep); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 923 | else |
| 924 | fputs(" Samples ", fp); |
| 925 | } |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 926 | |
Arnaldo Carvalho de Melo | 3f2728b | 2011-10-05 16:10:06 -0300 | [diff] [blame] | 927 | if (symbol_conf.show_total_period) { |
| 928 | if (sep) |
| 929 | ret += fprintf(fp, "%cPeriod", *sep); |
| 930 | else |
| 931 | ret += fprintf(fp, " Period "); |
| 932 | } |
| 933 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 934 | if (symbol_conf.show_cpu_utilization) { |
| 935 | if (sep) { |
| 936 | ret += fprintf(fp, "%csys", *sep); |
| 937 | ret += fprintf(fp, "%cus", *sep); |
| 938 | if (perf_guest) { |
| 939 | ret += fprintf(fp, "%cguest sys", *sep); |
| 940 | ret += fprintf(fp, "%cguest us", *sep); |
| 941 | } |
| 942 | } else { |
| 943 | ret += fprintf(fp, " sys "); |
| 944 | ret += fprintf(fp, " us "); |
| 945 | if (perf_guest) { |
| 946 | ret += fprintf(fp, " guest sys "); |
| 947 | ret += fprintf(fp, " guest us "); |
| 948 | } |
| 949 | } |
| 950 | } |
| 951 | |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 952 | if (pair) { |
| 953 | if (sep) |
| 954 | ret += fprintf(fp, "%cDelta", *sep); |
| 955 | else |
| 956 | ret += fprintf(fp, " Delta "); |
| 957 | |
| 958 | if (show_displacement) { |
| 959 | if (sep) |
| 960 | ret += fprintf(fp, "%cDisplacement", *sep); |
| 961 | else |
| 962 | ret += fprintf(fp, " Displ"); |
| 963 | } |
| 964 | } |
| 965 | |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 966 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
| 967 | if (se->elide) |
| 968 | continue; |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 969 | if (sep) { |
Frederic Weisbecker | fcd1498 | 2010-04-14 19:11:29 +0200 | [diff] [blame] | 970 | fprintf(fp, "%c%s", *sep, se->se_header); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 971 | continue; |
| 972 | } |
Frederic Weisbecker | fcd1498 | 2010-04-14 19:11:29 +0200 | [diff] [blame] | 973 | width = strlen(se->se_header); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 974 | if (symbol_conf.col_width_list_str) { |
| 975 | if (col_width) { |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 976 | hists__set_col_len(hists, se->se_width_idx, |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 977 | atoi(col_width)); |
| 978 | col_width = strchr(col_width, ','); |
| 979 | if (col_width) |
| 980 | ++col_width; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 981 | } |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 982 | } |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 983 | if (!hists__new_col_len(hists, se->se_width_idx, width)) |
| 984 | width = hists__col_len(hists, se->se_width_idx); |
Frederic Weisbecker | fcd1498 | 2010-04-14 19:11:29 +0200 | [diff] [blame] | 985 | fprintf(fp, " %*s", width, se->se_header); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 986 | } |
Arnaldo Carvalho de Melo | ef9dfe6 | 2011-09-26 12:46:11 -0300 | [diff] [blame] | 987 | |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 988 | fprintf(fp, "\n"); |
Arnaldo Carvalho de Melo | ef9dfe6 | 2011-09-26 12:46:11 -0300 | [diff] [blame] | 989 | if (max_rows && ++nr_rows >= max_rows) |
| 990 | goto out; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 991 | |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 992 | if (sep) |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 993 | goto print_entries; |
| 994 | |
| 995 | fprintf(fp, "# ........"); |
| 996 | if (symbol_conf.show_nr_samples) |
| 997 | fprintf(fp, " .........."); |
Arnaldo Carvalho de Melo | 3f2728b | 2011-10-05 16:10:06 -0300 | [diff] [blame] | 998 | if (symbol_conf.show_total_period) |
| 999 | fprintf(fp, " ............"); |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 1000 | if (pair) { |
| 1001 | fprintf(fp, " .........."); |
| 1002 | if (show_displacement) |
| 1003 | fprintf(fp, " ....."); |
| 1004 | } |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 1005 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
| 1006 | unsigned int i; |
| 1007 | |
| 1008 | if (se->elide) |
| 1009 | continue; |
| 1010 | |
| 1011 | fprintf(fp, " "); |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1012 | width = hists__col_len(hists, se->se_width_idx); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 1013 | if (width == 0) |
Frederic Weisbecker | fcd1498 | 2010-04-14 19:11:29 +0200 | [diff] [blame] | 1014 | width = strlen(se->se_header); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 1015 | for (i = 0; i < width; i++) |
| 1016 | fprintf(fp, "."); |
| 1017 | } |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 1018 | |
Arnaldo Carvalho de Melo | ef9dfe6 | 2011-09-26 12:46:11 -0300 | [diff] [blame] | 1019 | fprintf(fp, "\n"); |
| 1020 | if (max_rows && ++nr_rows >= max_rows) |
| 1021 | goto out; |
| 1022 | |
| 1023 | fprintf(fp, "#\n"); |
| 1024 | if (max_rows && ++nr_rows >= max_rows) |
| 1025 | goto out; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 1026 | |
| 1027 | print_entries: |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1028 | for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 1029 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 1030 | |
Frederic Weisbecker | e84d212 | 2011-06-29 22:23:03 +0200 | [diff] [blame] | 1031 | if (h->filtered) |
| 1032 | continue; |
| 1033 | |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 1034 | if (show_displacement) { |
| 1035 | if (h->pair != NULL) |
| 1036 | displacement = ((long)h->pair->position - |
| 1037 | (long)position); |
| 1038 | else |
| 1039 | displacement = 0; |
| 1040 | ++position; |
| 1041 | } |
Arnaldo Carvalho de Melo | ef9dfe6 | 2011-09-26 12:46:11 -0300 | [diff] [blame] | 1042 | ret += hist_entry__fprintf(h, max_cols, hists, pair, show_displacement, |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1043 | displacement, fp, hists->stats.total_period); |
Arnaldo Carvalho de Melo | 3997d37 | 2010-03-12 12:46:48 -0300 | [diff] [blame] | 1044 | |
| 1045 | if (symbol_conf.use_callchain) |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1046 | ret += hist_entry__fprintf_callchain(h, hists, fp, |
| 1047 | hists->stats.total_period); |
Arnaldo Carvalho de Melo | ef9dfe6 | 2011-09-26 12:46:11 -0300 | [diff] [blame] | 1048 | if (max_rows && ++nr_rows >= max_rows) |
| 1049 | goto out; |
| 1050 | |
Arnaldo Carvalho de Melo | 59fd530 | 2010-03-24 16:40:17 -0300 | [diff] [blame] | 1051 | if (h->ms.map == NULL && verbose > 1) { |
Arnaldo Carvalho de Melo | 65f2ed2 | 2010-03-09 15:58:17 -0300 | [diff] [blame] | 1052 | __map_groups__fprintf_maps(&h->thread->mg, |
Arnaldo Carvalho de Melo | c6e718f | 2010-03-26 12:11:06 -0300 | [diff] [blame] | 1053 | MAP__FUNCTION, verbose, fp); |
Arnaldo Carvalho de Melo | 65f2ed2 | 2010-03-09 15:58:17 -0300 | [diff] [blame] | 1054 | fprintf(fp, "%.10s end\n", graph_dotted_line); |
| 1055 | } |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 1056 | } |
Arnaldo Carvalho de Melo | ef9dfe6 | 2011-09-26 12:46:11 -0300 | [diff] [blame] | 1057 | out: |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 1058 | free(rem_sq_bracket); |
| 1059 | |
| 1060 | return ret; |
| 1061 | } |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1062 | |
Arnaldo Carvalho de Melo | 06daaab | 2010-07-21 17:58:25 -0300 | [diff] [blame] | 1063 | /* |
| 1064 | * See hists__fprintf to match the column widths |
| 1065 | */ |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1066 | unsigned int hists__sort_list_width(struct hists *hists) |
Arnaldo Carvalho de Melo | 06daaab | 2010-07-21 17:58:25 -0300 | [diff] [blame] | 1067 | { |
| 1068 | struct sort_entry *se; |
| 1069 | int ret = 9; /* total % */ |
| 1070 | |
| 1071 | if (symbol_conf.show_cpu_utilization) { |
| 1072 | ret += 7; /* count_sys % */ |
| 1073 | ret += 6; /* count_us % */ |
| 1074 | if (perf_guest) { |
| 1075 | ret += 13; /* count_guest_sys % */ |
| 1076 | ret += 12; /* count_guest_us % */ |
| 1077 | } |
| 1078 | } |
| 1079 | |
| 1080 | if (symbol_conf.show_nr_samples) |
| 1081 | ret += 11; |
| 1082 | |
Arnaldo Carvalho de Melo | 3f2728b | 2011-10-05 16:10:06 -0300 | [diff] [blame] | 1083 | if (symbol_conf.show_total_period) |
| 1084 | ret += 13; |
| 1085 | |
Arnaldo Carvalho de Melo | 06daaab | 2010-07-21 17:58:25 -0300 | [diff] [blame] | 1086 | list_for_each_entry(se, &hist_entry__sort_list, list) |
| 1087 | if (!se->elide) |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1088 | ret += 2 + hists__col_len(hists, se->se_width_idx); |
Arnaldo Carvalho de Melo | 06daaab | 2010-07-21 17:58:25 -0300 | [diff] [blame] | 1089 | |
Arnaldo Carvalho de Melo | 903cce6 | 2010-08-05 19:15:48 -0300 | [diff] [blame] | 1090 | if (verbose) /* Addr + origin */ |
| 1091 | ret += 3 + BITS_PER_LONG / 4; |
| 1092 | |
Arnaldo Carvalho de Melo | 06daaab | 2010-07-21 17:58:25 -0300 | [diff] [blame] | 1093 | return ret; |
| 1094 | } |
| 1095 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1096 | static void hists__remove_entry_filter(struct hists *hists, struct hist_entry *h, |
Arnaldo Carvalho de Melo | cc5edb0 | 2010-07-16 12:35:07 -0300 | [diff] [blame] | 1097 | enum hist_filter filter) |
| 1098 | { |
| 1099 | h->filtered &= ~(1 << filter); |
| 1100 | if (h->filtered) |
| 1101 | return; |
| 1102 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1103 | ++hists->nr_entries; |
Arnaldo Carvalho de Melo | 0f0cbf7 | 2010-07-26 17:13:40 -0300 | [diff] [blame] | 1104 | if (h->ms.unfolded) |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1105 | hists->nr_entries += h->nr_rows; |
Arnaldo Carvalho de Melo | 0f0cbf7 | 2010-07-26 17:13:40 -0300 | [diff] [blame] | 1106 | h->row_offset = 0; |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1107 | hists->stats.total_period += h->period; |
| 1108 | hists->stats.nr_events[PERF_RECORD_SAMPLE] += h->nr_events; |
Arnaldo Carvalho de Melo | cc5edb0 | 2010-07-16 12:35:07 -0300 | [diff] [blame] | 1109 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1110 | hists__calc_col_len(hists, h); |
Arnaldo Carvalho de Melo | cc5edb0 | 2010-07-16 12:35:07 -0300 | [diff] [blame] | 1111 | } |
| 1112 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 1113 | |
| 1114 | static bool hists__filter_entry_by_dso(struct hists *hists, |
| 1115 | struct hist_entry *he) |
| 1116 | { |
| 1117 | if (hists->dso_filter != NULL && |
| 1118 | (he->ms.map == NULL || he->ms.map->dso != hists->dso_filter)) { |
| 1119 | he->filtered |= (1 << HIST_FILTER__DSO); |
| 1120 | return true; |
| 1121 | } |
| 1122 | |
| 1123 | return false; |
| 1124 | } |
| 1125 | |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 1126 | void hists__filter_by_dso(struct hists *hists) |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1127 | { |
| 1128 | struct rb_node *nd; |
| 1129 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1130 | hists->nr_entries = hists->stats.total_period = 0; |
| 1131 | hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0; |
| 1132 | hists__reset_col_len(hists); |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1133 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1134 | for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1135 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 1136 | |
| 1137 | if (symbol_conf.exclude_other && !h->parent) |
| 1138 | continue; |
| 1139 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 1140 | if (hists__filter_entry_by_dso(hists, h)) |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1141 | continue; |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1142 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1143 | hists__remove_entry_filter(hists, h, HIST_FILTER__DSO); |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1144 | } |
| 1145 | } |
| 1146 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 1147 | static bool hists__filter_entry_by_thread(struct hists *hists, |
| 1148 | struct hist_entry *he) |
| 1149 | { |
| 1150 | if (hists->thread_filter != NULL && |
| 1151 | he->thread != hists->thread_filter) { |
| 1152 | he->filtered |= (1 << HIST_FILTER__THREAD); |
| 1153 | return true; |
| 1154 | } |
| 1155 | |
| 1156 | return false; |
| 1157 | } |
| 1158 | |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 1159 | void hists__filter_by_thread(struct hists *hists) |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1160 | { |
| 1161 | struct rb_node *nd; |
| 1162 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1163 | hists->nr_entries = hists->stats.total_period = 0; |
| 1164 | hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0; |
| 1165 | hists__reset_col_len(hists); |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1166 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1167 | for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1168 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 1169 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 1170 | if (hists__filter_entry_by_thread(hists, h)) |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1171 | continue; |
Arnaldo Carvalho de Melo | cc5edb0 | 2010-07-16 12:35:07 -0300 | [diff] [blame] | 1172 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1173 | hists__remove_entry_filter(hists, h, HIST_FILTER__THREAD); |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1174 | } |
| 1175 | } |
Arnaldo Carvalho de Melo | ef7b93a | 2010-05-11 23:18:06 -0300 | [diff] [blame] | 1176 | |
Arnaldo Carvalho de Melo | 2f525d0 | 2011-02-04 13:43:24 -0200 | [diff] [blame] | 1177 | int hist_entry__inc_addr_samples(struct hist_entry *he, int evidx, u64 ip) |
Arnaldo Carvalho de Melo | ef7b93a | 2010-05-11 23:18:06 -0300 | [diff] [blame] | 1178 | { |
Arnaldo Carvalho de Melo | 2f525d0 | 2011-02-04 13:43:24 -0200 | [diff] [blame] | 1179 | return symbol__inc_addr_samples(he->ms.sym, he->ms.map, evidx, ip); |
Arnaldo Carvalho de Melo | ef7b93a | 2010-05-11 23:18:06 -0300 | [diff] [blame] | 1180 | } |
| 1181 | |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 1182 | int hist_entry__annotate(struct hist_entry *he, size_t privsize) |
Arnaldo Carvalho de Melo | ef7b93a | 2010-05-11 23:18:06 -0300 | [diff] [blame] | 1183 | { |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 1184 | return symbol__annotate(he->ms.sym, he->ms.map, privsize); |
Arnaldo Carvalho de Melo | ef7b93a | 2010-05-11 23:18:06 -0300 | [diff] [blame] | 1185 | } |
Arnaldo Carvalho de Melo | c8446b9 | 2010-05-14 10:36:42 -0300 | [diff] [blame] | 1186 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1187 | void hists__inc_nr_events(struct hists *hists, u32 type) |
Arnaldo Carvalho de Melo | c8446b9 | 2010-05-14 10:36:42 -0300 | [diff] [blame] | 1188 | { |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1189 | ++hists->stats.nr_events[0]; |
| 1190 | ++hists->stats.nr_events[type]; |
Arnaldo Carvalho de Melo | c8446b9 | 2010-05-14 10:36:42 -0300 | [diff] [blame] | 1191 | } |
| 1192 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1193 | size_t hists__fprintf_nr_events(struct hists *hists, FILE *fp) |
Arnaldo Carvalho de Melo | c8446b9 | 2010-05-14 10:36:42 -0300 | [diff] [blame] | 1194 | { |
| 1195 | int i; |
| 1196 | size_t ret = 0; |
| 1197 | |
| 1198 | for (i = 0; i < PERF_RECORD_HEADER_MAX; ++i) { |
Arnaldo Carvalho de Melo | e248de3 | 2011-03-05 21:40:06 -0300 | [diff] [blame] | 1199 | const char *name; |
Thomas Gleixner | 3835bc00 | 2010-12-07 12:48:42 +0000 | [diff] [blame] | 1200 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1201 | if (hists->stats.nr_events[i] == 0) |
Arnaldo Carvalho de Melo | e248de3 | 2011-03-05 21:40:06 -0300 | [diff] [blame] | 1202 | continue; |
| 1203 | |
| 1204 | name = perf_event__name(i); |
Thomas Gleixner | 3835bc00 | 2010-12-07 12:48:42 +0000 | [diff] [blame] | 1205 | if (!strcmp(name, "UNKNOWN")) |
Arnaldo Carvalho de Melo | c8446b9 | 2010-05-14 10:36:42 -0300 | [diff] [blame] | 1206 | continue; |
Thomas Gleixner | 3835bc00 | 2010-12-07 12:48:42 +0000 | [diff] [blame] | 1207 | |
| 1208 | ret += fprintf(fp, "%16s events: %10d\n", name, |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1209 | hists->stats.nr_events[i]); |
Arnaldo Carvalho de Melo | c8446b9 | 2010-05-14 10:36:42 -0300 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | return ret; |
| 1213 | } |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 1214 | |
| 1215 | void hists__init(struct hists *hists) |
| 1216 | { |
| 1217 | memset(hists, 0, sizeof(*hists)); |
| 1218 | hists->entries_in_array[0] = hists->entries_in_array[1] = RB_ROOT; |
| 1219 | hists->entries_in = &hists->entries_in_array[0]; |
| 1220 | hists->entries_collapsed = RB_ROOT; |
| 1221 | hists->entries = RB_ROOT; |
| 1222 | pthread_mutex_init(&hists->lock, NULL); |
| 1223 | } |