public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf tool: save cmdline from user in file header vs what is passed to record
@ 2012-07-03  4:08 David Ahern
  2012-07-05 15:48 ` Stephane Eranian
  0 siblings, 1 reply; 7+ messages in thread
From: David Ahern @ 2012-07-03  4:08 UTC (permalink / raw)
  To: linux-kernel
  Cc: David Ahern, Arnaldo Carvalho de Melo, Ingo Molnar, Jiri Olsa,
	Namhyung Kim, Stephane Eranian, Frederic Weisbecker,
	Peter Zijlstra

A number of builtin commands process some user args and then pass the rest
to cmd_record. cmd_record then saves argc/argv that it receives into the
header of the perf data file. But this loses the arguments handled by the
first command -- ie., the real command line from the user. This patch saves
the command line as typed by the user rather than what was passed to
cmd_record.

As an example consider the command:
$ perf kvm --guest --host --guestmount=/tmp/guest-mount record
    -fo /tmp/perf.data -ag -- sleep 10

Currently the command saved to the header is:
 cmdline : /tmp/p3.5/perf record -o perf.data.kvm -fo /tmp/perf.data -ag -- sleep 1

(ignore the duplicated -o -- the first would be yet another bug with perf-kvm).

With this patch the command line saved to the header is:
 cmdline : /tmp/p3.5/perf kvm --guest --host --guestmount=/tmp/guest-mount
           record -fo /tmp/perf.data -ag -- sleep 1

Signed-off-by: David Ahern <dsahern@gmail.com>
CC: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
---
 tools/perf/builtin-kmem.c      |    2 ++
 tools/perf/builtin-kvm.c       |    2 ++
 tools/perf/builtin-lock.c      |    2 ++
 tools/perf/builtin-sched.c     |    2 ++
 tools/perf/builtin-script.c    |    2 ++
 tools/perf/builtin-timechart.c |    2 ++
 tools/perf/util/header.c       |    9 +++++++++
 7 files changed, 21 insertions(+)

diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index ce35015..08c8f74 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -770,6 +770,8 @@ static int __cmd_record(int argc, const char **argv)
 
 int cmd_kmem(int argc, const char **argv, const char *prefix __used)
 {
+	perf_header__set_cmdline(argc, argv);
+
 	argc = parse_options(argc, argv, kmem_options, kmem_usage, 0);
 
 	if (!argc)
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 9fc6e0f..913d0a8 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -107,6 +107,8 @@ int cmd_kvm(int argc, const char **argv, const char *prefix __used)
 	perf_host  = 0;
 	perf_guest = 1;
 
+	perf_header__set_cmdline(argc, argv);
+
 	argc = parse_options(argc, argv, kvm_options, kvm_usage,
 			PARSE_OPT_STOP_AT_NON_OPTION);
 	if (!argc)
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index b3c4285..89917e1 100644
--- a/tools/perf/builtin-lock.c
+++ b/tools/perf/builtin-lock.c
@@ -980,6 +980,8 @@ int cmd_lock(int argc, const char **argv, const char *prefix __used)
 	for (i = 0; i < LOCKHASH_SIZE; i++)
 		INIT_LIST_HEAD(lockhash_table + i);
 
+	perf_header__set_cmdline(argc, argv);
+
 	argc = parse_options(argc, argv, lock_options, lock_usage,
 			     PARSE_OPT_STOP_AT_NON_OPTION);
 	if (!argc)
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 7a9ad2b..25113b2 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -1899,6 +1899,8 @@ static int __cmd_record(int argc, const char **argv)
 
 int cmd_sched(int argc, const char **argv, const char *prefix __used)
 {
+	perf_header__set_cmdline(argc, argv);
+
 	argc = parse_options(argc, argv, sched_options, sched_usage,
 			     PARSE_OPT_STOP_AT_NON_OPTION);
 	if (!argc)
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 1e60ab7..07bc60b 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1206,6 +1206,8 @@ int cmd_script(int argc, const char **argv, const char *prefix __used)
 
 	setup_scripting();
 
+	perf_header__set_cmdline(argc, argv);
+
 	argc = parse_options(argc, argv, options, script_usage,
 			     PARSE_OPT_STOP_AT_NON_OPTION);
 
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index 3b75b2e..1e776a6 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -1108,6 +1108,8 @@ static const struct option options[] = {
 
 int cmd_timechart(int argc, const char **argv, const char *prefix __used)
 {
+	perf_header__set_cmdline(argc, argv);
+
 	argc = parse_options(argc, argv, options, timechart_usage,
 			PARSE_OPT_STOP_AT_NON_OPTION);
 
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 5a47aba..99e410c 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -174,6 +174,15 @@ perf_header__set_cmdline(int argc, const char **argv)
 {
 	int i;
 
+	/* 
+	 * If header_argv has already been set, do not override it.
+	 * This allows a command to set the cmdline, parse args and
+	 * then call another builtin function that implements a
+	 * command -- e.g, cmd_kvm calling cmd_record.
+	 */
+	if (header_argv)
+		return 0;
+
 	header_argc = (u32)argc;
 
 	/* do not include NULL termination */
-- 
1.7.10.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] perf tool: save cmdline from user in file header vs what is passed to record
  2012-07-03  4:08 [PATCH] perf tool: save cmdline from user in file header vs what is passed to record David Ahern
@ 2012-07-05 15:48 ` Stephane Eranian
  2012-07-05 16:47   ` David Ahern
  0 siblings, 1 reply; 7+ messages in thread
From: Stephane Eranian @ 2012-07-05 15:48 UTC (permalink / raw)
  To: David Ahern
  Cc: linux-kernel, Arnaldo Carvalho de Melo, Ingo Molnar, Jiri Olsa,
	Namhyung Kim, Frederic Weisbecker, Peter Zijlstra

On Tue, Jul 3, 2012 at 6:08 AM, David Ahern <dsahern@gmail.com> wrote:
> A number of builtin commands process some user args and then pass the rest
> to cmd_record. cmd_record then saves argc/argv that it receives into the
> header of the perf data file. But this loses the arguments handled by the
> first command -- ie., the real command line from the user. This patch saves
> the command line as typed by the user rather than what was passed to
> cmd_record.
>
> As an example consider the command:
> $ perf kvm --guest --host --guestmount=/tmp/guest-mount record
>     -fo /tmp/perf.data -ag -- sleep 10
>
> Currently the command saved to the header is:
>  cmdline : /tmp/p3.5/perf record -o perf.data.kvm -fo /tmp/perf.data -ag -- sleep 1
>
> (ignore the duplicated -o -- the first would be yet another bug with perf-kvm).
>
> With this patch the command line saved to the header is:
>  cmdline : /tmp/p3.5/perf kvm --guest --host --guestmount=/tmp/guest-mount
>            record -fo /tmp/perf.data -ag -- sleep 1
>
Yes, you need to manually add the pfm_header__set_cmdline(). That begs
the question
as to whether or not it would not be better to move this call directly into
the parse_option() function given that it must be done BEFORE parsing actually
takes place.That way we would be sure all present and future commands would
be covered.


> Signed-off-by: David Ahern <dsahern@gmail.com>
> CC: Arnaldo Carvalho de Melo <acme@redhat.com>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Jiri Olsa <jolsa@redhat.com>
> Cc: Namhyung Kim <namhyung@gmail.com>
> Cc: Stephane Eranian <eranian@google.com>
> Cc: Frederic Weisbecker <fweisbec@gmail.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> ---
>  tools/perf/builtin-kmem.c      |    2 ++
>  tools/perf/builtin-kvm.c       |    2 ++
>  tools/perf/builtin-lock.c      |    2 ++
>  tools/perf/builtin-sched.c     |    2 ++
>  tools/perf/builtin-script.c    |    2 ++
>  tools/perf/builtin-timechart.c |    2 ++
>  tools/perf/util/header.c       |    9 +++++++++
>  7 files changed, 21 insertions(+)
>
> diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
> index ce35015..08c8f74 100644
> --- a/tools/perf/builtin-kmem.c
> +++ b/tools/perf/builtin-kmem.c
> @@ -770,6 +770,8 @@ static int __cmd_record(int argc, const char **argv)
>
>  int cmd_kmem(int argc, const char **argv, const char *prefix __used)
>  {
> +       perf_header__set_cmdline(argc, argv);
> +
>         argc = parse_options(argc, argv, kmem_options, kmem_usage, 0);
>
>         if (!argc)
> diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
> index 9fc6e0f..913d0a8 100644
> --- a/tools/perf/builtin-kvm.c
> +++ b/tools/perf/builtin-kvm.c
> @@ -107,6 +107,8 @@ int cmd_kvm(int argc, const char **argv, const char *prefix __used)
>         perf_host  = 0;
>         perf_guest = 1;
>
> +       perf_header__set_cmdline(argc, argv);
> +
>         argc = parse_options(argc, argv, kvm_options, kvm_usage,
>                         PARSE_OPT_STOP_AT_NON_OPTION);
>         if (!argc)
> diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
> index b3c4285..89917e1 100644
> --- a/tools/perf/builtin-lock.c
> +++ b/tools/perf/builtin-lock.c
> @@ -980,6 +980,8 @@ int cmd_lock(int argc, const char **argv, const char *prefix __used)
>         for (i = 0; i < LOCKHASH_SIZE; i++)
>                 INIT_LIST_HEAD(lockhash_table + i);
>
> +       perf_header__set_cmdline(argc, argv);
> +
>         argc = parse_options(argc, argv, lock_options, lock_usage,
>                              PARSE_OPT_STOP_AT_NON_OPTION);
>         if (!argc)
> diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
> index 7a9ad2b..25113b2 100644
> --- a/tools/perf/builtin-sched.c
> +++ b/tools/perf/builtin-sched.c
> @@ -1899,6 +1899,8 @@ static int __cmd_record(int argc, const char **argv)
>
>  int cmd_sched(int argc, const char **argv, const char *prefix __used)
>  {
> +       perf_header__set_cmdline(argc, argv);
> +
>         argc = parse_options(argc, argv, sched_options, sched_usage,
>                              PARSE_OPT_STOP_AT_NON_OPTION);
>         if (!argc)
> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
> index 1e60ab7..07bc60b 100644
> --- a/tools/perf/builtin-script.c
> +++ b/tools/perf/builtin-script.c
> @@ -1206,6 +1206,8 @@ int cmd_script(int argc, const char **argv, const char *prefix __used)
>
>         setup_scripting();
>
> +       perf_header__set_cmdline(argc, argv);
> +
>         argc = parse_options(argc, argv, options, script_usage,
>                              PARSE_OPT_STOP_AT_NON_OPTION);
>
> diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
> index 3b75b2e..1e776a6 100644
> --- a/tools/perf/builtin-timechart.c
> +++ b/tools/perf/builtin-timechart.c
> @@ -1108,6 +1108,8 @@ static const struct option options[] = {
>
>  int cmd_timechart(int argc, const char **argv, const char *prefix __used)
>  {
> +       perf_header__set_cmdline(argc, argv);
> +
>         argc = parse_options(argc, argv, options, timechart_usage,
>                         PARSE_OPT_STOP_AT_NON_OPTION);
>
> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> index 5a47aba..99e410c 100644
> --- a/tools/perf/util/header.c
> +++ b/tools/perf/util/header.c
> @@ -174,6 +174,15 @@ perf_header__set_cmdline(int argc, const char **argv)
>  {
>         int i;
>
> +       /*
> +        * If header_argv has already been set, do not override it.
> +        * This allows a command to set the cmdline, parse args and
> +        * then call another builtin function that implements a
> +        * command -- e.g, cmd_kvm calling cmd_record.
> +        */
> +       if (header_argv)
> +               return 0;
> +
>         header_argc = (u32)argc;
>
>         /* do not include NULL termination */
> --
> 1.7.10.1
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] perf tool: save cmdline from user in file header vs what is passed to record
  2012-07-05 15:48 ` Stephane Eranian
