]> git.ipfire.org Git - thirdparty/linux.git/blame - tools/perf/util/annotate.h
perf annotate: Introduce struct sym_hist_entry
[thirdparty/linux.git] / tools / perf / util / annotate.h
CommitLineData
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
75b49202
ACM
14struct ins_ops;
15
16struct ins {
17 const char *name;
18 struct ins_ops *ops;
19};
28548d78 20
c7e6ead7
ACM
21struct ins_operands {
22 char *raw;
44d1a3ed 23 struct {
6de783b6 24 char *raw;
44d1a3ed 25 char *name;
44d1a3ed 26 u64 addr;
e216874c
RB
27 s64 offset;
28 bool offset_avail;
44d1a3ed 29 } target;
7a997fe4
ACM
30 union {
31 struct {
32 char *raw;
33 char *name;
34 u64 addr;
35 } source;
36 struct {
75b49202 37 struct ins ins;
7a997fe4
ACM
38 struct ins_operands *ops;
39 } locked;
40 };
c7e6ead7
ACM
41};
42
786c1b51
ACM
43struct arch;
44
4f9d0325 45struct ins_ops {
c46219ac 46 void (*free)(struct ins_operands *ops);
786c1b51 47 int (*parse)(struct arch *arch, struct ins_operands *ops, struct map *map);
28548d78 48 int (*scnprintf)(struct ins *ins, char *bf, size_t size,
5417072b 49 struct ins_operands *ops);
4f9d0325
ACM
50};
51
4f9d0325 52bool ins__is_jump(const struct ins *ins);
d86b0597 53bool ins__is_call(const struct ins *ins);
6ef94929 54bool ins__is_ret(const struct ins *ins);
7e63a13a 55bool ins__is_lock(const struct ins *ins);
5417072b 56int ins__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands *ops);
69fb09f6 57bool ins__is_fused(struct arch *arch, const char *ins1, const char *ins2);
4f9d0325 58
e64aa75b
NK
59struct annotation;
60
29ed6e76 61struct disasm_line {
c7e6ead7
ACM
62 struct list_head node;
63 s64 offset;
64 char *line;
75b49202 65 struct ins ins;
e592488c 66 int line_nr;
30e863bb
AK
67 float ipc;
68 u64 cycles;
c7e6ead7 69 struct ins_operands ops;
78f7defe
ACM
70};
71
fb29fa58
ACM
72static inline bool disasm_line__has_offset(const struct disasm_line *dl)
73{
e216874c 74 return dl->ops.target.offset_avail;
fb29fa58
ACM
75}
76
896bccd3
TS
77struct sym_hist_entry {
78 u64 nr_samples;
79 u64 period;
80};
81
29ed6e76
ACM
82void disasm_line__free(struct disasm_line *dl);
83struct disasm_line *disasm__get_next_ip_line(struct list_head *head, struct disasm_line *pos);
5417072b 84int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw);
5145418b 85size_t disasm__fprintf(struct list_head *head, FILE *fp);
e64aa75b 86double disasm__calc_percent(struct annotation *notes, int evidx, s64 offset,
896bccd3 87 s64 end, const char **path, struct sym_hist_entry *sample);
78f7defe
ACM
88
89struct sym_hist {
90 u64 sum;
896bccd3 91 struct sym_hist_entry addr[0];
78f7defe
ACM
92};
93
d4957633
AK
94struct cyc_hist {
95 u64 start;
96 u64 cycles;
97 u64 cycles_aggr;
98 u32 num;
99 u32 num_aggr;
100 u8 have_start;
101 /* 1 byte padding */
102 u16 reset;
103};
104
276af92f 105struct source_line_samples {
78f7defe 106 double percent;
41127965 107 double percent_sum;
99094a5e 108 u64 nr;
c5a8368c
NK
109};
110
111struct source_line {
112 struct rb_node node;
78f7defe 113 char *path;
1491c22a 114 int nr_pcnt;
276af92f 115 struct source_line_samples samples[1];
78f7defe
ACM
116};
117
ce6f4fab 118/** struct annotated_source - symbols with hits have this attached as in sannotation
2f525d01
ACM
119 *
120 * @histogram: Array of addr hit histograms per event being monitored
ce6f4fab 121 * @lines: If 'print_lines' is specified, per source code line percentages
29ed6e76 122 * @source: source parsed from a disassembler like objdump -dS
d4957633 123 * @cyc_hist: Average cycles per basic block
2f525d01 124 *
ce6f4fab 125 * lines is allocated, percentages calculated and all sorted by percentage
2f525d01
ACM
126 * when the annotation is about to be presented, so the percentages are for
127 * one of the entries in the histogram array, i.e. for the event/counter being
128 * presented. It is deallocated right after symbol__{tui,tty,etc}_annotate
129 * returns.
130 */
ce6f4fab
ACM
131struct annotated_source {
132 struct list_head source;
133 struct source_line *lines;
36532461 134 int nr_histograms;
5ec4502d 135 size_t sizeof_sym_hist;
d4957633 136 struct cyc_hist *cycles_hist;
ce6f4fab
ACM
137 struct sym_hist histograms[0];
138};
139
140struct annotation {
141 pthread_mutex_t lock;
70fbe057 142 u64 max_coverage;
ce6f4fab 143 struct annotated_source *src;
78f7defe
ACM
144};
145
2f525d01
ACM
146static inline struct sym_hist *annotation__histogram(struct annotation *notes, int idx)
147{
ce6f4fab
ACM
148 return (((void *)&notes->src->histograms) +
149 (notes->src->sizeof_sym_hist * idx));
2f525d01
ACM
150}
151
78f7defe
ACM
152static inline struct annotation *symbol__annotation(struct symbol *sym)
153{
813ccd15 154 return (void *)sym - symbol_conf.priv_size;
78f7defe
ACM
155}
156
0f4e7a24
ACM
157int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, int evidx);
158
d4957633
AK
159int addr_map_symbol__account_cycles(struct addr_map_symbol *ams,
160 struct addr_map_symbol *start,
161 unsigned cycles);
162
f626adff
ACM
163int hist_entry__inc_addr_samples(struct hist_entry *he, int evidx, u64 addr);
164
d04b35f8 165int symbol__alloc_hist(struct symbol *sym);
36532461 166void symbol__annotate_zero_histograms(struct symbol *sym);
78f7defe 167
dcaa3948
JY
168int symbol__disassemble(struct symbol *sym, struct map *map,
169 const char *arch_name, size_t privsize,
69fb09f6 170 struct arch **parch, char *cpuid);
f626adff 171
ee51d851
ACM
172enum symbol_disassemble_errno {
173 SYMBOL_ANNOTATE_ERRNO__SUCCESS = 0,
174
175 /*
176 * Choose an arbitrary negative big number not to clash with standard
177 * errno since SUS requires the errno has distinct positive values.
178 * See 'Issue 6' in the link below.
179 *
180 * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
181 */
182 __SYMBOL_ANNOTATE_ERRNO__START = -10000,
183
184 SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX = __SYMBOL_ANNOTATE_ERRNO__START,
185
186 __SYMBOL_ANNOTATE_ERRNO__END,
187};
188
189int symbol__strerror_disassemble(struct symbol *sym, struct map *map,
190 int errnum, char *buf, size_t buflen);
191
db8fd07a
NK
192int symbol__annotate_printf(struct symbol *sym, struct map *map,
193 struct perf_evsel *evsel, bool full_paths,
194 int min_pcnt, int max_lines, int context);
36532461 195void symbol__annotate_zero_histogram(struct symbol *sym, int evidx);
ce6f4fab 196void symbol__annotate_decay_histogram(struct symbol *sym, int evidx);
29ed6e76 197void disasm__purge(struct list_head *head);
78f7defe 198
48c65bda
NK
199bool ui__has_annotation(void);
200
db8fd07a
NK
201int symbol__tty_annotate(struct symbol *sym, struct map *map,
202 struct perf_evsel *evsel, bool print_lines,
203 bool full_paths, int min_pcnt, int max_lines);
78f7defe 204
89fe808a 205#ifdef HAVE_SLANG_SUPPORT
db8fd07a
NK
206int symbol__tui_annotate(struct symbol *sym, struct map *map,
207 struct perf_evsel *evsel,
9783adf7 208 struct hist_browser_timer *hbt);
1254b51e 209#else
1d037ca1 210static inline int symbol__tui_annotate(struct symbol *sym __maybe_unused,
db8fd07a
NK
211 struct map *map __maybe_unused,
212 struct perf_evsel *evsel __maybe_unused,
213 struct hist_browser_timer *hbt
214 __maybe_unused)
78f7defe
ACM
215{
216 return 0;
217}
78f7defe
ACM
218#endif
219
f69b64f7
AK
220extern const char *disassembler_style;
221
78f7defe 222#endif /* __PERF_ANNOTATE_H */