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
= {
82 he
= rb_entry(parent
, struct hist_entry
, rb_node
);
84 cmp
= hist_entry__cmp(&entry
, he
);
98 he
= hist_entry__new(&entry
);
101 rb_link_node(&he
->rb_node
, parent
, p
);
102 rb_insert_color(&he
->rb_node
, &self
->entries
);
103 hists__inc_nr_entries(self
, he
);
105 hist_entry__add_cpumode_period(he
, al
->cpumode
, period
);
110 hist_entry__cmp(struct hist_entry
*left
, struct hist_entry
*right
)
112 struct sort_entry
*se
;
115 list_for_each_entry(se
, &hist_entry__sort_list
, list
) {
116 cmp
= se
->se_cmp(left
, right
);
125 hist_entry__collapse(struct hist_entry
*left
, struct hist_entry
*right
)
127 struct sort_entry
*se
;
130 list_for_each_entry(se
, &hist_entry__sort_list
, list
) {
131 int64_t (*f
)(struct hist_entry
*, struct hist_entry
*);
133 f
= se
->se_collapse
?: se
->se_cmp
;
135 cmp
= f(left
, right
);
143 void hist_entry__free(struct hist_entry
*he
)
149 * collapse the histogram
152 static bool collapse__insert_entry(struct rb_root
*root
, struct hist_entry
*he
)
154 struct rb_node
**p
= &root
->rb_node
;
155 struct rb_node
*parent
= NULL
;
156 struct hist_entry
*iter
;
161 iter
= rb_entry(parent
, struct hist_entry
, rb_node
);
163 cmp
= hist_entry__collapse(iter
, he
);
166 iter
->period
+= he
->period
;
167 hist_entry__free(he
);
177 rb_link_node(&he
->rb_node
, parent
, p
);
178 rb_insert_color(&he
->rb_node
, root
);
182 void hists__collapse_resort(struct hists
*self
)
185 struct rb_node
*next
;
186 struct hist_entry
*n
;
188 if (!sort__need_collapse
)
192 next
= rb_first(&self
->entries
);
193 self
->nr_entries
= 0;
194 self
->max_sym_namelen
= 0;
197 n
= rb_entry(next
, struct hist_entry
, rb_node
);
198 next
= rb_next(&n
->rb_node
);
200 rb_erase(&n
->rb_node
, &self
->entries
);
201 if (collapse__insert_entry(&tmp
, n
))
202 hists__inc_nr_entries(self
, n
);
209 * reverse the map, sort on period.
212 static void __hists__insert_output_entry(struct rb_root
*entries
,
213 struct hist_entry
*he
,
214 u64 min_callchain_hits
)
216 struct rb_node
**p
= &entries
->rb_node
;
217 struct rb_node
*parent
= NULL
;
218 struct hist_entry
*iter
;
220 if (symbol_conf
.use_callchain
)
221 callchain_param
.sort(&he
->sorted_chain
, he
->callchain
,
222 min_callchain_hits
, &callchain_param
);
226 iter
= rb_entry(parent
, struct hist_entry
, rb_node
);
228 if (he
->period
> iter
->period
)
234 rb_link_node(&he
->rb_node
, parent
, p
);
235 rb_insert_color(&he
->rb_node
, entries
);
238 void hists__output_resort(struct hists
*self
)
241 struct rb_node
*next
;
242 struct hist_entry
*n
;
243 u64 min_callchain_hits
;
245 min_callchain_hits
= self
->stats
.total_period
* (callchain_param
.min_percent
/ 100);
248 next
= rb_first(&self
->entries
);
250 self
->nr_entries
= 0;
251 self
->max_sym_namelen
= 0;
254 n
= rb_entry(next
, struct hist_entry
, rb_node
);
255 next
= rb_next(&n
->rb_node
);
257 rb_erase(&n
->rb_node
, &self
->entries
);
258 __hists__insert_output_entry(&tmp
, n
, min_callchain_hits
);
259 hists__inc_nr_entries(self
, n
);
265 static size_t callchain__fprintf_left_margin(FILE *fp
, int left_margin
)
268 int ret
= fprintf(fp
, " ");
270 for (i
= 0; i
< left_margin
; i
++)
271 ret
+= fprintf(fp
, " ");
276 static size_t ipchain__fprintf_graph_line(FILE *fp
, int depth
, int depth_mask
,
280 size_t ret
= callchain__fprintf_left_margin(fp
, left_margin
);
282 for (i
= 0; i
< depth
; i
++)
283 if (depth_mask
& (1 << i
))
284 ret
+= fprintf(fp
, "| ");
286 ret
+= fprintf(fp
, " ");
288 ret
+= fprintf(fp
, "\n");
293 static size_t ipchain__fprintf_graph(FILE *fp
, struct callchain_list
*chain
,
294 int depth
, int depth_mask
, int period
,
295 u64 total_samples
, int hits
,
301 ret
+= callchain__fprintf_left_margin(fp
, left_margin
);
302 for (i
= 0; i
< depth
; i
++) {
303 if (depth_mask
& (1 << i
))
304 ret
+= fprintf(fp
, "|");
306 ret
+= fprintf(fp
, " ");
307 if (!period
&& i
== depth
- 1) {
310 percent
= hits
* 100.0 / total_samples
;
311 ret
+= percent_color_fprintf(fp
, "--%2.2f%%-- ", percent
);
313 ret
+= fprintf(fp
, "%s", " ");
316 ret
+= fprintf(fp
, "%s\n", chain
->ms
.sym
->name
);
318 ret
+= fprintf(fp
, "%p\n", (void *)(long)chain
->ip
);
323 static struct symbol
*rem_sq_bracket
;
324 static struct callchain_list rem_hits
;
326 static void init_rem_hits(void)
328 rem_sq_bracket
= malloc(sizeof(*rem_sq_bracket
) + 6);
329 if (!rem_sq_bracket
) {
330 fprintf(stderr
, "Not enough memory to display remaining hits\n");
334 strcpy(rem_sq_bracket
->name
, "[...]");
335 rem_hits
.ms
.sym
= rem_sq_bracket
;
338 static size_t __callchain__fprintf_graph(FILE *fp
, struct callchain_node
*self
,
339 u64 total_samples
, int depth
,
340 int depth_mask
, int left_margin
)
342 struct rb_node
*node
, *next
;
343 struct callchain_node
*child
;
344 struct callchain_list
*chain
;
345 int new_depth_mask
= depth_mask
;
350 uint entries_printed
= 0;
352 if (callchain_param
.mode
== CHAIN_GRAPH_REL
)
353 new_total
= self
->children_hit
;
355 new_total
= total_samples
;
357 remaining
= new_total
;
359 node
= rb_first(&self
->rb_root
);
363 child
= rb_entry(node
, struct callchain_node
, rb_node
);
364 cumul
= cumul_hits(child
);
368 * The depth mask manages the output of pipes that show
369 * the depth. We don't want to keep the pipes of the current
370 * level for the last child of this depth.
371 * Except if we have remaining filtered hits. They will
372 * supersede the last child
374 next
= rb_next(node
);
375 if (!next
&& (callchain_param
.mode
!= CHAIN_GRAPH_REL
|| !remaining
))
376 new_depth_mask
&= ~(1 << (depth
- 1));
379 * But we keep the older depth mask for the line separator
380 * to keep the level link until we reach the last child
382 ret
+= ipchain__fprintf_graph_line(fp
, depth
, depth_mask
,
385 list_for_each_entry(chain
, &child
->val
, list
) {
386 ret
+= ipchain__fprintf_graph(fp
, chain
, depth
,
392 ret
+= __callchain__fprintf_graph(fp
, child
, new_total
,
394 new_depth_mask
| (1 << depth
),
397 if (++entries_printed
== callchain_param
.print_limit
)
401 if (callchain_param
.mode
== CHAIN_GRAPH_REL
&&
402 remaining
&& remaining
!= new_total
) {
407 new_depth_mask
&= ~(1 << (depth
- 1));
409 ret
+= ipchain__fprintf_graph(fp
, &rem_hits
, depth
,
410 new_depth_mask
, 0, new_total
,
411 remaining
, left_margin
);
417 static size_t callchain__fprintf_graph(FILE *fp
, struct callchain_node
*self
,
418 u64 total_samples
, int left_margin
)
420 struct callchain_list
*chain
;
421 bool printed
= false;
424 u32 entries_printed
= 0;
426 list_for_each_entry(chain
, &self
->val
, list
) {
427 if (!i
++ && sort__first_dimension
== SORT_SYM
)
431 ret
+= callchain__fprintf_left_margin(fp
, left_margin
);
432 ret
+= fprintf(fp
, "|\n");
433 ret
+= callchain__fprintf_left_margin(fp
, left_margin
);
434 ret
+= fprintf(fp
, "---");
439 ret
+= callchain__fprintf_left_margin(fp
, left_margin
);
442 ret
+= fprintf(fp
, " %s\n", chain
->ms
.sym
->name
);
444 ret
+= fprintf(fp
, " %p\n", (void *)(long)chain
->ip
);
446 if (++entries_printed
== callchain_param
.print_limit
)
450 ret
+= __callchain__fprintf_graph(fp
, self
, total_samples
, 1, 1, left_margin
);
455 static size_t callchain__fprintf_flat(FILE *fp
, struct callchain_node
*self
,
458 struct callchain_list
*chain
;
464 ret
+= callchain__fprintf_flat(fp
, self
->parent
, total_samples
);
467 list_for_each_entry(chain
, &self
->val
, list
) {
468 if (chain
->ip
>= PERF_CONTEXT_MAX
)
471 ret
+= fprintf(fp
, " %s\n", chain
->ms
.sym
->name
);
473 ret
+= fprintf(fp
, " %p\n",
474 (void *)(long)chain
->ip
);
480 static size_t hist_entry_callchain__fprintf(FILE *fp
, struct hist_entry
*self
,
481 u64 total_samples
, int left_margin
)
483 struct rb_node
*rb_node
;
484 struct callchain_node
*chain
;
486 u32 entries_printed
= 0;
488 rb_node
= rb_first(&self
->sorted_chain
);
492 chain
= rb_entry(rb_node
, struct callchain_node
, rb_node
);
493 percent
= chain
->hit
* 100.0 / total_samples
;
494 switch (callchain_param
.mode
) {
496 ret
+= percent_color_fprintf(fp
, " %6.2f%%\n",
498 ret
+= callchain__fprintf_flat(fp
, chain
, total_samples
);
500 case CHAIN_GRAPH_ABS
: /* Falldown */
501 case CHAIN_GRAPH_REL
:
502 ret
+= callchain__fprintf_graph(fp
, chain
, total_samples
,
508 ret
+= fprintf(fp
, "\n");
509 if (++entries_printed
== callchain_param
.print_limit
)
511 rb_node
= rb_next(rb_node
);
517 int hist_entry__snprintf(struct hist_entry
*self
, char *s
, size_t size
,
518 struct hists
*pair_hists
, bool show_displacement
,
519 long displacement
, bool color
, u64 session_total
)
521 struct sort_entry
*se
;
522 u64 period
, total
, period_sys
, period_us
, period_guest_sys
, period_guest_us
;
523 const char *sep
= symbol_conf
.field_sep
;
526 if (symbol_conf
.exclude_other
&& !self
->parent
)
530 period
= self
->pair
? self
->pair
->period
: 0;
531 total
= pair_hists
->stats
.total_period
;
532 period_sys
= self
->pair
? self
->pair
->period_sys
: 0;
533 period_us
= self
->pair
? self
->pair
->period_us
: 0;
534 period_guest_sys
= self
->pair
? self
->pair
->period_guest_sys
: 0;
535 period_guest_us
= self
->pair
? self
->pair
->period_guest_us
: 0;
537 period
= self
->period
;
538 total
= session_total
;
539 period_sys
= self
->period_sys
;
540 period_us
= self
->period_us
;
541 period_guest_sys
= self
->period_guest_sys
;
542 period_guest_us
= self
->period_guest_us
;
547 ret
= percent_color_snprintf(s
, size
,
548 sep
? "%.2f" : " %6.2f%%",
549 (period
* 100.0) / total
);
551 ret
= snprintf(s
, size
, sep
? "%.2f" : " %6.2f%%",
552 (period
* 100.0) / total
);
553 if (symbol_conf
.show_cpu_utilization
) {
554 ret
+= percent_color_snprintf(s
+ ret
, size
- ret
,
555 sep
? "%.2f" : " %6.2f%%",
556 (period_sys
* 100.0) / total
);
557 ret
+= percent_color_snprintf(s
+ ret
, size
- ret
,
558 sep
? "%.2f" : " %6.2f%%",
559 (period_us
* 100.0) / total
);
561 ret
+= percent_color_snprintf(s
+ ret
,
563 sep
? "%.2f" : " %6.2f%%",
564 (period_guest_sys
* 100.0) /
566 ret
+= percent_color_snprintf(s
+ ret
,
568 sep
? "%.2f" : " %6.2f%%",
569 (period_guest_us
* 100.0) /
574 ret
= snprintf(s
, size
, sep
? "%lld" : "%12lld ", period
);
576 if (symbol_conf
.show_nr_samples
) {
578 ret
+= snprintf(s
+ ret
, size
- ret
, "%c%lld", *sep
, period
);
580 ret
+= snprintf(s
+ ret
, size
- ret
, "%11lld", period
);
585 double old_percent
= 0, new_percent
= 0, diff
;
588 old_percent
= (period
* 100.0) / total
;
589 if (session_total
> 0)
590 new_percent
= (self
->period
* 100.0) / session_total
;
592 diff
= new_percent
- old_percent
;
594 if (fabs(diff
) >= 0.01)
595 snprintf(bf
, sizeof(bf
), "%+4.2F%%", diff
);
597 snprintf(bf
, sizeof(bf
), " ");
600 ret
+= snprintf(s
+ ret
, size
- ret
, "%c%s", *sep
, bf
);
602 ret
+= snprintf(s
+ ret
, size
- ret
, "%11.11s", bf
);
604 if (show_displacement
) {
606 snprintf(bf
, sizeof(bf
), "%+4ld", displacement
);
608 snprintf(bf
, sizeof(bf
), " ");
611 ret
+= snprintf(s
+ ret
, size
- ret
, "%c%s", *sep
, bf
);
613 ret
+= snprintf(s
+ ret
, size
- ret
, "%6.6s", bf
);
617 list_for_each_entry(se
, &hist_entry__sort_list
, list
) {
621 ret
+= snprintf(s
+ ret
, size
- ret
, "%s", sep
?: " ");
622 ret
+= se
->se_snprintf(self
, s
+ ret
, size
- ret
,
623 se
->se_width
? *se
->se_width
: 0);
629 int hist_entry__fprintf(struct hist_entry
*self
, struct hists
*pair_hists
,
630 bool show_displacement
, long displacement
, FILE *fp
,
634 hist_entry__snprintf(self
, bf
, sizeof(bf
), pair_hists
,
635 show_displacement
, displacement
,
636 true, session_total
);
637 return fprintf(fp
, "%s\n", bf
);
640 static size_t hist_entry__fprintf_callchain(struct hist_entry
*self
, FILE *fp
,
645 if (sort__first_dimension
== SORT_COMM
) {
646 struct sort_entry
*se
= list_first_entry(&hist_entry__sort_list
,
648 left_margin
= se
->se_width
? *se
->se_width
: 0;
649 left_margin
-= thread__comm_len(self
->thread
);
652 return hist_entry_callchain__fprintf(fp
, self
, session_total
,
656 size_t hists__fprintf(struct hists
*self
, struct hists
*pair
,
657 bool show_displacement
, FILE *fp
)
659 struct sort_entry
*se
;
662 unsigned long position
= 1;
663 long displacement
= 0;
665 const char *sep
= symbol_conf
.field_sep
;
666 const char *col_width
= symbol_conf
.col_width_list_str
;
670 fprintf(fp
, "# %s", pair
? "Baseline" : "Overhead");
672 if (symbol_conf
.show_nr_samples
) {
674 fprintf(fp
, "%cSamples", *sep
);
676 fputs(" Samples ", fp
);
679 if (symbol_conf
.show_cpu_utilization
) {
681 ret
+= fprintf(fp
, "%csys", *sep
);
682 ret
+= fprintf(fp
, "%cus", *sep
);
684 ret
+= fprintf(fp
, "%cguest sys", *sep
);
685 ret
+= fprintf(fp
, "%cguest us", *sep
);
688 ret
+= fprintf(fp
, " sys ");
689 ret
+= fprintf(fp
, " us ");
691 ret
+= fprintf(fp
, " guest sys ");
692 ret
+= fprintf(fp
, " guest us ");
699 ret
+= fprintf(fp
, "%cDelta", *sep
);
701 ret
+= fprintf(fp
, " Delta ");
703 if (show_displacement
) {
705 ret
+= fprintf(fp
, "%cDisplacement", *sep
);
707 ret
+= fprintf(fp
, " Displ");
711 list_for_each_entry(se
, &hist_entry__sort_list
, list
) {
715 fprintf(fp
, "%c%s", *sep
, se
->se_header
);
718 width
= strlen(se
->se_header
);
720 if (symbol_conf
.col_width_list_str
) {
722 *se
->se_width
= atoi(col_width
);
723 col_width
= strchr(col_width
, ',');
728 width
= *se
->se_width
= max(*se
->se_width
, width
);
730 fprintf(fp
, " %*s", width
, se
->se_header
);
737 fprintf(fp
, "# ........");
738 if (symbol_conf
.show_nr_samples
)
739 fprintf(fp
, " ..........");
741 fprintf(fp
, " ..........");
742 if (show_displacement
)
743 fprintf(fp
, " .....");
745 list_for_each_entry(se
, &hist_entry__sort_list
, list
) {
753 width
= *se
->se_width
;
755 width
= strlen(se
->se_header
);
756 for (i
= 0; i
< width
; i
++)
760 fprintf(fp
, "\n#\n");
763 for (nd
= rb_first(&self
->entries
); nd
; nd
= rb_next(nd
)) {
764 struct hist_entry
*h
= rb_entry(nd
, struct hist_entry
, rb_node
);
766 if (show_displacement
) {
768 displacement
= ((long)h
->pair
->position
-
774 ret
+= hist_entry__fprintf(h
, pair
, show_displacement
,
775 displacement
, fp
, self
->stats
.total_period
);
777 if (symbol_conf
.use_callchain
)
778 ret
+= hist_entry__fprintf_callchain(h
, fp
, self
->stats
.total_period
);
780 if (h
->ms
.map
== NULL
&& verbose
> 1) {
781 __map_groups__fprintf_maps(&h
->thread
->mg
,
782 MAP__FUNCTION
, verbose
, fp
);
783 fprintf(fp
, "%.10s end\n", graph_dotted_line
);
787 free(rem_sq_bracket
);
797 void hists__filter_by_dso(struct hists
*self
, const struct dso
*dso
)
801 self
->nr_entries
= self
->stats
.total_period
= 0;
802 self
->stats
.nr_events
[PERF_RECORD_SAMPLE
] = 0;
803 self
->max_sym_namelen
= 0;
805 for (nd
= rb_first(&self
->entries
); nd
; nd
= rb_next(nd
)) {
806 struct hist_entry
*h
= rb_entry(nd
, struct hist_entry
, rb_node
);
808 if (symbol_conf
.exclude_other
&& !h
->parent
)
811 if (dso
!= NULL
&& (h
->ms
.map
== NULL
|| h
->ms
.map
->dso
!= dso
)) {
812 h
->filtered
|= (1 << HIST_FILTER__DSO
);
816 h
->filtered
&= ~(1 << HIST_FILTER__DSO
);
819 self
->stats
.total_period
+= h
->period
;
820 self
->stats
.nr_events
[PERF_RECORD_SAMPLE
] += h
->nr_events
;
822 self
->max_sym_namelen
< h
->ms
.sym
->namelen
)
823 self
->max_sym_namelen
= h
->ms
.sym
->namelen
;
828 void hists__filter_by_thread(struct hists
*self
, const struct thread
*thread
)
832 self
->nr_entries
= self
->stats
.total_period
= 0;
833 self
->stats
.nr_events
[PERF_RECORD_SAMPLE
] = 0;
834 self
->max_sym_namelen
= 0;
836 for (nd
= rb_first(&self
->entries
); nd
; nd
= rb_next(nd
)) {
837 struct hist_entry
*h
= rb_entry(nd
, struct hist_entry
, rb_node
);
839 if (thread
!= NULL
&& h
->thread
!= thread
) {
840 h
->filtered
|= (1 << HIST_FILTER__THREAD
);
843 h
->filtered
&= ~(1 << HIST_FILTER__THREAD
);
846 self
->stats
.total_period
+= h
->period
;
847 self
->stats
.nr_events
[PERF_RECORD_SAMPLE
] += h
->nr_events
;
849 self
->max_sym_namelen
< h
->ms
.sym
->namelen
)
850 self
->max_sym_namelen
= h
->ms
.sym
->namelen
;
855 static int symbol__alloc_hist(struct symbol
*self
)
857 struct sym_priv
*priv
= symbol__priv(self
);
858 const int size
= (sizeof(*priv
->hist
) +
859 (self
->end
- self
->start
) * sizeof(u64
));
861 priv
->hist
= zalloc(size
);
862 return priv
->hist
== NULL
? -1 : 0;
865 int hist_entry__inc_addr_samples(struct hist_entry
*self
, u64 ip
)
867 unsigned int sym_size
, offset
;
868 struct symbol
*sym
= self
->ms
.sym
;
869 struct sym_priv
*priv
;
872 if (!sym
|| !self
->ms
.map
)
875 priv
= symbol__priv(sym
);
876 if (priv
->hist
== NULL
&& symbol__alloc_hist(sym
) < 0)
879 sym_size
= sym
->end
- sym
->start
;
880 offset
= ip
- sym
->start
;
882 pr_debug3("%s: ip=%#Lx\n", __func__
, self
->ms
.map
->unmap_ip(self
->ms
.map
, ip
));
884 if (offset
>= sym_size
)
891 pr_debug3("%#Lx %s: period++ [ip: %#Lx, %#Lx] => %Ld\n", self
->ms
.sym
->start
,
892 self
->ms
.sym
->name
, ip
, ip
- self
->ms
.sym
->start
, h
->ip
[offset
]);
896 static struct objdump_line
*objdump_line__new(s64 offset
, char *line
)
898 struct objdump_line
*self
= malloc(sizeof(*self
));
901 self
->offset
= offset
;
908 void objdump_line__free(struct objdump_line
*self
)
914 static void objdump__add_line(struct list_head
*head
, struct objdump_line
*line
)
916 list_add_tail(&line
->node
, head
);
919 struct objdump_line
*objdump__get_next_ip_line(struct list_head
*head
,
920 struct objdump_line
*pos
)
922 list_for_each_entry_continue(pos
, head
, node
)
923 if (pos
->offset
>= 0)
929 static int hist_entry__parse_objdump_line(struct hist_entry
*self
, FILE *file
,
930 struct list_head
*head
)
932 struct symbol
*sym
= self
->ms
.sym
;
933 struct objdump_line
*objdump_line
;
934 char *line
= NULL
, *tmp
, *tmp2
, *c
;
936 s64 line_ip
, offset
= -1;
938 if (getline(&line
, &line_len
, file
) < 0)
944 while (line_len
!= 0 && isspace(line
[line_len
- 1]))
945 line
[--line_len
] = '\0';
947 c
= strchr(line
, '\n');
954 * Strip leading spaces:
965 * Parse hexa addresses followed by ':'
967 line_ip
= strtoull(tmp
, &tmp2
, 16);
973 u64 start
= map__rip_2objdump(self
->ms
.map
, sym
->start
);
974 offset
= line_ip
- start
;
977 objdump_line
= objdump_line__new(offset
, line
);
978 if (objdump_line
== NULL
) {
982 objdump__add_line(head
, objdump_line
);
987 int hist_entry__annotate(struct hist_entry
*self
, struct list_head
*head
)
989 struct symbol
*sym
= self
->ms
.sym
;
990 struct map
*map
= self
->ms
.map
;
991 struct dso
*dso
= map
->dso
;
992 char *filename
= dso__build_id_filename(dso
, NULL
, 0);
993 bool free_filename
= true;
994 char command
[PATH_MAX
* 2];
999 if (filename
== NULL
) {
1000 if (dso
->has_build_id
) {
1001 pr_err("Can't annotate %s: not enough memory\n",
1006 } else if (readlink(filename
, command
, sizeof(command
)) < 0 ||
1007 strstr(command
, "[kernel.kallsyms]") ||
1008 access(filename
, R_OK
)) {
1012 * If we don't have build-ids or the build-id file isn't in the
1013 * cache, or is just a kallsyms file, well, lets hope that this
1014 * DSO is the same as when 'perf record' ran.
1016 filename
= dso
->long_name
;
1017 free_filename
= false;
1020 if (dso
->origin
== DSO__ORIG_KERNEL
) {
1021 if (dso
->annotate_warned
)
1022 goto out_free_filename
;
1024 dso
->annotate_warned
= 1;
1025 pr_err("Can't annotate %s: No vmlinux file was found in the "
1026 "path\n", sym
->name
);
1027 goto out_free_filename
;
1030 pr_debug("%s: filename=%s, sym=%s, start=%#Lx, end=%#Lx\n", __func__
,
1031 filename
, sym
->name
, map
->unmap_ip(map
, sym
->start
),
1032 map
->unmap_ip(map
, sym
->end
));
1034 len
= sym
->end
- sym
->start
;
1036 pr_debug("annotating [%p] %30s : [%p] %30s\n",
1037 dso
, dso
->long_name
, sym
, sym
->name
);
1039 snprintf(command
, sizeof(command
),
1040 "objdump --start-address=0x%016Lx --stop-address=0x%016Lx -dS %s|grep -v %s|expand",
1041 map__rip_2objdump(map
, sym
->start
),
1042 map__rip_2objdump(map
, sym
->end
),
1043 filename
, filename
);
1045 pr_debug("Executing: %s\n", command
);
1047 file
= popen(command
, "r");
1049 goto out_free_filename
;
1052 if (hist_entry__parse_objdump_line(self
, file
, head
) < 0)
1062 void hists__inc_nr_events(struct hists
*self
, u32 type
)
1064 ++self
->stats
.nr_events
[0];
1065 ++self
->stats
.nr_events
[type
];
1068 size_t hists__fprintf_nr_events(struct hists
*self
, FILE *fp
)
1073 for (i
= 0; i
< PERF_RECORD_HEADER_MAX
; ++i
) {
1074 if (!event__name
[i
])
1076 ret
+= fprintf(fp
, "%10s events: %10d\n",
1077 event__name
[i
], self
->stats
.nr_events
[i
]);