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