blob: c6272011625a7ccdb9fb04af2bda8d5559ba1b41 [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"
Namhyung Kim9783adf2012-11-02 14:50:05 +09008#include "hist.h"
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -02009#include <linux/list.h>
10#include <linux/rbtree.h>
Irina Tirdea27683dc2012-09-08 03:43:19 +030011#include <pthread.h>
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -020012
Arnaldo Carvalho de Melo28548d72012-04-19 10:16:27 -030013struct ins;
14
Arnaldo Carvalho de Meloc7e6ead2012-04-20 14:38:46 -030015struct ins_operands {
16 char *raw;
Arnaldo Carvalho de Melo44d1a3e2012-04-25 08:00:23 -030017 struct {
Arnaldo Carvalho de Melo6de783b2012-05-11 16:48:49 -030018 char *raw;
Arnaldo Carvalho de Melo44d1a3e2012-04-25 08:00:23 -030019 char *name;
Arnaldo Carvalho de Melo44d1a3e2012-04-25 08:00:23 -030020 u64 addr;
Arnaldo Carvalho de Melo6de783b2012-05-11 16:48:49 -030021 u64 offset;
Arnaldo Carvalho de Melo44d1a3e2012-04-25 08:00:23 -030022 } target;
Arnaldo Carvalho de Melo7a997fe2012-05-12 13:15:34 -030023 union {
24 struct {
25 char *raw;
26 char *name;
27 u64 addr;
28 } source;
29 struct {
30 struct ins *ins;
31 struct ins_operands *ops;
32 } locked;
33 };
Arnaldo Carvalho de Meloc7e6ead2012-04-20 14:38:46 -030034};
35
Arnaldo Carvalho de Melo4f9d0322012-04-18 13:58:34 -030036struct ins_ops {
Arnaldo Carvalho de Meloc46219ac2012-05-12 13:26:20 -030037 void (*free)(struct ins_operands *ops);
Arnaldo Carvalho de Meloc7e6ead2012-04-20 14:38:46 -030038 int (*parse)(struct ins_operands *ops);
Arnaldo Carvalho de Melo28548d72012-04-19 10:16:27 -030039 int (*scnprintf)(struct ins *ins, char *bf, size_t size,
Arnaldo Carvalho de Melo54170722012-05-07 18:54:16 -030040 struct ins_operands *ops);
Arnaldo Carvalho de Melo4f9d0322012-04-18 13:58:34 -030041};
42
43struct ins {
44 const char *name;
45 struct ins_ops *ops;
46};
47
48bool ins__is_jump(const struct ins *ins);
Arnaldo Carvalho de Melod86b0592012-04-18 16:07:38 -030049bool ins__is_call(const struct ins *ins);
Arnaldo Carvalho de Melo54170722012-05-07 18:54:16 -030050int ins__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands *ops);
Arnaldo Carvalho de Melo4f9d0322012-04-18 13:58:34 -030051
Arnaldo Carvalho de Melo29ed6e72012-04-15 15:24:39 -030052struct disasm_line {
Arnaldo Carvalho de Meloc7e6ead2012-04-20 14:38:46 -030053 struct list_head node;
54 s64 offset;
55 char *line;
56 char *name;
57 struct ins *ins;
58 struct ins_operands ops;
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -020059};
60
Arnaldo Carvalho de Melofb29fa52012-04-25 14:16:03 -030061static inline bool disasm_line__has_offset(const struct disasm_line *dl)
62{
63 return dl->ops.target.offset != UINT64_MAX;
64}
65
Arnaldo Carvalho de Melo29ed6e72012-04-15 15:24:39 -030066void disasm_line__free(struct disasm_line *dl);
67struct disasm_line *disasm__get_next_ip_line(struct list_head *head, struct disasm_line *pos);
Arnaldo Carvalho de Melo54170722012-05-07 18:54:16 -030068int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw);
Arnaldo Carvalho de Melo51454182012-04-15 15:52:18 -030069size_t disasm__fprintf(struct list_head *head, FILE *fp);
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -020070
71struct sym_hist {
72 u64 sum;
73 u64 addr[0];
74};
75
76struct source_line {
77 struct rb_node node;
78 double percent;
79 char *path;
80};
81
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020082/** struct annotated_source - symbols with hits have this attached as in sannotation
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020083 *
84 * @histogram: Array of addr hit histograms per event being monitored
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020085 * @lines: If 'print_lines' is specified, per source code line percentages
Arnaldo Carvalho de Melo29ed6e72012-04-15 15:24:39 -030086 * @source: source parsed from a disassembler like objdump -dS
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020087 *
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020088 * lines is allocated, percentages calculated and all sorted by percentage
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020089 * when the annotation is about to be presented, so the percentages are for
90 * one of the entries in the histogram array, i.e. for the event/counter being
91 * presented. It is deallocated right after symbol__{tui,tty,etc}_annotate
92 * returns.
93 */
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020094struct annotated_source {
95 struct list_head source;
96 struct source_line *lines;
Arnaldo Carvalho de Melo36532462011-02-06 14:54:44 -020097 int nr_histograms;
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020098 int sizeof_sym_hist;
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020099 struct sym_hist histograms[0];
100};
101
102struct annotation {
103 pthread_mutex_t lock;
104 struct annotated_source *src;
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200105};
106
107struct sannotation {
108 struct annotation annotation;
109 struct symbol symbol;
110};
111
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -0200112static inline struct sym_hist *annotation__histogram(struct annotation *notes, int idx)
113{
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -0200114 return (((void *)&notes->src->histograms) +
115 (notes->src->sizeof_sym_hist * idx));
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -0200116}
117
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200118static inline struct annotation *symbol__annotation(struct symbol *sym)
119{
120 struct sannotation *a = container_of(sym, struct sannotation, symbol);
121 return &a->annotation;
122}
123
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -0200124int symbol__inc_addr_samples(struct symbol *sym, struct map *map,
125 int evidx, u64 addr);
Arnaldo Carvalho de Melod04b35f2011-11-11 22:17:32 -0200126int symbol__alloc_hist(struct symbol *sym);
Arnaldo Carvalho de Melo36532462011-02-06 14:54:44 -0200127void symbol__annotate_zero_histograms(struct symbol *sym);
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200128
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -0200129int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize);
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300130int symbol__annotate_init(struct map *map __maybe_unused, struct symbol *sym);
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -0200131int symbol__annotate_printf(struct symbol *sym, struct map *map, int evidx,
Arnaldo Carvalho de Melod5e3d742011-02-08 15:29:25 -0200132 bool full_paths, int min_pcnt, int max_lines,
133 int context);
Arnaldo Carvalho de Melo36532462011-02-06 14:54:44 -0200134void symbol__annotate_zero_histogram(struct symbol *sym, int evidx);
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -0200135void symbol__annotate_decay_histogram(struct symbol *sym, int evidx);
Arnaldo Carvalho de Melo29ed6e72012-04-15 15:24:39 -0300136void disasm__purge(struct list_head *head);
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200137
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -0200138int symbol__tty_annotate(struct symbol *sym, struct map *map, int evidx,
Arnaldo Carvalho de Melod040bd32011-02-05 15:37:31 -0200139 bool print_lines, bool full_paths, int min_pcnt,
140 int max_lines);
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200141
Namhyung Kim1254b512012-09-28 18:32:02 +0900142#ifdef NEWT_SUPPORT
143int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
Namhyung Kim9783adf2012-11-02 14:50:05 +0900144 struct hist_browser_timer *hbt);
Namhyung Kim1254b512012-09-28 18:32:02 +0900145#else
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300146static inline int symbol__tui_annotate(struct symbol *sym __maybe_unused,
147 struct map *map __maybe_unused,
148 int evidx __maybe_unused,
Namhyung Kim9783adf2012-11-02 14:50:05 +0900149 struct hist_browser_timer *hbt
150 __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;
157
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200158#endif /* __PERF_ANNOTATE_H */