]> git.ipfire.org Git - thirdparty/linux.git/blame - tools/perf/util/annotate.h
perf annotate: Introduce symbol__annotate2 method
[thirdparty/linux.git] / tools / perf / util / annotate.h
CommitLineData
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
15struct ins_ops;
16
17struct ins {
18 const char *name;
19 struct ins_ops *ops;
20};
28548d78 21
c7e6ead7
ACM
22struct 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
45struct arch;
46
4f9d0325 47struct 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 54bool ins__is_jump(const struct ins *ins);
d86b0597 55bool ins__is_call(const struct ins *ins);
6ef94929 56bool ins__is_ret(const struct ins *ins);
7e63a13a 57bool ins__is_lock(const struct ins *ins);
5417072b 58int ins__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands *ops);
69fb09f6 59bool 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
64struct 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
74struct annotation;
75
7e304557
JO
76struct sym_hist_entry {
77 u64 nr_samples;
78 u64 period;
79};
80
81struct annotation_data {
82 double percent;
8b4c74dc 83 double percent_sum;
7e304557
JO
84 struct sym_hist_entry he;
85};
86
a17c4ca0
JO
87struct 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 104struct 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
112static 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
117static 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
122bool disasm_line__is_valid_jump(struct disasm_line *dl, struct symbol *sym);
123
29ed6e76 124void disasm_line__free(struct disasm_line *dl);
c4c72436
JO
125struct annotation_line *
126annotation_line__next(struct annotation_line *pos, struct list_head *head);
5417072b 127int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw);
5145418b 128size_t disasm__fprintf(struct list_head *head, FILE *fp);
9e4e0a9d 129void symbol__calc_percent(struct symbol *sym, struct perf_evsel *evsel);
78f7defe
ACM
130
131struct sym_hist {
8158683d 132 u64 nr_samples;
461c17f0 133 u64 period;
896bccd3 134 struct sym_hist_entry addr[0];
78f7defe
ACM
135};
136
d4957633
AK
137struct cyc_hist {
138 u64 start;
139 u64 cycles;
140 u64 cycles_aggr;
141 u32 num;
142 u32 num_aggr;
143 u8 have_start;
144 /* 1 byte padding */
145 u16 reset;
146};
147
ce6f4fab 148/** struct annotated_source - symbols with hits have this attached as in sannotation
2f525d01
ACM
149 *
150 * @histogram: Array of addr hit histograms per event being monitored
ce6f4fab 151 * @lines: If 'print_lines' is specified, per source code line percentages
29ed6e76 152 * @source: source parsed from a disassembler like objdump -dS
d4957633 153 * @cyc_hist: Average cycles per basic block
2f525d01 154 *
ce6f4fab 155 * lines is allocated, percentages calculated and all sorted by percentage
2f525d01
ACM
156 * when the annotation is about to be presented, so the percentages are for
157 * one of the entries in the histogram array, i.e. for the event/counter being
158 * presented. It is deallocated right after symbol__{tui,tty,etc}_annotate
159 * returns.
160 */
ce6f4fab
ACM
161struct annotated_source {
162 struct list_head source;
36532461 163 int nr_histograms;
5ec4502d 164 size_t sizeof_sym_hist;
d4957633 165 struct cyc_hist *cycles_hist;
ce6f4fab
ACM
166 struct sym_hist histograms[0];
167};
168
169struct annotation {
170 pthread_mutex_t lock;
70fbe057 171 u64 max_coverage;
0ca693b3 172 u64 start;
16932d77 173 struct annotation_options *options;
9d6bb41d 174 struct annotation_line **offsets;
0553e83d 175 int nr_events;
6dcd57e8 176 int nr_jumps;
bc1c0f3d 177 int max_jump_sources;
1cf5f98a
ACM
178 int nr_entries;
179 int nr_asm_entries;
5bc49f61 180 u16 max_line_len;
9761e86e
ACM
181 struct {
182 u8 addr;
183 u8 jumps;
184 u8 target;
185 u8 min_addr;
186 u8 max_addr;
187 } widths;
0e83a7e9 188 bool have_cycles;
ce6f4fab 189 struct annotated_source *src;
78f7defe
ACM
190};
191
0e83a7e9
ACM
192static inline int annotation__cycles_width(struct annotation *notes)
193{
194 return notes->have_cycles ? ANNOTATION__IPC_WIDTH + ANNOTATION__CYCLES_WIDTH : 0;
195}
196
6af612d2
ACM
197static inline int annotation__pcnt_width(struct annotation *notes)
198{
199 return (notes->options->show_total_period ? 12 : 7) * notes->nr_events;
200}
201
5bc49f61
ACM
202
203void annotation__set_offsets(struct annotation *notes, s64 size);
f56c083b 204void annotation__compute_ipc(struct annotation *notes, size_t size);
0db45bcf 205void annotation__mark_jump_targets(struct annotation *notes, struct symbol *sym);
7232bf7a 206void annotation__update_column_widths(struct annotation *notes);
b8b0d819 207void annotation__init_column_widths(struct annotation *notes, struct symbol *sym);
f56c083b 208
2f525d01
ACM
209static inline struct sym_hist *annotation__histogram(struct annotation *notes, int idx)
210{
ce6f4fab
ACM
211 return (((void *)&notes->src->histograms) +
212 (notes->src->sizeof_sym_hist * idx));
2f525d01
ACM
213}
214
78f7defe
ACM
215static inline struct annotation *symbol__annotation(struct symbol *sym)
216{
813ccd15 217 return (void *)sym - symbol_conf.priv_size;
78f7defe
ACM
218}
219
bab89f6a
TS
220int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, struct perf_sample *sample,
221 int evidx);
0f4e7a24 222
d4957633
AK
223int addr_map_symbol__account_cycles(struct addr_map_symbol *ams,
224 struct addr_map_symbol *start,
225 unsigned cycles);
226
bab89f6a
TS
227int hist_entry__inc_addr_samples(struct hist_entry *he, struct perf_sample *sample,
228 int evidx, u64 addr);
f626adff 229
d04b35f8 230int symbol__alloc_hist(struct symbol *sym);
36532461 231void symbol__annotate_zero_histograms(struct symbol *sym);
78f7defe 232
c34df25b 233int symbol__annotate(struct symbol *sym, struct map *map,
d03a686e 234 struct perf_evsel *evsel, size_t privsize,
5449f13c 235 struct arch **parch);
ecda45bd
ACM
236int symbol__annotate2(struct symbol *sym, struct map *map,
237 struct perf_evsel *evsel,
238 struct annotation_options *options,
239 struct arch **parch);
f626adff 240
ee51d851
ACM
241enum symbol_disassemble_errno {
242 SYMBOL_ANNOTATE_ERRNO__SUCCESS = 0,
243
244 /*
245 * Choose an arbitrary negative big number not to clash with standard
246 * errno since SUS requires the errno has distinct positive values.
247 * See 'Issue 6' in the link below.
248 *
249 * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
250 */
251 __SYMBOL_ANNOTATE_ERRNO__START = -10000,
252
253 SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX = __SYMBOL_ANNOTATE_ERRNO__START,
254
255 __SYMBOL_ANNOTATE_ERRNO__END,
256};
257
258int symbol__strerror_disassemble(struct symbol *sym, struct map *map,
259 int errnum, char *buf, size_t buflen);
260
db8fd07a
NK
261int symbol__annotate_printf(struct symbol *sym, struct map *map,
262 struct perf_evsel *evsel, bool full_paths,
263 int min_pcnt, int max_lines, int context);
36532461 264void symbol__annotate_zero_histogram(struct symbol *sym, int evidx);
ce6f4fab 265void symbol__annotate_decay_histogram(struct symbol *sym, int evidx);
f8eb37bd 266void annotated_source__purge(struct annotated_source *as);
78f7defe 267
48c65bda
NK
268bool ui__has_annotation(void);
269
db8fd07a
NK
270int symbol__tty_annotate(struct symbol *sym, struct map *map,
271 struct perf_evsel *evsel, bool print_lines,
272 bool full_paths, int min_pcnt, int max_lines);
78f7defe 273
89fe808a 274#ifdef HAVE_SLANG_SUPPORT
db8fd07a
NK
275int symbol__tui_annotate(struct symbol *sym, struct map *map,
276 struct perf_evsel *evsel,
9783adf7 277 struct hist_browser_timer *hbt);
1254b51e 278#else
1d037ca1 279static inline int symbol__tui_annotate(struct symbol *sym __maybe_unused,
db8fd07a
NK
280 struct map *map __maybe_unused,
281 struct perf_evsel *evsel __maybe_unused,
282 struct hist_browser_timer *hbt
283 __maybe_unused)
78f7defe
ACM
284{
285 return 0;
286}
78f7defe
ACM
287#endif
288
f69b64f7
AK
289extern const char *disassembler_style;
290
78f7defe 291#endif /* __PERF_ANNOTATE_H */