xref: /openbmc/linux/tools/perf/util/dlfilter.h (revision 9f9c9a8d)
1291961fcSAdrian Hunter /* SPDX-License-Identifier: GPL-2.0 */
2291961fcSAdrian Hunter /*
3291961fcSAdrian Hunter  * dlfilter.h: Interface to perf script --dlfilter shared object
4291961fcSAdrian Hunter  * Copyright (c) 2021, Intel Corporation.
5291961fcSAdrian Hunter  */
6291961fcSAdrian Hunter 
7291961fcSAdrian Hunter #ifndef PERF_UTIL_DLFILTER_H
8291961fcSAdrian Hunter #define PERF_UTIL_DLFILTER_H
9291961fcSAdrian Hunter 
10291961fcSAdrian Hunter struct perf_session;
11291961fcSAdrian Hunter union  perf_event;
12291961fcSAdrian Hunter struct perf_sample;
13291961fcSAdrian Hunter struct evsel;
14291961fcSAdrian Hunter struct machine;
15291961fcSAdrian Hunter struct addr_location;
16291961fcSAdrian Hunter struct perf_dlfilter_fns;
17291961fcSAdrian Hunter struct perf_dlfilter_sample;
18291961fcSAdrian Hunter struct perf_dlfilter_al;
19291961fcSAdrian Hunter 
20291961fcSAdrian Hunter struct dlfilter {
21291961fcSAdrian Hunter 	char				*file;
22291961fcSAdrian Hunter 	void				*handle;
23291961fcSAdrian Hunter 	void				*data;
24291961fcSAdrian Hunter 	struct perf_session		*session;
25291961fcSAdrian Hunter 	bool				ctx_valid;
263d032a25SAdrian Hunter 	bool				in_start;
273d032a25SAdrian Hunter 	bool				in_stop;
283d032a25SAdrian Hunter 	int				dlargc;
293d032a25SAdrian Hunter 	char				**dlargv;
30291961fcSAdrian Hunter 
31291961fcSAdrian Hunter 	union perf_event		*event;
32291961fcSAdrian Hunter 	struct perf_sample		*sample;
33291961fcSAdrian Hunter 	struct evsel			*evsel;
34291961fcSAdrian Hunter 	struct machine			*machine;
35291961fcSAdrian Hunter 	struct addr_location		*al;
36291961fcSAdrian Hunter 	struct addr_location		*addr_al;
37291961fcSAdrian Hunter 	struct perf_dlfilter_sample	*d_sample;
38291961fcSAdrian Hunter 	struct perf_dlfilter_al		*d_ip_al;
39291961fcSAdrian Hunter 	struct perf_dlfilter_al		*d_addr_al;
40291961fcSAdrian Hunter 
41291961fcSAdrian Hunter 	int (*start)(void **data, void *ctx);
42291961fcSAdrian Hunter 	int (*stop)(void *data, void *ctx);
43291961fcSAdrian Hunter 
44291961fcSAdrian Hunter 	int (*filter_event)(void *data,
45291961fcSAdrian Hunter 			    const struct perf_dlfilter_sample *sample,
46291961fcSAdrian Hunter 			    void *ctx);
479bde93a7SAdrian Hunter 	int (*filter_event_early)(void *data,
489bde93a7SAdrian Hunter 				  const struct perf_dlfilter_sample *sample,
499bde93a7SAdrian Hunter 				  void *ctx);
50291961fcSAdrian Hunter 
51291961fcSAdrian Hunter 	struct perf_dlfilter_fns *fns;
52291961fcSAdrian Hunter };
53291961fcSAdrian Hunter 
543d032a25SAdrian Hunter struct dlfilter *dlfilter__new(const char *file, int dlargc, char **dlargv);
55291961fcSAdrian Hunter 
56291961fcSAdrian Hunter int dlfilter__start(struct dlfilter *d, struct perf_session *session);
57291961fcSAdrian Hunter 
58291961fcSAdrian Hunter int dlfilter__do_filter_event(struct dlfilter *d,
59291961fcSAdrian Hunter 			      union perf_event *event,
60291961fcSAdrian Hunter 			      struct perf_sample *sample,
61291961fcSAdrian Hunter 			      struct evsel *evsel,
62291961fcSAdrian Hunter 			      struct machine *machine,
63291961fcSAdrian Hunter 			      struct addr_location *al,
649bde93a7SAdrian Hunter 			      struct addr_location *addr_al,
659bde93a7SAdrian Hunter 			      bool early);
66291961fcSAdrian Hunter 
67291961fcSAdrian Hunter void dlfilter__cleanup(struct dlfilter *d);
68291961fcSAdrian Hunter 
dlfilter__filter_event(struct dlfilter * d,union perf_event * event,struct perf_sample * sample,struct evsel * evsel,struct machine * machine,struct addr_location * al,struct addr_location * addr_al)69291961fcSAdrian Hunter static inline int dlfilter__filter_event(struct dlfilter *d,
70291961fcSAdrian Hunter 					 union perf_event *event,
71291961fcSAdrian Hunter 					 struct perf_sample *sample,
72291961fcSAdrian Hunter 					 struct evsel *evsel,
73291961fcSAdrian Hunter 					 struct machine *machine,
74291961fcSAdrian Hunter 					 struct addr_location *al,
75291961fcSAdrian Hunter 					 struct addr_location *addr_al)
76291961fcSAdrian Hunter {
77291961fcSAdrian Hunter 	if (!d || !d->filter_event)
78291961fcSAdrian Hunter 		return 0;
799bde93a7SAdrian Hunter 	return dlfilter__do_filter_event(d, event, sample, evsel, machine, al, addr_al, false);
809bde93a7SAdrian Hunter }
819bde93a7SAdrian Hunter 
dlfilter__filter_event_early(struct dlfilter * d,union perf_event * event,struct perf_sample * sample,struct evsel * evsel,struct machine * machine,struct addr_location * al,struct addr_location * addr_al)829bde93a7SAdrian Hunter static inline int dlfilter__filter_event_early(struct dlfilter *d,
839bde93a7SAdrian Hunter 					       union perf_event *event,
849bde93a7SAdrian Hunter 					       struct perf_sample *sample,
859bde93a7SAdrian Hunter 					       struct evsel *evsel,
869bde93a7SAdrian Hunter 					       struct machine *machine,
879bde93a7SAdrian Hunter 					       struct addr_location *al,
889bde93a7SAdrian Hunter 					       struct addr_location *addr_al)
899bde93a7SAdrian Hunter {
909bde93a7SAdrian Hunter 	if (!d || !d->filter_event_early)
919bde93a7SAdrian Hunter 		return 0;
929bde93a7SAdrian Hunter 	return dlfilter__do_filter_event(d, event, sample, evsel, machine, al, addr_al, true);
93291961fcSAdrian Hunter }
94291961fcSAdrian Hunter 
95638e2b99SAdrian Hunter int list_available_dlfilters(const struct option *opt, const char *s, int unset);
96*9f9c9a8dSAdrian Hunter bool get_filter_desc(const char *dirname, const char *name, char **desc,
97*9f9c9a8dSAdrian Hunter 		     char **long_desc);
98638e2b99SAdrian Hunter 
99291961fcSAdrian Hunter #endif
100