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