blob: 6409811057888d3048c9097c7156b1a238f6dda4 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Steven Rostedt4ace73e2012-04-06 00:47:52 +02002#ifndef _PERF_UTIL_TRACE_EVENT_H
3#define _PERF_UTIL_TRACE_EVENT_H
Steven Rostedt520509432009-08-17 16:18:05 +02004
Robert Richter4e319022013-06-11 17:29:18 +02005#include <traceevent/event-parse.h>
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +02006#include "parse-events.h"
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -02007
8struct machine;
9struct perf_sample;
10union perf_event;
Arnaldo Carvalho de Meloda378962012-06-27 13:08:42 -030011struct perf_tool;
David Ahern2eaa1b42013-07-18 16:06:15 -060012struct thread;
Tzvetomir Stoyanov (VMware)785be0c2018-09-19 14:56:56 -040013struct tep_plugin_list;
Adrian Huntercac30402021-05-30 22:22:58 +030014struct evsel;
Jiri Olsa29f5ffd2013-12-03 14:09:23 +010015
16struct trace_event {
Tzvetomir Stoyanov (VMware)096177a2018-08-08 14:02:46 -040017 struct tep_handle *pevent;
Tzvetomir Stoyanov (VMware)785be0c2018-09-19 14:56:56 -040018 struct tep_plugin_list *plugin_list;
Jiri Olsa29f5ffd2013-12-03 14:09:23 +010019};
20
21int trace_event__init(struct trace_event *t);
22void trace_event__cleanup(struct trace_event *t);
Arnaldo Carvalho de Melo959c2192015-07-24 12:13:05 -030023int trace_event__register_resolver(struct machine *machine,
Tzvetomir Stoyanov (VMware)4d5c58b2018-08-08 14:02:49 -040024 tep_func_resolver_t *func);
Tzvetomir Stoyanov97fbf3f2018-11-30 10:44:07 -050025struct tep_event*
Jiri Olsa97978b32013-12-03 14:09:24 +010026trace_event__tp_format(const char *sys, const char *name);
Steven Rostedt520509432009-08-17 16:18:05 +020027
Tzvetomir Stoyanov97fbf3f2018-11-30 10:44:07 -050028struct tep_event *trace_event__tp_format_id(int id);
Jiri Olsa71fe1052016-07-10 13:07:54 +020029
Steven Rostedtaaf045f2012-04-06 00:47:56 +020030int bigendian(void);
31
Tzvetomir Stoyanov97fbf3f2018-11-30 10:44:07 -050032void event_format__fprintf(struct tep_event *event,
Arnaldo Carvalho de Meloaa1aac12015-02-03 12:46:58 -030033 int cpu, void *data, int size, FILE *fp);
34
Tzvetomir Stoyanov97fbf3f2018-11-30 10:44:07 -050035void event_format__print(struct tep_event *event,
Arnaldo Carvalho de Melofcf65bf2012-08-07 09:58:03 -030036 int cpu, void *data, int size);
Steven Rostedtaaf045f2012-04-06 00:47:56 +020037
Tzvetomir Stoyanov (VMware)096177a2018-08-08 14:02:46 -040038int parse_ftrace_file(struct tep_handle *pevent, char *buf, unsigned long size);
39int parse_event_file(struct tep_handle *pevent,
Arnaldo Carvalho de Meloda378962012-06-27 13:08:42 -030040 char *buf, unsigned long size, char *sys);
Steven Rostedtaaf045f2012-04-06 00:47:56 +020041
Steven Rostedtaaf045f2012-04-06 00:47:56 +020042unsigned long long
Tzvetomir Stoyanov97fbf3f2018-11-30 10:44:07 -050043raw_field_value(struct tep_event *event, const char *name, void *data);
Steven Rostedtaaf045f2012-04-06 00:47:56 +020044
Tzvetomir Stoyanov (VMware)096177a2018-08-08 14:02:46 -040045void parse_proc_kallsyms(struct tep_handle *pevent, char *file, unsigned int size);
46void parse_ftrace_printk(struct tep_handle *pevent, char *file, unsigned int size);
47void parse_saved_cmdline(struct tep_handle *pevent, char *file, unsigned int size);
Steven Rostedtaaf045f2012-04-06 00:47:56 +020048
Jiri Olsa29f5ffd2013-12-03 14:09:23 +010049ssize_t trace_report(int fd, struct trace_event *tevent, bool repipe);
Steven Rostedtaaf045f2012-04-06 00:47:56 +020050
Tzvetomir Stoyanov97fbf3f2018-11-30 10:44:07 -050051unsigned long long read_size(struct tep_event *event, void *ptr, int size);
Steven Rostedtaaf045f2012-04-06 00:47:56 +020052unsigned long long eval_flag(const char *flag);
53
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -020054int read_tracing_data(int fd, struct list_head *pattrs);
Jiri Olsa29208e52011-10-20 15:59:43 +020055
56struct tracing_data {
57 /* size is only valid if temp is 'true' */
58 ssize_t size;
59 bool temp;
60 char temp_file[50];
61};
62
63struct tracing_data *tracing_data_get(struct list_head *pattrs,
64 int fd, bool temp);
Namhyung Kim8755d5e2013-03-21 16:18:46 +090065int tracing_data_put(struct tracing_data *tdata);
Jiri Olsa29208e52011-10-20 15:59:43 +020066
Steven Rostedt520509432009-08-17 16:18:05 +020067
Feng Tang73994dc2012-08-08 17:57:52 +080068struct addr_location;
69
Jiri Olsa71ad0f52012-08-07 15:20:46 +020070struct perf_session;
Jiri Olsa8058a302016-01-05 22:09:08 +010071struct perf_stat_config;
Jiri Olsa71ad0f52012-08-07 15:20:46 +020072
Tom Zanussi956ffd02009-11-25 01:15:46 -060073struct scripting_ops {
74 const char *name;
Adrian Hunter6ea4b5d2021-05-24 09:57:18 +030075 const char *dirname; /* For script path .../scripts/<dirname>/... */
Adrian Hunter67e50ce2021-05-30 22:22:59 +030076 int (*start_script)(const char *script, int argc, const char **argv,
77 struct perf_session *session);
Adrian Hunterd445dd22014-08-15 22:08:37 +030078 int (*flush_script) (void);
Tom Zanussi956ffd02009-11-25 01:15:46 -060079 int (*stop_script) (void);
David Ahernbe6d8422011-03-09 22:23:23 -070080 void (*process_event) (union perf_event *event,
81 struct perf_sample *sample,
Jiri Olsa32dcd022019-07-21 13:23:51 +020082 struct evsel *evsel,
Adrian Hunter3f8e0092021-05-25 12:51:05 +030083 struct addr_location *al,
84 struct addr_location *addr_al);
Adrian Hunter5bf83c22019-07-10 11:58:06 +030085 void (*process_switch)(union perf_event *event,
86 struct perf_sample *sample,
87 struct machine *machine);
Adrian Hunter2ede9212021-05-25 12:51:11 +030088 void (*process_auxtrace_error)(struct perf_session *session,
89 union perf_event *event);
Jiri Olsa8058a302016-01-05 22:09:08 +010090 void (*process_stat)(struct perf_stat_config *config,
Jiri Olsa32dcd022019-07-21 13:23:51 +020091 struct evsel *evsel, u64 tstamp);
Jiri Olsa8058a302016-01-05 22:09:08 +010092 void (*process_stat_interval)(u64 tstamp);
Stephen Brennan538d9c12021-09-01 14:08:15 -070093 void (*process_throttle)(union perf_event *event,
94 struct perf_sample *sample,
95 struct machine *machine);
Tzvetomir Stoyanov (VMware)096177a2018-08-08 14:02:46 -040096 int (*generate_script) (struct tep_handle *pevent, const char *outfile);
Tom Zanussi956ffd02009-11-25 01:15:46 -060097};
98
Adrian Hunter44cbe722015-09-25 16:15:50 +030099extern unsigned int scripting_max_stack;
100
Tom Zanussi956ffd02009-11-25 01:15:46 -0600101int script_spec_register(const char *spec, struct scripting_ops *ops);
102
Adrian Hunterd9ae9c92021-05-30 22:23:01 +0300103void script_fetch_insn(struct perf_sample *sample, struct thread *thread,
104 struct machine *machine);
105
Tom Zanussi16c632d2009-11-25 01:15:48 -0600106void setup_perl_scripting(void);
Tom Zanussi7e4b21b2010-01-27 02:27:57 -0600107void setup_python_scripting(void);
Tom Zanussi16c632d2009-11-25 01:15:48 -0600108
Tom Zanussi7397d802010-01-27 02:27:54 -0600109struct scripting_context {
Tzvetomir Stoyanov (VMware)096177a2018-08-08 14:02:46 -0400110 struct tep_handle *pevent;
Tom Zanussi7397d802010-01-27 02:27:54 -0600111 void *event_data;
Adrian Huntercac30402021-05-30 22:22:58 +0300112 union perf_event *event;
113 struct perf_sample *sample;
114 struct evsel *evsel;
115 struct addr_location *al;
116 struct addr_location *addr_al;
Adrian Hunter67e50ce2021-05-30 22:22:59 +0300117 struct perf_session *session;
Tom Zanussi7397d802010-01-27 02:27:54 -0600118};
119
Adrian Huntercac30402021-05-30 22:22:58 +0300120void scripting_context__update(struct scripting_context *scripting_context,
121 union perf_event *event,
122 struct perf_sample *sample,
123 struct evsel *evsel,
124 struct addr_location *al,
125 struct addr_location *addr_al);
126
Tom Zanussi7397d802010-01-27 02:27:54 -0600127int common_pc(struct scripting_context *context);
128int common_flags(struct scripting_context *context);
129int common_lock_depth(struct scripting_context *context);
130
Adrian Hunter54cd8b02021-05-25 12:51:06 +0300131#define SAMPLE_FLAGS_BUF_SIZE 64
132int perf_sample__sprintf_flags(u32 flags, char *str, size_t sz);
133
Steven Rostedt4ace73e2012-04-06 00:47:52 +0200134#endif /* _PERF_UTIL_TRACE_EVENT_H */