2017-09-11 11:14:28

by Milian Wolff

[permalink] [raw]
Subject: [PATCH] perf: support running perf binaries with a dash in their name

Previously the part behind "perf-" was interpreted as an internal
perf command. If the suffix could not be handled, the execution
was stopped. This makes it impossible to launch perf binaries that
got renamed to have the `perf-` prefix. This is e.g. the case for
appimages (e.g. "perf-x86_64.AppImage"), but would also apply to
all other scenarios where users symlink or rename perf themselves:

Status quo with the broken behavior:
~~~~~
$ ln -s ./perf ./perf-custom-suffix
$ ./perf-custom-suffix list
cannot handle custom-suffix internally$
~~~~~

Also note the missing newline at the end of the error message.
With this patch applied, the above works properly:

~~~~~
$ ./perf-custom-suffix list

List of pre-defined events (to be used in -e):
...
~~~~~

Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Yao Jin <[email protected]>
Signed-off-by: Milian Wolff <[email protected]>
---
tools/perf/perf.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index e0279babe0c0..7a3a39014446 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -467,15 +467,19 @@ int main(int argc, const char **argv)
* - cannot execute it externally (since it would just do
* the same thing over again)
*
- * So we just directly call the internal command handler, and
- * die if that one cannot handle it.
+ * So we just directly call the internal command handler. If that one
+ * fails to handle this, then maybe we just run a renamed perf binary
+ * that contains a dash in its name. To handle this scenario, we just
+ * fall through and ignore the "xxxx" part of the command string.
*/
if (strstarts(cmd, "perf-")) {
cmd += 5;
argv[0] = cmd;
handle_internal_command(argc, argv);
- fprintf(stderr, "cannot handle %s internally", cmd);
- goto out;
+ // if the command is handled, the above function does not return
+ // undo changes and fall through in such a case
+ cmd -= 5;
+ argv[0] = cmd;
}
if (strstarts(cmd, "trace")) {
#ifdef HAVE_LIBAUDIT_SUPPORT
--
2.14.1


2017-09-11 14:08:27

by David Ahern

[permalink] [raw]
Subject: Re: [PATCH] perf: support running perf binaries with a dash in their name

On 9/11/17 4:14 AM, Milian Wolff wrote:
> Previously the part behind "perf-" was interpreted as an internal
> perf command. If the suffix could not be handled, the execution
> was stopped. This makes it impossible to launch perf binaries that
> got renamed to have the `perf-` prefix. This is e.g. the case for
> appimages (e.g. "perf-x86_64.AppImage"), but would also apply to
> all other scenarios where users symlink or rename perf themselves:
>
...
> ~~~~~
> $ ./perf-custom-suffix list
>
> List of pre-defined events (to be used in -e):
> ...
> ~~~~~
>
> Cc: Arnaldo Carvalho de Melo <[email protected]>
> Cc: David Ahern <[email protected]>
> Cc: Namhyung Kim <[email protected]>
> Cc: Peter Zijlstra <[email protected]>
> Cc: Yao Jin <[email protected]>
> Signed-off-by: Milian Wolff <[email protected]>
> ---
> tools/perf/perf.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/tools/perf/perf.c b/tools/perf/perf.c
> index e0279babe0c0..7a3a39014446 100644
> --- a/tools/perf/perf.c
> +++ b/tools/perf/perf.c
> @@ -467,15 +467,19 @@ int main(int argc, const char **argv)
> * - cannot execute it externally (since it would just do
> * the same thing over again)
> *
> - * So we just directly call the internal command handler, and
> - * die if that one cannot handle it.
> + * So we just directly call the internal command handler. If that one
> + * fails to handle this, then maybe we just run a renamed perf binary
> + * that contains a dash in its name. To handle this scenario, we just
> + * fall through and ignore the "xxxx" part of the command string.
> */
> if (strstarts(cmd, "perf-")) {
> cmd += 5;
> argv[0] = cmd;
> handle_internal_command(argc, argv);
> - fprintf(stderr, "cannot handle %s internally", cmd);
> - goto out;
> + // if the command is handled, the above function does not return
> + // undo changes and fall through in such a case

Those should be /* */ not //

> + cmd -= 5;
> + argv[0] = cmd;
> }
> if (strstarts(cmd, "trace")) {
> #ifdef HAVE_LIBAUDIT_SUPPORT
>

other than that LGTM and long over due.

Acked-by: David Ahern <[email protected]>

2017-09-11 14:33:17

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH] perf: support running perf binaries with a dash in their name

Em Mon, Sep 11, 2017 at 07:08:18AM -0700, David Ahern escreveu:
> On 9/11/17 4:14 AM, Milian Wolff wrote:
> > Previously the part behind "perf-" was interpreted as an internal
> > perf command. If the suffix could not be handled, the execution
<SNIP>
> > --- a/tools/perf/perf.c
> > - fprintf(stderr, "cannot handle %s internally", cmd);
> > - goto out;
> > + // if the command is handled, the above function does not return
> > + // undo changes and fall through in such a case

> Those should be /* */ not //
>
> > + cmd -= 5;
> > + argv[0] = cmd;
> > }
> > if (strstarts(cmd, "trace")) {
> > #ifdef HAVE_LIBAUDIT_SUPPORT

> other than that LGTM and long over due.

> Acked-by: David Ahern <[email protected]>

We got those from git, agreed it should go, thanks for the Acked-by,
always welcome!

- Arnaldo

2017-09-11 15:16:16

by Milian Wolff

[permalink] [raw]
Subject: Re: [PATCH] perf: support running perf binaries with a dash in their name

On Monday, September 11, 2017 4:33:12 PM CEST Arnaldo Carvalho de Melo wrote:
> Em Mon, Sep 11, 2017 at 07:08:18AM -0700, David Ahern escreveu:
> > On 9/11/17 4:14 AM, Milian Wolff wrote:
> > > Previously the part behind "perf-" was interpreted as an internal
> > > perf command. If the suffix could not be handled, the execution
>
> <SNIP>
>
> > > --- a/tools/perf/perf.c
> > > - fprintf(stderr, "cannot handle %s internally", cmd);
> > > - goto out;
> > > + // if the command is handled, the above function does not return
> > > + // undo changes and fall through in such a case
> >
> > Those should be /* */ not //
> >
> > > + cmd -= 5;
> > > + argv[0] = cmd;
> > >
> > > }
> > > if (strstarts(cmd, "trace")) {
> > >
> > > #ifdef HAVE_LIBAUDIT_SUPPORT
> >
> > other than that LGTM and long over due.
> >
> > Acked-by: David Ahern <[email protected]>
>
> We got those from git, agreed it should go, thanks for the Acked-by,
> always welcome!

Arnaldo, do you want me to fixup the commit, or can you handle it?

Thanks for the review guys

--
Milian Wolff | [email protected] | Senior Software Engineer
KDAB (Deutschland) GmbH&Co KG, a KDAB Group company
Tel: +49-30-521325470
KDAB - The Qt Experts


Attachments:
smime.p7s (3.74 kB)

2017-09-11 15:38:52

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH] perf: support running perf binaries with a dash in their name

