Merge remote-tracking branch 'tip/auto-latest'
[deliverable/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
28548d78
ACM
14struct ins;
15
c7e6ead7
ACM
16struct 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 37struct 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
44struct ins {
45 const char *name;
46 struct ins_ops *ops;
47};
48
49bool ins__is_jump(const struct ins *ins);
d86b0597 50bool ins__is_call(const struct ins *ins);
6ef94929 51bool ins__is_ret(const struct ins *ins);
5417072b 52int ins__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands *ops);
4f9d0325 53
e64aa75b
NK
54struct annotation;
55
29ed6e76 56struct 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
68static inline bool disasm_line__has_offset(const struct disasm_line *dl)
69{
70 return dl->ops.target.offset != UINT64_MAX;
71}
72
29ed6e76
ACM
73void disasm_line__free(struct disasm_line *dl);
74struct disasm_line *disasm__get_next_ip_line(struct list_head *head, struct disasm_line *pos);
5417072b 75int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw);
5145418b 76size_t disasm__fprintf(struct list_head *head, FILE *fp);
e64aa75b 77double disasm__calc_percent(struct annotation *notes, int evidx, s64 offset,
0c4a5bce 78 s64 end, const char **path, u64 *nr_samples);
78f7defe
ACM
79
80struct sym_hist {
81 u64 sum;
82 u64 addr[0];
83};
84
d4957633
AK
85struct 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 96struct source_line_samples {
78f7defe 97 double percent;
41127965 98 double percent_sum;
276af92f 99 double nr;
c5a8368c
NK
100};
101
102struct 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
122struct 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
131struct annotation {
132 pthread_mutex_t lock;
70fbe057 133 u64 max_coverage;
ce6f4fab 134 struct annotated_source *src;
78f7defe
ACM
135};
136
2f525d01
ACM
137static inline struct sym_hist *annotation__histogram(struct annotation *notes, int idx)
138{
ce6f4fab
ACM
139 return (((void *)&notes->src->histograms) +
140 (notes->src->sizeof_sym_hist * idx));
2f525d01
ACM
141}
142
78f7defe
ACM
143static inline struct annotation *symbol__annotation(struct symbol *sym)
144{
813ccd15 145 return (void *)sym - symbol_conf.priv_size;
78f7defe
ACM
146}
147
0f4e7a24
ACM
148int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, int evidx);
149
d4957633
AK
150int addr_map_symbol__account_cycles(struct addr_map_symbol *ams,
151 struct addr_map_symbol *start,
152 unsigned cycles);
153
f626adff
ACM
154int hist_entry__inc_addr_samples(struct hist_entry *he, int evidx, u64 addr);
155
d04b35f8 156int symbol__alloc_hist(struct symbol *sym);
36532461 157void symbol__annotate_zero_histograms(struct symbol *sym);
78f7defe 158
5cb725a9 159int symbol__disassemble(struct symbol *sym, struct map *map, size_t privsize);
f626adff 160
ee51d851
ACM
161enum symbol_disassemble_errno {
162 SYMBOL_ANNOTATE_ERRNO__SUCCESS = 0,
163
164 /*
165 * Choose an arbitrary negative big number not to clash with standard
166 * errno since SUS requires the errno has distinct positive values.
167 * See 'Issue 6' in the link below.
168 *
169 * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
170 */
171 __SYMBOL_ANNOTATE_ERRNO__START = -10000,
172
173 SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX = __SYMBOL_ANNOTATE_ERRNO__START,
174
175 __SYMBOL_ANNOTATE_ERRNO__END,
176};
177
178int symbol__strerror_disassemble(struct symbol *sym, struct map *map,
179 int errnum, char *buf, size_t buflen);
180
db8fd07a
NK
181int symbol__annotate_printf(struct symbol *sym, struct map *map,
182 struct perf_evsel *evsel, bool full_paths,
183 int min_pcnt, int max_lines, int context);
36532461 184void symbol__annotate_zero_histogram(struct symbol *sym, int evidx);
ce6f4fab 185void symbol__annotate_decay_histogram(struct symbol *sym, int evidx);
29ed6e76 186void disasm__purge(struct list_head *head);
78f7defe 187
48c65bda
NK
188bool ui__has_annotation(void);
189
db8fd07a
NK
190int symbol__tty_annotate(struct symbol *sym, struct map *map,
191 struct perf_evsel *evsel, bool print_lines,
192 bool full_paths, int min_pcnt, int max_lines);
78f7defe 193
89fe808a 194#ifdef HAVE_SLANG_SUPPORT
db8fd07a
NK
195int symbol__tui_annotate(struct symbol *sym, struct map *map,
196 struct perf_evsel *evsel,
9783adf7 197 struct hist_browser_timer *hbt);
1254b51e 198#else
1d037ca1 199static inline int symbol__tui_annotate(struct symbol *sym __maybe_unused,
db8fd07a
NK
200 struct map *map __maybe_unused,
201 struct perf_evsel *evsel __maybe_unused,
202 struct hist_browser_timer *hbt
203 __maybe_unused)
78f7defe
ACM
204{
205 return 0;
206}
78f7defe
ACM
207#endif
208
f69b64f7
AK
209extern const char *disassembler_style;
210
78f7defe 211#endif /* __PERF_ANNOTATE_H */
This page took 0.226152 seconds and 5 git commands to generate.