Commit | Line | Data |
---|---|---|
78f7defe ACM |
1 | #ifndef __PERF_ANNOTATE_H |
2 | #define __PERF_ANNOTATE_H | |
3 | ||
4 | #include <stdbool.h> | |
fb29fa58 | 5 | #include <stdint.h> |
78f7defe ACM |
6 | #include "types.h" |
7 | #include "symbol.h" | |
9783adf7 | 8 | #include "hist.h" |
78f7defe ACM |
9 | #include <linux/list.h> |
10 | #include <linux/rbtree.h> | |
27683dc5 | 11 | #include <pthread.h> |
78f7defe | 12 | |
28548d78 ACM |
13 | struct ins; |
14 | ||
c7e6ead7 ACM |
15 | struct ins_operands { |
16 | char *raw; | |
44d1a3ed | 17 | struct { |
6de783b6 | 18 | char *raw; |
44d1a3ed | 19 | char *name; |
44d1a3ed | 20 | u64 addr; |
6de783b6 | 21 | u64 offset; |
44d1a3ed | 22 | } target; |
7a997fe4 ACM |
23 | union { |
24 | struct { | |
25 | char *raw; | |
26 | char *name; | |
27 | u64 addr; | |
28 | } source; | |
29 | struct { | |
30 | struct ins *ins; | |
31 | struct ins_operands *ops; | |
32 | } locked; | |
33 | }; | |
c7e6ead7 ACM |
34 | }; |
35 | ||
4f9d0325 | 36 | struct ins_ops { |
c46219ac | 37 | void (*free)(struct ins_operands *ops); |
c7e6ead7 | 38 | int (*parse)(struct ins_operands *ops); |
28548d78 | 39 | int (*scnprintf)(struct ins *ins, char *bf, size_t size, |
5417072b | 40 | struct ins_operands *ops); |
4f9d0325 ACM |
41 | }; |
42 | ||
43 | struct ins { | |
44 | const char *name; | |
45 | struct ins_ops *ops; | |
46 | }; | |
47 | ||
48 | bool ins__is_jump(const struct ins *ins); | |
d86b0597 | 49 | bool ins__is_call(const struct ins *ins); |
5417072b | 50 | int ins__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands *ops); |
4f9d0325 | 51 | |
29ed6e76 | 52 | struct disasm_line { |
c7e6ead7 ACM |
53 | struct list_head node; |
54 | s64 offset; | |
55 | char *line; | |
56 | char *name; | |
57 | struct ins *ins; | |
58 | struct ins_operands ops; | |
78f7defe ACM |
59 | }; |
60 | ||
fb29fa58 ACM |
61 | static inline bool disasm_line__has_offset(const struct disasm_line *dl) |
62 | { | |
63 | return dl->ops.target.offset != UINT64_MAX; | |
64 | } | |
65 | ||
29ed6e76 ACM |
66 | void disasm_line__free(struct disasm_line *dl); |
67 | struct disasm_line *disasm__get_next_ip_line(struct list_head *head, struct disasm_line *pos); | |
5417072b | 68 | int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw); |
5145418b | 69 | size_t disasm__fprintf(struct list_head *head, FILE *fp); |
78f7defe ACM |
70 | |
71 | struct sym_hist { | |
72 | u64 sum; | |
73 | u64 addr[0]; | |
74 | }; | |
75 | ||
76 | struct source_line { | |
77 | struct rb_node node; | |
78 | double percent; | |
79 | char *path; | |
80 | }; | |
81 | ||
ce6f4fab | 82 | /** struct annotated_source - symbols with hits have this attached as in sannotation |
2f525d01 ACM |
83 | * |
84 | * @histogram: Array of addr hit histograms per event being monitored | |
ce6f4fab | 85 | * @lines: If 'print_lines' is specified, per source code line percentages |
29ed6e76 | 86 | * @source: source parsed from a disassembler like objdump -dS |
2f525d01 | 87 | * |
ce6f4fab | 88 | * lines is allocated, percentages calculated and all sorted by percentage |
2f525d01 ACM |
89 | * when the annotation is about to be presented, so the percentages are for |
90 | * one of the entries in the histogram array, i.e. for the event/counter being | |
91 | * presented. It is deallocated right after symbol__{tui,tty,etc}_annotate | |
92 | * returns. | |
93 | */ | |
ce6f4fab ACM |
94 | struct annotated_source { |
95 | struct list_head source; | |
96 | struct source_line *lines; | |
36532461 | 97 | int nr_histograms; |
2f525d01 | 98 | int sizeof_sym_hist; |
ce6f4fab ACM |
99 | struct sym_hist histograms[0]; |
100 | }; | |
101 | ||
102 | struct annotation { | |
103 | pthread_mutex_t lock; | |
104 | struct annotated_source *src; | |
78f7defe ACM |
105 | }; |
106 | ||
107 | struct sannotation { | |
108 | struct annotation annotation; | |
109 | struct symbol symbol; | |
110 | }; | |
111 | ||
2f525d01 ACM |
112 | static inline struct sym_hist *annotation__histogram(struct annotation *notes, int idx) |
113 | { | |
ce6f4fab ACM |
114 | return (((void *)¬es->src->histograms) + |
115 | (notes->src->sizeof_sym_hist * idx)); | |
2f525d01 ACM |
116 | } |
117 | ||
78f7defe ACM |
118 | static inline struct annotation *symbol__annotation(struct symbol *sym) |
119 | { | |
120 | struct sannotation *a = container_of(sym, struct sannotation, symbol); | |
121 | return &a->annotation; | |
122 | } | |
123 | ||
2f525d01 ACM |
124 | int symbol__inc_addr_samples(struct symbol *sym, struct map *map, |
125 | int evidx, u64 addr); | |
d04b35f8 | 126 | int symbol__alloc_hist(struct symbol *sym); |
36532461 | 127 | void symbol__annotate_zero_histograms(struct symbol *sym); |
78f7defe | 128 | |
ce6f4fab | 129 | int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize); |
1d037ca1 | 130 | int symbol__annotate_init(struct map *map __maybe_unused, struct symbol *sym); |
ce6f4fab | 131 | int symbol__annotate_printf(struct symbol *sym, struct map *map, int evidx, |
d5e3d747 ACM |
132 | bool full_paths, int min_pcnt, int max_lines, |
133 | int context); | |
36532461 | 134 | void symbol__annotate_zero_histogram(struct symbol *sym, int evidx); |
ce6f4fab | 135 | void symbol__annotate_decay_histogram(struct symbol *sym, int evidx); |
29ed6e76 | 136 | void disasm__purge(struct list_head *head); |
78f7defe | 137 | |
2f525d01 | 138 | int symbol__tty_annotate(struct symbol *sym, struct map *map, int evidx, |
d040bd36 ACM |
139 | bool print_lines, bool full_paths, int min_pcnt, |
140 | int max_lines); | |
78f7defe | 141 | |
1254b51e NK |
142 | #ifdef NEWT_SUPPORT |
143 | int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx, | |
9783adf7 | 144 | struct hist_browser_timer *hbt); |
1254b51e | 145 | #else |
1d037ca1 IT |
146 | static inline int symbol__tui_annotate(struct symbol *sym __maybe_unused, |
147 | struct map *map __maybe_unused, | |
148 | int evidx __maybe_unused, | |
9783adf7 NK |
149 | struct hist_browser_timer *hbt |
150 | __maybe_unused) | |
78f7defe ACM |
151 | { |
152 | return 0; | |
153 | } | |
78f7defe ACM |
154 | #endif |
155 | ||
f69b64f7 AK |
156 | extern const char *disassembler_style; |
157 | ||
78f7defe | 158 | #endif /* __PERF_ANNOTATE_H */ |