Em Mon, Sep 11, 2017 at 05:16:11PM +0200, Milian Wolff escreveu:
> On Monday, September 11, 2017 4:33:12 PM CEST Arnaldo Carvalho de Melo wrote:
> > Em Mon, Sep 11, 2017 at 07:08:18AM -0700, David Ahern escreveu:
> > > other than that LGTM and long over due.

> > > Acked-by: David Ahern <[email protected]>

> > We got those from git, agreed it should go, thanks for the Acked-by,
> > always welcome!

> Arnaldo, do you want me to fixup the commit, or can you handle it?

> Thanks for the review guys

I did it already, thanks.

- Arnaldo

Subject: [tip:perf/urgent] perf tools: Support running perf binaries with a dash in their name

Commit-ID: 3192f1ed3dd3a6883d5ae31bf2ff69984ea0fd54
Gitweb: http://git.kernel.org/tip/3192f1ed3dd3a6883d5ae31bf2ff69984ea0fd54
Author: Milian Wolff <[email protected]>
AuthorDate: Mon, 11 Sep 2017 13:14:22 +0200
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 12 Sep 2017 12:48:54 -0300

perf tools: Support running perf binaries with a dash in their name

Previously the part behind "perf-" was interpreted as an internal perf
command. If the suffix could not be handled, the execution was stopped.
This makes it impossible to launch perf binaries that got renamed to
have the `perf-` prefix. This is e.g. the case for appimages (e.g.
"perf-x86_64.AppImage"), but would also apply to all other scenarios
where users symlink or rename perf themselves:

Status quo with the broken behavior:

$ ln -s ./perf ./perf-custom-suffix
$ ./perf-custom-suffix list
cannot handle custom-suffix internally$

Also note the missing newline at the end of the error message.

With this patch applied, the above works properly:

$ ./perf-custom-suffix list

List of pre-defined events (to be used in -e):
...

Signed-off-by: Milian Wolff <[email protected]>
Acked-by: David Ahern <[email protected]>
Tested-by: Arnaldo Carvalho de Melo <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Yao Jin <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/perf.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index e0279ba..2f19e03 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -467,15 +467,21 @@ int main(int argc, const char **argv)
* - cannot execute it externally (since it would just do
* the same thing over again)
*
- * So we just directly call the internal command handler, and
- * die if that one cannot handle it.
+ * So we just directly call the internal command handler. If that one
+ * fails to handle this, then maybe we just run a renamed perf binary
+ * that contains a dash in its name. To handle this scenario, we just
+ * fall through and ignore the "xxxx" part of the command string.
*/
if (strstarts(cmd, "perf-")) {
cmd += 5;
argv[0] = cmd;
handle_internal_command(argc, argv);
- fprintf(stderr, "cannot handle %s internally", cmd);
- goto out;
+ /*
+ * If the command is handled, the above function does not
+ * return undo changes and fall through in such a case.
+ */
+ cmd -= 5;
+ argv[0] = cmd;
}
if (strstarts(cmd, "trace")) {
#ifdef HAVE_LIBAUDIT_SUPPORT