All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: Jin Yao <yao.jin@linux.intel.com>
Cc: acme@kernel.org, jolsa@kernel.org, peterz@infradead.org,
	mingo@redhat.com, alexander.shishkin@linux.intel.com,
	Linux-kernel@vger.kernel.org, ak@linux.intel.com,
	kan.liang@intel.com, yao.jin@intel.com
Subject: Re: [PATCH 1/2] perf script: Support filtering by hex address
Date: Thu, 28 Jan 2021 00:13:16 +0100	[thread overview]
Message-ID: <20210127222905.GD284633@krava> (raw)
In-Reply-To: <20210124232750.19170-1-yao.jin@linux.intel.com>

On Mon, Jan 25, 2021 at 07:27:49AM +0800, Jin Yao wrote:

SNIP

>  	perf script --symbols=noploop,0x4007a0
>  
> +	Support filtering trace records by symbol name, start address of
> +	symbol, any hexadecimal address and address range.
> +
> +	The comparison order is:
> +	1. symbol name comparison
> +	2. symbol start address comparison.
> +	3. any hexadecimal address comparison.
> +	4. address range comparison (see --addr-range).
> +
> +--addr-range::
> +	Use with -S or --symbols to list traced records within address range.
> +
> +	For example, to list the traced records within the address range
> +	[0x4007a0, 0x0x4007a9]:
> +	perf script -S 0x4007a0 --addr-range 10
> +
>  --call-trace::
>  	Show call stream for intel_pt traces. The CPUs are interleaved, but
>  	can be filtered with -C.
> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
> index edacfa98d073..e0feda33dbb9 100644
> --- a/tools/perf/builtin-script.c
> +++ b/tools/perf/builtin-script.c
> @@ -3525,6 +3525,8 @@ int cmd_script(int argc, const char **argv)
>  		    "system-wide collection from all CPUs"),
>  	OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",
>  		   "only consider these symbols"),
> +	OPT_INTEGER(0, "addr-range", &symbol_conf.addr_range,
> +		    "Use with -S to list traced records within address range"),
>  	OPT_CALLBACK_OPTARG(0, "insn-trace", &itrace_synth_opts, NULL, NULL,
>  			"Decode instructions from itrace", parse_insn_trace),
>  	OPT_CALLBACK_OPTARG(0, "xed", NULL, NULL, NULL,
> diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
> index fbe8578e4c47..525b859cb445 100644
> --- a/tools/perf/util/event.c
> +++ b/tools/perf/util/event.c
> @@ -645,6 +645,22 @@ struct symbol *thread__find_symbol_fb(struct thread *thread, u8 cpumode,
>  	return al->sym;
>  }
>  
> +static bool check_address_range(struct strlist *sym_list, int addr_range,
> +				struct addr_location *al)
> +{
> +	struct str_node *pos;
> +	char *endptr;
> +	u64 addr, al_addr = al->map->unmap_ip(al->map, al->addr);
> +
> +	strlist__for_each_entry(pos, sym_list) {
> +		addr = strtoull(pos->s, &endptr, 16);
> +		if (al_addr >= addr && al_addr < addr + addr_range)
> +			return true;
> +	}
> +
> +	return false;
> +}
> +
>  /*
>   * Callers need to drop the reference to al->thread, obtained in
>   * machine__findnew_thread()
> @@ -709,6 +725,26 @@ int machine__resolve(struct machine *machine, struct addr_location *al,
>  			ret = strlist__has_entry(symbol_conf.sym_list,
>  						al_addr_str);
>  		}
> +		if (!ret && al->map) {
> +			snprintf(al_addr_str, sz, "0x%"PRIx64,
> +				al->map->unmap_ip(al->map, al->addr));
> +			ret = strlist__has_entry(symbol_conf.sym_list,
> +						 al_addr_str);
> +			if (!ret) {
> +				/* Check for hex without "0x" prefix */
> +				snprintf(al_addr_str, sz, "%"PRIx64,
> +					al->map->unmap_ip(al->map, al->addr));
> +				ret = strlist__has_entry(symbol_conf.sym_list,
> +							 al_addr_str);
> +			}

that seems tricky.. what if user specify more leading zeros,
I think it'd be better to search intlist instead

we could move all 'address' entries from sym_list to
new intlist (in symbol__init) and use it for this search

jirka


  parent reply	other threads:[~2021-01-27 23:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-24 23:27 [PATCH 1/2] perf script: Support filtering by hex address Jin Yao
2021-01-24 23:27 ` [PATCH 2/2] perf script: Support dso filter Jin Yao
2021-01-27 22:15   ` Jiri Olsa
2021-01-28 13:12   ` Arnaldo Carvalho de Melo
2021-01-29  0:37     ` Jin, Yao
2021-01-27 23:13 ` Jiri Olsa [this message]
2021-01-28  3:31   ` [PATCH 1/2] perf script: Support filtering by hex address Jin, Yao
2021-01-28 12:43     ` Arnaldo Carvalho de Melo
2021-01-29  0:42       ` Jin, Yao

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=20210127222905.GD284633@krava \
    --to=jolsa@redhat.com \
    --cc=Linux-kernel@vger.kernel.org \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@intel.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=yao.jin@intel.com \
    --cc=yao.jin@linux.intel.com \
    /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.