blob: f4de055cab9bf74a0838fb660af6f57f6573174e [file] [log] [blame]
Namhyung Kim7ccf4f92012-08-20 13:52:05 +09001#include <stdio.h>
Namhyung Kim7ccf4f92012-08-20 13:52:05 +09002
3#include "../../util/util.h"
4#include "../../util/hist.h"
5#include "../../util/sort.h"
Namhyung Kim5b9e2142013-01-22 18:09:37 +09006#include "../../util/evsel.h"
Namhyung Kim7ccf4f92012-08-20 13:52:05 +09007
8
9static 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
20static 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
Namhyung Kim5ab250c2015-11-09 14:45:39 +090037static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_node *node,
38 struct callchain_list *chain,
Namhyung Kim7ccf4f92012-08-20 13:52:05 +090039 int depth, int depth_mask, int period,
Namhyung Kim5ab250c2015-11-09 14:45:39 +090040 u64 total_samples, int left_margin)
Namhyung Kim7ccf4f92012-08-20 13:52:05 +090041{
42 int i;
43 size_t ret = 0;
Andi Kleen2989cca2014-11-12 18:05:23 -080044 char bf[1024];
Namhyung Kim7ccf4f92012-08-20 13:52:05 +090045
46 ret += callchain__fprintf_left_margin(fp, left_margin);
47 for (i = 0; i < depth; i++) {
48 if (depth_mask & (1 << i))
49 ret += fprintf(fp, "|");
50 else
51 ret += fprintf(fp, " ");
52 if (!period && i == depth - 1) {
Namhyung Kim5ab250c2015-11-09 14:45:39 +090053 ret += fprintf(fp, "--");
54 ret += callchain_node__fprintf_value(node, fp, total_samples);
55 ret += fprintf(fp, "--");
Namhyung Kim7ccf4f92012-08-20 13:52:05 +090056 } else
57 ret += fprintf(fp, "%s", " ");
58 }
Andi Kleen2989cca2014-11-12 18:05:23 -080059 fputs(callchain_list__sym_name(chain, bf, sizeof(bf), false), fp);
60 fputc('\n', fp);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +090061 return ret;
62}
63
64static struct symbol *rem_sq_bracket;
65static struct callchain_list rem_hits;
66
67static void init_rem_hits(void)
68{
69 rem_sq_bracket = malloc(sizeof(*rem_sq_bracket) + 6);
70 if (!rem_sq_bracket) {
71 fprintf(stderr, "Not enough memory to display remaining hits\n");
72 return;
73 }
74
75 strcpy(rem_sq_bracket->name, "[...]");
76 rem_hits.ms.sym = rem_sq_bracket;
77}
78
79static size_t __callchain__fprintf_graph(FILE *fp, struct rb_root *root,
80 u64 total_samples, int depth,
81 int depth_mask, int left_margin)
82{
83 struct rb_node *node, *next;
84 struct callchain_node *child;
85 struct callchain_list *chain;
86 int new_depth_mask = depth_mask;
87 u64 remaining;
88 size_t ret = 0;
89 int i;
90 uint entries_printed = 0;
91
92 remaining = total_samples;
93
94 node = rb_first(root);
95 while (node) {
96 u64 new_total;
97 u64 cumul;
98
99 child = rb_entry(node, struct callchain_node, rb_node);
100 cumul = callchain_cumul_hits(child);
101 remaining -= cumul;
102
103 /*
104 * The depth mask manages the output of pipes that show
105 * the depth. We don't want to keep the pipes of the current
106 * level for the last child of this depth.
107 * Except if we have remaining filtered hits. They will
108 * supersede the last child
109 */
110 next = rb_next(node);
111 if (!next && (callchain_param.mode != CHAIN_GRAPH_REL || !remaining))
112 new_depth_mask &= ~(1 << (depth - 1));
113
114 /*
115 * But we keep the older depth mask for the line separator
116 * to keep the level link until we reach the last child
117 */
118 ret += ipchain__fprintf_graph_line(fp, depth, depth_mask,
119 left_margin);
120 i = 0;
121 list_for_each_entry(chain, &child->val, list) {
Namhyung Kim5ab250c2015-11-09 14:45:39 +0900122 ret += ipchain__fprintf_graph(fp, child, chain, depth,
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900123 new_depth_mask, i++,
124 total_samples,
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900125 left_margin);
126 }
127
128 if (callchain_param.mode == CHAIN_GRAPH_REL)
129 new_total = child->children_hit;
130 else
131 new_total = total_samples;
132
133 ret += __callchain__fprintf_graph(fp, &child->rb_root, new_total,
134 depth + 1,
135 new_depth_mask | (1 << depth),
136 left_margin);
137 node = next;
138 if (++entries_printed == callchain_param.print_limit)
139 break;
140 }
141
142 if (callchain_param.mode == CHAIN_GRAPH_REL &&
143 remaining && remaining != total_samples) {
Namhyung Kim5ab250c2015-11-09 14:45:39 +0900144 struct callchain_node rem_node = {
145 .hit = remaining,
146 };
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900147
148 if (!rem_sq_bracket)
149 return ret;
150
151 new_depth_mask &= ~(1 << (depth - 1));
Namhyung Kim5ab250c2015-11-09 14:45:39 +0900152 ret += ipchain__fprintf_graph(fp, &rem_node, &rem_hits, depth,
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900153 new_depth_mask, 0, total_samples,
Namhyung Kim5ab250c2015-11-09 14:45:39 +0900154 left_margin);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900155 }
156
157 return ret;
158}
159
160static size_t callchain__fprintf_graph(FILE *fp, struct rb_root *root,
161 u64 total_samples, int left_margin)
162{
163 struct callchain_node *cnode;
164 struct callchain_list *chain;
165 u32 entries_printed = 0;
166 bool printed = false;
167 struct rb_node *node;
168 int i = 0;
169 int ret = 0;
Andi Kleen2989cca2014-11-12 18:05:23 -0800170 char bf[1024];
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900171
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 Kimcfaa1542014-05-19 14:19:30 +0900186 if (!i++ && field_order == NULL &&
187 sort_order && !prefixcmp(sort_order, "sym"))
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900188 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
Andi Kleen2989cca2014-11-12 18:05:23 -0800199 ret += fprintf(fp, "%s\n", callchain_list__sym_name(chain, bf, sizeof(bf),
200 false));
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900201
202 if (++entries_printed == callchain_param.print_limit)
203 break;
204 }
205 root = &cnode->rb_root;
206 }
207
208 ret += __callchain__fprintf_graph(fp, root, total_samples,
209 1, 1, left_margin);
210 ret += fprintf(fp, "\n");
211
212 return ret;
213}
214
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -0300215static size_t __callchain__fprintf_flat(FILE *fp, struct callchain_node *node,
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900216 u64 total_samples)
217{
218 struct callchain_list *chain;
219 size_t ret = 0;
Andi Kleen2989cca2014-11-12 18:05:23 -0800220 char bf[1024];
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900221
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -0300222 if (!node)
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900223 return 0;
224
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -0300225 ret += __callchain__fprintf_flat(fp, node->parent, total_samples);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900226
227
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -0300228 list_for_each_entry(chain, &node->val, list) {
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900229 if (chain->ip >= PERF_CONTEXT_MAX)
230 continue;
Andi Kleen2989cca2014-11-12 18:05:23 -0800231 ret += fprintf(fp, " %s\n", callchain_list__sym_name(chain,
232 bf, sizeof(bf), false));
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900233 }
234
235 return ret;
236}
237
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -0300238static size_t callchain__fprintf_flat(FILE *fp, struct rb_root *tree,
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900239 u64 total_samples)
240{
241 size_t ret = 0;
242 u32 entries_printed = 0;
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900243 struct callchain_node *chain;
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -0300244 struct rb_node *rb_node = rb_first(tree);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900245
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900246 while (rb_node) {
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900247 chain = rb_entry(rb_node, struct callchain_node, rb_node);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900248
Namhyung Kim5ab250c2015-11-09 14:45:39 +0900249 ret += fprintf(fp, " ");
250 ret += callchain_node__fprintf_value(chain, fp, total_samples);
251 ret += fprintf(fp, "\n");
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900252 ret += __callchain__fprintf_flat(fp, chain, total_samples);
253 ret += fprintf(fp, "\n");
254 if (++entries_printed == callchain_param.print_limit)
255 break;
256
257 rb_node = rb_next(rb_node);
258 }
259
260 return ret;
261}
262
Namhyung Kim26e77922015-11-09 14:45:37 +0900263static size_t __callchain__fprintf_folded(FILE *fp, struct callchain_node *node)
264{
265 const char *sep = symbol_conf.field_sep ?: ";";
266 struct callchain_list *chain;
267 size_t ret = 0;
268 char bf[1024];
269 bool first;
270
271 if (!node)
272 return 0;
273
274 ret += __callchain__fprintf_folded(fp, node->parent);
275
276 first = (ret == 0);
277 list_for_each_entry(chain, &node->val, list) {
278 if (chain->ip >= PERF_CONTEXT_MAX)
279 continue;
280 ret += fprintf(fp, "%s%s", first ? "" : sep,
281 callchain_list__sym_name(chain,
282 bf, sizeof(bf), false));
283 first = false;
284 }
285
286 return ret;
287}
288
289static size_t callchain__fprintf_folded(FILE *fp, struct rb_root *tree,
290 u64 total_samples)
291{
292 size_t ret = 0;
293 u32 entries_printed = 0;
294 struct callchain_node *chain;
295 struct rb_node *rb_node = rb_first(tree);
296
297 while (rb_node) {
Namhyung Kim26e77922015-11-09 14:45:37 +0900298
299 chain = rb_entry(rb_node, struct callchain_node, rb_node);
Namhyung Kim26e77922015-11-09 14:45:37 +0900300
Namhyung Kim5ab250c2015-11-09 14:45:39 +0900301 ret += callchain_node__fprintf_value(chain, fp, total_samples);
302 ret += fprintf(fp, " ");
Namhyung Kim26e77922015-11-09 14:45:37 +0900303 ret += __callchain__fprintf_folded(fp, chain);
304 ret += fprintf(fp, "\n");
305 if (++entries_printed == callchain_param.print_limit)
306 break;
307
308 rb_node = rb_next(rb_node);
309 }
310
311 return ret;
312}
313
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900314static size_t hist_entry_callchain__fprintf(struct hist_entry *he,
315 u64 total_samples, int left_margin,
316 FILE *fp)
317{
318 switch (callchain_param.mode) {
319 case CHAIN_GRAPH_REL:
Namhyung Kim56772ad2014-05-23 18:31:52 +0900320 return callchain__fprintf_graph(fp, &he->sorted_chain,
321 symbol_conf.cumulate_callchain ?
322 he->stat_acc->period : he->stat.period,
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900323 left_margin);
324 break;
325 case CHAIN_GRAPH_ABS:
326 return callchain__fprintf_graph(fp, &he->sorted_chain, total_samples,
327 left_margin);
328 break;
329 case CHAIN_FLAT:
330 return callchain__fprintf_flat(fp, &he->sorted_chain, total_samples);
331 break;
Namhyung Kim26e77922015-11-09 14:45:37 +0900332 case CHAIN_FOLDED:
333 return callchain__fprintf_folded(fp, &he->sorted_chain, total_samples);
334 break;
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900335 case CHAIN_NONE:
336 break;
337 default:
338 pr_err("Bad callchain mode\n");
339 }
340
341 return 0;
342}
343
Namhyung Kim000078b2012-08-20 13:52:06 +0900344static size_t hist_entry__callchain_fprintf(struct hist_entry *he,
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900345 struct hists *hists,
Jiri Olsab5ff71c2012-10-04 21:49:40 +0900346 FILE *fp)
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900347{
348 int left_margin = 0;
Jiri Olsab5ff71c2012-10-04 21:49:40 +0900349 u64 total_period = hists->stats.total_period;
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900350
Namhyung Kimcfaa1542014-05-19 14:19:30 +0900351 if (field_order == NULL && (sort_order == NULL ||
352 !prefixcmp(sort_order, "comm"))) {
353 struct perf_hpp_fmt *fmt;
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900354
Namhyung Kimcfaa1542014-05-19 14:19:30 +0900355 perf_hpp__for_each_format(fmt) {
356 if (!perf_hpp__is_sort_entry(fmt))
357 continue;
358
359 /* must be 'comm' sort entry */
360 left_margin = fmt->width(fmt, NULL, hists_to_evsel(hists));
361 left_margin -= thread__comm_len(he->thread);
362 break;
363 }
364 }
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900365 return hist_entry_callchain__fprintf(he, total_period, left_margin, fp);
366}
367
Namhyung Kim26d8b332014-03-03 16:16:20 +0900368static int hist_entry__snprintf(struct hist_entry *he, struct perf_hpp *hpp)
Jiri Olsabe0e6d12013-02-04 16:33:19 +0100369{
370 const char *sep = symbol_conf.field_sep;
371 struct perf_hpp_fmt *fmt;
372 char *start = hpp->buf;
373 int ret;
374 bool first = true;
375
376 if (symbol_conf.exclude_other && !he->parent)
377 return 0;
378
379 perf_hpp__for_each_format(fmt) {
Namhyung Kime67d49a2014-03-18 13:00:59 +0900380 if (perf_hpp__should_skip(fmt))
381 continue;
382
Jiri Olsabe0e6d12013-02-04 16:33:19 +0100383 /*
384 * If there's no field_sep, we still need
385 * to display initial ' '.
386 */
387 if (!sep || !first) {
388 ret = scnprintf(hpp->buf, hpp->size, "%s", sep ?: " ");
389 advance_hpp(hpp, ret);
390 } else
391 first = false;
392
Jiri Olsa9754c4f2013-10-25 13:24:53 +0200393 if (perf_hpp__use_color() && fmt->color)
Jiri Olsabe0e6d12013-02-04 16:33:19 +0100394 ret = fmt->color(fmt, hpp, he);
395 else
396 ret = fmt->entry(fmt, hpp, he);
397
398 advance_hpp(hpp, ret);
399 }
400
401 return hpp->buf - start;
402}
403
Namhyung Kim000078b2012-08-20 13:52:06 +0900404static int hist_entry__fprintf(struct hist_entry *he, size_t size,
Arnaldo Carvalho de Melo99cf6662013-09-05 15:39:12 -0300405 struct hists *hists,
406 char *bf, size_t bfsz, FILE *fp)
Namhyung Kim000078b2012-08-20 13:52:06 +0900407{
Namhyung Kim000078b2012-08-20 13:52:06 +0900408 int ret;
Namhyung Kimea251d52012-09-03 11:53:06 +0900409 struct perf_hpp hpp = {
410 .buf = bf,
411 .size = size,
Namhyung Kimea251d52012-09-03 11:53:06 +0900412 };
Namhyung Kim000078b2012-08-20 13:52:06 +0900413
Arnaldo Carvalho de Melo99cf6662013-09-05 15:39:12 -0300414 if (size == 0 || size > bfsz)
415 size = hpp.size = bfsz;
Namhyung Kim000078b2012-08-20 13:52:06 +0900416
Namhyung Kim26d8b332014-03-03 16:16:20 +0900417 hist_entry__snprintf(he, &hpp);
Namhyung Kim000078b2012-08-20 13:52:06 +0900418
419 ret = fprintf(fp, "%s\n", bf);
420
421 if (symbol_conf.use_callchain)
Jiri Olsab5ff71c2012-10-04 21:49:40 +0900422 ret += hist_entry__callchain_fprintf(he, hists, fp);
Namhyung Kim000078b2012-08-20 13:52:06 +0900423
424 return ret;
425}
426
Jiri Olsa41724e42012-10-04 21:49:38 +0900427size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
Namhyung Kim064f1982013-05-14 11:09:04 +0900428 int max_cols, float min_pcnt, FILE *fp)
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900429{
Jiri Olsa12400052012-10-13 00:06:16 +0200430 struct perf_hpp_fmt *fmt;
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900431 struct rb_node *nd;
432 size_t ret = 0;
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900433 unsigned int width;
434 const char *sep = symbol_conf.field_sep;
Jiri Olsa12400052012-10-13 00:06:16 +0200435 int nr_rows = 0;
Jiri Olsaed279da2012-10-05 16:44:45 +0200436 char bf[96];
Namhyung Kimea251d52012-09-03 11:53:06 +0900437 struct perf_hpp dummy_hpp = {
438 .buf = bf,
439 .size = sizeof(bf),
Namhyung Kimea251d52012-09-03 11:53:06 +0900440 };
Jiri Olsa5395a042012-10-04 21:49:37 +0900441 bool first = true;
Arnaldo Carvalho de Melo99cf6662013-09-05 15:39:12 -0300442 size_t linesz;
443 char *line = NULL;
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900444
445 init_rem_hits();
446
Namhyung Kim678a5002014-03-20 11:18:54 +0900447 perf_hpp__for_each_format(fmt)
448 perf_hpp__reset_width(fmt, hists);
Namhyung Kim26d8b332014-03-03 16:16:20 +0900449
Namhyung Kim5b591662014-07-31 14:47:38 +0900450 if (symbol_conf.col_width_list_str)
451 perf_hpp__set_user_width(symbol_conf.col_width_list_str);
452
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900453 if (!show_header)
454 goto print_entries;
455
Namhyung Kimea251d52012-09-03 11:53:06 +0900456 fprintf(fp, "# ");
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900457
Jiri Olsa12400052012-10-13 00:06:16 +0200458 perf_hpp__for_each_format(fmt) {
Namhyung Kime67d49a2014-03-18 13:00:59 +0900459 if (perf_hpp__should_skip(fmt))
460 continue;
461
Jiri Olsa5395a042012-10-04 21:49:37 +0900462 if (!first)
Namhyung Kimea251d52012-09-03 11:53:06 +0900463 fprintf(fp, "%s", sep ?: " ");
Jiri Olsa5395a042012-10-04 21:49:37 +0900464 else
465 first = false;
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900466
Namhyung Kim94a07932014-03-10 16:43:52 +0900467 fmt->header(fmt, &dummy_hpp, hists_to_evsel(hists));
Namhyung Kimea251d52012-09-03 11:53:06 +0900468 fprintf(fp, "%s", bf);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900469 }
470
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900471 fprintf(fp, "\n");
472 if (max_rows && ++nr_rows >= max_rows)
473 goto out;
474
475 if (sep)
476 goto print_entries;
477
Jiri Olsa5395a042012-10-04 21:49:37 +0900478 first = true;
479
Namhyung Kimea251d52012-09-03 11:53:06 +0900480 fprintf(fp, "# ");
Namhyung Kimea251d52012-09-03 11:53:06 +0900481
Jiri Olsa12400052012-10-13 00:06:16 +0200482 perf_hpp__for_each_format(fmt) {
483 unsigned int i;
Namhyung Kimea251d52012-09-03 11:53:06 +0900484
Namhyung Kime67d49a2014-03-18 13:00:59 +0900485 if (perf_hpp__should_skip(fmt))
486 continue;
487
Jiri Olsa5395a042012-10-04 21:49:37 +0900488 if (!first)
Namhyung Kimea251d52012-09-03 11:53:06 +0900489 fprintf(fp, "%s", sep ?: " ");
Jiri Olsa5395a042012-10-04 21:49:37 +0900490 else
491 first = false;
Namhyung Kimea251d52012-09-03 11:53:06 +0900492
Namhyung Kim94a07932014-03-10 16:43:52 +0900493 width = fmt->width(fmt, &dummy_hpp, hists_to_evsel(hists));
Namhyung Kimea251d52012-09-03 11:53:06 +0900494 for (i = 0; i < width; i++)
495 fprintf(fp, ".");
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900496 }
Namhyung Kimea251d52012-09-03 11:53:06 +0900497
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900498 fprintf(fp, "\n");
499 if (max_rows && ++nr_rows >= max_rows)
500 goto out;
501
502 fprintf(fp, "#\n");
503 if (max_rows && ++nr_rows >= max_rows)
504 goto out;
505
506print_entries:
Arnaldo Carvalho de Melo99cf6662013-09-05 15:39:12 -0300507 linesz = hists__sort_list_width(hists) + 3 + 1;
Jiri Olsa9754c4f2013-10-25 13:24:53 +0200508 linesz += perf_hpp__color_overhead();
Arnaldo Carvalho de Melo99cf6662013-09-05 15:39:12 -0300509 line = malloc(linesz);
510 if (line == NULL) {
511 ret = -1;
512 goto out;
513 }
514
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900515 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
516 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
Namhyung Kim14135662013-10-31 10:17:39 +0900517 float percent;
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900518
519 if (h->filtered)
520 continue;
521
Namhyung Kim14135662013-10-31 10:17:39 +0900522 percent = hist_entry__get_percent_limit(h);
Namhyung Kim064f1982013-05-14 11:09:04 +0900523 if (percent < min_pcnt)
524 continue;
525
Arnaldo Carvalho de Melo99cf6662013-09-05 15:39:12 -0300526 ret += hist_entry__fprintf(h, max_cols, hists, line, linesz, fp);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900527
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900528 if (max_rows && ++nr_rows >= max_rows)
Arnaldo Carvalho de Melo99cf6662013-09-05 15:39:12 -0300529 break;
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900530
531 if (h->ms.map == NULL && verbose > 1) {
Arnaldo Carvalho de Melo93d57312014-03-21 17:57:01 -0300532 __map_groups__fprintf_maps(h->thread->mg,
Jiri Olsaacebd402014-07-14 23:46:47 +0200533 MAP__FUNCTION, fp);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900534 fprintf(fp, "%.10s end\n", graph_dotted_line);
535 }
536 }
Arnaldo Carvalho de Melo99cf6662013-09-05 15:39:12 -0300537
538 free(line);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900539out:
Arnaldo Carvalho de Melo74cf2492013-12-27 16:55:14 -0300540 zfree(&rem_sq_bracket);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900541
542 return ret;
543}
544
Arnaldo Carvalho de Melo52168ee2012-12-18 16:02:17 -0300545size_t events_stats__fprintf(struct events_stats *stats, FILE *fp)
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900546{
547 int i;
548 size_t ret = 0;
549
550 for (i = 0; i < PERF_RECORD_HEADER_MAX; ++i) {
551 const char *name;
552
Arnaldo Carvalho de Melo52168ee2012-12-18 16:02:17 -0300553 if (stats->nr_events[i] == 0)
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900554 continue;
555
556 name = perf_event__name(i);
557 if (!strcmp(name, "UNKNOWN"))
558 continue;
559
560 ret += fprintf(fp, "%16s events: %10d\n", name,
Arnaldo Carvalho de Melo52168ee2012-12-18 16:02:17 -0300561 stats->nr_events[i]);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900562 }
563
564 return ret;
565}