John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1 | #include "hist.h" |
Arnaldo Carvalho de Melo | 4e4f06e | 2009-12-14 13:10:39 -0200 | [diff] [blame] | 2 | #include "session.h" |
| 3 | #include "sort.h" |
Arnaldo Carvalho de Melo | 9b33827 | 2009-12-16 14:31:49 -0200 | [diff] [blame] | 4 | #include <math.h> |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 5 | |
| 6 | struct callchain_param callchain_param = { |
| 7 | .mode = CHAIN_GRAPH_REL, |
| 8 | .min_percent = 0.5 |
| 9 | }; |
| 10 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 11 | void __perf_session__add_count(struct hist_entry *he, |
| 12 | struct addr_location *al, |
| 13 | u64 count) |
| 14 | { |
| 15 | he->count += count; |
| 16 | |
| 17 | switch (al->cpumode) { |
| 18 | case PERF_RECORD_MISC_KERNEL: |
| 19 | he->count_sys += count; |
| 20 | break; |
| 21 | case PERF_RECORD_MISC_USER: |
| 22 | he->count_us += count; |
| 23 | break; |
| 24 | case PERF_RECORD_MISC_GUEST_KERNEL: |
| 25 | he->count_guest_sys += count; |
| 26 | break; |
| 27 | case PERF_RECORD_MISC_GUEST_USER: |
| 28 | he->count_guest_us += count; |
| 29 | break; |
| 30 | default: |
| 31 | break; |
| 32 | } |
| 33 | } |
| 34 | |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 35 | /* |
| 36 | * histogram, sorted on item, collects counts |
| 37 | */ |
| 38 | |
Eric B Munson | d403d0a | 2010-03-05 12:51:06 -0300 | [diff] [blame] | 39 | struct hist_entry *__perf_session__add_hist_entry(struct rb_root *hists, |
Arnaldo Carvalho de Melo | 4e4f06e | 2009-12-14 13:10:39 -0200 | [diff] [blame] | 40 | struct addr_location *al, |
| 41 | struct symbol *sym_parent, |
| 42 | u64 count, bool *hit) |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 43 | { |
Eric B Munson | d403d0a | 2010-03-05 12:51:06 -0300 | [diff] [blame] | 44 | struct rb_node **p = &hists->rb_node; |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 45 | struct rb_node *parent = NULL; |
| 46 | struct hist_entry *he; |
| 47 | struct hist_entry entry = { |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 48 | .thread = al->thread, |
Arnaldo Carvalho de Melo | 59fd530 | 2010-03-24 16:40:17 -0300 | [diff] [blame] | 49 | .ms = { |
| 50 | .map = al->map, |
| 51 | .sym = al->sym, |
| 52 | }, |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 53 | .ip = al->addr, |
| 54 | .level = al->level, |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 55 | .count = count, |
| 56 | .parent = sym_parent, |
| 57 | }; |
| 58 | int cmp; |
| 59 | |
| 60 | while (*p != NULL) { |
| 61 | parent = *p; |
| 62 | he = rb_entry(parent, struct hist_entry, rb_node); |
| 63 | |
| 64 | cmp = hist_entry__cmp(&entry, he); |
| 65 | |
| 66 | if (!cmp) { |
| 67 | *hit = true; |
| 68 | return he; |
| 69 | } |
| 70 | |
| 71 | if (cmp < 0) |
| 72 | p = &(*p)->rb_left; |
| 73 | else |
| 74 | p = &(*p)->rb_right; |
| 75 | } |
| 76 | |
Arnaldo Carvalho de Melo | b9fb930 | 2010-04-02 09:50:42 -0300 | [diff] [blame] | 77 | he = malloc(sizeof(*he) + (symbol_conf.use_callchain ? |
| 78 | sizeof(struct callchain_node) : 0)); |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 79 | if (!he) |
| 80 | return NULL; |
| 81 | *he = entry; |
| 82 | rb_link_node(&he->rb_node, parent, p); |
Eric B Munson | d403d0a | 2010-03-05 12:51:06 -0300 | [diff] [blame] | 83 | rb_insert_color(&he->rb_node, hists); |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 84 | *hit = false; |
| 85 | return he; |
| 86 | } |
| 87 | |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 88 | int64_t |
| 89 | hist_entry__cmp(struct hist_entry *left, struct hist_entry *right) |
| 90 | { |
| 91 | struct sort_entry *se; |
| 92 | int64_t cmp = 0; |
| 93 | |
| 94 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
Frederic Weisbecker | fcd1498 | 2010-04-14 19:11:29 +0200 | [diff] [blame] | 95 | cmp = se->se_cmp(left, right); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 96 | if (cmp) |
| 97 | break; |
| 98 | } |
| 99 | |
| 100 | return cmp; |
| 101 | } |
| 102 | |
| 103 | int64_t |
| 104 | hist_entry__collapse(struct hist_entry *left, struct hist_entry *right) |
| 105 | { |
| 106 | struct sort_entry *se; |
| 107 | int64_t cmp = 0; |
| 108 | |
| 109 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
| 110 | int64_t (*f)(struct hist_entry *, struct hist_entry *); |
| 111 | |
Frederic Weisbecker | fcd1498 | 2010-04-14 19:11:29 +0200 | [diff] [blame] | 112 | f = se->se_collapse ?: se->se_cmp; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 113 | |
| 114 | cmp = f(left, right); |
| 115 | if (cmp) |
| 116 | break; |
| 117 | } |
| 118 | |
| 119 | return cmp; |
| 120 | } |
| 121 | |
| 122 | void hist_entry__free(struct hist_entry *he) |
| 123 | { |
| 124 | free(he); |
| 125 | } |
| 126 | |
| 127 | /* |
| 128 | * collapse the histogram |
| 129 | */ |
| 130 | |
Arnaldo Carvalho de Melo | b9bf089 | 2009-12-14 11:37:11 -0200 | [diff] [blame] | 131 | static void collapse__insert_entry(struct rb_root *root, struct hist_entry *he) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 132 | { |
Arnaldo Carvalho de Melo | b9bf089 | 2009-12-14 11:37:11 -0200 | [diff] [blame] | 133 | struct rb_node **p = &root->rb_node; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 134 | struct rb_node *parent = NULL; |
| 135 | struct hist_entry *iter; |
| 136 | int64_t cmp; |
| 137 | |
| 138 | while (*p != NULL) { |
| 139 | parent = *p; |
| 140 | iter = rb_entry(parent, struct hist_entry, rb_node); |
| 141 | |
| 142 | cmp = hist_entry__collapse(iter, he); |
| 143 | |
| 144 | if (!cmp) { |
| 145 | iter->count += he->count; |
| 146 | hist_entry__free(he); |
| 147 | return; |
| 148 | } |
| 149 | |
| 150 | if (cmp < 0) |
| 151 | p = &(*p)->rb_left; |
| 152 | else |
| 153 | p = &(*p)->rb_right; |
| 154 | } |
| 155 | |
| 156 | rb_link_node(&he->rb_node, parent, p); |
Arnaldo Carvalho de Melo | b9bf089 | 2009-12-14 11:37:11 -0200 | [diff] [blame] | 157 | rb_insert_color(&he->rb_node, root); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 158 | } |
| 159 | |
Eric B Munson | eefc465 | 2010-03-05 12:51:08 -0300 | [diff] [blame] | 160 | void perf_session__collapse_resort(struct rb_root *hists) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 161 | { |
Arnaldo Carvalho de Melo | b9bf089 | 2009-12-14 11:37:11 -0200 | [diff] [blame] | 162 | struct rb_root tmp; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 163 | struct rb_node *next; |
| 164 | struct hist_entry *n; |
| 165 | |
| 166 | if (!sort__need_collapse) |
| 167 | return; |
| 168 | |
Arnaldo Carvalho de Melo | b9bf089 | 2009-12-14 11:37:11 -0200 | [diff] [blame] | 169 | tmp = RB_ROOT; |
Eric B Munson | eefc465 | 2010-03-05 12:51:08 -0300 | [diff] [blame] | 170 | next = rb_first(hists); |
Arnaldo Carvalho de Melo | b9bf089 | 2009-12-14 11:37:11 -0200 | [diff] [blame] | 171 | |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 172 | while (next) { |
| 173 | n = rb_entry(next, struct hist_entry, rb_node); |
| 174 | next = rb_next(&n->rb_node); |
| 175 | |
Eric B Munson | eefc465 | 2010-03-05 12:51:08 -0300 | [diff] [blame] | 176 | rb_erase(&n->rb_node, hists); |
Arnaldo Carvalho de Melo | b9bf089 | 2009-12-14 11:37:11 -0200 | [diff] [blame] | 177 | collapse__insert_entry(&tmp, n); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 178 | } |
Arnaldo Carvalho de Melo | b9bf089 | 2009-12-14 11:37:11 -0200 | [diff] [blame] | 179 | |
Eric B Munson | eefc465 | 2010-03-05 12:51:08 -0300 | [diff] [blame] | 180 | *hists = tmp; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | /* |
| 184 | * reverse the map, sort on count. |
| 185 | */ |
| 186 | |
Arnaldo Carvalho de Melo | d599db3 | 2009-12-15 20:04:42 -0200 | [diff] [blame] | 187 | static void perf_session__insert_output_hist_entry(struct rb_root *root, |
Arnaldo Carvalho de Melo | 4e4f06e | 2009-12-14 13:10:39 -0200 | [diff] [blame] | 188 | struct hist_entry *he, |
| 189 | u64 min_callchain_hits) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 190 | { |
Arnaldo Carvalho de Melo | b9bf089 | 2009-12-14 11:37:11 -0200 | [diff] [blame] | 191 | struct rb_node **p = &root->rb_node; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 192 | struct rb_node *parent = NULL; |
| 193 | struct hist_entry *iter; |
| 194 | |
Arnaldo Carvalho de Melo | d599db3 | 2009-12-15 20:04:42 -0200 | [diff] [blame] | 195 | if (symbol_conf.use_callchain) |
Arnaldo Carvalho de Melo | b9fb930 | 2010-04-02 09:50:42 -0300 | [diff] [blame] | 196 | callchain_param.sort(&he->sorted_chain, he->callchain, |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 197 | min_callchain_hits, &callchain_param); |
| 198 | |
| 199 | while (*p != NULL) { |
| 200 | parent = *p; |
| 201 | iter = rb_entry(parent, struct hist_entry, rb_node); |
| 202 | |
| 203 | if (he->count > iter->count) |
| 204 | p = &(*p)->rb_left; |
| 205 | else |
| 206 | p = &(*p)->rb_right; |
| 207 | } |
| 208 | |
| 209 | rb_link_node(&he->rb_node, parent, p); |
Arnaldo Carvalho de Melo | b9bf089 | 2009-12-14 11:37:11 -0200 | [diff] [blame] | 210 | rb_insert_color(&he->rb_node, root); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 211 | } |
| 212 | |
Arnaldo Carvalho de Melo | 5f4d3f8 | 2010-03-26 21:16:22 -0300 | [diff] [blame] | 213 | u64 perf_session__output_resort(struct rb_root *hists, u64 total_samples) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 214 | { |
Arnaldo Carvalho de Melo | b9bf089 | 2009-12-14 11:37:11 -0200 | [diff] [blame] | 215 | struct rb_root tmp; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 216 | struct rb_node *next; |
| 217 | struct hist_entry *n; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 218 | u64 min_callchain_hits; |
Arnaldo Carvalho de Melo | 5f4d3f8 | 2010-03-26 21:16:22 -0300 | [diff] [blame] | 219 | u64 nr_hists = 0; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 220 | |
| 221 | min_callchain_hits = |
| 222 | total_samples * (callchain_param.min_percent / 100); |
| 223 | |
Arnaldo Carvalho de Melo | b9bf089 | 2009-12-14 11:37:11 -0200 | [diff] [blame] | 224 | tmp = RB_ROOT; |
Eric B Munson | eefc465 | 2010-03-05 12:51:08 -0300 | [diff] [blame] | 225 | next = rb_first(hists); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 226 | |
| 227 | while (next) { |
| 228 | n = rb_entry(next, struct hist_entry, rb_node); |
| 229 | next = rb_next(&n->rb_node); |
| 230 | |
Eric B Munson | eefc465 | 2010-03-05 12:51:08 -0300 | [diff] [blame] | 231 | rb_erase(&n->rb_node, hists); |
Arnaldo Carvalho de Melo | d599db3 | 2009-12-15 20:04:42 -0200 | [diff] [blame] | 232 | perf_session__insert_output_hist_entry(&tmp, n, |
Arnaldo Carvalho de Melo | 4e4f06e | 2009-12-14 13:10:39 -0200 | [diff] [blame] | 233 | min_callchain_hits); |
Arnaldo Carvalho de Melo | 5f4d3f8 | 2010-03-26 21:16:22 -0300 | [diff] [blame] | 234 | ++nr_hists; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 235 | } |
Arnaldo Carvalho de Melo | b9bf089 | 2009-12-14 11:37:11 -0200 | [diff] [blame] | 236 | |
Eric B Munson | eefc465 | 2010-03-05 12:51:08 -0300 | [diff] [blame] | 237 | *hists = tmp; |
Arnaldo Carvalho de Melo | 5f4d3f8 | 2010-03-26 21:16:22 -0300 | [diff] [blame] | 238 | return nr_hists; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 239 | } |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 240 | |
| 241 | static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin) |
| 242 | { |
| 243 | int i; |
| 244 | int ret = fprintf(fp, " "); |
| 245 | |
| 246 | for (i = 0; i < left_margin; i++) |
| 247 | ret += fprintf(fp, " "); |
| 248 | |
| 249 | return ret; |
| 250 | } |
| 251 | |
| 252 | static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask, |
| 253 | int left_margin) |
| 254 | { |
| 255 | int i; |
| 256 | size_t ret = callchain__fprintf_left_margin(fp, left_margin); |
| 257 | |
| 258 | for (i = 0; i < depth; i++) |
| 259 | if (depth_mask & (1 << i)) |
| 260 | ret += fprintf(fp, "| "); |
| 261 | else |
| 262 | ret += fprintf(fp, " "); |
| 263 | |
| 264 | ret += fprintf(fp, "\n"); |
| 265 | |
| 266 | return ret; |
| 267 | } |
| 268 | |
| 269 | static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain, |
| 270 | int depth, int depth_mask, int count, |
| 271 | u64 total_samples, int hits, |
| 272 | int left_margin) |
| 273 | { |
| 274 | int i; |
| 275 | size_t ret = 0; |
| 276 | |
| 277 | ret += callchain__fprintf_left_margin(fp, left_margin); |
| 278 | for (i = 0; i < depth; i++) { |
| 279 | if (depth_mask & (1 << i)) |
| 280 | ret += fprintf(fp, "|"); |
| 281 | else |
| 282 | ret += fprintf(fp, " "); |
| 283 | if (!count && i == depth - 1) { |
| 284 | double percent; |
| 285 | |
| 286 | percent = hits * 100.0 / total_samples; |
| 287 | ret += percent_color_fprintf(fp, "--%2.2f%%-- ", percent); |
| 288 | } else |
| 289 | ret += fprintf(fp, "%s", " "); |
| 290 | } |
Arnaldo Carvalho de Melo | b3c9ac0 | 2010-03-24 16:40:18 -0300 | [diff] [blame] | 291 | if (chain->ms.sym) |
| 292 | ret += fprintf(fp, "%s\n", chain->ms.sym->name); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 293 | else |
| 294 | ret += fprintf(fp, "%p\n", (void *)(long)chain->ip); |
| 295 | |
| 296 | return ret; |
| 297 | } |
| 298 | |
| 299 | static struct symbol *rem_sq_bracket; |
| 300 | static struct callchain_list rem_hits; |
| 301 | |
| 302 | static void init_rem_hits(void) |
| 303 | { |
| 304 | rem_sq_bracket = malloc(sizeof(*rem_sq_bracket) + 6); |
| 305 | if (!rem_sq_bracket) { |
| 306 | fprintf(stderr, "Not enough memory to display remaining hits\n"); |
| 307 | return; |
| 308 | } |
| 309 | |
| 310 | strcpy(rem_sq_bracket->name, "[...]"); |
Arnaldo Carvalho de Melo | b3c9ac0 | 2010-03-24 16:40:18 -0300 | [diff] [blame] | 311 | rem_hits.ms.sym = rem_sq_bracket; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | static size_t __callchain__fprintf_graph(FILE *fp, struct callchain_node *self, |
| 315 | u64 total_samples, int depth, |
| 316 | int depth_mask, int left_margin) |
| 317 | { |
| 318 | struct rb_node *node, *next; |
| 319 | struct callchain_node *child; |
| 320 | struct callchain_list *chain; |
| 321 | int new_depth_mask = depth_mask; |
| 322 | u64 new_total; |
| 323 | u64 remaining; |
| 324 | size_t ret = 0; |
| 325 | int i; |
| 326 | |
| 327 | if (callchain_param.mode == CHAIN_GRAPH_REL) |
| 328 | new_total = self->children_hit; |
| 329 | else |
| 330 | new_total = total_samples; |
| 331 | |
| 332 | remaining = new_total; |
| 333 | |
| 334 | node = rb_first(&self->rb_root); |
| 335 | while (node) { |
| 336 | u64 cumul; |
| 337 | |
| 338 | child = rb_entry(node, struct callchain_node, rb_node); |
| 339 | cumul = cumul_hits(child); |
| 340 | remaining -= cumul; |
| 341 | |
| 342 | /* |
| 343 | * The depth mask manages the output of pipes that show |
| 344 | * the depth. We don't want to keep the pipes of the current |
| 345 | * level for the last child of this depth. |
| 346 | * Except if we have remaining filtered hits. They will |
| 347 | * supersede the last child |
| 348 | */ |
| 349 | next = rb_next(node); |
| 350 | if (!next && (callchain_param.mode != CHAIN_GRAPH_REL || !remaining)) |
| 351 | new_depth_mask &= ~(1 << (depth - 1)); |
| 352 | |
| 353 | /* |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 354 | * 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] | 355 | * to keep the level link until we reach the last child |
| 356 | */ |
| 357 | ret += ipchain__fprintf_graph_line(fp, depth, depth_mask, |
| 358 | left_margin); |
| 359 | i = 0; |
| 360 | list_for_each_entry(chain, &child->val, list) { |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 361 | ret += ipchain__fprintf_graph(fp, chain, depth, |
| 362 | new_depth_mask, i++, |
| 363 | new_total, |
| 364 | cumul, |
| 365 | left_margin); |
| 366 | } |
| 367 | ret += __callchain__fprintf_graph(fp, child, new_total, |
| 368 | depth + 1, |
| 369 | new_depth_mask | (1 << depth), |
| 370 | left_margin); |
| 371 | node = next; |
| 372 | } |
| 373 | |
| 374 | if (callchain_param.mode == CHAIN_GRAPH_REL && |
| 375 | remaining && remaining != new_total) { |
| 376 | |
| 377 | if (!rem_sq_bracket) |
| 378 | return ret; |
| 379 | |
| 380 | new_depth_mask &= ~(1 << (depth - 1)); |
| 381 | |
| 382 | ret += ipchain__fprintf_graph(fp, &rem_hits, depth, |
| 383 | new_depth_mask, 0, new_total, |
| 384 | remaining, left_margin); |
| 385 | } |
| 386 | |
| 387 | return ret; |
| 388 | } |
| 389 | |
| 390 | static size_t callchain__fprintf_graph(FILE *fp, struct callchain_node *self, |
| 391 | u64 total_samples, int left_margin) |
| 392 | { |
| 393 | struct callchain_list *chain; |
| 394 | bool printed = false; |
| 395 | int i = 0; |
| 396 | int ret = 0; |
| 397 | |
| 398 | list_for_each_entry(chain, &self->val, list) { |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 399 | if (!i++ && sort__first_dimension == SORT_SYM) |
| 400 | continue; |
| 401 | |
| 402 | if (!printed) { |
| 403 | ret += callchain__fprintf_left_margin(fp, left_margin); |
| 404 | ret += fprintf(fp, "|\n"); |
| 405 | ret += callchain__fprintf_left_margin(fp, left_margin); |
| 406 | ret += fprintf(fp, "---"); |
| 407 | |
| 408 | left_margin += 3; |
| 409 | printed = true; |
| 410 | } else |
| 411 | ret += callchain__fprintf_left_margin(fp, left_margin); |
| 412 | |
Arnaldo Carvalho de Melo | b3c9ac0 | 2010-03-24 16:40:18 -0300 | [diff] [blame] | 413 | if (chain->ms.sym) |
| 414 | ret += fprintf(fp, " %s\n", chain->ms.sym->name); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 415 | else |
| 416 | ret += fprintf(fp, " %p\n", (void *)(long)chain->ip); |
| 417 | } |
| 418 | |
| 419 | ret += __callchain__fprintf_graph(fp, self, total_samples, 1, 1, left_margin); |
| 420 | |
| 421 | return ret; |
| 422 | } |
| 423 | |
| 424 | static size_t callchain__fprintf_flat(FILE *fp, struct callchain_node *self, |
| 425 | u64 total_samples) |
| 426 | { |
| 427 | struct callchain_list *chain; |
| 428 | size_t ret = 0; |
| 429 | |
| 430 | if (!self) |
| 431 | return 0; |
| 432 | |
| 433 | ret += callchain__fprintf_flat(fp, self->parent, total_samples); |
| 434 | |
| 435 | |
| 436 | list_for_each_entry(chain, &self->val, list) { |
| 437 | if (chain->ip >= PERF_CONTEXT_MAX) |
| 438 | continue; |
Arnaldo Carvalho de Melo | b3c9ac0 | 2010-03-24 16:40:18 -0300 | [diff] [blame] | 439 | if (chain->ms.sym) |
| 440 | ret += fprintf(fp, " %s\n", chain->ms.sym->name); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 441 | else |
| 442 | ret += fprintf(fp, " %p\n", |
| 443 | (void *)(long)chain->ip); |
| 444 | } |
| 445 | |
| 446 | return ret; |
| 447 | } |
| 448 | |
| 449 | static size_t hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self, |
| 450 | u64 total_samples, int left_margin) |
| 451 | { |
| 452 | struct rb_node *rb_node; |
| 453 | struct callchain_node *chain; |
| 454 | size_t ret = 0; |
| 455 | |
| 456 | rb_node = rb_first(&self->sorted_chain); |
| 457 | while (rb_node) { |
| 458 | double percent; |
| 459 | |
| 460 | chain = rb_entry(rb_node, struct callchain_node, rb_node); |
| 461 | percent = chain->hit * 100.0 / total_samples; |
| 462 | switch (callchain_param.mode) { |
| 463 | case CHAIN_FLAT: |
| 464 | ret += percent_color_fprintf(fp, " %6.2f%%\n", |
| 465 | percent); |
| 466 | ret += callchain__fprintf_flat(fp, chain, total_samples); |
| 467 | break; |
| 468 | case CHAIN_GRAPH_ABS: /* Falldown */ |
| 469 | case CHAIN_GRAPH_REL: |
| 470 | ret += callchain__fprintf_graph(fp, chain, total_samples, |
| 471 | left_margin); |
| 472 | case CHAIN_NONE: |
| 473 | default: |
| 474 | break; |
| 475 | } |
| 476 | ret += fprintf(fp, "\n"); |
| 477 | rb_node = rb_next(rb_node); |
| 478 | } |
| 479 | |
| 480 | return ret; |
| 481 | } |
| 482 | |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 483 | int hist_entry__snprintf(struct hist_entry *self, |
| 484 | char *s, size_t size, |
Arnaldo Carvalho de Melo | dd2ee78 | 2010-03-11 20:12:43 -0300 | [diff] [blame] | 485 | struct perf_session *pair_session, |
| 486 | bool show_displacement, |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 487 | long displacement, bool color, |
Arnaldo Carvalho de Melo | dd2ee78 | 2010-03-11 20:12:43 -0300 | [diff] [blame] | 488 | u64 session_total) |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 489 | { |
| 490 | struct sort_entry *se; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 491 | u64 count, total, count_sys, count_us, count_guest_sys, count_guest_us; |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 492 | const char *sep = symbol_conf.field_sep; |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 493 | int ret; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 494 | |
| 495 | if (symbol_conf.exclude_other && !self->parent) |
| 496 | return 0; |
| 497 | |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 498 | if (pair_session) { |
| 499 | count = self->pair ? self->pair->count : 0; |
| 500 | total = pair_session->events_stats.total; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 501 | count_sys = self->pair ? self->pair->count_sys : 0; |
| 502 | count_us = self->pair ? self->pair->count_us : 0; |
| 503 | count_guest_sys = self->pair ? self->pair->count_guest_sys : 0; |
| 504 | count_guest_us = self->pair ? self->pair->count_guest_us : 0; |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 505 | } else { |
| 506 | count = self->count; |
Eric B Munson | eefc465 | 2010-03-05 12:51:08 -0300 | [diff] [blame] | 507 | total = session_total; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 508 | count_sys = self->count_sys; |
| 509 | count_us = self->count_us; |
| 510 | count_guest_sys = self->count_guest_sys; |
| 511 | count_guest_us = self->count_guest_us; |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 512 | } |
| 513 | |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 514 | if (total) { |
| 515 | if (color) |
| 516 | ret = percent_color_snprintf(s, size, |
| 517 | sep ? "%.2f" : " %6.2f%%", |
| 518 | (count * 100.0) / total); |
| 519 | else |
| 520 | ret = snprintf(s, size, sep ? "%.2f" : " %6.2f%%", |
| 521 | (count * 100.0) / total); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 522 | if (symbol_conf.show_cpu_utilization) { |
| 523 | ret += percent_color_snprintf(s + ret, size - ret, |
| 524 | sep ? "%.2f" : " %6.2f%%", |
| 525 | (count_sys * 100.0) / total); |
| 526 | ret += percent_color_snprintf(s + ret, size - ret, |
| 527 | sep ? "%.2f" : " %6.2f%%", |
| 528 | (count_us * 100.0) / total); |
| 529 | if (perf_guest) { |
| 530 | ret += percent_color_snprintf(s + ret, |
| 531 | size - ret, |
| 532 | sep ? "%.2f" : " %6.2f%%", |
| 533 | (count_guest_sys * 100.0) / |
| 534 | total); |
| 535 | ret += percent_color_snprintf(s + ret, |
| 536 | size - ret, |
| 537 | sep ? "%.2f" : " %6.2f%%", |
| 538 | (count_guest_us * 100.0) / |
| 539 | total); |
| 540 | } |
| 541 | } |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 542 | } else |
| 543 | ret = snprintf(s, size, sep ? "%lld" : "%12lld ", count); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 544 | |
| 545 | if (symbol_conf.show_nr_samples) { |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 546 | if (sep) |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 547 | ret += snprintf(s + ret, size - ret, "%c%lld", *sep, count); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 548 | else |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 549 | ret += snprintf(s + ret, size - ret, "%11lld", count); |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | if (pair_session) { |
| 553 | char bf[32]; |
| 554 | double old_percent = 0, new_percent = 0, diff; |
| 555 | |
| 556 | if (total > 0) |
Arnaldo Carvalho de Melo | 9b33827 | 2009-12-16 14:31:49 -0200 | [diff] [blame] | 557 | old_percent = (count * 100.0) / total; |
Eric B Munson | eefc465 | 2010-03-05 12:51:08 -0300 | [diff] [blame] | 558 | if (session_total > 0) |
| 559 | new_percent = (self->count * 100.0) / session_total; |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 560 | |
Arnaldo Carvalho de Melo | 9b33827 | 2009-12-16 14:31:49 -0200 | [diff] [blame] | 561 | diff = new_percent - old_percent; |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 562 | |
Arnaldo Carvalho de Melo | 9b33827 | 2009-12-16 14:31:49 -0200 | [diff] [blame] | 563 | if (fabs(diff) >= 0.01) |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 564 | snprintf(bf, sizeof(bf), "%+4.2F%%", diff); |
| 565 | else |
| 566 | snprintf(bf, sizeof(bf), " "); |
| 567 | |
| 568 | if (sep) |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 569 | ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf); |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 570 | else |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 571 | ret += snprintf(s + ret, size - ret, "%11.11s", bf); |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 572 | |
| 573 | if (show_displacement) { |
| 574 | if (displacement) |
| 575 | snprintf(bf, sizeof(bf), "%+4ld", displacement); |
| 576 | else |
| 577 | snprintf(bf, sizeof(bf), " "); |
| 578 | |
| 579 | if (sep) |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 580 | ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf); |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 581 | else |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 582 | ret += snprintf(s + ret, size - ret, "%6.6s", bf); |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 583 | } |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
| 587 | if (se->elide) |
| 588 | continue; |
| 589 | |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 590 | ret += snprintf(s + ret, size - ret, "%s", sep ?: " "); |
Frederic Weisbecker | fcd1498 | 2010-04-14 19:11:29 +0200 | [diff] [blame] | 591 | ret += se->se_snprintf(self, s + ret, size - ret, |
| 592 | se->se_width ? *se->se_width : 0); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 593 | } |
| 594 | |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 595 | return ret; |
| 596 | } |
| 597 | |
| 598 | int hist_entry__fprintf(struct hist_entry *self, |
| 599 | struct perf_session *pair_session, |
| 600 | bool show_displacement, |
| 601 | long displacement, FILE *fp, |
| 602 | u64 session_total) |
| 603 | { |
| 604 | char bf[512]; |
| 605 | hist_entry__snprintf(self, bf, sizeof(bf), pair_session, |
| 606 | show_displacement, displacement, |
| 607 | true, session_total); |
| 608 | return fprintf(fp, "%s\n", bf); |
Arnaldo Carvalho de Melo | 3997d37 | 2010-03-12 12:46:48 -0300 | [diff] [blame] | 609 | } |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 610 | |
Arnaldo Carvalho de Melo | 3997d37 | 2010-03-12 12:46:48 -0300 | [diff] [blame] | 611 | static size_t hist_entry__fprintf_callchain(struct hist_entry *self, FILE *fp, |
| 612 | u64 session_total) |
| 613 | { |
| 614 | int left_margin = 0; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 615 | |
Arnaldo Carvalho de Melo | 3997d37 | 2010-03-12 12:46:48 -0300 | [diff] [blame] | 616 | if (sort__first_dimension == SORT_COMM) { |
| 617 | struct sort_entry *se = list_first_entry(&hist_entry__sort_list, |
| 618 | typeof(*se), list); |
Frederic Weisbecker | fcd1498 | 2010-04-14 19:11:29 +0200 | [diff] [blame] | 619 | left_margin = se->se_width ? *se->se_width : 0; |
Arnaldo Carvalho de Melo | 3997d37 | 2010-03-12 12:46:48 -0300 | [diff] [blame] | 620 | left_margin -= thread__comm_len(self->thread); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 621 | } |
| 622 | |
Arnaldo Carvalho de Melo | 3997d37 | 2010-03-12 12:46:48 -0300 | [diff] [blame] | 623 | return hist_entry_callchain__fprintf(fp, self, session_total, |
| 624 | left_margin); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 625 | } |
| 626 | |
Eric B Munson | eefc465 | 2010-03-05 12:51:08 -0300 | [diff] [blame] | 627 | size_t perf_session__fprintf_hists(struct rb_root *hists, |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 628 | struct perf_session *pair, |
Eric B Munson | eefc465 | 2010-03-05 12:51:08 -0300 | [diff] [blame] | 629 | bool show_displacement, FILE *fp, |
| 630 | u64 session_total) |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 631 | { |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 632 | struct sort_entry *se; |
| 633 | struct rb_node *nd; |
| 634 | size_t ret = 0; |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 635 | unsigned long position = 1; |
| 636 | long displacement = 0; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 637 | unsigned int width; |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 638 | const char *sep = symbol_conf.field_sep; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 639 | char *col_width = symbol_conf.col_width_list_str; |
| 640 | |
| 641 | init_rem_hits(); |
| 642 | |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 643 | fprintf(fp, "# %s", pair ? "Baseline" : "Overhead"); |
| 644 | |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 645 | if (symbol_conf.show_nr_samples) { |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 646 | if (sep) |
| 647 | fprintf(fp, "%cSamples", *sep); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 648 | else |
| 649 | fputs(" Samples ", fp); |
| 650 | } |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 651 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 652 | if (symbol_conf.show_cpu_utilization) { |
| 653 | if (sep) { |
| 654 | ret += fprintf(fp, "%csys", *sep); |
| 655 | ret += fprintf(fp, "%cus", *sep); |
| 656 | if (perf_guest) { |
| 657 | ret += fprintf(fp, "%cguest sys", *sep); |
| 658 | ret += fprintf(fp, "%cguest us", *sep); |
| 659 | } |
| 660 | } else { |
| 661 | ret += fprintf(fp, " sys "); |
| 662 | ret += fprintf(fp, " us "); |
| 663 | if (perf_guest) { |
| 664 | ret += fprintf(fp, " guest sys "); |
| 665 | ret += fprintf(fp, " guest us "); |
| 666 | } |
| 667 | } |
| 668 | } |
| 669 | |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 670 | if (pair) { |
| 671 | if (sep) |
| 672 | ret += fprintf(fp, "%cDelta", *sep); |
| 673 | else |
| 674 | ret += fprintf(fp, " Delta "); |
| 675 | |
| 676 | if (show_displacement) { |
| 677 | if (sep) |
| 678 | ret += fprintf(fp, "%cDisplacement", *sep); |
| 679 | else |
| 680 | ret += fprintf(fp, " Displ"); |
| 681 | } |
| 682 | } |
| 683 | |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 684 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
| 685 | if (se->elide) |
| 686 | continue; |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 687 | if (sep) { |
Frederic Weisbecker | fcd1498 | 2010-04-14 19:11:29 +0200 | [diff] [blame] | 688 | fprintf(fp, "%c%s", *sep, se->se_header); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 689 | continue; |
| 690 | } |
Frederic Weisbecker | fcd1498 | 2010-04-14 19:11:29 +0200 | [diff] [blame] | 691 | width = strlen(se->se_header); |
| 692 | if (se->se_width) { |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 693 | if (symbol_conf.col_width_list_str) { |
| 694 | if (col_width) { |
Frederic Weisbecker | fcd1498 | 2010-04-14 19:11:29 +0200 | [diff] [blame] | 695 | *se->se_width = atoi(col_width); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 696 | col_width = strchr(col_width, ','); |
| 697 | if (col_width) |
| 698 | ++col_width; |
| 699 | } |
| 700 | } |
Frederic Weisbecker | fcd1498 | 2010-04-14 19:11:29 +0200 | [diff] [blame] | 701 | width = *se->se_width = max(*se->se_width, width); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 702 | } |
Frederic Weisbecker | fcd1498 | 2010-04-14 19:11:29 +0200 | [diff] [blame] | 703 | fprintf(fp, " %*s", width, se->se_header); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 704 | } |
| 705 | fprintf(fp, "\n"); |
| 706 | |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 707 | if (sep) |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 708 | goto print_entries; |
| 709 | |
| 710 | fprintf(fp, "# ........"); |
| 711 | if (symbol_conf.show_nr_samples) |
| 712 | fprintf(fp, " .........."); |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 713 | if (pair) { |
| 714 | fprintf(fp, " .........."); |
| 715 | if (show_displacement) |
| 716 | fprintf(fp, " ....."); |
| 717 | } |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 718 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
| 719 | unsigned int i; |
| 720 | |
| 721 | if (se->elide) |
| 722 | continue; |
| 723 | |
| 724 | fprintf(fp, " "); |
Frederic Weisbecker | fcd1498 | 2010-04-14 19:11:29 +0200 | [diff] [blame] | 725 | if (se->se_width) |
| 726 | width = *se->se_width; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 727 | else |
Frederic Weisbecker | fcd1498 | 2010-04-14 19:11:29 +0200 | [diff] [blame] | 728 | width = strlen(se->se_header); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 729 | for (i = 0; i < width; i++) |
| 730 | fprintf(fp, "."); |
| 731 | } |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 732 | |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 733 | fprintf(fp, "\n#\n"); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 734 | |
| 735 | print_entries: |
Eric B Munson | eefc465 | 2010-03-05 12:51:08 -0300 | [diff] [blame] | 736 | for (nd = rb_first(hists); nd; nd = rb_next(nd)) { |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 737 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 738 | |
| 739 | if (show_displacement) { |
| 740 | if (h->pair != NULL) |
| 741 | displacement = ((long)h->pair->position - |
| 742 | (long)position); |
| 743 | else |
| 744 | displacement = 0; |
| 745 | ++position; |
| 746 | } |
Eric B Munson | eefc465 | 2010-03-05 12:51:08 -0300 | [diff] [blame] | 747 | ret += hist_entry__fprintf(h, pair, show_displacement, |
| 748 | displacement, fp, session_total); |
Arnaldo Carvalho de Melo | 3997d37 | 2010-03-12 12:46:48 -0300 | [diff] [blame] | 749 | |
| 750 | if (symbol_conf.use_callchain) |
| 751 | ret += hist_entry__fprintf_callchain(h, fp, session_total); |
| 752 | |
Arnaldo Carvalho de Melo | 59fd530 | 2010-03-24 16:40:17 -0300 | [diff] [blame] | 753 | if (h->ms.map == NULL && verbose > 1) { |
Arnaldo Carvalho de Melo | 65f2ed2 | 2010-03-09 15:58:17 -0300 | [diff] [blame] | 754 | __map_groups__fprintf_maps(&h->thread->mg, |
Arnaldo Carvalho de Melo | c6e718f | 2010-03-26 12:11:06 -0300 | [diff] [blame] | 755 | MAP__FUNCTION, verbose, fp); |
Arnaldo Carvalho de Melo | 65f2ed2 | 2010-03-09 15:58:17 -0300 | [diff] [blame] | 756 | fprintf(fp, "%.10s end\n", graph_dotted_line); |
| 757 | } |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 758 | } |
| 759 | |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 760 | free(rem_sq_bracket); |
| 761 | |
| 762 | return ret; |
| 763 | } |