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> |
d944c4ee | 6 | #include <linux/types.h> |
78f7defe | 7 | #include "symbol.h" |
9783adf7 | 8 | #include "hist.h" |
2b676bf0 | 9 | #include "sort.h" |
78f7defe ACM |
10 | #include <linux/list.h> |
11 | #include <linux/rbtree.h> | |
27683dc5 | 12 | #include <pthread.h> |
78f7defe | 13 | |
28548d78 ACM |
14 | struct ins; |
15 | ||
c7e6ead7 ACM |
16 | struct ins_operands { |
17 | char *raw; | |
44d1a3ed | 18 | struct { |
6de783b6 | 19 | char *raw; |
44d1a3ed | 20 | char *name; |
44d1a3ed | 21 | u64 addr; |
6de783b6 | 22 | u64 offset; |
44d1a3ed | 23 | } target; |
7a997fe4 ACM |
24 | union { |
25 | struct { | |
26 | char *raw; | |
27 | char *name; | |
28 | u64 addr; | |
29 | } source; | |
30 | struct { | |
31 | struct ins *ins; | |
32 | struct ins_operands *ops; | |
33 | } locked; | |
34 | }; | |
c7e6ead7 ACM |
35 | }; |
36 | ||
4f9d0325 | 37 | struct ins_ops { |
c46219ac | 38 | void (*free)(struct ins_operands *ops); |
c7e6ead7 | 39 | int (*parse)(struct ins_operands *ops); |
28548d78 | 40 | int (*scnprintf)(struct ins *ins, char *bf, size_t size, |
5417072b | 41 | struct ins_operands *ops); |
4f9d0325 ACM |
42 | }; |
43 | ||
44 | struct ins { | |
45 | const char *name; | |
46 | struct ins_ops *ops; | |
47 | }; | |
48 | ||
49 | bool ins__is_jump(const struct ins *ins); | |
d86b0597 | 50 | bool ins__is_call(const struct ins *ins); |
6ef94929 | 51 | bool ins__is_ret(const struct ins *ins); |
5417072b | 52 | int ins__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands *ops); |
4f9d0325 | 53 | |
e64aa75b NK |
54 | struct annotation; |
55 | ||
29ed6e76 | 56 | struct disasm_line { |
c7e6ead7 ACM |
57 | struct list_head node; |
58 | s64 offset; | |
59 | char *line; | |
60 | char *name; | |
61 | struct ins *ins; | |
e592488c | 62 | int line_nr; |
30e863bb AK |
63 | float ipc; |
64 | u64 cycles; | |
c7e6ead7 | 65 | struct ins_operands ops; |
78f7defe ACM |
66 | }; |
67 | ||
fb29fa58 ACM |
68 | static inline bool disasm_line__has_offset(const struct disasm_line *dl) |
69 | { | |
70 | return dl->ops.target.offset != UINT64_MAX; | |
71 | } | |
72 | ||
29ed6e76 ACM |
73 | void disasm_line__free(struct disasm_line *dl); |
74 | struct disasm_line *disasm__get_next_ip_line(struct list_head *head, struct disasm_line *pos); | |
5417072b | 75 | int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw); |
5145418b | 76 | size_t disasm__fprintf(struct list_head *head, FILE *fp); |
e64aa75b | 77 | double disasm__calc_percent(struct annotation *notes, int evidx, s64 offset, |
0c4a5bce | 78 | s64 end, const char **path, u64 *nr_samples); |
78f7defe ACM |
79 | |
80 | struct sym_hist { | |
81 | u64 sum; | |
82 | u64 addr[0]; | |
83 | }; | |
84 | ||
d4957633 AK |
85 | struct cyc_hist { |
86 | u64 start; | |
87 | u64 cycles; | |
88 | u64 cycles_aggr; | |
89 | u32 num; | |
90 | u32 num_aggr; | |
91 | u8 have_start; | |
92 | /* 1 byte padding */ | |
93 | u16 reset; | |
94 | }; | |
95 | ||
276af92f | 96 | struct source_line_samples { |
78f7defe | 97 | double percent; |
41127965 | 98 | double percent_sum; |
276af92f | 99 | double nr; |
c5a8368c NK |
100 | }; |
101 | ||
102 | struct source_line { | |
103 | struct rb_node node; | |
78f7defe | 104 | char *path; |
1491c22a | 105 | int nr_pcnt; |
276af92f | 106 | struct source_line_samples samples[1]; |
78f7defe ACM |
107 | }; |
108 | ||
ce6f4fab | 109 | /** struct annotated_source - symbols with hits have this attached as in sannotation |
2f525d01 ACM |
110 | * |
111 | * @histogram: Array of addr hit histograms per event being monitored | |
ce6f4fab | 112 | * @lines: If 'print_lines' is specified, per source code line percentages |
29ed6e76 | 113 | * @source: source parsed from a disassembler like objdump -dS |
d4957633 | 114 | * @cyc_hist: Average cycles per basic block |
2f525d01 | 115 | * |
ce6f4fab | 116 | * lines is allocated, percentages calculated and all sorted by percentage |
2f525d01 ACM |
117 | * when the annotation is about to be presented, so the percentages are for |
118 | * one of the entries in the histogram array, i.e. for the event/counter being | |
119 | * presented. It is deallocated right after symbol__{tui,tty,etc}_annotate | |
120 | * returns. | |
121 | */ | |
ce6f4fab ACM |
122 | struct annotated_source { |
123 | struct list_head source; | |
124 | struct source_line *lines; | |
36532461 | 125 | int nr_histograms; |
5ec4502d | 126 | size_t sizeof_sym_hist; |
d4957633 | 127 | struct cyc_hist *cycles_hist; |
ce6f4fab ACM |
128 | struct sym_hist histograms[0]; |
129 | }; | |
130 | ||
131 | struct annotation { | |
132 | pthread_mutex_t lock; | |
133 | struct annotated_source *src; | |
78f7defe ACM |
134 | }; |
135 | ||
2f525d01 ACM |
136 | static inline struct sym_hist *annotation__histogram(struct annotation *notes, int idx) |
137 | { | |
ce6f4fab ACM |
138 | return (((void *)¬es->src->histograms) + |
139 | (notes->src->sizeof_sym_hist * idx)); | |
2f525d01 ACM |
140 | } |
141 | ||
78f7defe ACM |
142 | static inline struct annotation *symbol__annotation(struct symbol *sym) |
143 | { | |
813ccd15 | 144 | return (void *)sym - symbol_conf.priv_size; |
78f7defe ACM |
145 | } |
146 | ||
0f4e7a24 ACM |
147 | int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, int evidx); |
148 | ||
d4957633 AK |
149 | int addr_map_symbol__account_cycles(struct addr_map_symbol *ams, |
150 | struct addr_map_symbol *start, | |
151 | unsigned cycles); | |
152 | ||
f626adff ACM |
153 | int hist_entry__inc_addr_samples(struct hist_entry *he, int evidx, u64 addr); |
154 | ||
d04b35f8 | 155 | int symbol__alloc_hist(struct symbol *sym); |
36532461 | 156 | void symbol__annotate_zero_histograms(struct symbol *sym); |
78f7defe | 157 | |
ce6f4fab | 158 | int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize); |
f626adff | 159 | |
b8f8eb84 | 160 | int symbol__annotate_init(struct map *map, struct symbol *sym); |
db8fd07a NK |
161 | int symbol__annotate_printf(struct symbol *sym, struct map *map, |
162 | struct perf_evsel *evsel, bool full_paths, | |
163 | int min_pcnt, int max_lines, int context); | |
36532461 | 164 | void symbol__annotate_zero_histogram(struct symbol *sym, int evidx); |
ce6f4fab | 165 | void symbol__annotate_decay_histogram(struct symbol *sym, int evidx); |
29ed6e76 | 166 | void disasm__purge(struct list_head *head); |
78f7defe | 167 | |
48c65bda NK |
168 | bool ui__has_annotation(void); |
169 | ||
db8fd07a NK |
170 | int symbol__tty_annotate(struct symbol *sym, struct map *map, |
171 | struct perf_evsel *evsel, bool print_lines, | |
172 | bool full_paths, int min_pcnt, int max_lines); | |
78f7defe | 173 | |
89fe808a | 174 | #ifdef HAVE_SLANG_SUPPORT |
db8fd07a NK |
175 | int symbol__tui_annotate(struct symbol *sym, struct map *map, |
176 | struct perf_evsel *evsel, | |
9783adf7 | 177 | struct hist_browser_timer *hbt); |
1254b51e | 178 | #else |
1d037ca1 | 179 | static inline int symbol__tui_annotate(struct symbol *sym __maybe_unused, |
db8fd07a NK |
180 | struct map *map __maybe_unused, |
181 | struct perf_evsel *evsel __maybe_unused, | |
182 | struct hist_browser_timer *hbt | |
183 | __maybe_unused) | |
78f7defe ACM |
184 | { |
185 | return 0; | |
186 | } | |
78f7defe ACM |
187 | #endif |
188 | ||
f69b64f7 AK |
189 | extern const char *disassembler_style; |
190 | ||
78f7defe | 191 | #endif /* __PERF_ANNOTATE_H */ |