xref: /openbmc/linux/tools/perf/util/trace-event.h (revision 2612e3bbc0386368a850140a6c9b990cd496a5ec)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
24ace73eeSSteven Rostedt #ifndef _PERF_UTIL_TRACE_EVENT_H
34ace73eeSSteven Rostedt #define _PERF_UTIL_TRACE_EVENT_H
452050943SSteven Rostedt 
5378ef0f5SIan Rogers #include <stdbool.h>
6378ef0f5SIan Rogers #include <stdio.h>
7481028dbSJesus Sanchez-Palencia #include <sys/types.h>
8378ef0f5SIan Rogers #include <linux/types.h>
9743eb868SArnaldo Carvalho de Melo 
10378ef0f5SIan Rogers struct evlist;
11743eb868SArnaldo Carvalho de Melo struct machine;
12743eb868SArnaldo Carvalho de Melo struct perf_sample;
13743eb868SArnaldo Carvalho de Melo union perf_event;
14da378962SArnaldo Carvalho de Melo struct perf_tool;
152eaa1b40SDavid Ahern struct thread;
16785be0c9STzvetomir Stoyanov (VMware) struct tep_plugin_list;
17cac30400SAdrian Hunter struct evsel;
1829f5ffd3SJiri Olsa 
1929f5ffd3SJiri Olsa struct trace_event {
20096177a8STzvetomir Stoyanov (VMware) 	struct tep_handle	*pevent;
21785be0c9STzvetomir Stoyanov (VMware) 	struct tep_plugin_list	*plugin_list;
2229f5ffd3SJiri Olsa };
2329f5ffd3SJiri Olsa 
241784eeaeSIan Rogers /* Computes a version number comparable with LIBTRACEEVENT_VERSION from Makefile.config. */
251784eeaeSIan Rogers #define MAKE_LIBTRACEEVENT_VERSION(a, b, c) ((a)*255*255+(b)*255+(c))
261784eeaeSIan Rogers 
27378ef0f5SIan Rogers typedef char *(tep_func_resolver_t)(void *priv,
28378ef0f5SIan Rogers 				    unsigned long long *addrp, char **modp);
29378ef0f5SIan Rogers 
30378ef0f5SIan Rogers bool have_tracepoints(struct list_head *evlist);
31378ef0f5SIan Rogers 
3229f5ffd3SJiri Olsa int trace_event__init(struct trace_event *t);
3329f5ffd3SJiri Olsa void trace_event__cleanup(struct trace_event *t);
34959c2199SArnaldo Carvalho de Melo int trace_event__register_resolver(struct machine *machine,
354d5c58b1STzvetomir Stoyanov (VMware) 				   tep_func_resolver_t *func);
3697fbf3f0STzvetomir Stoyanov struct tep_event*
3797978b3eSJiri Olsa trace_event__tp_format(const char *sys, const char *name);
3852050943SSteven Rostedt 
3997fbf3f0STzvetomir Stoyanov struct tep_event *trace_event__tp_format_id(int id);
4071fe1052SJiri Olsa 
4197fbf3f0STzvetomir Stoyanov void event_format__fprintf(struct tep_event *event,
42aa1aac17SArnaldo Carvalho de Melo 			   int cpu, void *data, int size, FILE *fp);
43aa1aac17SArnaldo Carvalho de Melo 
4497fbf3f0STzvetomir Stoyanov void event_format__print(struct tep_event *event,
45fcf65bf1SArnaldo Carvalho de Melo 			 int cpu, void *data, int size);
46aaf045f7SSteven Rostedt 
47096177a8STzvetomir Stoyanov (VMware) int parse_ftrace_file(struct tep_handle *pevent, char *buf, unsigned long size);
48096177a8STzvetomir Stoyanov (VMware) int parse_event_file(struct tep_handle *pevent,
49da378962SArnaldo Carvalho de Melo 		     char *buf, unsigned long size, char *sys);
50aaf045f7SSteven Rostedt 
51aaf045f7SSteven Rostedt unsigned long long
5297fbf3f0STzvetomir Stoyanov raw_field_value(struct tep_event *event, const char *name, void *data);
53aaf045f7SSteven Rostedt 
54096177a8STzvetomir Stoyanov (VMware) void parse_proc_kallsyms(struct tep_handle *pevent, char *file, unsigned int size);
55096177a8STzvetomir Stoyanov (VMware) void parse_ftrace_printk(struct tep_handle *pevent, char *file, unsigned int size);
56096177a8STzvetomir Stoyanov (VMware) void parse_saved_cmdline(struct tep_handle *pevent, char *file, unsigned int size);
57aaf045f7SSteven Rostedt 
5829f5ffd3SJiri Olsa ssize_t trace_report(int fd, struct trace_event *tevent, bool repipe);
59aaf045f7SSteven Rostedt 
6097fbf3f0STzvetomir Stoyanov unsigned long long read_size(struct tep_event *event, void *ptr, int size);
61aaf045f7SSteven Rostedt unsigned long long eval_flag(const char *flag);
62aaf045f7SSteven Rostedt 
6369aad6f1SArnaldo Carvalho de Melo int read_tracing_data(int fd, struct list_head *pattrs);
6429208e57SJiri Olsa 
65*220f88b5SYang Jihong /*
66*220f88b5SYang Jihong  * Return the tracepoint name in the format "subsystem:event_name",
67*220f88b5SYang Jihong  * callers should free the returned string.
68*220f88b5SYang Jihong  */
69*220f88b5SYang Jihong char *tracepoint_id_to_name(u64 config);
70*220f88b5SYang Jihong 
7129208e57SJiri Olsa struct tracing_data {
7229208e57SJiri Olsa 	/* size is only valid if temp is 'true' */
7329208e57SJiri Olsa 	ssize_t size;
7429208e57SJiri Olsa 	bool temp;
7529208e57SJiri Olsa 	char temp_file[50];
7629208e57SJiri Olsa };
7729208e57SJiri Olsa 
7829208e57SJiri Olsa struct tracing_data *tracing_data_get(struct list_head *pattrs,
7929208e57SJiri Olsa 				      int fd, bool temp);
808755d5e2SNamhyung Kim int tracing_data_put(struct tracing_data *tdata);
8129208e57SJiri Olsa 
8252050943SSteven Rostedt 
8373994dc1SFeng Tang struct addr_location;
8473994dc1SFeng Tang 
8571ad0f5eSJiri Olsa struct perf_session;
868058a30cSJiri Olsa struct perf_stat_config;
8771ad0f5eSJiri Olsa 
88956ffd02STom Zanussi struct scripting_ops {
89956ffd02STom Zanussi 	const char *name;
906ea4b5dbSAdrian Hunter 	const char *dirname; /* For script path .../scripts/<dirname>/... */
9167e50ce0SAdrian Hunter 	int (*start_script)(const char *script, int argc, const char **argv,
9267e50ce0SAdrian Hunter 			    struct perf_session *session);
93d445dd2aSAdrian Hunter 	int (*flush_script) (void);
94956ffd02STom Zanussi 	int (*stop_script) (void);
95be6d842aSDavid Ahern 	void (*process_event) (union perf_event *event,
96be6d842aSDavid Ahern 			       struct perf_sample *sample,
9732dcd021SJiri Olsa 			       struct evsel *evsel,
983f8e009eSAdrian Hunter 			       struct addr_location *al,
993f8e009eSAdrian Hunter 			       struct addr_location *addr_al);
1005bf83c29SAdrian Hunter 	void (*process_switch)(union perf_event *event,
1015bf83c29SAdrian Hunter 			       struct perf_sample *sample,
1025bf83c29SAdrian Hunter 			       struct machine *machine);
1032ede9217SAdrian Hunter 	void (*process_auxtrace_error)(struct perf_session *session,
1042ede9217SAdrian Hunter 				       union perf_event *event);
1058058a30cSJiri Olsa 	void (*process_stat)(struct perf_stat_config *config,
10632dcd021SJiri Olsa 			     struct evsel *evsel, u64 tstamp);
1078058a30cSJiri Olsa 	void (*process_stat_interval)(u64 tstamp);
108538d9c18SStephen Brennan 	void (*process_throttle)(union perf_event *event,
109538d9c18SStephen Brennan 				 struct perf_sample *sample,
110538d9c18SStephen Brennan 				 struct machine *machine);
111096177a8STzvetomir Stoyanov (VMware) 	int (*generate_script) (struct tep_handle *pevent, const char *outfile);
112956ffd02STom Zanussi };
113956ffd02STom Zanussi 
11444cbe729SAdrian Hunter extern unsigned int scripting_max_stack;
11544cbe729SAdrian Hunter 
116956ffd02STom Zanussi int script_spec_register(const char *spec, struct scripting_ops *ops);
117956ffd02STom Zanussi 
118d9ae9c97SAdrian Hunter void script_fetch_insn(struct perf_sample *sample, struct thread *thread,
119d9ae9c97SAdrian Hunter 		       struct machine *machine);
120d9ae9c97SAdrian Hunter 
12116c632deSTom Zanussi void setup_perl_scripting(void);
1227e4b21b8STom Zanussi void setup_python_scripting(void);
12316c632deSTom Zanussi 
1247397d80dSTom Zanussi struct scripting_context {
125096177a8STzvetomir Stoyanov (VMware) 	struct tep_handle *pevent;
1267397d80dSTom Zanussi 	void *event_data;
127cac30400SAdrian Hunter 	union perf_event *event;
128cac30400SAdrian Hunter 	struct perf_sample *sample;
129cac30400SAdrian Hunter 	struct evsel *evsel;
130cac30400SAdrian Hunter 	struct addr_location *al;
131cac30400SAdrian Hunter 	struct addr_location *addr_al;
13267e50ce0SAdrian Hunter 	struct perf_session *session;
1337397d80dSTom Zanussi };
1347397d80dSTom Zanussi 
135cac30400SAdrian Hunter void scripting_context__update(struct scripting_context *scripting_context,
136cac30400SAdrian Hunter 			       union perf_event *event,
137cac30400SAdrian Hunter 			       struct perf_sample *sample,
138cac30400SAdrian Hunter 			       struct evsel *evsel,
139cac30400SAdrian Hunter 			       struct addr_location *al,
140cac30400SAdrian Hunter 			       struct addr_location *addr_al);
141cac30400SAdrian Hunter 
1427397d80dSTom Zanussi int common_pc(struct scripting_context *context);
1437397d80dSTom Zanussi int common_flags(struct scripting_context *context);
1447397d80dSTom Zanussi int common_lock_depth(struct scripting_context *context);
1457397d80dSTom Zanussi 
14654cd8b03SAdrian Hunter #define SAMPLE_FLAGS_BUF_SIZE 64
14754cd8b03SAdrian Hunter int perf_sample__sprintf_flags(u32 flags, char *str, size_t sz);
14854cd8b03SAdrian Hunter 
1491634bad3SIan Rogers #if defined(LIBTRACEEVENT_VERSION) &&  LIBTRACEEVENT_VERSION >= MAKE_LIBTRACEEVENT_VERSION(1, 5, 0)
1501634bad3SIan Rogers #include <traceevent/event-parse.h>
1511634bad3SIan Rogers 
tep_field_is_relative(unsigned long flags)1521634bad3SIan Rogers static inline bool tep_field_is_relative(unsigned long flags)
1531634bad3SIan Rogers {
1541634bad3SIan Rogers 	return (flags & TEP_FIELD_IS_RELATIVE) != 0;
1551634bad3SIan Rogers }
1561634bad3SIan Rogers #else
1571634bad3SIan Rogers #include <linux/compiler.h>
1581634bad3SIan Rogers 
tep_field_is_relative(unsigned long flags __maybe_unused)1591634bad3SIan Rogers static inline bool tep_field_is_relative(unsigned long flags __maybe_unused)
1601634bad3SIan Rogers {
1611634bad3SIan Rogers 	return false;
1621634bad3SIan Rogers }
1631634bad3SIan Rogers #endif
1641634bad3SIan Rogers 
1654ace73eeSSteven Rostedt #endif /* _PERF_UTIL_TRACE_EVENT_H */
166