@ 2012-07-05 16:47   ` David Ahern
  0 siblings, 0 replies; 7+ messages in thread
From: David Ahern @ 2012-07-05 16:47 UTC (permalink / raw)
  To: Stephane Eranian
  Cc: linux-kernel, Arnaldo Carvalho de Melo, Ingo Molnar, Jiri Olsa,
	Namhyung Kim, Frederic Weisbecker, Peter Zijlstra

On 7/5/12 9:48 AM, Stephane Eranian wrote:
> On Tue, Jul 3, 2012 at 6:08 AM, David Ahern <dsahern@gmail.com> wrote:
> Yes, you need to manually add the pfm_header__set_cmdline(). That begs

I take it you meant perf_header__set_cmdline, not pfm_header...

> the question
> as to whether or not it would not be better to move this call directly into
> the parse_option() function given that it must be done BEFORE parsing actually
> takes place.That way we would be sure all present and future commands would
> be covered.

Sure, I'll move it to parse_options.

David

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] perf tool: save cmdline from user in file header vs what is passed to record
@ 2012-07-06  4:09 David Ahern
  2012-07-06 17:17 ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 7+ messages in thread
From: David Ahern @ 2012-07-06  4:09 UTC (permalink / raw)
  To: linux-kernel
  Cc: David Ahern, Arnaldo Carvalho de Melo, Ingo Molnar, Jiri Olsa,
	Namhyung Kim, Stephane Eranian, Frederic Weisbecker,
	Peter Zijlstra

A number of builtin commands process some user args and then pass the rest
to cmd_record. cmd_record then saves argc/argv that it receives into the
header of the perf data file. But this loses the arguments handled by the
first command -- ie., the real command line from the user. This patch saves
the command line as typed by the user rather than what was passed to
cmd_record.

As an example consider the command:
$ perf kvm --guest --host --guestmount=/tmp/guest-mount record
    -fo /tmp/perf.data -ag -- sleep 10

Currently the command saved to the header is:
cmdline : /tmp/p3.5/perf record -o perf.data.kvm -fo /tmp/perf.data -ag -- sleep 1

(ignore the duplicated -o -- the first would be yet another bug with perf-kvm).

With this patch the command line saved to the header is:
cmdline : /tmp/p3.5/perf kvm --guest --host --guestmount=/tmp/guest-mount
    record -fo /tmp/perf.data -ag -- sleep 1

v2: simplified to saving the command in parse_options per Stephane's suggestion

Signed-off-by: David Ahern <dsahern@gmail.com>
CC: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
---
 tools/perf/builtin-record.c     |    2 --
 tools/perf/util/header.c        |    9 +++++++++
 tools/perf/util/parse-options.c |    3 +++
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index f5a6452..77adcd8 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -844,8 +844,6 @@ int cmd_record(int argc, const char **argv, const char *prefix __used)
 	struct perf_record *rec = &record;
 	char errbuf[BUFSIZ];
 
-	perf_header__set_cmdline(argc, argv);
-
 	evsel_list = perf_evlist__new(NULL, NULL);
 	if (evsel_list == NULL)
 		return -ENOMEM;
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 5a47aba..99e410c 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -174,6 +174,15 @@ perf_header__set_cmdline(int argc, const char **argv)
 {
 	int i;
 
+	/* 
+	 * If header_argv has already been set, do not override it.
+	 * This allows a command to set the cmdline, parse args and
+	 * then call another builtin function that implements a
+	 * command -- e.g, cmd_kvm calling cmd_record.
+	 */
+	if (header_argv)
+		return 0;
+
 	header_argc = (u32)argc;
 
 	/* do not include NULL termination */
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c
index 99d02aa..594f8fa 100644
--- a/tools/perf/util/parse-options.c
+++ b/tools/perf/util/parse-options.c
@@ -1,6 +1,7 @@
 #include "util.h"
 #include "parse-options.h"
 #include "cache.h"
+#include "header.h"
 
 #define OPT_SHORT 1
 #define OPT_UNSET 2
@@ -413,6 +414,8 @@ int parse_options(int argc, const char **argv, const struct option *options,
 {
 	struct parse_opt_ctx_t ctx;
 
+	perf_header__set_cmdline(argc, argv);
+
 	parse_options_start(&ctx, argc, argv, flags);
 	switch (parse_options_step(&ctx, options, usagestr)) {
 	case PARSE_OPT_HELP:
-- 
1.7.10.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] perf tool: save cmdline from user in file header vs what is passed to record
  2012-07-06  4:09 David Ahern
@ 2012-07-06 17:17 ` Arnaldo Carvalho de Melo
  2012-07-06 17:19   ` David Ahern
  0 siblings, 1 reply; 7+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-07-06 17:17 UTC (permalink / raw)
  To: David Ahern
  Cc: linux-kernel, Ingo Molnar, Jiri Olsa, Namhyung Kim,
	Stephane Eranian, Frederic Weisbecker, Peter Zijlstra

Em Thu, Jul 05, 2012 at 10:09:22PM -0600, David Ahern escreveu:
> A number of builtin commands process some user args and then pass the rest
> to cmd_record. cmd_record then saves argc/argv that it receives into the
> header of the perf data file. But this loses the arguments handled by the
> first command -- ie., the real command line from the user. This patch saves
> the command line as typed by the user rather than what was passed to
> cmd_record.

Can you please state for what branch, perf/urgent (i.e. current merge
window) or perf/core (next), this is intended? I usually have been
making the call, but having feedback from the submitter can help things
and help meet expectations more frequently.

I'd say this one should be for perf/core, as it is not so critical, what
do you think?

- Arnaldo
 
> As an example consider the command:
> $ perf kvm --guest --host --guestmount=/tmp/guest-mount record
>     -fo /tmp/perf.data -ag -- sleep 10
> 
> Currently the command saved to the header is:
> cmdline : /tmp/p3.5/perf record -o perf.data.kvm -fo /tmp/perf.data -ag -- sleep 1
> 
> (ignore the duplicated -o -- the first would be yet another bug with perf-kvm).
> 
> With this patch the command line saved to the header is:
> cmdline : /tmp/p3.5/perf kvm --guest --host --guestmount=/tmp/guest-mount
>     record -fo /tmp/perf.data -ag -- sleep 1
> 
> v2: simplified to saving the command in parse_options per Stephane's suggestion
> 
> Signed-off-by: David Ahern <dsahern@gmail.com>
> CC: Arnaldo Carvalho de Melo <acme@redhat.com>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Jiri Olsa <jolsa@redhat.com>
> Cc: Namhyung Kim <namhyung@gmail.com>
> Cc: Stephane Eranian <eranian@google.com>
> Cc: Frederic Weisbecker <fweisbec@gmail.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> ---
>  tools/perf/builtin-record.c     |    2 --
>  tools/perf/util/header.c        |    9 +++++++++
>  tools/perf/util/parse-options.c |    3 +++
>  3 files changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
> index f5a6452..77adcd8 100644
> --- a/tools/perf/builtin-record.c
> +++ b/tools/perf/builtin-record.c
> @@ -844,8 +844,6 @@ int cmd_record(int argc, const char **argv, const char *prefix __used)
>  	struct perf_record *rec = &record;
>  	char errbuf[BUFSIZ];
>  
> -	perf_header__set_cmdline(argc, argv);
> -
>  	evsel_list = perf_evlist__new(NULL, NULL);
>  	if (evsel_list == NULL)
>  		return -ENOMEM;
> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> index 5a47aba..99e410c 100644
> --- a/tools/perf/util/header.c
> +++ b/tools/perf/util/header.c
> @@ -174,6 +174,15 @@ perf_header__set_cmdline(int argc, const char **argv)
>  {
>  	int i;
>  
> +	/* 
> +	 * If header_argv has already been set, do not override it.
> +	 * This allows a command to set the cmdline, parse args and
> +	 * then call another builtin function that implements a
> +	 * command -- e.g, cmd_kvm calling cmd_record.
> +	 */
> +	if (header_argv)
> +		return 0;
> +
>  	header_argc = (u32)argc;
>  
>  	/* do not include NULL termination */
> diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c
> index 99d02aa..594f8fa 100644
> --- a/tools/perf/util/parse-options.c
> +++ b/tools/perf/util/parse-options.c
> @@ -1,6 +1,7 @@
>  #include "util.h"
>  #include "parse-options.h"
>  #include "cache.h"
> +#include "header.h"
>  
>  #define OPT_SHORT 1
>  #define OPT_UNSET 2
> @@ -413,6 +414,8 @@ int parse_options(int argc, const char **argv, const struct option *options,
>  {
>  	struct parse_opt_ctx_t ctx;
>  
> +	perf_header__set_cmdline(argc, argv);
> +
>  	parse_options_start(&ctx, argc, argv, flags);
>  	switch (parse_options_step(&ctx, options, usagestr)) {
>  	case PARSE_OPT_HELP:
> -- 
> 1.7.10.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] perf tool: save cmdline from user in file header vs what is passed to record
  2012-07-06 17:17 ` Arnaldo Carvalho de Melo
