15 struct callchain_param callchain_param = {
16 .mode = CHAIN_GRAPH_REL,
21 u16 hists__col_len(struct hists *hists, enum hist_column col)
23 return hists->col_len[col];
26 void hists__set_col_len(struct hists *hists, enum hist_column col, u16 len)
28 hists->col_len[col] = len;
31 bool hists__new_col_len(struct hists *hists, enum hist_column col, u16 len)
33 if (len > hists__col_len(hists, col)) {
34 hists__set_col_len(hists, col, len);
40 static void hists__reset_col_len(struct hists *hists)
44 for (col = 0; col < HISTC_NR_COLS; ++col)
45 hists__set_col_len(hists, col, 0);
48 static void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
53 hists__new_col_len(hists, HISTC_SYMBOL, h->ms.sym->namelen);
55 const unsigned int unresolved_col_width = BITS_PER_LONG / 4;
57 if (hists__col_len(hists, HISTC_DSO) < unresolved_col_width &&
58 !symbol_conf.col_width_list_str && !symbol_conf.field_sep &&
59 !symbol_conf.dso_list)
60 hists__set_col_len(hists, HISTC_DSO,
61 unresolved_col_width);
64 len = thread__comm_len(h->thread);
65 if (hists__new_col_len(hists, HISTC_COMM, len))
66 hists__set_col_len(hists, HISTC_THREAD, len + 6);
69 len = dso__name_len(h->ms.map->dso);
70 hists__new_col_len(hists, HISTC_DSO, len);
74 static void hist_entry__add_cpumode_period(struct hist_entry *self,
75 unsigned int cpumode, u64 period)
78 case PERF_RECORD_MISC_KERNEL:
79 self->period_sys += period;
81 case PERF_RECORD_MISC_USER:
82 self->period_us += period;
84 case PERF_RECORD_MISC_GUEST_KERNEL:
85 self->period_guest_sys += period;
87 case PERF_RECORD_MISC_GUEST_USER:
88 self->period_guest_us += period;
95 static void hist_entry__decay(struct hist_entry *he)
97 he->period = (he->period * 7) / 8;
98 he->nr_events = (he->nr_events * 7) / 8;
101 static bool hists__decay_entry(struct hists *hists, struct hist_entry *he)
105 hists->stats.total_period -= he->period;
106 hist_entry__decay(he);
107 hists->stats.total_period += he->period;
108 return he->period == 0;
111 static void __hists__decay_entries(struct hists *hists, bool zap_user,
112 bool zap_kernel, bool threaded)
114 struct rb_node *next = rb_first(&hists->entries);
115 struct hist_entry *n;
118 n = rb_entry(next, struct hist_entry, rb_node);
119 next = rb_next(&n->rb_node);
121 * We may be annotating this, for instance, so keep it here in
122 * case some it gets new samples, we'll eventually free it when
123 * the user stops browsing and it agains gets fully decayed.
125 if (((zap_user && n->level == '.') ||
126 (zap_kernel && n->level != '.') ||
127 hists__decay_entry(hists, n)) &&
129 rb_erase(&n->rb_node, &hists->entries);
131 if (sort__need_collapse || threaded)
132 rb_erase(&n->rb_node_in, &hists->entries_collapsed);
140 void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel)
142 return __hists__decay_entries(hists, zap_user, zap_kernel, false);
145 void hists__decay_entries_threaded(struct hists *hists,
146 bool zap_user, bool zap_kernel)
148 return __hists__decay_entries(hists, zap_user, zap_kernel, true);
152 * histogram, sorted on item, collects periods
155 static struct hist_entry *hist_entry__new(struct hist_entry *template)
157 size_t callchain_size = symbol_conf.use_callchain ? sizeof(struct callchain_root) : 0;
158 struct hist_entry *self = malloc(sizeof(*self) + callchain_size);
164 self->ms.map->referenced = true;
165 if (symbol_conf.use_callchain)
166 callchain_init(self->callchain);
172 static void hists__inc_nr_entries(struct hists *hists, struct hist_entry *h)
175 hists__calc_col_len(hists, h);
177 hists->stats.total_period += h->period;
181 static u8 symbol__parent_filter(const struct symbol *parent)
183 if (symbol_conf.exclude_other && parent == NULL)
184 return 1 << HIST_FILTER__PARENT;
188 struct hist_entry *__hists__add_entry(struct hists *hists,
189 struct addr_location *al,
190 struct symbol *sym_parent, u64 period)
193 struct rb_node *parent = NULL;
194 struct hist_entry *he;
195 struct hist_entry entry = {
196 .thread = al->thread,
205 .parent = sym_parent,
206 .filtered = symbol__parent_filter(sym_parent),
210 pthread_mutex_lock(&hists->lock);
212 p = &hists->entries_in->rb_node;
216 he = rb_entry(parent, struct hist_entry, rb_node_in);
218 cmp = hist_entry__cmp(&entry, he);
221 he->period += period;
232 he = hist_entry__new(&entry);
236 rb_link_node(&he->rb_node_in, parent, p);
237 rb_insert_color(&he->rb_node_in, hists->entries_in);
239 hist_entry__add_cpumode_period(he, al->cpumode, period);
241 pthread_mutex_unlock(&hists->lock);
246 hist_entry__cmp(struct hist_entry *left, struct hist_entry *right)
248 struct sort_entry *se;
251 list_for_each_entry(se, &hist_entry__sort_list, list) {
252 cmp = se->se_cmp(left, right);
261 hist_entry__collapse(struct hist_entry *left, struct hist_entry *right)
263 struct sort_entry *se;
266 list_for_each_entry(se, &hist_entry__sort_list, list) {
267 int64_t (*f)(struct hist_entry *, struct hist_entry *);
269 f = se->se_collapse ?: se->se_cmp;
271 cmp = f(left, right);
279 void hist_entry__free(struct hist_entry *he)
285 * collapse the histogram
288 static bool hists__collapse_insert_entry(struct hists *hists,
289 struct rb_root *root,
290 struct hist_entry *he)
292 struct rb_node **p = &root->rb_node;
293 struct rb_node *parent = NULL;
294 struct hist_entry *iter;
299 iter = rb_entry(parent, struct hist_entry, rb_node_in);
301 cmp = hist_entry__collapse(iter, he);
304 iter->period += he->period;
305 iter->nr_events += he->nr_events;
306 if (symbol_conf.use_callchain) {
307 callchain_cursor_reset(&hists->callchain_cursor);
308 callchain_merge(&hists->callchain_cursor, iter->callchain,
311 hist_entry__free(he);
321 rb_link_node(&he->rb_node_in, parent, p);
322 rb_insert_color(&he->rb_node_in, root);
326 static struct rb_root *hists__get_rotate_entries_in(struct hists *hists)
328 struct rb_root *root;
330 pthread_mutex_lock(&hists->lock);
332 root = hists->entries_in;
333 if (++hists->entries_in > &hists->entries_in_array[1])
334 hists->entries_in = &hists->entries_in_array[0];
336 pthread_mutex_unlock(&hists->lock);
341 static void __hists__collapse_resort(struct hists *hists, bool threaded)
343 struct rb_root *root;
344 struct rb_node *next;
345 struct hist_entry *n;
347 if (!sort__need_collapse && !threaded)
350 root = hists__get_rotate_entries_in(hists);
351 next = rb_first(root);
352 hists->stats.total_period = 0;
355 n = rb_entry(next, struct hist_entry, rb_node_in);
356 next = rb_next(&n->rb_node_in);
358 rb_erase(&n->rb_node_in, root);
359 if (hists__collapse_insert_entry(hists, &hists->entries_collapsed, n))
360 hists__inc_nr_entries(hists, n);
364 void hists__collapse_resort(struct hists *hists)
366 return __hists__collapse_resort(hists, false);
369 void hists__collapse_resort_threaded(struct hists *hists)
371 return __hists__collapse_resort(hists, true);
375 * reverse the map, sort on period.
378 static void __hists__insert_output_entry(struct rb_root *entries,
379 struct hist_entry *he,
380 u64 min_callchain_hits)
382 struct rb_node **p = &entries->rb_node;
383 struct rb_node *parent = NULL;
384 struct hist_entry *iter;
386 if (symbol_conf.use_callchain)
387 callchain_param.sort(&he->sorted_chain, he->callchain,
388 min_callchain_hits, &callchain_param);
392 iter = rb_entry(parent, struct hist_entry, rb_node);
394 if (he->period > iter->period)
400 rb_link_node(&he->rb_node, parent, p);
401 rb_insert_color(&he->rb_node, entries);
404 static void __hists__output_resort(struct hists *hists, bool threaded)
406 struct rb_root *root;
407 struct rb_node *next;
408 struct hist_entry *n;
409 u64 min_callchain_hits;
411 min_callchain_hits = hists->stats.total_period * (callchain_param.min_percent / 100);
413 if (sort__need_collapse || threaded)
414 root = &hists->entries_collapsed;
416 root = hists->entries_in;
418 next = rb_first(root);
419 hists->entries = RB_ROOT;
421 hists->nr_entries = 0;
422 hists__reset_col_len(hists);
425 n = rb_entry(next, struct hist_entry, rb_node_in);
426 next = rb_next(&n->rb_node_in);
428 __hists__insert_output_entry(&hists->entries, n, min_callchain_hits);
429 hists__inc_nr_entries(hists, n);
433 void hists__output_resort(struct hists *hists)
435 return __hists__output_resort(hists, false);
438 void hists__output_resort_threaded(struct hists *hists)
440 return __hists__output_resort(hists, true);
443 static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin)
446 int ret = fprintf(fp, " ");
448 for (i = 0; i < left_margin; i++)
449 ret += fprintf(fp, " ");
454 static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask,
458 size_t ret = callchain__fprintf_left_margin(fp, left_margin);
460 for (i = 0; i < depth; i++)
461 if (depth_mask & (1 << i))
462 ret += fprintf(fp, "| ");
464 ret += fprintf(fp, " ");
466 ret += fprintf(fp, "\n");
471 static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain,
472 int depth, int depth_mask, int period,
473 u64 total_samples, u64 hits,
479 ret += callchain__fprintf_left_margin(fp, left_margin);
480 for (i = 0; i < depth; i++) {
481 if (depth_mask & (1 << i))
482 ret += fprintf(fp, "|");
484 ret += fprintf(fp, " ");
485 if (!period && i == depth - 1) {
488 percent = hits * 100.0 / total_samples;
489 ret += percent_color_fprintf(fp, "--%2.2f%%-- ", percent);
491 ret += fprintf(fp, "%s", " ");
494 ret += fprintf(fp, "%s\n", chain->ms.sym->name);
496 ret += fprintf(fp, "%p\n", (void *)(long)chain->ip);
501 static struct symbol *rem_sq_bracket;
502 static struct callchain_list rem_hits;
504 static void init_rem_hits(void)
506 rem_sq_bracket = malloc(sizeof(*rem_sq_bracket) + 6);
507 if (!rem_sq_bracket) {
508 fprintf(stderr, "Not enough memory to display remaining hits\n");
512 strcpy(rem_sq_bracket->name, "[...]");
513 rem_hits.ms.sym = rem_sq_bracket;
516 static size_t __callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
517 u64 total_samples, int depth,
518 int depth_mask, int left_margin)
520 struct rb_node *node, *next;
521 struct callchain_node *child;
522 struct callchain_list *chain;
523 int new_depth_mask = depth_mask;
528 uint entries_printed = 0;
530 if (callchain_param.mode == CHAIN_GRAPH_REL)
531 new_total = self->children_hit;
533 new_total = total_samples;
535 remaining = new_total;
537 node = rb_first(&self->rb_root);
541 child = rb_entry(node, struct callchain_node, rb_node);
542 cumul = callchain_cumul_hits(child);
546 * The depth mask manages the output of pipes that show
547 * the depth. We don't want to keep the pipes of the current
548 * level for the last child of this depth.
549 * Except if we have remaining filtered hits. They will
550 * supersede the last child
552 next = rb_next(node);
553 if (!next && (callchain_param.mode != CHAIN_GRAPH_REL || !remaining))
554 new_depth_mask &= ~(1 << (depth - 1));
557 * But we keep the older depth mask for the line separator
558 * to keep the level link until we reach the last child
560 ret += ipchain__fprintf_graph_line(fp, depth, depth_mask,
563 list_for_each_entry(chain, &child->val, list) {
564 ret += ipchain__fprintf_graph(fp, chain, depth,
570 ret += __callchain__fprintf_graph(fp, child, new_total,
572 new_depth_mask | (1 << depth),
575 if (++entries_printed == callchain_param.print_limit)
579 if (callchain_param.mode == CHAIN_GRAPH_REL &&
580 remaining && remaining != new_total) {
585 new_depth_mask &= ~(1 << (depth - 1));
587 ret += ipchain__fprintf_graph(fp, &rem_hits, depth,
588 new_depth_mask, 0, new_total,
589 remaining, left_margin);
595 static size_t callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
596 u64 total_samples, int left_margin)
598 struct callchain_list *chain;
599 bool printed = false;
602 u32 entries_printed = 0;
604 list_for_each_entry(chain, &self->val, list) {
605 if (!i++ && sort__first_dimension == SORT_SYM)
609 ret += callchain__fprintf_left_margin(fp, left_margin);
610 ret += fprintf(fp, "|\n");
611 ret += callchain__fprintf_left_margin(fp, left_margin);
612 ret += fprintf(fp, "---");
617 ret += callchain__fprintf_left_margin(fp, left_margin);
620 ret += fprintf(fp, " %s\n", chain->ms.sym->name);
622 ret += fprintf(fp, " %p\n", (void *)(long)chain->ip);
624 if (++entries_printed == callchain_param.print_limit)
628 ret += __callchain__fprintf_graph(fp, self, total_samples, 1, 1, left_margin);
633 static size_t callchain__fprintf_flat(FILE *fp, struct callchain_node *self,
636 struct callchain_list *chain;
642 ret += callchain__fprintf_flat(fp, self->parent, total_samples);
645 list_for_each_entry(chain, &self->val, list) {
646 if (chain->ip >= PERF_CONTEXT_MAX)
649 ret += fprintf(fp, " %s\n", chain->ms.sym->name);
651 ret += fprintf(fp, " %p\n",
652 (void *)(long)chain->ip);
658 static size_t hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self,
659 u64 total_samples, int left_margin)
661 struct rb_node *rb_node;
662 struct callchain_node *chain;
664 u32 entries_printed = 0;
666 rb_node = rb_first(&self->sorted_chain);
670 chain = rb_entry(rb_node, struct callchain_node, rb_node);
671 percent = chain->hit * 100.0 / total_samples;
672 switch (callchain_param.mode) {
674 ret += percent_color_fprintf(fp, " %6.2f%%\n",
676 ret += callchain__fprintf_flat(fp, chain, total_samples);
678 case CHAIN_GRAPH_ABS: /* Falldown */
679 case CHAIN_GRAPH_REL:
680 ret += callchain__fprintf_graph(fp, chain, total_samples,
686 ret += fprintf(fp, "\n");
687 if (++entries_printed == callchain_param.print_limit)
689 rb_node = rb_next(rb_node);
695 void hists__output_recalc_col_len(struct hists *hists, int max_rows)
697 struct rb_node *next = rb_first(&hists->entries);
698 struct hist_entry *n;
701 hists__reset_col_len(hists);
703 while (next && row++ < max_rows) {
704 n = rb_entry(next, struct hist_entry, rb_node);
705 hists__calc_col_len(hists, n);
706 next = rb_next(&n->rb_node);
710 static int hist_entry__pcnt_snprintf(struct hist_entry *self, char *s,
711 size_t size, struct hists *pair_hists,
712 bool show_displacement, long displacement,
713 bool color, u64 session_total)
715 u64 period, total, period_sys, period_us, period_guest_sys, period_guest_us;
717 const char *sep = symbol_conf.field_sep;
720 if (symbol_conf.exclude_other && !self->parent)
724 period = self->pair ? self->pair->period : 0;
725 nr_events = self->pair ? self->pair->nr_events : 0;
726 total = pair_hists->stats.total_period;
727 period_sys = self->pair ? self->pair->period_sys : 0;
728 period_us = self->pair ? self->pair->period_us : 0;
729 period_guest_sys = self->pair ? self->pair->period_guest_sys : 0;
730 period_guest_us = self->pair ? self->pair->period_guest_us : 0;
732 period = self->period;
733 nr_events = self->nr_events;
734 total = session_total;
735 period_sys = self->period_sys;
736 period_us = self->period_us;
737 period_guest_sys = self->period_guest_sys;
738 period_guest_us = self->period_guest_us;
743 ret = percent_color_snprintf(s, size,
744 sep ? "%.2f" : " %6.2f%%",
745 (period * 100.0) / total);
747 ret = snprintf(s, size, sep ? "%.2f" : " %6.2f%%",
748 (period * 100.0) / total);
749 if (symbol_conf.show_cpu_utilization) {
750 ret += percent_color_snprintf(s + ret, size - ret,
751 sep ? "%.2f" : " %6.2f%%",
752 (period_sys * 100.0) / total);
753 ret += percent_color_snprintf(s + ret, size - ret,
754 sep ? "%.2f" : " %6.2f%%",
755 (period_us * 100.0) / total);
757 ret += percent_color_snprintf(s + ret,
759 sep ? "%.2f" : " %6.2f%%",
760 (period_guest_sys * 100.0) /
762 ret += percent_color_snprintf(s + ret,
764 sep ? "%.2f" : " %6.2f%%",
765 (period_guest_us * 100.0) /
770 ret = snprintf(s, size, sep ? "%" PRIu64 : "%12" PRIu64 " ", period);
772 if (symbol_conf.show_nr_samples) {
774 ret += snprintf(s + ret, size - ret, "%c%" PRIu64, *sep, nr_events);
776 ret += snprintf(s + ret, size - ret, "%11" PRIu64, nr_events);
779 if (symbol_conf.show_total_period) {
781 ret += snprintf(s + ret, size - ret, "%c%" PRIu64, *sep, period);
783 ret += snprintf(s + ret, size - ret, " %12" PRIu64, period);
788 double old_percent = 0, new_percent = 0, diff;
791 old_percent = (period * 100.0) / total;
792 if (session_total > 0)
793 new_percent = (self->period * 100.0) / session_total;
795 diff = new_percent - old_percent;
797 if (fabs(diff) >= 0.01)
798 snprintf(bf, sizeof(bf), "%+4.2F%%", diff);
800 snprintf(bf, sizeof(bf), " ");
803 ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf);
805 ret += snprintf(s + ret, size - ret, "%11.11s", bf);
807 if (show_displacement) {
809 snprintf(bf, sizeof(bf), "%+4ld", displacement);
811 snprintf(bf, sizeof(bf), " ");
814 ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf);
816 ret += snprintf(s + ret, size - ret, "%6.6s", bf);
823 int hist_entry__snprintf(struct hist_entry *he, char *s, size_t size,
826 const char *sep = symbol_conf.field_sep;
827 struct sort_entry *se;
830 list_for_each_entry(se, &hist_entry__sort_list, list) {
834 ret += snprintf(s + ret, size - ret, "%s", sep ?: " ");
835 ret += se->se_snprintf(he, s + ret, size - ret,
836 hists__col_len(hists, se->se_width_idx));
842 int hist_entry__fprintf(struct hist_entry *he, size_t size, struct hists *hists,
843 struct hists *pair_hists, bool show_displacement,
844 long displacement, FILE *fp, u64 session_total)
849 if (size == 0 || size > sizeof(bf))
852 ret = hist_entry__pcnt_snprintf(he, bf, size, pair_hists,
853 show_displacement, displacement,
854 true, session_total);
855 hist_entry__snprintf(he, bf + ret, size - ret, hists);
856 return fprintf(fp, "%s\n", bf);
859 static size_t hist_entry__fprintf_callchain(struct hist_entry *self,
860 struct hists *hists, FILE *fp,
865 if (sort__first_dimension == SORT_COMM) {
866 struct sort_entry *se = list_first_entry(&hist_entry__sort_list,
868 left_margin = hists__col_len(hists, se->se_width_idx);
869 left_margin -= thread__comm_len(self->thread);
872 return hist_entry_callchain__fprintf(fp, self, session_total,
876 size_t hists__fprintf(struct hists *hists, struct hists *pair,
877 bool show_displacement, bool show_header, int max_rows,
878 int max_cols, FILE *fp)
880 struct sort_entry *se;
883 unsigned long position = 1;
884 long displacement = 0;
886 const char *sep = symbol_conf.field_sep;
887 const char *col_width = symbol_conf.col_width_list_str;
895 fprintf(fp, "# %s", pair ? "Baseline" : "Overhead");
897 if (symbol_conf.show_nr_samples) {
899 fprintf(fp, "%cSamples", *sep);
901 fputs(" Samples ", fp);
904 if (symbol_conf.show_total_period) {
906 ret += fprintf(fp, "%cPeriod", *sep);
908 ret += fprintf(fp, " Period ");
911 if (symbol_conf.show_cpu_utilization) {
913 ret += fprintf(fp, "%csys", *sep);
914 ret += fprintf(fp, "%cus", *sep);
916 ret += fprintf(fp, "%cguest sys", *sep);
917 ret += fprintf(fp, "%cguest us", *sep);
920 ret += fprintf(fp, " sys ");
921 ret += fprintf(fp, " us ");
923 ret += fprintf(fp, " guest sys ");
924 ret += fprintf(fp, " guest us ");
931 ret += fprintf(fp, "%cDelta", *sep);
933 ret += fprintf(fp, " Delta ");
935 if (show_displacement) {
937 ret += fprintf(fp, "%cDisplacement", *sep);
939 ret += fprintf(fp, " Displ");
943 list_for_each_entry(se, &hist_entry__sort_list, list) {
947 fprintf(fp, "%c%s", *sep, se->se_header);
950 width = strlen(se->se_header);
951 if (symbol_conf.col_width_list_str) {
953 hists__set_col_len(hists, se->se_width_idx,
955 col_width = strchr(col_width, ',');
960 if (!hists__new_col_len(hists, se->se_width_idx, width))
961 width = hists__col_len(hists, se->se_width_idx);
962 fprintf(fp, " %*s", width, se->se_header);
966 if (max_rows && ++nr_rows >= max_rows)
972 fprintf(fp, "# ........");
973 if (symbol_conf.show_nr_samples)
974 fprintf(fp, " ..........");
975 if (symbol_conf.show_total_period)
976 fprintf(fp, " ............");
978 fprintf(fp, " ..........");
979 if (show_displacement)
980 fprintf(fp, " .....");
982 list_for_each_entry(se, &hist_entry__sort_list, list) {
989 width = hists__col_len(hists, se->se_width_idx);
991 width = strlen(se->se_header);
992 for (i = 0; i < width; i++)
997 if (max_rows && ++nr_rows >= max_rows)
1001 if (max_rows && ++nr_rows >= max_rows)
1005 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
1006 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
1011 if (show_displacement) {
1012 if (h->pair != NULL)
1013 displacement = ((long)h->pair->position -
1019 ret += hist_entry__fprintf(h, max_cols, hists, pair, show_displacement,
1020 displacement, fp, hists->stats.total_period);
1022 if (symbol_conf.use_callchain)
1023 ret += hist_entry__fprintf_callchain(h, hists, fp,
1024 hists->stats.total_period);
1025 if (max_rows && ++nr_rows >= max_rows)
1028 if (h->ms.map == NULL && verbose > 1) {
1029 __map_groups__fprintf_maps(&h->thread->mg,
1030 MAP__FUNCTION, verbose, fp);
1031 fprintf(fp, "%.10s end\n", graph_dotted_line);
1035 free(rem_sq_bracket);
1041 * See hists__fprintf to match the column widths
1043 unsigned int hists__sort_list_width(struct hists *hists)
1045 struct sort_entry *se;
1046 int ret = 9; /* total % */
1048 if (symbol_conf.show_cpu_utilization) {
1049 ret += 7; /* count_sys % */
1050 ret += 6; /* count_us % */
1052 ret += 13; /* count_guest_sys % */
1053 ret += 12; /* count_guest_us % */
1057 if (symbol_conf.show_nr_samples)
1060 if (symbol_conf.show_total_period)
1063 list_for_each_entry(se, &hist_entry__sort_list, list)
1065 ret += 2 + hists__col_len(hists, se->se_width_idx);
1067 if (verbose) /* Addr + origin */
1068 ret += 3 + BITS_PER_LONG / 4;
1073 static void hists__remove_entry_filter(struct hists *hists, struct hist_entry *h,
1074 enum hist_filter filter)
1076 h->filtered &= ~(1 << filter);
1080 ++hists->nr_entries;
1082 hists->nr_entries += h->nr_rows;
1084 hists->stats.total_period += h->period;
1085 hists->stats.nr_events[PERF_RECORD_SAMPLE] += h->nr_events;
1087 hists__calc_col_len(hists, h);
1090 void hists__filter_by_dso(struct hists *hists)
1094 hists->nr_entries = hists->stats.total_period = 0;
1095 hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0;
1096 hists__reset_col_len(hists);
1098 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
1099 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
1101 if (symbol_conf.exclude_other && !h->parent)
1104 if (hists->dso_filter != NULL &&
1105 (h->ms.map == NULL || h->ms.map->dso != hists->dso_filter)) {
1106 h->filtered |= (1 << HIST_FILTER__DSO);
1110 hists__remove_entry_filter(hists, h, HIST_FILTER__DSO);
1114 void hists__filter_by_thread(struct hists *hists)
1118 hists->nr_entries = hists->stats.total_period = 0;
1119 hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0;
1120 hists__reset_col_len(hists);
1122 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
1123 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
1125 if (hists->thread_filter != NULL &&
1126 h->thread != hists->thread_filter) {
1127 h->filtered |= (1 << HIST_FILTER__THREAD);
1131 hists__remove_entry_filter(hists, h, HIST_FILTER__THREAD);
1135 int hist_entry__inc_addr_samples(struct hist_entry *he, int evidx, u64 ip)
1137 return symbol__inc_addr_samples(he->ms.sym, he->ms.map, evidx, ip);
1140 int hist_entry__annotate(struct hist_entry *he, size_t privsize)
1142 return symbol__annotate(he->ms.sym, he->ms.map, privsize);
1145 void hists__inc_nr_events(struct hists *hists, u32 type)
1147 ++hists->stats.nr_events[0];
1148 ++hists->stats.nr_events[type];
1151 size_t hists__fprintf_nr_events(struct hists *hists, FILE *fp)
1156 for (i = 0; i < PERF_RECORD_HEADER_MAX; ++i) {
1159 if (hists->stats.nr_events[i] == 0)
1162 name = perf_event__name(i);
1163 if (!strcmp(name, "UNKNOWN"))
1166 ret += fprintf(fp, "%16s events: %10d\n", name,
1167 hists->stats.nr_events[i]);
1173 void hists__init(struct hists *hists)
1175 memset(hists, 0, sizeof(*hists));
1176 hists->entries_in_array[0] = hists->entries_in_array[1] = RB_ROOT;
1177 hists->entries_in = &hists->entries_in_array[0];
1178 hists->entries_collapsed = RB_ROOT;
1179 hists->entries = RB_ROOT;
1180 pthread_mutex_init(&hists->lock, NULL);