18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef __PERF_ANNOTATE_H
38c2ecf20Sopenharmony_ci#define __PERF_ANNOTATE_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <stdbool.h>
68c2ecf20Sopenharmony_ci#include <stdint.h>
78c2ecf20Sopenharmony_ci#include <stdio.h>
88c2ecf20Sopenharmony_ci#include <linux/types.h>
98c2ecf20Sopenharmony_ci#include <linux/list.h>
108c2ecf20Sopenharmony_ci#include <linux/rbtree.h>
118c2ecf20Sopenharmony_ci#include <pthread.h>
128c2ecf20Sopenharmony_ci#include <asm/bug.h>
138c2ecf20Sopenharmony_ci#include "symbol_conf.h"
148c2ecf20Sopenharmony_ci#include "spark.h"
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_cistruct hist_browser_timer;
178c2ecf20Sopenharmony_cistruct hist_entry;
188c2ecf20Sopenharmony_cistruct ins_ops;
198c2ecf20Sopenharmony_cistruct map;
208c2ecf20Sopenharmony_cistruct map_symbol;
218c2ecf20Sopenharmony_cistruct addr_map_symbol;
228c2ecf20Sopenharmony_cistruct option;
238c2ecf20Sopenharmony_cistruct perf_sample;
248c2ecf20Sopenharmony_cistruct evsel;
258c2ecf20Sopenharmony_cistruct symbol;
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_cistruct ins {
288c2ecf20Sopenharmony_ci	const char     *name;
298c2ecf20Sopenharmony_ci	struct ins_ops *ops;
308c2ecf20Sopenharmony_ci};
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_cistruct ins_operands {
338c2ecf20Sopenharmony_ci	char	*raw;
348c2ecf20Sopenharmony_ci	char	*raw_comment;
358c2ecf20Sopenharmony_ci	char	*raw_func_start;
368c2ecf20Sopenharmony_ci	struct {
378c2ecf20Sopenharmony_ci		char	*raw;
388c2ecf20Sopenharmony_ci		char	*name;
398c2ecf20Sopenharmony_ci		struct symbol *sym;
408c2ecf20Sopenharmony_ci		u64	addr;
418c2ecf20Sopenharmony_ci		s64	offset;
428c2ecf20Sopenharmony_ci		bool	offset_avail;
438c2ecf20Sopenharmony_ci		bool	outside;
448c2ecf20Sopenharmony_ci	} target;
458c2ecf20Sopenharmony_ci	union {
468c2ecf20Sopenharmony_ci		struct {
478c2ecf20Sopenharmony_ci			char	*raw;
488c2ecf20Sopenharmony_ci			char	*name;
498c2ecf20Sopenharmony_ci			u64	addr;
508c2ecf20Sopenharmony_ci		} source;
518c2ecf20Sopenharmony_ci		struct {
528c2ecf20Sopenharmony_ci			struct ins	    ins;
538c2ecf20Sopenharmony_ci			struct ins_operands *ops;
548c2ecf20Sopenharmony_ci		} locked;
558c2ecf20Sopenharmony_ci	};
568c2ecf20Sopenharmony_ci};
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cistruct arch;
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_cistruct ins_ops {
618c2ecf20Sopenharmony_ci	void (*free)(struct ins_operands *ops);
628c2ecf20Sopenharmony_ci	int (*parse)(struct arch *arch, struct ins_operands *ops, struct map_symbol *ms);
638c2ecf20Sopenharmony_ci	int (*scnprintf)(struct ins *ins, char *bf, size_t size,
648c2ecf20Sopenharmony_ci			 struct ins_operands *ops, int max_ins_name);
658c2ecf20Sopenharmony_ci};
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_cibool ins__is_jump(const struct ins *ins);
688c2ecf20Sopenharmony_cibool ins__is_call(const struct ins *ins);
698c2ecf20Sopenharmony_cibool ins__is_ret(const struct ins *ins);
708c2ecf20Sopenharmony_cibool ins__is_lock(const struct ins *ins);
718c2ecf20Sopenharmony_ciint ins__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name);
728c2ecf20Sopenharmony_cibool ins__is_fused(struct arch *arch, const char *ins1, const char *ins2);
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci#define ANNOTATION__IPC_WIDTH 6
758c2ecf20Sopenharmony_ci#define ANNOTATION__CYCLES_WIDTH 6
768c2ecf20Sopenharmony_ci#define ANNOTATION__MINMAX_CYCLES_WIDTH 19
778c2ecf20Sopenharmony_ci#define ANNOTATION__AVG_IPC_WIDTH 36
788c2ecf20Sopenharmony_ci#define ANNOTATION_DUMMY_LEN	256
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_cistruct annotation_options {
818c2ecf20Sopenharmony_ci	bool hide_src_code,
828c2ecf20Sopenharmony_ci	     use_offset,
838c2ecf20Sopenharmony_ci	     jump_arrows,
848c2ecf20Sopenharmony_ci	     print_lines,
858c2ecf20Sopenharmony_ci	     full_path,
868c2ecf20Sopenharmony_ci	     show_linenr,
878c2ecf20Sopenharmony_ci	     show_nr_jumps,
888c2ecf20Sopenharmony_ci	     show_minmax_cycle,
898c2ecf20Sopenharmony_ci	     show_asm_raw,
908c2ecf20Sopenharmony_ci	     annotate_src;
918c2ecf20Sopenharmony_ci	u8   offset_level;
928c2ecf20Sopenharmony_ci	int  min_pcnt;
938c2ecf20Sopenharmony_ci	int  max_lines;
948c2ecf20Sopenharmony_ci	int  context;
958c2ecf20Sopenharmony_ci	const char *objdump_path;
968c2ecf20Sopenharmony_ci	const char *disassembler_style;
978c2ecf20Sopenharmony_ci	const char *prefix;
988c2ecf20Sopenharmony_ci	const char *prefix_strip;
998c2ecf20Sopenharmony_ci	unsigned int percent_type;
1008c2ecf20Sopenharmony_ci};
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_cienum {
1038c2ecf20Sopenharmony_ci	ANNOTATION__OFFSET_JUMP_TARGETS = 1,
1048c2ecf20Sopenharmony_ci	ANNOTATION__OFFSET_CALL,
1058c2ecf20Sopenharmony_ci	ANNOTATION__MAX_OFFSET_LEVEL,
1068c2ecf20Sopenharmony_ci};
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci#define ANNOTATION__MIN_OFFSET_LEVEL ANNOTATION__OFFSET_JUMP_TARGETS
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ciextern struct annotation_options annotation__default_options;
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_cistruct annotation;
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_cistruct sym_hist_entry {
1158c2ecf20Sopenharmony_ci	u64		nr_samples;
1168c2ecf20Sopenharmony_ci	u64		period;
1178c2ecf20Sopenharmony_ci};
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_cienum {
1208c2ecf20Sopenharmony_ci	PERCENT_HITS_LOCAL,
1218c2ecf20Sopenharmony_ci	PERCENT_HITS_GLOBAL,
1228c2ecf20Sopenharmony_ci	PERCENT_PERIOD_LOCAL,
1238c2ecf20Sopenharmony_ci	PERCENT_PERIOD_GLOBAL,
1248c2ecf20Sopenharmony_ci	PERCENT_MAX,
1258c2ecf20Sopenharmony_ci};
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_cistruct annotation_data {
1288c2ecf20Sopenharmony_ci	double			 percent[PERCENT_MAX];
1298c2ecf20Sopenharmony_ci	double			 percent_sum;
1308c2ecf20Sopenharmony_ci	struct sym_hist_entry	 he;
1318c2ecf20Sopenharmony_ci};
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_cistruct annotation_line {
1348c2ecf20Sopenharmony_ci	struct list_head	 node;
1358c2ecf20Sopenharmony_ci	struct rb_node		 rb_node;
1368c2ecf20Sopenharmony_ci	s64			 offset;
1378c2ecf20Sopenharmony_ci	char			*line;
1388c2ecf20Sopenharmony_ci	int			 line_nr;
1398c2ecf20Sopenharmony_ci	int			 jump_sources;
1408c2ecf20Sopenharmony_ci	float			 ipc;
1418c2ecf20Sopenharmony_ci	u64			 cycles;
1428c2ecf20Sopenharmony_ci	u64			 cycles_max;
1438c2ecf20Sopenharmony_ci	u64			 cycles_min;
1448c2ecf20Sopenharmony_ci	char			*path;
1458c2ecf20Sopenharmony_ci	u32			 idx;
1468c2ecf20Sopenharmony_ci	int			 idx_asm;
1478c2ecf20Sopenharmony_ci	int			 data_nr;
1488c2ecf20Sopenharmony_ci	struct annotation_data	 data[];
1498c2ecf20Sopenharmony_ci};
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_cistruct disasm_line {
1528c2ecf20Sopenharmony_ci	struct ins		 ins;
1538c2ecf20Sopenharmony_ci	struct ins_operands	 ops;
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci	/* This needs to be at the end. */
1568c2ecf20Sopenharmony_ci	struct annotation_line	 al;
1578c2ecf20Sopenharmony_ci};
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_cistatic inline double annotation_data__percent(struct annotation_data *data,
1608c2ecf20Sopenharmony_ci					      unsigned int which)
1618c2ecf20Sopenharmony_ci{
1628c2ecf20Sopenharmony_ci	return which < PERCENT_MAX ? data->percent[which] : -1;
1638c2ecf20Sopenharmony_ci}
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_cistatic inline const char *percent_type_str(unsigned int type)
1668c2ecf20Sopenharmony_ci{
1678c2ecf20Sopenharmony_ci	static const char *str[PERCENT_MAX] = {
1688c2ecf20Sopenharmony_ci		"local hits",
1698c2ecf20Sopenharmony_ci		"global hits",
1708c2ecf20Sopenharmony_ci		"local period",
1718c2ecf20Sopenharmony_ci		"global period",
1728c2ecf20Sopenharmony_ci	};
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci	if (WARN_ON(type >= PERCENT_MAX))
1758c2ecf20Sopenharmony_ci		return "N/A";
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci	return str[type];
1788c2ecf20Sopenharmony_ci}
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_cistatic inline struct disasm_line *disasm_line(struct annotation_line *al)
1818c2ecf20Sopenharmony_ci{
1828c2ecf20Sopenharmony_ci	return al ? container_of(al, struct disasm_line, al) : NULL;
1838c2ecf20Sopenharmony_ci}
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci/*
1868c2ecf20Sopenharmony_ci * Is this offset in the same function as the line it is used?
1878c2ecf20Sopenharmony_ci * asm functions jump to other functions, for instance.
1888c2ecf20Sopenharmony_ci */
1898c2ecf20Sopenharmony_cistatic inline bool disasm_line__has_local_offset(const struct disasm_line *dl)
1908c2ecf20Sopenharmony_ci{
1918c2ecf20Sopenharmony_ci	return dl->ops.target.offset_avail && !dl->ops.target.outside;
1928c2ecf20Sopenharmony_ci}
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci/*
1958c2ecf20Sopenharmony_ci * Can we draw an arrow from the jump to its target, for instance? I.e.
1968c2ecf20Sopenharmony_ci * is the jump and its target in the same function?
1978c2ecf20Sopenharmony_ci */
1988c2ecf20Sopenharmony_cibool disasm_line__is_valid_local_jump(struct disasm_line *dl, struct symbol *sym);
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_civoid disasm_line__free(struct disasm_line *dl);
2018c2ecf20Sopenharmony_cistruct annotation_line *
2028c2ecf20Sopenharmony_ciannotation_line__next(struct annotation_line *pos, struct list_head *head);
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_cistruct annotation_write_ops {
2058c2ecf20Sopenharmony_ci	bool first_line, current_entry, change_color;
2068c2ecf20Sopenharmony_ci	int  width;
2078c2ecf20Sopenharmony_ci	void *obj;
2088c2ecf20Sopenharmony_ci	int  (*set_color)(void *obj, int color);
2098c2ecf20Sopenharmony_ci	void (*set_percent_color)(void *obj, double percent, bool current);
2108c2ecf20Sopenharmony_ci	int  (*set_jumps_percent_color)(void *obj, int nr, bool current);
2118c2ecf20Sopenharmony_ci	void (*printf)(void *obj, const char *fmt, ...);
2128c2ecf20Sopenharmony_ci	void (*write_graph)(void *obj, int graph);
2138c2ecf20Sopenharmony_ci};
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_civoid annotation_line__write(struct annotation_line *al, struct annotation *notes,
2168c2ecf20Sopenharmony_ci			    struct annotation_write_ops *ops,
2178c2ecf20Sopenharmony_ci			    struct annotation_options *opts);
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ciint __annotation__scnprintf_samples_period(struct annotation *notes,
2208c2ecf20Sopenharmony_ci					   char *bf, size_t size,
2218c2ecf20Sopenharmony_ci					   struct evsel *evsel,
2228c2ecf20Sopenharmony_ci					   bool show_freq);
2238c2ecf20Sopenharmony_ci
2248c2ecf20Sopenharmony_ciint disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw, int max_ins_name);
2258c2ecf20Sopenharmony_cisize_t disasm__fprintf(struct list_head *head, FILE *fp);
2268c2ecf20Sopenharmony_civoid symbol__calc_percent(struct symbol *sym, struct evsel *evsel);
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_cistruct sym_hist {
2298c2ecf20Sopenharmony_ci	u64		      nr_samples;
2308c2ecf20Sopenharmony_ci	u64		      period;
2318c2ecf20Sopenharmony_ci	struct sym_hist_entry addr[];
2328c2ecf20Sopenharmony_ci};
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_cistruct cyc_hist {
2358c2ecf20Sopenharmony_ci	u64	start;
2368c2ecf20Sopenharmony_ci	u64	cycles;
2378c2ecf20Sopenharmony_ci	u64	cycles_aggr;
2388c2ecf20Sopenharmony_ci	u64	cycles_max;
2398c2ecf20Sopenharmony_ci	u64	cycles_min;
2408c2ecf20Sopenharmony_ci	s64	cycles_spark[NUM_SPARKS];
2418c2ecf20Sopenharmony_ci	u32	num;
2428c2ecf20Sopenharmony_ci	u32	num_aggr;
2438c2ecf20Sopenharmony_ci	u8	have_start;
2448c2ecf20Sopenharmony_ci	/* 1 byte padding */
2458c2ecf20Sopenharmony_ci	u16	reset;
2468c2ecf20Sopenharmony_ci};
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_ci/** struct annotated_source - symbols with hits have this attached as in sannotation
2498c2ecf20Sopenharmony_ci *
2508c2ecf20Sopenharmony_ci * @histograms: Array of addr hit histograms per event being monitored
2518c2ecf20Sopenharmony_ci * nr_histograms: This may not be the same as evsel->evlist->core.nr_entries if
2528c2ecf20Sopenharmony_ci * 		  we have more than a group in a evlist, where we will want
2538c2ecf20Sopenharmony_ci * 		  to see each group separately, that is why symbol__annotate2()
2548c2ecf20Sopenharmony_ci * 		  sets src->nr_histograms to evsel->nr_members.
2558c2ecf20Sopenharmony_ci * @lines: If 'print_lines' is specified, per source code line percentages
2568c2ecf20Sopenharmony_ci * @source: source parsed from a disassembler like objdump -dS
2578c2ecf20Sopenharmony_ci * @cyc_hist: Average cycles per basic block
2588c2ecf20Sopenharmony_ci *
2598c2ecf20Sopenharmony_ci * lines is allocated, percentages calculated and all sorted by percentage
2608c2ecf20Sopenharmony_ci * when the annotation is about to be presented, so the percentages are for
2618c2ecf20Sopenharmony_ci * one of the entries in the histogram array, i.e. for the event/counter being
2628c2ecf20Sopenharmony_ci * presented. It is deallocated right after symbol__{tui,tty,etc}_annotate
2638c2ecf20Sopenharmony_ci * returns.
2648c2ecf20Sopenharmony_ci */
2658c2ecf20Sopenharmony_cistruct annotated_source {
2668c2ecf20Sopenharmony_ci	struct list_head   source;
2678c2ecf20Sopenharmony_ci	int    		   nr_histograms;
2688c2ecf20Sopenharmony_ci	size_t		   sizeof_sym_hist;
2698c2ecf20Sopenharmony_ci	struct cyc_hist	   *cycles_hist;
2708c2ecf20Sopenharmony_ci	struct sym_hist	   *histograms;
2718c2ecf20Sopenharmony_ci};
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_cistruct annotation {
2748c2ecf20Sopenharmony_ci	pthread_mutex_t		lock;
2758c2ecf20Sopenharmony_ci	u64			max_coverage;
2768c2ecf20Sopenharmony_ci	u64			start;
2778c2ecf20Sopenharmony_ci	u64			hit_cycles;
2788c2ecf20Sopenharmony_ci	u64			hit_insn;
2798c2ecf20Sopenharmony_ci	unsigned int		total_insn;
2808c2ecf20Sopenharmony_ci	unsigned int		cover_insn;
2818c2ecf20Sopenharmony_ci	struct annotation_options *options;
2828c2ecf20Sopenharmony_ci	struct annotation_line	**offsets;
2838c2ecf20Sopenharmony_ci	int			nr_events;
2848c2ecf20Sopenharmony_ci	int			max_jump_sources;
2858c2ecf20Sopenharmony_ci	int			nr_entries;
2868c2ecf20Sopenharmony_ci	int			nr_asm_entries;
2878c2ecf20Sopenharmony_ci	u16			max_line_len;
2888c2ecf20Sopenharmony_ci	struct {
2898c2ecf20Sopenharmony_ci		u8		addr;
2908c2ecf20Sopenharmony_ci		u8		jumps;
2918c2ecf20Sopenharmony_ci		u8		target;
2928c2ecf20Sopenharmony_ci		u8		min_addr;
2938c2ecf20Sopenharmony_ci		u8		max_addr;
2948c2ecf20Sopenharmony_ci		u8		max_ins_name;
2958c2ecf20Sopenharmony_ci	} widths;
2968c2ecf20Sopenharmony_ci	bool			have_cycles;
2978c2ecf20Sopenharmony_ci	struct annotated_source *src;
2988c2ecf20Sopenharmony_ci};
2998c2ecf20Sopenharmony_ci
3008c2ecf20Sopenharmony_cistatic inline int annotation__cycles_width(struct annotation *notes)
3018c2ecf20Sopenharmony_ci{
3028c2ecf20Sopenharmony_ci	if (notes->have_cycles && notes->options->show_minmax_cycle)
3038c2ecf20Sopenharmony_ci		return ANNOTATION__IPC_WIDTH + ANNOTATION__MINMAX_CYCLES_WIDTH;
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_ci	return notes->have_cycles ? ANNOTATION__IPC_WIDTH + ANNOTATION__CYCLES_WIDTH : 0;
3068c2ecf20Sopenharmony_ci}
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_cistatic inline int annotation__pcnt_width(struct annotation *notes)
3098c2ecf20Sopenharmony_ci{
3108c2ecf20Sopenharmony_ci	return (symbol_conf.show_total_period ? 12 : 7) * notes->nr_events;
3118c2ecf20Sopenharmony_ci}
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_cistatic inline bool annotation_line__filter(struct annotation_line *al, struct annotation *notes)
3148c2ecf20Sopenharmony_ci{
3158c2ecf20Sopenharmony_ci	return notes->options->hide_src_code && al->offset == -1;
3168c2ecf20Sopenharmony_ci}
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_civoid annotation__set_offsets(struct annotation *notes, s64 size);
3198c2ecf20Sopenharmony_civoid annotation__compute_ipc(struct annotation *notes, size_t size);
3208c2ecf20Sopenharmony_civoid annotation__mark_jump_targets(struct annotation *notes, struct symbol *sym);
3218c2ecf20Sopenharmony_civoid annotation__update_column_widths(struct annotation *notes);
3228c2ecf20Sopenharmony_civoid annotation__init_column_widths(struct annotation *notes, struct symbol *sym);
3238c2ecf20Sopenharmony_ci
3248c2ecf20Sopenharmony_cistatic inline struct sym_hist *annotated_source__histogram(struct annotated_source *src, int idx)
3258c2ecf20Sopenharmony_ci{
3268c2ecf20Sopenharmony_ci	return ((void *)src->histograms) + (src->sizeof_sym_hist * idx);
3278c2ecf20Sopenharmony_ci}
3288c2ecf20Sopenharmony_ci
3298c2ecf20Sopenharmony_cistatic inline struct sym_hist *annotation__histogram(struct annotation *notes, int idx)
3308c2ecf20Sopenharmony_ci{
3318c2ecf20Sopenharmony_ci	return annotated_source__histogram(notes->src, idx);
3328c2ecf20Sopenharmony_ci}
3338c2ecf20Sopenharmony_ci
3348c2ecf20Sopenharmony_cistatic inline struct annotation *symbol__annotation(struct symbol *sym)
3358c2ecf20Sopenharmony_ci{
3368c2ecf20Sopenharmony_ci	return (void *)sym - symbol_conf.priv_size;
3378c2ecf20Sopenharmony_ci}
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_ciint addr_map_symbol__inc_samples(struct addr_map_symbol *ams, struct perf_sample *sample,
3408c2ecf20Sopenharmony_ci				 struct evsel *evsel);
3418c2ecf20Sopenharmony_ci
3428c2ecf20Sopenharmony_ciint addr_map_symbol__account_cycles(struct addr_map_symbol *ams,
3438c2ecf20Sopenharmony_ci				    struct addr_map_symbol *start,
3448c2ecf20Sopenharmony_ci				    unsigned cycles);
3458c2ecf20Sopenharmony_ci
3468c2ecf20Sopenharmony_ciint hist_entry__inc_addr_samples(struct hist_entry *he, struct perf_sample *sample,
3478c2ecf20Sopenharmony_ci				 struct evsel *evsel, u64 addr);
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_cistruct annotated_source *symbol__hists(struct symbol *sym, int nr_hists);
3508c2ecf20Sopenharmony_civoid symbol__annotate_zero_histograms(struct symbol *sym);
3518c2ecf20Sopenharmony_ci
3528c2ecf20Sopenharmony_ciint symbol__annotate(struct map_symbol *ms,
3538c2ecf20Sopenharmony_ci		     struct evsel *evsel,
3548c2ecf20Sopenharmony_ci		     struct annotation_options *options,
3558c2ecf20Sopenharmony_ci		     struct arch **parch);
3568c2ecf20Sopenharmony_ciint symbol__annotate2(struct map_symbol *ms,
3578c2ecf20Sopenharmony_ci		      struct evsel *evsel,
3588c2ecf20Sopenharmony_ci		      struct annotation_options *options,
3598c2ecf20Sopenharmony_ci		      struct arch **parch);
3608c2ecf20Sopenharmony_ci
3618c2ecf20Sopenharmony_cienum symbol_disassemble_errno {
3628c2ecf20Sopenharmony_ci	SYMBOL_ANNOTATE_ERRNO__SUCCESS		= 0,
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_ci	/*
3658c2ecf20Sopenharmony_ci	 * Choose an arbitrary negative big number not to clash with standard
3668c2ecf20Sopenharmony_ci	 * errno since SUS requires the errno has distinct positive values.
3678c2ecf20Sopenharmony_ci	 * See 'Issue 6' in the link below.
3688c2ecf20Sopenharmony_ci	 *
3698c2ecf20Sopenharmony_ci	 * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
3708c2ecf20Sopenharmony_ci	 */
3718c2ecf20Sopenharmony_ci	__SYMBOL_ANNOTATE_ERRNO__START		= -10000,
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_ci	SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX	= __SYMBOL_ANNOTATE_ERRNO__START,
3748c2ecf20Sopenharmony_ci	SYMBOL_ANNOTATE_ERRNO__NO_LIBOPCODES_FOR_BPF,
3758c2ecf20Sopenharmony_ci	SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING,
3768c2ecf20Sopenharmony_ci	SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_REGEXP,
3778c2ecf20Sopenharmony_ci	SYMBOL_ANNOTATE_ERRNO__BPF_INVALID_FILE,
3788c2ecf20Sopenharmony_ci	SYMBOL_ANNOTATE_ERRNO__BPF_MISSING_BTF,
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_ci	__SYMBOL_ANNOTATE_ERRNO__END,
3818c2ecf20Sopenharmony_ci};
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_ciint symbol__strerror_disassemble(struct map_symbol *ms, int errnum, char *buf, size_t buflen);
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_ciint symbol__annotate_printf(struct map_symbol *ms, struct evsel *evsel,
3868c2ecf20Sopenharmony_ci			    struct annotation_options *options);
3878c2ecf20Sopenharmony_civoid symbol__annotate_zero_histogram(struct symbol *sym, int evidx);
3888c2ecf20Sopenharmony_civoid symbol__annotate_decay_histogram(struct symbol *sym, int evidx);
3898c2ecf20Sopenharmony_civoid annotated_source__purge(struct annotated_source *as);
3908c2ecf20Sopenharmony_ci
3918c2ecf20Sopenharmony_ciint map_symbol__annotation_dump(struct map_symbol *ms, struct evsel *evsel,
3928c2ecf20Sopenharmony_ci				struct annotation_options *opts);
3938c2ecf20Sopenharmony_ci
3948c2ecf20Sopenharmony_cibool ui__has_annotation(void);
3958c2ecf20Sopenharmony_ci
3968c2ecf20Sopenharmony_ciint symbol__tty_annotate(struct map_symbol *ms, struct evsel *evsel, struct annotation_options *opts);
3978c2ecf20Sopenharmony_ci
3988c2ecf20Sopenharmony_ciint symbol__tty_annotate2(struct map_symbol *ms, struct evsel *evsel, struct annotation_options *opts);
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_ci#ifdef HAVE_SLANG_SUPPORT
4018c2ecf20Sopenharmony_ciint symbol__tui_annotate(struct map_symbol *ms, struct evsel *evsel,
4028c2ecf20Sopenharmony_ci			 struct hist_browser_timer *hbt,
4038c2ecf20Sopenharmony_ci			 struct annotation_options *opts);
4048c2ecf20Sopenharmony_ci#else
4058c2ecf20Sopenharmony_cistatic inline int symbol__tui_annotate(struct map_symbol *ms __maybe_unused,
4068c2ecf20Sopenharmony_ci				struct evsel *evsel  __maybe_unused,
4078c2ecf20Sopenharmony_ci				struct hist_browser_timer *hbt __maybe_unused,
4088c2ecf20Sopenharmony_ci				struct annotation_options *opts __maybe_unused)
4098c2ecf20Sopenharmony_ci{
4108c2ecf20Sopenharmony_ci	return 0;
4118c2ecf20Sopenharmony_ci}
4128c2ecf20Sopenharmony_ci#endif
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_civoid annotation_config__init(struct annotation_options *opt);
4158c2ecf20Sopenharmony_ci
4168c2ecf20Sopenharmony_ciint annotate_parse_percent_type(const struct option *opt, const char *_str,
4178c2ecf20Sopenharmony_ci				int unset);
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_ciint annotate_check_args(struct annotation_options *args);
4208c2ecf20Sopenharmony_ci
4218c2ecf20Sopenharmony_ci#endif	/* __PERF_ANNOTATE_H */
422