linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>, Andi Kleen <ak@linux.intel.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Namhyung Kim <namhyung@kernel.org>, Leo Yan <leo.yan@linaro.org>,
	Kan Liang <kan.liang@linux.intel.com>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH RFC 03/11] perf script: Share addr_al between functions
Date: Tue, 22 Jun 2021 15:21:48 -0300	[thread overview]
Message-ID: <YNIqPIIKqmWrfl5n@kernel.org> (raw)
In-Reply-To: <20210621150514.32159-4-adrian.hunter@intel.com>

Em Mon, Jun 21, 2021 at 06:05:06PM +0300, Adrian Hunter escreveu:
> Share the addr_location of 'addr' so that it need not be resolved more than
> once.

Another nice patch, i.e. don't resolve it unconditionally, let the first
function that needs it under a callchain to do it, then reuse if another
needs it.

Looks ok, applied.

- Arnaldo
 
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> ---
>  tools/perf/builtin-script.c | 38 +++++++++++++++++++++++--------------
>  1 file changed, 24 insertions(+), 14 deletions(-)
> 
> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
> index ff7b43899f2e..d2771a997e26 100644
> --- a/tools/perf/builtin-script.c
> +++ b/tools/perf/builtin-script.c
> @@ -1337,17 +1337,18 @@ static const char *resolve_branch_sym(struct perf_sample *sample,
>  				      struct evsel *evsel,
>  				      struct thread *thread,
>  				      struct addr_location *al,
> +				      struct addr_location *addr_al,
>  				      u64 *ip)
>  {
> -	struct addr_location addr_al;
>  	struct perf_event_attr *attr = &evsel->core.attr;
>  	const char *name = NULL;
>  
>  	if (sample->flags & (PERF_IP_FLAG_CALL | PERF_IP_FLAG_TRACE_BEGIN)) {
>  		if (sample_addr_correlates_sym(attr)) {
> -			thread__resolve(thread, &addr_al, sample);
> -			if (addr_al.sym)
> -				name = addr_al.sym->name;
> +			if (!addr_al->thread)
> +				thread__resolve(thread, addr_al, sample);
> +			if (addr_al->sym)
> +				name = addr_al->sym->name;
>  			else
>  				*ip = sample->addr;
>  		} else {
> @@ -1365,7 +1366,9 @@ static const char *resolve_branch_sym(struct perf_sample *sample,
>  static int perf_sample__fprintf_callindent(struct perf_sample *sample,
>  					   struct evsel *evsel,
>  					   struct thread *thread,
> -					   struct addr_location *al, FILE *fp)
> +					   struct addr_location *al,
> +					   struct addr_location *addr_al,
> +					   FILE *fp)
>  {
>  	struct perf_event_attr *attr = &evsel->core.attr;
>  	size_t depth = thread_stack__depth(thread, sample->cpu);
> @@ -1382,7 +1385,7 @@ static int perf_sample__fprintf_callindent(struct perf_sample *sample,
>  	if (thread->ts && sample->flags & PERF_IP_FLAG_RETURN)
>  		depth += 1;
>  
> -	name = resolve_branch_sym(sample, evsel, thread, al, &ip);
> +	name = resolve_branch_sym(sample, evsel, thread, al, addr_al, &ip);
>  
>  	if (PRINT_FIELD(DSO) && !(PRINT_FIELD(IP) || PRINT_FIELD(ADDR))) {
>  		dlen += fprintf(fp, "(");
> @@ -1466,6 +1469,7 @@ static int perf_sample__fprintf_bts(struct perf_sample *sample,
>  				    struct evsel *evsel,
>  				    struct thread *thread,
>  				    struct addr_location *al,
> +				    struct addr_location *addr_al,
>  				    struct machine *machine, FILE *fp)
>  {
>  	struct perf_event_attr *attr = &evsel->core.attr;
> @@ -1474,7 +1478,7 @@ static int perf_sample__fprintf_bts(struct perf_sample *sample,
>  	int printed = 0;
>  
>  	if (PRINT_FIELD(CALLINDENT))
> -		printed += perf_sample__fprintf_callindent(sample, evsel, thread, al, fp);
> +		printed += perf_sample__fprintf_callindent(sample, evsel, thread, al, addr_al, fp);
>  
>  	/* print branch_from information */
>  	if (PRINT_FIELD(IP)) {
> @@ -1931,7 +1935,8 @@ static void perf_sample__fprint_metric(struct perf_script *script,
>  static bool show_event(struct perf_sample *sample,
>  		       struct evsel *evsel,
>  		       struct thread *thread,
> -		       struct addr_location *al)
> +		       struct addr_location *al,
> +		       struct addr_location *addr_al)
>  {
>  	int depth = thread_stack__depth(thread, sample->cpu);
>  
> @@ -1947,7 +1952,7 @@ static bool show_event(struct perf_sample *sample,
>  	} else {
>  		const char *s = symbol_conf.graph_function;
>  		u64 ip;
> -		const char *name = resolve_branch_sym(sample, evsel, thread, al,
> +		const char *name = resolve_branch_sym(sample, evsel, thread, al, addr_al,
>  				&ip);
>  		unsigned nlen;
>  
> @@ -1972,6 +1977,7 @@ static bool show_event(struct perf_sample *sample,
>  static void process_event(struct perf_script *script,
>  			  struct perf_sample *sample, struct evsel *evsel,
>  			  struct addr_location *al,
> +			  struct addr_location *addr_al,
>  			  struct machine *machine)
>  {
>  	struct thread *thread = al->thread;
> @@ -2005,7 +2011,7 @@ static void process_event(struct perf_script *script,
>  		perf_sample__fprintf_flags(sample->flags, fp);
>  
>  	if (is_bts_event(attr)) {
> -		perf_sample__fprintf_bts(sample, evsel, thread, al, machine, fp);
> +		perf_sample__fprintf_bts(sample, evsel, thread, al, addr_al, machine, fp);
>  		return;
>  	}
>  
> @@ -2168,6 +2174,7 @@ static int process_sample_event(struct perf_tool *tool,
>  {
>  	struct perf_script *scr = container_of(tool, struct perf_script, tool);
>  	struct addr_location al;
> +	struct addr_location addr_al;
>  
>  	if (perf_time__ranges_skip_sample(scr->ptime_range, scr->range_num,
>  					  sample->time)) {
> @@ -2197,7 +2204,10 @@ static int process_sample_event(struct perf_tool *tool,
>  	if (al.filtered)
>  		goto out_put;
>  
> -	if (!show_event(sample, evsel, al.thread, &al))
> +	/* Set thread to NULL to indicate addr_al is not initialized */
> +	addr_al.thread = NULL;
> +
> +	if (!show_event(sample, evsel, al.thread, &al, &addr_al))
>  		goto out_put;
>  
>  	if (evswitch__discard(&scr->evswitch, evsel))
> @@ -2205,16 +2215,16 @@ static int process_sample_event(struct perf_tool *tool,
>  
>  	if (scripting_ops) {
>  		struct addr_location *addr_al_ptr = NULL;
> -		struct addr_location addr_al;
>  
>  		if ((evsel->core.attr.sample_type & PERF_SAMPLE_ADDR) &&
>  		    sample_addr_correlates_sym(&evsel->core.attr)) {
> -			thread__resolve(al.thread, &addr_al, sample);
> +			if (!addr_al.thread)
> +				thread__resolve(al.thread, &addr_al, sample);
>  			addr_al_ptr = &addr_al;
>  		}
>  		scripting_ops->process_event(event, sample, evsel, &al, addr_al_ptr);
>  	} else {
> -		process_event(scr, sample, evsel, &al, machine);
> +		process_event(scr, sample, evsel, &al, &addr_al, machine);
>  	}
>  
>  out_put:
> -- 
> 2.17.1
> 

-- 

- Arnaldo

  reply	other threads:[~2021-06-22 18:21 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-21 15:05 [PATCH RFC 00/11] perf script: Add API for filtering via dynamically loaded shared object Adrian Hunter
2021-06-21 15:05 ` [PATCH RFC 01/11] perf script: Move filter_cpu() earlier Adrian Hunter
2021-06-22 18:16   ` Arnaldo Carvalho de Melo
2021-06-21 15:05 ` [PATCH RFC 02/11] perf script: Move filtering before scripting Adrian Hunter
2021-06-22 18:18   ` Arnaldo Carvalho de Melo
2021-06-21 15:05 ` [PATCH RFC 03/11] perf script: Share addr_al between functions Adrian Hunter
2021-06-22 18:21   ` Arnaldo Carvalho de Melo [this message]
2021-06-21 15:05 ` [PATCH RFC 04/11] perf script: Add API for filtering via dynamically loaded shared object Adrian Hunter
2021-06-22 18:32   ` Arnaldo Carvalho de Melo
2021-06-23  9:25     ` Adrian Hunter
2021-06-21 15:05 ` [PATCH RFC 05/11] perf script: Add dlfilter__filter_event_early() Adrian Hunter
2021-06-21 15:05 ` [PATCH RFC 06/11] perf build: Install perf_dlfilter.h Adrian Hunter
2021-06-21 15:05 ` [PATCH RFC 07/11] perf dlfilter: Add resolve_address() to perf_dlfilter_fns Adrian Hunter
2021-06-21 15:05 ` [PATCH RFC 08/11] perf dlfilter: Add insn() " Adrian Hunter
2021-06-21 15:05 ` [PATCH RFC 09/11] perf dlfilter: Add srcline() " Adrian Hunter
2021-06-21 15:05 ` [PATCH RFC 10/11] perf dlfilter: Add attr() " Adrian Hunter
2021-06-21 15:05 ` [PATCH RFC 11/11] perf dlfilter: Add object_code() " Adrian Hunter

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=YNIqPIIKqmWrfl5n@kernel.org \
    --to=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=jolsa@redhat.com \
    --cc=kan.liang@linux.intel.com \
    --cc=leo.yan@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --subject='Re: [PATCH RFC 03/11] perf script: Share addr_al between functions' \
    /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

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).