annotate.h revision e6817ec1d8ab31fc7b01906e305f848542df6413
1#ifndef __PERF_ANNOTATE_H
2#define __PERF_ANNOTATE_H
3
4#include <stdbool.h>
5#include "types.h"
6#include "symbol.h"
7/* ANDROID_CHANGE_BEGIN */
8#if 0
9#include <linux/list.h>
10#include <linux/rbtree.h>
11#else
12#include "include/linux/list.h"
13#include "include/linux/rbtree.h"
14#ifdef __BIONIC__
15#include <pthread.h>
16#endif
17#endif
18/* ANDROID_CHANGE_END */
19
20struct objdump_line {
21	struct list_head node;
22	s64		 offset;
23	char		 *line;
24};
25
26void objdump_line__free(struct objdump_line *self);
27struct objdump_line *objdump__get_next_ip_line(struct list_head *head,
28					       struct objdump_line *pos);
29
30struct sym_hist {
31	u64		sum;
32	u64		addr[0];
33};
34
35struct source_line {
36	struct rb_node	node;
37	double		percent;
38	char		*path;
39};
40
41/** struct annotated_source - symbols with hits have this attached as in sannotation
42 *
43 * @histogram: Array of addr hit histograms per event being monitored
44 * @lines: If 'print_lines' is specified, per source code line percentages
45 * @source: source parsed from objdump -dS
46 *
47 * lines is allocated, percentages calculated and all sorted by percentage
48 * when the annotation is about to be presented, so the percentages are for
49 * one of the entries in the histogram array, i.e. for the event/counter being
50 * presented. It is deallocated right after symbol__{tui,tty,etc}_annotate
51 * returns.
52 */
53struct annotated_source {
54	struct list_head   source;
55	struct source_line *lines;
56	int    		   nr_histograms;
57	int    		   sizeof_sym_hist;
58	struct sym_hist	   histograms[0];
59};
60
61struct annotation {
62	pthread_mutex_t		lock;
63	struct annotated_source *src;
64};
65
66struct sannotation {
67	struct annotation annotation;
68	struct symbol	  symbol;
69};
70
71static inline struct sym_hist *annotation__histogram(struct annotation *notes, int idx)
72{
73	return (((void *)&notes->src->histograms) +
74	 	(notes->src->sizeof_sym_hist * idx));
75}
76
77static inline struct annotation *symbol__annotation(struct symbol *sym)
78{
79	struct sannotation *a = container_of(sym, struct sannotation, symbol);
80	return &a->annotation;
81}
82
83int symbol__inc_addr_samples(struct symbol *sym, struct map *map,
84			     int evidx, u64 addr);
85int symbol__alloc_hist(struct symbol *sym, int nevents);
86void symbol__annotate_zero_histograms(struct symbol *sym);
87
88int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize);
89int symbol__annotate_init(struct map *map __used, struct symbol *sym);
90int symbol__annotate_printf(struct symbol *sym, struct map *map, int evidx,
91			    bool full_paths, int min_pcnt, int max_lines,
92			    int context);
93void symbol__annotate_zero_histogram(struct symbol *sym, int evidx);
94void symbol__annotate_decay_histogram(struct symbol *sym, int evidx);
95void objdump_line_list__purge(struct list_head *head);
96
97int symbol__tty_annotate(struct symbol *sym, struct map *map, int evidx,
98			 bool print_lines, bool full_paths, int min_pcnt,
99			 int max_lines);
100
101#ifdef NO_NEWT_SUPPORT
102static inline int symbol__tui_annotate(struct symbol *sym __used,
103				       struct map *map __used,
104				       int evidx __used, int refresh __used)
105{
106	return 0;
107}
108#else
109int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
110			 int refresh);
111#endif
112
113#endif	/* __PERF_ANNOTATE_H */
114