xref: /linux/tools/perf/util/annotate-data.h (revision a06c3fad49a50d5d5eb078f93e70f4d3eca5d5a5)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _PERF_ANNOTATE_DATA_H
3 #define _PERF_ANNOTATE_DATA_H
4 
5 #include <errno.h>
6 #include <linux/compiler.h>
7 #include <linux/rbtree.h>
8 #include <linux/types.h>
9 
10 struct annotated_op_loc;
11 struct debuginfo;
12 struct evsel;
13 struct hist_browser_timer;
14 struct hist_entry;
15 struct map_symbol;
16 struct thread;
17 
18 /**
19  * struct annotated_member - Type of member field
20  * @node: List entry in the parent list
21  * @children: List head for child nodes
22  * @type_name: Name of the member type
23  * @var_name: Name of the member variable
24  * @offset: Offset from the outer data type
25  * @size: Size of the member field
26  *
27  * This represents a member type in a data type.
28  */
29 struct annotated_member {
30 	struct list_head node;
31 	struct list_head children;
32 	char *type_name;
33 	char *var_name;
34 	int offset;
35 	int size;
36 };
37 
38 /**
39  * struct type_hist_entry - Histogram entry per offset
40  * @nr_samples: Number of samples
41  * @period: Count of event
42  */
43 struct type_hist_entry {
44 	int nr_samples;
45 	u64 period;
46 };
47 
48 /**
49  * struct type_hist - Type histogram for each event
50  * @nr_samples: Total number of samples in this data type
51  * @period: Total count of the event in this data type
52  * @offset: Array of histogram entry
53  */
54 struct type_hist {
55 	u64			nr_samples;
56 	u64			period;
57 	struct type_hist_entry	addr[];
58 };
59 
60 /**
61  * struct annotated_data_type - Data type to profile
62  * @node: RB-tree node for dso->type_tree
63  * @self: Actual type information
64  * @nr_histogram: Number of histogram entries
65  * @histograms: An array of pointers to histograms
66  *
67  * This represents a data type accessed by samples in the profile data.
68  */
69 struct annotated_data_type {
70 	struct rb_node node;
71 	struct annotated_member self;
72 	int nr_histograms;
73 	struct type_hist **histograms;
74 };
75 
76 extern struct annotated_data_type unknown_type;
77 extern struct annotated_data_type stackop_type;
78 extern struct annotated_data_type canary_type;
79 
80 /**
81  * struct data_loc_info - Data location information
82  * @arch: CPU architecture info
83  * @thread: Thread info
84  * @ms: Map and Symbol info
85  * @ip: Instruction address
86  * @var_addr: Data address (for global variables)
87  * @cpumode: CPU execution mode
88  * @op: Instruction operand location (regs and offset)
89  * @di: Debug info
90  * @fbreg: Frame base register
91  * @fb_cfa: Whether the frame needs to check CFA
92  * @type_offset: Final offset in the type
93  */
94 struct data_loc_info {
95 	/* These are input field, should be filled by caller */
96 	struct arch *arch;
97 	struct thread *thread;
98 	struct map_symbol *ms;
99 	u64 ip;
100 	u64 var_addr;
101 	u8 cpumode;
102 	struct annotated_op_loc *op;
103 
104 	/* These are used internally */
105 	struct debuginfo *di;
106 	int fbreg;
107 	bool fb_cfa;
108 
109 	/* This is for the result */
110 	int type_offset;
111 };
112 
113 /**
114  * struct annotated_data_stat - Debug statistics
115  * @total: Total number of entry
116  * @no_sym: No symbol or map found
117  * @no_insn: Failed to get disasm line
118  * @no_insn_ops: The instruction has no operands
119  * @no_mem_ops: The instruction has no memory operands
120  * @no_reg: Failed to extract a register from the operand
121  * @no_dbginfo: The binary has no debug information
122  * @no_cuinfo: Failed to find a compile_unit
123  * @no_var: Failed to find a matching variable
124  * @no_typeinfo: Failed to get a type info for the variable
125  * @invalid_size: Failed to get a size info of the type
126  * @bad_offset: The access offset is out of the type
127  */
128 struct annotated_data_stat {
129 	int total;
130 	int no_sym;
131 	int no_insn;
132 	int no_insn_ops;
133 	int no_mem_ops;
134 	int no_reg;
135 	int no_dbginfo;
136 	int no_cuinfo;
137 	int no_var;
138 	int no_typeinfo;
139 	int invalid_size;
140 	int bad_offset;
141 	int insn_track;
142 };
143 extern struct annotated_data_stat ann_data_stat;
144 
145 #ifdef HAVE_DWARF_SUPPORT
146 
147 /* Returns data type at the location (ip, reg, offset) */
148 struct annotated_data_type *find_data_type(struct data_loc_info *dloc);
149 
150 /* Update type access histogram at the given offset */
151 int annotated_data_type__update_samples(struct annotated_data_type *adt,
152 					struct evsel *evsel, int offset,
153 					int nr_samples, u64 period);
154 
155 /* Release all data type information in the tree */
156 void annotated_data_type__tree_delete(struct rb_root *root);
157 
158 /* Release all global variable information in the tree */
159 void global_var_type__tree_delete(struct rb_root *root);
160 
161 int hist_entry__annotate_data_tty(struct hist_entry *he, struct evsel *evsel);
162 
163 #else /* HAVE_DWARF_SUPPORT */
164 
165 static inline struct annotated_data_type *
166 find_data_type(struct data_loc_info *dloc __maybe_unused)
167 {
168 	return NULL;
169 }
170 
171 static inline int
172 annotated_data_type__update_samples(struct annotated_data_type *adt __maybe_unused,
173 				    struct evsel *evsel __maybe_unused,
174 				    int offset __maybe_unused,
175 				    int nr_samples __maybe_unused,
176 				    u64 period __maybe_unused)
177 {
178 	return -1;
179 }
180 
181 static inline void annotated_data_type__tree_delete(struct rb_root *root __maybe_unused)
182 {
183 }
184 
185 static inline void global_var_type__tree_delete(struct rb_root *root __maybe_unused)
186 {
187 }
188 
189 static inline int hist_entry__annotate_data_tty(struct hist_entry *he __maybe_unused,
190 						struct evsel *evsel __maybe_unused)
191 {
192 	return -1;
193 }
194 
195 #endif /* HAVE_DWARF_SUPPORT */
196 
197 #ifdef HAVE_SLANG_SUPPORT
198 int hist_entry__annotate_data_tui(struct hist_entry *he, struct evsel *evsel,
199 				  struct hist_browser_timer *hbt);
200 #else
201 static inline int hist_entry__annotate_data_tui(struct hist_entry *he __maybe_unused,
202 						struct evsel *evsel __maybe_unused,
203 						struct hist_browser_timer *hbt __maybe_unused)
204 {
205 	return -1;
206 }
207 #endif /* HAVE_SLANG_SUPPORT */
208 
209 #endif /* _PERF_ANNOTATE_DATA_H */
210