perf tools: Builtin options related improvements
v3 cover perf tools: Builtin options related improvements
According to Arnaldo's suggestion, patch 1/2 ensures options always there even if they are not build. When user tries to use a not build option, error or warning messages would tell them the reason.
Patch 2/2 adds vmlinux option to perf record to support BPF argument fetching better. Without this patch vmlinux must be reside in standard path for BPF loader finding it.
He Kuang (1):
perf record: Support custom vmlinux path
Wang Nan (1):
perf tools: Always give options even it not compiled
tools/perf/Documentation/perf-record.txt | 10 ++- tools/perf/builtin-probe.c | 15 +++- tools/perf/builtin-record.c | 25 ++++++- tools/perf/util/parse-options.c | 113 ++++++++++++++++++++++++++++--- tools/perf/util/parse-options.h | 5 ++ 5 files changed, 153 insertions(+), 15 deletions(-)
Signature · 1 line
1.8.3.4
PATCH v3 1/2 perf tools: Always give options even it not compiled
This patch keeps options of perf builtins same in all conditions. If one option is disabled because of compiling options, users should be notified.
Masami suggested another implementation in [1] that, by adding a OPTION_NEXT_DEPENDS option before those options in the 'struct option' array, options parser knows an option is disabled. However, in some cases this array is reordered (options__order()). In addition, in parse-option.c that array is const, so we can't simply merge information in decorator option into the affacted option.
This patch chooses a simpler implementation that, introducing a set_option_nobuild() function and two option parsing flags. Builtins with such options should call set_option_nobuild() before option parsing. The complexity of this patch is because we want some of options can be skipped safely. In this case their arguments should also be consumed.
Options in 'perf record' and 'perf probe' are fixed in this patch.
Test result:
Normal case:
# ./perf probe --vmlinux /tmp/vmlinux sys_write Added new event: probe:sys_write (on sys_write)
You can now use it in all perf tools, such as:
perf record -e probe:sys_write -aR sleep 1
Build with NO_DWARF=1:
# ./perf probe -L sys_write Error: switch `L' is not built because NO_DWARF=1
Usage: perf probe [<options>] 'PROBEDEF' ['PROBEDEF' ...]
or: perf probe [<options>] --add 'PROBEDEF' [--add 'PROBEDEF' ...]
or: perf probe [<options>] --del '[GROUP:]EVENT' ...
or: perf probe --list [GROUP:]EVENT ...
or: perf probe [<options>] --funcs
-L, --line <FUNC[:RLN[+NUM|-RLN2]]|SRC:ALN[+NUM|-ALN2]>
Show source code lines.
(not build because NO_DWARF=1)# ./perf probe -k /tmp/vmlinux sys_write Warning: switch `k' is not built because NO_DWARF=1 Added new event: probe:sys_write (on sys_write)
You can now use it in all perf tools, such as:
perf record -e probe:sys_write -aR sleep 1
# ./perf probe --vmlinux /tmp/vmlinux sys_write Warning: option `vmlinux' is not built because NO_DWARF=1 Added new event: [SNIP]
# ./perf probe -l
Usage: perf probe [<options>] 'PROBEDEF' ['PROBEDEF' ...]
or: perf probe [<options>] --add 'PROBEDEF' [--add 'PROBEDEF' ...]
...
-k, --vmlinux <file> vmlinux pathname
(not build because NO_DWARF=1)
-L, --line <FUNC[:RLN[+NUM|-RLN2]]|SRC:ALN[+NUM|-ALN2]>
Show source code lines.
(not build because NO_DWARF=1)
...
-V, --vars <FUNC[@SRC][+OFF|%return|:RL|;PT]|SRC:AL|SRC;PT>
Show accessible variables on PROBEDEF
(not build because NO_DWARF=1)
--externs Show external variables too (with --vars only)
(not build because NO_DWARF=1)
--no-inlines Don't search inlined functions
(not build because NO_DWARF=1)
--range Show variables location range in scope (with --vars only)
(not build because NO_DWARF=1)--- tools/perf/builtin-probe.c | 15 +++++- tools/perf/builtin-record.c | 9 +++- tools/perf/util/parse-options.c | 113 ++++++++++++++++++++++++++++++++++++---- tools/perf/util/parse-options.h | 5 ++ 4 files changed, 129 insertions(+), 13 deletions(-)
tools/perf/builtin-probe.c +13 -2
@@ -249,6 +249,9 @@ static int opt_show_vars(const struct option *opt, return ret; } +#else +# define opt_show_lines NULL +# define opt_show_vars NULL#endif static int opt_add_probe_event (const struct option *opt,const char *str,int unset__maybe_unused )
@@ -473,7 +476,6 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused) opt_add_probe_event),OPT_BOOLEAN ('f' ,"force" , &probe_conf.force_add,"forcibly add events" " with existing name" ), -#ifdef HAVE_DWARF_SUPPORTOPT_CALLBACK ('L' ,"line" ,NULL ,"FUNC[:RLN[+NUM|-RLN2]]|SRC:ALN[+NUM|-ALN2]" , "Show source code lines.", opt_show_lines),
@@ -490,7 +492,6 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused) "directory", "path to kernel source"),OPT_BOOLEAN ('\0' ,"no-inlines" , &probe_conf.no_inlines,"Don't search inlined functions" ), -#endif OPT__DRY_RUN (&probe_event_dry_run),OPT_INTEGER ('\0' ,"max-probes" , &probe_conf.max_probes, "Set how many probe points can be found for a probe."),
@@ -521,6 +522,16 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused)#ifdef HAVE_DWARF_SUPPORT set_option_flag (options,'L' ,"line" ,PARSE_OPT_EXCLUSIVE );set_option_flag (options,'V' ,"vars" ,PARSE_OPT_EXCLUSIVE ); +#else +# define set_nobuild (s, l, c) set_option_nobuild(options, s, l, "NO_DWARF=1", c) +set_nobuild ('L' ,"line" , false); +set_nobuild ('V' ,"vars" , false); +set_nobuild ('\0' ,"externs" , false); +set_nobuild ('\0' ,"range" , false); +set_nobuild ('k' ,"vmlinux" , true); +set_nobuild ('s' ,"source" , true); +set_nobuild ('\0' ,"no-inlines" , true); +# undef set_nobuild#endif set_option_flag (options,'F' ,"funcs" ,PARSE_OPT_EXCLUSIVE );
tools/perf/builtin-record.c +7 -2
@@ -1124,12 +1124,10 @@ struct option __record_options[] = { "per thread proc mmap processing timeout in ms"),OPT_BOOLEAN (0 ,"switch-events" , &record.opts.record_switch_events,"Record context switch events" ), -#ifdef HAVE_LIBBPF_SUPPORTOPT_STRING (0 ,"clang-path" , &llvm_param.clang_path,"clang path" ,"clang binary to use for compiling BPF scriptlets" ),OPT_STRING (0 ,"clang-opt" , &llvm_param.clang_opt,"clang options" ,"options passed to clang when compiling BPF scriptlets" ), -#endif OPT_END() };
@@ -1141,6 +1139,13 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)struct record *rec = &record;char errbuf[BUFSIZ ]; +#ifndef HAVE_LIBBPF_SUPPORT +# define set_nobuild (s, l, c) set_option_nobuild(record_options, s, l, "NO_LIBBPF=1", c) +set_nobuild ('\0' ,"clang-path" , true); +set_nobuild ('\0' ,"clang-opt" , true); +# undef set_nobuild +#endif + rec->evlist =perf_evlist__new ();if (rec->evlist ==NULL )return -ENOMEM ;
tools/perf/util/parse-options.c +104 -9
151 lines not on this page · raw message
tools/perf/util/parse-options.h +5 -0
@@ -41,6 +41,8 @@ enum parse_opt_option_flags {PARSE_OPT_DISABLED =32 ,PARSE_OPT_EXCLUSIVE =64 ,PARSE_OPT_NOEMPTY =128 , +PARSE_OPT_NOBUILD =256 , + PARSE_OPT_CANSKIP = 512, };struct option ;
@@ -96,6 +98,7 @@ struct option {void *value;const char *argh;const char *help; +const char *build_opt;int flags;parse_opt_cb *callback;
@@ -226,4 +229,6 @@ extern int parse_opt_verbosity_cb(const struct option *, const char *, int);extern const char *parse_options_fix_filename (const char *prefix,const char *file);void set_option_flag (struct option *opts,int sopt,const char *lopt,int flag); +void set_option_nobuild (struct option *opts,int shortopt,const char *longopt, +const char *build_opt,bool can_skip);#endif /* __PERF_PARSE_OPTIONS_H */
Signature · 1 line
1.8.3.4
PATCH v3 2/2 perf record: Support custom vmlinux path
In reply to Wang NanFrom: He Kuang <[email protected]>
Make perf-record command support --vmlinux option if BPF_PROLOGUE is on.
'perf record' needs vmlinux as the source of DWARF info to generate prologue for BPF programs, so path of vmlinux should be specified.
Short name 'k' has been taken by 'clockid'. This patch skips the short option name and use '--vmlinux' for vmlinux path.
Documentation is also updated.
Test result:
In a production (or broken) environment:
(built by
# rm -rf ~/.debug/ # mv /lib/modules/`uname -r`/build/vmlinux /tmp/ )
# ./perf record -e ./test_bpf_base.c ls
Failed to find the path for kernel: No such file or directory
event syntax error: './test_bpf_base.c'
\___ You need to check probing points in BPF file
...# ./perf record --vmlinux /tmp/vmlinux -e ./test_bpf_base.c ls ... [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.011 MB perf.data ]
Help messages when build with NO_LIBBPF:
# ./perf record -h
--transaction sample transaction flags (special events only)
--vmlinux <file> vmlinux pathname
(not build because NO_LIBBPF=1)
# ./perf record --vmlinux /tmp/vmlinux ls /
Warning: option `vmlinux' is not built because NO_LIBBPF=1
...
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.011 MB perf.data (11 samples) ]Help messages when build with NO_DWARF:
# ./perf record -h
--transaction sample transaction flags (special events only)
--vmlinux <file> vmlinux pathname
(not build because NO_DWARF=1)--- tools/perf/Documentation/perf-record.txt | 10 ++++++++-- tools/perf/builtin-record.c | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-record.txt +8 -2
@@ -314,11 +314,17 @@ This option sets the time out limit. The default value is 500 ms. Record context switch events i.e. events of type PERF_RECORD_SWITCH or PERF_RECORD_SWITCH_CPU_WIDE. ---clang-path:: +--clang-path=PATH:: Path to clang binary to use for compiling BPF scriptlets. +(enabled when BPF support is on) ---clang-opt:: +--clang-opt=OPTIONS:: Options passed to clang when compiling BPF scriptlets. +(enabled when BPF support is on) + +--vmlinux=PATH:: +Specify vmlinux path which has debuginfo. +(enabled when BPF prologue is on) SEE ALSO --------
tools/perf/builtin-record.c +16 -0
@@ -1128,6 +1128,8 @@ struct option __record_options[] = { "clang binary to use for compiling BPF scriptlets"),OPT_STRING (0 ,"clang-opt" , &llvm_param.clang_opt,"clang options" ,"options passed to clang when compiling BPF scriptlets" ), +OPT_STRING (0 ,"vmlinux" , &symbol_conf.vmlinux_name, +"file" ,"vmlinux pathname" ), OPT_END() };
@@ -1146,6 +1148,20 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)# undef set_nobuild#endif +#ifndef HAVE_BPF_PROLOGUE +# if !defined (HAVE_DWARF_SUPPORT ) +# define REASON "NO_DWARF=1" +# elif !defined (HAVE_LIBBPF_SUPPORT ) +# define REASON "NO_LIBBPF=1" +# else +# define REASON "this architecture doesn't support BPF prologue" +# endif +# define set_nobuild (s, l, c) set_option_nobuild(record_options, s, l, REASON, c) +set_nobuild ('\0' ,"vmlinux" , true); +# undef set_nobuild +# undef REASON +#endif + rec->evlist =perf_evlist__new ();if (rec->evlist ==NULL )return -ENOMEM ;
Signature · 1 line
1.8.3.4