1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __PERF_ANNOTATE_H
3 #define __PERF_ANNOTATE_H
7 #include <linux/types.h>
11 #include <linux/list.h>
12 #include <linux/rbtree.h>
40 struct ins_operands *ops;
48 void (*free)(struct ins_operands *ops);
49 int (*parse)(struct arch *arch, struct ins_operands *ops, struct map *map);
50 int (*scnprintf)(struct ins *ins, char *bf, size_t size,
51 struct ins_operands *ops);
54 bool ins__is_jump(const struct ins *ins);
55 bool ins__is_call(const struct ins *ins);
56 bool ins__is_ret(const struct ins *ins);
57 bool ins__is_lock(const struct ins *ins);
58 int ins__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands *ops);
59 bool ins__is_fused(struct arch *arch, const char *ins1, const char *ins2);
63 struct sym_hist_entry {
68 struct annotation_data {
71 struct sym_hist_entry he;
74 struct annotation_line {
75 struct list_head node;
76 struct rb_node rb_node;
85 struct annotation_data samples[0];
90 struct ins_operands ops;
92 /* This needs to be at the end. */
93 struct annotation_line al;
96 static inline struct disasm_line *disasm_line(struct annotation_line *al)
98 return al ? container_of(al, struct disasm_line, al) : NULL;
101 static inline bool disasm_line__has_offset(const struct disasm_line *dl)
103 return dl->ops.target.offset_avail;
106 void disasm_line__free(struct disasm_line *dl);
107 struct annotation_line *
108 annotation_line__next(struct annotation_line *pos, struct list_head *head);
109 int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw);
110 size_t disasm__fprintf(struct list_head *head, FILE *fp);
111 void symbol__calc_percent(struct symbol *sym, struct perf_evsel *evsel);
116 struct sym_hist_entry addr[0];
130 /** struct annotated_source - symbols with hits have this attached as in sannotation
132 * @histogram: Array of addr hit histograms per event being monitored
133 * @lines: If 'print_lines' is specified, per source code line percentages
134 * @source: source parsed from a disassembler like objdump -dS
135 * @cyc_hist: Average cycles per basic block
137 * lines is allocated, percentages calculated and all sorted by percentage
138 * when the annotation is about to be presented, so the percentages are for
139 * one of the entries in the histogram array, i.e. for the event/counter being
140 * presented. It is deallocated right after symbol__{tui,tty,etc}_annotate
143 struct annotated_source {
144 struct list_head source;
146 size_t sizeof_sym_hist;
147 struct cyc_hist *cycles_hist;
148 struct sym_hist histograms[0];
152 pthread_mutex_t lock;
154 struct annotated_source *src;
157 static inline struct sym_hist *annotation__histogram(struct annotation *notes, int idx)
159 return (((void *)¬es->src->histograms) +
160 (notes->src->sizeof_sym_hist * idx));
163 static inline struct annotation *symbol__annotation(struct symbol *sym)
165 return (void *)sym - symbol_conf.priv_size;
168 int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, struct perf_sample *sample,
171 int addr_map_symbol__account_cycles(struct addr_map_symbol *ams,
172 struct addr_map_symbol *start,
175 int hist_entry__inc_addr_samples(struct hist_entry *he, struct perf_sample *sample,
176 int evidx, u64 addr);
178 int symbol__alloc_hist(struct symbol *sym);
179 void symbol__annotate_zero_histograms(struct symbol *sym);
181 int symbol__annotate(struct symbol *sym, struct map *map,
182 struct perf_evsel *evsel, size_t privsize,
183 struct arch **parch);
185 enum symbol_disassemble_errno {
186 SYMBOL_ANNOTATE_ERRNO__SUCCESS = 0,
189 * Choose an arbitrary negative big number not to clash with standard
190 * errno since SUS requires the errno has distinct positive values.
191 * See 'Issue 6' in the link below.
193 * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
195 __SYMBOL_ANNOTATE_ERRNO__START = -10000,
197 SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX = __SYMBOL_ANNOTATE_ERRNO__START,
199 __SYMBOL_ANNOTATE_ERRNO__END,
202 int symbol__strerror_disassemble(struct symbol *sym, struct map *map,
203 int errnum, char *buf, size_t buflen);
205 int symbol__annotate_printf(struct symbol *sym, struct map *map,
206 struct perf_evsel *evsel, bool full_paths,
207 int min_pcnt, int max_lines, int context);
208 void symbol__annotate_zero_histogram(struct symbol *sym, int evidx);
209 void symbol__annotate_decay_histogram(struct symbol *sym, int evidx);
210 void annotated_source__purge(struct annotated_source *as);
212 bool ui__has_annotation(void);
214 int symbol__tty_annotate(struct symbol *sym, struct map *map,
215 struct perf_evsel *evsel, bool print_lines,
216 bool full_paths, int min_pcnt, int max_lines);
218 #ifdef HAVE_SLANG_SUPPORT
219 int symbol__tui_annotate(struct symbol *sym, struct map *map,
220 struct perf_evsel *evsel,
221 struct hist_browser_timer *hbt);
223 static inline int symbol__tui_annotate(struct symbol *sym __maybe_unused,
224 struct map *map __maybe_unused,
225 struct perf_evsel *evsel __maybe_unused,
226 struct hist_browser_timer *hbt
233 extern const char *disassembler_style;
235 #endif /* __PERF_ANNOTATE_H */