blob: 96188ea1277159c00def387c1b3dde6c44cdccd7 [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;
Namhyung Kimf2af0082015-11-09 14:45:41 +090084 struct callchain_node *child = NULL;
Namhyung Kim7ccf4f92012-08-20 13:52:05 +090085 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;
Namhyung Kimf2af0082015-11-09 14:45:41 +090091 int cumul_count = 0;
Namhyung Kim7ccf4f92012-08-20 13:52:05 +090092
93 remaining = total_samples;
94
95 node = rb_first(root);
96 while (node) {
97 u64 new_total;
98 u64 cumul;
99
100 child = rb_entry(node, struct callchain_node, rb_node);
101 cumul = callchain_cumul_hits(child);
102 remaining -= cumul;
Namhyung Kimf2af0082015-11-09 14:45:41 +0900103 cumul_count += callchain_cumul_counts(child);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900104
105 /*
106 * The depth mask manages the output of pipes that show
107 * the depth. We don't want to keep the pipes of the current
108 * level for the last child of this depth.
109 * Except if we have remaining filtered hits. They will
110 * supersede the last child
111 */
112 next = rb_next(node);
113 if (!next && (callchain_param.mode != CHAIN_GRAPH_REL || !remaining))
114 new_depth_mask &= ~(1 << (depth - 1));
115
116 /*
117 * But we keep the older depth mask for the line separator
118 * to keep the level link until we reach the last child
119 */
120 ret += ipchain__fprintf_graph_line(fp, depth, depth_mask,
121 left_margin);
122 i = 0;
123 list_for_each_entry(chain, &child->val, list) {
Namhyung Kim5ab250c2015-11-09 14:45:39 +0900124 ret += ipchain__fprintf_graph(fp, child, chain, depth,
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900125 new_depth_mask, i++,
126 total_samples,
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900127 left_margin);
128 }
129
130 if (callchain_param.mode == CHAIN_GRAPH_REL)
131 new_total = child->children_hit;
132 else
133 new_total = total_samples;
134
135 ret += __callchain__fprintf_graph(fp, &child->rb_root, new_total,
136 depth + 1,
137 new_depth_mask | (1 << depth),
138 left_margin);
139 node = next;
140 if (++entries_printed == callchain_param.print_limit)
141 break;
142 }
143
144 if (callchain_param.mode == CHAIN_GRAPH_REL &&
145 remaining && remaining != total_samples) {
Namhyung Kim5ab250c2015-11-09 14:45:39 +0900146 struct callchain_node rem_node = {
147 .hit = remaining,
148 };
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900149
150 if (!rem_sq_bracket)
151 return ret;
152
Namhyung Kimf2af0082015-11-09 14:45:41 +0900153 if (callchain_param.value == CCVAL_COUNT && child && child->parent) {
154 rem_node.count = child->parent->children_count - cumul_count;
155 if (rem_node.count <= 0)
156 return ret;
157 }
158
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900159 new_depth_mask &= ~(1 << (depth - 1));
Namhyung Kim5ab250c2015-11-09 14:45:39 +0900160 ret += ipchain__fprintf_graph(fp, &rem_node, &rem_hits, depth,
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900161 new_depth_mask, 0, total_samples,
Namhyung Kim5ab250c2015-11-09 14:45:39 +0900162 left_margin);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900163 }
164
165 return ret;
166}
167
168static size_t callchain__fprintf_graph(FILE *fp, struct rb_root *root,
Namhyung Kim54d27b32016-01-28 00:40:52 +0900169 u64 total_samples, u64 parent_samples,
170 int left_margin)
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900171{
172 struct callchain_node *cnode;
173 struct callchain_list *chain;
174 u32 entries_printed = 0;
175 bool printed = false;
176 struct rb_node *node;
177 int i = 0;
178 int ret = 0;
Andi Kleen2989cca2014-11-12 18:05:23 -0800179 char bf[1024];
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900180
181 /*
182 * If have one single callchain root, don't bother printing
183 * its percentage (100 % in fractal mode and the same percentage
184 * than the hist in graph mode). This also avoid one level of column.
185 */
186 node = rb_first(root);
187 if (node && !rb_next(node)) {
188 cnode = rb_entry(node, struct callchain_node, rb_node);
189 list_for_each_entry(chain, &cnode->val, list) {
190 /*
191 * If we sort by symbol, the first entry is the same than
192 * the symbol. No need to print it otherwise it appears as
193 * displayed twice.
194 */
Namhyung Kimcfaa1542014-05-19 14:19:30 +0900195 if (!i++ && field_order == NULL &&
196 sort_order && !prefixcmp(sort_order, "sym"))
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900197 continue;
198 if (!printed) {
199 ret += callchain__fprintf_left_margin(fp, left_margin);
200 ret += fprintf(fp, "|\n");
201 ret += callchain__fprintf_left_margin(fp, left_margin);
202 ret += fprintf(fp, "---");
203 left_margin += 3;
204 printed = true;
205 } else
206 ret += callchain__fprintf_left_margin(fp, left_margin);
207
Andi Kleen2989cca2014-11-12 18:05:23 -0800208 ret += fprintf(fp, "%s\n", callchain_list__sym_name(chain, bf, sizeof(bf),
209 false));
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900210
211 if (++entries_printed == callchain_param.print_limit)
212 break;
213 }
214 root = &cnode->rb_root;
215 }
216
Namhyung Kim54d27b32016-01-28 00:40:52 +0900217 if (callchain_param.mode == CHAIN_GRAPH_REL)
218 total_samples = parent_samples;
219
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900220 ret += __callchain__fprintf_graph(fp, root, total_samples,
221 1, 1, left_margin);
222 ret += fprintf(fp, "\n");
223
224 return ret;
225}
226
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -0300227static size_t __callchain__fprintf_flat(FILE *fp, struct callchain_node *node,
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900228 u64 total_samples)
229{
230 struct callchain_list *chain;
231 size_t ret = 0;
Andi Kleen2989cca2014-11-12 18:05:23 -0800232 char bf[1024];
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900233
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -0300234 if (!node)
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900235 return 0;
236
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -0300237 ret += __callchain__fprintf_flat(fp, node->parent, total_samples);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900238
239
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -0300240 list_for_each_entry(chain, &node->val, list) {
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900241 if (chain->ip >= PERF_CONTEXT_MAX)
242 continue;
Andi Kleen2989cca2014-11-12 18:05:23 -0800243 ret += fprintf(fp, " %s\n", callchain_list__sym_name(chain,
244 bf, sizeof(bf), false));
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900245 }
246
247 return ret;
248}
249
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -0300250static size_t callchain__fprintf_flat(FILE *fp, struct rb_root *tree,
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900251 u64 total_samples)
252{
253 size_t ret = 0;
254 u32 entries_printed = 0;
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900255 struct callchain_node *chain;
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -0300256 struct rb_node *rb_node = rb_first(tree);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900257
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900258 while (rb_node) {
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900259 chain = rb_entry(rb_node, struct callchain_node, rb_node);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900260
Namhyung Kim5ab250c2015-11-09 14:45:39 +0900261 ret += fprintf(fp, " ");
262 ret += callchain_node__fprintf_value(chain, fp, total_samples);
263 ret += fprintf(fp, "\n");
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900264 ret += __callchain__fprintf_flat(fp, chain, total_samples);
265 ret += fprintf(fp, "\n");
266 if (++entries_printed == callchain_param.print_limit)
267 break;
268
269 rb_node = rb_next(rb_node);
270 }
271
272 return ret;
273}
274
Namhyung Kim26e77922015-11-09 14:45:37 +0900275static size_t __callchain__fprintf_folded(FILE *fp, struct callchain_node *node)
276{
277 const char *sep = symbol_conf.field_sep ?: ";";
278 struct callchain_list *chain;
279 size_t ret = 0;
280 char bf[1024];
281 bool first;
282
283 if (!node)
284 return 0;
285
286 ret += __callchain__fprintf_folded(fp, node->parent);
287
288 first = (ret == 0);
289 list_for_each_entry(chain, &node->val, list) {
290 if (chain->ip >= PERF_CONTEXT_MAX)
291 continue;
292 ret += fprintf(fp, "%s%s", first ? "" : sep,
293 callchain_list__sym_name(chain,
294 bf, sizeof(bf), false));
295 first = false;
296 }
297
298 return ret;
299}
300
301static size_t callchain__fprintf_folded(FILE *fp, struct rb_root *tree,
302 u64 total_samples)
303{
304 size_t ret = 0;
305 u32 entries_printed = 0;
306 struct callchain_node *chain;
307 struct rb_node *rb_node = rb_first(tree);
308
309 while (rb_node) {
Namhyung Kim26e77922015-11-09 14:45:37 +0900310
311 chain = rb_entry(rb_node, struct callchain_node, rb_node);
Namhyung Kim26e77922015-11-09 14:45:37 +0900312
Namhyung Kim5ab250c2015-11-09 14:45:39 +0900313 ret += callchain_node__fprintf_value(chain, fp, total_samples);
314 ret += fprintf(fp, " ");
Namhyung Kim26e77922015-11-09 14:45:37 +0900315 ret += __callchain__fprintf_folded(fp, chain);
316 ret += fprintf(fp, "\n");
317 if (++entries_printed == callchain_param.print_limit)
318 break;
319
320 rb_node = rb_next(rb_node);
321 }
322
323 return ret;
324}
325
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900326static size_t hist_entry_callchain__fprintf(struct hist_entry *he,
327 u64 total_samples, int left_margin,
328 FILE *fp)
329{
Namhyung Kim54d27b32016-01-28 00:40:52 +0900330 u64 parent_samples = he->stat.period;
331
332 if (symbol_conf.cumulate_callchain)
333 parent_samples = he->stat_acc->period;
334
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900335 switch (callchain_param.mode) {
336 case CHAIN_GRAPH_REL:
Namhyung Kim54d27b32016-01-28 00:40:52 +0900337 return callchain__fprintf_graph(fp, &he->sorted_chain, total_samples,
338 parent_samples, left_margin);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900339 break;
340 case CHAIN_GRAPH_ABS:
341 return callchain__fprintf_graph(fp, &he->sorted_chain, total_samples,
Namhyung Kim54d27b32016-01-28 00:40:52 +0900342 parent_samples, left_margin);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900343 break;
344 case CHAIN_FLAT:
345 return callchain__fprintf_flat(fp, &he->sorted_chain, total_samples);
346 break;
Namhyung Kim26e77922015-11-09 14:45:37 +0900347 case CHAIN_FOLDED:
348 return callchain__fprintf_folded(fp, &he->sorted_chain, total_samples);
349 break;
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900350 case CHAIN_NONE:
351 break;
352 default:
353 pr_err("Bad callchain mode\n");
354 }
355
356 return 0;
357}
358
Namhyung Kim26d8b332014-03-03 16:16:20 +0900359static int hist_entry__snprintf(struct hist_entry *he, struct perf_hpp *hpp)
Jiri Olsabe0e6d12013-02-04 16:33:19 +0100360{
361 const char *sep = symbol_conf.field_sep;
362 struct perf_hpp_fmt *fmt;
363 char *start = hpp->buf;
364 int ret;
365 bool first = true;
366
367 if (symbol_conf.exclude_other && !he->parent)
368 return 0;
369
370 perf_hpp__for_each_format(fmt) {
Namhyung Kim361459f2015-12-23 02:07:08 +0900371 if (perf_hpp__should_skip(fmt, he->hists))
Namhyung Kime67d49a2014-03-18 13:00:59 +0900372 continue;
373
Jiri Olsabe0e6d12013-02-04 16:33:19 +0100374 /*
375 * If there's no field_sep, we still need
376 * to display initial ' '.
377 */
378 if (!sep || !first) {
379 ret = scnprintf(hpp->buf, hpp->size, "%s", sep ?: " ");
380 advance_hpp(hpp, ret);
381 } else
382 first = false;
383
Jiri Olsa9754c4f2013-10-25 13:24:53 +0200384 if (perf_hpp__use_color() && fmt->color)
Jiri Olsabe0e6d12013-02-04 16:33:19 +0100385 ret = fmt->color(fmt, hpp, he);
386 else
387 ret = fmt->entry(fmt, hpp, he);
388
389 advance_hpp(hpp, ret);
390 }
391
392 return hpp->buf - start;
393}
394
Namhyung Kim000078b2012-08-20 13:52:06 +0900395static int hist_entry__fprintf(struct hist_entry *he, size_t size,
Arnaldo Carvalho de Melo99cf6662013-09-05 15:39:12 -0300396 struct hists *hists,
397 char *bf, size_t bfsz, FILE *fp)
Namhyung Kim000078b2012-08-20 13:52:06 +0900398{
Namhyung Kim000078b2012-08-20 13:52:06 +0900399 int ret;
Namhyung Kimea251d52012-09-03 11:53:06 +0900400 struct perf_hpp hpp = {
401 .buf = bf,
402 .size = size,
Namhyung Kimea251d52012-09-03 11:53:06 +0900403 };
Namhyung Kim7e597d32016-01-28 00:40:51 +0900404 u64 total_period = hists->stats.total_period;
Namhyung Kim000078b2012-08-20 13:52:06 +0900405
Arnaldo Carvalho de Melo99cf6662013-09-05 15:39:12 -0300406 if (size == 0 || size > bfsz)
407 size = hpp.size = bfsz;
Namhyung Kim000078b2012-08-20 13:52:06 +0900408
Namhyung Kim26d8b332014-03-03 16:16:20 +0900409 hist_entry__snprintf(he, &hpp);
Namhyung Kim000078b2012-08-20 13:52:06 +0900410
411 ret = fprintf(fp, "%s\n", bf);
412
413 if (symbol_conf.use_callchain)
Namhyung Kim7e597d32016-01-28 00:40:51 +0900414 ret += hist_entry_callchain__fprintf(he, total_period, 0, fp);
Namhyung Kim000078b2012-08-20 13:52:06 +0900415
416 return ret;
417}
418
Jiri Olsa41724e42012-10-04 21:49:38 +0900419size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
Namhyung Kim064f1982013-05-14 11:09:04 +0900420 int max_cols, float min_pcnt, FILE *fp)
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900421{
Jiri Olsa12400052012-10-13 00:06:16 +0200422 struct perf_hpp_fmt *fmt;
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900423 struct rb_node *nd;
424 size_t ret = 0;
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900425 unsigned int width;
426 const char *sep = symbol_conf.field_sep;
Jiri Olsa12400052012-10-13 00:06:16 +0200427 int nr_rows = 0;
Jiri Olsaed279da2012-10-05 16:44:45 +0200428 char bf[96];
Namhyung Kimea251d52012-09-03 11:53:06 +0900429 struct perf_hpp dummy_hpp = {
430 .buf = bf,
431 .size = sizeof(bf),
Namhyung Kimea251d52012-09-03 11:53:06 +0900432 };
Jiri Olsa5395a042012-10-04 21:49:37 +0900433 bool first = true;
Arnaldo Carvalho de Melo99cf6662013-09-05 15:39:12 -0300434 size_t linesz;
435 char *line = NULL;
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900436
437 init_rem_hits();
438
Namhyung Kim678a5002014-03-20 11:18:54 +0900439 perf_hpp__for_each_format(fmt)
440 perf_hpp__reset_width(fmt, hists);
Namhyung Kim26d8b332014-03-03 16:16:20 +0900441
Namhyung Kim5b591662014-07-31 14:47:38 +0900442 if (symbol_conf.col_width_list_str)
443 perf_hpp__set_user_width(symbol_conf.col_width_list_str);
444
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900445 if (!show_header)
446 goto print_entries;
447
Namhyung Kimea251d52012-09-03 11:53:06 +0900448 fprintf(fp, "# ");
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900449
Jiri Olsa12400052012-10-13 00:06:16 +0200450 perf_hpp__for_each_format(fmt) {
Namhyung Kim361459f2015-12-23 02:07:08 +0900451 if (perf_hpp__should_skip(fmt, hists))
Namhyung Kime67d49a2014-03-18 13:00:59 +0900452 continue;
453
Jiri Olsa5395a042012-10-04 21:49:37 +0900454 if (!first)
Namhyung Kimea251d52012-09-03 11:53:06 +0900455 fprintf(fp, "%s", sep ?: " ");
Jiri Olsa5395a042012-10-04 21:49:37 +0900456 else
457 first = false;
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900458
Namhyung Kim94a07932014-03-10 16:43:52 +0900459 fmt->header(fmt, &dummy_hpp, hists_to_evsel(hists));
Namhyung Kimea251d52012-09-03 11:53:06 +0900460 fprintf(fp, "%s", bf);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900461 }
462
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900463 fprintf(fp, "\n");
464 if (max_rows && ++nr_rows >= max_rows)
465 goto out;
466
467 if (sep)
468 goto print_entries;
469
Jiri Olsa5395a042012-10-04 21:49:37 +0900470 first = true;
471
Namhyung Kimea251d52012-09-03 11:53:06 +0900472 fprintf(fp, "# ");
Namhyung Kimea251d52012-09-03 11:53:06 +0900473
Jiri Olsa12400052012-10-13 00:06:16 +0200474 perf_hpp__for_each_format(fmt) {
475 unsigned int i;
Namhyung Kimea251d52012-09-03 11:53:06 +0900476
Namhyung Kim361459f2015-12-23 02:07:08 +0900477 if (perf_hpp__should_skip(fmt, hists))
Namhyung Kime67d49a2014-03-18 13:00:59 +0900478 continue;
479
Jiri Olsa5395a042012-10-04 21:49:37 +0900480 if (!first)
Namhyung Kimea251d52012-09-03 11:53:06 +0900481 fprintf(fp, "%s", sep ?: " ");
Jiri Olsa5395a042012-10-04 21:49:37 +0900482 else
483 first = false;
Namhyung Kimea251d52012-09-03 11:53:06 +0900484
Namhyung Kim94a07932014-03-10 16:43:52 +0900485 width = fmt->width(fmt, &dummy_hpp, hists_to_evsel(hists));
Namhyung Kimea251d52012-09-03 11:53:06 +0900486 for (i = 0; i < width; i++)
487 fprintf(fp, ".");
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900488 }
Namhyung Kimea251d52012-09-03 11:53:06 +0900489
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900490 fprintf(fp, "\n");
491 if (max_rows && ++nr_rows >= max_rows)
492 goto out;
493
494 fprintf(fp, "#\n");
495 if (max_rows && ++nr_rows >= max_rows)
496 goto out;
497
498print_entries:
Arnaldo Carvalho de Melo99cf6662013-09-05 15:39:12 -0300499 linesz = hists__sort_list_width(hists) + 3 + 1;
Jiri Olsa9754c4f2013-10-25 13:24:53 +0200500 linesz += perf_hpp__color_overhead();
Arnaldo Carvalho de Melo99cf6662013-09-05 15:39:12 -0300501 line = malloc(linesz);
502 if (line == NULL) {
503 ret = -1;
504 goto out;
505 }
506
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900507 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
508 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
Namhyung Kim14135662013-10-31 10:17:39 +0900509 float percent;
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900510
511 if (h->filtered)
512 continue;
513
Namhyung Kim14135662013-10-31 10:17:39 +0900514 percent = hist_entry__get_percent_limit(h);
Namhyung Kim064f1982013-05-14 11:09:04 +0900515 if (percent < min_pcnt)
516 continue;
517
Arnaldo Carvalho de Melo99cf6662013-09-05 15:39:12 -0300518 ret += hist_entry__fprintf(h, max_cols, hists, line, linesz, fp);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900519
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900520 if (max_rows && ++nr_rows >= max_rows)
Arnaldo Carvalho de Melo99cf6662013-09-05 15:39:12 -0300521 break;
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900522
523 if (h->ms.map == NULL && verbose > 1) {
Arnaldo Carvalho de Melo93d57312014-03-21 17:57:01 -0300524 __map_groups__fprintf_maps(h->thread->mg,
Jiri Olsaacebd402014-07-14 23:46:47 +0200525 MAP__FUNCTION, fp);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900526 fprintf(fp, "%.10s end\n", graph_dotted_line);
527 }
528 }
Arnaldo Carvalho de Melo99cf6662013-09-05 15:39:12 -0300529
530 free(line);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900531out:
Arnaldo Carvalho de Melo74cf2492013-12-27 16:55:14 -0300532 zfree(&rem_sq_bracket);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900533
534 return ret;
535}
536
Arnaldo Carvalho de Melo52168ee2012-12-18 16:02:17 -0300537size_t events_stats__fprintf(struct events_stats *stats, FILE *fp)
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900538{
539 int i;
540 size_t ret = 0;
541
542 for (i = 0; i < PERF_RECORD_HEADER_MAX; ++i) {
543 const char *name;
544
Arnaldo Carvalho de Melo52168ee2012-12-18 16:02:17 -0300545 if (stats->nr_events[i] == 0)
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900546 continue;
547
548 name = perf_event__name(i);
549 if (!strcmp(name, "UNKNOWN"))
550 continue;
551
552 ret += fprintf(fp, "%16s events: %10d\n", name,
Arnaldo Carvalho de Melo52168ee2012-12-18 16:02:17 -0300553 stats->nr_events[i]);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900554 }
555
556 return ret;
557}