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 | */ |
Namhyung Kim | cfaa154 | 2014-05-19 14:19:30 +0900 | [diff] [blame] | 186 | if (!i++ && field_order == NULL && |
| 187 | sort_order && !prefixcmp(sort_order, "sym")) |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 188 | continue; |
| 189 | if (!printed) { |
| 190 | ret += callchain__fprintf_left_margin(fp, left_margin); |
| 191 | ret += fprintf(fp, "|\n"); |
| 192 | ret += callchain__fprintf_left_margin(fp, left_margin); |
| 193 | ret += fprintf(fp, "---"); |
| 194 | left_margin += 3; |
| 195 | printed = true; |
| 196 | } else |
| 197 | ret += callchain__fprintf_left_margin(fp, left_margin); |
| 198 | |
| 199 | if (chain->ms.sym) |
| 200 | ret += fprintf(fp, " %s\n", chain->ms.sym->name); |
| 201 | else |
| 202 | ret += fprintf(fp, " %p\n", (void *)(long)chain->ip); |
| 203 | |
| 204 | if (++entries_printed == callchain_param.print_limit) |
| 205 | break; |
| 206 | } |
| 207 | root = &cnode->rb_root; |
| 208 | } |
| 209 | |
| 210 | ret += __callchain__fprintf_graph(fp, root, total_samples, |
| 211 | 1, 1, left_margin); |
| 212 | ret += fprintf(fp, "\n"); |
| 213 | |
| 214 | return ret; |
| 215 | } |
| 216 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 217 | static size_t __callchain__fprintf_flat(FILE *fp, struct callchain_node *node, |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 218 | u64 total_samples) |
| 219 | { |
| 220 | struct callchain_list *chain; |
| 221 | size_t ret = 0; |
| 222 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 223 | if (!node) |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 224 | return 0; |
| 225 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 226 | ret += __callchain__fprintf_flat(fp, node->parent, total_samples); |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 227 | |
| 228 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 229 | list_for_each_entry(chain, &node->val, list) { |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 230 | if (chain->ip >= PERF_CONTEXT_MAX) |
| 231 | continue; |
| 232 | if (chain->ms.sym) |
| 233 | ret += fprintf(fp, " %s\n", chain->ms.sym->name); |
| 234 | else |
| 235 | ret += fprintf(fp, " %p\n", |
| 236 | (void *)(long)chain->ip); |
| 237 | } |
| 238 | |
| 239 | return ret; |
| 240 | } |
| 241 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 242 | static size_t callchain__fprintf_flat(FILE *fp, struct rb_root *tree, |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 243 | u64 total_samples) |
| 244 | { |
| 245 | size_t ret = 0; |
| 246 | u32 entries_printed = 0; |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 247 | struct callchain_node *chain; |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 248 | struct rb_node *rb_node = rb_first(tree); |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 249 | |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 250 | while (rb_node) { |
| 251 | double percent; |
| 252 | |
| 253 | chain = rb_entry(rb_node, struct callchain_node, rb_node); |
| 254 | percent = chain->hit * 100.0 / total_samples; |
| 255 | |
| 256 | ret = percent_color_fprintf(fp, " %6.2f%%\n", percent); |
| 257 | ret += __callchain__fprintf_flat(fp, chain, total_samples); |
| 258 | ret += fprintf(fp, "\n"); |
| 259 | if (++entries_printed == callchain_param.print_limit) |
| 260 | break; |
| 261 | |
| 262 | rb_node = rb_next(rb_node); |
| 263 | } |
| 264 | |
| 265 | return ret; |
| 266 | } |
| 267 | |
| 268 | static size_t hist_entry_callchain__fprintf(struct hist_entry *he, |
| 269 | u64 total_samples, int left_margin, |
| 270 | FILE *fp) |
| 271 | { |
| 272 | switch (callchain_param.mode) { |
| 273 | case CHAIN_GRAPH_REL: |
Namhyung Kim | 56772ad | 2014-05-23 18:31:52 +0900 | [diff] [blame] | 274 | return callchain__fprintf_graph(fp, &he->sorted_chain, |
| 275 | symbol_conf.cumulate_callchain ? |
| 276 | he->stat_acc->period : he->stat.period, |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 277 | left_margin); |
| 278 | break; |
| 279 | case CHAIN_GRAPH_ABS: |
| 280 | return callchain__fprintf_graph(fp, &he->sorted_chain, total_samples, |
| 281 | left_margin); |
| 282 | break; |
| 283 | case CHAIN_FLAT: |
| 284 | return callchain__fprintf_flat(fp, &he->sorted_chain, total_samples); |
| 285 | break; |
| 286 | case CHAIN_NONE: |
| 287 | break; |
| 288 | default: |
| 289 | pr_err("Bad callchain mode\n"); |
| 290 | } |
| 291 | |
| 292 | return 0; |
| 293 | } |
| 294 | |
Namhyung Kim | 000078b | 2012-08-20 13:52:06 +0900 | [diff] [blame] | 295 | static size_t hist_entry__callchain_fprintf(struct hist_entry *he, |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 296 | struct hists *hists, |
Jiri Olsa | b5ff71c | 2012-10-04 21:49:40 +0900 | [diff] [blame] | 297 | FILE *fp) |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 298 | { |
| 299 | int left_margin = 0; |
Jiri Olsa | b5ff71c | 2012-10-04 21:49:40 +0900 | [diff] [blame] | 300 | u64 total_period = hists->stats.total_period; |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 301 | |
Namhyung Kim | cfaa154 | 2014-05-19 14:19:30 +0900 | [diff] [blame] | 302 | if (field_order == NULL && (sort_order == NULL || |
| 303 | !prefixcmp(sort_order, "comm"))) { |
| 304 | struct perf_hpp_fmt *fmt; |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 305 | |
Namhyung Kim | cfaa154 | 2014-05-19 14:19:30 +0900 | [diff] [blame] | 306 | perf_hpp__for_each_format(fmt) { |
| 307 | if (!perf_hpp__is_sort_entry(fmt)) |
| 308 | continue; |
| 309 | |
| 310 | /* must be 'comm' sort entry */ |
| 311 | left_margin = fmt->width(fmt, NULL, hists_to_evsel(hists)); |
| 312 | left_margin -= thread__comm_len(he->thread); |
| 313 | break; |
| 314 | } |
| 315 | } |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 316 | return hist_entry_callchain__fprintf(he, total_period, left_margin, fp); |
| 317 | } |
| 318 | |
Namhyung Kim | 26d8b33 | 2014-03-03 16:16:20 +0900 | [diff] [blame] | 319 | static int hist_entry__snprintf(struct hist_entry *he, struct perf_hpp *hpp) |
Jiri Olsa | be0e6d1 | 2013-02-04 16:33:19 +0100 | [diff] [blame] | 320 | { |
| 321 | const char *sep = symbol_conf.field_sep; |
| 322 | struct perf_hpp_fmt *fmt; |
| 323 | char *start = hpp->buf; |
| 324 | int ret; |
| 325 | bool first = true; |
| 326 | |
| 327 | if (symbol_conf.exclude_other && !he->parent) |
| 328 | return 0; |
| 329 | |
| 330 | perf_hpp__for_each_format(fmt) { |
Namhyung Kim | e67d49a | 2014-03-18 13:00:59 +0900 | [diff] [blame] | 331 | if (perf_hpp__should_skip(fmt)) |
| 332 | continue; |
| 333 | |
Jiri Olsa | be0e6d1 | 2013-02-04 16:33:19 +0100 | [diff] [blame] | 334 | /* |
| 335 | * If there's no field_sep, we still need |
| 336 | * to display initial ' '. |
| 337 | */ |
| 338 | if (!sep || !first) { |
| 339 | ret = scnprintf(hpp->buf, hpp->size, "%s", sep ?: " "); |
| 340 | advance_hpp(hpp, ret); |
| 341 | } else |
| 342 | first = false; |
| 343 | |
Jiri Olsa | 9754c4f | 2013-10-25 13:24:53 +0200 | [diff] [blame] | 344 | if (perf_hpp__use_color() && fmt->color) |
Jiri Olsa | be0e6d1 | 2013-02-04 16:33:19 +0100 | [diff] [blame] | 345 | ret = fmt->color(fmt, hpp, he); |
| 346 | else |
| 347 | ret = fmt->entry(fmt, hpp, he); |
| 348 | |
| 349 | advance_hpp(hpp, ret); |
| 350 | } |
| 351 | |
| 352 | return hpp->buf - start; |
| 353 | } |
| 354 | |
Namhyung Kim | 000078b | 2012-08-20 13:52:06 +0900 | [diff] [blame] | 355 | 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] | 356 | struct hists *hists, |
| 357 | char *bf, size_t bfsz, FILE *fp) |
Namhyung Kim | 000078b | 2012-08-20 13:52:06 +0900 | [diff] [blame] | 358 | { |
Namhyung Kim | 000078b | 2012-08-20 13:52:06 +0900 | [diff] [blame] | 359 | int ret; |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 360 | struct perf_hpp hpp = { |
| 361 | .buf = bf, |
| 362 | .size = size, |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 363 | }; |
Namhyung Kim | 000078b | 2012-08-20 13:52:06 +0900 | [diff] [blame] | 364 | |
Arnaldo Carvalho de Melo | 99cf666 | 2013-09-05 15:39:12 -0300 | [diff] [blame] | 365 | if (size == 0 || size > bfsz) |
| 366 | size = hpp.size = bfsz; |
Namhyung Kim | 000078b | 2012-08-20 13:52:06 +0900 | [diff] [blame] | 367 | |
Namhyung Kim | 26d8b33 | 2014-03-03 16:16:20 +0900 | [diff] [blame] | 368 | hist_entry__snprintf(he, &hpp); |
Namhyung Kim | 000078b | 2012-08-20 13:52:06 +0900 | [diff] [blame] | 369 | |
| 370 | ret = fprintf(fp, "%s\n", bf); |
| 371 | |
| 372 | if (symbol_conf.use_callchain) |
Jiri Olsa | b5ff71c | 2012-10-04 21:49:40 +0900 | [diff] [blame] | 373 | ret += hist_entry__callchain_fprintf(he, hists, fp); |
Namhyung Kim | 000078b | 2012-08-20 13:52:06 +0900 | [diff] [blame] | 374 | |
| 375 | return ret; |
| 376 | } |
| 377 | |
Jiri Olsa | 41724e4 | 2012-10-04 21:49:38 +0900 | [diff] [blame] | 378 | 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] | 379 | int max_cols, float min_pcnt, FILE *fp) |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 380 | { |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 381 | struct perf_hpp_fmt *fmt; |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 382 | struct rb_node *nd; |
| 383 | size_t ret = 0; |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 384 | unsigned int width; |
| 385 | const char *sep = symbol_conf.field_sep; |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 386 | int nr_rows = 0; |
Jiri Olsa | ed279da | 2012-10-05 16:44:45 +0200 | [diff] [blame] | 387 | char bf[96]; |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 388 | struct perf_hpp dummy_hpp = { |
| 389 | .buf = bf, |
| 390 | .size = sizeof(bf), |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 391 | }; |
Jiri Olsa | 5395a04 | 2012-10-04 21:49:37 +0900 | [diff] [blame] | 392 | bool first = true; |
Arnaldo Carvalho de Melo | 99cf666 | 2013-09-05 15:39:12 -0300 | [diff] [blame] | 393 | size_t linesz; |
| 394 | char *line = NULL; |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 395 | |
| 396 | init_rem_hits(); |
| 397 | |
Namhyung Kim | 678a500 | 2014-03-20 11:18:54 +0900 | [diff] [blame] | 398 | perf_hpp__for_each_format(fmt) |
| 399 | perf_hpp__reset_width(fmt, hists); |
Namhyung Kim | 26d8b33 | 2014-03-03 16:16:20 +0900 | [diff] [blame] | 400 | |
Namhyung Kim | 5b59166 | 2014-07-31 14:47:38 +0900 | [diff] [blame^] | 401 | if (symbol_conf.col_width_list_str) |
| 402 | perf_hpp__set_user_width(symbol_conf.col_width_list_str); |
| 403 | |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 404 | if (!show_header) |
| 405 | goto print_entries; |
| 406 | |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 407 | fprintf(fp, "# "); |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 408 | |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 409 | perf_hpp__for_each_format(fmt) { |
Namhyung Kim | e67d49a | 2014-03-18 13:00:59 +0900 | [diff] [blame] | 410 | if (perf_hpp__should_skip(fmt)) |
| 411 | continue; |
| 412 | |
Jiri Olsa | 5395a04 | 2012-10-04 21:49:37 +0900 | [diff] [blame] | 413 | if (!first) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 414 | fprintf(fp, "%s", sep ?: " "); |
Jiri Olsa | 5395a04 | 2012-10-04 21:49:37 +0900 | [diff] [blame] | 415 | else |
| 416 | first = false; |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 417 | |
Namhyung Kim | 94a0793 | 2014-03-10 16:43:52 +0900 | [diff] [blame] | 418 | fmt->header(fmt, &dummy_hpp, hists_to_evsel(hists)); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 419 | fprintf(fp, "%s", bf); |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 420 | } |
| 421 | |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 422 | fprintf(fp, "\n"); |
| 423 | if (max_rows && ++nr_rows >= max_rows) |
| 424 | goto out; |
| 425 | |
| 426 | if (sep) |
| 427 | goto print_entries; |
| 428 | |
Jiri Olsa | 5395a04 | 2012-10-04 21:49:37 +0900 | [diff] [blame] | 429 | first = true; |
| 430 | |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 431 | fprintf(fp, "# "); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 432 | |
Jiri Olsa | 1240005 | 2012-10-13 00:06:16 +0200 | [diff] [blame] | 433 | perf_hpp__for_each_format(fmt) { |
| 434 | unsigned int i; |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 435 | |
Namhyung Kim | e67d49a | 2014-03-18 13:00:59 +0900 | [diff] [blame] | 436 | if (perf_hpp__should_skip(fmt)) |
| 437 | continue; |
| 438 | |
Jiri Olsa | 5395a04 | 2012-10-04 21:49:37 +0900 | [diff] [blame] | 439 | if (!first) |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 440 | fprintf(fp, "%s", sep ?: " "); |
Jiri Olsa | 5395a04 | 2012-10-04 21:49:37 +0900 | [diff] [blame] | 441 | else |
| 442 | first = false; |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 443 | |
Namhyung Kim | 94a0793 | 2014-03-10 16:43:52 +0900 | [diff] [blame] | 444 | width = fmt->width(fmt, &dummy_hpp, hists_to_evsel(hists)); |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 445 | for (i = 0; i < width; i++) |
| 446 | fprintf(fp, "."); |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 447 | } |
Namhyung Kim | ea251d5 | 2012-09-03 11:53:06 +0900 | [diff] [blame] | 448 | |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 449 | fprintf(fp, "\n"); |
| 450 | if (max_rows && ++nr_rows >= max_rows) |
| 451 | goto out; |
| 452 | |
| 453 | fprintf(fp, "#\n"); |
| 454 | if (max_rows && ++nr_rows >= max_rows) |
| 455 | goto out; |
| 456 | |
| 457 | print_entries: |
Arnaldo Carvalho de Melo | 99cf666 | 2013-09-05 15:39:12 -0300 | [diff] [blame] | 458 | linesz = hists__sort_list_width(hists) + 3 + 1; |
Jiri Olsa | 9754c4f | 2013-10-25 13:24:53 +0200 | [diff] [blame] | 459 | linesz += perf_hpp__color_overhead(); |
Arnaldo Carvalho de Melo | 99cf666 | 2013-09-05 15:39:12 -0300 | [diff] [blame] | 460 | line = malloc(linesz); |
| 461 | if (line == NULL) { |
| 462 | ret = -1; |
| 463 | goto out; |
| 464 | } |
| 465 | |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 466 | for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { |
| 467 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
Namhyung Kim | 1413566 | 2013-10-31 10:17:39 +0900 | [diff] [blame] | 468 | float percent; |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 469 | |
| 470 | if (h->filtered) |
| 471 | continue; |
| 472 | |
Namhyung Kim | 1413566 | 2013-10-31 10:17:39 +0900 | [diff] [blame] | 473 | percent = hist_entry__get_percent_limit(h); |
Namhyung Kim | 064f198 | 2013-05-14 11:09:04 +0900 | [diff] [blame] | 474 | if (percent < min_pcnt) |
| 475 | continue; |
| 476 | |
Arnaldo Carvalho de Melo | 99cf666 | 2013-09-05 15:39:12 -0300 | [diff] [blame] | 477 | ret += hist_entry__fprintf(h, max_cols, hists, line, linesz, fp); |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 478 | |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 479 | if (max_rows && ++nr_rows >= max_rows) |
Arnaldo Carvalho de Melo | 99cf666 | 2013-09-05 15:39:12 -0300 | [diff] [blame] | 480 | break; |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 481 | |
| 482 | if (h->ms.map == NULL && verbose > 1) { |
Arnaldo Carvalho de Melo | 93d5731 | 2014-03-21 17:57:01 -0300 | [diff] [blame] | 483 | __map_groups__fprintf_maps(h->thread->mg, |
Jiri Olsa | acebd40 | 2014-07-14 23:46:47 +0200 | [diff] [blame] | 484 | MAP__FUNCTION, fp); |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 485 | fprintf(fp, "%.10s end\n", graph_dotted_line); |
| 486 | } |
| 487 | } |
Arnaldo Carvalho de Melo | 99cf666 | 2013-09-05 15:39:12 -0300 | [diff] [blame] | 488 | |
| 489 | free(line); |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 490 | out: |
Arnaldo Carvalho de Melo | 74cf249 | 2013-12-27 16:55:14 -0300 | [diff] [blame] | 491 | zfree(&rem_sq_bracket); |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 492 | |
| 493 | return ret; |
| 494 | } |
| 495 | |
Arnaldo Carvalho de Melo | 52168ee | 2012-12-18 16:02:17 -0300 | [diff] [blame] | 496 | size_t events_stats__fprintf(struct events_stats *stats, FILE *fp) |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 497 | { |
| 498 | int i; |
| 499 | size_t ret = 0; |
| 500 | |
| 501 | for (i = 0; i < PERF_RECORD_HEADER_MAX; ++i) { |
| 502 | const char *name; |
| 503 | |
Arnaldo Carvalho de Melo | 52168ee | 2012-12-18 16:02:17 -0300 | [diff] [blame] | 504 | if (stats->nr_events[i] == 0) |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 505 | continue; |
| 506 | |
| 507 | name = perf_event__name(i); |
| 508 | if (!strcmp(name, "UNKNOWN")) |
| 509 | continue; |
| 510 | |
| 511 | ret += fprintf(fp, "%16s events: %10d\n", name, |
Arnaldo Carvalho de Melo | 52168ee | 2012-12-18 16:02:17 -0300 | [diff] [blame] | 512 | stats->nr_events[i]); |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | return ret; |
| 516 | } |