LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
To: Naohiro Aota <naota@elisp.net>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Paul Mackerras <paulus@samba.org>, Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>, Jiri Olsa <jolsa@kernel.org>,
	"open list:PERFORMANCE EVENT..." <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] perf probe: Find compilation directory path for lazy matching
Date: Wed, 04 Mar 2015 21:34:38 +0900	[thread overview]
Message-ID: <54F6FBDE.6060909@hitachi.com> (raw)
In-Reply-To: <1425455533-19551-1-git-send-email-naota@elisp.net>

(2015/03/04 16:52), Naohiro Aota wrote:
> If we use lazy matching, it failed to open a souce file if perf command
> is invoked outside of compilation directory:
> 
> $ perf probe -a '__schedule;clear_*'
> Failed to open kernel/sched/core.c: No such file or directory
>   Error: Failed to add events. (-2)
> 
> OTOH, other commands like "probe -L" can solve the souce directory by
> themselves. Let's make it possible for lazy matching too!
> 

Looks good to me :)

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

Thank you!

> Signed-off-by: Naohiro Aota <naota@elisp.net>
> ---
>  tools/perf/util/probe-event.c  | 59 -----------------------------------
>  tools/perf/util/probe-finder.c | 71 +++++++++++++++++++++++++++++++++++++++++-
>  tools/perf/util/probe-finder.h |  4 +++
>  3 files changed, 74 insertions(+), 60 deletions(-)
> 
> diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
> index 1c570c2..adb8d1f 100644
> --- a/tools/perf/util/probe-event.c
> +++ b/tools/perf/util/probe-event.c
> @@ -515,65 +515,6 @@ static int try_to_find_probe_trace_events(struct perf_probe_event *pev,
>  	return ntevs;
>  }
>  
> -/*
> - * 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, const char *comp_dir,
> -			 char **new_path)
> -{
> -	const char *prefix = symbol_conf.source_prefix;
> -
> -	if (!prefix) {
> -		if (raw_path[0] != '/' && comp_dir)
> -			/* If not an absolute path, try to use comp_dir */
> -			prefix = comp_dir;
> -		else {
> -			if (access(raw_path, R_OK) == 0) {
> -				*new_path = strdup(raw_path);
> -				return *new_path ? 0 : -ENOMEM;
> -			} else
> -				return -errno;
> -		}
> -	}
> -
> -	*new_path = malloc((strlen(prefix) + strlen(raw_path) + 2));
> -	if (!*new_path)
> -		return -ENOMEM;
> -
> -	for (;;) {
> -		sprintf(*new_path, "%s/%s", prefix, raw_path);
> -
> -		if (access(*new_path, R_OK) == 0)
> -			return 0;
> -
> -		if (!symbol_conf.source_prefix) {
> -			/* In case of searching comp_dir, don't retry */
> -			zfree(new_path);
> -			return -errno;
> -		}
> -
> -		switch (errno) {
> -		case ENAMETOOLONG:
> -		case ENOENT:
> -		case EROFS:
> -		case EFAULT:
> -			raw_path = strchr(++raw_path, '/');
> -			if (!raw_path) {
> -				zfree(new_path);
> -				return -ENOENT;
> -			}
> -			continue;
> -
> -		default:
> -			zfree(new_path);
> -			return -errno;
> -		}
> -	}
> -}
> -
>  #define LINEBUF_SIZE 256
>  #define NR_ADDITIONAL_LINES 2
>  
> diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
> index 46f009a..e6c0262 100644
> --- a/tools/perf/util/probe-finder.c
> +++ b/tools/perf/util/probe-finder.c
> @@ -849,11 +849,22 @@ static int probe_point_lazy_walker(const char *fname, int lineno,
>  static int find_probe_point_lazy(Dwarf_Die *sp_die, struct probe_finder *pf)
>  {
>  	int ret = 0;
> +	char *fpath;
>  
>  	if (intlist__empty(pf->lcache)) {
> +		const char *comp_dir;
> +
> +		comp_dir = cu_get_comp_dir(&pf->cu_die);
> +		ret = get_real_path(pf->fname, comp_dir, &fpath);
> +		if (ret < 0) {
> +			pr_warning("Failed to find source file path.\n");
> +			return ret;
> +		}
> +
>  		/* Matching lazy line pattern */
> -		ret = find_lazy_match_lines(pf->lcache, pf->fname,
> +		ret = find_lazy_match_lines(pf->lcache, fpath,
>  					    pf->pev->point.lazy_line);
> +		free(fpath);
>  		if (ret <= 0)
>  			return ret;
>  	}
> @@ -1616,3 +1627,61 @@ found:
>  	return (ret < 0) ? ret : lf.found;
>  }
>  
> +/*
> + * 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, const char *comp_dir,
> +			 char **new_path)
> +{
> +	const char *prefix = symbol_conf.source_prefix;
> +
> +	if (!prefix) {
> +		if (raw_path[0] != '/' && comp_dir)
> +			/* If not an absolute path, try to use comp_dir */
> +			prefix = comp_dir;
> +		else {
> +			if (access(raw_path, R_OK) == 0) {
> +				*new_path = strdup(raw_path);
> +				return *new_path ? 0 : -ENOMEM;
> +			} else
> +				return -errno;
> +		}
> +	}
> +
> +	*new_path = malloc((strlen(prefix) + strlen(raw_path) + 2));
> +	if (!*new_path)
> +		return -ENOMEM;
> +
> +	for (;;) {
> +		sprintf(*new_path, "%s/%s", prefix, raw_path);
> +
> +		if (access(*new_path, R_OK) == 0)
> +			return 0;
> +
> +		if (!symbol_conf.source_prefix) {
> +			/* In case of searching comp_dir, don't retry */
> +			zfree(new_path);
> +			return -errno;
> +		}
> +
> +		switch (errno) {
> +		case ENAMETOOLONG:
> +		case ENOENT:
> +		case EROFS:
> +		case EFAULT:
> +			raw_path = strchr(++raw_path, '/');
> +			if (!raw_path) {
> +				zfree(new_path);
> +				return -ENOENT;
> +			}
> +			continue;
> +
> +		default:
> +			zfree(new_path);
> +			return -errno;
> +		}
> +	}
> +}
> diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h
> index 92590b2..5ef82dd 100644
> --- a/tools/perf/util/probe-finder.h
> +++ b/tools/perf/util/probe-finder.h
> @@ -55,6 +55,10 @@ extern int debuginfo__find_available_vars_at(struct debuginfo *dbg,
>  					     struct variable_list **vls,
>  					     int max_points, bool externs);
>  
> +/* Find a src file from a DWARF tag path */
> +extern int get_real_path(const char *raw_path, const char *comp_dir,
> +			 char **new_path);
> +
>  struct probe_finder {
>  	struct perf_probe_event	*pev;		/* Target probe event */
>  
> 


-- 
Masami HIRAMATSU
Software Platform Research Dept. Linux Technology Research Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt@hitachi.com



  reply	other threads:[~2015-03-04 12:34 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-26  7:12 [PATCH 1/2] perf probe: export get_real_path Naohiro Aota
2015-02-26  7:12 ` [PATCH 2/2] perf probe: Find compilation directory path for lazy matching Naohiro Aota
2015-02-26  8:08   ` Masami Hiramatsu
2015-02-26  8:25     ` [PATCH perf/core ] [BUGFIX] perf-probe: Fix get_real_path to free allocated memory in error path Masami Hiramatsu
2015-02-26 14:46       ` Arnaldo Carvalho de Melo
2015-02-27  0:58         ` Masami Hiramatsu
2015-02-28  9:31       ` [tip:perf/core] perf probe: " tip-bot for Masami Hiramatsu
2015-02-26  7:50 ` [PATCH 1/2] perf probe: export get_real_path Masami Hiramatsu
2015-03-04  7:52 ` [PATCH v2] perf probe: Find compilation directory path for lazy matching Naohiro Aota
2015-03-04 12:34   ` Masami Hiramatsu [this message]
2015-03-11 13:30     ` Arnaldo Carvalho de Melo
2015-03-12  1:42       ` Masami Hiramatsu
2015-03-13  5:13         ` Naohiro Aota
2015-03-13  5:18       ` [PATCH v3] " Naohiro Aota
2015-03-13 12:21         ` Masami Hiramatsu
2015-04-13 23:10         ` Arnaldo Carvalho de Melo
2015-04-14  6:35           ` Masami Hiramatsu
2015-04-14 12:17         ` [tip:perf/urgent] " tip-bot for Naohiro Aota

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=54F6FBDE.6060909@hitachi.com \
    --to=masami.hiramatsu.pt@hitachi.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=naota@elisp.net \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).