Re: [PATCH v2 2/2] perf script: Support filtering by hex address

2021-02-06 Thread Jin, Yao

Hi Jiri,

On 2/5/2021 5:49 PM, Jiri Olsa wrote:

On Fri, Jan 29, 2021 at 03:08:54PM +0800, Jin Yao wrote:

SNIP


+   }
+   }
+
if (!ret)
al->filtered |= (1 << HIST_FILTER__SYMBOL);
}
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 64a039cbba1b..2c13f6acda7f 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -2406,6 +2406,39 @@ int setup_intlist(struct intlist **list, const char 
*list_str,
return 0;
  }
  
+static int setup_addrlist(struct intlist **addr_list, struct strlist *sym_list)

+{
+   struct str_node *pos, *tmp;
+   unsigned long val;
+   char *sep;
+   int err = 0, i = 0;
+
+   *addr_list = intlist__new(NULL);
+   if (!*addr_list)
+   return -1;
+
+   strlist__for_each_entry_safe(pos, tmp, sym_list) {
+   val = strtoul(pos->s, , 16);
+   if (*sep != ',' && *sep != '\0')
+   continue;


I think you also need to check that val is valid and errno
(check other strtoul we call in perf)
because above could pass for:

$ ./perf script -S ",7fd0f1b69a13"
ls 651468 410180.795577:  90098 cycles:u:  7fd0f1b69a13 
__GI___tunables_init+0x73 (/usr/lib64/ld-2.32.so)




Now I think this may be OK because that's not the pattern matching. It just matches the 7fd0f1b69a13 
in address list.


And we also need to support the address + symbol combination, such as,

$ ./perf script -S "9a51de2a,put_cmsg"
 swapper 0 [007] 347304.359521:  44937   cycles:  9a51de2a rcu_core+0x29a 
([kernel.kallsyms])
avahi-daemon   580 [007] 347304.468122:  57176   cycles:  9af4764e put_cmsg+0xde 
([kernel.kallsyms])


So the idea is when we can get a valid address from -S list, we add the address to intlist for 
address comparison otherwise we still leave it to symbol list for symbol comparison.


Anyway, I will post v3 patch for review.

Thanks
Jin Yao


plus check for " " so we could do:

$ ./perf script -S "7fd0f1b69a13 ,7fd0f1b5e189"
ls 651468 410180.796055: 190731 cycles:u:  7fd0f1b5e189 
_dl_relocate_object+0x4b9 (/usr/lib64/ld-2.32.so)

$ ./perf script -S "7fd0f1b69a13,7fd0f1b5e189"
ls 651468 410180.795577:  90098 cycles:u:  7fd0f1b69a13 
__GI___tunables_init+0x73 (/usr/lib64/ld-2.32.so)
ls 651468 410180.796055: 190731 cycles:u:  7fd0f1b5e189 
_dl_relocate_object+0x4b9 (/usr/lib64/ld-2.32.so)


thanks,
jirka



Re: [PATCH v2 2/2] perf script: Support filtering by hex address

2021-02-06 Thread Jin, Yao

Hi Jiri,

On 2/5/2021 5:49 PM, Jiri Olsa wrote:

On Fri, Jan 29, 2021 at 03:08:54PM +0800, Jin Yao wrote:

SNIP


+   }
+   }
+
if (!ret)
al->filtered |= (1 << HIST_FILTER__SYMBOL);
}
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 64a039cbba1b..2c13f6acda7f 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -2406,6 +2406,39 @@ int setup_intlist(struct intlist **list, const char 
*list_str,
return 0;
  }
  
+static int setup_addrlist(struct intlist **addr_list, struct strlist *sym_list)

