blob: 5843a9c572ad8266e2d5690cdf9fef626601e547 [file] [log] [blame]
John Kacur3d1d07e2009-09-28 15:32:55 +02001#include "hist.h"
Arnaldo Carvalho de Melo4e4f06e2009-12-14 13:10:39 -02002#include "session.h"
3#include "sort.h"
Arnaldo Carvalho de Melo9b338272009-12-16 14:31:49 -02004#include <math.h>
John Kacur3d1d07e2009-09-28 15:32:55 +02005
6struct callchain_param callchain_param = {
7 .mode = CHAIN_GRAPH_REL,
8 .min_percent = 0.5
9};
10
John Kacur3d1d07e2009-09-28 15:32:55 +020011/*
12 * histogram, sorted on item, collects counts
13 */
14
Eric B Munsond403d0a2010-03-05 12:51:06 -030015struct hist_entry *__perf_session__add_hist_entry(struct rb_root *hists,
Arnaldo Carvalho de Melo4e4f06e2009-12-14 13:10:39 -020016 struct addr_location *al,
17 struct symbol *sym_parent,
18 u64 count, bool *hit)
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -030019{
Eric B Munsond403d0a2010-03-05 12:51:06 -030020 struct rb_node **p = &hists->rb_node;
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -030021 struct rb_node *parent = NULL;
22 struct hist_entry *he;
23 struct hist_entry entry = {
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -020024 .thread = al->thread,
25 .map = al->map,
26 .sym = al->sym,
27 .ip = al->addr,
28 .level = al->level,
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -030029 .count = count,
30 .parent = sym_parent,
31 };
32 int cmp;
33
34 while (*p != NULL) {
35 parent = *p;
36 he = rb_entry(parent, struct hist_entry, rb_node);
37
38 cmp = hist_entry__cmp(&entry, he);
39
40 if (!cmp) {
41 *hit = true;
42 return he;
43 }
44
45 if (cmp < 0)
46 p = &(*p)->rb_left;
47 else
48 p = &(*p)->rb_right;
49 }
50
51 he = malloc(sizeof(*he));
52 if (!he)
53 return NULL;
54 *he = entry;
55 rb_link_node(&he->rb_node, parent, p);
Eric B Munsond403d0a2010-03-05 12:51:06 -030056 rb_insert_color(&he->rb_node, hists);
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -030057 *hit = false;
58 return he;
59}
60
John Kacur3d1d07e2009-09-28 15:32:55 +020061int64_t
62hist_entry__cmp(struct hist_entry *left, struct hist_entry *right)
63{
64 struct sort_entry *se;
65 int64_t cmp = 0;
66
67 list_for_each_entry(se, &hist_entry__sort_list, list) {
68 cmp = se->cmp(left, right);
69 if (cmp)
70 break;
71 }
72
73 return cmp;
74}
75
76int64_t
77hist_entry__collapse(struct hist_entry *left, struct hist_entry *right)
78{
79 struct sort_entry *se;
80 int64_t cmp = 0;
81
82 list_for_each_entry(se, &hist_entry__sort_list, list) {
83 int64_t (*f)(struct hist_entry *, struct hist_entry *);
84
85 f = se->collapse ?: se->cmp;
86
87 cmp = f(left, right);
88 if (cmp)
89 break;
90 }
91
92 return cmp;
93}
94
95void hist_entry__free(struct hist_entry *he)
96{
97 free(he);
98}
99
100/*
101 * collapse the histogram
102 */
103
Arnaldo Carvalho de Melob9bf0892009-12-14 11:37:11 -0200104static void collapse__insert_entry(struct rb_root *root, struct hist_entry *he)
John Kacur3d1d07e2009-09-28 15:32:55 +0200105{
Arnaldo Carvalho de Melob9bf0892009-12-14 11:37:11 -0200106 struct rb_node **p = &root->rb_node;
John Kacur3d1d07e2009-09-28 15:32:55 +0200107 struct rb_node *parent = NULL;
108 struct hist_entry *iter;
109 int64_t cmp;
110
111 while (*p != NULL) {
112 parent = *p;
113 iter = rb_entry(parent, struct hist_entry, rb_node);
114
115 cmp = hist_entry__collapse(iter, he);
116
117 if (!cmp) {
118 iter->count += he->count;
119 hist_entry__free(he);
120 return;
121 }
122
123 if (cmp < 0)
124 p = &(*p)->rb_left;
125 else
126 p = &(*p)->rb_right;
127 }
128
129 rb_link_node(&he->rb_node, parent, p);
Arnaldo Carvalho de Melob9bf0892009-12-14 11:37:11 -0200130 rb_insert_color(&he->rb_node, root);
John Kacur3d1d07e2009-09-28 15:32:55 +0200131}
132
Eric B Munsoneefc4652010-03-05 12:51:08 -0300133void perf_session__collapse_resort(struct rb_root *hists)
John Kacur3d1d07e2009-09-28 15:32:55 +0200134{
Arnaldo Carvalho de Melob9bf0892009-12-14 11:37:11 -0200135 struct rb_root tmp;
John Kacur3d1d07e2009-09-28 15:32:55 +0200136 struct rb_node *next;
137 struct hist_entry *n;
138
139 if (!sort__need_collapse)
140 return;
141
Arnaldo Carvalho de Melob9bf0892009-12-14 11:37:11 -0200142 tmp = RB_ROOT;
Eric B Munsoneefc4652010-03-05 12:51:08 -0300143 next = rb_first(hists);
Arnaldo Carvalho de Melob9bf0892009-12-14 11:37:11 -0200144
John Kacur3d1d07e2009-09-28 15:32:55 +0200145 while (next) {
146 n = rb_entry(next, struct hist_entry, rb_node);
147 next = rb_next(&n->rb_node);
148
Eric B Munsoneefc4652010-03-05 12:51:08 -0300149 rb_erase(&n->rb_node, hists);
Arnaldo Carvalho de Melob9bf0892009-12-14 11:37:11 -0200150 collapse__insert_entry(&tmp, n);
John Kacur3d1d07e2009-09-28 15:32:55 +0200151 }
Arnaldo Carvalho de Melob9bf0892009-12-14 11:37:11 -0200152
Eric B Munsoneefc4652010-03-05 12:51:08 -0300153 *hists = tmp;
John Kacur3d1d07e2009-09-28 15:32:55 +0200154}
155
156/*
157 * reverse the map, sort on count.
158 */
159
Arnaldo Carvalho de Melod599db32009-12-15 20:04:42 -0200160static void perf_session__insert_output_hist_entry(struct rb_root *root,
Arnaldo Carvalho de Melo4e4f06e2009-12-14 13:10:39 -0200161 struct hist_entry *he,
162 u64 min_callchain_hits)
John Kacur3d1d07e2009-09-28 15:32:55 +0200163{
Arnaldo Carvalho de Melob9bf0892009-12-14 11:37:11 -0200164 struct rb_node **p = &root->rb_node;
John Kacur3d1d07e2009-09-28 15:32:55 +0200165 struct rb_node *parent = NULL;
166 struct hist_entry *iter;
167
Arnaldo Carvalho de Melod599db32009-12-15 20:04:42 -0200168 if (symbol_conf.use_callchain)
John Kacur3d1d07e2009-09-28 15:32:55 +0200169 callchain_param.sort(&he->sorted_chain, &he->callchain,
170 min_callchain_hits, &callchain_param);
171
172 while (*p != NULL) {
173 parent = *p;
174 iter = rb_entry(parent, struct hist_entry, rb_node);
175
176 if (he->count > iter->count)
177 p = &(*p)->rb_left;
178 else
179 p = &(*p)->rb_right;
180 }
181
182 rb_link_node(&he->rb_node, parent, p);
Arnaldo Carvalho de Melob9bf0892009-12-14 11:37:11 -0200183 rb_insert_color(&he->rb_node, root);
John Kacur3d1d07e2009-09-28 15:32:55 +0200184}
185
Eric B Munsoneefc4652010-03-05 12:51:08 -0300186void perf_session__output_resort(struct rb_root *hists, u64 total_samples)
John Kacur3d1d07e2009-09-28 15:32:55 +0200187{
Arnaldo Carvalho de Melob9bf0892009-12-14 11:37:11 -0200188 struct rb_root tmp;
John Kacur3d1d07e2009-09-28 15:32:55 +0200189 struct rb_node *next;
190 struct hist_entry *n;
John Kacur3d1d07e2009-09-28 15:32:55 +0200191 u64 min_callchain_hits;
192
193 min_callchain_hits =
194 total_samples * (callchain_param.min_percent / 100);
195
Arnaldo Carvalho de Melob9bf0892009-12-14 11:37:11 -0200196 tmp = RB_ROOT;
Eric B Munsoneefc4652010-03-05 12:51:08 -0300197 next = rb_first(hists);
John Kacur3d1d07e2009-09-28 15:32:55 +0200198
199 while (next) {
200 n = rb_entry(next, struct hist_entry, rb_node);
201 next = rb_next(&n->rb_node);
202
Eric B Munsoneefc4652010-03-05 12:51:08 -0300203 rb_erase(&n->rb_node, hists);
Arnaldo Carvalho de Melod599db32009-12-15 20:04:42 -0200204 perf_session__insert_output_hist_entry(&tmp, n,
Arnaldo Carvalho de Melo4e4f06e2009-12-14 13:10:39 -0200205 min_callchain_hits);
John Kacur3d1d07e2009-09-28 15:32:55 +0200206 }
Arnaldo Carvalho de Melob9bf0892009-12-14 11:37:11 -0200207
Eric B Munsoneefc4652010-03-05 12:51:08 -0300208 *hists = tmp;
John Kacur3d1d07e2009-09-28 15:32:55 +0200209}
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200210
211static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin)
212{
213 int i;
214 int ret = fprintf(fp, " ");
215
216 for (i = 0; i < left_margin; i++)
217 ret += fprintf(fp, " ");
218
219 return ret;
220}
221
222static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask,
223 int left_margin)
224{
225 int i;
226 size_t ret = callchain__fprintf_left_margin(fp, left_margin);
227
228 for (i = 0; i < depth; i++)
229 if (depth_mask & (1 << i))
230 ret += fprintf(fp, "| ");
231 else
232 ret += fprintf(fp, " ");
233
234 ret += fprintf(fp, "\n");
235
236 return ret;
237}
238
239static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain,
240 int depth, int depth_mask, int count,
241 u64 total_samples, int hits,
242 int left_margin)
243{
244 int i;
245 size_t ret = 0;
246
247 ret += callchain__fprintf_left_margin(fp, left_margin);
248 for (i = 0; i < depth; i++) {
249 if (depth_mask & (1 << i))
250 ret += fprintf(fp, "|");
251 else
252 ret += fprintf(fp, " ");
253 if (!count && i == depth - 1) {
254 double percent;
255
256 percent = hits * 100.0 / total_samples;
257 ret += percent_color_fprintf(fp, "--%2.2f%%-- ", percent);
258 } else
259 ret += fprintf(fp, "%s", " ");
260 }
261 if (chain->sym)
262 ret += fprintf(fp, "%s\n", chain->sym->name);
263 else
264 ret += fprintf(fp, "%p\n", (void *)(long)chain->ip);
265
266 return ret;
267}
268
269static struct symbol *rem_sq_bracket;
270static struct callchain_list rem_hits;
271
272static void init_rem_hits(void)
273{
274 rem_sq_bracket = malloc(sizeof(*rem_sq_bracket) + 6);
275 if (!rem_sq_bracket) {
276 fprintf(stderr, "Not enough memory to display remaining hits\n");
277 return;
278 }
279
280 strcpy(rem_sq_bracket->name, "[...]");
281 rem_hits.sym = rem_sq_bracket;
282}
283
284static size_t __callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
285 u64 total_samples, int depth,
286 int depth_mask, int left_margin)
287{
288 struct rb_node *node, *next;
289 struct callchain_node *child;
290 struct callchain_list *chain;
291 int new_depth_mask = depth_mask;
292 u64 new_total;
293 u64 remaining;
294 size_t ret = 0;
295 int i;
296
297 if (callchain_param.mode == CHAIN_GRAPH_REL)
298 new_total = self->children_hit;
299 else
300 new_total = total_samples;
301
302 remaining = new_total;
303
304 node = rb_first(&self->rb_root);
305 while (node) {
306 u64 cumul;
307
308 child = rb_entry(node, struct callchain_node, rb_node);
309 cumul = cumul_hits(child);
310 remaining -= cumul;
311
312 /*
313 * The depth mask manages the output of pipes that show
314 * the depth. We don't want to keep the pipes of the current
315 * level for the last child of this depth.
316 * Except if we have remaining filtered hits. They will
317 * supersede the last child
318 */
319 next = rb_next(node);
320 if (!next && (callchain_param.mode != CHAIN_GRAPH_REL || !remaining))
321 new_depth_mask &= ~(1 << (depth - 1));
322
323 /*
Daniel Mack3ad2f3f2010-02-03 08:01:28 +0800324 * But we keep the older depth mask for the line separator
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200325 * to keep the level link until we reach the last child
326 */
327 ret += ipchain__fprintf_graph_line(fp, depth, depth_mask,
328 left_margin);
329 i = 0;
330 list_for_each_entry(chain, &child->val, list) {
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200331 ret += ipchain__fprintf_graph(fp, chain, depth,
332 new_depth_mask, i++,
333 new_total,
334 cumul,
335 left_margin);
336 }
337 ret += __callchain__fprintf_graph(fp, child, new_total,
338 depth + 1,
339 new_depth_mask | (1 << depth),
340 left_margin);
341 node = next;
342 }
343
344 if (callchain_param.mode == CHAIN_GRAPH_REL &&
345 remaining && remaining != new_total) {
346
347 if (!rem_sq_bracket)
348 return ret;
349
350 new_depth_mask &= ~(1 << (depth - 1));
351
352 ret += ipchain__fprintf_graph(fp, &rem_hits, depth,
353 new_depth_mask, 0, new_total,
354 remaining, left_margin);
355 }
356
357 return ret;
358}
359
360static size_t callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
361 u64 total_samples, int left_margin)
362{
363 struct callchain_list *chain;
364 bool printed = false;
365 int i = 0;
366 int ret = 0;
367
368 list_for_each_entry(chain, &self->val, list) {
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200369 if (!i++ && sort__first_dimension == SORT_SYM)
370 continue;
371
372 if (!printed) {
373 ret += callchain__fprintf_left_margin(fp, left_margin);
374 ret += fprintf(fp, "|\n");
375 ret += callchain__fprintf_left_margin(fp, left_margin);
376 ret += fprintf(fp, "---");
377
378 left_margin += 3;
379 printed = true;
380 } else
381 ret += callchain__fprintf_left_margin(fp, left_margin);
382
383 if (chain->sym)
384 ret += fprintf(fp, " %s\n", chain->sym->name);
385 else
386 ret += fprintf(fp, " %p\n", (void *)(long)chain->ip);
387 }
388
389 ret += __callchain__fprintf_graph(fp, self, total_samples, 1, 1, left_margin);
390
391 return ret;
392}
393
394static size_t callchain__fprintf_flat(FILE *fp, struct callchain_node *self,
395 u64 total_samples)
396{
397 struct callchain_list *chain;
398 size_t ret = 0;
399
400 if (!self)
401 return 0;
402
403 ret += callchain__fprintf_flat(fp, self->parent, total_samples);
404
405
406 list_for_each_entry(chain, &self->val, list) {
407 if (chain->ip >= PERF_CONTEXT_MAX)
408 continue;
409 if (chain->sym)
410 ret += fprintf(fp, " %s\n", chain->sym->name);
411 else
412 ret += fprintf(fp, " %p\n",
413 (void *)(long)chain->ip);
414 }
415
416 return ret;
417}
418
419static size_t hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self,
420 u64 total_samples, int left_margin)
421{
422 struct rb_node *rb_node;
423 struct callchain_node *chain;
424 size_t ret = 0;
425
426 rb_node = rb_first(&self->sorted_chain);
427 while (rb_node) {
428 double percent;
429
430 chain = rb_entry(rb_node, struct callchain_node, rb_node);
431 percent = chain->hit * 100.0 / total_samples;
432 switch (callchain_param.mode) {
433 case CHAIN_FLAT:
434 ret += percent_color_fprintf(fp, " %6.2f%%\n",
435 percent);
436 ret += callchain__fprintf_flat(fp, chain, total_samples);
437 break;
438 case CHAIN_GRAPH_ABS: /* Falldown */
439 case CHAIN_GRAPH_REL:
440 ret += callchain__fprintf_graph(fp, chain, total_samples,
441 left_margin);
442 case CHAIN_NONE:
443 default:
444 break;
445 }
446 ret += fprintf(fp, "\n");
447 rb_node = rb_next(rb_node);
448 }
449
450 return ret;
451}
452
Arnaldo Carvalho de Melodd2ee782010-03-11 20:12:43 -0300453size_t hist_entry__fprintf(struct hist_entry *self,
454 struct perf_session *pair_session,
455 bool show_displacement,
456 long displacement, FILE *fp,
457 u64 session_total)
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200458{
459 struct sort_entry *se;
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200460 u64 count, total;
461 const char *sep = symbol_conf.field_sep;
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200462 size_t ret;
463
464 if (symbol_conf.exclude_other && !self->parent)
465 return 0;
466
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200467 if (pair_session) {
468 count = self->pair ? self->pair->count : 0;
469 total = pair_session->events_stats.total;
470 } else {
471 count = self->count;
Eric B Munsoneefc4652010-03-05 12:51:08 -0300472 total = session_total;
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200473 }
474
475 if (total)
476 ret = percent_color_fprintf(fp, sep ? "%.2f" : " %6.2f%%",
477 (count * 100.0) / total);
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200478 else
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200479 ret = fprintf(fp, sep ? "%lld" : "%12lld ", count);
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200480
481 if (symbol_conf.show_nr_samples) {
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200482 if (sep)
Arnaldo Carvalho de Melodd2ee782010-03-11 20:12:43 -0300483 ret += fprintf(fp, "%c%lld", *sep, count);
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200484 else
Arnaldo Carvalho de Melodd2ee782010-03-11 20:12:43 -0300485 ret += fprintf(fp, "%11lld", count);
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200486 }
487
488 if (pair_session) {
489 char bf[32];
490 double old_percent = 0, new_percent = 0, diff;
491
492 if (total > 0)
Arnaldo Carvalho de Melo9b338272009-12-16 14:31:49 -0200493 old_percent = (count * 100.0) / total;
Eric B Munsoneefc4652010-03-05 12:51:08 -0300494 if (session_total > 0)
495 new_percent = (self->count * 100.0) / session_total;
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200496
Arnaldo Carvalho de Melo9b338272009-12-16 14:31:49 -0200497 diff = new_percent - old_percent;
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200498
Arnaldo Carvalho de Melo9b338272009-12-16 14:31:49 -0200499 if (fabs(diff) >= 0.01)
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200500 snprintf(bf, sizeof(bf), "%+4.2F%%", diff);
501 else
502 snprintf(bf, sizeof(bf), " ");
503
504 if (sep)
505 ret += fprintf(fp, "%c%s", *sep, bf);
506 else
507 ret += fprintf(fp, "%11.11s", bf);
508
509 if (show_displacement) {
510 if (displacement)
511 snprintf(bf, sizeof(bf), "%+4ld", displacement);
512 else
513 snprintf(bf, sizeof(bf), " ");
514
515 if (sep)
Arnaldo Carvalho de Melodd2ee782010-03-11 20:12:43 -0300516 ret += fprintf(fp, "%c%s", *sep, bf);
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200517 else
Arnaldo Carvalho de Melodd2ee782010-03-11 20:12:43 -0300518 ret += fprintf(fp, "%6.6s", bf);
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200519 }
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200520 }
521
522 list_for_each_entry(se, &hist_entry__sort_list, list) {
523 if (se->elide)
524 continue;
525
Arnaldo Carvalho de Melodd2ee782010-03-11 20:12:43 -0300526 ret += fprintf(fp, "%s", sep ?: " ");
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200527 ret += se->print(fp, self, se->width ? *se->width : 0);
528 }
529
Arnaldo Carvalho de Melo3997d372010-03-12 12:46:48 -0300530 return ret + fprintf(fp, "\n");
531}
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200532
Arnaldo Carvalho de Melo3997d372010-03-12 12:46:48 -0300533static size_t hist_entry__fprintf_callchain(struct hist_entry *self, FILE *fp,
534 u64 session_total)
535{
536 int left_margin = 0;
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200537
Arnaldo Carvalho de Melo3997d372010-03-12 12:46:48 -0300538 if (sort__first_dimension == SORT_COMM) {
539 struct sort_entry *se = list_first_entry(&hist_entry__sort_list,
540 typeof(*se), list);
541 left_margin = se->width ? *se->width : 0;
542 left_margin -= thread__comm_len(self->thread);
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200543 }
544
Arnaldo Carvalho de Melo3997d372010-03-12 12:46:48 -0300545 return hist_entry_callchain__fprintf(fp, self, session_total,
546 left_margin);
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200547}
548
Eric B Munsoneefc4652010-03-05 12:51:08 -0300549size_t perf_session__fprintf_hists(struct rb_root *hists,
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200550 struct perf_session *pair,
Eric B Munsoneefc4652010-03-05 12:51:08 -0300551 bool show_displacement, FILE *fp,
552 u64 session_total)
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200553{
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200554 struct sort_entry *se;
555 struct rb_node *nd;
556 size_t ret = 0;
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200557 unsigned long position = 1;
558 long displacement = 0;
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200559 unsigned int width;
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200560 const char *sep = symbol_conf.field_sep;
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200561 char *col_width = symbol_conf.col_width_list_str;
562
563 init_rem_hits();
564
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200565 fprintf(fp, "# %s", pair ? "Baseline" : "Overhead");
566
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200567 if (symbol_conf.show_nr_samples) {
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200568 if (sep)
569 fprintf(fp, "%cSamples", *sep);
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200570 else
571 fputs(" Samples ", fp);
572 }
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200573
574 if (pair) {
575 if (sep)
576 ret += fprintf(fp, "%cDelta", *sep);
577 else
578 ret += fprintf(fp, " Delta ");
579
580 if (show_displacement) {
581 if (sep)
582 ret += fprintf(fp, "%cDisplacement", *sep);
583 else
584 ret += fprintf(fp, " Displ");
585 }
586 }
587
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200588 list_for_each_entry(se, &hist_entry__sort_list, list) {
589 if (se->elide)
590 continue;
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200591 if (sep) {
592 fprintf(fp, "%c%s", *sep, se->header);
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200593 continue;
594 }
595 width = strlen(se->header);
596 if (se->width) {
597 if (symbol_conf.col_width_list_str) {
598 if (col_width) {
599 *se->width = atoi(col_width);
600 col_width = strchr(col_width, ',');
601 if (col_width)
602 ++col_width;
603 }
604 }
605 width = *se->width = max(*se->width, width);
606 }
607 fprintf(fp, " %*s", width, se->header);
608 }
609 fprintf(fp, "\n");
610
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200611 if (sep)
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200612 goto print_entries;
613
614 fprintf(fp, "# ........");
615 if (symbol_conf.show_nr_samples)
616 fprintf(fp, " ..........");
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200617 if (pair) {
618 fprintf(fp, " ..........");
619 if (show_displacement)
620 fprintf(fp, " .....");
621 }
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200622 list_for_each_entry(se, &hist_entry__sort_list, list) {
623 unsigned int i;
624
625 if (se->elide)
626 continue;
627
628 fprintf(fp, " ");
629 if (se->width)
630 width = *se->width;
631 else
632 width = strlen(se->header);
633 for (i = 0; i < width; i++)
634 fprintf(fp, ".");
635 }
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200636
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200637 fprintf(fp, "\n#\n");
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200638
639print_entries:
Eric B Munsoneefc4652010-03-05 12:51:08 -0300640 for (nd = rb_first(hists); nd; nd = rb_next(nd)) {
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200641 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
642
643 if (show_displacement) {
644 if (h->pair != NULL)
645 displacement = ((long)h->pair->position -
646 (long)position);
647 else
648 displacement = 0;
649 ++position;
650 }
Eric B Munsoneefc4652010-03-05 12:51:08 -0300651 ret += hist_entry__fprintf(h, pair, show_displacement,
652 displacement, fp, session_total);
Arnaldo Carvalho de Melo3997d372010-03-12 12:46:48 -0300653
654 if (symbol_conf.use_callchain)
655 ret += hist_entry__fprintf_callchain(h, fp, session_total);
656
Arnaldo Carvalho de Melo65f2ed22010-03-09 15:58:17 -0300657 if (h->map == NULL && verbose > 1) {
658 __map_groups__fprintf_maps(&h->thread->mg,
659 MAP__FUNCTION, fp);
660 fprintf(fp, "%.10s end\n", graph_dotted_line);
661 }
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200662 }
663
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200664 free(rem_sq_bracket);
665
666 return ret;
667}