perf tools: Add dlfilter test
Adrian Hunter
reviewerv2 cover perf tools: Add dlfilter test
Hi
Here is V2 of some minor fixes / improvements to dlfilters and a new perf test for the dlfilter C API.
Changes in V2:
perf script: Fix documented const'ness of perf_dlfilter_fns
New patch
perf tools: Add dlfilter test
Do not make perf_dlfilter_fns const in test dlfilter
Adrian Hunter (6):
perf script: Fix documented const'ness of perf_dlfilter_fns perf script: Fix unnecessary machine_resolve()
perf script: Fix --list-dlfilters documentation
perf tools: Amend dlfilter documentation wrt library dependencies perf tools: Move perf_dlfilters.h in the source tree perf tools: Add dlfilter test
tools/perf/Documentation/perf-dlfilter.txt | 12 +-
tools/perf/Documentation/perf-script.txt | 2 +-
tools/perf/Makefile.perf | 17 +-
tools/perf/builtin-script.c | 2 +-
tools/perf/dlfilters/dlfilter-test-api-v0.c | 336 ++++++++++++++++++
tools/perf/{util => include/perf}/perf_dlfilter.h | 0
tools/perf/tests/Build | 1 +
tools/perf/tests/builtin-test.c | 4 +
tools/perf/tests/dlfilter-test.c | 411 ++++++++++++++++++++++
tools/perf/tests/tests.h | 1 +
tools/perf/util/dlfilter.c | 6 +-
tools/perf/util/dlfilter.h | 2 +
12 files changed, 785 insertions(+), 9 deletions(-)
create mode 100644 tools/perf/dlfilters/dlfilter-test-api-v0.c
rename tools/perf/{util => include/perf}/perf_dlfilter.h (100%)
create mode 100644 tools/perf/tests/dlfilter-test.cRegards
Adrian
Adrian Hunter
reviewerPATCH v2 1/6 perf script: Fix documented const'ness of perf_dlfilter_fns
perf_dlfilter_fns must not be const, because it is not. Declaring it const can result in it being mapped read-only, causing a segfaullt when it is written. Update documentation accordingly.
--- tools/perf/Documentation/perf-dlfilter.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-dlfilter.txt +2 -2
@@ -32,7 +32,7 @@ The API for filtering consists of the following: ---- #include <perf/perf_dlfilter.h> -const struct perf_dlfilter_fns perf_dlfilter_fns; +struct perf_dlfilter_fns perf_dlfilter_fns; int start(void **data, void *ctx); int stop(void *data, void *ctx);
@@ -214,7 +214,7 @@ Filter out everything except branches from "foo" to "bar": #include <perf/perf_dlfilter.h> #include <string.h> -const struct perf_dlfilter_fns perf_dlfilter_fns; +struct perf_dlfilter_fns perf_dlfilter_fns; int filter_event(void *data, const struct perf_dlfilter_sample *sample, void *ctx) {
Signature · 1 line
2.17.1
Adrian Hunter
reviewerPATCH v2 2/6 perf script: Fix unnecessary machine_resolve()
In reply to Adrian Huntermachine_resolve() may have already been called. Test for that to avoid calling it again unnecessarily.
--- tools/perf/builtin-script.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-script.c +1 -1
@@ -2212,7 +2212,7 @@ static int process_sample_event(struct perf_tool *tool,if (filter_cpu (sample)) goto out_put; -if (machine__resolve (machine, &al, sample) <0 ) { +if (!al.thread &&machine__resolve (machine, &al, sample) <0 ) {pr_err ("problem processing %d event, skipping it.\n" , event->header.type); ret =-1 ;
Signature · 1 line
2.17.1
Adrian Hunter
reviewerPATCH v2 3/6 perf script: Fix --list-dlfilters documentation
In reply to Adrian HunterThe option --list-dlfilters does use a string value.
--- tools/perf/Documentation/perf-script.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/Documentation/perf-script.txt +1 -1
@@ -106,7 +106,7 @@ OPTIONS Pass 'arg' as an argument to the dlfilter. --dlarg may be repeated to add more arguments. ---list-dlfilters=:: +--list-dlfilters:: Display a list of available dlfilters. Use with option -v (must come before option --list-dlfilters) to show long descriptions.
Signature · 1 line
2.17.1
Adrian Hunter
reviewerPATCH v2 4/6 perf tools: Amend dlfilter documentation wrt library dependencies
In reply to Adrian HunterLike all locally-built programs, dlfilters may need to be re-built if shared libraries they use change. Also there may be unexpected results if the dfilter uses different versions of the shared libraries that perf uses.
Note those things in the documentation.
--- tools/perf/Documentation/perf-dlfilter.txt | 8 ++++++++ 1 file changed, 8 insertions(+)
tools/perf/Documentation/perf-dlfilter.txt +8 -0
@@ -246,6 +246,14 @@ To use the filter with perf script: perf script --dlfilter dlfilter-example.so +NOTES +----- + +The dlfilter .so file will be dependent on shared libraries. If those change, +it may be necessary to rebuild the .so. Also there may be unexpected results +if the .so uses different versions of the shared libraries that perf uses. +Versions can be checked using the ldd command. + SEE ALSO -------- linkperf:perf-script[1]
Signature · 1 line
2.17.1
Adrian Hunter
reviewerPATCH v2 5/6 perf tools: Move perf_dlfilters.h in the source tree
In reply to Adrian HunterMove perf_dlfilters.h in the source tree so that it will be found when building dlfilters as part of the perf build.
---
tools/perf/Makefile.perf | 2 +-
tools/perf/{util => include/perf}/perf_dlfilter.h | 0
tools/perf/util/dlfilter.c | 2 +-
3 files changed, 2 insertions(+), 2 deletions(-)
rename tools/perf/{util => include/perf}/perf_dlfilter.h (100%)tools/perf/Makefile.perf +1 -1
@@ -925,7 +925,7 @@ install-tools: all install-gtk $(INSTALL) $(OUTPUT)perf '$(DESTDIR_SQ)$(bindir_SQ)'; \ $(LN) '$(DESTDIR_SQ)$(bindir_SQ)/perf' '$(DESTDIR_SQ)$(bindir_SQ)/trace'; \ $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(includedir_SQ)/perf'; \ - $(INSTALL) util/perf_dlfilter.h -t '$(DESTDIR_SQ)$(includedir_SQ)/perf' + $(INSTALL) -m 644 include/perf/perf_dlfilter.h -t '$(DESTDIR_SQ)$(includedir_SQ)/perf' ifndef NO_PERF_READ_VDSO32 $(call QUIET_INSTALL, perf-read-vdso32) \ $(INSTALL) $(OUTPUT)perf-read-vdso32 '$(DESTDIR_SQ)$(bindir_SQ)';
tools/perf/include/perf/perf_dlfilter.h renamed from tools/perf/util/perf_dlfilter.h +0 -0
tools/perf/util/dlfilter.c +1 -1
@@ -21,7 +21,7 @@#include "symbol.h" #include "srcline.h" #include "dlfilter.h" -#include "perf_dlfilter.h" +#include "../include/perf/perf_dlfilter.h" static void al_to_d_al (struct addr_location *al,struct perf_dlfilter_al *d_al) {
Signature · 1 line
2.17.1
Adrian Hunter
reviewerPATCH v2 6/6 perf tools: Add dlfilter test
In reply to Adrian HunterAdd 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.
--- tools/perf/Makefile.perf | 15 +- tools/perf/dlfilters/dlfilter-test-api-v0.c | 336 ++++++++++++++++ tools/perf/tests/Build | 1 + tools/perf/tests/builtin-test.c | 4 + tools/perf/tests/dlfilter-test.c | 411 ++++++++++++++++++++ tools/perf/tests/tests.h | 1 + tools/perf/util/dlfilter.c | 4 +- tools/perf/util/dlfilter.h | 2 + 8 files changed, 771 insertions(+), 3 deletions(-) create mode 100644 tools/perf/dlfilters/dlfilter-test-api-v0.c create mode 100644 tools/perf/tests/dlfilter-test.c
tools/perf/Makefile.perf +14 -1
@@ -360,8 +360,11 @@ ifndef NO_JVMTI PROGRAMS += $(OUTPUT)$(LIBJVMTI) endif +DLFILTERS := dlfilter-test-api-v0.so +DLFILTERS := $(patsubst %,$(OUTPUT)dlfilters/%,$(DLFILTERS)) + # what 'all' will build and 'install' will install, in perfexecdir -ALL_PROGRAMS = $(PROGRAMS) $(SCRIPTS) +ALL_PROGRAMS = $(PROGRAMS) $(SCRIPTS) $(DLFILTERS) # what 'all' will build but not install in perfexecdir OTHER_PROGRAMS = $(OUTPUT)perf
@@ -780,6 +783,13 @@ $(OUTPUT)perf-read-vdsox32: perf-read-vdso.c util/find-map.c $(QUIET_CC)$(CC) -mx32 $(filter -static,$(LDFLAGS)) -Wall -Werror -o $@ perf-read-vdso.c endif +$(OUTPUT)dlfilters/%.o: dlfilters/%.c include/perf/perf_dlfilter.h + $(Q)$(MKDIR) -p $(OUTPUT)dlfilters + $(QUIET_CC)$(CC) -c -Iinclude -o $@ -fpic $< + +$(OUTPUT)dlfilters/%.so: $(OUTPUT)dlfilters/%.o + $(QUIET_LINK)$(CC) -shared -o $@ $< + ifndef NO_JVMTI LIBJVMTI_IN := $(OUTPUT)jvmti/jvmti-in.o
@@ -978,6 +988,9 @@ ifndef NO_LIBPYTHON $(INSTALL) scripts/python/*.py -m 644 -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python'; \ $(INSTALL) scripts/python/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin' endif + $(call QUIET_INSTALL, dlfilters) \ + $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/dlfilters'; \ + $(INSTALL) $(DLFILTERS) '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/dlfilters'; $(call QUIET_INSTALL, perf_completion-script) \ $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(sysconfdir_SQ)/bash_completion.d'; \ $(INSTALL) perf-completion.sh '$(DESTDIR_SQ)$(sysconfdir_SQ)/bash_completion.d/perf'
tools/perf/dlfilters/dlfilter-test-api-v0.c new file +336 -0
336 lines not on this page · raw message
tools/perf/tests/Build +1 -0
@@ -64,6 +64,7 @@ perf-y += parse-metric.o perf-y += pe-file-parsing.o perf-y += expand-cgroup.o perf-y += perf-time-to-tsc.o +perf-y += dlfilter-test.o $(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c tests/Build $(call rule_mkdir)
tools/perf/tests/builtin-test.c +4 -0
@@ -360,6 +360,10 @@ static struct test generic_tests[] = { .func = test__perf_time_to_tsc, .is_supported = test__tsc_is_supported, }, + { + .desc = "dlfilter C API", + .func = test__dlfilter, + }, { .func = NULL, },
tools/perf/tests/dlfilter-test.c new file +411 -0
411 lines not on this page · raw message
tools/perf/tests/tests.h +1 -0
@@ -127,6 +127,7 @@ int test__parse_metric(struct test *test, int subtest);int test__pe_file_parsing (struct test *test,int subtest);int test__expand_cgroup_events (struct test *test,int subtest);int test__perf_time_to_tsc (struct test *test,int subtest); +int test__dlfilter (struct test *test,int subtest);bool test__bp_signal_is_supported (void );bool test__bp_account_is_supported (void );
tools/perf/util/dlfilter.c +2 -2
@@ -530,8 +530,8 @@ int dlfilter__do_filter_event(struct dlfilter *d,return ret; } -static bool get_filter_desc (const char *dirname,const char *name, -char **desc,char **long_desc) +bool get_filter_desc (const char *dirname,const char *name,char **desc, +char **long_desc) {char path[PATH_MAX ];void *handle;
tools/perf/util/dlfilter.h +2 -0
@@ -93,5 +93,7 @@ static inline int dlfilter__filter_event_early(struct dlfilter *d, }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
Signature · 1 line
2.17.1
Em Wed, Aug 11, 2021 at 01:10:30PM +0300, Adrian Hunter escreveu:
Quoted 6 lines
Hi
Here is V2 of some minor fixes / improvements to dlfilters and a new perf test for the dlfilter C API.
Quoted 7 lines
Changes in V2:
perf script: Fix documented const'ness of
perf_dlfilter_fns
New patchperf tools: Add dlfilter test
Do not makeperf_dlfilter_fnsconst in test dlfilter
Thanks, tested and applied, added a commiter notes section with the test output in verbose mode so that people get a glimpse of what it does.
- Arnaldo
commit 9f9c9a8de2d5e96c045deaf769006ef7b7b7fb1b
Author: Adrian Hunter <[email protected]> Date: Wed Aug 11 13:10:36 2021 +0300
perf tests: Add dlfilter test
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 ~]#
tools/perf/Makefile.perf +14 -1
@@ -360,8 +360,11 @@ ifndef NO_JVMTI PROGRAMS += $(OUTPUT)$(LIBJVMTI) endif +DLFILTERS := dlfilter-test-api-v0.so +DLFILTERS := $(patsubst %,$(OUTPUT)dlfilters/%,$(DLFILTERS)) + # what 'all' will build and 'install' will install, in perfexecdir -ALL_PROGRAMS = $(PROGRAMS) $(SCRIPTS) +ALL_PROGRAMS = $(PROGRAMS) $(SCRIPTS) $(DLFILTERS) # what 'all' will build but not install in perfexecdir OTHER_PROGRAMS = $(OUTPUT)perf
@@ -780,6 +783,13 @@ $(OUTPUT)perf-read-vdsox32: perf-read-vdso.c util/find-map.c $(QUIET_CC)$(CC) -mx32 $(filter -static,$(LDFLAGS)) -Wall -Werror -o $@ perf-read-vdso.c endif +$(OUTPUT)dlfilters/%.o: dlfilters/%.c include/perf/perf_dlfilter.h + $(Q)$(MKDIR) -p $(OUTPUT)dlfilters + $(QUIET_CC)$(CC) -c -Iinclude -o $@ -fpic $< + +$(OUTPUT)dlfilters/%.so: $(OUTPUT)dlfilters/%.o + $(QUIET_LINK)$(CC) -shared -o $@ $< + ifndef NO_JVMTI LIBJVMTI_IN := $(OUTPUT)jvmti/jvmti-in.o
@@ -978,6 +988,9 @@ ifndef NO_LIBPYTHON $(INSTALL) scripts/python/*.py -m 644 -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python'; \ $(INSTALL) scripts/python/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin' endif + $(call QUIET_INSTALL, dlfilters) \ + $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/dlfilters'; \ + $(INSTALL) $(DLFILTERS) '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/dlfilters'; $(call QUIET_INSTALL, perf_completion-script) \ $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(sysconfdir_SQ)/bash_completion.d'; \ $(INSTALL) perf-completion.sh '$(DESTDIR_SQ)$(sysconfdir_SQ)/bash_completion.d/perf'
tools/perf/dlfilters/dlfilter-test-api-v0.c new file +336 -0
336 lines not on this page · raw message
tools/perf/tests/Build +1 -0
@@ -64,6 +64,7 @@ perf-y += parse-metric.o perf-y += pe-file-parsing.o perf-y += expand-cgroup.o perf-y += perf-time-to-tsc.o +perf-y += dlfilter-test.o $(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c tests/Build $(call rule_mkdir)
tools/perf/tests/builtin-test.c +4 -0
@@ -360,6 +360,10 @@ static struct test generic_tests[] = { .func = test__perf_time_to_tsc, .is_supported = test__tsc_is_supported, }, + { + .desc = "dlfilter C API", + .func = test__dlfilter, + }, { .func = NULL, },
tools/perf/tests/dlfilter-test.c new file +411 -0
411 lines not on this page · raw message
tools/perf/tests/tests.h +1 -0
@@ -127,6 +127,7 @@ int test__parse_metric(struct test *test, int subtest);int test__pe_file_parsing (struct test *test,int subtest);int test__expand_cgroup_events (struct test *test,int subtest);int test__perf_time_to_tsc (struct test *test,int subtest); +int test__dlfilter (struct test *test,int subtest);bool test__bp_signal_is_supported (void );bool test__bp_account_is_supported (void );
tools/perf/util/dlfilter.c +2 -2
@@ -530,8 +530,8 @@ int dlfilter__do_filter_event(struct dlfilter *d,return ret; } -static bool get_filter_desc (const char *dirname,const char *name, -char **desc,char **long_desc) +bool get_filter_desc (const char *dirname,const char *name,char **desc, +char **long_desc) {char path[PATH_MAX ];void *handle;
tools/perf/util/dlfilter.h +2 -0
@@ -93,5 +93,7 @@ static inline int dlfilter__filter_event_early(struct dlfilter *d, }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