Support perf -vv
v3 cover Support perf -vv
We keep having bug reports that when users build perf on their own, but they don't install some needed libraries such as libelf, libbfd/libibery.
The perf can build, but it is missing important functionality. And users may complain that perf has issue or bug.
This patch-set support to print the status of compiled-in libraries.
Once users think perf missing some functionality, it should be very easy for them to check the libraries status.
For example:
$ ./perf version --build-options
or
./perf --version --build-options
or
./perf -v --build-options
or
./perf -vvperf version 4.13.rc5.g4c1df1
dwarf: [ on ]
dwarf_getlocations: [ on ]
glibc: [ on ]
gtk2: [ on ]
libaudit: [ OFF ]
libbfd: [ on ]
libelf: [ on ]
libnuma: [ on ]
numa_num_possible_cpus: [ on ]
libperl: [ on ]
libpython: [ on ]
libslang: [ on ]
libcrypto: [ on ]
libunwind: [ on ]
libdw-dwarf-unwind: [ on ]
zlib: [ on ]
lzma: [ on ]
get_cpuid: [ on ]
bpf: [ on ]Jin Yao (4):
perf config: Add some new -DHAVE_XXX to CFLAGS perf version: Print the compiled-in status of libraries
perf: Support perf -vv
perf Documentation: Create perf-version.txt
Jiri Olsa (1):
tools include: Add config.h header file
tools/include/tools/config.h | 34 +++++++++++++ tools/perf/Documentation/perf-version.txt | 24 +++++++++ tools/perf/Makefile.config | 6 +++ tools/perf/builtin-version.c | 81 ++++++++++++++++++++++++++++++- tools/perf/perf.c | 6 +++ tools/perf/perf.h | 1 + 6 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 tools/include/tools/config.h create mode 100644 tools/perf/Documentation/perf-version.txt
Signature · 1 line
2.7.4
PATCH v3 1/5 tools include: Add config.h header file
From: Jiri Olsa <[email protected]>
Adding IS_BUILTIN macro and its dependencies into
tools world.
It's taken from kernel's include/linux/kconfig.h, which can't be taken completely due to its kconfig dependencies.
--- tools/include/tools/config.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tools/include/tools/config.h
tools/include/tools/config.h new file +34 -0
@@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _TOOLS_CONFIG_H +#define _TOOLS_CONFIG_H + +/* Subset of include/linux/kconfig.h */ + +#define __ARG_PLACEHOLDER_1 0, +#define __take_second_arg (__ignored, val, ...) val + +/* +* Helper macros to use CONFIG_ options in C/CPP expressions. Note that +* these only work with boolean and tristate options. +*/ + +/* +* Getting something that works in C and CPP for an arg that may or may +* not be defined is tricky. Here, if we have "#define CONFIG_BOOGER 1" +* we match on the placeholder define, insert the "0," for arg1 and generate +* the triplet (0, 1, 0). Then the last step cherry picks the 2nd arg (a one). +* When CONFIG_BOOGER is not defined, we generate a (... 1, 0) pair, and when +* the last step cherry picks the 2nd arg, we get a zero. +*/ +#define __is_defined (x) ___is_defined(x) +#define ___is_defined (val) ____is_defined(__ARG_PLACEHOLDER_##val) +#define ____is_defined (arg1_or_junk) __take_second_arg(arg1_or_junk 1, 0) + +/* +* IS_BUILTIN(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y', 0 +* otherwise. For boolean options, this is equivalent to +* IS_ENABLED(CONFIG_FOO). +*/ +#define IS_BUILTIN (option) __is_defined(option) + +#endif /* _TOOLS_CONFIG_H */
Signature · 1 line
2.7.4
PATCH v3 3/5 perf version: Print the compiled-in status of libraries
In reply to Jin YaoThis patch checks the values passed by CFLAGS (-DHAVE_XXX) and then print the status of libraries.
For example, if HAVE_DWARF_SUPPORT is defined, that means the library "dwarf" is compiled-in. The patch will print the status "on" for this library otherwise it print the status "OFF".
A new option '--build-options' created for 'perf version' supports the printing of library status.
For example:
$ ./perf version --build-options
or
./perf --version --build-options
or
./perf -v --build-optionsperf version 4.13.rc5.g4c1df1
dwarf: [ on ]
dwarf_getlocations: [ on ]
glibc: [ on ]
gtk2: [ on ]
libaudit: [ OFF ]
libbfd: [ on ]
libelf: [ on ]
libnuma: [ on ]
numa_num_possible_cpus: [ on ]
libperl: [ on ]
libpython: [ on ]
libslang: [ on ]
libcrypto: [ on ]
libunwind: [ on ]
libdw-dwarf-unwind: [ on ]
zlib: [ on ]
lzma: [ on ]
get_cpuid: [ on ]
bpf: [ on ]v3:
---
Remove following unnecessary help message.
1. [ on ]: library is compiled-in
[ OFF ]: library is disabled in make configuration
OR library is not installed in build environment
2. Create '--build-options' option.
3. Use standard option parsing API 'parse_options'.
v2:
---
1. Use IS_BUILTIN macro to replace #ifdef/#endif block.
2. Print color for on/OFF.
--- tools/perf/builtin-version.c | 81 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-)
tools/perf/builtin-version.c +80 -1
@@ -1,11 +1,90 @@// SPDX-License-Identifier: GPL-2.0 #include "builtin.h" #include "perf.h" +#include "color.h" #include <linux/compiler.h> +#include <tools/config.h> #include <stdio.h> +#include <string.h> +#include <subcmd/parse-options.h> -int cmd_version (int argc__maybe_unused ,const char **argv__maybe_unused ) +int version_verbose; + +struct version { +bool build_options; +}; + +static struct version version; + +static struct option version_options[] = { +OPT_BOOLEAN (0 ,"build-options" , &version.build_options, +"display the build options" ), +}; + +static const char *const version_usage[] = { +"perf version [<options>]" , +NULL +}; + +static void on_off_print (const char *status) +{ +printf ("[ " ); + +if (!strcmp (status,"OFF" )) +color_fprintf (stdout,PERF_COLOR_RED ,"%-3s" , status); +else +color_fprintf (stdout,PERF_COLOR_GREEN ,"%-3s" , status); + +printf (" ]" ); +} + +static void status_print (const char *name,const char *status) { +printf ("%22s: " , name); +on_off_print (status); +printf ("\n" ); +} + +#define STATUS (__d, __m) \ +do { \ + if (IS_BUILTIN(__d)) \ + status_print(#__m, "on"); \ + else \ + status_print(#__m, "OFF"); \ +} while (0) + +static void library_status (void ) +{ +STATUS (HAVE_DWARF_SUPPORT , dwarf); +STATUS (HAVE_DWARF_GETLOCATIONS , dwarf_getlocations); +STATUS (HAVE_GLIBC_SUPPORT , glibc); +STATUS (HAVE_GTK2_SUPPORT , gtk2); +STATUS (HAVE_LIBAUDIT_SUPPORT , libaudit); +STATUS (HAVE_LIBBFD_SUPPORT , libbfd); +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); +} + +int cmd_version (int argc,const char **argv) +{ + argc =parse_options (argc, argv, version_options, version_usage, +PARSE_OPT_STOP_AT_NON_OPTION ); +printf ("perf version %s\n" , perf_version_string); + +if (version.build_options || version_verbose ==1 ) +library_status (); +return 0 ; }
Signature · 1 line
2.7.4
PATCH v3 4/5 perf: Support perf -vv
In reply to Jin YaoWe keep having bug reports that when users build perf on their own, but they don't install some needed libraries such as libelf, libbfd/libibery.
The perf can build, but it is missing important functionality.
This patch provides a new option '-vv' for perf which will print the compiled-in status of libraries.
The 'perf -vv' is mapped to 'perf version --build-options'.
For example:
$ ./perf -vv
perf version 4.13.rc5.g4c1df1
dwarf: [ on ]
dwarf_getlocations: [ on ]
glibc: [ on ]
gtk2: [ on ]
libaudit: [ OFF ]
libbfd: [ on ]
libelf: [ on ]
libnuma: [ on ]
numa_num_possible_cpus: [ on ]
libperl: [ on ]
libpython: [ on ]
libslang: [ on ]
libcrypto: [ on ]
libunwind: [ on ]
libdw-dwarf-unwind: [ on ]
zlib: [ on ]
lzma: [ on ]
get_cpuid: [ on ]
bpf: [ on ]v3:
---
One bug is found in v2. It didn't process the option like '-vabc' correctly. Fix this bug.
v2:
---
Use a global variable version_verbose to record the number of 'v'.
--- tools/perf/perf.c | 6 ++++++ tools/perf/perf.h | 1 + 2 files changed, 7 insertions(+)
tools/perf/perf.c +6 -0
@@ -190,6 +190,12 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)break ; } +if (!strcmp (cmd,"-vv" )) { + (*argv)[0 ] ="version" ; + version_verbose =1 ; +break ; + } +/* * Check remaining flags. */
tools/perf/perf.h +1 -0
@@ -84,6 +84,7 @@ struct record_opts {struct option ;extern const char *const *record_usage;extern struct option *record_options; +extern int version_verbose;int record__parse_freq (const struct option *opt,const char *str,int unset);#endif
Signature · 1 line
2.7.4
PATCH v3 5/5 perf Documentation: Create perf-version.txt
In reply to Jin YaoSince a new option '--build-options' is created for 'perf version', so we need to document it.
--- tools/perf/Documentation/perf-version.txt | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tools/perf/Documentation/perf-version.txt
tools/perf/Documentation/perf-version.txt new file +24 -0
@@ -0,0 +1,24 @@ +perf-version(1) +=============== + +NAME +---- +perf-version - display the version of perf binary + +SYNOPSIS +-------- +'perf version' [--build-options] + +DESCRIPTION +----------- +With no options given, the 'perf version' prints the perf version +on the standard output. + +If the option '--build-options' is given, then the status of +compiled-in libraries are printed on the standard output. + +OPTIONS +------- +--build-options:: + Prints the status of compiled-in libraries on the + standard output.
Signature · 1 line
2.7.4
Quoted 9 lines · Jin Yao
For example:
$ ./perf version --build-options or ./perf --version --build-options or ./perf -v --build-options or ./perf -vv
Thank you, the UI looks perfect to me!
Quoted 12 lines
perf version 4.13.rc5.g4c1df1
dwarf: [ on ] dwarf_getlocations: [ on ] glibc: [ on ] gtk2: [ on ] libaudit: [ OFF ] libbfd: [ on ] libelf: [ on ] libnuma: [ on ] numa_num_possible_cpus: [ on ] libperl: [ on ] libpython: [ on ]
Quoted 8 lines
libslang: [ on ]
libcrypto: [ on ]
libunwind: [ on ]
libdw-dwarf-unwind: [ on ]
zlib: [ on ]
lzma: [ on ]
get_cpuid: [ on ]
bpf: [ on ]... and it's a nice touch that this is now printed in color, like the perf build system does.
BTW., perhaps it would be nice to also print the macro name that is used within the sources:
dwarf: [ on ] # HAVE_DWARF_SUPPORT
dwarf_getlocations: [ on ] # HAVE_DWARF_GETLOCATIONS
glibc: [ on ] # HAVE_GLIBC_SUPPORT
gtk2: [ on ] # HAVE_GTK2_SUPPORT
libaudit: [ OFF ] # HAVE_LIBAUDIT_SUPPORT
...?
That would make it easier to grep around in the source looking for where code related a particular features is located.
BTW. #2: to the compulsive perfectionist in me "HAVE_DWARF_GETLOCATIONS" is now sticking out like a sore thumb: it's the only library flag left that doesn't have the _SUPPORT suffix. Rename it to HAVE_DWARF_GETLOCATIONS_SUPPORT perhaps?
Thanks,
Ingo
Quoted 36 lines · Ingo Molnar
Quoted 9 lines · Jin Yao
For example:
$ ./perf version --build-options or ./perf --version --build-options or ./perf -v --build-options or ./perf -vvThank you, the UI looks perfect to me!
Quoted 10 lines
perf version 4.13.rc5.g4c1df1
dwarf: [ on ] dwarf_getlocations: [ on ] glibc: [ on ] gtk2: [ on ]libaudit: [ OFF ]
libbfd: [ on ]
libelf: [ on ]
libnuma: [ on ]numa_num_possible_cpus: [ on ]Quoted 10 lines
libperl: [ on ] libpython: [ on ] libslang: [ on ] libcrypto: [ on ] libunwind: [ on ] libdw-dwarf-unwind: [ on ] zlib: [ on ] lzma: [ on ] get_cpuid: [ on ] bpf: [ on ]
Quoted 3 lines
... and it's a nice touch that this is now printed in color, like the perf build system does.
Yes, the printing is in color yet. Green for [on] and red for [OFF]. :)
Quoted 10 lines
BTW., perhaps it would be nice to also print the macro name that is used within the sources:
dwarf: [ on ] # HAVE_DWARF_SUPPORT dwarf_getlocations: [ on ] # HAVE_DWARF_GETLOCATIONS glibc: [ on ] # HAVE_GLIBC_SUPPORT gtk2: [ on ] # HAVE_GTK2_SUPPORT libaudit: [ OFF ] # HAVE_LIBAUDIT_SUPPORT ...
Quoted 5 lines
?
That would make it easier to grep around in the source looking for where code related a particular features is located.
Good idea, thanks! I will support it in v4.
Quoted 8 lines
BTW. #2: to the compulsive perfectionist in me "
HAVE_DWARF_GETLOCATIONS" is now sticking out like a sore thumb: it's the only library flag left that doesn't have the_SUPPORTsuffix. Rename it toHAVE_DWARF_GETLOCATIONS_SUPPORTperhaps?Thanks,
Ingo
OK, I will rename it to HAVE_DWARF_GETLOCATIONS_SUPPORT in v4.
Thanks
Jin Yao
On Thu, Mar 29, 2018 at 03:49:18PM +0800, Jin, Yao wrote:
SNIP
Quoted 10 lines
Quoted 3 lines
That would make it easier to grep around in the source looking for where code related a particular features is located.
Good idea, thanks! I will support it in v4.
Quoted 4 lines
BTW. #2: to the compulsive perfectionist in me "
HAVE_DWARF_GETLOCATIONS" is now sticking out like a sore thumb: it's the only library flag left that doesn't have the_SUPPORTsuffix. Rename it toHAVE_DWARF_GETLOCATIONS_SUPPORTperhaps?
Quoted 6 lines
Quoted 4 lines
Thanks,
Ingo
OK, I will rename it to
HAVE_DWARF_GETLOCATIONS_SUPPORTin v4.
thanks for doing this, I'll ack the new version then
jirka