xref: /linux/tools/perf/util/annotate-data.h (revision aece2094e34e602f37403dda028f464bb41da50c)
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 evsel;
11 struct map_symbol;
12 
13 /**
14  * struct annotated_member - Type of member field
15  * @node: List entry in the parent list
16  * @children: List head for child nodes
17  * @type_name: Name of the member type
18  * @var_name: Name of the member variable
19  * @offset: Offset from the outer data type
20  * @size: Size of the member field
21  *
22  * This represents a member type in a data type.
23  */
24 struct annotated_member {
25 	struct list_head node;
26 	struct list_head children;
27 	char *type_name;
28 	char *var_name;
29 	int offset;
30 	int size;
31 };
32 
33 /**
34  * struct type_hist_entry - Histogram entry per offset
35  * @nr_samples: Number of samples
36  * @period: Count of event
37  */
38 struct type_hist_entry {
39 	int nr_samples;
40 	u64 period;
41 };
42 
43 /**
44  * struct type_hist - Type histogram for each event
45  * @nr_samples: Total number of samples in this data type
46  * @period: Total count of the event in this data type
47  * @offset: Array of histogram entry
48  */
49 struct type_hist {
50 	u64			nr_samples;
51 	u64			period;
52 	struct type_hist_entry	addr[];
53 };
54 
55 /**
56  * struct annotated_data_type - Data type to profile
57  * @node: RB-tree node for dso->type_tree
58  * @self: Actual type information
59  * @nr_histogram: Number of histogram entries
60  * @histograms: An array of pointers to histograms
61  *
62  * This represents a data type accessed by samples in the profile data.
63  */
64 struct annotated_data_type {
65 	struct rb_node node;
66 	struct annotated_member self;
67 	int nr_histograms;
68 	struct type_hist **histograms;
69 };
70 
71 extern struct annotated_data_type unknown_type;
72 
73 /**
74  * struct annotated_data_stat - Debug statistics
75  * @total: Total number of entry
76  * @no_sym: No symbol or map found
77  * @no_insn: Failed to get disasm line
78  * @no_insn_ops: The instruction has no operands
79  * @no_mem_ops: The instruction has no memory operands
80  * @no_reg: Failed to extract a register from the operand
81  * @no_dbginfo: The binary has no debug information
82  * @no_cuinfo: Failed to find a compile_unit
83  * @no_var: Failed to find a matching variable
84  * @no_typeinfo: Failed to get a type info for the variable
85  * @invalid_size: Failed to get a size info of the type
86  * @bad_offset: The access offset is out of the type
87  */
88 struct annotated_data_stat {
89 	int total;
90 	int no_sym;
91 	int no_insn;
92 	int no_insn_ops;
93 	int no_mem_ops;
94 	int no_reg;
95 	int no_dbginfo;
96 	int no_cuinfo;
97 	int no_var;
98 	int no_typeinfo;
99 	int invalid_size;
100 	int bad_offset;
101 };
102 extern struct annotated_data_stat ann_data_stat;
103 
104 #ifdef HAVE_DWARF_SUPPORT
105 
106 /* Returns data type at the location (ip, reg, offset) */
107 struct annotated_data_type *find_data_type(struct map_symbol *ms, u64 ip,
108 					   int reg, int offset);
109 
110 /* Update type access histogram at the given offset */
111 int annotated_data_type__update_samples(struct annotated_data_type *adt,
112 					struct evsel *evsel, int offset,
113 					int nr_samples, u64 period);
114 
115 /* Release all data type information in the tree */
116 void annotated_data_type__tree_delete(struct rb_root *root);
117 
118 #else /* HAVE_DWARF_SUPPORT */
119 
120 static inline struct annotated_data_type *
121 find_data_type(struct map_symbol *ms __maybe_unused, u64 ip __maybe_unused,
122 	       int reg __maybe_unused, int offset __maybe_unused)
123 {
124 	return NULL;
125 }
126 
127 static inline int
128 annotated_data_type__update_samples(struct annotated_data_type *adt __maybe_unused,
129 				    struct evsel *evsel __maybe_unused,
130 				    int offset __maybe_unused,
131 				    int nr_samples __maybe_unused,
132 				    u64 period __maybe_unused)
133 {
134 	return -1;
135 }
136 
137 static inline void annotated_data_type__tree_delete(struct rb_root *root __maybe_unused)
138 {
139 }
140 
141 #endif /* HAVE_DWARF_SUPPORT */
142 
143 #endif /* _PERF_ANNOTATE_DATA_H */
144