3 #include "../../util/util.h"
4 #include "../../util/hist.h"
5 #include "../../util/sort.h"
8 static size_t callchain__fprintf_left_margin(FILE *
fp,
int left_margin)
13 for (i = 0; i < left_margin; i++)
19 static size_t ipchain__fprintf_graph_line(FILE *fp,
int depth,
int depth_mask,
23 size_t ret = callchain__fprintf_left_margin(fp, left_margin);
25 for (i = 0; i <
depth; i++)
26 if (depth_mask & (1 << i))
37 int depth,
int depth_mask,
int period,
38 u64 total_samples,
u64 hits,
44 ret += callchain__fprintf_left_margin(fp, left_margin);
45 for (i = 0; i <
depth; i++) {
46 if (depth_mask & (1 << i))
50 if (!period && i == depth - 1) {
53 percent = hits * 100.0 / total_samples;
59 ret +=
fprintf(fp,
"%s\n", chain->
ms.sym->name);
66 static struct symbol *rem_sq_bracket;
69 static void init_rem_hits(
void)
71 rem_sq_bracket =
malloc(
sizeof(*rem_sq_bracket) + 6);
72 if (!rem_sq_bracket) {
73 fprintf(stderr,
"Not enough memory to display remaining hits\n");
78 rem_hits.ms.sym = rem_sq_bracket;
81 static size_t __callchain__fprintf_graph(FILE *fp,
struct rb_root *root,
82 u64 total_samples,
int depth,
83 int depth_mask,
int left_margin)
88 int new_depth_mask = depth_mask;
92 uint entries_printed = 0;
94 remaining = total_samples;
102 cumul = callchain_cumul_hits(child);
114 new_depth_mask &= ~(1 << (depth - 1));
120 ret += ipchain__fprintf_graph_line(fp, depth, depth_mask,
124 ret += ipchain__fprintf_graph(fp, chain, depth,
134 new_total = total_samples;
136 ret += __callchain__fprintf_graph(fp, &child->
rb_root, new_total,
138 new_depth_mask | (1 << depth),
146 remaining && remaining != total_samples) {
151 new_depth_mask &= ~(1 << (depth - 1));
152 ret += ipchain__fprintf_graph(fp, &rem_hits, depth,
153 new_depth_mask, 0, total_samples,
154 remaining, left_margin);
160 static size_t callchain__fprintf_graph(FILE *fp,
struct rb_root *root,
161 u64 total_samples,
int left_margin)
165 u32 entries_printed = 0;
166 bool printed =
false;
188 ret += callchain__fprintf_left_margin(fp, left_margin);
190 ret += callchain__fprintf_left_margin(fp, left_margin);
195 ret += callchain__fprintf_left_margin(fp, left_margin);
198 ret +=
fprintf(fp,
" %s\n", chain->
ms.sym->name);
200 ret +=
fprintf(fp,
" %p\n", (
void *)(
long)chain->
ip);
208 ret += __callchain__fprintf_graph(fp, root, total_samples,
215 static size_t __callchain__fprintf_flat(FILE *fp,
225 ret += __callchain__fprintf_flat(fp, self->parent, total_samples);
232 ret +=
fprintf(fp,
" %s\n", chain->
ms.sym->name);
235 (
void *)(
long)chain->
ip);
241 static size_t callchain__fprintf_flat(FILE *fp,
struct rb_root *
self,
245 u32 entries_printed = 0;
254 percent = chain->
hit * 100.0 / total_samples;
257 ret += __callchain__fprintf_flat(fp, chain, total_samples);
268 static size_t hist_entry_callchain__fprintf(
struct hist_entry *he,
269 u64 total_samples,
int left_margin,
278 return callchain__fprintf_graph(fp, &he->
sorted_chain, total_samples,
282 return callchain__fprintf_flat(fp, &he->
sorted_chain, total_samples);
287 pr_err(
"Bad callchain mode\n");
293 static size_t hist_entry__callchain_fprintf(
struct hist_entry *he,
298 u64 total_period = hists->
stats.total_period;
307 return hist_entry_callchain__fprintf(he, total_period, left_margin, fp);
310 static int hist_entry__fprintf(
struct hist_entry *he,
size_t size,
311 struct hists *hists, FILE *fp)
321 if (size == 0 || size >
sizeof(bf))
322 size = hpp.
size =
sizeof(
bf);
330 ret += hist_entry__callchain_fprintf(he, hists, fp);
336 int max_cols, FILE *fp)
344 int idx, nr_rows = 0;
383 col_width =
strchr(col_width,
',');
394 if (max_rows && ++nr_rows >= max_rows)
415 for (i = 0; i <
width; i++)
429 for (i = 0; i <
width; i++)
434 if (max_rows && ++nr_rows >= max_rows)
438 if (max_rows && ++nr_rows >= max_rows)
448 ret += hist_entry__fprintf(h, max_cols, hists, fp);
450 if (max_rows && ++nr_rows >= max_rows)
460 free(rem_sq_bracket);
473 if (hists->
stats.nr_events[i] == 0)
477 if (!
strcmp(name,
"UNKNOWN"))
480 ret +=
fprintf(fp,
"%16s events: %10d\n", name,
481 hists->
stats.nr_events[i]);