blob: 39242dcee8f20bd5160bf8d1ea34f1a4ca79ff29 [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>
Irina Tirdea27683dc2012-09-08 03:43:19 +030010#include <pthread.h>
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -020011
Arnaldo Carvalho de Melo28548d72012-04-19 10:16:27 -030012struct ins;
13
Arnaldo Carvalho de Meloc7e6ead2012-04-20 14:38:46 -030014struct ins_operands {
15 char *raw;
Arnaldo Carvalho de Melo44d1a3e2012-04-25 08:00:23 -030016 struct {
Arnaldo Carvalho de Melo6de783b2012-05-11 16:48:49 -030017 char *raw;
Arnaldo Carvalho de Melo44d1a3e2012-04-25 08:00:23 -030018 char *name;
Arnaldo Carvalho de Melo44d1a3e2012-04-25 08:00:23 -030019 u64 addr;
Arnaldo Carvalho de Melo6de783b2012-05-11 16:48:49 -030020 u64 offset;
Arnaldo Carvalho de Melo44d1a3e2012-04-25 08:00:23 -030021 } target;
Arnaldo Carvalho de Melo7a997fe2012-05-12 13:15:34 -030022 union {
23 struct {
24 char *raw;
25 char *name;
26 u64 addr;
27 } source;
28 struct {
29 struct ins *ins;
30 struct ins_operands *ops;
31 } locked;
32 };
Arnaldo Carvalho de Meloc7e6ead2012-04-20 14:38:46 -030033};
34
Arnaldo Carvalho de Melo4f9d0322012-04-18 13:58:34 -030035struct ins_ops {
Arnaldo Carvalho de Meloc46219ac2012-05-12 13:26:20 -030036 void (*free)(struct ins_operands *ops);
Arnaldo Carvalho de Meloc7e6ead2012-04-20 14:38:46 -030037 int (*parse)(struct ins_operands *ops);
Arnaldo Carvalho de Melo28548d72012-04-19 10:16:27 -030038 int (*scnprintf)(struct ins *ins, char *bf, size_t size,
Arnaldo Carvalho de Melo54170722012-05-07 18:54:16 -030039 struct ins_operands *ops);
Arnaldo Carvalho de Melo4f9d0322012-04-18 13:58:34 -030040};
41
42struct ins {
43 const char *name;
44 struct ins_ops *ops;
45};
46
47bool ins__is_jump(const struct ins *ins);
Arnaldo Carvalho de Melod86b0592012-04-18 16:07:38 -030048bool ins__is_call(const struct ins *ins);
Arnaldo Carvalho de Melo54170722012-05-07 18:54:16 -030049int ins__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands *ops);
Arnaldo Carvalho de Melo4f9d0322012-04-18 13:58:34 -030050
Arnaldo Carvalho de Melo29ed6e72012-04-15 15:24:39 -030051struct disasm_line {
Arnaldo Carvalho de Meloc7e6ead2012-04-20 14:38:46 -030052 struct list_head node;
53 s64 offset;
54 char *line;
55 char *name;
56 struct ins *ins;
57 struct ins_operands ops;
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -020058};
59
Arnaldo Carvalho de Melofb29fa52012-04-25 14:16:03 -030060static inline bool disasm_line__has_offset(const struct disasm_line *dl)
61{
62 return dl->ops.target.offset != UINT64_MAX;
63}
64
Arnaldo Carvalho de Melo29ed6e72012-04-15 15:24:39 -030065void disasm_line__free(struct disasm_line *dl);
66struct disasm_line *disasm__get_next_ip_line(struct list_head *head, struct disasm_line *pos);
Arnaldo Carvalho de Melo54170722012-05-07 18:54:16 -030067int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw);
Arnaldo Carvalho de Melo51454182012-04-15 15:52:18 -030068size_t disasm__fprintf(struct list_head *head, FILE *fp);
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -020069
70struct sym_hist {
71 u64 sum;
72 u64 addr[0];
73};
74
75struct source_line {
76 struct rb_node node;
77 double percent;
78 char *path;
79};
80
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020081/** struct annotated_source - symbols with hits have this attached as in sannotation
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020082 *
83 * @histogram: Array of addr hit histograms per event being monitored
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020084 * @lines: If 'print_lines' is specified, per source code line percentages
Arnaldo Carvalho de Melo29ed6e72012-04-15 15:24:39 -030085 * @source: source parsed from a disassembler like objdump -dS
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020086 *
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020087 * lines is allocated, percentages calculated and all sorted by percentage
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020088 * when the annotation is about to be presented, so the percentages are for
89 * one of the entries in the histogram array, i.e. for the event/counter being
90 * presented. It is deallocated right after symbol__{tui,tty,etc}_annotate
91 * returns.
92 */
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020093struct annotated_source {
94 struct list_head source;
95 struct source_line *lines;
Arnaldo Carvalho de Melo36532462011-02-06 14:54:44 -020096 int nr_histograms;
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020097 int sizeof_sym_hist;
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020098 struct sym_hist histograms[0];
99};
100
101struct annotation {
102 pthread_mutex_t lock;
103 struct annotated_source *src;
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200104};
105
106struct sannotation {
107 struct annotation annotation;
108 struct symbol symbol;
109};
110
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -0200111static inline struct sym_hist *annotation__histogram(struct annotation *notes, int idx)
112{
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -0200113 return (((void *)&notes->src->histograms) +
114 (notes->src->sizeof_sym_hist * idx));
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -0200115}
116
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200117static inline struct annotation *symbol__annotation(struct symbol *sym)
118{
119 struct sannotation *a = container_of(sym, struct sannotation, symbol);
120 return &a->annotation;
121}
122
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -0200123int symbol__inc_addr_samples(struct symbol *sym, struct map *map,
124 int evidx, u64 addr);
Arnaldo Carvalho de Melod04b35f2011-11-11 22:17:32 -0200125int symbol__alloc_hist(struct symbol *sym);
Arnaldo Carvalho de Melo36532462011-02-06 14:54:44 -0200126void symbol__annotate_zero_histograms(struct symbol *sym);
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200127
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -0200128int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize);
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300129int symbol__annotate_init(struct map *map __maybe_unused, struct symbol *sym);
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -0200130int symbol__annotate_printf(struct symbol *sym, struct map *map, int evidx,
Arnaldo Carvalho de Melod5e3d742011-02-08 15:29:25 -0200131 bool full_paths, int min_pcnt, int max_lines,
132 int context);
Arnaldo Carvalho de Melo36532462011-02-06 14:54:44 -0200133void symbol__annotate_zero_histogram(struct symbol *sym, int evidx);
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -0200134void symbol__annotate_decay_histogram(struct symbol *sym, int evidx);
Arnaldo Carvalho de Melo29ed6e72012-04-15 15:24:39 -0300135void disasm__purge(struct list_head *head);
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200136
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -0200137int symbol__tty_annotate(struct symbol *sym, struct map *map, int evidx,
Arnaldo Carvalho de Melod040bd32011-02-05 15:37:31 -0200138 bool print_lines, bool full_paths, int min_pcnt,
139 int max_lines);
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200140
Namhyung Kim1254b51e2012-09-28 18:32:02 +0900141#ifdef NEWT_SUPPORT
142int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
143 void(*timer)(void *arg), void *arg, int delay_secs);
144#else
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300145static inline int symbol__tui_annotate(struct symbol *sym __maybe_unused,
146 struct map *map __maybe_unused,
147 int evidx __maybe_unused,
148 void(*timer)(void *arg) __maybe_unused,
149 void *arg __maybe_unused,
150 int delay_secs __maybe_unused)
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200151{
152 return 0;
153}
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200154#endif
155
Andi Kleenf69b64f2011-09-15 14:31:41 -0700156extern const char *disassembler_style;
Maciek Borzecki7a4ec932012-09-04 12:32:30 +0200157extern const char *objdump_path;
Andi Kleenf69b64f2011-09-15 14:31:41 -0700158
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200159#endif /* __PERF_ANNOTATE_H */