blob: a2105f204a421338cd2b368aad2b8df0e1bc41b5 [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>
5#include "types.h"
6#include "symbol.h"
7#include <linux/list.h>
8#include <linux/rbtree.h>
9
Arnaldo Carvalho de Melo4f9d0322012-04-18 13:58:34 -030010struct ins_ops {
11 int (*parse_target)(const char *operands, u64 *target);
12};
13
14struct ins {
15 const char *name;
16 struct ins_ops *ops;
17};
18
19bool ins__is_jump(const struct ins *ins);
Arnaldo Carvalho de Melod86b0592012-04-18 16:07:38 -030020bool ins__is_call(const struct ins *ins);
Arnaldo Carvalho de Melo4f9d0322012-04-18 13:58:34 -030021
Arnaldo Carvalho de Melo29ed6e72012-04-15 15:24:39 -030022struct disasm_line {
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -020023 struct list_head node;
24 s64 offset;
Arnaldo Carvalho de Melo4f9d0322012-04-18 13:58:34 -030025 u64 target;
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -020026 char *line;
Arnaldo Carvalho de Melo51454182012-04-15 15:52:18 -030027 char *name;
Arnaldo Carvalho de Melo4f9d0322012-04-18 13:58:34 -030028 struct ins *ins;
Arnaldo Carvalho de Melo51454182012-04-15 15:52:18 -030029 char *operands;
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -020030};
31
Arnaldo Carvalho de Melo29ed6e72012-04-15 15:24:39 -030032void disasm_line__free(struct disasm_line *dl);
33struct disasm_line *disasm__get_next_ip_line(struct list_head *head, struct disasm_line *pos);
Arnaldo Carvalho de Melo51454182012-04-15 15:52:18 -030034size_t disasm__fprintf(struct list_head *head, FILE *fp);
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -020035
36struct sym_hist {
37 u64 sum;
38 u64 addr[0];
39};
40
41struct source_line {
42 struct rb_node node;
43 double percent;
44 char *path;
45};
46
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020047/** struct annotated_source - symbols with hits have this attached as in sannotation
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020048 *
49 * @histogram: Array of addr hit histograms per event being monitored
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020050 * @lines: If 'print_lines' is specified, per source code line percentages
Arnaldo Carvalho de Melo29ed6e72012-04-15 15:24:39 -030051 * @source: source parsed from a disassembler like objdump -dS
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020052 *
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020053 * lines is allocated, percentages calculated and all sorted by percentage
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020054 * when the annotation is about to be presented, so the percentages are for
55 * one of the entries in the histogram array, i.e. for the event/counter being
56 * presented. It is deallocated right after symbol__{tui,tty,etc}_annotate
57 * returns.
58 */
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020059struct annotated_source {
60 struct list_head source;
61 struct source_line *lines;
Arnaldo Carvalho de Melo36532462011-02-06 14:54:44 -020062 int nr_histograms;
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020063 int sizeof_sym_hist;
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020064 struct sym_hist histograms[0];
65};
66
67struct annotation {
68 pthread_mutex_t lock;
69 struct annotated_source *src;
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -020070};
71
72struct sannotation {
73 struct annotation annotation;
74 struct symbol symbol;
75};
76
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020077static inline struct sym_hist *annotation__histogram(struct annotation *notes, int idx)
78{
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020079 return (((void *)&notes->src->histograms) +
80 (notes->src->sizeof_sym_hist * idx));
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020081}
82
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -020083static inline struct annotation *symbol__annotation(struct symbol *sym)
84{
85 struct sannotation *a = container_of(sym, struct sannotation, symbol);
86 return &a->annotation;
87}
88
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020089int symbol__inc_addr_samples(struct symbol *sym, struct map *map,
90 int evidx, u64 addr);
Arnaldo Carvalho de Melod04b35f2011-11-11 22:17:32 -020091int symbol__alloc_hist(struct symbol *sym);
Arnaldo Carvalho de Melo36532462011-02-06 14:54:44 -020092void symbol__annotate_zero_histograms(struct symbol *sym);
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -020093
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020094int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize);
95int symbol__annotate_init(struct map *map __used, struct symbol *sym);
96int symbol__annotate_printf(struct symbol *sym, struct map *map, int evidx,
Arnaldo Carvalho de Melod5e3d742011-02-08 15:29:25 -020097 bool full_paths, int min_pcnt, int max_lines,
98 int context);
Arnaldo Carvalho de Melo36532462011-02-06 14:54:44 -020099void symbol__annotate_zero_histogram(struct symbol *sym, int evidx);
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -0200100void symbol__annotate_decay_histogram(struct symbol *sym, int evidx);
Arnaldo Carvalho de Melo29ed6e72012-04-15 15:24:39 -0300101void disasm__purge(struct list_head *head);
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200102
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -0200103int symbol__tty_annotate(struct symbol *sym, struct map *map, int evidx,
Arnaldo Carvalho de Melod040bd32011-02-05 15:37:31 -0200104 bool print_lines, bool full_paths, int min_pcnt,
105 int max_lines);
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200106
107#ifdef NO_NEWT_SUPPORT
Borislav Petkova2221792011-02-07 15:32:18 +0100108static inline int symbol__tui_annotate(struct symbol *sym __used,
Arnaldo Carvalho de Meloc97cf422011-02-22 12:02:07 -0300109 struct map *map __used,
Arnaldo Carvalho de Melo81cce8d2011-10-05 19:11:32 -0300110 int evidx __used,
111 void(*timer)(void *arg) __used,
112 void *arg __used, int delay_secs __used)
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200113{
114 return 0;
115}
116#else
Arnaldo Carvalho de Meloc97cf422011-02-22 12:02:07 -0300117int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
Arnaldo Carvalho de Melod04b35f2011-11-11 22:17:32 -0200118 void(*timer)(void *arg), void *arg, int delay_secs);
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200119#endif
120
Andi Kleenf69b64f2011-09-15 14:31:41 -0700121extern const char *disassembler_style;
122
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200123#endif /* __PERF_ANNOTATE_H */