14 struct callchain_param callchain_param = {
15 .mode = CHAIN_GRAPH_REL,
19 u16 hists__col_len(struct hists *self, enum hist_column col)
21 return self->col_len[col];
24 void hists__set_col_len(struct hists *self, enum hist_column col, u16 len)
26 self->col_len[col] = len;
29 bool hists__new_col_len(struct hists *self, enum hist_column col, u16 len)
31 if (len > hists__col_len(self, col)) {
32 hists__set_col_len(self, col, len);
38 static void hists__reset_col_len(struct hists *self)
42 for (col = 0; col < HISTC_NR_COLS; ++col)
43 hists__set_col_len(self, col, 0);
46 static void hists__calc_col_len(struct hists *self, struct hist_entry *h)
51 hists__new_col_len(self, HISTC_SYMBOL, h->ms.sym->namelen);
53 len = thread__comm_len(h->thread);
54 if (hists__new_col_len(self, HISTC_COMM, len))
55 hists__set_col_len(self, HISTC_THREAD, len + 6);
58 len = dso__name_len(h->ms.map->dso);
59 hists__new_col_len(self, HISTC_DSO, len);
63 static void hist_entry__add_cpumode_period(struct hist_entry *self,
64 unsigned int cpumode, u64 period)
67 case PERF_RECORD_MISC_KERNEL:
68 self->period_sys += period;
70 case PERF_RECORD_MISC_USER:
71 self->period_us += period;
73 case PERF_RECORD_MISC_GUEST_KERNEL:
74 self->period_guest_sys += period;
76 case PERF_RECORD_MISC_GUEST_USER:
77 self->period_guest_us += period;
85 * histogram, sorted on item, collects periods
88 static struct hist_entry *hist_entry__new(struct hist_entry *template)
90 size_t callchain_size = symbol_conf.use_callchain ? sizeof(struct callchain_root) : 0;
91 struct hist_entry *self = malloc(sizeof(*self) + callchain_size);
97 self->ms.map->referenced = true;
98 if (symbol_conf.use_callchain)
99 callchain_init(self->callchain);
105 static void hists__inc_nr_entries(struct hists *self, struct hist_entry *h)
108 hists__calc_col_len(self, h);
113 static u8 symbol__parent_filter(const struct symbol *parent)
115 if (symbol_conf.exclude_other && parent == NULL)
116 return 1 << HIST_FILTER__PARENT;
120 struct hist_entry *__hists__add_entry(struct hists *self,
121 struct addr_location *al,
122 struct symbol *sym_parent, u64 period)
124 struct rb_node **p = &self->entries.rb_node;
125 struct rb_node *parent = NULL;
126 struct hist_entry *he;
127 struct hist_entry entry = {
128 .thread = al->thread,
137 .parent = sym_parent,
138 .filtered = symbol__parent_filter(sym_parent),
144 he = rb_entry(parent, struct hist_entry, rb_node);
146 cmp = hist_entry__cmp(&entry, he);
149 he->period += period;
160 he = hist_entry__new(&entry);
163 rb_link_node(&he->rb_node, parent, p);
164 rb_insert_color(&he->rb_node, &self->entries);
165 hists__inc_nr_entries(self, he);
167 hist_entry__add_cpumode_period(he, al->cpumode, period);
172 hist_entry__cmp(struct hist_entry *left, struct hist_entry *right)
174 struct sort_entry *se;
177 list_for_each_entry(se, &hist_entry__sort_list, list) {
178 cmp = se->se_cmp(left, right);
187 hist_entry__collapse(struct hist_entry *left, struct hist_entry *right)
189 struct sort_entry *se;
192 list_for_each_entry(se, &hist_entry__sort_list, list) {
193 int64_t (*f)(struct hist_entry *, struct hist_entry *);
195 f = se->se_collapse ?: se->se_cmp;
197 cmp = f(left, right);
205 void hist_entry__free(struct hist_entry *he)
211 * collapse the histogram
214 static bool collapse__insert_entry(struct rb_root *root, struct hist_entry *he)
216 struct rb_node **p = &root->rb_node;
217 struct rb_node *parent = NULL;
218 struct hist_entry *iter;
223 iter = rb_entry(parent, struct hist_entry, rb_node);
225 cmp = hist_entry__collapse(iter, he);
228 iter->period += he->period;
229 if (symbol_conf.use_callchain)
230 callchain_merge(iter->callchain, he->callchain);
231 hist_entry__free(he);
241 rb_link_node(&he->rb_node, parent, p);
242 rb_insert_color(&he->rb_node, root);
246 void hists__collapse_resort(struct hists *self)
249 struct rb_node *next;
250 struct hist_entry *n;
252 if (!sort__need_collapse)
256 next = rb_first(&self->entries);
257 self->nr_entries = 0;
258 hists__reset_col_len(self);
261 n = rb_entry(next, struct hist_entry, rb_node);
262 next = rb_next(&n->rb_node);
264 rb_erase(&n->rb_node, &self->entries);
265 if (collapse__insert_entry(&tmp, n))
266 hists__inc_nr_entries(self, n);
273 * reverse the map, sort on period.
276 static void __hists__insert_output_entry(struct rb_root *entries,
277 struct hist_entry *he,
278 u64 min_callchain_hits)
280 struct rb_node **p = &entries->rb_node;
281 struct rb_node *parent = NULL;
282 struct hist_entry *iter;
284 if (symbol_conf.use_callchain)
285 callchain_param.sort(&he->sorted_chain, he->callchain,
286 min_callchain_hits, &callchain_param);
290 iter = rb_entry(parent, struct hist_entry, rb_node);
292 if (he->period > iter->period)
298 rb_link_node(&he->rb_node, parent, p);
299 rb_insert_color(&he->rb_node, entries);
302 void hists__output_resort(struct hists *self)
305 struct rb_node *next;
306 struct hist_entry *n;
307 u64 min_callchain_hits;
309 min_callchain_hits = self->stats.total_period * (callchain_param.min_percent / 100);
312 next = rb_first(&self->entries);
314 self->nr_entries = 0;
315 hists__reset_col_len(self);
318 n = rb_entry(next, struct hist_entry, rb_node);
319 next = rb_next(&n->rb_node);
321 rb_erase(&n->rb_node, &self->entries);
322 __hists__insert_output_entry(&tmp, n, min_callchain_hits);
323 hists__inc_nr_entries(self, n);
329 static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin)
332 int ret = fprintf(fp, " ");
334 for (i = 0; i < left_margin; i++)
335 ret += fprintf(fp, " ");
340 static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask,
344 size_t ret = callchain__fprintf_left_margin(fp, left_margin);
346 for (i = 0; i < depth; i++)
347 if (depth_mask & (1 << i))
348 ret += fprintf(fp, "| ");
350 ret += fprintf(fp, " ");
352 ret += fprintf(fp, "\n");
357 static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain,
358 int depth, int depth_mask, int period,
359 u64 total_samples, u64 hits,
365 ret += callchain__fprintf_left_margin(fp, left_margin);
366 for (i = 0; i < depth; i++) {
367 if (depth_mask & (1 << i))
368 ret += fprintf(fp, "|");
370 ret += fprintf(fp, " ");
371 if (!period && i == depth - 1) {
374 percent = hits * 100.0 / total_samples;
375 ret += percent_color_fprintf(fp, "--%2.2f%%-- ", percent);
377 ret += fprintf(fp, "%s", " ");
380 ret += fprintf(fp, "%s\n", chain->ms.sym->name);
382 ret += fprintf(fp, "%p\n", (void *)(long)chain->ip);
387 static struct symbol *rem_sq_bracket;
388 static struct callchain_list rem_hits;
390 static void init_rem_hits(void)
392 rem_sq_bracket = malloc(sizeof(*rem_sq_bracket) + 6);
393 if (!rem_sq_bracket) {
394 fprintf(stderr, "Not enough memory to display remaining hits\n");
398 strcpy(rem_sq_bracket->name, "[...]");
399 rem_hits.ms.sym = rem_sq_bracket;
402 static size_t __callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
403 u64 total_samples, int depth,
404 int depth_mask, int left_margin)
406 struct rb_node *node, *next;
407 struct callchain_node *child;
408 struct callchain_list *chain;
409 int new_depth_mask = depth_mask;
414 uint entries_printed = 0;
416 if (callchain_param.mode == CHAIN_GRAPH_REL)
417 new_total = self->children_hit;
419 new_total = total_samples;
421 remaining = new_total;
423 node = rb_first(&self->rb_root);
427 child = rb_entry(node, struct callchain_node, rb_node);
428 cumul = cumul_hits(child);
432 * The depth mask manages the output of pipes that show
433 * the depth. We don't want to keep the pipes of the current
434 * level for the last child of this depth.
435 * Except if we have remaining filtered hits. They will
436 * supersede the last child
438 next = rb_next(node);
439 if (!next && (callchain_param.mode != CHAIN_GRAPH_REL || !remaining))
440 new_depth_mask &= ~(1 << (depth - 1));
443 * But we keep the older depth mask for the line separator
444 * to keep the level link until we reach the last child
446 ret += ipchain__fprintf_graph_line(fp, depth, depth_mask,
449 list_for_each_entry(chain, &child->val, list) {
450 ret += ipchain__fprintf_graph(fp, chain, depth,
456 ret += __callchain__fprintf_graph(fp, child, new_total,
458 new_depth_mask | (1 << depth),
461 if (++entries_printed == callchain_param.print_limit)
465 if (callchain_param.mode == CHAIN_GRAPH_REL &&
466 remaining && remaining != new_total) {
471 new_depth_mask &= ~(1 << (depth - 1));
473 ret += ipchain__fprintf_graph(fp, &rem_hits, depth,
474 new_depth_mask, 0, new_total,
475 remaining, left_margin);
481 static size_t callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
482 u64 total_samples, int left_margin)
484 struct callchain_list *chain;
485 bool printed = false;
488 u32 entries_printed = 0;
490 list_for_each_entry(chain, &self->val, list) {
491 if (!i++ && sort__first_dimension == SORT_SYM)
495 ret += callchain__fprintf_left_margin(fp, left_margin);
496 ret += fprintf(fp, "|\n");
497 ret += callchain__fprintf_left_margin(fp, left_margin);
498 ret += fprintf(fp, "---");
503 ret += callchain__fprintf_left_margin(fp, left_margin);
506 ret += fprintf(fp, " %s\n", chain->ms.sym->name);
508 ret += fprintf(fp, " %p\n", (void *)(long)chain->ip);
510 if (++entries_printed == callchain_param.print_limit)
514 ret += __callchain__fprintf_graph(fp, self, total_samples, 1, 1, left_margin);
519 static size_t callchain__fprintf_flat(FILE *fp, struct callchain_node *self,
522 struct callchain_list *chain;
528 ret += callchain__fprintf_flat(fp, self->parent, total_samples);
531 list_for_each_entry(chain, &self->val, list) {
532 if (chain->ip >= PERF_CONTEXT_MAX)
535 ret += fprintf(fp, " %s\n", chain->ms.sym->name);
537 ret += fprintf(fp, " %p\n",
538 (void *)(long)chain->ip);
544 static size_t hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self,
545 u64 total_samples, int left_margin)
547 struct rb_node *rb_node;
548 struct callchain_node *chain;
550 u32 entries_printed = 0;
552 rb_node = rb_first(&self->sorted_chain);
556 chain = rb_entry(rb_node, struct callchain_node, rb_node);
557 percent = chain->hit * 100.0 / total_samples;
558 switch (callchain_param.mode) {
560 ret += percent_color_fprintf(fp, " %6.2f%%\n",
562 ret += callchain__fprintf_flat(fp, chain, total_samples);
564 case CHAIN_GRAPH_ABS: /* Falldown */
565 case CHAIN_GRAPH_REL:
566 ret += callchain__fprintf_graph(fp, chain, total_samples,
572 ret += fprintf(fp, "\n");
573 if (++entries_printed == callchain_param.print_limit)
575 rb_node = rb_next(rb_node);
581 int hist_entry__snprintf(struct hist_entry *self, char *s, size_t size,
582 struct hists *hists, struct hists *pair_hists,
583 bool show_displacement, long displacement,
584 bool color, u64 session_total)
586 struct sort_entry *se;
587 u64 period, total, period_sys, period_us, period_guest_sys, period_guest_us;
589 const char *sep = symbol_conf.field_sep;
592 if (symbol_conf.exclude_other && !self->parent)
596 period = self->pair ? self->pair->period : 0;
597 nr_events = self->pair ? self->pair->nr_events : 0;
598 total = pair_hists->stats.total_period;
599 period_sys = self->pair ? self->pair->period_sys : 0;
600 period_us = self->pair ? self->pair->period_us : 0;
601 period_guest_sys = self->pair ? self->pair->period_guest_sys : 0;
602 period_guest_us = self->pair ? self->pair->period_guest_us : 0;
604 period = self->period;
605 nr_events = self->nr_events;
606 total = session_total;
607 period_sys = self->period_sys;
608 period_us = self->period_us;
609 period_guest_sys = self->period_guest_sys;
610 period_guest_us = self->period_guest_us;
615 ret = percent_color_snprintf(s, size,
616 sep ? "%.2f" : " %6.2f%%",
617 (period * 100.0) / total);
619 ret = snprintf(s, size, sep ? "%.2f" : " %6.2f%%",
620 (period * 100.0) / total);
621 if (symbol_conf.show_cpu_utilization) {
622 ret += percent_color_snprintf(s + ret, size - ret,
623 sep ? "%.2f" : " %6.2f%%",
624 (period_sys * 100.0) / total);
625 ret += percent_color_snprintf(s + ret, size - ret,
626 sep ? "%.2f" : " %6.2f%%",
627 (period_us * 100.0) / total);
629 ret += percent_color_snprintf(s + ret,
631 sep ? "%.2f" : " %6.2f%%",
632 (period_guest_sys * 100.0) /
634 ret += percent_color_snprintf(s + ret,
636 sep ? "%.2f" : " %6.2f%%",
637 (period_guest_us * 100.0) /
642 ret = snprintf(s, size, sep ? "%" PRIu64 : "%12" PRIu64 " ", period);
644 if (symbol_conf.show_nr_samples) {
646 ret += snprintf(s + ret, size - ret, "%c%" PRIu64, *sep, nr_events);
648 ret += snprintf(s + ret, size - ret, "%11" PRIu64, nr_events);
653 double old_percent = 0, new_percent = 0, diff;
656 old_percent = (period * 100.0) / total;
657 if (session_total > 0)
658 new_percent = (self->period * 100.0) / session_total;
660 diff = new_percent - old_percent;
662 if (fabs(diff) >= 0.01)
663 snprintf(bf, sizeof(bf), "%+4.2F%%", diff);
665 snprintf(bf, sizeof(bf), " ");
668 ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf);
670 ret += snprintf(s + ret, size - ret, "%11.11s", bf);
672 if (show_displacement) {
674 snprintf(bf, sizeof(bf), "%+4ld", displacement);
676 snprintf(bf, sizeof(bf), " ");
679 ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf);
681 ret += snprintf(s + ret, size - ret, "%6.6s", bf);
685 list_for_each_entry(se, &hist_entry__sort_list, list) {
689 ret += snprintf(s + ret, size - ret, "%s", sep ?: " ");
690 ret += se->se_snprintf(self, s + ret, size - ret,
691 hists__col_len(hists, se->se_width_idx));
697 int hist_entry__fprintf(struct hist_entry *self, struct hists *hists,
698 struct hists *pair_hists, bool show_displacement,
699 long displacement, FILE *fp, u64 session_total)
702 hist_entry__snprintf(self, bf, sizeof(bf), hists, pair_hists,
703 show_displacement, displacement,
704 true, session_total);
705 return fprintf(fp, "%s\n", bf);
708 static size_t hist_entry__fprintf_callchain(struct hist_entry *self,
709 struct hists *hists, FILE *fp,
714 if (sort__first_dimension == SORT_COMM) {
715 struct sort_entry *se = list_first_entry(&hist_entry__sort_list,
717 left_margin = hists__col_len(hists, se->se_width_idx);
718 left_margin -= thread__comm_len(self->thread);
721 return hist_entry_callchain__fprintf(fp, self, session_total,
725 size_t hists__fprintf(struct hists *self, struct hists *pair,
726 bool show_displacement, FILE *fp)
728 struct sort_entry *se;
731 unsigned long position = 1;
732 long displacement = 0;
734 const char *sep = symbol_conf.field_sep;
735 const char *col_width = symbol_conf.col_width_list_str;
739 fprintf(fp, "# %s", pair ? "Baseline" : "Overhead");
741 if (symbol_conf.show_nr_samples) {
743 fprintf(fp, "%cSamples", *sep);
745 fputs(" Samples ", fp);
748 if (symbol_conf.show_cpu_utilization) {
750 ret += fprintf(fp, "%csys", *sep);
751 ret += fprintf(fp, "%cus", *sep);
753 ret += fprintf(fp, "%cguest sys", *sep);
754 ret += fprintf(fp, "%cguest us", *sep);
757 ret += fprintf(fp, " sys ");
758 ret += fprintf(fp, " us ");
760 ret += fprintf(fp, " guest sys ");
761 ret += fprintf(fp, " guest us ");
768 ret += fprintf(fp, "%cDelta", *sep);
770 ret += fprintf(fp, " Delta ");
772 if (show_displacement) {
774 ret += fprintf(fp, "%cDisplacement", *sep);
776 ret += fprintf(fp, " Displ");
780 list_for_each_entry(se, &hist_entry__sort_list, list) {
784 fprintf(fp, "%c%s", *sep, se->se_header);
787 width = strlen(se->se_header);
788 if (symbol_conf.col_width_list_str) {
790 hists__set_col_len(self, se->se_width_idx,
792 col_width = strchr(col_width, ',');
797 if (!hists__new_col_len(self, se->se_width_idx, width))
798 width = hists__col_len(self, se->se_width_idx);
799 fprintf(fp, " %*s", width, se->se_header);
806 fprintf(fp, "# ........");
807 if (symbol_conf.show_nr_samples)
808 fprintf(fp, " ..........");
810 fprintf(fp, " ..........");
811 if (show_displacement)
812 fprintf(fp, " .....");
814 list_for_each_entry(se, &hist_entry__sort_list, list) {
821 width = hists__col_len(self, se->se_width_idx);
823 width = strlen(se->se_header);
824 for (i = 0; i < width; i++)
828 fprintf(fp, "\n#\n");
831 for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) {
832 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
834 if (show_displacement) {
836 displacement = ((long)h->pair->position -
842 ret += hist_entry__fprintf(h, self, pair, show_displacement,
843 displacement, fp, self->stats.total_period);
845 if (symbol_conf.use_callchain)
846 ret += hist_entry__fprintf_callchain(h, self, fp,
847 self->stats.total_period);
848 if (h->ms.map == NULL && verbose > 1) {
849 __map_groups__fprintf_maps(&h->thread->mg,
850 MAP__FUNCTION, verbose, fp);
851 fprintf(fp, "%.10s end\n", graph_dotted_line);
855 free(rem_sq_bracket);
861 * See hists__fprintf to match the column widths
863 unsigned int hists__sort_list_width(struct hists *self)
865 struct sort_entry *se;
866 int ret = 9; /* total % */
868 if (symbol_conf.show_cpu_utilization) {
869 ret += 7; /* count_sys % */
870 ret += 6; /* count_us % */
872 ret += 13; /* count_guest_sys % */
873 ret += 12; /* count_guest_us % */
877 if (symbol_conf.show_nr_samples)
880 list_for_each_entry(se, &hist_entry__sort_list, list)
882 ret += 2 + hists__col_len(self, se->se_width_idx);
884 if (verbose) /* Addr + origin */
885 ret += 3 + BITS_PER_LONG / 4;
890 static void hists__remove_entry_filter(struct hists *self, struct hist_entry *h,
891 enum hist_filter filter)
893 h->filtered &= ~(1 << filter);
899 self->nr_entries += h->nr_rows;
901 self->stats.total_period += h->period;
902 self->stats.nr_events[PERF_RECORD_SAMPLE] += h->nr_events;
904 hists__calc_col_len(self, h);
907 void hists__filter_by_dso(struct hists *self, const struct dso *dso)
911 self->nr_entries = self->stats.total_period = 0;
912 self->stats.nr_events[PERF_RECORD_SAMPLE] = 0;
913 hists__reset_col_len(self);
915 for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) {
916 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
918 if (symbol_conf.exclude_other && !h->parent)
921 if (dso != NULL && (h->ms.map == NULL || h->ms.map->dso != dso)) {
922 h->filtered |= (1 << HIST_FILTER__DSO);
926 hists__remove_entry_filter(self, h, HIST_FILTER__DSO);
930 void hists__filter_by_thread(struct hists *self, const struct thread *thread)
934 self->nr_entries = self->stats.total_period = 0;
935 self->stats.nr_events[PERF_RECORD_SAMPLE] = 0;
936 hists__reset_col_len(self);
938 for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) {
939 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
941 if (thread != NULL && h->thread != thread) {
942 h->filtered |= (1 << HIST_FILTER__THREAD);
946 hists__remove_entry_filter(self, h, HIST_FILTER__THREAD);
950 static int symbol__alloc_hist(struct symbol *self)
952 struct sym_priv *priv = symbol__priv(self);
953 const int size = (sizeof(*priv->hist) +
954 (self->end - self->start) * sizeof(u64));
956 priv->hist = zalloc(size);
957 return priv->hist == NULL ? -1 : 0;
960 int hist_entry__inc_addr_samples(struct hist_entry *self, u64 ip)
962 unsigned int sym_size, offset;
963 struct symbol *sym = self->ms.sym;
964 struct sym_priv *priv;
967 if (!sym || !self->ms.map)
970 priv = symbol__priv(sym);
971 if (priv->hist == NULL && symbol__alloc_hist(sym) < 0)
974 sym_size = sym->end - sym->start;
975 offset = ip - sym->start;
977 pr_debug3("%s: ip=%#" PRIx64 "\n", __func__, self->ms.map->unmap_ip(self->ms.map, ip));
979 if (offset >= sym_size)
986 pr_debug3("%#" PRIx64 " %s: period++ [ip: %#" PRIx64 ", %#" PRIx64
987 "] => %" PRIu64 "\n", self->ms.sym->start, self->ms.sym->name,
988 ip, ip - self->ms.sym->start, h->ip[offset]);
992 static struct objdump_line *objdump_line__new(s64 offset, char *line, size_t privsize)
994 struct objdump_line *self = malloc(sizeof(*self) + privsize);
997 self->offset = offset;
1004 void objdump_line__free(struct objdump_line *self)
1010 static void objdump__add_line(struct list_head *head, struct objdump_line *line)
1012 list_add_tail(&line->node, head);
1015 struct objdump_line *objdump__get_next_ip_line(struct list_head *head,
1016 struct objdump_line *pos)
1018 list_for_each_entry_continue(pos, head, node)
1019 if (pos->offset >= 0)
1025 static int hist_entry__parse_objdump_line(struct hist_entry *self, FILE *file,
1026 struct list_head *head, size_t privsize)
1028 struct symbol *sym = self->ms.sym;
1029 struct objdump_line *objdump_line;
1030 char *line = NULL, *tmp, *tmp2, *c;
1032 s64 line_ip, offset = -1;
1034 if (getline(&line, &line_len, file) < 0)
1040 while (line_len != 0 && isspace(line[line_len - 1]))
1041 line[--line_len] = '\0';
1043 c = strchr(line, '\n');
1050 * Strip leading spaces:
1061 * Parse hexa addresses followed by ':'
1063 line_ip = strtoull(tmp, &tmp2, 16);
1064 if (*tmp2 != ':' || tmp == tmp2 || tmp2[1] == '\0')
1068 if (line_ip != -1) {
1069 u64 start = map__rip_2objdump(self->ms.map, sym->start),
1070 end = map__rip_2objdump(self->ms.map, sym->end);
1072 offset = line_ip - start;
1073 if (offset < 0 || (u64)line_ip > end)
1077 objdump_line = objdump_line__new(offset, line, privsize);
1078 if (objdump_line == NULL) {
1082 objdump__add_line(head, objdump_line);
1087 int hist_entry__annotate(struct hist_entry *self, struct list_head *head,
1090 struct symbol *sym = self->ms.sym;
1091 struct map *map = self->ms.map;
1092 struct dso *dso = map->dso;
1093 char *filename = dso__build_id_filename(dso, NULL, 0);
1094 bool free_filename = true;
1095 char command[PATH_MAX * 2];
1099 char symfs_filename[PATH_MAX];
1102 snprintf(symfs_filename, sizeof(symfs_filename), "%s%s",
1103 symbol_conf.symfs, filename);
1106 if (filename == NULL) {
1107 if (dso->has_build_id) {
1108 pr_err("Can't annotate %s: not enough memory\n",
1113 } else if (readlink(symfs_filename, command, sizeof(command)) < 0 ||
1114 strstr(command, "[kernel.kallsyms]") ||
1115 access(symfs_filename, R_OK)) {
1119 * If we don't have build-ids or the build-id file isn't in the
1120 * cache, or is just a kallsyms file, well, lets hope that this
1121 * DSO is the same as when 'perf record' ran.
1123 filename = dso->long_name;
1124 snprintf(symfs_filename, sizeof(symfs_filename), "%s%s",
1125 symbol_conf.symfs, filename);
1126 free_filename = false;
1129 if (dso->origin == DSO__ORIG_KERNEL) {
1130 if (dso->annotate_warned)
1131 goto out_free_filename;
1133 dso->annotate_warned = 1;
1134 pr_err("Can't annotate %s: No vmlinux file was found in the "
1135 "path\n", sym->name);
1136 goto out_free_filename;
1139 pr_debug("%s: filename=%s, sym=%s, start=%#" PRIx64 ", end=%#" PRIx64 "\n", __func__,
1140 filename, sym->name, map->unmap_ip(map, sym->start),
1141 map->unmap_ip(map, sym->end));
1143 len = sym->end - sym->start;
1145 pr_debug("annotating [%p] %30s : [%p] %30s\n",
1146 dso, dso->long_name, sym, sym->name);
1148 snprintf(command, sizeof(command),
1149 "objdump --start-address=0x%016" PRIx64 " --stop-address=0x%016" PRIx64 " -dS -C %s|grep -v %s|expand",
1150 map__rip_2objdump(map, sym->start),
1151 map__rip_2objdump(map, sym->end),
1152 symfs_filename, filename);
1154 pr_debug("Executing: %s\n", command);
1156 file = popen(command, "r");
1158 goto out_free_filename;
1161 if (hist_entry__parse_objdump_line(self, file, head, privsize) < 0)
1171 void hists__inc_nr_events(struct hists *self, u32 type)
1173 ++self->stats.nr_events[0];
1174 ++self->stats.nr_events[type];
1177 size_t hists__fprintf_nr_events(struct hists *self, FILE *fp)
1182 for (i = 0; i < PERF_RECORD_HEADER_MAX; ++i) {
1183 const char *name = event__get_event_name(i);
1185 if (!strcmp(name, "UNKNOWN"))
1188 ret += fprintf(fp, "%16s events: %10d\n", name,
1189 self->stats.nr_events[i]);