blob: ea7984932d9a74daf21f8a6db77bc7add34082cc [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
37static 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;
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) {
53 double percent;
54
55 percent = hits * 100.0 / total_samples;
56 ret += percent_color_fprintf(fp, "--%2.2f%%-- ", percent);
57 } else
58 ret += fprintf(fp, "%s", " ");
59 }
Andi Kleen2989cca2014-11-12 18:05:23 -080060 fputs(callchain_list__sym_name(chain, bf, sizeof(bf), false), fp);
61 fputc('\n', fp);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +090062 return ret;
63}
64
65static struct symbol *rem_sq_bracket;
66static struct callchain_list rem_hits;
67
68static void init_rem_hits(void)
69{
70 rem_sq_bracket = malloc(sizeof(*rem_sq_bracket) + 6);
71 if (!rem_sq_bracket) {
72 fprintf(stderr, "Not enough memory to display remaining hits\n");
73 return;
74 }
75
76 strcpy(rem_sq_bracket->name, "[...]");
77 rem_hits.ms.sym = rem_sq_bracket;
78}
79
80static size_t __callchain__fprintf_graph(FILE *fp, struct rb_root *root,
81 u64 total_samples, int depth,
82 int depth_mask, int left_margin)
83{
84 struct rb_node *node, *next;
85 struct callchain_node *child;
86 struct callchain_list *chain;
87 int new_depth_mask = depth_mask;
88 u64 remaining;
89 size_t ret = 0;
90 int i;
91 uint entries_printed = 0;
92
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;
103
104 /*
105 * The depth mask manages the output of pipes that show
106 * the depth. We don't want to keep the pipes of the current
107 * level for the last child of this depth.
108 * Except if we have remaining filtered hits. They will
109 * supersede the last child
110 */
111 next = rb_next(node);
112 if (!next && (callchain_param.mode != CHAIN_GRAPH_REL || !remaining))
113 new_depth_mask &= ~(1 << (depth - 1));
114
115 /*
116 * But we keep the older depth mask for the line separator
117 * to keep the level link until we reach the last child
118 */
119 ret += ipchain__fprintf_graph_line(fp, depth, depth_mask,
120 left_margin);
121 i = 0;
122 list_for_each_entry(chain, &child->val, list) {
123 ret += ipchain__fprintf_graph(fp, chain, depth,
124 new_depth_mask, i++,
125 total_samples,
126 cumul,
127 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) {
146
147 if (!rem_sq_bracket)
148 return ret;
149
150 new_depth_mask &= ~(1 << (depth - 1));
151 ret += ipchain__fprintf_graph(fp, &rem_hits, depth,
152 new_depth_mask, 0, total_samples,
153 remaining, left_margin);
154 }
155
156 return ret;
157}
158
159static size_t callchain__fprintf_graph(FILE *fp, struct rb_root *root,
160 u64 total_samples, int left_margin)
161{
162 struct callchain_node *cnode;
163 struct callchain_list *chain;
164 u32 entries_printed = 0;
165 bool printed = false;
166 struct rb_node *node;
167 int i = 0;
168 int ret = 0;
Andi Kleen2989cca2014-11-12 18:05:23 -0800169 char bf[1024];
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900170
171 /*
172 * If have one single callchain root, don't bother printing
173 * its percentage (100 % in fractal mode and the same percentage
174 * than the hist in graph mode). This also avoid one level of column.
175 */
176 node = rb_first(root);
177 if (node && !rb_next(node)) {
178 cnode = rb_entry(node, struct callchain_node, rb_node);
179 list_for_each_entry(chain, &cnode->val, list) {
180 /*
181 * If we sort by symbol, the first entry is the same than
182 * the symbol. No need to print it otherwise it appears as
183 * displayed twice.
184 */
Namhyung Kimcfaa1542014-05-19 14:19:30 +0900185 if (!i++ && field_order == NULL &&
186 sort_order && !prefixcmp(sort_order, "sym"))
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900187 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
Andi Kleen2989cca2014-11-12 18:05:23 -0800198 ret += fprintf(fp, "%s\n", callchain_list__sym_name(chain, bf, sizeof(bf),
199 false));
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900200
201 if (++entries_printed == callchain_param.print_limit)
202 break;
203 }
204 root = &cnode->rb_root;
205 }
206
207 ret += __callchain__fprintf_graph(fp, root, total_samples,
208 1, 1, left_margin);
209 ret += fprintf(fp, "\n");
210
211 return ret;
212}
213
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -0300214static size_t __callchain__fprintf_flat(FILE *fp, struct callchain_node *node,
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900215 u64 total_samples)
216{
217 struct callchain_list *chain;
218 size_t ret = 0;
Andi Kleen2989cca2014-11-12 18:05:23 -0800219 char bf[1024];
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900220
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -0300221 if (!node)
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900222 return 0;
223
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -0300224 ret += __callchain__fprintf_flat(fp, node->parent, total_samples);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900225
226
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -0300227 list_for_each_entry(chain, &node->val, list) {
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900228 if (chain->ip >= PERF_CONTEXT_MAX)
229 continue;
Andi Kleen2989cca2014-11-12 18:05:23 -0800230 ret += fprintf(fp, " %s\n", callchain_list__sym_name(chain,
231 bf, sizeof(bf), false));
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900232 }
233
234 return ret;
235}
236
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -0300237static size_t callchain__fprintf_flat(FILE *fp, struct rb_root *tree,
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900238 u64 total_samples)
239{
240 size_t ret = 0;
241 u32 entries_printed = 0;
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900242 struct callchain_node *chain;
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -0300243 struct rb_node *rb_node = rb_first(tree);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900244
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900245 while (rb_node) {
246 double percent;
247
248 chain = rb_entry(rb_node, struct callchain_node, rb_node);
249 percent = chain->hit * 100.0 / total_samples;
250
251 ret = percent_color_fprintf(fp, " %6.2f%%\n", percent);
252 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) {
298 double percent;
299
300 chain = rb_entry(rb_node, struct callchain_node, rb_node);
301 percent = chain->hit * 100.0 / total_samples;
302
303 ret += fprintf(fp, "%.2f%% ", percent);
304 ret += __callchain__fprintf_folded(fp, chain);
305 ret += fprintf(fp, "\n");
306 if (++entries_printed == callchain_param.print_limit)
307 break;
308
309 rb_node = rb_next(rb_node);
310 }
311
312 return ret;
313}
314
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900315static size_t hist_entry_callchain__fprintf(struct hist_entry *he,
316 u64 total_samples, int left_margin,
317 FILE *fp)
318{
319 switch (callchain_param.mode) {
320 case CHAIN_GRAPH_REL:
Namhyung Kim56772ad2014-05-23 18:31:52 +0900321 return callchain__fprintf_graph(fp, &he->sorted_chain,
322 symbol_conf.cumulate_callchain ?
323 he->stat_acc->period : he->stat.period,
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900324 left_margin);
325 break;
326 case CHAIN_GRAPH_ABS:
327 return callchain__fprintf_graph(fp, &he->sorted_chain, total_samples,
328 left_margin);
329 break;
330 case CHAIN_FLAT:
331 return callchain__fprintf_flat(fp, &he->sorted_chain, total_samples);
332 break;
Namhyung Kim26e77922015-11-09 14:45:37 +0900333 case CHAIN_FOLDED:
334 return callchain__fprintf_folded(fp, &he->sorted_chain, total_samples);
335 break;
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900336 case CHAIN_NONE:
337 break;
338 default:
339 pr_err("Bad callchain mode\n");
340 }
341
342 return 0;
343}
344
Namhyung Kim000078b2012-08-20 13:52:06 +0900345static size_t hist_entry__callchain_fprintf(struct hist_entry *he,
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900346 struct hists *hists,
Jiri Olsab5ff71c2012-10-04 21:49:40 +0900347 FILE *fp)
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900348{
349 int left_margin = 0;
Jiri Olsab5ff71c2012-10-04 21:49:40 +0900350 u64 total_period = hists->stats.total_period;
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900351
Namhyung Kimcfaa1542014-05-19 14:19:30 +0900352 if (field_order == NULL && (sort_order == NULL ||
353 !prefixcmp(sort_order, "comm"))) {
354 struct perf_hpp_fmt *fmt;
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900355
Namhyung Kimcfaa1542014-05-19 14:19:30 +0900356 perf_hpp__for_each_format(fmt) {
357 if (!perf_hpp__is_sort_entry(fmt))
358 continue;
359
360 /* must be 'comm' sort entry */
361 left_margin = fmt->width(fmt, NULL, hists_to_evsel(hists));
362 left_margin -= thread__comm_len(he->thread);
363 break;
364 }
365 }
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900366 return hist_entry_callchain__fprintf(he, total_period, left_margin, fp);
367}
368
Namhyung Kim26d8b332014-03-03 16:16:20 +0900369static int hist_entry__snprintf(struct hist_entry *he, struct perf_hpp *hpp)
Jiri Olsabe0e6d12013-02-04 16:33:19 +0100370{
371 const char *sep = symbol_conf.field_sep;
372 struct perf_hpp_fmt *fmt;
373 char *start = hpp->buf;
374 int ret;
375 bool first = true;
376
377 if (symbol_conf.exclude_other && !he->parent)
378 return 0;
379
380 perf_hpp__for_each_format(fmt) {
Namhyung Kime67d49a2014-03-18 13:00:59 +0900381 if (perf_hpp__should_skip(fmt))
382 continue;
383
Jiri Olsabe0e6d12013-02-04 16:33:19 +0100384 /*
385 * If there's no field_sep, we still need
386 * to display initial ' '.
387 */
388 if (!sep || !first) {
389 ret = scnprintf(hpp->buf, hpp->size, "%s", sep ?: " ");
390 advance_hpp(hpp, ret);
391 } else
392 first = false;
393
Jiri Olsa9754c4f2013-10-25 13:24:53 +0200394 if (perf_hpp__use_color() && fmt->color)
Jiri Olsabe0e6d12013-02-04 16:33:19 +0100395 ret = fmt->color(fmt, hpp, he);
396 else
397 ret = fmt->entry(fmt, hpp, he);
398
399 advance_hpp(hpp, ret);
400 }
401
402 return hpp->buf - start;
403}
404
Namhyung Kim000078b2012-08-20 13:52:06 +0900405static int hist_entry__fprintf(struct hist_entry *he, size_t size,
Arnaldo Carvalho de Melo99cf6662013-09-05 15:39:12 -0300406 struct hists *hists,
407 char *bf, size_t bfsz, FILE *fp)
Namhyung Kim000078b2012-08-20 13:52:06 +0900408{
Namhyung Kim000078b2012-08-20 13:52:06 +0900409 int ret;
Namhyung Kimea251d52012-09-03 11:53:06 +0900410 struct perf_hpp hpp = {
411 .buf = bf,
412 .size = size,
Namhyung Kimea251d52012-09-03 11:53:06 +0900413 };
Namhyung Kim000078b2012-08-20 13:52:06 +0900414
Arnaldo Carvalho de Melo99cf6662013-09-05 15:39:12 -0300415 if (size == 0 || size > bfsz)
416 size = hpp.size = bfsz;
Namhyung Kim000078b2012-08-20 13:52:06 +0900417
Namhyung Kim26d8b332014-03-03 16:16:20 +0900418 hist_entry__snprintf(he, &hpp);
Namhyung Kim000078b2012-08-20 13:52:06 +0900419
420 ret = fprintf(fp, "%s\n", bf);
421
422 if (symbol_conf.use_callchain)
Jiri Olsab5ff71c2012-10-04 21:49:40 +0900423 ret += hist_entry__callchain_fprintf(he, hists, fp);
Namhyung Kim000078b2012-08-20 13:52:06 +0900424
425 return ret;
426}
427
Jiri Olsa41724e42012-10-04 21:49:38 +0900428size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
Namhyung Kim064f1982013-05-14 11:09:04 +0900429 int max_cols, float min_pcnt, FILE *fp)
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900430{
Jiri Olsa12400052012-10-13 00:06:16 +0200431 struct perf_hpp_fmt *fmt;
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900432 struct rb_node *nd;
433 size_t ret = 0;
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900434 unsigned int width;
435 const char *sep = symbol_conf.field_sep;
Jiri Olsa12400052012-10-13 00:06:16 +0200436 int nr_rows = 0;
Jiri Olsaed279da2012-10-05 16:44:45 +0200437 char bf[96];
Namhyung Kimea251d52012-09-03 11:53:06 +0900438 struct perf_hpp dummy_hpp = {
439 .buf = bf,
440 .size = sizeof(bf),
Namhyung Kimea251d52012-09-03 11:53:06 +0900441 };
Jiri Olsa5395a042012-10-04 21:49:37 +0900442 bool first = true;
Arnaldo Carvalho de Melo99cf6662013-09-05 15:39:12 -0300443 size_t linesz;
444 char *line = NULL;
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900445
446 init_rem_hits();
447
Namhyung Kim678a5002014-03-20 11:18:54 +0900448 perf_hpp__for_each_format(fmt)
449 perf_hpp__reset_width(fmt, hists);
Namhyung Kim26d8b332014-03-03 16:16:20 +0900450
Namhyung Kim5b591662014-07-31 14:47:38 +0900451 if (symbol_conf.col_width_list_str)
452 perf_hpp__set_user_width(symbol_conf.col_width_list_str);
453
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900454 if (!show_header)
455 goto print_entries;
456
Namhyung Kimea251d52012-09-03 11:53:06 +0900457 fprintf(fp, "# ");
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900458
Jiri Olsa12400052012-10-13 00:06:16 +0200459 perf_hpp__for_each_format(fmt) {
Namhyung Kime67d49a2014-03-18 13:00:59 +0900460 if (perf_hpp__should_skip(fmt))
461 continue;
462
Jiri Olsa5395a042012-10-04 21:49:37 +0900463 if (!first)
Namhyung Kimea251d52012-09-03 11:53:06 +0900464 fprintf(fp, "%s", sep ?: " ");
Jiri Olsa5395a042012-10-04 21:49:37 +0900465 else
466 first = false;
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900467
Namhyung Kim94a07932014-03-10 16:43:52 +0900468 fmt->header(fmt, &dummy_hpp, hists_to_evsel(hists));
Namhyung Kimea251d52012-09-03 11:53:06 +0900469 fprintf(fp, "%s", bf);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900470 }
471
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900472 fprintf(fp, "\n");
473 if (max_rows && ++nr_rows >= max_rows)
474 goto out;
475
476 if (sep)
477 goto print_entries;
478
Jiri Olsa5395a042012-10-04 21:49:37 +0900479 first = true;
480
Namhyung Kimea251d52012-09-03 11:53:06 +0900481 fprintf(fp, "# ");
Namhyung Kimea251d52012-09-03 11:53:06 +0900482
Jiri Olsa12400052012-10-13 00:06:16 +0200483 perf_hpp__for_each_format(fmt) {
484 unsigned int i;
Namhyung Kimea251d52012-09-03 11:53:06 +0900485
Namhyung Kime67d49a2014-03-18 13:00:59 +0900486 if (perf_hpp__should_skip(fmt))
487 continue;
488
Jiri Olsa5395a042012-10-04 21:49:37 +0900489 if (!first)
Namhyung Kimea251d52012-09-03 11:53:06 +0900490 fprintf(fp, "%s", sep ?: " ");
Jiri Olsa5395a042012-10-04 21:49:37 +0900491 else
492 first = false;
Namhyung Kimea251d52012-09-03 11:53:06 +0900493
Namhyung Kim94a07932014-03-10 16:43:52 +0900494 width = fmt->width(fmt, &dummy_hpp, hists_to_evsel(hists));
Namhyung Kimea251d52012-09-03 11:53:06 +0900495 for (i = 0; i < width; i++)
496 fprintf(fp, ".");
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900497 }
Namhyung Kimea251d52012-09-03 11:53:06 +0900498
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900499 fprintf(fp, "\n");
500 if (max_rows && ++nr_rows >= max_rows)
501 goto out;
502
503 fprintf(fp, "#\n");
504 if (max_rows && ++nr_rows >= max_rows)
505 goto out;
506
507print_entries:
Arnaldo Carvalho de Melo99cf6662013-09-05 15:39:12 -0300508 linesz = hists__sort_list_width(hists) + 3 + 1;
Jiri Olsa9754c4f2013-10-25 13:24:53 +0200509 linesz += perf_hpp__color_overhead();
Arnaldo Carvalho de Melo99cf6662013-09-05 15:39:12 -0300510 line = malloc(linesz);
511 if (line == NULL) {
512 ret = -1;
513 goto out;
514 }
515
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900516 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
517 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
Namhyung Kim14135662013-10-31 10:17:39 +0900518 float percent;
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900519
520 if (h->filtered)
521 continue;
522
Namhyung Kim14135662013-10-31 10:17:39 +0900523 percent = hist_entry__get_percent_limit(h);
Namhyung Kim064f1982013-05-14 11:09:04 +0900524 if (percent < min_pcnt)
525 continue;
526
Arnaldo Carvalho de Melo99cf6662013-09-05 15:39:12 -0300527 ret += hist_entry__fprintf(h, max_cols, hists, line, linesz, fp);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900528
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900529 if (max_rows && ++nr_rows >= max_rows)
Arnaldo Carvalho de Melo99cf6662013-09-05 15:39:12 -0300530 break;
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900531
532 if (h->ms.map == NULL && verbose > 1) {
Arnaldo Carvalho de Melo93d57312014-03-21 17:57:01 -0300533 __map_groups__fprintf_maps(h->thread->mg,
Jiri Olsaacebd402014-07-14 23:46:47 +0200534 MAP__FUNCTION, fp);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900535 fprintf(fp, "%.10s end\n", graph_dotted_line);
536 }
537 }
Arnaldo Carvalho de Melo99cf6662013-09-05 15:39:12 -0300538
539 free(line);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900540out:
Arnaldo Carvalho de Melo74cf2492013-12-27 16:55:14 -0300541 zfree(&rem_sq_bracket);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900542
543 return ret;
544}
545
Arnaldo Carvalho de Melo52168ee2012-12-18 16:02:17 -0300546size_t events_stats__fprintf(struct events_stats *stats, FILE *fp)
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900547{
548 int i;
549 size_t ret = 0;
550
551 for (i = 0; i < PERF_RECORD_HEADER_MAX; ++i) {
552 const char *name;
553
Arnaldo Carvalho de Melo52168ee2012-12-18 16:02:17 -0300554 if (stats->nr_events[i] == 0)
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900555 continue;
556
557 name = perf_event__name(i);
558 if (!strcmp(name, "UNKNOWN"))
559 continue;
560
561 ret += fprintf(fp, "%16s events: %10d\n", name,
Arnaldo Carvalho de Melo52168ee2012-12-18 16:02:17 -0300562 stats->nr_events[i]);
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900563 }
564
565 return ret;
566}