Re: [PATCH] perf trace: get rid of the hard-coded paths in the report scripts

From: Stephane Eranian
Date: Thu Aug 12 2010 - 17:29:10 EST


On Thu, Aug 12, 2010 at 7:59 PM, Tom Zanussi <tzanussi@xxxxxxxxx> wrote:
> The perf trace report shell scripts hard-code the exec path of the
> scripts into their command-lines, which doesn't work if perf has been
> installed somewhere else.
>
> Instead, perf trace should create the paths at run-time. ÂThis patch
> does that and removes the hard-coded paths from all the report scripts.
>
> v2 changes: The first version inadvertantly caused scripts run from
> outside the perf exec path to fail e.g. 'perf trace -s test.py'. ÂThe
> fix is to try the script name without the exec path first, then the
> version using the exec path, which restores the expected behavior.
>
> Reported-by: Stephane Eranian <eranian@xxxxxxxxxx>
> Signed-off-by: Tom Zanussi <tzanussi@xxxxxxxxx>
> ---
> Âtools/perf/builtin-trace.c             |  22 ++++++++++++++++---
> Âtools/perf/scripts/perl/bin/failed-syscalls-report | Â Â2 +-
> Âtools/perf/scripts/perl/bin/rw-by-file-report   Â|  Â2 +-
> Âtools/perf/scripts/perl/bin/rw-by-pid-report    |  Â2 +-
> Âtools/perf/scripts/perl/bin/rwtop-report      |  Â2 +-
> Âtools/perf/scripts/perl/bin/wakeup-latency-report Â| Â Â2 +-
> Âtools/perf/scripts/perl/bin/workqueue-stats-report | Â Â2 +-
> Â.../python/bin/failed-syscalls-by-pid-report    |  Â2 +-
> Â.../perf/scripts/python/bin/sched-migration-report | Â Â2 +-
> Âtools/perf/scripts/python/bin/sctop-report     |  Â2 +-
> Â.../python/bin/syscall-counts-by-pid-report    Â|  Â2 +-
> Â.../perf/scripts/python/bin/syscall-counts-report Â| Â Â3 +-
> Â12 files changed, 30 insertions(+), 15 deletions(-)
>
> diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
> index 40a6a29..88a1883 100644
> --- a/tools/perf/builtin-trace.c
> +++ b/tools/perf/builtin-trace.c
> @@ -573,6 +573,7 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used)
> Â Â Â Âconst char *suffix = NULL;
> Â Â Â Âconst char **__argv;
> Â Â Â Âchar *script_path;
> + Â Â Â struct stat perf_stat;
> Â Â Â Âint i, err;
>
> Â Â Â Âif (argc >= 2 && strncmp(argv[1], "rec", strlen("rec")) == 0) {
> @@ -689,8 +690,6 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used)
> Â Â Â Â Â Â Â Âreturn -EINVAL;
>
> Â Â Â Âif (generate_script_lang) {
> - Â Â Â Â Â Â Â struct stat perf_stat;
> -
> Â Â Â Â Â Â Â Âint input = open(input_name, O_RDONLY);
> Â Â Â Â Â Â Â Âif (input < 0) {
> Â Â Â Â Â Â Â Â Â Â Â Âperror("failed to open file");
> @@ -719,10 +718,25 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used)
> Â Â Â Â}
>
> Â Â Â Âif (script_name) {
> - Â Â Â Â Â Â Â err = scripting_ops->start_script(script_name, argc, argv);
> + Â Â Â Â Â Â Â char script_exec_path[MAXPATHLEN];
> +
> + Â Â Â Â Â Â Â snprintf(script_exec_path, MAXPATHLEN, "%s", script_name);
> + Â Â Â Â Â Â Â err = stat(script_exec_path, &perf_stat);

Why not simply use access() instead of stat() here?

> + Â Â Â Â Â Â Â if (err < 0) {
> + Â Â Â Â Â Â Â Â Â Â Â snprintf(script_exec_path, MAXPATHLEN, "%s/scripts/%s",
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âperf_exec_path(), script_name);
> + Â Â Â Â Â Â Â Â Â Â Â err = stat(script_exec_path, &perf_stat);
And here?
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/