xref: /openbmc/linux/tools/perf/util/trace-event.h (revision 5626af8f)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _PERF_UTIL_TRACE_EVENT_H
3 #define _PERF_UTIL_TRACE_EVENT_H
4 
5 #include <stdbool.h>
6 #include <stdio.h>
7 #include <linux/types.h>
8 
9 struct evlist;
10 struct machine;
11 struct perf_sample;
12 union perf_event;
13 struct perf_tool;
14 struct thread;
15 struct tep_plugin_list;
16 struct evsel;
17 
18 struct trace_event {
19 	struct tep_handle	*pevent;
20 	struct tep_plugin_list	*plugin_list;
21 };
22 
23 typedef char *(tep_func_resolver_t)(void *priv,
24 				    unsigned long long *addrp, char **modp);
25 
26 bool have_tracepoints(struct list_head *evlist);
27 
28 int trace_event__init(struct trace_event *t);
29 void trace_event__cleanup(struct trace_event *t);
30 int trace_event__register_resolver(struct machine *machine,
31 				   tep_func_resolver_t *func);
32 struct tep_event*
33 trace_event__tp_format(const char *sys, const char *name);
34 
35 struct tep_event *trace_event__tp_format_id(int id);
36 
37 void event_format__fprintf(struct tep_event *event,
38 			   int cpu, void *data, int size, FILE *fp);
39 
40 void event_format__print(struct tep_event *event,
41 			 int cpu, void *data, int size);
42 
43 int parse_ftrace_file(struct tep_handle *pevent, char *buf, unsigned long size);
44 int parse_event_file(struct tep_handle *pevent,
45 		     char *buf, unsigned long size, char *sys);
46 
47 unsigned long long
48 raw_field_value(struct tep_event *event, const char *name, void *data);
49 
50 void parse_proc_kallsyms(struct tep_handle *pevent, char *file, unsigned int size);
51 void parse_ftrace_printk(struct tep_handle *pevent, char *file, unsigned int size);
52 void parse_saved_cmdline(struct tep_handle *pevent, char *file, unsigned int size);
53 
54 ssize_t trace_report(int fd, struct trace_event *tevent, bool repipe);
55 
56 unsigned long long read_size(struct tep_event *event, void *ptr, int size);
57 unsigned long long eval_flag(const char *flag);
58 
59 int read_tracing_data(int fd, struct list_head *pattrs);
60 
61 struct tracing_data {
62 	/* size is only valid if temp is 'true' */
63 	ssize_t size;
64 	bool temp;
65 	char temp_file[50];
66 };
67 
68 struct tracing_data *tracing_data_get(struct list_head *pattrs,
69 				      int fd, bool temp);
70 int tracing_data_put(struct tracing_data *tdata);
71 
72 
73 struct addr_location;
74 
75 struct perf_session;
76 struct perf_stat_config;
77 
78 struct scripting_ops {
79 	const char *name;
80 	const char *dirname; /* For script path .../scripts/<dirname>/... */
81 	int (*start_script)(const char *script, int argc, const char **argv,
82 			    struct perf_session *session);
83 	int (*flush_script) (void);
84 	int (*stop_script) (void);
85 	void (*process_event) (union perf_event *event,
86 			       struct perf_sample *sample,
87 			       struct evsel *evsel,
88 			       struct addr_location *al,
89 			       struct addr_location *addr_al);
90 	void (*process_switch)(union perf_event *event,
91 			       struct perf_sample *sample,
92 			       struct machine *machine);
93 	void (*process_auxtrace_error)(struct perf_session *session,
94 				       union perf_event *event);
95 	void (*process_stat)(struct perf_stat_config *config,
96 			     struct evsel *evsel, u64 tstamp);
97 	void (*process_stat_interval)(u64 tstamp);
98 	void (*process_throttle)(union perf_event *event,
99 				 struct perf_sample *sample,
100 				 struct machine *machine);
101 	int (*generate_script) (struct tep_handle *pevent, const char *outfile);
102 };
103 
104 extern unsigned int scripting_max_stack;
105 
106 int script_spec_register(const char *spec, struct scripting_ops *ops);
107 
108 void script_fetch_insn(struct perf_sample *sample, struct thread *thread,
109 		       struct machine *machine);
110 
111 void setup_perl_scripting(void);
112 void setup_python_scripting(void);
113 
114 struct scripting_context {
115 	struct tep_handle *pevent;
116 	void *event_data;
117 	union perf_event *event;
118 	struct perf_sample *sample;
119 	struct evsel *evsel;
120 	struct addr_location *al;
121 	struct addr_location *addr_al;
122 	struct perf_session *session;
123 };
124 
125 void scripting_context__update(struct scripting_context *scripting_context,
126 			       union perf_event *event,
127 			       struct perf_sample *sample,
128 			       struct evsel *evsel,
129 			       struct addr_location *al,
130 			       struct addr_location *addr_al);
131 
132 int common_pc(struct scripting_context *context);
133 int common_flags(struct scripting_context *context);
134 int common_lock_depth(struct scripting_context *context);
135 
136 #define SAMPLE_FLAGS_BUF_SIZE 64
137 int perf_sample__sprintf_flags(u32 flags, char *str, size_t sz);
138 
139 #endif /* _PERF_UTIL_TRACE_EVENT_H */
140