+{
+   struct str_node *pos, *tmp;
+   unsigned long val;
+   char *sep;
+   int err = 0, i = 0;
+
+   *addr_list = intlist__new(NULL);
+   if (!*addr_list)
+   return -1;
+
+   strlist__for_each_entry_safe(pos, tmp, sym_list) {
+   val = strtoul(pos->s, , 16);
+   if (*sep != ',' && *sep != '\0')
+   continue;


I think you also need to check that val is valid and errno
(check other strtoul we call in perf)
because above could pass for:

$ ./perf script -S ",7fd0f1b69a13"
ls 651468 410180.795577:  90098 cycles:u:  7fd0f1b69a13 
__GI___tunables_init+0x73 (/usr/lib64/ld-2.32.so)


plus check for " " so we could do:

$ ./perf script -S "7fd0f1b69a13 ,7fd0f1b5e189"
ls 651468 410180.796055: 190731 cycles:u:  7fd0f1b5e189 
_dl_relocate_object+0x4b9 (/usr/lib64/ld-2.32.so)

$ ./perf script -S "7fd0f1b69a13,7fd0f1b5e189"
ls 651468 410180.795577:  90098 cycles:u:  7fd0f1b69a13 
__GI___tunables_init+0x73 (/usr/lib64/ld-2.32.so)
ls 651468 410180.796055: 190731 cycles:u:  7fd0f1b5e189 
_dl_relocate_object+0x4b9 (/usr/lib64/ld-2.32.so)


thanks,
jirka



Thanks for reminding. Yes, these cases I need to cover. I will prepare the v3.

Thanks
Jin Yao


Re: [PATCH v2 2/2] perf script: Support filtering by hex address

2021-02-05 Thread Jiri Olsa
On Fri, Jan 29, 2021 at 03:08:54PM +0800, Jin Yao wrote:

SNIP

> + }
> + }
> +
>   if (!ret)
>   al->filtered |= (1 << HIST_FILTER__SYMBOL);
>   }
> diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
> index 64a039cbba1b..2c13f6acda7f 100644
> --- a/tools/perf/util/symbol.c
> +++ b/tools/perf/util/symbol.c
> @@ -2406,6 +2406,39 @@ int setup_intlist(struct intlist **list, const char 
> *list_str,
>   return 0;
>  }
>  
> +static int setup_addrlist(struct intlist **addr_list, struct strlist 
> *sym_list)
> +{
> + struct str_node *pos, *tmp;
> + unsigned long val;
> + char *sep;
> + int err = 0, i = 0;
> +
> + *addr_list = intlist__new(NULL);
> + if (!*addr_list)
> + return -1;
> +
> + strlist__for_each_entry_safe(pos, tmp, sym_list) {
> + val = strtoul(pos->s, , 16);
> + if (*sep != ',' && *sep != '\0')
> + continue;

I think you also need to check that val is valid and errno
(check other strtoul we call in perf)
because above could pass for:

$ ./perf script -S ",7fd0f1b69a13"
ls 651468 410180.795577:  90098 cycles:u:  7fd0f1b69a13 
__GI___tunables_init+0x73 (/usr/lib64/ld-2.32.so)


plus check for " " so we could do:

$ ./perf script -S "7fd0f1b69a13 ,7fd0f1b5e189"
ls 651468 410180.796055: 190731 cycles:u:  7fd0f1b5e189 
_dl_relocate_object+0x4b9 (/usr/lib64/ld-2.32.so)

$ ./perf script -S "7fd0f1b69a13,7fd0f1b5e189"
ls 651468 410180.795577:  90098 cycles:u:  7fd0f1b69a13 
__GI___tunables_init+0x73 (/usr/lib64/ld-2.32.so)
ls 651468 410180.796055: 190731 cycles:u:  7fd0f1b5e189 
_dl_relocate_object+0x4b9 (/usr/lib64/ld-2.32.so)


thanks,
jirka



[PATCH v2 2/2] perf script: Support filtering by hex address

2021-01-28 Thread Jin Yao
Perf-script supports '-S' or '--symbol' options to only list the
trace records in given symbols. Symbol is typically a name
or hex address. If it's hex address, it is the start address of
one symbol.

While it would be useful if we can filter trace records by any hex
address (not only the start address of symbol). So now we support
filtering trace records by more conditions, such as:
- symbol name
- start address of symbol
- any hexadecimal address
- address range

The comparison order is defined as:

1. symbol name comparison
2. symbol start address comparison.
3. any hexadecimal address comparison.
4. address range comparison.

Let's see some examples:

root@kbl-ppc:~# ./perf script -S 0x9ca77308
perf 18123 [000] 6142863.075104:  1   cycles:  
9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [000] 6142863.075107:  1   cycles:  
9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [000] 6142863.075108: 10   cycles:  
9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [001] 6142863.075156:  1   cycles:  
9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [001] 6142863.075158:  1   cycles:  
9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [001] 6142863.075159: 17   cycles:  
9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [002] 6142863.075202:  1   cycles:  
9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [002] 6142863.075204:  1   cycles:  
9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [002] 6142863.075205: 16   cycles:  
9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [003] 6142863.075250:  1   cycles:  
9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [003] 6142863.075252:  1   cycles:  
9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [003] 6142863.075253: 16   cycles:  
9ca77308 native_write_msr+0x8 ([kernel.kallsyms])

Filter the traced records by hex address 0x9ca77308.

Easy to use, we support the hex address without '0x' prefix,
e.g.
./perf script -S 9ca77308

It has the same effect.

We also support to filter trace records by a address range.

root@kbl-ppc:~# ./perf script -S 9ca77304 --addr-range 16
perf 18123 [000] 6142863.075104:  1   cycles:  
9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [000] 6142863.075107:  1   cycles:  
9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [000] 6142863.075108: 10   cycles:  
9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [000] 6142863.075109:273   cycles:  
9ca7730a native_write_msr+0xa ([kernel.kallsyms])
perf 18123 [001] 6142863.075156:  1   cycles:  
9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [001] 6142863.075158:  1   cycles:  
9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [001] 6142863.075159: 17   cycles:  
9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [001] 6142863.075160:456   cycles:  
9ca7730f native_write_msr+0xf ([kernel.kallsyms])
perf 18123 [002] 6142863.075202:  1   cycles:  
9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [002] 6142863.075204:  1   cycles:  
9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [002] 6142863.075205: 16   cycles:  
9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [002] 6142863.075206:436   cycles:  
9ca7730f native_write_msr+0xf ([kernel.kallsyms])
perf 18123 [003] 6142863.075250:  1   cycles:  
9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [003] 6142863.075252:  1   cycles:  
9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [003] 6142863.075253: 16   cycles:  
9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [003] 6142863.075254:436   cycles:  
9ca7730f native_write_msr+0xf ([kernel.kallsyms])
perf 18123 [004] 6142863.075299:  1   cycles:  
9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [004] 6142863.075301:  1   cycles:  
9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [004] 6142863.075302: 16   cycles:  
9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [004] 6142863.075303:431