xref: /linux/tools/perf/util/annotate-data.h (revision 61a9741e9f78c64c5178e4ae9d405eeceff04c8f)
1b9c87f53SNamhyung Kim /* SPDX-License-Identifier: GPL-2.0 */
2b9c87f53SNamhyung Kim #ifndef _PERF_ANNOTATE_DATA_H
3b9c87f53SNamhyung Kim #define _PERF_ANNOTATE_DATA_H
4b9c87f53SNamhyung Kim 
5b9c87f53SNamhyung Kim #include <errno.h>
6b9c87f53SNamhyung Kim #include <linux/compiler.h>
7fc044c53SNamhyung Kim #include <linux/rbtree.h>
8b9c87f53SNamhyung Kim #include <linux/types.h>
9b9c87f53SNamhyung Kim 
109bd7ddd1SNamhyung Kim struct evsel;
11b9c87f53SNamhyung Kim struct map_symbol;
12b9c87f53SNamhyung Kim 
13b9c87f53SNamhyung Kim /**
144a111cadSNamhyung Kim  * struct annotated_member - Type of member field
154a111cadSNamhyung Kim  * @node: List entry in the parent list
164a111cadSNamhyung Kim  * @children: List head for child nodes
174a111cadSNamhyung Kim  * @type_name: Name of the member type
184a111cadSNamhyung Kim  * @var_name: Name of the member variable
194a111cadSNamhyung Kim  * @offset: Offset from the outer data type
204a111cadSNamhyung Kim  * @size: Size of the member field
214a111cadSNamhyung Kim  *
224a111cadSNamhyung Kim  * This represents a member type in a data type.
234a111cadSNamhyung Kim  */
244a111cadSNamhyung Kim struct annotated_member {
254a111cadSNamhyung Kim 	struct list_head node;
264a111cadSNamhyung Kim 	struct list_head children;
274a111cadSNamhyung Kim 	char *type_name;
284a111cadSNamhyung Kim 	char *var_name;
294a111cadSNamhyung Kim 	int offset;
304a111cadSNamhyung Kim 	int size;
314a111cadSNamhyung Kim };
324a111cadSNamhyung Kim 
334a111cadSNamhyung Kim /**
349bd7ddd1SNamhyung Kim  * struct type_hist_entry - Histogram entry per offset
359bd7ddd1SNamhyung Kim  * @nr_samples: Number of samples
369bd7ddd1SNamhyung Kim  * @period: Count of event
379bd7ddd1SNamhyung Kim  */
389bd7ddd1SNamhyung Kim struct type_hist_entry {
399bd7ddd1SNamhyung Kim 	int nr_samples;
409bd7ddd1SNamhyung Kim 	u64 period;
419bd7ddd1SNamhyung Kim };
429bd7ddd1SNamhyung Kim 
439bd7ddd1SNamhyung Kim /**
449bd7ddd1SNamhyung Kim  * struct type_hist - Type histogram for each event
459bd7ddd1SNamhyung Kim  * @nr_samples: Total number of samples in this data type
469bd7ddd1SNamhyung Kim  * @period: Total count of the event in this data type
479bd7ddd1SNamhyung Kim  * @offset: Array of histogram entry
489bd7ddd1SNamhyung Kim  */
499bd7ddd1SNamhyung Kim struct type_hist {
509bd7ddd1SNamhyung Kim 	u64			nr_samples;
519bd7ddd1SNamhyung Kim 	u64			period;
529bd7ddd1SNamhyung Kim 	struct type_hist_entry	addr[];
539bd7ddd1SNamhyung Kim };
549bd7ddd1SNamhyung Kim 
559bd7ddd1SNamhyung Kim /**
56b9c87f53SNamhyung Kim  * struct annotated_data_type - Data type to profile
574a111cadSNamhyung Kim  * @node: RB-tree node for dso->type_tree
584a111cadSNamhyung Kim  * @self: Actual type information
599bd7ddd1SNamhyung Kim  * @nr_histogram: Number of histogram entries
609bd7ddd1SNamhyung Kim  * @histograms: An array of pointers to histograms
61b9c87f53SNamhyung Kim  *
62b9c87f53SNamhyung Kim  * This represents a data type accessed by samples in the profile data.
63b9c87f53SNamhyung Kim  */
64b9c87f53SNamhyung Kim struct annotated_data_type {
65fc044c53SNamhyung Kim 	struct rb_node node;
664a111cadSNamhyung Kim 	struct annotated_member self;
679bd7ddd1SNamhyung Kim 	int nr_histograms;
689bd7ddd1SNamhyung Kim 	struct type_hist **histograms;
69b9c87f53SNamhyung Kim };
70b9c87f53SNamhyung Kim 
712f2c41bdSNamhyung Kim extern struct annotated_data_type unknown_type;
722f2c41bdSNamhyung Kim 
73*61a9741eSNamhyung Kim /**
74*61a9741eSNamhyung Kim  * struct annotated_data_stat - Debug statistics
75*61a9741eSNamhyung Kim  * @total: Total number of entry
76*61a9741eSNamhyung Kim  * @no_sym: No symbol or map found
77*61a9741eSNamhyung Kim  * @no_insn: Failed to get disasm line
78*61a9741eSNamhyung Kim  * @no_insn_ops: The instruction has no operands
79*61a9741eSNamhyung Kim  * @no_mem_ops: The instruction has no memory operands
80*61a9741eSNamhyung Kim  * @no_reg: Failed to extract a register from the operand
81*61a9741eSNamhyung Kim  * @no_dbginfo: The binary has no debug information
82*61a9741eSNamhyung Kim  * @no_cuinfo: Failed to find a compile_unit
83*61a9741eSNamhyung Kim  * @no_var: Failed to find a matching variable
84*61a9741eSNamhyung Kim  * @no_typeinfo: Failed to get a type info for the variable
85*61a9741eSNamhyung Kim  * @invalid_size: Failed to get a size info of the type
86*61a9741eSNamhyung Kim  * @bad_offset: The access offset is out of the type
87*61a9741eSNamhyung Kim  */
88*61a9741eSNamhyung Kim struct annotated_data_stat {
89*61a9741eSNamhyung Kim 	int total;
90*61a9741eSNamhyung Kim 	int no_sym;
91*61a9741eSNamhyung Kim 	int no_insn;
92*61a9741eSNamhyung Kim 	int no_insn_ops;
93*61a9741eSNamhyung Kim 	int no_mem_ops;
94*61a9741eSNamhyung Kim 	int no_reg;
95*61a9741eSNamhyung Kim 	int no_dbginfo;
96*61a9741eSNamhyung Kim 	int no_cuinfo;
97*61a9741eSNamhyung Kim 	int no_var;
98*61a9741eSNamhyung Kim 	int no_typeinfo;
99*61a9741eSNamhyung Kim 	int invalid_size;
100*61a9741eSNamhyung Kim 	int bad_offset;
101*61a9741eSNamhyung Kim };
102*61a9741eSNamhyung Kim extern struct annotated_data_stat ann_data_stat;
103*61a9741eSNamhyung Kim 
104b9c87f53SNamhyung Kim #ifdef HAVE_DWARF_SUPPORT
105b9c87f53SNamhyung Kim 
106b9c87f53SNamhyung Kim /* Returns data type at the location (ip, reg, offset) */
107b9c87f53SNamhyung Kim struct annotated_data_type *find_data_type(struct map_symbol *ms, u64 ip,
108b9c87f53SNamhyung Kim 					   int reg, int offset);
109b9c87f53SNamhyung Kim 
1109bd7ddd1SNamhyung Kim /* Update type access histogram at the given offset */
1119bd7ddd1SNamhyung Kim int annotated_data_type__update_samples(struct annotated_data_type *adt,
1129bd7ddd1SNamhyung Kim 					struct evsel *evsel, int offset,
1139bd7ddd1SNamhyung Kim 					int nr_samples, u64 period);
1149bd7ddd1SNamhyung Kim 
115fc044c53SNamhyung Kim /* Release all data type information in the tree */
116fc044c53SNamhyung Kim void annotated_data_type__tree_delete(struct rb_root *root);
117fc044c53SNamhyung Kim 
118b9c87f53SNamhyung Kim #else /* HAVE_DWARF_SUPPORT */
119b9c87f53SNamhyung Kim 
120b9c87f53SNamhyung Kim static inline struct annotated_data_type *
121b9c87f53SNamhyung Kim find_data_type(struct map_symbol *ms __maybe_unused, u64 ip __maybe_unused,
122b9c87f53SNamhyung Kim 	       int reg __maybe_unused, int offset __maybe_unused)
123b9c87f53SNamhyung Kim {
124b9c87f53SNamhyung Kim 	return NULL;
125b9c87f53SNamhyung Kim }
126b9c87f53SNamhyung Kim 
1279bd7ddd1SNamhyung Kim static inline int
1289bd7ddd1SNamhyung Kim annotated_data_type__update_samples(struct annotated_data_type *adt __maybe_unused,
1299bd7ddd1SNamhyung Kim 				    struct evsel *evsel __maybe_unused,
1309bd7ddd1SNamhyung Kim 				    int offset __maybe_unused,
1319bd7ddd1SNamhyung Kim 				    int nr_samples __maybe_unused,
1329bd7ddd1SNamhyung Kim 				    u64 period __maybe_unused)
1339bd7ddd1SNamhyung Kim {
1349bd7ddd1SNamhyung Kim 	return -1;
1359bd7ddd1SNamhyung Kim }
1369bd7ddd1SNamhyung Kim 
137fc044c53SNamhyung Kim static inline void annotated_data_type__tree_delete(struct rb_root *root __maybe_unused)
138fc044c53SNamhyung Kim {
139fc044c53SNamhyung Kim }
140fc044c53SNamhyung Kim 
141b9c87f53SNamhyung Kim #endif /* HAVE_DWARF_SUPPORT */
142b9c87f53SNamhyung Kim 
143b9c87f53SNamhyung Kim #endif /* _PERF_ANNOTATE_DATA_H */
144