提交 3c17e7f0 编写于 作者: L Li Huafei 提交者: Zheng Zengkai

perf kmem: Do not pass additional arguments to 'perf record'

hulk inclusion
category: bugfix
bugzilla: 51797
CVE: NA

--------------------------------

The commit be8299e4 passes additional arguments directly to the
'perf record' to support the '-o' option. If used in the current
format of the'perf kmem --help' command, there is no problem. But
we're used to using this: 'perf kmem record --slab --page', where the
subcommand is placed before the option. After the commit be8299e4,
there is a problem with this use:

  # perf kmem record --slab --page
   Error: unknown option `slab'

  Usage: perf record [<options>] [<command>]
     or: perf record [<options>] -- <command> [<options>]

     -a, --all-cpus        system-wide collection from all CPUs
     -b, --branch-any      sample any taken branches
     -B, --no-buildid      do not collect buildids in perf.data
     -c, --count <n>       event period to sample
     -C, --cpu <cpu>       list of cpus to monitor
     -d, --data            Record the sample addresses
     ...

This is because we pass all the options directly to 'perf record', but
these options are 'perf kmem' options. In order to be able to use the
format 'perf kmem {record|stat} [option]', we revert the commit be8299e4.
In order to still support the '-o' option, we first process the '-o' option
in 'perf kmem' and then add it to the list of options in'perf record'.

Fixes: be8299e4("perf kmem: Pass additional arguments to 'perf record'")
Signed-off-by: NLi Huafei <lihuafei1@huawei.com>
Reviewed-by: NYang Jihong <yangjihong1@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 fbdb75a8
...@@ -82,6 +82,9 @@ static unsigned long nr_allocs, nr_cross_allocs; ...@@ -82,6 +82,9 @@ static unsigned long nr_allocs, nr_cross_allocs;
static struct perf_time_interval ptime; static struct perf_time_interval ptime;
const char *time_str; const char *time_str;
/* output file of 'perf kmem record' */
static const char *output_name;
static int insert_alloc_stat(unsigned long call_site, unsigned long ptr, static int insert_alloc_stat(unsigned long call_site, unsigned long ptr,
int bytes_req, int bytes_alloc, int cpu) int bytes_req, int bytes_alloc, int cpu)
{ {
...@@ -1848,6 +1851,8 @@ static int __cmd_record(int argc, const char **argv) ...@@ -1848,6 +1851,8 @@ static int __cmd_record(int argc, const char **argv)
rec_argc += ARRAY_SIZE(slab_events); rec_argc += ARRAY_SIZE(slab_events);
if (kmem_page) if (kmem_page)
rec_argc += ARRAY_SIZE(page_events) + 1; /* for -g */ rec_argc += ARRAY_SIZE(page_events) + 1; /* for -g */
if (output_name)
rec_argc += 2;
rec_argv = calloc(rec_argc + 1, sizeof(char *)); rec_argv = calloc(rec_argc + 1, sizeof(char *));
...@@ -1868,6 +1873,11 @@ static int __cmd_record(int argc, const char **argv) ...@@ -1868,6 +1873,11 @@ static int __cmd_record(int argc, const char **argv)
rec_argv[i] = strdup(page_events[j]); rec_argv[i] = strdup(page_events[j]);
} }
if (output_name) {
rec_argv[i++] = strdup("-o");
rec_argv[i++] = strdup(output_name);
}
for (j = 1; j < (unsigned int)argc; j++, i++) for (j = 1; j < (unsigned int)argc; j++, i++)
rec_argv[i] = argv[j]; rec_argv[i] = argv[j];
...@@ -1899,6 +1909,7 @@ int cmd_kmem(int argc, const char **argv) ...@@ -1899,6 +1909,7 @@ int cmd_kmem(int argc, const char **argv)
}; };
const struct option kmem_options[] = { const struct option kmem_options[] = {
OPT_STRING('i', "input", &input_name, "file", "input file name"), OPT_STRING('i', "input", &input_name, "file", "input file name"),
OPT_STRING('o', "output", &output_name, "file", "output file name"),
OPT_INCR('v', "verbose", &verbose, OPT_INCR('v', "verbose", &verbose,
"be more verbose (show symbol address, etc)"), "be more verbose (show symbol address, etc)"),
OPT_CALLBACK_NOOPT(0, "caller", NULL, NULL, OPT_CALLBACK_NOOPT(0, "caller", NULL, NULL,
...@@ -1933,8 +1944,7 @@ int cmd_kmem(int argc, const char **argv) ...@@ -1933,8 +1944,7 @@ int cmd_kmem(int argc, const char **argv)
return ret; return ret;
argc = parse_options_subcommand(argc, argv, kmem_options, argc = parse_options_subcommand(argc, argv, kmem_options,
kmem_subcommands, kmem_usage, kmem_subcommands, kmem_usage, 0);
PARSE_OPT_STOP_AT_NON_OPTION);
if (!argc) if (!argc)
usage_with_options(kmem_usage, kmem_options); usage_with_options(kmem_usage, kmem_options);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册