]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
78f7defe ACM |
2 | #ifndef __PERF_ANNOTATE_H |
3 | #define __PERF_ANNOTATE_H | |
4 | ||
5 | #include <stdbool.h> | |
fb29fa58 | 6 | #include <stdint.h> |
d944c4ee | 7 | #include <linux/types.h> |
78f7defe | 8 | #include "symbol.h" |
9783adf7 | 9 | #include "hist.h" |
2b676bf0 | 10 | #include "sort.h" |
78f7defe ACM |
11 | #include <linux/list.h> |
12 | #include <linux/rbtree.h> | |
27683dc5 | 13 | #include <pthread.h> |
78f7defe | 14 | |
75b49202 ACM |
15 | struct ins_ops; |
16 | ||
17 | struct ins { | |
18 | const char *name; | |
19 | struct ins_ops *ops; | |
20 | }; | |
28548d78 | 21 | |
c7e6ead7 ACM |
22 | struct ins_operands { |
23 | char *raw; | |
44d1a3ed | 24 | struct { |
6de783b6 | 25 | char *raw; |
44d1a3ed | 26 | char *name; |
696703af | 27 | struct symbol *sym; |
44d1a3ed | 28 | u64 addr; |
e216874c RB |
29 | s64 offset; |
30 | bool offset_avail; | |
44d1a3ed | 31 | } target; |
7a997fe4 ACM |
32 | union { |
33 | struct { | |
34 | char *raw; | |
35 | char *name; | |
36 | u64 addr; | |
37 | } source; | |
38 | struct { | |
75b49202 | 39 | struct ins ins; |
7a997fe4 ACM |
40 | struct ins_operands *ops; |
41 | } locked; | |
42 | }; | |
c7e6ead7 ACM |
43 | }; |
44 | ||
786c1b51 ACM |
45 | struct arch; |
46 | ||
4f9d0325 | 47 | struct ins_ops { |
c46219ac | 48 | void (*free)(struct ins_operands *ops); |
786c1b51 | 49 | int (*parse)(struct arch *arch, struct ins_operands *ops, struct map *map); |
28548d78 | 50 | int (*scnprintf)(struct ins *ins, char *bf, size_t size, |
5417072b | 51 | struct ins_operands *ops); |
4f9d0325 ACM |
52 | }; |
53 | ||
4f9d0325 | 54 | bool ins__is_jump(const struct ins *ins); |
d86b0597 | 55 | bool ins__is_call(const struct ins *ins); |
6ef94929 | 56 | bool ins__is_ret(const struct ins *ins); |
7e63a13a | 57 | bool ins__is_lock(const struct ins *ins); |
5417072b | 58 | int ins__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands *ops); |
69fb09f6 | 59 | bool ins__is_fused(struct arch *arch, const char *ins1, const char *ins2); |
4f9d0325 | 60 | |
c426e584 ACM |
61 | #define ANNOTATION__IPC_WIDTH 6 |
62 | #define ANNOTATION__CYCLES_WIDTH 6 | |
63 | ||
98bc80b0 ACM |
64 | struct annotation_options { |
65 | bool hide_src_code, | |
66 | use_offset, | |
67 | jump_arrows, | |
68 | show_linenr, | |
69 | show_nr_jumps, | |
70 | show_nr_samples, | |
71 | show_total_period; | |
72 | }; | |
73 | ||
e64aa75b NK |
74 | struct annotation; |
75 | ||
7e304557 JO |
76 | struct sym_hist_entry { |
77 | u64 nr_samples; | |
78 | u64 period; | |
79 | }; | |
80 | ||
81 | struct annotation_data { | |
82 | double percent; | |
8b4c74dc | 83 | double percent_sum; |
7e304557 JO |
84 | struct sym_hist_entry he; |
85 | }; | |
86 | ||
a17c4ca0 JO |
87 | struct annotation_line { |
88 | struct list_head node; | |
5b12adc8 | 89 | struct rb_node rb_node; |
d5490b96 JO |
90 | s64 offset; |
91 | char *line; | |
92 | int line_nr; | |
0db45bcf | 93 | int jump_sources; |
37236d5e JO |
94 | float ipc; |
95 | u64 cycles; | |
c835e191 | 96 | size_t privsize; |
8b4c74dc | 97 | char *path; |
4850c92e ACM |
98 | u32 idx; |
99 | int idx_asm; | |
7e304557 JO |
100 | int samples_nr; |
101 | struct annotation_data samples[0]; | |
a17c4ca0 JO |
102 | }; |
103 | ||
29ed6e76 | 104 | struct disasm_line { |
a17c4ca0 | 105 | struct ins ins; |
a17c4ca0 | 106 | struct ins_operands ops; |
c835e191 JO |
107 | |
108 | /* This needs to be at the end. */ | |
109 | struct annotation_line al; | |
78f7defe ACM |
110 | }; |
111 | ||
c835e191 JO |
112 | static inline struct disasm_line *disasm_line(struct annotation_line *al) |
113 | { | |
114 | return al ? container_of(al, struct disasm_line, al) : NULL; | |
115 | } | |
116 | ||
fb29fa58 ACM |
117 | static inline bool disasm_line__has_offset(const struct disasm_line *dl) |
118 | { | |
e216874c | 119 | return dl->ops.target.offset_avail; |
fb29fa58 ACM |
120 | } |
121 | ||
0db45bcf ACM |
122 | bool disasm_line__is_valid_jump(struct disasm_line *dl, struct symbol *sym); |
123 | ||
29ed6e76 | 124 | void disasm_line__free(struct disasm_line *dl); |
c4c72436 JO |
125 | struct annotation_line * |
126 | annotation_line__next(struct annotation_line *pos, struct list_head *head); | |
2f025ea0 | 127 | |
c298304b ACM |
128 | struct annotation_write_ops { |
129 | bool first_line, current_entry, change_color; | |
130 | int width; | |
131 | void *obj; | |
132 | int (*set_color)(void *obj, int color); | |
133 | void (*set_percent_color)(void *obj, double percent, bool current); | |
134 | int (*set_jumps_percent_color)(void *obj, int nr, bool current); | |
135 | void (*printf)(void *obj, const char *fmt, ...); | |
136 | void (*write_graph)(void *obj, int graph); | |
137 | }; | |
138 | ||
2f025ea0 | 139 | double annotation_line__max_percent(struct annotation_line *al, struct annotation *notes); |
a1e9b74c | 140 | void annotation_line__write(struct annotation_line *al, struct annotation *notes, |
c298304b | 141 | struct annotation_write_ops *ops); |
2f025ea0 | 142 | |
5417072b | 143 | int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw); |
5145418b | 144 | size_t disasm__fprintf(struct list_head *head, FILE *fp); |
9e4e0a9d | 145 | void symbol__calc_percent(struct symbol *sym, struct perf_evsel *evsel); |
78f7defe ACM |
146 | |
147 | struct sym_hist { | |
8158683d | 148 | u64 nr_samples; |
461c17f0 | 149 | u64 period; |
896bccd3 | 150 | struct sym_hist_entry addr[0]; |
78f7defe ACM |
151 | }; |
152 | ||
d4957633 AK |
153 | struct cyc_hist { |
154 | u64 start; | |
155 | u64 cycles; | |
156 | u64 cycles_aggr; | |
157 | u32 num; | |
158 | u32 num_aggr; | |
159 | u8 have_start; | |
160 | /* 1 byte padding */ | |
161 | u16 reset; | |
162 | }; | |
163 | ||
ce6f4fab | 164 | /** struct annotated_source - symbols with hits have this attached as in sannotation |
2f525d01 ACM |
165 | * |
166 | * @histogram: Array of addr hit histograms per event being monitored | |
ce6f4fab | 167 | * @lines: If 'print_lines' is specified, per source code line percentages |
29ed6e76 | 168 | * @source: source parsed from a disassembler like objdump -dS |
d4957633 | 169 | * @cyc_hist: Average cycles per basic block |
2f525d01 | 170 | * |
ce6f4fab | 171 | * lines is allocated, percentages calculated and all sorted by percentage |
2f525d01 ACM |
172 | * when the annotation is about to be presented, so the percentages are for |
173 | * one of the entries in the histogram array, i.e. for the event/counter being | |
174 | * presented. It is deallocated right after symbol__{tui,tty,etc}_annotate | |
175 | * returns. | |
176 | */ | |
ce6f4fab ACM |
177 | struct annotated_source { |
178 | struct list_head source; | |
36532461 | 179 | int nr_histograms; |
5ec4502d | 180 | size_t sizeof_sym_hist; |
d4957633 | 181 | struct cyc_hist *cycles_hist; |
ce6f4fab ACM |
182 | struct sym_hist histograms[0]; |
183 | }; | |
184 | ||
185 | struct annotation { | |
186 | pthread_mutex_t lock; | |
70fbe057 | 187 | u64 max_coverage; |
0ca693b3 | 188 | u64 start; |
16932d77 | 189 | struct annotation_options *options; |
9d6bb41d | 190 | struct annotation_line **offsets; |
0553e83d | 191 | int nr_events; |
6dcd57e8 | 192 | int nr_jumps; |
bc1c0f3d | 193 | int max_jump_sources; |
1cf5f98a ACM |
194 | int nr_entries; |
195 | int nr_asm_entries; | |
5bc49f61 | 196 | u16 max_line_len; |
9761e86e ACM |
197 | struct { |
198 | u8 addr; | |
199 | u8 jumps; | |
200 | u8 target; | |
201 | u8 min_addr; | |
202 | u8 max_addr; | |
203 | } widths; | |
0e83a7e9 | 204 | bool have_cycles; |
ce6f4fab | 205 | struct annotated_source *src; |
78f7defe ACM |
206 | }; |
207 | ||
0e83a7e9 ACM |
208 | static inline int annotation__cycles_width(struct annotation *notes) |
209 | { | |
210 | return notes->have_cycles ? ANNOTATION__IPC_WIDTH + ANNOTATION__CYCLES_WIDTH : 0; | |
211 | } | |
212 | ||
6af612d2 ACM |
213 | static inline int annotation__pcnt_width(struct annotation *notes) |
214 | { | |
215 | return (notes->options->show_total_period ? 12 : 7) * notes->nr_events; | |
216 | } | |
217 | ||
9b80d1f9 ACM |
218 | static inline bool annotation_line__filter(struct annotation_line *al, struct annotation *notes) |
219 | { | |
220 | return notes->options->hide_src_code && al->offset == -1; | |
221 | } | |
5bc49f61 ACM |
222 | |
223 | void annotation__set_offsets(struct annotation *notes, s64 size); | |
f56c083b | 224 | void annotation__compute_ipc(struct annotation *notes, size_t size); |
0db45bcf | 225 | void annotation__mark_jump_targets(struct annotation *notes, struct symbol *sym); |
7232bf7a | 226 | void annotation__update_column_widths(struct annotation *notes); |
b8b0d819 | 227 | void annotation__init_column_widths(struct annotation *notes, struct symbol *sym); |
f56c083b | 228 | |
2f525d01 ACM |
229 | static inline struct sym_hist *annotation__histogram(struct annotation *notes, int idx) |
230 | { | |
ce6f4fab ACM |
231 | return (((void *)¬es->src->histograms) + |
232 | (notes->src->sizeof_sym_hist * idx)); | |
2f525d01 ACM |
233 | } |
234 | ||
78f7defe ACM |
235 | static inline struct annotation *symbol__annotation(struct symbol *sym) |
236 | { | |
813ccd15 | 237 | return (void *)sym - symbol_conf.priv_size; |
78f7defe ACM |
238 | } |
239 | ||
bab89f6a TS |
240 | int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, struct perf_sample *sample, |
241 | int evidx); | |
0f4e7a24 | 242 | |
d4957633 AK |
243 | int addr_map_symbol__account_cycles(struct addr_map_symbol *ams, |
244 | struct addr_map_symbol *start, | |
245 | unsigned cycles); | |
246 | ||
bab89f6a TS |
247 | int hist_entry__inc_addr_samples(struct hist_entry *he, struct perf_sample *sample, |
248 | int evidx, u64 addr); | |
f626adff | 249 | |
d04b35f8 | 250 | int symbol__alloc_hist(struct symbol *sym); |
36532461 | 251 | void symbol__annotate_zero_histograms(struct symbol *sym); |
78f7defe | 252 | |
c34df25b | 253 | int symbol__annotate(struct symbol *sym, struct map *map, |
d03a686e | 254 | struct perf_evsel *evsel, size_t privsize, |
5449f13c | 255 | struct arch **parch); |
ecda45bd ACM |
256 | int symbol__annotate2(struct symbol *sym, struct map *map, |
257 | struct perf_evsel *evsel, | |
258 | struct annotation_options *options, | |
259 | struct arch **parch); | |
f626adff | 260 | |
ee51d851 ACM |
261 | enum symbol_disassemble_errno { |
262 | SYMBOL_ANNOTATE_ERRNO__SUCCESS = 0, | |
263 | ||
264 | /* | |
265 | * Choose an arbitrary negative big number not to clash with standard | |
266 | * errno since SUS requires the errno has distinct positive values. | |
267 | * See 'Issue 6' in the link below. | |
268 | * | |
269 | * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html | |
270 | */ | |
271 | __SYMBOL_ANNOTATE_ERRNO__START = -10000, | |
272 | ||
273 | SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX = __SYMBOL_ANNOTATE_ERRNO__START, | |
274 | ||
275 | __SYMBOL_ANNOTATE_ERRNO__END, | |
276 | }; | |
277 | ||
278 | int symbol__strerror_disassemble(struct symbol *sym, struct map *map, | |
279 | int errnum, char *buf, size_t buflen); | |
280 | ||
db8fd07a NK |
281 | int symbol__annotate_printf(struct symbol *sym, struct map *map, |
282 | struct perf_evsel *evsel, bool full_paths, | |
283 | int min_pcnt, int max_lines, int context); | |
befd2a38 | 284 | int symbol__annotate_fprintf2(struct symbol *sym, FILE *fp); |
36532461 | 285 | void symbol__annotate_zero_histogram(struct symbol *sym, int evidx); |
ce6f4fab | 286 | void symbol__annotate_decay_histogram(struct symbol *sym, int evidx); |
f8eb37bd | 287 | void annotated_source__purge(struct annotated_source *as); |
78f7defe | 288 | |
48c65bda NK |
289 | bool ui__has_annotation(void); |
290 | ||
db8fd07a NK |
291 | int symbol__tty_annotate(struct symbol *sym, struct map *map, |
292 | struct perf_evsel *evsel, bool print_lines, | |
293 | bool full_paths, int min_pcnt, int max_lines); | |
78f7defe | 294 | |
befd2a38 ACM |
295 | int symbol__tty_annotate2(struct symbol *sym, struct map *map, |
296 | struct perf_evsel *evsel, bool print_lines, | |
297 | bool full_paths); | |
298 | ||
89fe808a | 299 | #ifdef HAVE_SLANG_SUPPORT |
db8fd07a NK |
300 | int symbol__tui_annotate(struct symbol *sym, struct map *map, |
301 | struct perf_evsel *evsel, | |
9783adf7 | 302 | struct hist_browser_timer *hbt); |
1254b51e | 303 | #else |
1d037ca1 | 304 | static inline int symbol__tui_annotate(struct symbol *sym __maybe_unused, |
db8fd07a NK |
305 | struct map *map __maybe_unused, |
306 | struct perf_evsel *evsel __maybe_unused, | |
307 | struct hist_browser_timer *hbt | |
308 | __maybe_unused) | |
78f7defe ACM |
309 | { |
310 | return 0; | |
311 | } | |
78f7defe ACM |
312 | #endif |
313 | ||
f69b64f7 AK |
314 | extern const char *disassembler_style; |
315 | ||
78f7defe | 316 | #endif /* __PERF_ANNOTATE_H */ |