@ 2012-07-06 17:19   ` David Ahern
  0 siblings, 0 replies; 7+ messages in thread
From: David Ahern @ 2012-07-06 17:19 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: linux-kernel, Ingo Molnar, Jiri Olsa, Namhyung Kim,
	Stephane Eranian, Frederic Weisbecker, Peter Zijlstra

On 7/6/12 11:17 AM, Arnaldo Carvalho de Melo wrote:
> Can you please state for what branch, perf/urgent (i.e. current merge
> window) or perf/core (next), this is intended? I usually have been
> making the call, but having feedback from the submitter can help things
> and help meet expectations more frequently.
>
> I'd say this one should be for perf/core, as it is not so critical, what
> do you think?

right, need to add that tag. It's not a regression, just an oversight on 
the original implementation. perf/core is the right branch.

David



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] perf tool: save cmdline from user in file header vs what is passed to record
@ 2012-07-30  2:53 David Ahern
  0 siblings, 0 replies; 7+ messages in thread
From: David Ahern @ 2012-07-30  2:53 UTC (permalink / raw)
  To: acme, linux-kernel
  Cc: David Ahern, Arnaldo Carvalho de Melo, Ingo Molnar, Jiri Olsa,
	Namhyung Kim, Stephane Eranian, Frederic Weisbecker,
	Peter Zijlstra

A number of builtin commands process some user args and then pass the rest to
cmd_record. cmd_record then saves argc/argv that it receives into the header of
the perf data file. But this loses the arguments handled by the first command
-- ie., the real command line from the user. This patch saves the command line
as typed by the user rather than what was passed to cmd_record.

As an example consider the command:
$ perf kvm --guest --host --guestmount=/tmp/guest-mount record
    -fo /tmp/perf.data -ag -- sleep 10

Currently the command saved to the header is:
    cmdline : /tmp/p3.5/perf record -o perf.data.kvm -fo /tmp/perf.data -ag -- sleep 1

(ignore the duplicated -o -- the first would be yet another bug with perf-kvm).

With this patch the command line saved to the header is:
cmdline : /tmp/p3.5/perf kvm --guest --host --guestmount=/tmp/guest-mount
    record -fo /tmp/perf.data -ag -- sleep 1

v2: simplified to saving the command in parse_options per Stephane's suggestion

Signed-off-by: David Ahern <dsahern@gmail.com>
CC: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
---
 tools/perf/builtin-record.c     |    2 --
 tools/perf/util/header.c        |    9 +++++++++
 tools/perf/util/parse-options.c |    3 +++
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index f5a6452..77adcd8 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -844,8 +844,6 @@ int cmd_record(int argc, const char **argv, const char *prefix __used)
 	struct perf_record *rec = &record;
 	char errbuf[BUFSIZ];
 
-	perf_header__set_cmdline(argc, argv);
-
 	evsel_list = perf_evlist__new(NULL, NULL);
 	if (evsel_list == NULL)
 		return -ENOMEM;
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 3a6d204..74ea3c2 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -174,6 +174,15 @@ perf_header__set_cmdline(int argc, const char **argv)
 {
 	int i;
 
+	/*
+	 * If header_argv has already been set, do not override it.
+	 * This allows a command to set the cmdline, parse args and
+	 * then call another builtin function that implements a
+	 * command -- e.g, cmd_kvm calling cmd_record.
+	 */
+	if (header_argv)
+		return 0;
+
 	header_argc = (u32)argc;
 
 	/* do not include NULL termination */
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c
index 99d02aa..594f8fa 100644
--- a/tools/perf/util/parse-options.c
+++ b/tools/perf/util/parse-options.c
@@ -1,6 +1,7 @@
 #include "util.h"
 #include "parse-options.h"
 #include "cache.h"
+#include "header.h"
 
 #define OPT_SHORT 1
 #define OPT_UNSET 2
@@ -413,6 +414,8 @@ int parse_options(int argc, const char **argv, const struct option *options,
 {
 	struct parse_opt_ctx_t ctx;
 
+	perf_header__set_cmdline(argc, argv);
+
 	parse_options_start(&ctx, argc, argv, flags);
 	switch (parse_options_step(&ctx, options, usagestr)) {
 	case PARSE_OPT_HELP:
-- 
1.7.10.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-07-30  2:54 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-03  4:08 [PATCH] perf tool: save cmdline from user in file header vs what is passed to record David Ahern
2012-07-05 15:48 ` Stephane Eranian
2012-07-05 16:47   ` David Ahern
  -- strict thread matches above, loose matches on Subject: below --
2012-07-06  4:09 David Ahern
2012-07-06 17:17 ` Arnaldo Carvalho de Melo
2012-07-06 17:19   ` David Ahern
2012-07-30  2:53 David Ahern

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox