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 10d3030191SNamhyung Kim struct annotated_op_loc; 11a3f4d5b5SNamhyung Kim struct debuginfo; 129bd7ddd1SNamhyung Kim struct evsel; 13*d001c7a7SNamhyung Kim struct hist_browser_timer; 149b561be1SNamhyung Kim struct hist_entry; 15b9c87f53SNamhyung Kim struct map_symbol; 161ebb5e17SNamhyung Kim struct thread; 17b9c87f53SNamhyung Kim 18b9c87f53SNamhyung Kim /** 194a111cadSNamhyung Kim * struct annotated_member - Type of member field 204a111cadSNamhyung Kim * @node: List entry in the parent list 214a111cadSNamhyung Kim * @children: List head for child nodes 224a111cadSNamhyung Kim * @type_name: Name of the member type 234a111cadSNamhyung Kim * @var_name: Name of the member variable 244a111cadSNamhyung Kim * @offset: Offset from the outer data type 254a111cadSNamhyung Kim * @size: Size of the member field 264a111cadSNamhyung Kim * 274a111cadSNamhyung Kim * This represents a member type in a data type. 284a111cadSNamhyung Kim */ 294a111cadSNamhyung Kim struct annotated_member { 304a111cadSNamhyung Kim struct list_head node; 314a111cadSNamhyung Kim struct list_head children; 324a111cadSNamhyung Kim char *type_name; 334a111cadSNamhyung Kim char *var_name; 344a111cadSNamhyung Kim int offset; 354a111cadSNamhyung Kim int size; 364a111cadSNamhyung Kim }; 374a111cadSNamhyung Kim 384a111cadSNamhyung Kim /** 399bd7ddd1SNamhyung Kim * struct type_hist_entry - Histogram entry per offset 409bd7ddd1SNamhyung Kim * @nr_samples: Number of samples 419bd7ddd1SNamhyung Kim * @period: Count of event 429bd7ddd1SNamhyung Kim */ 439bd7ddd1SNamhyung Kim struct type_hist_entry { 449bd7ddd1SNamhyung Kim int nr_samples; 459bd7ddd1SNamhyung Kim u64 period; 469bd7ddd1SNamhyung Kim }; 479bd7ddd1SNamhyung Kim 489bd7ddd1SNamhyung Kim /** 499bd7ddd1SNamhyung Kim * struct type_hist - Type histogram for each event 509bd7ddd1SNamhyung Kim * @nr_samples: Total number of samples in this data type 519bd7ddd1SNamhyung Kim * @period: Total count of the event in this data type 529bd7ddd1SNamhyung Kim * @offset: Array of histogram entry 539bd7ddd1SNamhyung Kim */ 549bd7ddd1SNamhyung Kim struct type_hist { 559bd7ddd1SNamhyung Kim u64 nr_samples; 569bd7ddd1SNamhyung Kim u64 period; 579bd7ddd1SNamhyung Kim struct type_hist_entry addr[]; 589bd7ddd1SNamhyung Kim }; 599bd7ddd1SNamhyung Kim 609bd7ddd1SNamhyung Kim /** 61b9c87f53SNamhyung Kim * struct annotated_data_type - Data type to profile 624a111cadSNamhyung Kim * @node: RB-tree node for dso->type_tree 634a111cadSNamhyung Kim * @self: Actual type information 649bd7ddd1SNamhyung Kim * @nr_histogram: Number of histogram entries 659bd7ddd1SNamhyung Kim * @histograms: An array of pointers to histograms 66b9c87f53SNamhyung Kim * 67b9c87f53SNamhyung Kim * This represents a data type accessed by samples in the profile data. 68b9c87f53SNamhyung Kim */ 69b9c87f53SNamhyung Kim struct annotated_data_type { 70fc044c53SNamhyung Kim struct rb_node node; 714a111cadSNamhyung Kim struct annotated_member self; 729bd7ddd1SNamhyung Kim int nr_histograms; 739bd7ddd1SNamhyung Kim struct type_hist **histograms; 74b9c87f53SNamhyung Kim }; 75b9c87f53SNamhyung Kim 762f2c41bdSNamhyung Kim extern struct annotated_data_type unknown_type; 777a54f1d8SNamhyung Kim extern struct annotated_data_type stackop_type; 78b3c95109SNamhyung Kim extern struct annotated_data_type canary_type; 792f2c41bdSNamhyung Kim 8061a9741eSNamhyung Kim /** 81a3f4d5b5SNamhyung Kim * struct data_loc_info - Data location information 824f903455SNamhyung Kim * @arch: CPU architecture info 831ebb5e17SNamhyung Kim * @thread: Thread info 84a3f4d5b5SNamhyung Kim * @ms: Map and Symbol info 85a3f4d5b5SNamhyung Kim * @ip: Instruction address 86a3f4d5b5SNamhyung Kim * @var_addr: Data address (for global variables) 871ebb5e17SNamhyung Kim * @cpumode: CPU execution mode 88a3f4d5b5SNamhyung Kim * @op: Instruction operand location (regs and offset) 89a3f4d5b5SNamhyung Kim * @di: Debug info 90a3f4d5b5SNamhyung Kim * @fbreg: Frame base register 91a3f4d5b5SNamhyung Kim * @fb_cfa: Whether the frame needs to check CFA 92a3f4d5b5SNamhyung Kim * @type_offset: Final offset in the type 93a3f4d5b5SNamhyung Kim */ 94a3f4d5b5SNamhyung Kim struct data_loc_info { 95a3f4d5b5SNamhyung Kim /* These are input field, should be filled by caller */ 964f903455SNamhyung Kim struct arch *arch; 971ebb5e17SNamhyung Kim struct thread *thread; 98a3f4d5b5SNamhyung Kim struct map_symbol *ms; 99a3f4d5b5SNamhyung Kim u64 ip; 100a3f4d5b5SNamhyung Kim u64 var_addr; 1011ebb5e17SNamhyung Kim u8 cpumode; 102a3f4d5b5SNamhyung Kim struct annotated_op_loc *op; 103a3f4d5b5SNamhyung Kim 104a3f4d5b5SNamhyung Kim /* These are used internally */ 105a3f4d5b5SNamhyung Kim struct debuginfo *di; 106a3f4d5b5SNamhyung Kim int fbreg; 107a3f4d5b5SNamhyung Kim bool fb_cfa; 108a3f4d5b5SNamhyung Kim 109a3f4d5b5SNamhyung Kim /* This is for the result */ 110a3f4d5b5SNamhyung Kim int type_offset; 111a3f4d5b5SNamhyung Kim }; 112a3f4d5b5SNamhyung Kim 113a3f4d5b5SNamhyung Kim /** 11461a9741eSNamhyung Kim * struct annotated_data_stat - Debug statistics 11561a9741eSNamhyung Kim * @total: Total number of entry 11661a9741eSNamhyung Kim * @no_sym: No symbol or map found 11761a9741eSNamhyung Kim * @no_insn: Failed to get disasm line 11861a9741eSNamhyung Kim * @no_insn_ops: The instruction has no operands 11961a9741eSNamhyung Kim * @no_mem_ops: The instruction has no memory operands 12061a9741eSNamhyung Kim * @no_reg: Failed to extract a register from the operand 12161a9741eSNamhyung Kim * @no_dbginfo: The binary has no debug information 12261a9741eSNamhyung Kim * @no_cuinfo: Failed to find a compile_unit 12361a9741eSNamhyung Kim * @no_var: Failed to find a matching variable 12461a9741eSNamhyung Kim * @no_typeinfo: Failed to get a type info for the variable 12561a9741eSNamhyung Kim * @invalid_size: Failed to get a size info of the type 12661a9741eSNamhyung Kim * @bad_offset: The access offset is out of the type 12761a9741eSNamhyung Kim */ 12861a9741eSNamhyung Kim struct annotated_data_stat { 12961a9741eSNamhyung Kim int total; 13061a9741eSNamhyung Kim int no_sym; 13161a9741eSNamhyung Kim int no_insn; 13261a9741eSNamhyung Kim int no_insn_ops; 13361a9741eSNamhyung Kim int no_mem_ops; 13461a9741eSNamhyung Kim int no_reg; 13561a9741eSNamhyung Kim int no_dbginfo; 13661a9741eSNamhyung Kim int no_cuinfo; 13761a9741eSNamhyung Kim int no_var; 13861a9741eSNamhyung Kim int no_typeinfo; 13961a9741eSNamhyung Kim int invalid_size; 14061a9741eSNamhyung Kim int bad_offset; 141eb8a55e0SNamhyung Kim int insn_track; 14261a9741eSNamhyung Kim }; 14361a9741eSNamhyung Kim extern struct annotated_data_stat ann_data_stat; 14461a9741eSNamhyung Kim 145b9c87f53SNamhyung Kim #ifdef HAVE_DWARF_SUPPORT 146b9c87f53SNamhyung Kim 147b9c87f53SNamhyung Kim /* Returns data type at the location (ip, reg, offset) */ 148a3f4d5b5SNamhyung Kim struct annotated_data_type *find_data_type(struct data_loc_info *dloc); 149b9c87f53SNamhyung Kim 1509bd7ddd1SNamhyung Kim /* Update type access histogram at the given offset */ 1519bd7ddd1SNamhyung Kim int annotated_data_type__update_samples(struct annotated_data_type *adt, 1529bd7ddd1SNamhyung Kim struct evsel *evsel, int offset, 1539bd7ddd1SNamhyung Kim int nr_samples, u64 period); 1549bd7ddd1SNamhyung Kim 155fc044c53SNamhyung Kim /* Release all data type information in the tree */ 156fc044c53SNamhyung Kim void annotated_data_type__tree_delete(struct rb_root *root); 157fc044c53SNamhyung Kim 15855ee3d00SNamhyung Kim /* Release all global variable information in the tree */ 15955ee3d00SNamhyung Kim void global_var_type__tree_delete(struct rb_root *root); 16055ee3d00SNamhyung Kim 1619b561be1SNamhyung Kim int hist_entry__annotate_data_tty(struct hist_entry *he, struct evsel *evsel); 1629b561be1SNamhyung Kim 163b9c87f53SNamhyung Kim #else /* HAVE_DWARF_SUPPORT */ 164b9c87f53SNamhyung Kim 165b9c87f53SNamhyung Kim static inline struct annotated_data_type * 166a3f4d5b5SNamhyung Kim find_data_type(struct data_loc_info *dloc __maybe_unused) 167b9c87f53SNamhyung Kim { 168b9c87f53SNamhyung Kim return NULL; 169b9c87f53SNamhyung Kim } 170b9c87f53SNamhyung Kim 1719bd7ddd1SNamhyung Kim static inline int 1729bd7ddd1SNamhyung Kim annotated_data_type__update_samples(struct annotated_data_type *adt __maybe_unused, 1739bd7ddd1SNamhyung Kim struct evsel *evsel __maybe_unused, 1749bd7ddd1SNamhyung Kim int offset __maybe_unused, 1759bd7ddd1SNamhyung Kim int nr_samples __maybe_unused, 1769bd7ddd1SNamhyung Kim u64 period __maybe_unused) 1779bd7ddd1SNamhyung Kim { 1789bd7ddd1SNamhyung Kim return -1; 1799bd7ddd1SNamhyung Kim } 1809bd7ddd1SNamhyung Kim 181fc044c53SNamhyung Kim static inline void annotated_data_type__tree_delete(struct rb_root *root __maybe_unused) 182fc044c53SNamhyung Kim { 183fc044c53SNamhyung Kim } 184fc044c53SNamhyung Kim 18555ee3d00SNamhyung Kim static inline void global_var_type__tree_delete(struct rb_root *root __maybe_unused) 18655ee3d00SNamhyung Kim { 18755ee3d00SNamhyung Kim } 18855ee3d00SNamhyung Kim 1899b561be1SNamhyung Kim static inline int hist_entry__annotate_data_tty(struct hist_entry *he __maybe_unused, 1909b561be1SNamhyung Kim struct evsel *evsel __maybe_unused) 1919b561be1SNamhyung Kim { 1929b561be1SNamhyung Kim return -1; 1939b561be1SNamhyung Kim } 1949b561be1SNamhyung Kim 195b9c87f53SNamhyung Kim #endif /* HAVE_DWARF_SUPPORT */ 196b9c87f53SNamhyung Kim 197*d001c7a7SNamhyung Kim #ifdef HAVE_SLANG_SUPPORT 198*d001c7a7SNamhyung Kim int hist_entry__annotate_data_tui(struct hist_entry *he, struct evsel *evsel, 199*d001c7a7SNamhyung Kim struct hist_browser_timer *hbt); 200*d001c7a7SNamhyung Kim #else 201*d001c7a7SNamhyung Kim static inline int hist_entry__annotate_data_tui(struct hist_entry *he __maybe_unused, 202*d001c7a7SNamhyung Kim struct evsel *evsel __maybe_unused, 203*d001c7a7SNamhyung Kim struct hist_browser_timer *hbt __maybe_unused) 204*d001c7a7SNamhyung Kim { 205*d001c7a7SNamhyung Kim return -1; 206*d001c7a7SNamhyung Kim } 207*d001c7a7SNamhyung Kim #endif /* HAVE_SLANG_SUPPORT */ 208*d001c7a7SNamhyung Kim 209b9c87f53SNamhyung Kim #endif /* _PERF_ANNOTATE_DATA_H */ 210