All of lore.kernel.org
 help / color / mirror / Atom feed
From: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
To: Chase Douglas <chase.douglas@canonical.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Paul Mackerras <paulus@samba.org>, Ingo Molnar <mingo@elte.hu>,
	Masami Hiramatsu <mhiramat@redhat.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [RESEND][PATCH v2] perf probe: add kernel source path option
Date: Tue, 15 Jun 2010 14:17:40 +0900	[thread overview]
Message-ID: <4C170CF4.2050908@hitachi.com> (raw)
In-Reply-To: <1276543590-10486-1-git-send-email-chase.douglas@canonical.com>

Chase Douglas wrote:
> The probe plugin requires access to the source code for some operations.
> The source code must be in the exact same location as specified by the
> DWARF tags, but sometimes the location is an absolute path that cannot
> be replicated by a normal user. This change adds the -s|--source option
> to allow the user to specify the root of the kernel source tree.

Thanks, it looks very good to me :) and works!

Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>

Thank you,

> 
> Signed-off-by: Chase Douglas <chase.douglas@canonical.com>
> ---
>  tools/perf/Documentation/perf-probe.txt |    4 ++
>  tools/perf/builtin-probe.c              |    2 +
>  tools/perf/util/probe-finder.c          |   58 +++++++++++++++++++++++++++++--
>  tools/perf/util/symbol.h                |    1 +
>  4 files changed, 62 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt
> index 94a258c..ea531d9 100644
> --- a/tools/perf/Documentation/perf-probe.txt
> +++ b/tools/perf/Documentation/perf-probe.txt
> @@ -31,6 +31,10 @@ OPTIONS
>  --vmlinux=PATH::
>  	Specify vmlinux path which has debuginfo (Dwarf binary).
>  
> +-s::
> +--source=PATH::
> +	Specify path to kernel source.
> +
>  -v::
>  --verbose::
>          Be more verbose (show parsed arguments, etc).
> diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
> index e4a4da3..5455186 100644
> --- a/tools/perf/builtin-probe.c
> +++ b/tools/perf/builtin-probe.c
> @@ -182,6 +182,8 @@ static const struct option options[] = {
>  		     "Show source code lines.", opt_show_lines),
>  	OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
>  		   "file", "vmlinux pathname"),
> +	OPT_STRING('s', "source", &symbol_conf.source_prefix,
> +		   "directory", "path to kernel source"),
>  #endif
>  	OPT__DRY_RUN(&probe_event_dry_run),
>  	OPT_INTEGER('\0', "max-probes", &params.max_probe_points,
> diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
> index d964cb1..8c33aa1 100644
> --- a/tools/perf/util/probe-finder.c
> +++ b/tools/perf/util/probe-finder.c
> @@ -37,6 +37,7 @@
>  #include "event.h"
>  #include "debug.h"
>  #include "util.h"
> +#include "symbol.h"
>  #include "probe-finder.h"
>  
>  /* Kprobe tracer basic type is up to u64 */
> @@ -57,6 +58,55 @@ static int strtailcmp(const char *s1, const char *s2)
>  	return 0;
>  }
>  
> +/*
> + * Find a src file from a DWARF tag path. Prepend optional source path prefix
> + * and chop off leading directories that do not exist. Result is passed back as
> + * a newly allocated path on success.
> + * Return 0 if file was found and readable, -errno otherwise.
> + */
> +static int get_real_path(const char *raw_path, char **new_path)
> +{
> +	if (!symbol_conf.source_prefix) {
> +		if (access(raw_path, R_OK) == 0) {
> +			*new_path = strdup(raw_path);
> +			return 0;
> +		} else
> +			return -errno;
> +	}
> +
> +	*new_path = malloc(strlen(symbol_conf.source_prefix)
> +			   + strlen(raw_path) + 2);
> +	if (!*new_path)
> +		return -ENOMEM;
> +
> +	for (;;) {
> +		sprintf(*new_path, "%s/%s", symbol_conf.source_prefix,
> +			raw_path);
> +
> +		if (access(*new_path, R_OK) == 0)
> +			return 0;
> +
> +		switch (errno) {
> +		case ENAMETOOLONG:
> +		case ENOENT:
> +		case EROFS:
> +		case EFAULT:
> +			raw_path = strchr(++raw_path, '/');
> +			if (!raw_path) {
> +				free(*new_path);
> +				*new_path = NULL;
> +				return -ENOENT;
> +			}
> +			continue;
> +
> +		default:
> +			free(*new_path);
> +			*new_path = NULL;
> +			return -errno;
> +		}
> +	}
> +}
> +
>  /* Line number list operations */
>  
>  /* Add a line to line number list */
> @@ -1096,11 +1146,13 @@ end:
>  static int line_range_add_line(const char *src, unsigned int lineno,
>  			       struct line_range *lr)
>  {
> +	int ret;
> +
>  	/* Copy real path */
>  	if (!lr->path) {
> -		lr->path = strdup(src);
> -		if (lr->path == NULL)
> -			return -ENOMEM;
> +		ret = get_real_path(src, &lr->path);
> +		if (ret != 0)
> +			return ret;
>  	}
>  	return line_list__add_line(&lr->line_list, lineno);
>  }
> diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
> index 10b7ff8..80e569b 100644
> --- a/tools/perf/util/symbol.h
> +++ b/tools/perf/util/symbol.h
> @@ -71,6 +71,7 @@ struct symbol_conf {
>  			full_paths,
>  			show_cpu_utilization;
>  	const char	*vmlinux_name,
> +			*source_prefix,
>  			*field_sep;
>  	const char	*default_guest_vmlinux_name,
>  			*default_guest_kallsyms,



  parent reply	other threads:[~2010-06-15  5:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-14 19:26 [RESEND][PATCH v2] perf probe: add kernel source path option Chase Douglas
2010-06-15  1:03 ` Arnaldo Carvalho de Melo
2010-06-15  5:17 ` Masami Hiramatsu [this message]
2010-06-17 22:50 ` Arnaldo Carvalho de Melo
2010-06-18 10:17 ` [tip:perf/core] perf probe: Add " tip-bot for Chase Douglas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4C170CF4.2050908@hitachi.com \
    --to=masami.hiramatsu.pt@hitachi.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=chase.douglas@canonical.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@redhat.com \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.