mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-13 22:25:03 +00:00
9f9c9a8de2
Add a perf test to test the dlfilter C API. A perf.data file is synthesized and then processed by perf script with a dlfilter named dlfilter-test-api-v0.so. Also a C file is compiled to provide a dso to match the synthesized perf.data file. Committer testing: [root@five ~]# perf test dlfilter 72: dlfilter C API : Ok [root@five ~]# perf test -v dlfilter 72: dlfilter C API : --- start --- test child forked, pid 3387712 Checking for gcc Command: gcc --version gcc (GCC) 11.1.1 20210531 (Red Hat 11.1.1-3) Copyright (C) 2021 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. dlfilters path: /var/home/acme/libexec/perf-core/dlfilters Command: gcc -g -o /tmp/dlfilter-test-3387712-prog /tmp/dlfilter-test-3387712-prog.c Creating new host machine structure Command: /var/home/acme/bin/perf script -i /tmp/dlfilter-test-3387712-perf-data --dlfilter /var/home/acme/libexec/perf-core/dlfilters/dlfilter-test-api-v0.so --dlarg first --dlarg 1 --dlarg 4198669 --dlarg 4198662 --dlarg 0 --dlarg last start API filter_event_early API filter_event API stop API Command: /var/home/acme/bin/perf script -i /tmp/dlfilter-test-3387712-perf-data --dlfilter /var/home/acme/libexec/perf-core/dlfilters/dlfilter-test-api-v0.so --dlarg first --dlarg 1 --dlarg 4198669 --dlarg 4198662 --dlarg 1 --dlarg last start API filter_event_early API filter_event API stop API Command: /var/home/acme/bin/perf script -i /tmp/dlfilter-test-3387712-perf-data --dlfilter /var/home/acme/libexec/perf-core/dlfilters/dlfilter-test-api-v0.so --dlarg first --dlarg 1 --dlarg 4198669 --dlarg 4198662 --dlarg 2 --dlarg last start API filter_event_early API stop API test child finished with 0 ---- end ---- dlfilter C API: Ok [root@five ~]# Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Jiri Olsa <jolsa@redhat.com> Link: https //lore.kernel.org/r/20210811101036.17986-7-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
99 lines
2.6 KiB
C
99 lines
2.6 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
/*
|
|
* dlfilter.h: Interface to perf script --dlfilter shared object
|
|
* Copyright (c) 2021, Intel Corporation.
|
|
*/
|
|
|
|
#ifndef PERF_UTIL_DLFILTER_H
|
|
#define PERF_UTIL_DLFILTER_H
|
|
|
|
struct perf_session;
|
|
union perf_event;
|
|
struct perf_sample;
|
|
struct evsel;
|
|
struct machine;
|
|
struct addr_location;
|
|
struct perf_dlfilter_fns;
|
|
struct perf_dlfilter_sample;
|
|
struct perf_dlfilter_al;
|
|
|
|
struct dlfilter {
|
|
char *file;
|
|
void *handle;
|
|
void *data;
|
|
struct perf_session *session;
|
|
bool ctx_valid;
|
|
bool in_start;
|
|
bool in_stop;
|
|
int dlargc;
|
|
char **dlargv;
|
|
|
|
union perf_event *event;
|
|
struct perf_sample *sample;
|
|
struct evsel *evsel;
|
|
struct machine *machine;
|
|
struct addr_location *al;
|
|
struct addr_location *addr_al;
|
|
struct perf_dlfilter_sample *d_sample;
|
|
struct perf_dlfilter_al *d_ip_al;
|
|
struct perf_dlfilter_al *d_addr_al;
|
|
|
|
int (*start)(void **data, void *ctx);
|
|
int (*stop)(void *data, void *ctx);
|
|
|
|
int (*filter_event)(void *data,
|
|
const struct perf_dlfilter_sample *sample,
|
|
void *ctx);
|
|
int (*filter_event_early)(void *data,
|
|
const struct perf_dlfilter_sample *sample,
|
|
void *ctx);
|
|
|
|
struct perf_dlfilter_fns *fns;
|
|
};
|
|
|
|
struct dlfilter *dlfilter__new(const char *file, int dlargc, char **dlargv);
|
|
|
|
int dlfilter__start(struct dlfilter *d, struct perf_session *session);
|
|
|
|
int dlfilter__do_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,
|
|
bool early);
|
|
|
|
void dlfilter__cleanup(struct dlfilter *d);
|
|
|
|
static inline int 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)
|
|
{
|
|
if (!d || !d->filter_event)
|
|
return 0;
|
|
return dlfilter__do_filter_event(d, event, sample, evsel, machine, al, addr_al, false);
|
|
}
|
|
|
|
static inline int 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)
|
|
{
|
|
if (!d || !d->filter_event_early)
|
|
return 0;
|
|
return dlfilter__do_filter_event(d, event, sample, evsel, machine, al, addr_al, true);
|
|
}
|
|
|
|
int list_available_dlfilters(const struct option *opt, const char *s, int unset);
|
|
bool get_filter_desc(const char *dirname, const char *name, char **desc,
|
|
char **long_desc);
|
|
|
|
#endif
|