blob: 6314335007f05f1c45a1805f7ccd71b0b8e91138 [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 Melo28548d72012-04-19 10:16:27 -030010struct ins;
11
Arnaldo Carvalho de Melo4f9d0322012-04-18 13:58:34 -030012struct ins_ops {
13 int (*parse_target)(const char *operands, u64 *target);
Arnaldo Carvalho de Melo28548d72012-04-19 10:16:27 -030014 int (*scnprintf)(struct ins *ins, char *bf, size_t size,
15 const char *operands, u64 target);
Arnaldo Carvalho de Melo4f9d0322012-04-18 13:58:34 -030016};
17
18struct ins {
19 const char *name;
20 struct ins_ops *ops;
21};
22
23bool ins__is_jump(const struct ins *ins);
Arnaldo Carvalho de Melod86b0592012-04-18 16:07:38 -030024bool ins__is_call(const struct ins *ins);
Arnaldo Carvalho de Melo4f9d0322012-04-18 13:58:34 -030025
Arnaldo Carvalho de Melo29ed6e72012-04-15 15:24:39 -030026struct disasm_line {
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -020027 struct list_head node;
28 s64 offset;
Arnaldo Carvalho de Melo4f9d0322012-04-18 13:58:34 -030029 u64 target;
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -020030 char *line;
Arnaldo Carvalho de Melo51454182012-04-15 15:52:18 -030031 char *name;
Arnaldo Carvalho de Melo4f9d0322012-04-18 13:58:34 -030032 struct ins *ins;
Arnaldo Carvalho de Melo51454182012-04-15 15:52:18 -030033 char *operands;
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -020034};
35
Arnaldo Carvalho de Melo29ed6e72012-04-15 15:24:39 -030036void disasm_line__free(struct disasm_line *dl);
37struct disasm_line *disasm__get_next_ip_line(struct list_head *head, struct disasm_line *pos);
Arnaldo Carvalho de Melo51454182012-04-15 15:52:18 -030038size_t disasm__fprintf(struct list_head *head, FILE *fp);
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -020039
40struct sym_hist {
41 u64 sum;
42 u64 addr[0];
43};
44
45struct source_line {
46 struct rb_node node;
47 double percent;
48 char *path;
49};
50
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020051/** struct annotated_source - symbols with hits have this attached as in sannotation
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020052 *
53 * @histogram: Array of addr hit histograms per event being monitored
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020054 * @lines: If 'print_lines' is specified, per source code line percentages
Arnaldo Carvalho de Melo29ed6e72012-04-15 15:24:39 -030055 * @source: source parsed from a disassembler like objdump -dS
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020056 *
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020057 * lines is allocated, percentages calculated and all sorted by percentage
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020058 * when the annotation is about to be presented, so the percentages are for
59 * one of the entries in the histogram array, i.e. for the event/counter being
60 * presented. It is deallocated right after symbol__{tui,tty,etc}_annotate
61 * returns.
62 */
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020063struct annotated_source {
64 struct list_head source;
65 struct source_line *lines;
Arnaldo Carvalho de Melo36532462011-02-06 14:54:44 -020066 int nr_histograms;
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020067 int sizeof_sym_hist;
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020068 struct sym_hist histograms[0];
69};
70
71struct annotation {
72 pthread_mutex_t lock;
73 struct annotated_source *src;
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -020074};
75
76struct sannotation {
77 struct annotation annotation;
78 struct symbol symbol;
79};
80
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020081static inline struct sym_hist *annotation__histogram(struct annotation *notes, int idx)
82{
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020083 return (((void *)&notes->src->histograms) +
84 (notes->src->sizeof_sym_hist * idx));
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020085}
86
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -020087static inline struct annotation *symbol__annotation(struct symbol *sym)
88{
89 struct sannotation *a = container_of(sym, struct sannotation, symbol);
90 return &a->annotation;
91}
92
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020093int symbol__inc_addr_samples(struct symbol *sym, struct map *map,
94 int evidx, u64 addr);
Arnaldo Carvalho de Melod04b35f2011-11-11 22:17:32 -020095int symbol__alloc_hist(struct symbol *sym);
Arnaldo Carvalho de Melo36532462011-02-06 14:54:44 -020096void symbol__annotate_zero_histograms(struct symbol *sym);
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -020097
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020098int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize);
99int symbol__annotate_init(struct map *map __used, struct symbol *sym);
100int symbol__annotate_printf(struct symbol *sym, struct map *map, int evidx,
Arnaldo Carvalho de Melod5e3d742011-02-08 15:29:25 -0200101 bool full_paths, int min_pcnt, int max_lines,
102 int context);
Arnaldo Carvalho de Melo36532462011-02-06 14:54:44 -0200103void symbol__annotate_zero_histogram(struct symbol *sym, int evidx);
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -0200104void symbol__annotate_decay_histogram(struct symbol *sym, int evidx);
Arnaldo Carvalho de Melo29ed6e72012-04-15 15:24:39 -0300105void disasm__purge(struct list_head *head);
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200106
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -0200107int symbol__tty_annotate(struct symbol *sym, struct map *map, int evidx,
Arnaldo Carvalho de Melod040bd32011-02-05 15:37:31 -0200108 bool print_lines, bool full_paths, int min_pcnt,
109 int max_lines);
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200110
111#ifdef NO_NEWT_SUPPORT
Borislav Petkova2221792011-02-07 15:32:18 +0100112static inline int symbol__tui_annotate(struct symbol *sym __used,
Arnaldo Carvalho de Meloc97cf422011-02-22 12:02:07 -0300113 struct map *map __used,
Arnaldo Carvalho de Melo81cce8d2011-10-05 19:11:32 -0300114 int evidx __used,
115 void(*timer)(void *arg) __used,
116 void *arg __used, int delay_secs __used)
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200117{
118 return 0;
119}
120#else
Arnaldo Carvalho de Meloc97cf422011-02-22 12:02:07 -0300121int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
Arnaldo Carvalho de Melod04b35f2011-11-11 22:17:32 -0200122 void(*timer)(void *arg), void *arg, int delay_secs);
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200123#endif
124
Andi Kleenf69b64f2011-09-15 14:31:41 -0700125extern const char *disassembler_style;
126
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200127#endif /* __PERF_ANNOTATE_H */