9 static bool hists__filter_entry_by_dso(struct hists *hists,
10 struct hist_entry *he);
11 static bool hists__filter_entry_by_thread(struct hists *hists,
12 struct hist_entry *he);
20 struct callchain_param callchain_param = {
21 .mode = CHAIN_GRAPH_REL,
26 u16 hists__col_len(struct hists *hists, enum hist_column col)
28 return hists->col_len[col];
31 void hists__set_col_len(struct hists *hists, enum hist_column col, u16 len)
33 hists->col_len[col] = len;
36 bool hists__new_col_len(struct hists *hists, enum hist_column col, u16 len)
38 if (len > hists__col_len(hists, col)) {
39 hists__set_col_len(hists, col, len);
45 static void hists__reset_col_len(struct hists *hists)
49 for (col = 0; col < HISTC_NR_COLS; ++col)
50 hists__set_col_len(hists, col, 0);
53 static void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
58 hists__new_col_len(hists, HISTC_SYMBOL, h->ms.sym->namelen);
60 const unsigned int unresolved_col_width = BITS_PER_LONG / 4;
62 if (hists__col_len(hists, HISTC_DSO) < unresolved_col_width &&
63 !symbol_conf.col_width_list_str && !symbol_conf.field_sep &&
64 !symbol_conf.dso_list)
65 hists__set_col_len(hists, HISTC_DSO,
66 unresolved_col_width);
69 len = thread__comm_len(h->thread);
70 if (hists__new_col_len(hists, HISTC_COMM, len))
71 hists__set_col_len(hists, HISTC_THREAD, len + 6);
74 len = dso__name_len(h->ms.map->dso);
75 hists__new_col_len(hists, HISTC_DSO, len);
79 static void hist_entry__add_cpumode_period(struct hist_entry *self,
80 unsigned int cpumode, u64 period)
83 case PERF_RECORD_MISC_KERNEL:
84 self->period_sys += period;
86 case PERF_RECORD_MISC_USER:
87 self->period_us += period;
89 case PERF_RECORD_MISC_GUEST_KERNEL:
90 self->period_guest_sys += period;
92 case PERF_RECORD_MISC_GUEST_USER:
93 self->period_guest_us += period;
100 static void hist_entry__decay(struct hist_entry *he)
102 he->period = (he->period * 7) / 8;
103 he->nr_events = (he->nr_events * 7) / 8;
106 static bool hists__decay_entry(struct hists *hists, struct hist_entry *he)
108 u64 prev_period = he->period;
110 if (prev_period == 0)
113 hist_entry__decay(he);
116 hists->stats.total_period -= prev_period - he->period;
118 return he->period == 0;
121 static void __hists__decay_entries(struct hists *hists, bool zap_user,
122 bool zap_kernel, bool threaded)
124 struct rb_node *next = rb_first(&hists->entries);
125 struct hist_entry *n;
128 n = rb_entry(next, struct hist_entry, rb_node);
129 next = rb_next(&n->rb_node);
131 * We may be annotating this, for instance, so keep it here in
132 * case some it gets new samples, we'll eventually free it when
133 * the user stops browsing and it agains gets fully decayed.
135 if (((zap_user && n->level == '.') ||
136 (zap_kernel && n->level != '.') ||
137 hists__decay_entry(hists, n)) &&
139 rb_erase(&n->rb_node, &hists->entries);
141 if (sort__need_collapse || threaded)
142 rb_erase(&n->rb_node_in, &hists->entries_collapsed);
150 void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel)
152 return __hists__decay_entries(hists, zap_user, zap_kernel, false);
155 void hists__decay_entries_threaded(struct hists *hists,
156 bool zap_user, bool zap_kernel)
158 return __hists__decay_entries(hists, zap_user, zap_kernel, true);
162 * histogram, sorted on item, collects periods
165 static struct hist_entry *hist_entry__new(struct hist_entry *template)
167 size_t callchain_size = symbol_conf.use_callchain ? sizeof(struct callchain_root) : 0;
168 struct hist_entry *self = malloc(sizeof(*self) + callchain_size);
174 self->ms.map->referenced = true;
175 if (symbol_conf.use_callchain)
176 callchain_init(self->callchain);
182 static void hists__inc_nr_entries(struct hists *hists, struct hist_entry *h)
185 hists__calc_col_len(hists, h);
187 hists->stats.total_period += h->period;
191 static u8 symbol__parent_filter(const struct symbol *parent)
193 if (symbol_conf.exclude_other && parent == NULL)
194 return 1 << HIST_FILTER__PARENT;
198 struct hist_entry *__hists__add_entry(struct hists *hists,
199 struct addr_location *al,
200 struct symbol *sym_parent, u64 period)
203 struct rb_node *parent = NULL;
204 struct hist_entry *he;
205 struct hist_entry entry = {
206 .thread = al->thread,
215 .parent = sym_parent,
216 .filtered = symbol__parent_filter(sym_parent),
220 pthread_mutex_lock(&hists->lock);
222 p = &hists->entries_in->rb_node;
226 he = rb_entry(parent, struct hist_entry, rb_node_in);
228 cmp = hist_entry__cmp(&entry, he);
231 he->period += period;
242 he = hist_entry__new(&entry);
246 rb_link_node(&he->rb_node_in, parent, p);
247 rb_insert_color(&he->rb_node_in, hists->entries_in);
249 hist_entry__add_cpumode_period(he, al->cpumode, period);
251 pthread_mutex_unlock(&hists->lock);
256 hist_entry__cmp(struct hist_entry *left, struct hist_entry *right)
258 struct sort_entry *se;
261 list_for_each_entry(se, &hist_entry__sort_list, list) {
262 cmp = se->se_cmp(left, right);
271 hist_entry__collapse(struct hist_entry *left, struct hist_entry *right)
273 struct sort_entry *se;
276 list_for_each_entry(se, &hist_entry__sort_list, list) {
277 int64_t (*f)(struct hist_entry *, struct hist_entry *);
279 f = se->se_collapse ?: se->se_cmp;
281 cmp = f(left, right);
289 void hist_entry__free(struct hist_entry *he)
295 * collapse the histogram
298 static bool hists__collapse_insert_entry(struct hists *hists,
299 struct rb_root *root,
300 struct hist_entry *he)
302 struct rb_node **p = &root->rb_node;
303 struct rb_node *parent = NULL;
304 struct hist_entry *iter;
309 iter = rb_entry(parent, struct hist_entry, rb_node_in);
311 cmp = hist_entry__collapse(iter, he);
314 iter->period += he->period;
315 iter->nr_events += he->nr_events;
316 if (symbol_conf.use_callchain) {
317 callchain_cursor_reset(&hists->callchain_cursor);
318 callchain_merge(&hists->callchain_cursor, iter->callchain,
321 hist_entry__free(he);
331 rb_link_node(&he->rb_node_in, parent, p);
332 rb_insert_color(&he->rb_node_in, root);
336 static struct rb_root *hists__get_rotate_entries_in(struct hists *hists)
338 struct rb_root *root;
340 pthread_mutex_lock(&hists->lock);
342 root = hists->entries_in;
343 if (++hists->entries_in > &hists->entries_in_array[1])
344 hists->entries_in = &hists->entries_in_array[0];
346 pthread_mutex_unlock(&hists->lock);
351 static void hists__apply_filters(struct hists *hists, struct hist_entry *he)
353 hists__filter_entry_by_dso(hists, he);
354 hists__filter_entry_by_thread(hists, he);
357 static void __hists__collapse_resort(struct hists *hists, bool threaded)
359 struct rb_root *root;
360 struct rb_node *next;
361 struct hist_entry *n;
363 if (!sort__need_collapse && !threaded)
366 root = hists__get_rotate_entries_in(hists);
367 next = rb_first(root);
368 hists->stats.total_period = 0;
371 n = rb_entry(next, struct hist_entry, rb_node_in);
372 next = rb_next(&n->rb_node_in);
374 rb_erase(&n->rb_node_in, root);
375 if (hists__collapse_insert_entry(hists, &hists->entries_collapsed, n)) {
377 * If it wasn't combined with one of the entries already
378 * collapsed, we need to apply the filters that may have
379 * been set by, say, the hist_browser.
381 hists__apply_filters(hists, n);
382 hists__inc_nr_entries(hists, n);
387 void hists__collapse_resort(struct hists *hists)
389 return __hists__collapse_resort(hists, false);
392 void hists__collapse_resort_threaded(struct hists *hists)
394 return __hists__collapse_resort(hists, true);
398 * reverse the map, sort on period.
401 static void __hists__insert_output_entry(struct rb_root *entries,
402 struct hist_entry *he,
403 u64 min_callchain_hits)
405 struct rb_node **p = &entries->rb_node;
406 struct rb_node *parent = NULL;
407 struct hist_entry *iter;
409 if (symbol_conf.use_callchain)
410 callchain_param.sort(&he->sorted_chain, he->callchain,
411 min_callchain_hits, &callchain_param);
415 iter = rb_entry(parent, struct hist_entry, rb_node);
417 if (he->period > iter->period)
423 rb_link_node(&he->rb_node, parent, p);
424 rb_insert_color(&he->rb_node, entries);
427 static void __hists__output_resort(struct hists *hists, bool threaded)
429 struct rb_root *root;
430 struct rb_node *next;
431 struct hist_entry *n;
432 u64 min_callchain_hits;
434 min_callchain_hits = hists->stats.total_period * (callchain_param.min_percent / 100);
436 if (sort__need_collapse || threaded)
437 root = &hists->entries_collapsed;
439 root = hists->entries_in;
441 next = rb_first(root);
442 hists->entries = RB_ROOT;
444 hists->nr_entries = 0;
445 hists__reset_col_len(hists);
448 n = rb_entry(next, struct hist_entry, rb_node_in);
449 next = rb_next(&n->rb_node_in);
451 __hists__insert_output_entry(&hists->entries, n, min_callchain_hits);
452 hists__inc_nr_entries(hists, n);
456 void hists__output_resort(struct hists *hists)
458 return __hists__output_resort(hists, false);
461 void hists__output_resort_threaded(struct hists *hists)
463 return __hists__output_resort(hists, true);
466 static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin)
469 int ret = fprintf(fp, " ");
471 for (i = 0; i < left_margin; i++)
472 ret += fprintf(fp, " ");
477 static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask,
481 size_t ret = callchain__fprintf_left_margin(fp, left_margin);
483 for (i = 0; i < depth; i++)
484 if (depth_mask & (1 << i))
485 ret += fprintf(fp, "| ");
487 ret += fprintf(fp, " ");
489 ret += fprintf(fp, "\n");
494 static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain,
495 int depth, int depth_mask, int period,
496 u64 total_samples, u64 hits,
502 ret += callchain__fprintf_left_margin(fp, left_margin);
503 for (i = 0; i < depth; i++) {
504 if (depth_mask & (1 << i))
505 ret += fprintf(fp, "|");
507 ret += fprintf(fp, " ");
508 if (!period && i == depth - 1) {
511 percent = hits * 100.0 / total_samples;
512 ret += percent_color_fprintf(fp, "--%2.2f%%-- ", percent);
514 ret += fprintf(fp, "%s", " ");
517 ret += fprintf(fp, "%s\n", chain->ms.sym->name);
519 ret += fprintf(fp, "%p\n", (void *)(long)chain->ip);
524 static struct symbol *rem_sq_bracket;
525 static struct callchain_list rem_hits;
527 static void init_rem_hits(void)
529 rem_sq_bracket = malloc(sizeof(*rem_sq_bracket) + 6);
530 if (!rem_sq_bracket) {
531 fprintf(stderr, "Not enough memory to display remaining hits\n");
535 strcpy(rem_sq_bracket->name, "[...]");
536 rem_hits.ms.sym = rem_sq_bracket;
539 static size_t __callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
540 u64 total_samples, int depth,
541 int depth_mask, int left_margin)
543 struct rb_node *node, *next;
544 struct callchain_node *child;
545 struct callchain_list *chain;
546 int new_depth_mask = depth_mask;
551 uint entries_printed = 0;
553 if (callchain_param.mode == CHAIN_GRAPH_REL)
554 new_total = self->children_hit;
556 new_total = total_samples;
558 remaining = new_total;
560 node = rb_first(&self->rb_root);
564 child = rb_entry(node, struct callchain_node, rb_node);
565 cumul = callchain_cumul_hits(child);
569 * The depth mask manages the output of pipes that show
570 * the depth. We don't want to keep the pipes of the current
571 * level for the last child of this depth.
572 * Except if we have remaining filtered hits. They will
573 * supersede the last child
575 next = rb_next(node);
576 if (!next && (callchain_param.mode != CHAIN_GRAPH_REL || !remaining))
577 new_depth_mask &= ~(1 << (depth - 1));
580 * But we keep the older depth mask for the line separator
581 * to keep the level link until we reach the last child
583 ret += ipchain__fprintf_graph_line(fp, depth, depth_mask,
586 list_for_each_entry(chain, &child->val, list) {
587 ret += ipchain__fprintf_graph(fp, chain, depth,
593 ret += __callchain__fprintf_graph(fp, child, new_total,
595 new_depth_mask | (1 << depth),
598 if (++entries_printed == callchain_param.print_limit)
602 if (callchain_param.mode == CHAIN_GRAPH_REL &&
603 remaining && remaining != new_total) {
608 new_depth_mask &= ~(1 << (depth - 1));
610 ret += ipchain__fprintf_graph(fp, &rem_hits, depth,
611 new_depth_mask, 0, new_total,
612 remaining, left_margin);
618 static size_t callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
619 u64 total_samples, int left_margin)
621 struct callchain_list *chain;
622 bool printed = false;
625 u32 entries_printed = 0;
627 list_for_each_entry(chain, &self->val, list) {
628 if (!i++ && sort__first_dimension == SORT_SYM)
632 ret += callchain__fprintf_left_margin(fp, left_margin);
633 ret += fprintf(fp, "|\n");
634 ret += callchain__fprintf_left_margin(fp, left_margin);
635 ret += fprintf(fp, "---");
640 ret += callchain__fprintf_left_margin(fp, left_margin);
643 ret += fprintf(fp, " %s\n", chain->ms.sym->name);
645 ret += fprintf(fp, " %p\n", (void *)(long)chain->ip);
647 if (++entries_printed == callchain_param.print_limit)
651 ret += __callchain__fprintf_graph(fp, self, total_samples, 1, 1, left_margin);
656 static size_t callchain__fprintf_flat(FILE *fp, struct callchain_node *self,
659 struct callchain_list *chain;
665 ret += callchain__fprintf_flat(fp, self->parent, total_samples);
668 list_for_each_entry(chain, &self->val, list) {
669 if (chain->ip >= PERF_CONTEXT_MAX)
672 ret += fprintf(fp, " %s\n", chain->ms.sym->name);
674 ret += fprintf(fp, " %p\n",
675 (void *)(long)chain->ip);
681 static size_t hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self,
682 u64 total_samples, int left_margin)
684 struct rb_node *rb_node;
685 struct callchain_node *chain;
687 u32 entries_printed = 0;
689 rb_node = rb_first(&self->sorted_chain);
693 chain = rb_entry(rb_node, struct callchain_node, rb_node);
694 percent = chain->hit * 100.0 / total_samples;
695 switch (callchain_param.mode) {
697 ret += percent_color_fprintf(fp, " %6.2f%%\n",
699 ret += callchain__fprintf_flat(fp, chain, total_samples);
701 case CHAIN_GRAPH_ABS: /* Falldown */
702 case CHAIN_GRAPH_REL:
703 ret += callchain__fprintf_graph(fp, chain, total_samples,
709 ret += fprintf(fp, "\n");
710 if (++entries_printed == callchain_param.print_limit)
712 rb_node = rb_next(rb_node);
718 void hists__output_recalc_col_len(struct hists *hists, int max_rows)
720 struct rb_node *next = rb_first(&hists->entries);
721 struct hist_entry *n;
724 hists__reset_col_len(hists);
726 while (next && row++ < max_rows) {
727 n = rb_entry(next, struct hist_entry, rb_node);
729 hists__calc_col_len(hists, n);
730 next = rb_next(&n->rb_node);
734 static int hist_entry__pcnt_snprintf(struct hist_entry *self, char *s,
735 size_t size, struct hists *pair_hists,
736 bool show_displacement, long displacement,
737 bool color, u64 session_total)
739 u64 period, total, period_sys, period_us, period_guest_sys, period_guest_us;
741 const char *sep = symbol_conf.field_sep;
744 if (symbol_conf.exclude_other && !self->parent)
748 period = self->pair ? self->pair->period : 0;
749 nr_events = self->pair ? self->pair->nr_events : 0;
750 total = pair_hists->stats.total_period;
751 period_sys = self->pair ? self->pair->period_sys : 0;
752 period_us = self->pair ? self->pair->period_us : 0;
753 period_guest_sys = self->pair ? self->pair->period_guest_sys : 0;
754 period_guest_us = self->pair ? self->pair->period_guest_us : 0;
756 period = self->period;
757 nr_events = self->nr_events;
758 total = session_total;
759 period_sys = self->period_sys;
760 period_us = self->period_us;
761 period_guest_sys = self->period_guest_sys;
762 period_guest_us = self->period_guest_us;
767 ret = percent_color_snprintf(s, size,
768 sep ? "%.2f" : " %6.2f%%",
769 (period * 100.0) / total);
771 ret = snprintf(s, size, sep ? "%.2f" : " %6.2f%%",
772 (period * 100.0) / total);
773 if (symbol_conf.show_cpu_utilization) {
774 ret += percent_color_snprintf(s + ret, size - ret,
775 sep ? "%.2f" : " %6.2f%%",
776 (period_sys * 100.0) / total);
777 ret += percent_color_snprintf(s + ret, size - ret,
778 sep ? "%.2f" : " %6.2f%%",
779 (period_us * 100.0) / total);
781 ret += percent_color_snprintf(s + ret,
783 sep ? "%.2f" : " %6.2f%%",
784 (period_guest_sys * 100.0) /
786 ret += percent_color_snprintf(s + ret,
788 sep ? "%.2f" : " %6.2f%%",
789 (period_guest_us * 100.0) /
794 ret = snprintf(s, size, sep ? "%" PRIu64 : "%12" PRIu64 " ", period);
796 if (symbol_conf.show_nr_samples) {
798 ret += snprintf(s + ret, size - ret, "%c%" PRIu64, *sep, nr_events);
800 ret += snprintf(s + ret, size - ret, "%11" PRIu64, nr_events);
803 if (symbol_conf.show_total_period) {
805 ret += snprintf(s + ret, size - ret, "%c%" PRIu64, *sep, period);
807 ret += snprintf(s + ret, size - ret, " %12" PRIu64, period);
812 double old_percent = 0, new_percent = 0, diff;
815 old_percent = (period * 100.0) / total;
816 if (session_total > 0)
817 new_percent = (self->period * 100.0) / session_total;
819 diff = new_percent - old_percent;
821 if (fabs(diff) >= 0.01)
822 snprintf(bf, sizeof(bf), "%+4.2F%%", diff);
824 snprintf(bf, sizeof(bf), " ");
827 ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf);
829 ret += snprintf(s + ret, size - ret, "%11.11s", bf);
831 if (show_displacement) {
833 snprintf(bf, sizeof(bf), "%+4ld", displacement);
835 snprintf(bf, sizeof(bf), " ");
838 ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf);
840 ret += snprintf(s + ret, size - ret, "%6.6s", bf);
847 int hist_entry__snprintf(struct hist_entry *he, char *s, size_t size,
850 const char *sep = symbol_conf.field_sep;
851 struct sort_entry *se;
854 list_for_each_entry(se, &hist_entry__sort_list, list) {
858 ret += snprintf(s + ret, size - ret, "%s", sep ?: " ");
859 ret += se->se_snprintf(he, s + ret, size - ret,
860 hists__col_len(hists, se->se_width_idx));
866 int hist_entry__fprintf(struct hist_entry *he, size_t size, struct hists *hists,
867 struct hists *pair_hists, bool show_displacement,
868 long displacement, FILE *fp, u64 session_total)
873 if (size == 0 || size > sizeof(bf))
876 ret = hist_entry__pcnt_snprintf(he, bf, size, pair_hists,
877 show_displacement, displacement,
878 true, session_total);
879 hist_entry__snprintf(he, bf + ret, size - ret, hists);
880 return fprintf(fp, "%s\n", bf);
883 static size_t hist_entry__fprintf_callchain(struct hist_entry *self,
884 struct hists *hists, FILE *fp,
889 if (sort__first_dimension == SORT_COMM) {
890 struct sort_entry *se = list_first_entry(&hist_entry__sort_list,
892 left_margin = hists__col_len(hists, se->se_width_idx);
893 left_margin -= thread__comm_len(self->thread);
896 return hist_entry_callchain__fprintf(fp, self, session_total,
900 size_t hists__fprintf(struct hists *hists, struct hists *pair,
901 bool show_displacement, bool show_header, int max_rows,
902 int max_cols, FILE *fp)
904 struct sort_entry *se;
907 unsigned long position = 1;
908 long displacement = 0;
910 const char *sep = symbol_conf.field_sep;
911 const char *col_width = symbol_conf.col_width_list_str;
919 fprintf(fp, "# %s", pair ? "Baseline" : "Overhead");
921 if (symbol_conf.show_nr_samples) {
923 fprintf(fp, "%cSamples", *sep);
925 fputs(" Samples ", fp);
928 if (symbol_conf.show_total_period) {
930 ret += fprintf(fp, "%cPeriod", *sep);
932 ret += fprintf(fp, " Period ");
935 if (symbol_conf.show_cpu_utilization) {
937 ret += fprintf(fp, "%csys", *sep);
938 ret += fprintf(fp, "%cus", *sep);
940 ret += fprintf(fp, "%cguest sys", *sep);
941 ret += fprintf(fp, "%cguest us", *sep);
944 ret += fprintf(fp, " sys ");
945 ret += fprintf(fp, " us ");
947 ret += fprintf(fp, " guest sys ");
948 ret += fprintf(fp, " guest us ");
955 ret += fprintf(fp, "%cDelta", *sep);
957 ret += fprintf(fp, " Delta ");
959 if (show_displacement) {
961 ret += fprintf(fp, "%cDisplacement", *sep);
963 ret += fprintf(fp, " Displ");
967 list_for_each_entry(se, &hist_entry__sort_list, list) {
971 fprintf(fp, "%c%s", *sep, se->se_header);
974 width = strlen(se->se_header);
975 if (symbol_conf.col_width_list_str) {
977 hists__set_col_len(hists, se->se_width_idx,
979 col_width = strchr(col_width, ',');
984 if (!hists__new_col_len(hists, se->se_width_idx, width))
985 width = hists__col_len(hists, se->se_width_idx);
986 fprintf(fp, " %*s", width, se->se_header);
990 if (max_rows && ++nr_rows >= max_rows)
996 fprintf(fp, "# ........");
997 if (symbol_conf.show_nr_samples)
998 fprintf(fp, " ..........");
999 if (symbol_conf.show_total_period)
1000 fprintf(fp, " ............");
1002 fprintf(fp, " ..........");
1003 if (show_displacement)
1004 fprintf(fp, " .....");
1006 list_for_each_entry(se, &hist_entry__sort_list, list) {
1013 width = hists__col_len(hists, se->se_width_idx);
1015 width = strlen(se->se_header);
1016 for (i = 0; i < width; i++)
1021 if (max_rows && ++nr_rows >= max_rows)
1025 if (max_rows && ++nr_rows >= max_rows)
1029 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
1030 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
1035 if (show_displacement) {
1036 if (h->pair != NULL)
1037 displacement = ((long)h->pair->position -
1043 ret += hist_entry__fprintf(h, max_cols, hists, pair, show_displacement,
1044 displacement, fp, hists->stats.total_period);
1046 if (symbol_conf.use_callchain)
1047 ret += hist_entry__fprintf_callchain(h, hists, fp,
1048 hists->stats.total_period);
1049 if (max_rows && ++nr_rows >= max_rows)
1052 if (h->ms.map == NULL && verbose > 1) {
1053 __map_groups__fprintf_maps(&h->thread->mg,
1054 MAP__FUNCTION, verbose, fp);
1055 fprintf(fp, "%.10s end\n", graph_dotted_line);
1059 free(rem_sq_bracket);
1065 * See hists__fprintf to match the column widths
1067 unsigned int hists__sort_list_width(struct hists *hists)
1069 struct sort_entry *se;
1070 int ret = 9; /* total % */
1072 if (symbol_conf.show_cpu_utilization) {
1073 ret += 7; /* count_sys % */
1074 ret += 6; /* count_us % */
1076 ret += 13; /* count_guest_sys % */
1077 ret += 12; /* count_guest_us % */
1081 if (symbol_conf.show_nr_samples)
1084 if (symbol_conf.show_total_period)
1087 list_for_each_entry(se, &hist_entry__sort_list, list)
1089 ret += 2 + hists__col_len(hists, se->se_width_idx);
1091 if (verbose) /* Addr + origin */
1092 ret += 3 + BITS_PER_LONG / 4;
1097 static void hists__remove_entry_filter(struct hists *hists, struct hist_entry *h,
1098 enum hist_filter filter)
1100 h->filtered &= ~(1 << filter);
1104 ++hists->nr_entries;
1106 hists->nr_entries += h->nr_rows;
1108 hists->stats.total_period += h->period;
1109 hists->stats.nr_events[PERF_RECORD_SAMPLE] += h->nr_events;
1111 hists__calc_col_len(hists, h);
1115 static bool hists__filter_entry_by_dso(struct hists *hists,
1116 struct hist_entry *he)
1118 if (hists->dso_filter != NULL &&
1119 (he->ms.map == NULL || he->ms.map->dso != hists->dso_filter)) {
1120 he->filtered |= (1 << HIST_FILTER__DSO);
1127 void hists__filter_by_dso(struct hists *hists)
1131 hists->nr_entries = hists->stats.total_period = 0;
1132 hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0;
1133 hists__reset_col_len(hists);
1135 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
1136 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
1138 if (symbol_conf.exclude_other && !h->parent)
1141 if (hists__filter_entry_by_dso(hists, h))
1144 hists__remove_entry_filter(hists, h, HIST_FILTER__DSO);
1148 static bool hists__filter_entry_by_thread(struct hists *hists,
1149 struct hist_entry *he)
1151 if (hists->thread_filter != NULL &&
1152 he->thread != hists->thread_filter) {
1153 he->filtered |= (1 << HIST_FILTER__THREAD);
1160 void hists__filter_by_thread(struct hists *hists)
1164 hists->nr_entries = hists->stats.total_period = 0;
1165 hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0;
1166 hists__reset_col_len(hists);
1168 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
1169 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
1171 if (hists__filter_entry_by_thread(hists, h))
1174 hists__remove_entry_filter(hists, h, HIST_FILTER__THREAD);
1178 int hist_entry__inc_addr_samples(struct hist_entry *he, int evidx, u64 ip)
1180 return symbol__inc_addr_samples(he->ms.sym, he->ms.map, evidx, ip);
1183 int hist_entry__annotate(struct hist_entry *he, size_t privsize)
1185 return symbol__annotate(he->ms.sym, he->ms.map, privsize);
1188 void hists__inc_nr_events(struct hists *hists, u32 type)
1190 ++hists->stats.nr_events[0];
1191 ++hists->stats.nr_events[type];
1194 size_t hists__fprintf_nr_events(struct hists *hists, FILE *fp)
1199 for (i = 0; i < PERF_RECORD_HEADER_MAX; ++i) {
1202 if (hists->stats.nr_events[i] == 0)
1205 name = perf_event__name(i);
1206 if (!strcmp(name, "UNKNOWN"))
1209 ret += fprintf(fp, "%16s events: %10d\n", name,
1210 hists->stats.nr_events[i]);
1216 void hists__init(struct hists *hists)
1218 memset(hists, 0, sizeof(*hists));
1219 hists->entries_in_array[0] = hists->entries_in_array[1] = RB_ROOT;
1220 hists->entries_in = &hists->entries_in_array[0];
1221 hists->entries_collapsed = RB_ROOT;
1222 hists->entries = RB_ROOT;
1223 pthread_mutex_init(&hists->lock, NULL);