public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
To: Lin Ming <ming.m.lin@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@infradead.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Ingo Molnar <mingo@elte.hu>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] perf probe: Add fastpath to do lookup by function name
Date: Thu, 24 Mar 2011 18:08:35 +0900	[thread overview]
Message-ID: <4D8B0A13.8000008@hitachi.com> (raw)
In-Reply-To: <1300981134-7333-1-git-send-email-ming.m.lin@intel.com>

(2011/03/25 0:38), Lin Ming wrote:
> The vmlinux file may have thousands of CUs.
> We can lookup function name from .debug_pubnames section
> to avoid the slow loop on CUs.
> 
> Signed-off-by: Lin Ming <ming.m.lin@intel.com>
> ---
>  tools/perf/util/probe-finder.c |   38 ++++++++++++++++++++++++++++++++++++++
>  tools/perf/util/probe-finder.h |    1 +
>  2 files changed, 39 insertions(+), 0 deletions(-)
> 
> diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
> index 194f9e2..b2034c2 100644
> --- a/tools/perf/util/probe-finder.c
> +++ b/tools/perf/util/probe-finder.c
> @@ -1876,6 +1876,30 @@ static int find_line_range_by_func(struct line_finder *lf)
>  	return param.retval;
>  }
>  
> +static int pubname_search_cb(Dwarf *dbg, Dwarf_Global *gl, void *data)
> +{
> +	struct line_finder *lf = data;
> +	struct line_range *lr = lf->lr;
> +
> +	if (dwarf_offdie(dbg, gl->die_offset, &lf->sp_die)) {
> +		if (dwarf_tag(&lf->sp_die) != DW_TAG_subprogram)
> +			return DWARF_CB_OK;
> +
> +		if (die_compare_name(&lf->sp_die, lr->function)) {
> +			if (!dwarf_offdie(dbg, gl->cu_offset, &lf->cu_die))
> +				return DWARF_CB_OK;
> +

Just one comment.
Could you ensure that the decl_file of sp_die matches lr->file (by strtailcmp) here?

Other parts look good to me:)

Thanks!

> +			if (lr->file && !cu_find_realpath(&lf->cu_die, lr->file))
> +				return DWARF_CB_OK;
> +
> +			lf->found = 1;
> +			return DWARF_CB_ABORT;
> +		}
> +	}
> +
> +	return DWARF_CB_OK;
> +}
> +
>  int find_line_range(int fd, struct line_range *lr)
>  {
>  	struct line_finder lf = {.lr = lr, .found = 0};
> @@ -1895,6 +1919,19 @@ int find_line_range(int fd, struct line_range *lr)
>  		return -EBADF;
>  	}
>  
> +	/* Fastpath: lookup by function name from .debug_pubnames section */
> +	if (lr->function) {
> +		struct dwarf_callback_param param = {.data = (void *)&lf, .retval = 0};
> +
> +		dwarf_getpubnames(dbg, pubname_search_cb, &lf, 0);
> +		if (lf.found) {
> +			lf.found = 0;
> +			line_range_search_cb(&lf.sp_die, &param);
> +			if (lf.found)
> +				goto found;
> +		}
> +	}
> +
>  	/* Loop on CUs (Compilation Unit) */
>  	while (!lf.found && ret >= 0) {
>  		if (dwarf_nextcu(dbg, off, &noff, &cuhl, NULL, NULL, NULL) != 0)
> @@ -1923,6 +1960,7 @@ int find_line_range(int fd, struct line_range *lr)
>  		off = noff;
>  	}
>  
> +found:
>  	/* Store comp_dir */
>  	if (lf.found) {
>  		comp_dir = cu_get_comp_dir(&lf.cu_die);
> diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h
> index beaefc3..4bc56a4 100644
> --- a/tools/perf/util/probe-finder.h
> +++ b/tools/perf/util/probe-finder.h
> @@ -83,6 +83,7 @@ struct line_finder {
>  	int			lno_s;		/* Start line number */
>  	int			lno_e;		/* End line number */
>  	Dwarf_Die		cu_die;		/* Current CU */
> +	Dwarf_Die		sp_die;
>  	int			found;
>  };
>  


-- 
Masami HIRAMATSU
2nd Dept. Linux Technology Center
Hitachi, Ltd., Systems Development Laboratory
E-mail: masami.hiramatsu.pt@hitachi.com

  parent reply	other threads:[~2011-03-24  9:08 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-24 15:38 [PATCH] perf probe: Add fastpath to do lookup by function name Lin Ming
2011-03-24  7:58 ` Ingo Molnar
2011-03-24  8:38   ` Lin Ming
2011-03-24  8:47     ` Ingo Molnar
2011-03-24  9:08 ` Masami Hiramatsu [this message]
2011-03-24 13:47   ` Lin Ming
2011-03-24 14:09     ` [PATCH v2 -tip] " Lin Ming
2011-03-25  1:14       ` Masami Hiramatsu
2011-03-25  2:57         ` Arnaldo Carvalho de Melo
2011-03-25  6:33           ` Lin Ming
2011-03-25  8:30             ` Lin Ming

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=4D8B0A13.8000008@hitachi.com \
    --to=masami.hiramatsu.pt@hitachi.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ming.m.lin@intel.com \
    --cc=mingo@elte.hu \
    /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