]>
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; | |
37236d5e JO |
93 | float ipc; |
94 | u64 cycles; | |
c835e191 | 95 | size_t privsize; |
8b4c74dc | 96 | char *path; |
7e304557 JO |
97 | int samples_nr; |
98 | struct annotation_data samples[0]; | |
a17c4ca0 JO |
99 | }; |
100 | ||
29ed6e76 | 101 | struct disasm_line { |
a17c4ca0 | 102 | struct ins ins; |
a17c4ca0 | 103 | struct ins_operands ops; |
c835e191 JO |
104 | |
105 | /* This needs to be at the end. */ | |
106 | struct annotation_line al; | |
78f7defe ACM |
107 | }; |
108 | ||
c835e191 JO |
109 | static inline struct disasm_line *disasm_line(struct annotation_line *al) |
110 | { | |
111 | return al ? container_of(al, struct disasm_line, al) : NULL; | |
112 | } | |
113 | ||
fb29fa58 ACM |
114 | static inline bool disasm_line__has_offset(const struct disasm_line *dl) |
115 | { | |
e216874c | 116 | return dl->ops.target.offset_avail; |
fb29fa58 ACM |
117 | } |
118 | ||
29ed6e76 | 119 | void disasm_line__free(struct disasm_line *dl); |
c4c72436 JO |
120 | struct annotation_line * |
121 | annotation_line__next(struct annotation_line *pos, struct list_head *head); | |
5417072b | 122 | int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw); |
5145418b | 123 | size_t disasm__fprintf(struct list_head *head, FILE *fp); |
9e4e0a9d | 124 | void symbol__calc_percent(struct symbol *sym, struct perf_evsel *evsel); |
78f7defe ACM |
125 | |
126 | struct sym_hist { | |
8158683d | 127 | u64 nr_samples; |
461c17f0 | 128 | u64 period; |
896bccd3 | 129 | struct sym_hist_entry addr[0]; |
78f7defe ACM |
130 | }; |
131 | ||
d4957633 AK |
132 | struct cyc_hist { |
133 | u64 start; | |
134 | u64 cycles; | |
135 | u64 cycles_aggr; | |
136 | u32 num; | |
137 | u32 num_aggr; | |
138 | u8 have_start; | |
139 | /* 1 byte padding */ | |
140 | u16 reset; | |
141 | }; | |
142 | ||
ce6f4fab | 143 | /** struct annotated_source - symbols with hits have this attached as in sannotation |
2f525d01 ACM |
144 | * |
145 | * @histogram: Array of addr hit histograms per event being monitored | |
ce6f4fab | 146 | * @lines: If 'print_lines' is specified, per source code line percentages |
29ed6e76 | 147 | * @source: source parsed from a disassembler like objdump -dS |
d4957633 | 148 | * @cyc_hist: Average cycles per basic block |
2f525d01 | 149 | * |
ce6f4fab | 150 | * lines is allocated, percentages calculated and all sorted by percentage |
2f525d01 ACM |
151 | * when the annotation is about to be presented, so the percentages are for |
152 | * one of the entries in the histogram array, i.e. for the event/counter being | |
153 | * presented. It is deallocated right after symbol__{tui,tty,etc}_annotate | |
154 | * returns. | |
155 | */ | |
ce6f4fab ACM |
156 | struct annotated_source { |
157 | struct list_head source; | |
36532461 | 158 | int nr_histograms; |
5ec4502d | 159 | size_t sizeof_sym_hist; |
d4957633 | 160 | struct cyc_hist *cycles_hist; |
ce6f4fab ACM |
161 | struct sym_hist histograms[0]; |
162 | }; | |
163 | ||
164 | struct annotation { | |
165 | pthread_mutex_t lock; | |
70fbe057 | 166 | u64 max_coverage; |
9d6bb41d | 167 | struct annotation_line **offsets; |
0553e83d | 168 | int nr_events; |
0e83a7e9 | 169 | bool have_cycles; |
ce6f4fab | 170 | struct annotated_source *src; |
78f7defe ACM |
171 | }; |
172 | ||
0e83a7e9 ACM |
173 | static inline int annotation__cycles_width(struct annotation *notes) |
174 | { | |
175 | return notes->have_cycles ? ANNOTATION__IPC_WIDTH + ANNOTATION__CYCLES_WIDTH : 0; | |
176 | } | |
177 | ||
f56c083b ACM |
178 | void annotation__compute_ipc(struct annotation *notes, size_t size); |
179 | ||
2f525d01 ACM |
180 | static inline struct sym_hist *annotation__histogram(struct annotation *notes, int idx) |
181 | { | |
ce6f4fab ACM |
182 | return (((void *)¬es->src->histograms) + |
183 | (notes->src->sizeof_sym_hist * idx)); | |
2f525d01 ACM |
184 | } |
185 | ||
78f7defe ACM |
186 | static inline struct annotation *symbol__annotation(struct symbol *sym) |
187 | { | |
813ccd15 | 188 | return (void *)sym - symbol_conf.priv_size; |
78f7defe ACM |
189 | } |
190 | ||
bab89f6a TS |
191 | int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, struct perf_sample *sample, |
192 | int evidx); | |
0f4e7a24 | 193 | |
d4957633 AK |
194 | int addr_map_symbol__account_cycles(struct addr_map_symbol *ams, |
195 | struct addr_map_symbol *start, | |
196 | unsigned cycles); | |
197 | ||
bab89f6a TS |
198 | int hist_entry__inc_addr_samples(struct hist_entry *he, struct perf_sample *sample, |
199 | int evidx, u64 addr); | |
f626adff | 200 | |
d04b35f8 | 201 | int symbol__alloc_hist(struct symbol *sym); |
36532461 | 202 | void symbol__annotate_zero_histograms(struct symbol *sym); |
78f7defe | 203 | |
c34df25b | 204 | int symbol__annotate(struct symbol *sym, struct map *map, |
d03a686e | 205 | struct perf_evsel *evsel, size_t privsize, |
5449f13c | 206 | struct arch **parch); |
f626adff | 207 | |
ee51d851 ACM |
208 | enum symbol_disassemble_errno { |
209 | SYMBOL_ANNOTATE_ERRNO__SUCCESS = 0, | |
210 | ||
211 | /* | |
212 | * Choose an arbitrary negative big number not to clash with standard | |
213 | * errno since SUS requires the errno has distinct positive values. | |
214 | * See 'Issue 6' in the link below. | |
215 | * | |
216 | * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html | |
217 | */ | |
218 | __SYMBOL_ANNOTATE_ERRNO__START = -10000, | |
219 | ||
220 | SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX = __SYMBOL_ANNOTATE_ERRNO__START, | |
221 | ||
222 | __SYMBOL_ANNOTATE_ERRNO__END, | |
223 | }; | |
224 | ||
225 | int symbol__strerror_disassemble(struct symbol *sym, struct map *map, | |
226 | int errnum, char *buf, size_t buflen); | |
227 | ||
db8fd07a NK |
228 | int symbol__annotate_printf(struct symbol *sym, struct map *map, |
229 | struct perf_evsel *evsel, bool full_paths, | |
230 | int min_pcnt, int max_lines, int context); | |
36532461 | 231 | void symbol__annotate_zero_histogram(struct symbol *sym, int evidx); |
ce6f4fab | 232 | void symbol__annotate_decay_histogram(struct symbol *sym, int evidx); |
f8eb37bd | 233 | void annotated_source__purge(struct annotated_source *as); |
78f7defe | 234 | |
48c65bda NK |
235 | bool ui__has_annotation(void); |
236 | ||
db8fd07a NK |
237 | int symbol__tty_annotate(struct symbol *sym, struct map *map, |
238 | struct perf_evsel *evsel, bool print_lines, | |
239 | bool full_paths, int min_pcnt, int max_lines); | |
78f7defe | 240 | |
89fe808a | 241 | #ifdef HAVE_SLANG_SUPPORT |
db8fd07a NK |
242 | int symbol__tui_annotate(struct symbol *sym, struct map *map, |
243 | struct perf_evsel *evsel, | |
9783adf7 | 244 | struct hist_browser_timer *hbt); |
1254b51e | 245 | #else |
1d037ca1 | 246 | static inline int symbol__tui_annotate(struct symbol *sym __maybe_unused, |
db8fd07a NK |
247 | struct map *map __maybe_unused, |
248 | struct perf_evsel *evsel __maybe_unused, | |
249 | struct hist_browser_timer *hbt | |
250 | __maybe_unused) | |
78f7defe ACM |
251 | { |
252 | return 0; | |
253 | } | |
78f7defe ACM |
254 | #endif |
255 | ||
f69b64f7 AK |
256 | extern const char *disassembler_style; |
257 | ||
78f7defe | 258 | #endif /* __PERF_ANNOTATE_H */ |