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)
110 hists->stats.total_period -= he->period;
111 hist_entry__decay(he);
112 hists->stats.total_period += he->period;
113 return he->period == 0;
116 static void __hists__decay_entries(struct hists *hists, bool zap_user,
117 bool zap_kernel, bool threaded)
119 struct rb_node *next = rb_first(&hists->entries);
120 struct hist_entry *n;
123 n = rb_entry(next, struct hist_entry, rb_node);
124 next = rb_next(&n->rb_node);
126 * We may be annotating this, for instance, so keep it here in
127 * case some it gets new samples, we'll eventually free it when
128 * the user stops browsing and it agains gets fully decayed.
130 if (((zap_user && n->level == '.') ||
131 (zap_kernel && n->level != '.') ||
132 hists__decay_entry(hists, n)) &&
134 rb_erase(&n->rb_node, &hists->entries);
136 if (sort__need_collapse || threaded)
137 rb_erase(&n->rb_node_in, &hists->entries_collapsed);
145 void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel)
147 return __hists__decay_entries(hists, zap_user, zap_kernel, false);
150 void hists__decay_entries_threaded(struct hists *hists,
151 bool zap_user, bool zap_kernel)
153 return __hists__decay_entries(hists, zap_user, zap_kernel, true);
157 * histogram, sorted on item, collects periods
160 static struct hist_entry *hist_entry__new(struct hist_entry *template)
162 size_t callchain_size = symbol_conf.use_callchain ? sizeof(struct callchain_root) : 0;
163 struct hist_entry *self = malloc(sizeof(*self) + callchain_size);
169 self->ms.map->referenced = true;
170 if (symbol_conf.use_callchain)
171 callchain_init(self->callchain);
177 static void hists__inc_nr_entries(struct hists *hists, struct hist_entry *h)
180 hists__calc_col_len(hists, h);
182 hists->stats.total_period += h->period;
186 static u8 symbol__parent_filter(const struct symbol *parent)
188 if (symbol_conf.exclude_other && parent == NULL)
189 return 1 << HIST_FILTER__PARENT;
193 struct hist_entry *__hists__add_entry(struct hists *hists,
194 struct addr_location *al,
195 struct symbol *sym_parent, u64 period)
198 struct rb_node *parent = NULL;
199 struct hist_entry *he;
200 struct hist_entry entry = {
201 .thread = al->thread,
210 .parent = sym_parent,
211 .filtered = symbol__parent_filter(sym_parent),
215 pthread_mutex_lock(&hists->lock);
217 p = &hists->entries_in->rb_node;
221 he = rb_entry(parent, struct hist_entry, rb_node_in);
223 cmp = hist_entry__cmp(&entry, he);
226 he->period += period;
237 he = hist_entry__new(&entry);
241 rb_link_node(&he->rb_node_in, parent, p);
242 rb_insert_color(&he->rb_node_in, hists->entries_in);
244 hist_entry__add_cpumode_period(he, al->cpumode, period);
246 pthread_mutex_unlock(&hists->lock);
251 hist_entry__cmp(struct hist_entry *left, struct hist_entry *right)
253 struct sort_entry *se;
256 list_for_each_entry(se, &hist_entry__sort_list, list) {
257 cmp = se->se_cmp(left, right);
266 hist_entry__collapse(struct hist_entry *left, struct hist_entry *right)
268 struct sort_entry *se;
271 list_for_each_entry(se, &hist_entry__sort_list, list) {
272 int64_t (*f)(struct hist_entry *, struct hist_entry *);
274 f = se->se_collapse ?: se->se_cmp;
276 cmp = f(left, right);
284 void hist_entry__free(struct hist_entry *he)
290 * collapse the histogram
293 static bool hists__collapse_insert_entry(struct hists *hists,
294 struct rb_root *root,
295 struct hist_entry *he)
297 struct rb_node **p = &root->rb_node;
298 struct rb_node *parent = NULL;
299 struct hist_entry *iter;
304 iter = rb_entry(parent, struct hist_entry, rb_node_in);
306 cmp = hist_entry__collapse(iter, he);
309 iter->period += he->period;
310 iter->nr_events += he->nr_events;
311 if (symbol_conf.use_callchain) {
312 callchain_cursor_reset(&hists->callchain_cursor);
313 callchain_merge(&hists->callchain_cursor, iter->callchain,
316 hist_entry__free(he);
326 rb_link_node(&he->rb_node_in, parent, p);
327 rb_insert_color(&he->rb_node_in, root);
331 static struct rb_root *hists__get_rotate_entries_in(struct hists *hists)
333 struct rb_root *root;
335 pthread_mutex_lock(&hists->lock);
337 root = hists->entries_in;
338 if (++hists->entries_in > &hists->entries_in_array[1])
339 hists->entries_in = &hists->entries_in_array[0];
341 pthread_mutex_unlock(&hists->lock);
346 static void hists__apply_filters(struct hists *hists, struct hist_entry *he)
348 hists__filter_entry_by_dso(hists, he);
349 hists__filter_entry_by_thread(hists, he);
352 static void __hists__collapse_resort(struct hists *hists, bool threaded)
354 struct rb_root *root;
355 struct rb_node *next;
356 struct hist_entry *n;
358 if (!sort__need_collapse && !threaded)
361 root = hists__get_rotate_entries_in(hists);
362 next = rb_first(root);
363 hists->stats.total_period = 0;
366 n = rb_entry(next, struct hist_entry, rb_node_in);
367 next = rb_next(&n->rb_node_in);
369 rb_erase(&n->rb_node_in, root);
370 if (hists__collapse_insert_entry(hists, &hists->entries_collapsed, n)) {
372 * If it wasn't combined with one of the entries already
373 * collapsed, we need to apply the filters that may have
374 * been set by, say, the hist_browser.
376 hists__apply_filters(hists, n);
377 hists__inc_nr_entries(hists, n);
382 void hists__collapse_resort(struct hists *hists)
384 return __hists__collapse_resort(hists, false);
387 void hists__collapse_resort_threaded(struct hists *hists)
389 return __hists__collapse_resort(hists, true);
393 * reverse the map, sort on period.
396 static void __hists__insert_output_entry(struct rb_root *entries,
397 struct hist_entry *he,
398 u64 min_callchain_hits)
400 struct rb_node **p = &entries->rb_node;
401 struct rb_node *parent = NULL;
402 struct hist_entry *iter;
404 if (symbol_conf.use_callchain)
405 callchain_param.sort(&he->sorted_chain, he->callchain,
406 min_callchain_hits, &callchain_param);
410 iter = rb_entry(parent, struct hist_entry, rb_node);
412 if (he->period > iter->period)
418 rb_link_node(&he->rb_node, parent, p);
419 rb_insert_color(&he->rb_node, entries);
422 static void __hists__output_resort(struct hists *hists, bool threaded)
424 struct rb_root *root;
425 struct rb_node *next;
426 struct hist_entry *n;
427 u64 min_callchain_hits;
429 min_callchain_hits = hists->stats.total_period * (callchain_param.min_percent / 100);
431 if (sort__need_collapse || threaded)
432 root = &hists->entries_collapsed;
434 root = hists->entries_in;
436 next = rb_first(root);
437 hists->entries = RB_ROOT;
439 hists->nr_entries = 0;
440 hists__reset_col_len(hists);
443 n = rb_entry(next, struct hist_entry, rb_node_in);
444 next = rb_next(&n->rb_node_in);
446 __hists__insert_output_entry(&hists->entries, n, min_callchain_hits);
447 hists__inc_nr_entries(hists, n);
451 void hists__output_resort(struct hists *hists)
453 return __hists__output_resort(hists, false);
456 void hists__output_resort_threaded(struct hists *hists)
458 return __hists__output_resort(hists, true);
461 static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin)
464 int ret = fprintf(fp, " ");
466 for (i = 0; i < left_margin; i++)
467 ret += fprintf(fp, " ");
472 static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask,
476 size_t ret = callchain__fprintf_left_margin(fp, left_margin);
478 for (i = 0; i < depth; i++)
479 if (depth_mask & (1 << i))
480 ret += fprintf(fp, "| ");
482 ret += fprintf(fp, " ");
484 ret += fprintf(fp, "\n");
489 static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain,
490 int depth, int depth_mask, int period,
491 u64 total_samples, u64 hits,
497 ret += callchain__fprintf_left_margin(fp, left_margin);
498 for (i = 0; i < depth; i++) {
499 if (depth_mask & (1 << i))
500 ret += fprintf(fp, "|");
502 ret += fprintf(fp, " ");
503 if (!period && i == depth - 1) {
506 percent = hits * 100.0 / total_samples;
507 ret += percent_color_fprintf(fp, "--%2.2f%%-- ", percent);
509 ret += fprintf(fp, "%s", " ");
512 ret += fprintf(fp, "%s\n", chain->ms.sym->name);
514 ret += fprintf(fp, "%p\n", (void *)(long)chain->ip);
519 static struct symbol *rem_sq_bracket;
520 static struct callchain_list rem_hits;
522 static void init_rem_hits(void)
524 rem_sq_bracket = malloc(sizeof(*rem_sq_bracket) + 6);
525 if (!rem_sq_bracket) {
526 fprintf(stderr, "Not enough memory to display remaining hits\n");
530 strcpy(rem_sq_bracket->name, "[...]");
531 rem_hits.ms.sym = rem_sq_bracket;
534 static size_t __callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
535 u64 total_samples, int depth,
536 int depth_mask, int left_margin)
538 struct rb_node *node, *next;
539 struct callchain_node *child;
540 struct callchain_list *chain;
541 int new_depth_mask = depth_mask;
546 uint entries_printed = 0;
548 if (callchain_param.mode == CHAIN_GRAPH_REL)
549 new_total = self->children_hit;
551 new_total = total_samples;
553 remaining = new_total;
555 node = rb_first(&self->rb_root);
559 child = rb_entry(node, struct callchain_node, rb_node);
560 cumul = callchain_cumul_hits(child);
564 * The depth mask manages the output of pipes that show
565 * the depth. We don't want to keep the pipes of the current
566 * level for the last child of this depth.
567 * Except if we have remaining filtered hits. They will
568 * supersede the last child
570 next = rb_next(node);
571 if (!next && (callchain_param.mode != CHAIN_GRAPH_REL || !remaining))
572 new_depth_mask &= ~(1 << (depth - 1));
575 * But we keep the older depth mask for the line separator
576 * to keep the level link until we reach the last child
578 ret += ipchain__fprintf_graph_line(fp, depth, depth_mask,
581 list_for_each_entry(chain, &child->val, list) {
582 ret += ipchain__fprintf_graph(fp, chain, depth,
588 ret += __callchain__fprintf_graph(fp, child, new_total,
590 new_depth_mask | (1 << depth),
593 if (++entries_printed == callchain_param.print_limit)
597 if (callchain_param.mode == CHAIN_GRAPH_REL &&
598 remaining && remaining != new_total) {
603 new_depth_mask &= ~(1 << (depth - 1));
605 ret += ipchain__fprintf_graph(fp, &rem_hits, depth,
606 new_depth_mask, 0, new_total,
607 remaining, left_margin);
613 static size_t callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
614 u64 total_samples, int left_margin)
616 struct callchain_list *chain;
617 bool printed = false;
620 u32 entries_printed = 0;
622 list_for_each_entry(chain, &self->val, list) {
623 if (!i++ && sort__first_dimension == SORT_SYM)
627 ret += callchain__fprintf_left_margin(fp, left_margin);
628 ret += fprintf(fp, "|\n");
629 ret += callchain__fprintf_left_margin(fp, left_margin);
630 ret += fprintf(fp, "---");
635 ret += callchain__fprintf_left_margin(fp, left_margin);
638 ret += fprintf(fp, " %s\n", chain->ms.sym->name);
640 ret += fprintf(fp, " %p\n", (void *)(long)chain->ip);
642 if (++entries_printed == callchain_param.print_limit)
646 ret += __callchain__fprintf_graph(fp, self, total_samples, 1, 1, left_margin);
651 static size_t callchain__fprintf_flat(FILE *fp, struct callchain_node *self,
654 struct callchain_list *chain;
660 ret += callchain__fprintf_flat(fp, self->parent, total_samples);
663 list_for_each_entry(chain, &self->val, list) {
664 if (chain->ip >= PERF_CONTEXT_MAX)
667 ret += fprintf(fp, " %s\n", chain->ms.sym->name);
669 ret += fprintf(fp, " %p\n",
670 (void *)(long)chain->ip);
676 static size_t hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self,
677 u64 total_samples, int left_margin)
679 struct rb_node *rb_node;
680 struct callchain_node *chain;
682 u32 entries_printed = 0;
684 rb_node = rb_first(&self->sorted_chain);
688 chain = rb_entry(rb_node, struct callchain_node, rb_node);
689 percent = chain->hit * 100.0 / total_samples;
690 switch (callchain_param.mode) {
692 ret += percent_color_fprintf(fp, " %6.2f%%\n",
694 ret += callchain__fprintf_flat(fp, chain, total_samples);
696 case CHAIN_GRAPH_ABS: /* Falldown */
697 case CHAIN_GRAPH_REL:
698 ret += callchain__fprintf_graph(fp, chain, total_samples,
704 ret += fprintf(fp, "\n");
705 if (++entries_printed == callchain_param.print_limit)
707 rb_node = rb_next(rb_node);
713 void hists__output_recalc_col_len(struct hists *hists, int max_rows)
715 struct rb_node *next = rb_first(&hists->entries);
716 struct hist_entry *n;
719 hists__reset_col_len(hists);
721 while (next && row++ < max_rows) {
722 n = rb_entry(next, struct hist_entry, rb_node);
723 hists__calc_col_len(hists, n);
724 next = rb_next(&n->rb_node);
728 static int hist_entry__pcnt_snprintf(struct hist_entry *self, char *s,
729 size_t size, struct hists *pair_hists,
730 bool show_displacement, long displacement,
731 bool color, u64 session_total)
733 u64 period, total, period_sys, period_us, period_guest_sys, period_guest_us;
735 const char *sep = symbol_conf.field_sep;
738 if (symbol_conf.exclude_other && !self->parent)
742 period = self->pair ? self->pair->period : 0;
743 nr_events = self->pair ? self->pair->nr_events : 0;
744 total = pair_hists->stats.total_period;
745 period_sys = self->pair ? self->pair->period_sys : 0;
746 period_us = self->pair ? self->pair->period_us : 0;
747 period_guest_sys = self->pair ? self->pair->period_guest_sys : 0;
748 period_guest_us = self->pair ? self->pair->period_guest_us : 0;
750 period = self->period;
751 nr_events = self->nr_events;
752 total = session_total;
753 period_sys = self->period_sys;
754 period_us = self->period_us;
755 period_guest_sys = self->period_guest_sys;
756 period_guest_us = self->period_guest_us;
761 ret = percent_color_snprintf(s, size,
762 sep ? "%.2f" : " %6.2f%%",
763 (period * 100.0) / total);
765 ret = snprintf(s, size, sep ? "%.2f" : " %6.2f%%",
766 (period * 100.0) / total);
767 if (symbol_conf.show_cpu_utilization) {
768 ret += percent_color_snprintf(s + ret, size - ret,
769 sep ? "%.2f" : " %6.2f%%",
770 (period_sys * 100.0) / total);
771 ret += percent_color_snprintf(s + ret, size - ret,
772 sep ? "%.2f" : " %6.2f%%",
773 (period_us * 100.0) / total);
775 ret += percent_color_snprintf(s + ret,
777 sep ? "%.2f" : " %6.2f%%",
778 (period_guest_sys * 100.0) /
780 ret += percent_color_snprintf(s + ret,
782 sep ? "%.2f" : " %6.2f%%",
783 (period_guest_us * 100.0) /
788 ret = snprintf(s, size, sep ? "%" PRIu64 : "%12" PRIu64 " ", period);
790 if (symbol_conf.show_nr_samples) {
792 ret += snprintf(s + ret, size - ret, "%c%" PRIu64, *sep, nr_events);
794 ret += snprintf(s + ret, size - ret, "%11" PRIu64, nr_events);
797 if (symbol_conf.show_total_period) {
799 ret += snprintf(s + ret, size - ret, "%c%" PRIu64, *sep, period);
801 ret += snprintf(s + ret, size - ret, " %12" PRIu64, period);
806 double old_percent = 0, new_percent = 0, diff;
809 old_percent = (period * 100.0) / total;
810 if (session_total > 0)
811 new_percent = (self->period * 100.0) / session_total;
813 diff = new_percent - old_percent;
815 if (fabs(diff) >= 0.01)
816 snprintf(bf, sizeof(bf), "%+4.2F%%", diff);
818 snprintf(bf, sizeof(bf), " ");
821 ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf);
823 ret += snprintf(s + ret, size - ret, "%11.11s", bf);
825 if (show_displacement) {
827 snprintf(bf, sizeof(bf), "%+4ld", displacement);
829 snprintf(bf, sizeof(bf), " ");
832 ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf);
834 ret += snprintf(s + ret, size - ret, "%6.6s", bf);
841 int hist_entry__snprintf(struct hist_entry *he, char *s, size_t size,
844 const char *sep = symbol_conf.field_sep;
845 struct sort_entry *se;
848 list_for_each_entry(se, &hist_entry__sort_list, list) {
852 ret += snprintf(s + ret, size - ret, "%s", sep ?: " ");
853 ret += se->se_snprintf(he, s + ret, size - ret,
854 hists__col_len(hists, se->se_width_idx));
860 int hist_entry__fprintf(struct hist_entry *he, size_t size, struct hists *hists,
861 struct hists *pair_hists, bool show_displacement,
862 long displacement, FILE *fp, u64 session_total)
867 if (size == 0 || size > sizeof(bf))
870 ret = hist_entry__pcnt_snprintf(he, bf, size, pair_hists,
871 show_displacement, displacement,
872 true, session_total);
873 hist_entry__snprintf(he, bf + ret, size - ret, hists);
874 return fprintf(fp, "%s\n", bf);
877 static size_t hist_entry__fprintf_callchain(struct hist_entry *self,
878 struct hists *hists, FILE *fp,
883 if (sort__first_dimension == SORT_COMM) {
884 struct sort_entry *se = list_first_entry(&hist_entry__sort_list,
886 left_margin = hists__col_len(hists, se->se_width_idx);
887 left_margin -= thread__comm_len(self->thread);
890 return hist_entry_callchain__fprintf(fp, self, session_total,
894 size_t hists__fprintf(struct hists *hists, struct hists *pair,
895 bool show_displacement, bool show_header, int max_rows,
896 int max_cols, FILE *fp)
898 struct sort_entry *se;
901 unsigned long position = 1;
902 long displacement = 0;
904 const char *sep = symbol_conf.field_sep;
905 const char *col_width = symbol_conf.col_width_list_str;
913 fprintf(fp, "# %s", pair ? "Baseline" : "Overhead");
915 if (symbol_conf.show_nr_samples) {
917 fprintf(fp, "%cSamples", *sep);
919 fputs(" Samples ", fp);
922 if (symbol_conf.show_total_period) {
924 ret += fprintf(fp, "%cPeriod", *sep);
926 ret += fprintf(fp, " Period ");
929 if (symbol_conf.show_cpu_utilization) {
931 ret += fprintf(fp, "%csys", *sep);
932 ret += fprintf(fp, "%cus", *sep);
934 ret += fprintf(fp, "%cguest sys", *sep);
935 ret += fprintf(fp, "%cguest us", *sep);
938 ret += fprintf(fp, " sys ");
939 ret += fprintf(fp, " us ");
941 ret += fprintf(fp, " guest sys ");
942 ret += fprintf(fp, " guest us ");
949 ret += fprintf(fp, "%cDelta", *sep);
951 ret += fprintf(fp, " Delta ");
953 if (show_displacement) {
955 ret += fprintf(fp, "%cDisplacement", *sep);
957 ret += fprintf(fp, " Displ");
961 list_for_each_entry(se, &hist_entry__sort_list, list) {
965 fprintf(fp, "%c%s", *sep, se->se_header);
968 width = strlen(se->se_header);
969 if (symbol_conf.col_width_list_str) {
971 hists__set_col_len(hists, se->se_width_idx,
973 col_width = strchr(col_width, ',');
978 if (!hists__new_col_len(hists, se->se_width_idx, width))
979 width = hists__col_len(hists, se->se_width_idx);
980 fprintf(fp, " %*s", width, se->se_header);
984 if (max_rows && ++nr_rows >= max_rows)
990 fprintf(fp, "# ........");
991 if (symbol_conf.show_nr_samples)
992 fprintf(fp, " ..........");
993 if (symbol_conf.show_total_period)
994 fprintf(fp, " ............");
996 fprintf(fp, " ..........");
997 if (show_displacement)
998 fprintf(fp, " .....");
1000 list_for_each_entry(se, &hist_entry__sort_list, list) {
1007 width = hists__col_len(hists, se->se_width_idx);
1009 width = strlen(se->se_header);
1010 for (i = 0; i < width; i++)
1015 if (max_rows && ++nr_rows >= max_rows)
1019 if (max_rows && ++nr_rows >= max_rows)
1023 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
1024 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
1029 if (show_displacement) {
1030 if (h->pair != NULL)
1031 displacement = ((long)h->pair->position -
1037 ret += hist_entry__fprintf(h, max_cols, hists, pair, show_displacement,
1038 displacement, fp, hists->stats.total_period);
1040 if (symbol_conf.use_callchain)
1041 ret += hist_entry__fprintf_callchain(h, hists, fp,
1042 hists->stats.total_period);
1043 if (max_rows && ++nr_rows >= max_rows)
1046 if (h->ms.map == NULL && verbose > 1) {
1047 __map_groups__fprintf_maps(&h->thread->mg,
1048 MAP__FUNCTION, verbose, fp);
1049 fprintf(fp, "%.10s end\n", graph_dotted_line);
1053 free(rem_sq_bracket);
1059 * See hists__fprintf to match the column widths
1061 unsigned int hists__sort_list_width(struct hists *hists)
1063 struct sort_entry *se;
1064 int ret = 9; /* total % */
1066 if (symbol_conf.show_cpu_utilization) {
1067 ret += 7; /* count_sys % */
1068 ret += 6; /* count_us % */
1070 ret += 13; /* count_guest_sys % */
1071 ret += 12; /* count_guest_us % */
1075 if (symbol_conf.show_nr_samples)
1078 if (symbol_conf.show_total_period)
1081 list_for_each_entry(se, &hist_entry__sort_list, list)
1083 ret += 2 + hists__col_len(hists, se->se_width_idx);
1085 if (verbose) /* Addr + origin */
1086 ret += 3 + BITS_PER_LONG / 4;
1091 static void hists__remove_entry_filter(struct hists *hists, struct hist_entry *h,
1092 enum hist_filter filter)
1094 h->filtered &= ~(1 << filter);
1098 ++hists->nr_entries;
1100 hists->nr_entries += h->nr_rows;
1102 hists->stats.total_period += h->period;
1103 hists->stats.nr_events[PERF_RECORD_SAMPLE] += h->nr_events;
1105 hists__calc_col_len(hists, h);
1109 static bool hists__filter_entry_by_dso(struct hists *hists,
1110 struct hist_entry *he)
1112 if (hists->dso_filter != NULL &&
1113 (he->ms.map == NULL || he->ms.map->dso != hists->dso_filter)) {
1114 he->filtered |= (1 << HIST_FILTER__DSO);
1121 void hists__filter_by_dso(struct hists *hists)
1125 hists->nr_entries = hists->stats.total_period = 0;
1126 hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0;
1127 hists__reset_col_len(hists);
1129 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
1130 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
1132 if (symbol_conf.exclude_other && !h->parent)
1135 if (hists__filter_entry_by_dso(hists, h))
1138 hists__remove_entry_filter(hists, h, HIST_FILTER__DSO);
1142 static bool hists__filter_entry_by_thread(struct hists *hists,
1143 struct hist_entry *he)
1145 if (hists->thread_filter != NULL &&
1146 he->thread != hists->thread_filter) {
1147 he->filtered |= (1 << HIST_FILTER__THREAD);
1154 void hists__filter_by_thread(struct hists *hists)
1158 hists->nr_entries = hists->stats.total_period = 0;
1159 hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0;
1160 hists__reset_col_len(hists);
1162 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
1163 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
1165 if (hists__filter_entry_by_thread(hists, h))
1168 hists__remove_entry_filter(hists, h, HIST_FILTER__THREAD);
1172 int hist_entry__inc_addr_samples(struct hist_entry *he, int evidx, u64 ip)
1174 return symbol__inc_addr_samples(he->ms.sym, he->ms.map, evidx, ip);
1177 int hist_entry__annotate(struct hist_entry *he, size_t privsize)
1179 return symbol__annotate(he->ms.sym, he->ms.map, privsize);
1182 void hists__inc_nr_events(struct hists *hists, u32 type)
1184 ++hists->stats.nr_events[0];
1185 ++hists->stats.nr_events[type];
1188 size_t hists__fprintf_nr_events(struct hists *hists, FILE *fp)
1193 for (i = 0; i < PERF_RECORD_HEADER_MAX; ++i) {
1196 if (hists->stats.nr_events[i] == 0)
1199 name = perf_event__name(i);
1200 if (!strcmp(name, "UNKNOWN"))
1203 ret += fprintf(fp, "%16s events: %10d\n", name,
1204 hists->stats.nr_events[i]);
1210 void hists__init(struct hists *hists)
1212 memset(hists, 0, sizeof(*hists));
1213 hists->entries_in_array[0] = hists->entries_in_array[1] = RB_ROOT;
1214 hists->entries_in = &hists->entries_in_array[0];
1215 hists->entries_collapsed = RB_ROOT;
1216 hists->entries = RB_ROOT;
1217 pthread_mutex_init(&hists->lock, NULL);