8 struct callchain_param callchain_param
= {
9 .mode
= CHAIN_GRAPH_REL
,
13 static void hist_entry__add_cpumode_period(struct hist_entry
*self
,
14 unsigned int cpumode
, u64 period
)
17 case PERF_RECORD_MISC_KERNEL
:
18 self
->period_sys
+= period
;
20 case PERF_RECORD_MISC_USER
:
21 self
->period_us
+= period
;
23 case PERF_RECORD_MISC_GUEST_KERNEL
:
24 self
->period_guest_sys
+= period
;
26 case PERF_RECORD_MISC_GUEST_USER
:
27 self
->period_guest_us
+= period
;
35 * histogram, sorted on item, collects periods
38 static struct hist_entry
*hist_entry__new(struct hist_entry
*template)
40 size_t callchain_size
= symbol_conf
.use_callchain
? sizeof(struct callchain_node
) : 0;
41 struct hist_entry
*self
= malloc(sizeof(*self
) + callchain_size
);
46 if (symbol_conf
.use_callchain
)
47 callchain_init(self
->callchain
);
53 static void hists__inc_nr_entries(struct hists
*self
, struct hist_entry
*entry
)
55 if (entry
->ms
.sym
&& self
->max_sym_namelen
< entry
->ms
.sym
->namelen
)
56 self
->max_sym_namelen
= entry
->ms
.sym
->namelen
;
60 struct hist_entry
*__hists__add_entry(struct hists
*self
,
61 struct addr_location
*al
,
62 struct symbol
*sym_parent
, u64 period
)
64 struct rb_node
**p
= &self
->entries
.rb_node
;
65 struct rb_node
*parent
= NULL
;
66 struct hist_entry
*he
;
67 struct hist_entry entry
= {
83 he
= rb_entry(parent
, struct hist_entry
, rb_node
);
85 cmp
= hist_entry__cmp(&entry
, he
);
99 he
= hist_entry__new(&entry
);
102 rb_link_node(&he
->rb_node
, parent
, p
);
103 rb_insert_color(&he
->rb_node
, &self
->entries
);
104 hists__inc_nr_entries(self
, he
);
106 hist_entry__add_cpumode_period(he
, al
->cpumode
, period
);
111 hist_entry__cmp(struct hist_entry
*left
, struct hist_entry
*right
)
113 struct sort_entry
*se
;
116 list_for_each_entry(se
, &hist_entry__sort_list
, list
) {
117 cmp
= se
->se_cmp(left
, right
);
126 hist_entry__collapse(struct hist_entry
*left
, struct hist_entry
*right
)
128 struct sort_entry
*se
;
131 list_for_each_entry(se
, &hist_entry__sort_list
, list
) {
132 int64_t (*f
)(struct hist_entry
*, struct hist_entry
*);
134 f
= se
->se_collapse
?: se
->se_cmp
;
136 cmp
= f(left
, right
);
144 void hist_entry__free(struct hist_entry
*he
)
150 * collapse the histogram
153 static bool collapse__insert_entry(struct rb_root
*root
, struct hist_entry
*he
)
155 struct rb_node
**p
= &root
->rb_node
;
156 struct rb_node
*parent
= NULL
;
157 struct hist_entry
*iter
;
162 iter
= rb_entry(parent
, struct hist_entry
, rb_node
);
164 cmp
= hist_entry__collapse(iter
, he
);
167 iter
->period
+= he
->period
;
168 hist_entry__free(he
);
178 rb_link_node(&he
->rb_node
, parent
, p
);
179 rb_insert_color(&he
->rb_node
, root
);
183 void hists__collapse_resort(struct hists
*self
)
186 struct rb_node
*next
;
187 struct hist_entry
*n
;
189 if (!sort__need_collapse
)
193 next
= rb_first(&self
->entries
);
194 self
->nr_entries
= 0;
195 self
->max_sym_namelen
= 0;
198 n
= rb_entry(next
, struct hist_entry
, rb_node
);
199 next
= rb_next(&n
->rb_node
);
201 rb_erase(&n
->rb_node
, &self
->entries
);
202 if (collapse__insert_entry(&tmp
, n
))
203 hists__inc_nr_entries(self
, n
);
210 * reverse the map, sort on period.
213 static void __hists__insert_output_entry(struct rb_root
*entries
,
214 struct hist_entry
*he
,
215 u64 min_callchain_hits
)
217 struct rb_node
**p
= &entries
->rb_node
;
218 struct rb_node
*parent
= NULL
;
219 struct hist_entry
*iter
;
221 if (symbol_conf
.use_callchain
)
222 callchain_param
.sort(&he
->sorted_chain
, he
->callchain
,
223 min_callchain_hits
, &callchain_param
);
227 iter
= rb_entry(parent
, struct hist_entry
, rb_node
);
229 if (he
->period
> iter
->period
)
235 rb_link_node(&he
->rb_node
, parent
, p
);
236 rb_insert_color(&he
->rb_node
, entries
);
239 void hists__output_resort(struct hists
*self
)
242 struct rb_node
*next
;
243 struct hist_entry
*n
;
244 u64 min_callchain_hits
;
246 min_callchain_hits
= self
->stats
.total_period
* (callchain_param
.min_percent
/ 100);
249 next
= rb_first(&self
->entries
);
251 self
->nr_entries
= 0;
252 self
->max_sym_namelen
= 0;
255 n
= rb_entry(next
, struct hist_entry
, rb_node
);
256 next
= rb_next(&n
->rb_node
);
258 rb_erase(&n
->rb_node
, &self
->entries
);
259 __hists__insert_output_entry(&tmp
, n
, min_callchain_hits
);
260 hists__inc_nr_entries(self
, n
);
266 static size_t callchain__fprintf_left_margin(FILE *fp
, int left_margin
)
269 int ret
= fprintf(fp
, " ");
271 for (i
= 0; i
< left_margin
; i
++)
272 ret
+= fprintf(fp
, " ");
277 static size_t ipchain__fprintf_graph_line(FILE *fp
, int depth
, int depth_mask
,
281 size_t ret
= callchain__fprintf_left_margin(fp
, left_margin
);
283 for (i
= 0; i
< depth
; i
++)
284 if (depth_mask
& (1 << i
))
285 ret
+= fprintf(fp
, "| ");
287 ret
+= fprintf(fp
, " ");
289 ret
+= fprintf(fp
, "\n");
294 static size_t ipchain__fprintf_graph(FILE *fp
, struct callchain_list
*chain
,
295 int depth
, int depth_mask
, int period
,
296 u64 total_samples
, int hits
,
302 ret
+= callchain__fprintf_left_margin(fp
, left_margin
);
303 for (i
= 0; i
< depth
; i
++) {
304 if (depth_mask
& (1 << i
))
305 ret
+= fprintf(fp
, "|");
307 ret
+= fprintf(fp
, " ");
308 if (!period
&& i
== depth
- 1) {
311 percent
= hits
* 100.0 / total_samples
;
312 ret
+= percent_color_fprintf(fp
, "--%2.2f%%-- ", percent
);
314 ret
+= fprintf(fp
, "%s", " ");
317 ret
+= fprintf(fp
, "%s\n", chain
->ms
.sym
->name
);
319 ret
+= fprintf(fp
, "%p\n", (void *)(long)chain
->ip
);
324 static struct symbol
*rem_sq_bracket
;
325 static struct callchain_list rem_hits
;
327 static void init_rem_hits(void)
329 rem_sq_bracket
= malloc(sizeof(*rem_sq_bracket
) + 6);
330 if (!rem_sq_bracket
) {
331 fprintf(stderr
, "Not enough memory to display remaining hits\n");
335 strcpy(rem_sq_bracket
->name
, "[...]");
336 rem_hits
.ms
.sym
= rem_sq_bracket
;
339 static size_t __callchain__fprintf_graph(FILE *fp
, struct callchain_node
*self
,
340 u64 total_samples
, int depth
,
341 int depth_mask
, int left_margin
)
343 struct rb_node
*node
, *next
;
344 struct callchain_node
*child
;
345 struct callchain_list
*chain
;
346 int new_depth_mask
= depth_mask
;
351 uint entries_printed
= 0;
353 if (callchain_param
.mode
== CHAIN_GRAPH_REL
)
354 new_total
= self
->children_hit
;
356 new_total
= total_samples
;
358 remaining
= new_total
;
360 node
= rb_first(&self
->rb_root
);
364 child
= rb_entry(node
, struct callchain_node
, rb_node
);
365 cumul
= cumul_hits(child
);
369 * The depth mask manages the output of pipes that show
370 * the depth. We don't want to keep the pipes of the current
371 * level for the last child of this depth.
372 * Except if we have remaining filtered hits. They will
373 * supersede the last child
375 next
= rb_next(node
);
376 if (!next
&& (callchain_param
.mode
!= CHAIN_GRAPH_REL
|| !remaining
))
377 new_depth_mask
&= ~(1 << (depth
- 1));
380 * But we keep the older depth mask for the line separator
381 * to keep the level link until we reach the last child
383 ret
+= ipchain__fprintf_graph_line(fp
, depth
, depth_mask
,
386 list_for_each_entry(chain
, &child
->val
, list
) {
387 ret
+= ipchain__fprintf_graph(fp
, chain
, depth
,
393 ret
+= __callchain__fprintf_graph(fp
, child
, new_total
,
395 new_depth_mask
| (1 << depth
),
398 if (++entries_printed
== callchain_param
.print_limit
)
402 if (callchain_param
.mode
== CHAIN_GRAPH_REL
&&
403 remaining
&& remaining
!= new_total
) {
408 new_depth_mask
&= ~(1 << (depth
- 1));
410 ret
+= ipchain__fprintf_graph(fp
, &rem_hits
, depth
,
411 new_depth_mask
, 0, new_total
,
412 remaining
, left_margin
);
418 static size_t callchain__fprintf_graph(FILE *fp
, struct callchain_node
*self
,
419 u64 total_samples
, int left_margin
)
421 struct callchain_list
*chain
;
422 bool printed
= false;
425 u32 entries_printed
= 0;
427 list_for_each_entry(chain
, &self
->val
, list
) {
428 if (!i
++ && sort__first_dimension
== SORT_SYM
)
432 ret
+= callchain__fprintf_left_margin(fp
, left_margin
);
433 ret
+= fprintf(fp
, "|\n");
434 ret
+= callchain__fprintf_left_margin(fp
, left_margin
);
435 ret
+= fprintf(fp
, "---");
440 ret
+= callchain__fprintf_left_margin(fp
, left_margin
);
443 ret
+= fprintf(fp
, " %s\n", chain
->ms
.sym
->name
);
445 ret
+= fprintf(fp
, " %p\n", (void *)(long)chain
->ip
);
447 if (++entries_printed
== callchain_param
.print_limit
)
451 ret
+= __callchain__fprintf_graph(fp
, self
, total_samples
, 1, 1, left_margin
);
456 static size_t callchain__fprintf_flat(FILE *fp
, struct callchain_node
*self
,
459 struct callchain_list
*chain
;
465 ret
+= callchain__fprintf_flat(fp
, self
->parent
, total_samples
);
468 list_for_each_entry(chain
, &self
->val
, list
) {
469 if (chain
->ip
>= PERF_CONTEXT_MAX
)
472 ret
+= fprintf(fp
, " %s\n", chain
->ms
.sym
->name
);
474 ret
+= fprintf(fp
, " %p\n",
475 (void *)(long)chain
->ip
);
481 static size_t hist_entry_callchain__fprintf(FILE *fp
, struct hist_entry
*self
,
482 u64 total_samples
, int left_margin
)
484 struct rb_node
*rb_node
;
485 struct callchain_node
*chain
;
487 u32 entries_printed
= 0;
489 rb_node
= rb_first(&self
->sorted_chain
);
493 chain
= rb_entry(rb_node
, struct callchain_node
, rb_node
);
494 percent
= chain
->hit
* 100.0 / total_samples
;
495 switch (callchain_param
.mode
) {
497 ret
+= percent_color_fprintf(fp
, " %6.2f%%\n",
499 ret
+= callchain__fprintf_flat(fp
, chain
, total_samples
);
501 case CHAIN_GRAPH_ABS
: /* Falldown */
502 case CHAIN_GRAPH_REL
:
503 ret
+= callchain__fprintf_graph(fp
, chain
, total_samples
,
509 ret
+= fprintf(fp
, "\n");
510 if (++entries_printed
== callchain_param
.print_limit
)
512 rb_node
= rb_next(rb_node
);
518 int hist_entry__snprintf(struct hist_entry
*self
, char *s
, size_t size
,
519 struct hists
*pair_hists
, bool show_displacement
,
520 long displacement
, bool color
, u64 session_total
)
522 struct sort_entry
*se
;
523 u64 period
, total
, period_sys
, period_us
, period_guest_sys
, period_guest_us
;
524 const char *sep
= symbol_conf
.field_sep
;
527 if (symbol_conf
.exclude_other
&& !self
->parent
)
531 period
= self
->pair
? self
->pair
->period
: 0;
532 total
= pair_hists
->stats
.total_period
;
533 period_sys
= self
->pair
? self
->pair
->period_sys
: 0;
534 period_us
= self
->pair
? self
->pair
->period_us
: 0;
535 period_guest_sys
= self
->pair
? self
->pair
->period_guest_sys
: 0;
536 period_guest_us
= self
->pair
? self
->pair
->period_guest_us
: 0;
538 period
= self
->period
;
539 total
= session_total
;
540 period_sys
= self
->period_sys
;
541 period_us
= self
->period_us
;
542 period_guest_sys
= self
->period_guest_sys
;
543 period_guest_us
= self
->period_guest_us
;
548 ret
= percent_color_snprintf(s
, size
,
549 sep
? "%.2f" : " %6.2f%%",
550 (period
* 100.0) / total
);
552 ret
= snprintf(s
, size
, sep
? "%.2f" : " %6.2f%%",
553 (period
* 100.0) / total
);
554 if (symbol_conf
.show_cpu_utilization
) {
555 ret
+= percent_color_snprintf(s
+ ret
, size
- ret
,
556 sep
? "%.2f" : " %6.2f%%",
557 (period_sys
* 100.0) / total
);
558 ret
+= percent_color_snprintf(s
+ ret
, size
- ret
,
559 sep
? "%.2f" : " %6.2f%%",
560 (period_us
* 100.0) / total
);
562 ret
+= percent_color_snprintf(s
+ ret
,
564 sep
? "%.2f" : " %6.2f%%",
565 (period_guest_sys
* 100.0) /
567 ret
+= percent_color_snprintf(s
+ ret
,
569 sep
? "%.2f" : " %6.2f%%",
570 (period_guest_us
* 100.0) /
575 ret
= snprintf(s
, size
, sep
? "%lld" : "%12lld ", period
);
577 if (symbol_conf
.show_nr_samples
) {
579 ret
+= snprintf(s
+ ret
, size
- ret
, "%c%lld", *sep
, period
);
581 ret
+= snprintf(s
+ ret
, size
- ret
, "%11lld", period
);
586 double old_percent
= 0, new_percent
= 0, diff
;
589 old_percent
= (period
* 100.0) / total
;
590 if (session_total
> 0)
591 new_percent
= (self
->period
* 100.0) / session_total
;
593 diff
= new_percent
- old_percent
;
595 if (fabs(diff
) >= 0.01)
596 snprintf(bf
, sizeof(bf
), "%+4.2F%%", diff
);
598 snprintf(bf
, sizeof(bf
), " ");
601 ret
+= snprintf(s
+ ret
, size
- ret
, "%c%s", *sep
, bf
);
603 ret
+= snprintf(s
+ ret
, size
- ret
, "%11.11s", bf
);
605 if (show_displacement
) {
607 snprintf(bf
, sizeof(bf
), "%+4ld", displacement
);
609 snprintf(bf
, sizeof(bf
), " ");
612 ret
+= snprintf(s
+ ret
, size
- ret
, "%c%s", *sep
, bf
);
614 ret
+= snprintf(s
+ ret
, size
- ret
, "%6.6s", bf
);
618 list_for_each_entry(se
, &hist_entry__sort_list
, list
) {
622 ret
+= snprintf(s
+ ret
, size
- ret
, "%s", sep
?: " ");
623 ret
+= se
->se_snprintf(self
, s
+ ret
, size
- ret
,
624 se
->se_width
? *se
->se_width
: 0);
630 int hist_entry__fprintf(struct hist_entry
*self
, struct hists
*pair_hists
,
631 bool show_displacement
, long displacement
, FILE *fp
,
635 hist_entry__snprintf(self
, bf
, sizeof(bf
), pair_hists
,
636 show_displacement
, displacement
,
637 true, session_total
);
638 return fprintf(fp
, "%s\n", bf
);
641 static size_t hist_entry__fprintf_callchain(struct hist_entry
*self
, FILE *fp
,
646 if (sort__first_dimension
== SORT_COMM
) {
647 struct sort_entry
*se
= list_first_entry(&hist_entry__sort_list
,
649 left_margin
= se
->se_width
? *se
->se_width
: 0;
650 left_margin
-= thread__comm_len(self
->thread
);
653 return hist_entry_callchain__fprintf(fp
, self
, session_total
,
657 size_t hists__fprintf(struct hists
*self
, struct hists
*pair
,
658 bool show_displacement
, FILE *fp
)
660 struct sort_entry
*se
;
663 unsigned long position
= 1;
664 long displacement
= 0;
666 const char *sep
= symbol_conf
.field_sep
;
667 const char *col_width
= symbol_conf
.col_width_list_str
;
671 fprintf(fp
, "# %s", pair
? "Baseline" : "Overhead");
673 if (symbol_conf
.show_nr_samples
) {
675 fprintf(fp
, "%cSamples", *sep
);
677 fputs(" Samples ", fp
);
680 if (symbol_conf
.show_cpu_utilization
) {
682 ret
+= fprintf(fp
, "%csys", *sep
);
683 ret
+= fprintf(fp
, "%cus", *sep
);
685 ret
+= fprintf(fp
, "%cguest sys", *sep
);
686 ret
+= fprintf(fp
, "%cguest us", *sep
);
689 ret
+= fprintf(fp
, " sys ");
690 ret
+= fprintf(fp
, " us ");
692 ret
+= fprintf(fp
, " guest sys ");
693 ret
+= fprintf(fp
, " guest us ");
700 ret
+= fprintf(fp
, "%cDelta", *sep
);
702 ret
+= fprintf(fp
, " Delta ");
704 if (show_displacement
) {
706 ret
+= fprintf(fp
, "%cDisplacement", *sep
);
708 ret
+= fprintf(fp
, " Displ");
712 list_for_each_entry(se
, &hist_entry__sort_list
, list
) {
716 fprintf(fp
, "%c%s", *sep
, se
->se_header
);
719 width
= strlen(se
->se_header
);
721 if (symbol_conf
.col_width_list_str
) {
723 *se
->se_width
= atoi(col_width
);
724 col_width
= strchr(col_width
, ',');
729 width
= *se
->se_width
= max(*se
->se_width
, width
);
731 fprintf(fp
, " %*s", width
, se
->se_header
);
738 fprintf(fp
, "# ........");
739 if (symbol_conf
.show_nr_samples
)
740 fprintf(fp
, " ..........");
742 fprintf(fp
, " ..........");
743 if (show_displacement
)
744 fprintf(fp
, " .....");
746 list_for_each_entry(se
, &hist_entry__sort_list
, list
) {
754 width
= *se
->se_width
;
756 width
= strlen(se
->se_header
);
757 for (i
= 0; i
< width
; i
++)
761 fprintf(fp
, "\n#\n");
764 for (nd
= rb_first(&self
->entries
); nd
; nd
= rb_next(nd
)) {
765 struct hist_entry
*h
= rb_entry(nd
, struct hist_entry
, rb_node
);
767 if (show_displacement
) {
769 displacement
= ((long)h
->pair
->position
-
775 ret
+= hist_entry__fprintf(h
, pair
, show_displacement
,
776 displacement
, fp
, self
->stats
.total_period
);
778 if (symbol_conf
.use_callchain
)
779 ret
+= hist_entry__fprintf_callchain(h
, fp
, self
->stats
.total_period
);
781 if (h
->ms
.map
== NULL
&& verbose
> 1) {
782 __map_groups__fprintf_maps(&h
->thread
->mg
,
783 MAP__FUNCTION
, verbose
, fp
);
784 fprintf(fp
, "%.10s end\n", graph_dotted_line
);
788 free(rem_sq_bracket
);
798 void hists__filter_by_dso(struct hists
*self
, const struct dso
*dso
)
802 self
->nr_entries
= self
->stats
.total_period
= 0;
803 self
->stats
.nr_events
[PERF_RECORD_SAMPLE
] = 0;
804 self
->max_sym_namelen
= 0;
806 for (nd
= rb_first(&self
->entries
); nd
; nd
= rb_next(nd
)) {
807 struct hist_entry
*h
= rb_entry(nd
, struct hist_entry
, rb_node
);
809 if (symbol_conf
.exclude_other
&& !h
->parent
)
812 if (dso
!= NULL
&& (h
->ms
.map
== NULL
|| h
->ms
.map
->dso
!= dso
)) {
813 h
->filtered
|= (1 << HIST_FILTER__DSO
);
817 h
->filtered
&= ~(1 << HIST_FILTER__DSO
);
820 self
->stats
.total_period
+= h
->period
;
821 self
->stats
.nr_events
[PERF_RECORD_SAMPLE
] += h
->nr_events
;
823 self
->max_sym_namelen
< h
->ms
.sym
->namelen
)
824 self
->max_sym_namelen
= h
->ms
.sym
->namelen
;
829 void hists__filter_by_thread(struct hists
*self
, const struct thread
*thread
)
833 self
->nr_entries
= self
->stats
.total_period
= 0;
834 self
->stats
.nr_events
[PERF_RECORD_SAMPLE
] = 0;
835 self
->max_sym_namelen
= 0;
837 for (nd
= rb_first(&self
->entries
); nd
; nd
= rb_next(nd
)) {
838 struct hist_entry
*h
= rb_entry(nd
, struct hist_entry
, rb_node
);
840 if (thread
!= NULL
&& h
->thread
!= thread
) {
841 h
->filtered
|= (1 << HIST_FILTER__THREAD
);
844 h
->filtered
&= ~(1 << HIST_FILTER__THREAD
);
847 self
->stats
.total_period
+= h
->period
;
848 self
->stats
.nr_events
[PERF_RECORD_SAMPLE
] += h
->nr_events
;
850 self
->max_sym_namelen
< h
->ms
.sym
->namelen
)
851 self
->max_sym_namelen
= h
->ms
.sym
->namelen
;
856 static int symbol__alloc_hist(struct symbol
*self
)
858 struct sym_priv
*priv
= symbol__priv(self
);
859 const int size
= (sizeof(*priv
->hist
) +
860 (self
->end
- self
->start
) * sizeof(u64
));
862 priv
->hist
= zalloc(size
);
863 return priv
->hist
== NULL
? -1 : 0;
866 int hist_entry__inc_addr_samples(struct hist_entry
*self
, u64 ip
)
868 unsigned int sym_size
, offset
;
869 struct symbol
*sym
= self
->ms
.sym
;
870 struct sym_priv
*priv
;
873 if (!sym
|| !self
->ms
.map
)
876 priv
= symbol__priv(sym
);
877 if (priv
->hist
== NULL
&& symbol__alloc_hist(sym
) < 0)
880 sym_size
= sym
->end
- sym
->start
;
881 offset
= ip
- sym
->start
;
883 pr_debug3("%s: ip=%#Lx\n", __func__
, self
->ms
.map
->unmap_ip(self
->ms
.map
, ip
));
885 if (offset
>= sym_size
)
892 pr_debug3("%#Lx %s: period++ [ip: %#Lx, %#Lx] => %Ld\n", self
->ms
.sym
->start
,
893 self
->ms
.sym
->name
, ip
, ip
- self
->ms
.sym
->start
, h
->ip
[offset
]);
897 static struct objdump_line
*objdump_line__new(s64 offset
, char *line
)
899 struct objdump_line
*self
= malloc(sizeof(*self
));
902 self
->offset
= offset
;
909 void objdump_line__free(struct objdump_line
*self
)
915 static void objdump__add_line(struct list_head
*head
, struct objdump_line
*line
)
917 list_add_tail(&line
->node
, head
);
920 struct objdump_line
*objdump__get_next_ip_line(struct list_head
*head
,
921 struct objdump_line
*pos
)
923 list_for_each_entry_continue(pos
, head
, node
)
924 if (pos
->offset
>= 0)
930 static int hist_entry__parse_objdump_line(struct hist_entry
*self
, FILE *file
,
931 struct list_head
*head
)
933 struct symbol
*sym
= self
->ms
.sym
;
934 struct objdump_line
*objdump_line
;
935 char *line
= NULL
, *tmp
, *tmp2
, *c
;
937 s64 line_ip
, offset
= -1;
939 if (getline(&line
, &line_len
, file
) < 0)
945 while (line_len
!= 0 && isspace(line
[line_len
- 1]))
946 line
[--line_len
] = '\0';
948 c
= strchr(line
, '\n');
955 * Strip leading spaces:
966 * Parse hexa addresses followed by ':'
968 line_ip
= strtoull(tmp
, &tmp2
, 16);
969 if (*tmp2
!= ':' || tmp
== tmp2
)
974 u64 start
= map__rip_2objdump(self
->ms
.map
, sym
->start
);
975 offset
= line_ip
- start
;
978 objdump_line
= objdump_line__new(offset
, line
);
979 if (objdump_line
== NULL
) {
983 objdump__add_line(head
, objdump_line
);
988 int hist_entry__annotate(struct hist_entry
*self
, struct list_head
*head
)
990 struct symbol
*sym
= self
->ms
.sym
;
991 struct map
*map
= self
->ms
.map
;
992 struct dso
*dso
= map
->dso
;
993 char *filename
= dso__build_id_filename(dso
, NULL
, 0);
994 bool free_filename
= true;
995 char command
[PATH_MAX
* 2];
1000 if (filename
== NULL
) {
1001 if (dso
->has_build_id
) {
1002 pr_err("Can't annotate %s: not enough memory\n",
1007 } else if (readlink(filename
, command
, sizeof(command
)) < 0 ||
1008 strstr(command
, "[kernel.kallsyms]") ||
1009 access(filename
, R_OK
)) {
1013 * If we don't have build-ids or the build-id file isn't in the
1014 * cache, or is just a kallsyms file, well, lets hope that this
1015 * DSO is the same as when 'perf record' ran.
1017 filename
= dso
->long_name
;
1018 free_filename
= false;
1021 if (dso
->origin
== DSO__ORIG_KERNEL
) {
1022 if (dso
->annotate_warned
)
1023 goto out_free_filename
;
1025 dso
->annotate_warned
= 1;
1026 pr_err("Can't annotate %s: No vmlinux file was found in the "
1027 "path\n", sym
->name
);
1028 goto out_free_filename
;
1031 pr_debug("%s: filename=%s, sym=%s, start=%#Lx, end=%#Lx\n", __func__
,
1032 filename
, sym
->name
, map
->unmap_ip(map
, sym
->start
),
1033 map
->unmap_ip(map
, sym
->end
));
1035 len
= sym
->end
- sym
->start
;
1037 pr_debug("annotating [%p] %30s : [%p] %30s\n",
1038 dso
, dso
->long_name
, sym
, sym
->name
);
1040 snprintf(command
, sizeof(command
),
1041 "objdump --start-address=0x%016Lx --stop-address=0x%016Lx -dS -C %s|grep -v %s|expand",
1042 map__rip_2objdump(map
, sym
->start
),
1043 map__rip_2objdump(map
, sym
->end
),
1044 filename
, filename
);
1046 pr_debug("Executing: %s\n", command
);
1048 file
= popen(command
, "r");
1050 goto out_free_filename
;
1053 if (hist_entry__parse_objdump_line(self
, file
, head
) < 0)
1063 void hists__inc_nr_events(struct hists
*self
, u32 type
)
1065 ++self
->stats
.nr_events
[0];
1066 ++self
->stats
.nr_events
[type
];
1069 size_t hists__fprintf_nr_events(struct hists
*self
, FILE *fp
)
1074 for (i
= 0; i
< PERF_RECORD_HEADER_MAX
; ++i
) {
1075 if (!event__name
[i
])
1077 ret
+= fprintf(fp
, "%10s events: %10d\n",
1078 event__name
[i
], self
->stats
.nr_events
[i
]);