162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef __PERF_ANNOTATE_H
362306a36Sopenharmony_ci#define __PERF_ANNOTATE_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#include <stdbool.h>
662306a36Sopenharmony_ci#include <stdint.h>
762306a36Sopenharmony_ci#include <stdio.h>
862306a36Sopenharmony_ci#include <linux/types.h>
962306a36Sopenharmony_ci#include <linux/list.h>
1062306a36Sopenharmony_ci#include <linux/rbtree.h>
1162306a36Sopenharmony_ci#include <asm/bug.h>
1262306a36Sopenharmony_ci#include "symbol_conf.h"
1362306a36Sopenharmony_ci#include "mutex.h"
1462306a36Sopenharmony_ci#include "spark.h"
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_cistruct hist_browser_timer;
1762306a36Sopenharmony_cistruct hist_entry;
1862306a36Sopenharmony_cistruct ins_ops;
1962306a36Sopenharmony_cistruct map;
2062306a36Sopenharmony_cistruct map_symbol;
2162306a36Sopenharmony_cistruct addr_map_symbol;
2262306a36Sopenharmony_cistruct option;
2362306a36Sopenharmony_cistruct perf_sample;
2462306a36Sopenharmony_cistruct evsel;
2562306a36Sopenharmony_cistruct symbol;
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_cistruct ins {
2862306a36Sopenharmony_ci	const char     *name;
2962306a36Sopenharmony_ci	struct ins_ops *ops;
3062306a36Sopenharmony_ci};
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_cistruct ins_operands {
3362306a36Sopenharmony_ci	char	*raw;
3462306a36Sopenharmony_ci	char	*raw_comment;
3562306a36Sopenharmony_ci	char	*raw_func_start;
3662306a36Sopenharmony_ci	struct {
3762306a36Sopenharmony_ci		char	*raw;
3862306a36Sopenharmony_ci		char	*name;
3962306a36Sopenharmony_ci		struct symbol *sym;
4062306a36Sopenharmony_ci		u64	addr;
4162306a36Sopenharmony_ci		s64	offset;
4262306a36Sopenharmony_ci		bool	offset_avail;
4362306a36Sopenharmony_ci		bool	outside;
4462306a36Sopenharmony_ci	} target;
4562306a36Sopenharmony_ci	union {
4662306a36Sopenharmony_ci		struct {
4762306a36Sopenharmony_ci			char	*raw;
4862306a36Sopenharmony_ci			char	*name;
4962306a36Sopenharmony_ci			u64	addr;
5062306a36Sopenharmony_ci		} source;
5162306a36Sopenharmony_ci		struct {
5262306a36Sopenharmony_ci			struct ins	    ins;
5362306a36Sopenharmony_ci			struct ins_operands *ops;
5462306a36Sopenharmony_ci		} locked;
5562306a36Sopenharmony_ci	};
5662306a36Sopenharmony_ci};
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_cistruct arch;
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_cistruct ins_ops {
6162306a36Sopenharmony_ci	void (*free)(struct ins_operands *ops);
6262306a36Sopenharmony_ci	int (*parse)(struct arch *arch, struct ins_operands *ops, struct map_symbol *ms);
6362306a36Sopenharmony_ci	int (*scnprintf)(struct ins *ins, char *bf, size_t size,
6462306a36Sopenharmony_ci			 struct ins_operands *ops, int max_ins_name);
6562306a36Sopenharmony_ci};
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_cibool ins__is_jump(const struct ins *ins);
6862306a36Sopenharmony_cibool ins__is_call(const struct ins *ins);
6962306a36Sopenharmony_cibool ins__is_ret(const struct ins *ins);
7062306a36Sopenharmony_cibool ins__is_lock(const struct ins *ins);
7162306a36Sopenharmony_ciint ins__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name);
7262306a36Sopenharmony_cibool ins__is_fused(struct arch *arch, const char *ins1, const char *ins2);
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci#define ANNOTATION__IPC_WIDTH 6
7562306a36Sopenharmony_ci#define ANNOTATION__CYCLES_WIDTH 6
7662306a36Sopenharmony_ci#define ANNOTATION__MINMAX_CYCLES_WIDTH 19
7762306a36Sopenharmony_ci#define ANNOTATION__AVG_IPC_WIDTH 36
7862306a36Sopenharmony_ci#define ANNOTATION_DUMMY_LEN	256
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_cistruct annotation_options {
8162306a36Sopenharmony_ci	bool hide_src_code,
8262306a36Sopenharmony_ci	     use_offset,
8362306a36Sopenharmony_ci	     jump_arrows,
8462306a36Sopenharmony_ci	     print_lines,
8562306a36Sopenharmony_ci	     full_path,
8662306a36Sopenharmony_ci	     show_linenr,
8762306a36Sopenharmony_ci	     show_fileloc,
8862306a36Sopenharmony_ci	     show_nr_jumps,
8962306a36Sopenharmony_ci	     show_minmax_cycle,
9062306a36Sopenharmony_ci	     show_asm_raw,
9162306a36Sopenharmony_ci	     annotate_src,
9262306a36Sopenharmony_ci	     full_addr;
9362306a36Sopenharmony_ci	u8   offset_level;
9462306a36Sopenharmony_ci	int  min_pcnt;
9562306a36Sopenharmony_ci	int  max_lines;
9662306a36Sopenharmony_ci	int  context;
9762306a36Sopenharmony_ci	char *objdump_path;
9862306a36Sopenharmony_ci	char *disassembler_style;
9962306a36Sopenharmony_ci	const char *prefix;
10062306a36Sopenharmony_ci	const char *prefix_strip;
10162306a36Sopenharmony_ci	unsigned int percent_type;
10262306a36Sopenharmony_ci};
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_cienum {
10562306a36Sopenharmony_ci	ANNOTATION__OFFSET_JUMP_TARGETS = 1,
10662306a36Sopenharmony_ci	ANNOTATION__OFFSET_CALL,
10762306a36Sopenharmony_ci	ANNOTATION__MAX_OFFSET_LEVEL,
10862306a36Sopenharmony_ci};
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ci#define ANNOTATION__MIN_OFFSET_LEVEL ANNOTATION__OFFSET_JUMP_TARGETS
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_cistruct annotation;
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_cistruct sym_hist_entry {
11562306a36Sopenharmony_ci	u64		nr_samples;
11662306a36Sopenharmony_ci	u64		period;
11762306a36Sopenharmony_ci};
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_cienum {
12062306a36Sopenharmony_ci	PERCENT_HITS_LOCAL,
12162306a36Sopenharmony_ci	PERCENT_HITS_GLOBAL,
12262306a36Sopenharmony_ci	PERCENT_PERIOD_LOCAL,
12362306a36Sopenharmony_ci	PERCENT_PERIOD_GLOBAL,
12462306a36Sopenharmony_ci	PERCENT_MAX,
12562306a36Sopenharmony_ci};
12662306a36Sopenharmony_ci
12762306a36Sopenharmony_cistruct annotation_data {
12862306a36Sopenharmony_ci	double			 percent[PERCENT_MAX];
12962306a36Sopenharmony_ci	double			 percent_sum;
13062306a36Sopenharmony_ci	struct sym_hist_entry	 he;
13162306a36Sopenharmony_ci};
13262306a36Sopenharmony_ci
13362306a36Sopenharmony_cistruct annotation_line {
13462306a36Sopenharmony_ci	struct list_head	 node;
13562306a36Sopenharmony_ci	struct rb_node		 rb_node;
13662306a36Sopenharmony_ci	s64			 offset;
13762306a36Sopenharmony_ci	char			*line;
13862306a36Sopenharmony_ci	int			 line_nr;
13962306a36Sopenharmony_ci	char			*fileloc;
14062306a36Sopenharmony_ci	int			 jump_sources;
14162306a36Sopenharmony_ci	float			 ipc;
14262306a36Sopenharmony_ci	u64			 cycles;
14362306a36Sopenharmony_ci	u64			 cycles_max;
14462306a36Sopenharmony_ci	u64			 cycles_min;
14562306a36Sopenharmony_ci	char			*path;
14662306a36Sopenharmony_ci	u32			 idx;
14762306a36Sopenharmony_ci	int			 idx_asm;
14862306a36Sopenharmony_ci	int			 data_nr;
14962306a36Sopenharmony_ci	struct annotation_data	 data[];
15062306a36Sopenharmony_ci};
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_cistruct disasm_line {
15362306a36Sopenharmony_ci	struct ins		 ins;
15462306a36Sopenharmony_ci	struct ins_operands	 ops;
15562306a36Sopenharmony_ci
15662306a36Sopenharmony_ci	/* This needs to be at the end. */
15762306a36Sopenharmony_ci	struct annotation_line	 al;
15862306a36Sopenharmony_ci};
15962306a36Sopenharmony_ci
16062306a36Sopenharmony_cistatic inline double annotation_data__percent(struct annotation_data *data,
16162306a36Sopenharmony_ci					      unsigned int which)
16262306a36Sopenharmony_ci{
16362306a36Sopenharmony_ci	return which < PERCENT_MAX ? data->percent[which] : -1;
16462306a36Sopenharmony_ci}
16562306a36Sopenharmony_ci
16662306a36Sopenharmony_cistatic inline const char *percent_type_str(unsigned int type)
16762306a36Sopenharmony_ci{
16862306a36Sopenharmony_ci	static const char *str[PERCENT_MAX] = {
16962306a36Sopenharmony_ci		"local hits",
17062306a36Sopenharmony_ci		"global hits",
17162306a36Sopenharmony_ci		"local period",
17262306a36Sopenharmony_ci		"global period",
17362306a36Sopenharmony_ci	};
17462306a36Sopenharmony_ci
17562306a36Sopenharmony_ci	if (WARN_ON(type >= PERCENT_MAX))
17662306a36Sopenharmony_ci		return "N/A";
17762306a36Sopenharmony_ci
17862306a36Sopenharmony_ci	return str[type];
17962306a36Sopenharmony_ci}
18062306a36Sopenharmony_ci
18162306a36Sopenharmony_cistatic inline struct disasm_line *disasm_line(struct annotation_line *al)
18262306a36Sopenharmony_ci{
18362306a36Sopenharmony_ci	return al ? container_of(al, struct disasm_line, al) : NULL;
18462306a36Sopenharmony_ci}
18562306a36Sopenharmony_ci
18662306a36Sopenharmony_ci/*
18762306a36Sopenharmony_ci * Is this offset in the same function as the line it is used?
18862306a36Sopenharmony_ci * asm functions jump to other functions, for instance.
18962306a36Sopenharmony_ci */
19062306a36Sopenharmony_cistatic inline bool disasm_line__has_local_offset(const struct disasm_line *dl)
19162306a36Sopenharmony_ci{
19262306a36Sopenharmony_ci	return dl->ops.target.offset_avail && !dl->ops.target.outside;
19362306a36Sopenharmony_ci}
19462306a36Sopenharmony_ci
19562306a36Sopenharmony_ci/*
19662306a36Sopenharmony_ci * Can we draw an arrow from the jump to its target, for instance? I.e.
19762306a36Sopenharmony_ci * is the jump and its target in the same function?
19862306a36Sopenharmony_ci */
19962306a36Sopenharmony_cibool disasm_line__is_valid_local_jump(struct disasm_line *dl, struct symbol *sym);
20062306a36Sopenharmony_ci
20162306a36Sopenharmony_civoid disasm_line__free(struct disasm_line *dl);
20262306a36Sopenharmony_cistruct annotation_line *
20362306a36Sopenharmony_ciannotation_line__next(struct annotation_line *pos, struct list_head *head);
20462306a36Sopenharmony_ci
20562306a36Sopenharmony_cistruct annotation_write_ops {
20662306a36Sopenharmony_ci	bool first_line, current_entry, change_color;
20762306a36Sopenharmony_ci	int  width;
20862306a36Sopenharmony_ci	void *obj;
20962306a36Sopenharmony_ci	int  (*set_color)(void *obj, int color);
21062306a36Sopenharmony_ci	void (*set_percent_color)(void *obj, double percent, bool current);
21162306a36Sopenharmony_ci	int  (*set_jumps_percent_color)(void *obj, int nr, bool current);
21262306a36Sopenharmony_ci	void (*printf)(void *obj, const char *fmt, ...);
21362306a36Sopenharmony_ci	void (*write_graph)(void *obj, int graph);
21462306a36Sopenharmony_ci};
21562306a36Sopenharmony_ci
21662306a36Sopenharmony_civoid annotation_line__write(struct annotation_line *al, struct annotation *notes,
21762306a36Sopenharmony_ci			    struct annotation_write_ops *ops,
21862306a36Sopenharmony_ci			    struct annotation_options *opts);
21962306a36Sopenharmony_ci
22062306a36Sopenharmony_ciint __annotation__scnprintf_samples_period(struct annotation *notes,
22162306a36Sopenharmony_ci					   char *bf, size_t size,
22262306a36Sopenharmony_ci					   struct evsel *evsel,
22362306a36Sopenharmony_ci					   bool show_freq);
22462306a36Sopenharmony_ci
22562306a36Sopenharmony_ciint disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw, int max_ins_name);
22662306a36Sopenharmony_cisize_t disasm__fprintf(struct list_head *head, FILE *fp);
22762306a36Sopenharmony_civoid symbol__calc_percent(struct symbol *sym, struct evsel *evsel);
22862306a36Sopenharmony_ci
22962306a36Sopenharmony_cistruct sym_hist {
23062306a36Sopenharmony_ci	u64		      nr_samples;
23162306a36Sopenharmony_ci	u64		      period;
23262306a36Sopenharmony_ci	struct sym_hist_entry addr[];
23362306a36Sopenharmony_ci};
23462306a36Sopenharmony_ci
23562306a36Sopenharmony_cistruct cyc_hist {
23662306a36Sopenharmony_ci	u64	start;
23762306a36Sopenharmony_ci	u64	cycles;
23862306a36Sopenharmony_ci	u64	cycles_aggr;
23962306a36Sopenharmony_ci	u64	cycles_max;
24062306a36Sopenharmony_ci	u64	cycles_min;
24162306a36Sopenharmony_ci	s64	cycles_spark[NUM_SPARKS];
24262306a36Sopenharmony_ci	u32	num;
24362306a36Sopenharmony_ci	u32	num_aggr;
24462306a36Sopenharmony_ci	u8	have_start;
24562306a36Sopenharmony_ci	/* 1 byte padding */
24662306a36Sopenharmony_ci	u16	reset;
24762306a36Sopenharmony_ci};
24862306a36Sopenharmony_ci
24962306a36Sopenharmony_ci/** struct annotated_source - symbols with hits have this attached as in sannotation
25062306a36Sopenharmony_ci *
25162306a36Sopenharmony_ci * @histograms: Array of addr hit histograms per event being monitored
25262306a36Sopenharmony_ci * nr_histograms: This may not be the same as evsel->evlist->core.nr_entries if
25362306a36Sopenharmony_ci * 		  we have more than a group in a evlist, where we will want
25462306a36Sopenharmony_ci * 		  to see each group separately, that is why symbol__annotate2()
25562306a36Sopenharmony_ci * 		  sets src->nr_histograms to evsel->nr_members.
25662306a36Sopenharmony_ci * @lines: If 'print_lines' is specified, per source code line percentages
25762306a36Sopenharmony_ci * @source: source parsed from a disassembler like objdump -dS
25862306a36Sopenharmony_ci * @cyc_hist: Average cycles per basic block
25962306a36Sopenharmony_ci *
26062306a36Sopenharmony_ci * lines is allocated, percentages calculated and all sorted by percentage
26162306a36Sopenharmony_ci * when the annotation is about to be presented, so the percentages are for
26262306a36Sopenharmony_ci * one of the entries in the histogram array, i.e. for the event/counter being
26362306a36Sopenharmony_ci * presented. It is deallocated right after symbol__{tui,tty,etc}_annotate
26462306a36Sopenharmony_ci * returns.
26562306a36Sopenharmony_ci */
26662306a36Sopenharmony_cistruct annotated_source {
26762306a36Sopenharmony_ci	struct list_head   source;
26862306a36Sopenharmony_ci	int    		   nr_histograms;
26962306a36Sopenharmony_ci	size_t		   sizeof_sym_hist;
27062306a36Sopenharmony_ci	struct cyc_hist	   *cycles_hist;
27162306a36Sopenharmony_ci	struct sym_hist	   *histograms;
27262306a36Sopenharmony_ci};
27362306a36Sopenharmony_ci
27462306a36Sopenharmony_cistruct LOCKABLE annotation {
27562306a36Sopenharmony_ci	u64			max_coverage;
27662306a36Sopenharmony_ci	u64			start;
27762306a36Sopenharmony_ci	u64			hit_cycles;
27862306a36Sopenharmony_ci	u64			hit_insn;
27962306a36Sopenharmony_ci	unsigned int		total_insn;
28062306a36Sopenharmony_ci	unsigned int		cover_insn;
28162306a36Sopenharmony_ci	struct annotation_options *options;
28262306a36Sopenharmony_ci	struct annotation_line	**offsets;
28362306a36Sopenharmony_ci	int			nr_events;
28462306a36Sopenharmony_ci	int			max_jump_sources;
28562306a36Sopenharmony_ci	int			nr_entries;
28662306a36Sopenharmony_ci	int			nr_asm_entries;
28762306a36Sopenharmony_ci	u16			max_line_len;
28862306a36Sopenharmony_ci	struct {
28962306a36Sopenharmony_ci		u8		addr;
29062306a36Sopenharmony_ci		u8		jumps;
29162306a36Sopenharmony_ci		u8		target;
29262306a36Sopenharmony_ci		u8		min_addr;
29362306a36Sopenharmony_ci		u8		max_addr;
29462306a36Sopenharmony_ci		u8		max_ins_name;
29562306a36Sopenharmony_ci	} widths;
29662306a36Sopenharmony_ci	bool			have_cycles;
29762306a36Sopenharmony_ci	struct annotated_source *src;
29862306a36Sopenharmony_ci};
29962306a36Sopenharmony_ci
30062306a36Sopenharmony_cistatic inline void annotation__init(struct annotation *notes __maybe_unused)
30162306a36Sopenharmony_ci{
30262306a36Sopenharmony_ci}
30362306a36Sopenharmony_civoid annotation__exit(struct annotation *notes);
30462306a36Sopenharmony_ci
30562306a36Sopenharmony_civoid annotation__lock(struct annotation *notes) EXCLUSIVE_LOCK_FUNCTION(*notes);
30662306a36Sopenharmony_civoid annotation__unlock(struct annotation *notes) UNLOCK_FUNCTION(*notes);
30762306a36Sopenharmony_cibool annotation__trylock(struct annotation *notes) EXCLUSIVE_TRYLOCK_FUNCTION(true, *notes);
30862306a36Sopenharmony_ci
30962306a36Sopenharmony_cistatic inline int annotation__cycles_width(struct annotation *notes)
31062306a36Sopenharmony_ci{
31162306a36Sopenharmony_ci	if (notes->have_cycles && notes->options->show_minmax_cycle)
31262306a36Sopenharmony_ci		return ANNOTATION__IPC_WIDTH + ANNOTATION__MINMAX_CYCLES_WIDTH;
31362306a36Sopenharmony_ci
31462306a36Sopenharmony_ci	return notes->have_cycles ? ANNOTATION__IPC_WIDTH + ANNOTATION__CYCLES_WIDTH : 0;
31562306a36Sopenharmony_ci}
31662306a36Sopenharmony_ci
31762306a36Sopenharmony_cistatic inline int annotation__pcnt_width(struct annotation *notes)
31862306a36Sopenharmony_ci{
31962306a36Sopenharmony_ci	return (symbol_conf.show_total_period ? 12 : 7) * notes->nr_events;
32062306a36Sopenharmony_ci}
32162306a36Sopenharmony_ci
32262306a36Sopenharmony_cistatic inline bool annotation_line__filter(struct annotation_line *al, struct annotation *notes)
32362306a36Sopenharmony_ci{
32462306a36Sopenharmony_ci	return notes->options->hide_src_code && al->offset == -1;
32562306a36Sopenharmony_ci}
32662306a36Sopenharmony_ci
32762306a36Sopenharmony_civoid annotation__set_offsets(struct annotation *notes, s64 size);
32862306a36Sopenharmony_civoid annotation__compute_ipc(struct annotation *notes, size_t size);
32962306a36Sopenharmony_civoid annotation__mark_jump_targets(struct annotation *notes, struct symbol *sym);
33062306a36Sopenharmony_civoid annotation__update_column_widths(struct annotation *notes);
33162306a36Sopenharmony_civoid annotation__init_column_widths(struct annotation *notes, struct symbol *sym);
33262306a36Sopenharmony_civoid annotation__toggle_full_addr(struct annotation *notes, struct map_symbol *ms);
33362306a36Sopenharmony_ci
33462306a36Sopenharmony_cistatic inline struct sym_hist *annotated_source__histogram(struct annotated_source *src, int idx)
33562306a36Sopenharmony_ci{
33662306a36Sopenharmony_ci	return ((void *)src->histograms) + (src->sizeof_sym_hist * idx);
33762306a36Sopenharmony_ci}
33862306a36Sopenharmony_ci
33962306a36Sopenharmony_cistatic inline struct sym_hist *annotation__histogram(struct annotation *notes, int idx)
34062306a36Sopenharmony_ci{
34162306a36Sopenharmony_ci	return annotated_source__histogram(notes->src, idx);
34262306a36Sopenharmony_ci}
34362306a36Sopenharmony_ci
34462306a36Sopenharmony_cistatic inline struct annotation *symbol__annotation(struct symbol *sym)
34562306a36Sopenharmony_ci{
34662306a36Sopenharmony_ci	return (void *)sym - symbol_conf.priv_size;
34762306a36Sopenharmony_ci}
34862306a36Sopenharmony_ci
34962306a36Sopenharmony_ciint addr_map_symbol__inc_samples(struct addr_map_symbol *ams, struct perf_sample *sample,
35062306a36Sopenharmony_ci				 struct evsel *evsel);
35162306a36Sopenharmony_ci
35262306a36Sopenharmony_ciint addr_map_symbol__account_cycles(struct addr_map_symbol *ams,
35362306a36Sopenharmony_ci				    struct addr_map_symbol *start,
35462306a36Sopenharmony_ci				    unsigned cycles);
35562306a36Sopenharmony_ci
35662306a36Sopenharmony_ciint hist_entry__inc_addr_samples(struct hist_entry *he, struct perf_sample *sample,
35762306a36Sopenharmony_ci				 struct evsel *evsel, u64 addr);
35862306a36Sopenharmony_ci
35962306a36Sopenharmony_cistruct annotated_source *symbol__hists(struct symbol *sym, int nr_hists);
36062306a36Sopenharmony_civoid symbol__annotate_zero_histograms(struct symbol *sym);
36162306a36Sopenharmony_ci
36262306a36Sopenharmony_ciint symbol__annotate(struct map_symbol *ms,
36362306a36Sopenharmony_ci		     struct evsel *evsel,
36462306a36Sopenharmony_ci		     struct annotation_options *options,
36562306a36Sopenharmony_ci		     struct arch **parch);
36662306a36Sopenharmony_ciint symbol__annotate2(struct map_symbol *ms,
36762306a36Sopenharmony_ci		      struct evsel *evsel,
36862306a36Sopenharmony_ci		      struct annotation_options *options,
36962306a36Sopenharmony_ci		      struct arch **parch);
37062306a36Sopenharmony_ci
37162306a36Sopenharmony_cienum symbol_disassemble_errno {
37262306a36Sopenharmony_ci	SYMBOL_ANNOTATE_ERRNO__SUCCESS		= 0,
37362306a36Sopenharmony_ci
37462306a36Sopenharmony_ci	/*
37562306a36Sopenharmony_ci	 * Choose an arbitrary negative big number not to clash with standard
37662306a36Sopenharmony_ci	 * errno since SUS requires the errno has distinct positive values.
37762306a36Sopenharmony_ci	 * See 'Issue 6' in the link below.
37862306a36Sopenharmony_ci	 *
37962306a36Sopenharmony_ci	 * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
38062306a36Sopenharmony_ci	 */
38162306a36Sopenharmony_ci	__SYMBOL_ANNOTATE_ERRNO__START		= -10000,
38262306a36Sopenharmony_ci
38362306a36Sopenharmony_ci	SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX	= __SYMBOL_ANNOTATE_ERRNO__START,
38462306a36Sopenharmony_ci	SYMBOL_ANNOTATE_ERRNO__NO_LIBOPCODES_FOR_BPF,
38562306a36Sopenharmony_ci	SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING,
38662306a36Sopenharmony_ci	SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_REGEXP,
38762306a36Sopenharmony_ci	SYMBOL_ANNOTATE_ERRNO__BPF_INVALID_FILE,
38862306a36Sopenharmony_ci	SYMBOL_ANNOTATE_ERRNO__BPF_MISSING_BTF,
38962306a36Sopenharmony_ci
39062306a36Sopenharmony_ci	__SYMBOL_ANNOTATE_ERRNO__END,
39162306a36Sopenharmony_ci};
39262306a36Sopenharmony_ci
39362306a36Sopenharmony_ciint symbol__strerror_disassemble(struct map_symbol *ms, int errnum, char *buf, size_t buflen);
39462306a36Sopenharmony_ci
39562306a36Sopenharmony_ciint symbol__annotate_printf(struct map_symbol *ms, struct evsel *evsel,
39662306a36Sopenharmony_ci			    struct annotation_options *options);
39762306a36Sopenharmony_civoid symbol__annotate_zero_histogram(struct symbol *sym, int evidx);
39862306a36Sopenharmony_civoid symbol__annotate_decay_histogram(struct symbol *sym, int evidx);
39962306a36Sopenharmony_civoid annotated_source__purge(struct annotated_source *as);
40062306a36Sopenharmony_ci
40162306a36Sopenharmony_ciint map_symbol__annotation_dump(struct map_symbol *ms, struct evsel *evsel,
40262306a36Sopenharmony_ci				struct annotation_options *opts);
40362306a36Sopenharmony_ci
40462306a36Sopenharmony_cibool ui__has_annotation(void);
40562306a36Sopenharmony_ci
40662306a36Sopenharmony_ciint symbol__tty_annotate(struct map_symbol *ms, struct evsel *evsel, struct annotation_options *opts);
40762306a36Sopenharmony_ci
40862306a36Sopenharmony_ciint symbol__tty_annotate2(struct map_symbol *ms, struct evsel *evsel, struct annotation_options *opts);
40962306a36Sopenharmony_ci
41062306a36Sopenharmony_ci#ifdef HAVE_SLANG_SUPPORT
41162306a36Sopenharmony_ciint symbol__tui_annotate(struct map_symbol *ms, struct evsel *evsel,
41262306a36Sopenharmony_ci			 struct hist_browser_timer *hbt,
41362306a36Sopenharmony_ci			 struct annotation_options *opts);
41462306a36Sopenharmony_ci#else
41562306a36Sopenharmony_cistatic inline int symbol__tui_annotate(struct map_symbol *ms __maybe_unused,
41662306a36Sopenharmony_ci				struct evsel *evsel  __maybe_unused,
41762306a36Sopenharmony_ci				struct hist_browser_timer *hbt __maybe_unused,
41862306a36Sopenharmony_ci				struct annotation_options *opts __maybe_unused)
41962306a36Sopenharmony_ci{
42062306a36Sopenharmony_ci	return 0;
42162306a36Sopenharmony_ci}
42262306a36Sopenharmony_ci#endif
42362306a36Sopenharmony_ci
42462306a36Sopenharmony_civoid annotation_options__init(struct annotation_options *opt);
42562306a36Sopenharmony_civoid annotation_options__exit(struct annotation_options *opt);
42662306a36Sopenharmony_ci
42762306a36Sopenharmony_civoid annotation_config__init(struct annotation_options *opt);
42862306a36Sopenharmony_ci
42962306a36Sopenharmony_ciint annotate_parse_percent_type(const struct option *opt, const char *_str,
43062306a36Sopenharmony_ci				int unset);
43162306a36Sopenharmony_ci
43262306a36Sopenharmony_ciint annotate_check_args(struct annotation_options *args);
43362306a36Sopenharmony_ci
43462306a36Sopenharmony_ci#endif	/* __PERF_ANNOTATE_H */
435