Introduce perf build subcommand
cover Introduce perf build subcommand
The Problem
===========
Currently the presence of a feature is checked with a combination of perf version --build-options and greps, such as:
perf version --build-options | grep " on .* HAVE_FEATURE"
Proposed solution
=================
As suggested by contributors in:
https://lore.kernel.org/linux-perf-users/[email protected]/
Introduce a subcommand "perf build --has", with which scripts can test for presence of a feature, such as:
perf build --has HAVE_FEATURE
The usage of "perf version --build-options | grep" has been replaced in two tests, with "perf build --has" command
Also, to not duplicate the same feature list at multiple places, a new global 'supported_features' array has been introduced in builtin.h, so both commands 'perf build --has' and 'perf version --build-options' use the same array
'supported_features' feature is an array of 'struct feature_support', which also has the name of the feature, macro used to test it's presence, and a is_builtin member, which will be 0 if feature not built-in, and 1 if built-in
Architectures Tested
====================
* x86_64
* ppc64le
Git tree
========
Git tree with this patch series applied for testing:
https://github.com/adi-g15-ibm/linux/tree/perf-build-has
Aditya Gupta (3):
perf build: introduce build subcommand
perf version: update --build-options to use 'supported_features' array perf tests task_analyzer: check perf build for libtraceevent support
Athira Rajeev (1):
tools/perf/tests: Update probe_vfs_getname.sh script to use perf build
--has
tools/perf/Build | 1 + tools/perf/builtin-build.c | 94 +++++++++++++++++++ tools/perf/builtin-version.c | 39 ++------ tools/perf/builtin.h | 47 ++++++++++ tools/perf/perf.c | 1 + .../perf/tests/shell/lib/probe_vfs_getname.sh | 4 +- .../shell/record+probe_libc_inet_pton.sh | 5 +- .../shell/record+script_probe_vfs_getname.sh | 5 +- tools/perf/tests/shell/test_task_analyzer.sh | 4 +- 9 files changed, 163 insertions(+), 37 deletions(-) create mode 100644 tools/perf/builtin-build.c
Signature · 1 line
2.41.0
PATCH 1/4 perf build: introduce build subcommand
Currently the presence of a feature is checked with a combination of perf version --build-options and greps, such as:
perf version --build-options | grep " on .* HAVE_FEATURE"
Instead of this, introduce a subcommand "perf build --has", with which scripts can test for presence of a feature, such as:
perf build --has HAVE_FEATURE
'perf build --has' command is expected to have exit status of 1 if feature is built-in, and 0 if not, -2 if feature is not known.
A global array 'supported_features' has also been introduced that can be used by other commands like 'perf version --build-options', so that new features can be added in one place, with the array
--- tools/perf/Build | 1 + tools/perf/builtin-build.c | 94 ++++++++++++++++++++++++++++++++++++++ tools/perf/builtin.h | 47 +++++++++++++++++++ tools/perf/perf.c | 1 + 4 files changed, 143 insertions(+) create mode 100644 tools/perf/builtin-build.c
tools/perf/Build +1 -0
@@ -5,6 +5,7 @@ perf-y += builtin-diff.o perf-y += builtin-evlist.o perf-y += builtin-ftrace.o perf-y += builtin-help.o +perf-y += builtin-build.o perf-y += builtin-buildid-list.o perf-y += builtin-buildid-cache.o perf-y += builtin-kallsyms.o
tools/perf/builtin-build.c new file +94 -0
94 lines not on this page · raw message
tools/perf/builtin.h +47 -0
58 lines not on this page · raw message
tools/perf/perf.c +1 -0
@@ -48,6 +48,7 @@ struct cmd_struct {static struct cmd_struct commands[] = { {"archive" ,NULL ,0 }, + {"build" , cmd_build,0 }, {"buildid-cache" , cmd_buildid_cache,0 }, {"buildid-list" , cmd_buildid_list,0 }, {"config" , cmd_config,0 },
Signature · 1 line
2.41.0
PATCH 2/4 perf version: update --build-options to use 'supported_features' array
In reply to Aditya GuptaNow that the feature list has been duplicated in a global 'supported_features' array, use that array instead of manually checking status of built-in features.
This helps in being consistent with commands such as 'perf build --has', so commands can use the same array, and any new feature can be added at one place, in the 'supported_features' array
--- tools/perf/builtin-version.c | 39 ++++++++---------------------------- 1 file changed, 8 insertions(+), 31 deletions(-)
tools/perf/builtin-version.c +8 -31
@@ -46,41 +46,18 @@ static void status_print(const char *name, const char *macro,printf (" # %s\n" , macro); } -#define STATUS (__d, __m) \ -do { \ - if (IS_BUILTIN(__d)) \ - status_print(#__m, #__d, "on"); \ - else \ - status_print(#__m, #__d, "OFF"); \ +#define STATUS (feature) \ +do { \ + if (feature.is_builtin) \ + status_print(feature.name, feature.macro, "on"); \ + else \ + status_print(feature.name, feature.macro, "OFF"); \ } while (0)static void library_status (void ) { -STATUS (HAVE_DWARF_SUPPORT , dwarf); -STATUS (HAVE_DWARF_GETLOCATIONS_SUPPORT , dwarf_getlocations); -#ifndef HAVE_SYSCALL_TABLE_SUPPORT -STATUS (HAVE_LIBAUDIT_SUPPORT , libaudit); -#endif -STATUS (HAVE_SYSCALL_TABLE_SUPPORT , syscall_table); -STATUS (HAVE_LIBBFD_SUPPORT , libbfd); -STATUS (HAVE_DEBUGINFOD_SUPPORT , debuginfod); -STATUS (HAVE_LIBELF_SUPPORT , libelf); -STATUS (HAVE_LIBNUMA_SUPPORT , libnuma); -STATUS (HAVE_LIBNUMA_SUPPORT , numa_num_possible_cpus); -STATUS (HAVE_LIBPERL_SUPPORT , libperl); -STATUS (HAVE_LIBPYTHON_SUPPORT , libpython); -STATUS (HAVE_SLANG_SUPPORT , libslang); -STATUS (HAVE_LIBCRYPTO_SUPPORT , libcrypto); -STATUS (HAVE_LIBUNWIND_SUPPORT , libunwind); -STATUS (HAVE_DWARF_SUPPORT , libdw-dwarf-unwind); -STATUS (HAVE_ZLIB_SUPPORT , zlib); -STATUS (HAVE_LZMA_SUPPORT , lzma); -STATUS (HAVE_AUXTRACE_SUPPORT , get_cpuid); -STATUS (HAVE_LIBBPF_SUPPORT , bpf); -STATUS (HAVE_AIO_SUPPORT , aio); -STATUS (HAVE_ZSTD_SUPPORT , zstd); -STATUS (HAVE_LIBPFM , libpfm4); -STATUS (HAVE_LIBTRACEEVENT , libtraceevent); +for (int i =0 ; supported_features[i].name; ++i) +STATUS (supported_features[i]); }int cmd_version (int argc,const char **argv)
Signature · 1 line
2.41.0
PATCH 3/4 perf tests task_analyzer: check perf build for libtraceevent support
In reply to Aditya GuptaCurrently we depend on output of 'perf record -e "sched:sched_switch"', to check whether perf was built with libtraceevent support.
Instead, a more straightforward approach can be to check the build options, using 'perf build --has libtraceevent', to check for libtraceevent support.
--- tools/perf/tests/shell/test_task_analyzer.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/tests/shell/test_task_analyzer.sh +2 -2
@@ -52,8 +52,8 @@ find_str_or_fail() { # check if perf is compiled with libtraceevent support skip_no_probe_record_support() { - perf version --build-options | grep -q " OFF .* HAVE_LIBTRACEEVENT" && return 2 - return 0 + perf build --has libtraceevent >/dev/null && return 0 + return 2 } prepare_perf_data() {
Signature · 1 line
2.41.0
PATCH 4/4 tools/perf/tests: Update probe_vfs_getname.sh script to use perf build --has
In reply to Aditya GuptaFrom: Athira Rajeev <[email protected]>
In probe_vfs_getname.sh, current we use "perf record --dry-run" to check for libtraceevent and skip the test if perf is not build with libtraceevent. Change the check to use "perf build --has" option
--- tools/perf/tests/shell/lib/probe_vfs_getname.sh | 4 ++-- tools/perf/tests/shell/record+probe_libc_inet_pton.sh | 5 ++++- tools/perf/tests/shell/record+script_probe_vfs_getname.sh | 5 ++++- 3 files changed, 10 insertions(+), 4 deletions(-)
tools/perf/tests/shell/lib/probe_vfs_getname.sh +2 -2
@@ -27,7 +27,7 @@ skip_if_no_debuginfo() { # check if perf is compiled with libtraceevent support skip_no_probe_record_support() { if [ $had_vfs_getname -eq 1 ] ; then - perf record --dry-run -e $1 2>&1 | grep "libtraceevent is necessary for tracepoint support" && return 2 - return 1 + perf build --has libtraceevent >/dev/null && return 1 + return 2 fi }
tools/perf/tests/shell/record+probe_libc_inet_pton.sh +4 -1
@@ -58,7 +58,10 @@ trace_libc_inet_pton_backtrace() { # Check presence of libtraceevent support to run perf record skip_no_probe_record_support "$event_name/$eventattr/" - [ $? -eq 2 ] && return 2 + if [ $? -eq 2 ]; then + echo "WARN: Skipping test trace_libc_inet_pton_backtrace. No libtraceevent support." + return 2 + fi perf record -e $event_name/$eventattr/ -o $perf_data ping -6 -c 1 ::1 > /dev/null 2>&1 # check if perf data file got created in above step.
tools/perf/tests/shell/record+script_probe_vfs_getname.sh +4 -1
@@ -19,7 +19,10 @@ record_open_file() { echo "Recording open file:" # Check presence of libtraceevent support to run perf record skip_no_probe_record_support "probe:vfs_getname*" - [ $? -eq 2 ] && return 2 + if [ $? -eq 2 ]; then + echo "WARN: Skipping test record_open_file. No libtraceevent support" + return 2 + fi perf record -o ${perfdata} -e probe:vfs_getname\* touch $file }
Signature · 1 line
2.41.0
Namhyung Kim
maintainerHello,
Quoted 15 lines · Aditya Gupta
The Problem
===========Currently the presence of a feature is checked with a combination of perf version --build-options and greps, such as:
perf version --build-options | grep " on .* HAVE_FEATURE"Proposed solution
=================As suggested by contributors in:
https://lore.kernel.org/linux-perf-users/[email protected]/
Quoted 7 lines
Introduce a subcommand "perf build --has", with which scripts can test for presence of a feature, such as:
perf build --has HAVE_FEATUREThe usage of "perf version --build-options | grep" has been replaced in two tests, with "perf build --has" command
I'm not sure 'perf build' is a good name, it sounds like it needs to build something. Maybe 'perf check --feature XXX' ?
Then we can extend the perf check command to *check* system settings like perf_event_paranoid, kptr_restrict, nmi_watchdog and so on, and possibly provides some advice or even change the values easily.
What do you think?
Thanks,
Namhyung
Quoted 44 lines
Also, to not duplicate the same feature list at multiple places, a new global '
supported_features' array has been introduced inbuiltin.h, so both commands 'perf build --has' and 'perf version --build-options' use the same array'
supported_features' feature is an array of 'structfeature_support', which also has the name of the feature, macro used to test it's presence, and ais_builtinmember, which will be 0 if feature not built-in, and 1 if built-inArchitectures Tested
====================
*x86_64
* ppc64leGit tree
========Git tree with this patch series applied for testing:
https://github.com/adi-g15-ibm/linux/tree/perf-build-hasAditya Gupta (3):
perf build: introduce build subcommand
perf version: update --build-options to use 'supported_features' array perf teststask_analyzer: check perf build for libtraceevent supportAthira Rajeev (1):
tools/perf/tests: Updateprobe_vfs_getname.shscript to use perf build--hastools/perf/Build | 1 + tools/perf/builtin-build.c | 94 +++++++++++++++++++ tools/perf/builtin-version.c | 39 ++------ tools/perf/builtin.h | 47 ++++++++++ tools/perf/perf.c | 1 + .../perf/tests/shell/lib/probe_vfs_getname.sh | 4 +- .../shell/record+probe_libc_inet_pton.sh | 5 +- .../shell/record+script_probe_vfs_getname.sh | 5 +- tools/perf/tests/shell/test_task_analyzer.sh | 4 +- 9 files changed, 163 insertions(+), 37 deletions(-) create mode 100644 tools/perf/builtin-build.c--
2.41.0
Hello,
Quoted 22 lines · Namhyung Kim
Hello,
Quoted 9 lines · Aditya Gupta
<...>
Proposed solution
=================As suggested by contributors in:
https://lore.kernel.org/linux-perf-users/[email protected]/Quoted 6 lines
Introduce a subcommand "perf build --has", with which scripts can test for presence of a feature, such as:
perf build --has HAVE_FEATURE<...>
I'm not sure 'perf build' is a good name, it sounds like it needs to build something. Maybe 'perf check --feature XXX' ?
Quoted 7 lines
Then we can extend the perf check command to *check* system settings like
perf_event_paranoid,kptr_restrict,nmi_watchdogand so on, and possibly provides some advice or even change the values easily.What do you think?
Sure, the said confusion due to 'build' makes sense. I will discuss with athira also and post a V2 with suggested change.
And, since a new subcommand is being introduced, where do I add a documentation, such that it can be visible in a manpage etc, similar to perf-version(1) ?
Thanks,
Aditya Gupta
Hello Namhyung,
Quoted 27 lines · Namhyung Kim
Quoted 15 lines · Aditya Gupta
The Problem
===========Currently the presence of a feature is checked with a combination of perf version --build-options and greps, such as:
perf version --build-options | grep " on .* HAVE_FEATURE"Proposed solution
=================As suggested by contributors in:
https://lore.kernel.org/linux-perf-users/[email protected]/Quoted 7 lines
Introduce a subcommand "perf build --has", with which scripts can test for presence of a feature, such as:
perf build --has HAVE_FEATUREThe usage of "perf version --build-options | grep" has been replaced in two tests, with "perf build --has" command
I'm not sure 'perf build' is a good name, it sounds like it needs to build something. Maybe 'perf check --feature XXX' ?
Quoted 6 lines
Then we can extend the perf check command to *check* system settings like
perf_event_paranoid,kptr_restrict,nmi_watchdogand so on, and possibly provides some advice or even change the values easily.What do you think?
Thanks for the suggestion, we agree with it.
I have sent the updated patch series, but it's again from V1 since the subcommand changed.
Patch series: https://lore.kernel.org/linux-perf-users/[email protected]
Thanks,
Aditya Gupta