Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 1 | #include <stdio.h> |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 2 | |
| 3 | #include "../../util/util.h" |
| 4 | #include "../../util/hist.h" |
| 5 | #include "../../util/sort.h" |
Namhyung Kim | 5b9e214 | 2013-01-22 18:09:37 +0900 | [diff] [blame] | 6 | #include "../../util/evsel.h" |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 7 | |
| 8 | |
| 9 | static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin) |
| 10 | { |
| 11 | int i; |
| 12 | int ret = fprintf(fp, " "); |
| 13 | |
| 14 | for (i = 0; i < left_margin; i++) |
| 15 | ret += fprintf(fp, " "); |
| 16 | |
| 17 | return ret; |
| 18 | } |
| 19 | |
| 20 | static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask, |
| 21 | int left_margin) |
| 22 | { |
| 23 | int i; |
| 24 | size_t ret = callchain__fprintf_left_margin(fp, left_margin); |
| 25 | |
| 26 | for (i = 0; i < depth; i++) |
| 27 | if (depth_mask & (1 << i)) |
| 28 | ret += fprintf(fp, "| "); |
| 29 | else |
| 30 | ret += fprintf(fp, " "); |
| 31 | |
| 32 | ret += fprintf(fp, "\n"); |
| 33 | |
| 34 | return ret; |
| 35 | } |
| 36 | |
| 37 | static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain, |
| 38 | int depth, int depth_mask, int period, |
| 39 | u64 total_samples, u64 hits, |
| 40 | int left_margin) |
| 41 | { |
| 42 | int i; |
| 43 | size_t ret = 0; |
| 44 | |
| 45 | ret += callchain__fprintf_left_margin(fp, left_margin); |
| 46 | for (i = 0; i < depth; i++) { |
| 47 | if (depth_mask & (1 << i)) |
| 48 | ret += fprintf(fp, "|"); |
| 49 | else |
| 50 | ret += fprintf(fp, " "); |
| 51 | if (!period && i == depth - 1) { |
| 52 | double percent; |
| 53 | |
| 54 | percent = hits * 100.0 / total_samples; |
| 55 | ret += percent_color_fprintf(fp, "--%2.2f%%-- ", percent); |
| 56 | } else |
| 57 | ret += fprintf(fp, "%s", " "); |
| 58 | } |
| 59 | if (chain->ms.sym) |
| 60 | ret += fprintf(fp, "%s\n", chain->ms.sym->name); |
| 61 | else |
| 62 | ret += fprintf(fp, "0x%0" PRIx64 "\n", chain->ip); |
| 63 | |
| 64 | return ret; |
| 65 | } |
| 66 | |
| 67 | static struct symbol *rem_sq_bracket; |
| 68 | static struct callchain_list rem_hits; |
| 69 | |
| 70 | static void init_rem_hits(void) |
| 71 | { |
| 72 | rem_sq_bracket = malloc(sizeof(*rem_sq_bracket) + 6); |
| 73 | if (!rem_sq_bracket) { |
| 74 | fprintf(stderr, "Not enough memory to display remaining hits\n"); |
| 75 | return; |
| 76 | } |
| 77 | |
| 78 | strcpy(rem_sq_bracket->name, "[...]"); |
| 79 | rem_hits.ms.sym = rem_sq_bracket; |
| 80 | } |
| 81 | |
| 82 | static size_t __callchain__fprintf_graph(FILE *fp, struct rb_root *root, |
| 83 | u64 total_samples, int depth, |
| 84 | int depth_mask, int left_margin) |
| 85 | { |
| 86 | struct rb_node *node, *next; |
| 87 | struct callchain_node *child; |
| 88 | struct callchain_list *chain; |
| 89 | int new_depth_mask = depth_mask; |
| 90 | u64 remaining; |
| 91 | size_t ret = 0; |
| 92 | int i; |
| 93 | uint entries_printed = 0; |
| 94 | |
| 95 | remaining = total_samples; |
| 96 | |
| 97 | node = rb_first(root); |
| 98 | while (node) { |
| 99 | u64 new_total; |
| 100 | u64 cumul; |
| 101 | |
| 102 | child = rb_entry(node, struct callchain_node, rb_node); |
| 103 | cumul = callchain_cumul_hits(child); |
| 104 | remaining -= cumul; |
| 105 | |
| 106 | /* |
| 107 | * The depth mask manages the output of pipes that show |
| 108 | * the depth. We don't want to keep the pipes of the current |
| 109 | * level for the last child of this depth. |
| 110 | * Except if we have remaining filtered hits. They will |
| 111 | * supersede the last child |
| 112 | */ |
| 113 | next = rb_next(node); |
| 114 | if (!next && (callchain_param.mode != CHAIN_GRAPH_REL || !remaining)) |
| 115 | new_depth_mask &= ~(1 << (depth - 1)); |
| 116 | |
| 117 | /* |
| 118 | * But we keep the older depth mask for the line separator |
| 119 | * to keep the level link until we reach the last child |
| 120 | */ |
| 121 | ret += ipchain__fprintf_graph_line(fp, depth, depth_mask, |
| 122 | left_margin); |
| 123 | i = 0; |
| 124 | list_for_each_entry(chain, &child->val, list) { |
| 125 | ret += ipchain__fprintf_graph(fp, chain, depth, |
| 126 | new_depth_mask, i++, |
| 127 | total_samples, |
| 128 | cumul, |
| 129 | left_margin); |
| 130 | } |
| 131 | |
| 132 | if (callchain_param.mode == CHAIN_GRAPH_REL) |
| 133 | new_total = child->children_hit; |
| 134 | else |
| 135 | new_total = total_samples; |
| 136 | |
| 137 | ret += __callchain__fprintf_graph(fp, &child->rb_root, new_total, |
| 138 | depth + 1, |
| 139 | new_depth_mask | (1 << depth), |
| 140 | left_margin); |
| 141 | node = next; |
| 142 | if (++entries_printed == callchain_param.print_limit) |
| 143 | break; |
| 144 | } |
| 145 | |
| 146 | if (callchain_param.mode == CHAIN_GRAPH_REL && |
| 147 | remaining && remaining != total_samples) { |
| 148 | |
| 149 | if (!rem_sq_bracket) |
| 150 | return ret; |
| 151 | |
| 152 | new_depth_mask &= ~(1 << (depth - 1)); |
| 153 | ret += ipchain__fprintf_graph(fp, &rem_hits, depth, |
| 154 | new_depth_mask, 0, total_samples, |
| 155 | remaining, left_margin); |
| 156 | } |
| 157 | |
| 158 | return ret; |
| 159 | } |
| 160 | |
| 161 | static size_t callchain__fprintf_graph(FILE *fp, struct rb_root *root, |
| 162 | u64 total_samples, int left_margin) |
| 163 | { |
| 164 | struct callchain_node *cnode; |
| 165 | struct callchain_list *chain; |
| 166 | u32 entries_printed = 0; |
| 167 | bool printed = false; |
| 168 | struct rb_node *node; |
| 169 | int i = 0; |
| 170 | int ret = 0; |
| 171 | |
| 172 | /* |
| 173 | * If have one single callchain root, don't bother printing |
| 174 | * its percentage (100 % in fractal mode and the same percentage |
| 175 | * than the hist in graph mode). This also avoid one level of column. |
| 176 | */ |
| 177 | node = rb_first(root); |
| 178 | if (node && !rb_next(node)) { |
| 179 | cnode = rb_entry(node, struct callchain_node, rb_node); |
| 180 | list_for_each_entry(chain, &cnode->val, list) { |
| 181 | /* |
| 182 | * If we sort by symbol, the first entry is the same than |
| 183 | * the symbol. No need to print it otherwise it appears as |
| 184 | * displayed twice. |
| 185 | */ |
| 186 | if (!i++ && sort__first_dimension == SORT_SYM) |
| 187 | continue; |
| 188 | if (!printed) { |
| 189 | ret += callchain__fprintf_left_margin(fp, left_margin); |
| 190 | ret += fprintf(fp, "|\n"); |
| 191 | ret += callchain__fprintf_left_margin(fp, left_margin); |
| 192 | ret += fprintf(fp, "---"); |
| 193 | left_margin += 3; |
| 194 | printed = true; |
| 195 | } else |
| 196 | ret += callchain__fprintf_left_margin(fp, left_margin); |
| 197 | |
| 198 | if (chain->ms.sym) |
| 199 | ret += fprintf(fp, " %s\n", chain->ms.sym->name); |
| 200 | else |
| 201 | ret += fprintf(fp, " %p\n", (void *)(long)chain->ip); |
| 202 | |
| 203 | if (++entries_printed == callchain_param.print_limit) |
| 204 | break; |
| 205 | } |
| 206 | root = &cnode->rb_root; |
| 207 | } |
| 208 | |
| 209 | ret += __callchain__fprintf_graph(fp, root, total_samples, |
| 210 | 1, 1, left_margin); |
| 211 | ret += fprintf(fp, "\n"); |
| 212 | |
| 213 | return ret; |
| 214 | } |
| 215 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame^] | 216 | static size_t __callchain__fprintf_flat(FILE *fp, struct callchain_node *node, |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 217 | u64 total_samples) |
| 218 | { |
| 219 | struct callchain_list *chain; |
| 220 | size_t ret = 0; |
| 221 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame^] | 222 | if (!node) |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 223 | return 0; |
| 224 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame^] | 225 | ret += __callchain__fprintf_flat(fp, node->parent, total_samples); |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 226 | |
| 227 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame^] | 228 | list_for_each_entry(chain, &node->val, list) { |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 229 | if (chain->ip >= PERF_CONTEXT_MAX) |
| 230 | continue; |
| 231 | if (chain->ms.sym) |
| 232 | ret += fprintf(fp, " %s\n", chain->ms.sym->name); |
| 233 | else |
| 234 | ret += fprintf(fp, " %p\n", |
| 235 | (void *)(long)chain->ip); |
| 236 | } |
| 237 | |
| 238 | return ret; |
| 239 | } |
| 240 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame^] | 241 | static size_t callchain__fprintf_flat(FILE *fp, struct rb_root *tree, |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 242 | u64 total_samples) |
| 243 | { |
| 244 | size_t ret = 0; |
| 245 | u32 entries_printed = 0; |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 246 | struct callchain_node *chain; |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame^] | 247 | struct rb_node *rb_node = rb_first(tree); |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 248 | |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 249 | while (rb_node) { |
| 250 | double percent; |
| 251 | |
| 252 | chain = rb_entry(rb_node, struct callchain_node, rb_node); |
| 253 | percent = chain->hit * 100.0 / total_samples; |
| 254 | |
| 255 | ret = percent_color_fprintf(fp, " %6.2f%%\n", percent); |
| 256 | ret += __callchain__fprintf_flat(fp, chain, total_samples); |
| 257 | ret += fprintf(fp, "\n"); |
| 258 | if (++entries_printed == callchain_param.print_limit) |
| 259 | break; |
| 260 | |
| 261 | rb_node = rb_next(rb_node); |
| 262 | } |
| 263 | |
| 264 | return ret; |
| 265 | } |
| 266 | |
| 267 | static size_t hist_entry_callchain__fprintf(struct hist_entry *he, |
| 268 | u64 total_samples, int left_margin, |
| 269 | FILE *fp) |
| 270 | { |
| 271 | switch (callchain_param.mode) { |
| 272 | case CHAIN_GRAPH_REL: |
Namhyung Kim | b24c28f | 2012-10-04 21:49:41 +0900 | [diff] [blame] | 273 | return callchain__fprintf_graph(fp, &he->sorted_chain, he->stat.period, |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 274 | left_margin); |
| 275 | break; |
| 276 | case CHAIN_GRAPH_ABS: |
| 277 | return callchain__fprintf_graph(fp, &he->sorted_chain, total_samples, |
| 278 | left_margin); |
| 279 | break; |
| 280 | case CHAIN_FLAT: |
| 281 | return callchain__fprintf_flat(fp, &he->sorted_chain, total_samples); |
| 282 | break; |
| 283 | case CHAIN_NONE: |
| 284 | break; |
| 285 | default: |
| 286 | pr_err("Bad callchain mode\n"); |
| 287 | } |
| 288 | |
| 289 | return 0; |
| 290 | } |
| 291 | |
Namhyung Kim | 000078b | 2012-08-20 13:52:06 +0900 | [diff] [blame] | 292 | static size_t hist_entry__callchain_fprintf(struct hist_entry *he, |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 293 | struct hists *hists, |
Jiri Olsa | b5ff71c | 2012-10-04 21:49:40 +0900 | [diff] [blame] | 294 | FILE *fp) |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 295 | { |
| 296 | int left_margin = 0; |
Jiri Olsa | b5ff71c | 2012-10-04 21:49:40 +0900 | [diff] [blame] | 297 | u64 total_period = hists->stats.total_period; |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 298 | |
| 299 | if (sort__first_dimension == SORT_COMM) { |
| 300 | struct sort_entry *se = list_first_entry(&hist_entry__sort_list, |
| 301 | typeof(*se), list); |
| 302 | left_margin = hists__col_len(hists, se->se_width_idx); |
| 303 | left_margin -= thread__comm_len(he->thread); |
| 304 | } |
| 305 | |
| 306 | return hist_entry_callchain__fprintf(he, total_period, left_margin, fp); |
| 307 | } |
| 308 | |
Jiri Olsa | be0e6d1 | 2013-02-04 16:33:19 +0100 | [diff] [blame] | 309 | static inline void advance_hpp(struct perf_hpp *hpp, int inc) |
| 310 | { |
| 311 | hpp->buf += inc; |
| 312 | hpp->size -= inc; |
| 313 | } |
| 314 | |
| 315 | static int hist_entry__period_snprintf(struct perf_hpp *hpp, |
Jiri Olsa | 9754c4f | 2013-10-25 13:24:53 +0200 | [diff] [blame] | 316 | struct hist_entry *he) |
Jiri Olsa | be0e6d1 | 2013-02-04 16:33:19 +0100 | [diff] [blame] | 317 | { |
| 318 | const char *sep = symbol_conf.field_sep; |
| 319 | struct perf_hpp_fmt *fmt; |
| 320 | char *start = hpp->buf; |
| 321 | int ret; |
| 322 | bool first = true; |
| 323 | |
| 324 | if (symbol_conf.exclude_other && !he->parent) |
| 325 | return 0; |
| 326 | |
| 327 | perf_hpp__for_each_format(fmt) { |
| 328 | /* |
| 329 | * If there's no field_sep, we still need |
| 330 | * to display initial ' '. |
| 331 | */ |
| 332 | if (!sep || !first) { |
| 333 | ret = scnprintf(hpp->buf, hpp->size, "%s", sep ?: " "); |
| 334 | advance_hpp(hpp, ret); |
| 335 | } else |
| 336 | first = false; |
| 337 | |
Jiri Olsa | 9754c4f | 2013-10-25 13:24:53 +0200 | [diff] [blame] | 338 | if (perf_hpp__use_color() && fmt->color) |
Jiri Olsa | be0e6d1 | 2013-02-04 16:33:19 +0100 | [diff] [blame] | 339 | ret = fmt->color(fmt, hpp, he); |
| 340 | else |
| 341 | ret = fmt->entry(fmt, hpp, he); |
| 342 | |
| 343 | advance_hpp(hpp, ret); |
| 344 | } |
| 345 | |
| 346 | return hpp->buf - start; |
| 347 | } |
| 348 | |
Namhyung Kim | 000078b | 2012-08-20 13:52:06 +0900 | [diff] [blame] | 349 | static int hist_entry__fprintf(struct hist_entry *he, size_t size, |
Arnaldo Carvalho de Melo | 99cf666 | 2013-09-05 15:39:12 -0300 | [diff] [blame] | 350 | struct hists *hists, |
| 351 | char *bf, size_t bfsz, FILE *fp) |
Namhyung Kim | 000078b | 2012-08-20 13:52:06 +0900 | [diff] [blame] | 352 | { |
Namhyung Kim | 000078b | 2012-08-20 13:52:06 +0900 | [diff] [blame] | 353 | int ret; |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 354 | struct perf_hpp hpp = { |
| 355 | .buf = bf, |
| 356 | .size = size, |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 357 | }; |
Namhyung Kim | 000078b | 2012-08-20 13:52:06 +0900 | [diff] [blame] | 358 | |
Arnaldo Carvalho de Melo | 99cf666 | 2013-09-05 15:39:12 -0300 | [diff] [blame] | 359 | if (size == 0 || size > bfsz) |
| 360 | size = hpp.size = bfsz; |
Namhyung Kim | 000078b | 2012-08-20 13:52:06 +0900 | [diff] [blame] | 361 | |
Jiri Olsa | 9754c4f | 2013-10-25 13:24:53 +0200 | [diff] [blame] | 362 | ret = hist_entry__period_snprintf(&hpp, he); |
Namhyung Kim | 000078b | 2012-08-20 13:52:06 +0900 | [diff] [blame] | 363 | hist_entry__sort_snprintf(he, bf + ret, size - ret, hists); |
| 364 | |
| 365 | ret = fprintf(fp, "%s\n", bf); |
| 366 | |
| 367 | if (symbol_conf.use_callchain) |
Jiri Olsa | b5ff71c | 2012-10-04 21:49:40 +0900 | [diff] [blame] | 368 | ret += hist_entry__callchain_fprintf(he, hists, fp); |
Namhyung Kim | 000078b | 2012-08-20 13:52:06 +0900 | [diff] [blame] | 369 | |
| 370 | return ret; |
| 371 | } |
| 372 | |
Jiri Olsa | 41724e4 | 2012-10-04 21:49:38 +0900 | [diff] [blame] | 373 | size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows, |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 374 | int max_cols, float min_pcnt, FILE *fp) |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 375 | { |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 376 | struct perf_hpp_fmt *fmt; |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 377 | struct sort_entry *se; |
| 378 | struct rb_node *nd; |
| 379 | size_t ret = 0; |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 380 | unsigned int width; |
| 381 | const char *sep = symbol_conf.field_sep; |
| 382 | const char *col_width = symbol_conf.col_width_list_str; |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 383 | int nr_rows = 0; |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 384 | char bf[96]; |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 385 | struct perf_hpp dummy_hpp = { |
| 386 | .buf = bf, |
| 387 | .size = sizeof(bf), |
Namhyung Kim | 5b9e214 | 2013-01-22 18:09:37 +0900 | [diff] [blame] | 388 | .ptr = hists_to_evsel(hists), |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 389 | }; |
Jiri Olsa | 5395a04 | 2012-10-04 21:49:37 +0900 | [diff] [blame] | 390 | bool first = true; |
Arnaldo Carvalho de Melo | 99cf666 | 2013-09-05 15:39:12 -0300 | [diff] [blame] | 391 | size_t linesz; |
| 392 | char *line = NULL; |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 393 | |
| 394 | init_rem_hits(); |
| 395 | |
| 396 | if (!show_header) |
| 397 | goto print_entries; |
| 398 | |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 399 | fprintf(fp, "# "); |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 400 | |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 401 | perf_hpp__for_each_format(fmt) { |
Jiri Olsa | 5395a04 | 2012-10-04 21:49:37 +0900 | [diff] [blame] | 402 | if (!first) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 403 | fprintf(fp, "%s", sep ?: " "); |
Jiri Olsa | 5395a04 | 2012-10-04 21:49:37 +0900 | [diff] [blame] | 404 | else |
| 405 | first = false; |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 406 | |
Jiri Olsa | 2c5d4b4 | 2013-01-31 23:31:11 +0100 | [diff] [blame] | 407 | fmt->header(fmt, &dummy_hpp); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 408 | fprintf(fp, "%s", bf); |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
| 412 | if (se->elide) |
| 413 | continue; |
| 414 | if (sep) { |
| 415 | fprintf(fp, "%c%s", *sep, se->se_header); |
| 416 | continue; |
| 417 | } |
| 418 | width = strlen(se->se_header); |
| 419 | if (symbol_conf.col_width_list_str) { |
| 420 | if (col_width) { |
| 421 | hists__set_col_len(hists, se->se_width_idx, |
| 422 | atoi(col_width)); |
| 423 | col_width = strchr(col_width, ','); |
| 424 | if (col_width) |
| 425 | ++col_width; |
| 426 | } |
| 427 | } |
| 428 | if (!hists__new_col_len(hists, se->se_width_idx, width)) |
| 429 | width = hists__col_len(hists, se->se_width_idx); |
| 430 | fprintf(fp, " %*s", width, se->se_header); |
| 431 | } |
| 432 | |
| 433 | fprintf(fp, "\n"); |
| 434 | if (max_rows && ++nr_rows >= max_rows) |
| 435 | goto out; |
| 436 | |
| 437 | if (sep) |
| 438 | goto print_entries; |
| 439 | |
Jiri Olsa | 5395a04 | 2012-10-04 21:49:37 +0900 | [diff] [blame] | 440 | first = true; |
| 441 | |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 442 | fprintf(fp, "# "); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 443 | |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 444 | perf_hpp__for_each_format(fmt) { |
| 445 | unsigned int i; |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 446 | |
Jiri Olsa | 5395a04 | 2012-10-04 21:49:37 +0900 | [diff] [blame] | 447 | if (!first) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 448 | fprintf(fp, "%s", sep ?: " "); |
Jiri Olsa | 5395a04 | 2012-10-04 21:49:37 +0900 | [diff] [blame] | 449 | else |
| 450 | first = false; |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 451 | |
Jiri Olsa | 2c5d4b4 | 2013-01-31 23:31:11 +0100 | [diff] [blame] | 452 | width = fmt->width(fmt, &dummy_hpp); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 453 | for (i = 0; i < width; i++) |
| 454 | fprintf(fp, "."); |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 455 | } |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 456 | |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 457 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
| 458 | unsigned int i; |
| 459 | |
| 460 | if (se->elide) |
| 461 | continue; |
| 462 | |
| 463 | fprintf(fp, " "); |
| 464 | width = hists__col_len(hists, se->se_width_idx); |
| 465 | if (width == 0) |
| 466 | width = strlen(se->se_header); |
| 467 | for (i = 0; i < width; i++) |
| 468 | fprintf(fp, "."); |
| 469 | } |
| 470 | |
| 471 | fprintf(fp, "\n"); |
| 472 | if (max_rows && ++nr_rows >= max_rows) |
| 473 | goto out; |
| 474 | |
| 475 | fprintf(fp, "#\n"); |
| 476 | if (max_rows && ++nr_rows >= max_rows) |
| 477 | goto out; |
| 478 | |
| 479 | print_entries: |
Arnaldo Carvalho de Melo | 99cf666 | 2013-09-05 15:39:12 -0300 | [diff] [blame] | 480 | linesz = hists__sort_list_width(hists) + 3 + 1; |
Jiri Olsa | 9754c4f | 2013-10-25 13:24:53 +0200 | [diff] [blame] | 481 | linesz += perf_hpp__color_overhead(); |
Arnaldo Carvalho de Melo | 99cf666 | 2013-09-05 15:39:12 -0300 | [diff] [blame] | 482 | line = malloc(linesz); |
| 483 | if (line == NULL) { |
| 484 | ret = -1; |
| 485 | goto out; |
| 486 | } |
| 487 | |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 488 | for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { |
| 489 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 490 | float percent = h->stat.period * 100.0 / |
| 491 | hists->stats.total_period; |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 492 | |
| 493 | if (h->filtered) |
| 494 | continue; |
| 495 | |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 496 | if (percent < min_pcnt) |
| 497 | continue; |
| 498 | |
Arnaldo Carvalho de Melo | 99cf666 | 2013-09-05 15:39:12 -0300 | [diff] [blame] | 499 | ret += hist_entry__fprintf(h, max_cols, hists, line, linesz, fp); |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 500 | |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 501 | if (max_rows && ++nr_rows >= max_rows) |
Arnaldo Carvalho de Melo | 99cf666 | 2013-09-05 15:39:12 -0300 | [diff] [blame] | 502 | break; |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 503 | |
| 504 | if (h->ms.map == NULL && verbose > 1) { |
| 505 | __map_groups__fprintf_maps(&h->thread->mg, |
| 506 | MAP__FUNCTION, verbose, fp); |
| 507 | fprintf(fp, "%.10s end\n", graph_dotted_line); |
| 508 | } |
| 509 | } |
Arnaldo Carvalho de Melo | 99cf666 | 2013-09-05 15:39:12 -0300 | [diff] [blame] | 510 | |
| 511 | free(line); |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 512 | out: |
| 513 | free(rem_sq_bracket); |
| 514 | |
| 515 | return ret; |
| 516 | } |
| 517 | |
Arnaldo Carvalho de Melo | 52168ee | 2012-12-18 16:02:17 -0300 | [diff] [blame] | 518 | size_t events_stats__fprintf(struct events_stats *stats, FILE *fp) |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 519 | { |
| 520 | int i; |
| 521 | size_t ret = 0; |
| 522 | |
| 523 | for (i = 0; i < PERF_RECORD_HEADER_MAX; ++i) { |
| 524 | const char *name; |
| 525 | |
Arnaldo Carvalho de Melo | 52168ee | 2012-12-18 16:02:17 -0300 | [diff] [blame] | 526 | if (stats->nr_events[i] == 0) |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 527 | continue; |
| 528 | |
| 529 | name = perf_event__name(i); |
| 530 | if (!strcmp(name, "UNKNOWN")) |
| 531 | continue; |
| 532 | |
| 533 | ret += fprintf(fp, "%16s events: %10d\n", name, |
Arnaldo Carvalho de Melo | 52168ee | 2012-12-18 16:02:17 -0300 | [diff] [blame] | 534 | stats->nr_events[i]); |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | return ret; |
| 538 | } |