diff options
author | Adrian Hunter <adrian.hunter@intel.com> | 2021-06-27 16:18:12 +0300 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2021-07-01 16:14:37 -0300 |
commit | 3d032a251605740b75decd3381dc9d496a245ca0 (patch) | |
tree | 918201b7c7b8adc4ce17e53f923685eafbd85fc4 /tools/perf/builtin-script.c | |
parent | 638e2b9984ee1b8d485366f74d579467880283b4 (diff) | |
download | linux-stable-3d032a251605740b75decd3381dc9d496a245ca0.tar.gz linux-stable-3d032a251605740b75decd3381dc9d496a245ca0.tar.bz2 linux-stable-3d032a251605740b75decd3381dc9d496a245ca0.zip |
perf script: Add option to pass arguments to dlfilters
Add option --dlarg to pass arguments to dlfilters. The --dlarg option can
be repeated to pass more than 1 argument.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20210627131818.810-5-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/builtin-script.c')
-rw-r--r-- | tools/perf/builtin-script.c | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 4ffba1dbc55d..2030936cc891 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -81,6 +81,8 @@ static struct perf_stat_config stat_config; static int max_blocks; static bool native_arch; static struct dlfilter *dlfilter; +static int dlargc; +static char **dlargv; unsigned int scripting_max_stack = PERF_MAX_STACK_DEPTH; @@ -3175,6 +3177,34 @@ static int list_available_scripts(const struct option *opt __maybe_unused, exit(0); } +static int add_dlarg(const struct option *opt __maybe_unused, + const char *s, int unset __maybe_unused) +{ + char *arg = strdup(s); + void *a; + + if (!arg) + return -1; + + a = realloc(dlargv, sizeof(dlargv[0]) * (dlargc + 1)); + if (!a) { + free(arg); + return -1; + } + + dlargv = a; + dlargv[dlargc++] = arg; + + return 0; +} + +static void free_dlarg(void) +{ + while (dlargc--) + free(dlargv[dlargc]); + free(dlargv); +} + /* * Some scripts specify the required events in their "xxx-record" file, * this function will check if the events in perf.data match those @@ -3639,6 +3669,8 @@ int cmd_script(int argc, const char **argv) OPT_STRING('g', "gen-script", &generate_script_lang, "lang", "generate perf-script.xx script in specified language"), OPT_STRING(0, "dlfilter", &dlfilter_file, "file", "filter .so file name"), + OPT_CALLBACK(0, "dlarg", NULL, "argument", "filter argument", + add_dlarg), OPT_STRING('i', "input", &input_name, "file", "input file name"), OPT_BOOLEAN('d', "debug-mode", &debug_mode, "do various checks like samples ordering and lost events"), @@ -3958,7 +3990,7 @@ script_found: } if (dlfilter_file) { - dlfilter = dlfilter__new(dlfilter_file); + dlfilter = dlfilter__new(dlfilter_file, dlargc, dlargv); if (!dlfilter) return -1; } @@ -4116,6 +4148,7 @@ out_delete: if (script_started) cleanup_scripting(); dlfilter__cleanup(dlfilter); + free_dlarg(); out: return err; } |