blob: 13a21f10dabb28032982d32fd4f056434913aef4 [file] [log] [blame]
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -02001#ifndef __PERF_ANNOTATE_H
2#define __PERF_ANNOTATE_H
3
4#include <stdbool.h>
Arnaldo Carvalho de Melofb29fa52012-04-25 14:16:03 -03005#include <stdint.h>
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -02006#include "types.h"
7#include "symbol.h"
8#include <linux/list.h>
9#include <linux/rbtree.h>
10
Arnaldo Carvalho de Melo28548d72012-04-19 10:16:27 -030011struct ins;
12
Arnaldo Carvalho de Meloc7e6ead2012-04-20 14:38:46 -030013struct ins_operands {
14 char *raw;
Arnaldo Carvalho de Melo44d1a3e2012-04-25 08:00:23 -030015 struct {
16 char *name;
17 u64 offset;
18 u64 addr;
19 } target;
Arnaldo Carvalho de Meloc7e6ead2012-04-20 14:38:46 -030020};
21
Arnaldo Carvalho de Melo4f9d0322012-04-18 13:58:34 -030022struct ins_ops {
Arnaldo Carvalho de Meloc7e6ead2012-04-20 14:38:46 -030023 int (*parse)(struct ins_operands *ops);
Arnaldo Carvalho de Melo28548d72012-04-19 10:16:27 -030024 int (*scnprintf)(struct ins *ins, char *bf, size_t size,
Arnaldo Carvalho de Meloc7e6ead2012-04-20 14:38:46 -030025 struct ins_operands *ops, bool addrs);
Arnaldo Carvalho de Melo4f9d0322012-04-18 13:58:34 -030026};
27
28struct ins {
29 const char *name;
30 struct ins_ops *ops;
31};
32
33bool ins__is_jump(const struct ins *ins);
Arnaldo Carvalho de Melod86b0592012-04-18 16:07:38 -030034bool ins__is_call(const struct ins *ins);
Arnaldo Carvalho de Melo4f9d0322012-04-18 13:58:34 -030035
Arnaldo Carvalho de Melo29ed6e72012-04-15 15:24:39 -030036struct disasm_line {
Arnaldo Carvalho de Meloc7e6ead2012-04-20 14:38:46 -030037 struct list_head node;
38 s64 offset;
39 char *line;
40 char *name;
41 struct ins *ins;
42 struct ins_operands ops;
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -020043};
44
Arnaldo Carvalho de Melofb29fa52012-04-25 14:16:03 -030045static inline bool disasm_line__has_offset(const struct disasm_line *dl)
46{
47 return dl->ops.target.offset != UINT64_MAX;
48}
49
Arnaldo Carvalho de Melo29ed6e72012-04-15 15:24:39 -030050void disasm_line__free(struct disasm_line *dl);
51struct disasm_line *disasm__get_next_ip_line(struct list_head *head, struct disasm_line *pos);
Arnaldo Carvalho de Melo51454182012-04-15 15:52:18 -030052size_t disasm__fprintf(struct list_head *head, FILE *fp);
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -020053
54struct sym_hist {
55 u64 sum;
56 u64 addr[0];
57};
58
59struct source_line {
60 struct rb_node node;
61 double percent;
62 char *path;
63};
64
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020065/** struct annotated_source - symbols with hits have this attached as in sannotation
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020066 *
67 * @histogram: Array of addr hit histograms per event being monitored
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020068 * @lines: If 'print_lines' is specified, per source code line percentages
Arnaldo Carvalho de Melo29ed6e72012-04-15 15:24:39 -030069 * @source: source parsed from a disassembler like objdump -dS
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020070 *
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020071 * lines is allocated, percentages calculated and all sorted by percentage
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020072 * when the annotation is about to be presented, so the percentages are for
73 * one of the entries in the histogram array, i.e. for the event/counter being
74 * presented. It is deallocated right after symbol__{tui,tty,etc}_annotate
75 * returns.
76 */
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020077struct annotated_source {
78 struct list_head source;
79 struct source_line *lines;
Arnaldo Carvalho de Melo36532462011-02-06 14:54:44 -020080 int nr_histograms;
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020081 int sizeof_sym_hist;
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020082 struct sym_hist histograms[0];
83};
84
85struct annotation {
86 pthread_mutex_t lock;
87 struct annotated_source *src;
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -020088};
89
90struct sannotation {
91 struct annotation annotation;
92 struct symbol symbol;
93};
94
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020095static inline struct sym_hist *annotation__histogram(struct annotation *notes, int idx)
96{
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020097 return (((void *)&notes->src->histograms) +
98 (notes->src->sizeof_sym_hist * idx));
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020099}
100
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200101static inline struct annotation *symbol__annotation(struct symbol *sym)
102{
103 struct sannotation *a = container_of(sym, struct sannotation, symbol);
104 return &a->annotation;
105}
106
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -0200107int symbol__inc_addr_samples(struct symbol *sym, struct map *map,
108 int evidx, u64 addr);
Arnaldo Carvalho de Melod04b35f2011-11-11 22:17:32 -0200109int symbol__alloc_hist(struct symbol *sym);
Arnaldo Carvalho de Melo36532462011-02-06 14:54:44 -0200110void symbol__annotate_zero_histograms(struct symbol *sym);
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200111
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -0200112int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize);
113int symbol__annotate_init(struct map *map __used, struct symbol *sym);
114int symbol__annotate_printf(struct symbol *sym, struct map *map, int evidx,
Arnaldo Carvalho de Melod5e3d742011-02-08 15:29:25 -0200115 bool full_paths, int min_pcnt, int max_lines,
116 int context);
Arnaldo Carvalho de Melo36532462011-02-06 14:54:44 -0200117void symbol__annotate_zero_histogram(struct symbol *sym, int evidx);
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -0200118void symbol__annotate_decay_histogram(struct symbol *sym, int evidx);
Arnaldo Carvalho de Melo29ed6e72012-04-15 15:24:39 -0300119void disasm__purge(struct list_head *head);
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200120
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -0200121int symbol__tty_annotate(struct symbol *sym, struct map *map, int evidx,
Arnaldo Carvalho de Melod040bd32011-02-05 15:37:31 -0200122 bool print_lines, bool full_paths, int min_pcnt,
123 int max_lines);
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200124
125#ifdef NO_NEWT_SUPPORT
Borislav Petkova2221792011-02-07 15:32:18 +0100126static inline int symbol__tui_annotate(struct symbol *sym __used,
Arnaldo Carvalho de Meloc97cf422011-02-22 12:02:07 -0300127 struct map *map __used,
Arnaldo Carvalho de Melo81cce8d2011-10-05 19:11:32 -0300128 int evidx __used,
129 void(*timer)(void *arg) __used,
130 void *arg __used, int delay_secs __used)
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200131{
132 return 0;
133}
134#else
Arnaldo Carvalho de Meloc97cf422011-02-22 12:02:07 -0300135int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
Arnaldo Carvalho de Melod04b35f2011-11-11 22:17:32 -0200136 void(*timer)(void *arg), void *arg, int delay_secs);
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200137#endif
138
Andi Kleenf69b64f2011-09-15 14:31:41 -0700139extern const char *disassembler_style;
140
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200141#endif /* __PERF_ANNOTATE_H */