blob: 8eec94358a4a1cc627e2d7b16acd62679626bd65 [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;
Namhyung Kim41127962012-11-09 14:58:49 +090079 double percent_sum;
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -020080 char *path;
81};
82
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020083/** struct annotated_source - symbols with hits have this attached as in sannotation
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020084 *
85 * @histogram: Array of addr hit histograms per event being monitored
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020086 * @lines: If 'print_lines' is specified, per source code line percentages
Arnaldo Carvalho de Melo29ed6e72012-04-15 15:24:39 -030087 * @source: source parsed from a disassembler like objdump -dS
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020088 *
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020089 * lines is allocated, percentages calculated and all sorted by percentage
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020090 * when the annotation is about to be presented, so the percentages are for
91 * one of the entries in the histogram array, i.e. for the event/counter being
92 * presented. It is deallocated right after symbol__{tui,tty,etc}_annotate
93 * returns.
94 */
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020095struct annotated_source {
96 struct list_head source;
97 struct source_line *lines;
Arnaldo Carvalho de Melo36532462011-02-06 14:54:44 -020098 int nr_histograms;
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020099 int sizeof_sym_hist;
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -0200100 struct sym_hist histograms[0];
101};
102
103struct annotation {
104 pthread_mutex_t lock;
105 struct annotated_source *src;
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200106};
107
108struct sannotation {
109 struct annotation annotation;
110 struct symbol symbol;
111};
112
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -0200113static inline struct sym_hist *annotation__histogram(struct annotation *notes, int idx)
114{
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -0200115 return (((void *)&notes->src->histograms) +
116 (notes->src->sizeof_sym_hist * idx));
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -0200117}
118
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200119static inline struct annotation *symbol__annotation(struct symbol *sym)
120{
121 struct sannotation *a = container_of(sym, struct sannotation, symbol);
122 return &a->annotation;
123}
124
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -0200125int symbol__inc_addr_samples(struct symbol *sym, struct map *map,
126 int evidx, u64 addr);
Arnaldo Carvalho de Melod04b35f2011-11-11 22:17:32 -0200127int symbol__alloc_hist(struct symbol *sym);
Arnaldo Carvalho de Melo36532462011-02-06 14:54:44 -0200128void symbol__annotate_zero_histograms(struct symbol *sym);
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200129
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -0200130int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize);
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300131int symbol__annotate_init(struct map *map __maybe_unused, struct symbol *sym);
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -0200132int symbol__annotate_printf(struct symbol *sym, struct map *map, int evidx,
Arnaldo Carvalho de Melod5e3d742011-02-08 15:29:25 -0200133 bool full_paths, int min_pcnt, int max_lines,
134 int context);
Arnaldo Carvalho de Melo36532462011-02-06 14:54:44 -0200135void symbol__annotate_zero_histogram(struct symbol *sym, int evidx);
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -0200136void symbol__annotate_decay_histogram(struct symbol *sym, int evidx);
Arnaldo Carvalho de Melo29ed6e72012-04-15 15:24:39 -0300137void disasm__purge(struct list_head *head);
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200138
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -0200139int symbol__tty_annotate(struct symbol *sym, struct map *map, int evidx,
Arnaldo Carvalho de Melod040bd32011-02-05 15:37:31 -0200140 bool print_lines, bool full_paths, int min_pcnt,
141 int max_lines);
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200142
Namhyung Kim1254b512012-09-28 18:32:02 +0900143#ifdef NEWT_SUPPORT
144int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
Namhyung Kim9783adf2012-11-02 14:50:05 +0900145 struct hist_browser_timer *hbt);
Namhyung Kim1254b512012-09-28 18:32:02 +0900146#else
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300147static inline int symbol__tui_annotate(struct symbol *sym __maybe_unused,
148 struct map *map __maybe_unused,
149 int evidx __maybe_unused,
Namhyung Kim9783adf2012-11-02 14:50:05 +0900150 struct hist_browser_timer *hbt
151 __maybe_unused)
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200152{
153 return 0;
154}
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200155#endif
156
Andi Kleenf69b64f2011-09-15 14:31:41 -0700157extern const char *disassembler_style;
158
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200159#endif /* __PERF_ANNOTATE_H */