2021-01-26 01:25:59

by Jin Yao

[permalink] [raw]
Subject: [PATCH 2/2] perf script: Support dso filter

Other perf tool builtins have already supported dso filter.

For example,
perf report --dso, which only considers symbols in these dsos.

Now dso filter is supported for perf-script.

root@kbl-ppc:~# ./perf script --dso "[kernel.kallsyms]"
perf 18123 [000] 6142863.075104: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [000] 6142863.075107: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [000] 6142863.075108: 10 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [000] 6142863.075109: 273 cycles: ffffffff9ca7730a native_write_msr+0xa ([kernel.kallsyms])
perf 18123 [000] 6142863.075110: 7684 cycles: ffffffff9ca3c9c0 native_sched_clock+0x50 ([kernel.kallsyms])
perf 18123 [000] 6142863.075112: 213017 cycles: ffffffff9d765a92 syscall_exit_to_user_mode+0x32 ([kernel.kallsyms])
perf 18123 [001] 6142863.075156: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [001] 6142863.075158: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [001] 6142863.075159: 17 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])

Signed-off-by: Jin Yao <[email protected]>
---
tools/perf/Documentation/perf-script.txt | 3 +++
tools/perf/builtin-script.c | 2 ++
2 files changed, 5 insertions(+)

diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index 0ef2261baeb9..6e32b2f9b828 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -444,6 +444,9 @@ include::itrace.txt[]
[0x4007a0, 0x0x4007a9]:
perf script -S 0x4007a0 --addr-range 10

+--dsos=::
+ Only consider symbols in these dsos.
+
--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 e0feda33dbb9..f8d3d8582ea2 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -3523,6 +3523,8 @@ int cmd_script(int argc, const char **argv)
parse_output_fields),
OPT_BOOLEAN('a', "all-cpus", &system_wide,
"system-wide collection from all CPUs"),
+ OPT_STRING(0, "dsos", &symbol_conf.dso_list_str, "dso[,dso...]",
+ "only consider symbols in these dsos"),
OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",
"only consider these symbols"),
OPT_INTEGER(0, "addr-range", &symbol_conf.addr_range,
--
2.17.1


2021-01-28 00:41:54

by Jiri Olsa

[permalink] [raw]
Subject: Re: [PATCH 2/2] perf script: Support dso filter

On Mon, Jan 25, 2021 at 07:27:50AM +0800, Jin Yao wrote:
> Other perf tool builtins have already supported dso filter.
>
> For example,
> perf report --dso, which only considers symbols in these dsos.
>
> Now dso filter is supported for perf-script.
>
> root@kbl-ppc:~# ./perf script --dso "[kernel.kallsyms]"
> perf 18123 [000] 6142863.075104: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
> perf 18123 [000] 6142863.075107: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
> perf 18123 [000] 6142863.075108: 10 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
> perf 18123 [000] 6142863.075109: 273 cycles: ffffffff9ca7730a native_write_msr+0xa ([kernel.kallsyms])
> perf 18123 [000] 6142863.075110: 7684 cycles: ffffffff9ca3c9c0 native_sched_clock+0x50 ([kernel.kallsyms])
> perf 18123 [000] 6142863.075112: 213017 cycles: ffffffff9d765a92 syscall_exit_to_user_mode+0x32 ([kernel.kallsyms])
> perf 18123 [001] 6142863.075156: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
> perf 18123 [001] 6142863.075158: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
> perf 18123 [001] 6142863.075159: 17 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
>
> Signed-off-by: Jin Yao <[email protected]>

Acked-by: Jiri Olsa <[email protected]>

thanks,
jirka

> ---
> tools/perf/Documentation/perf-script.txt | 3 +++
> tools/perf/builtin-script.c | 2 ++
> 2 files changed, 5 insertions(+)
>
> diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
> index 0ef2261baeb9..6e32b2f9b828 100644
> --- a/tools/perf/Documentation/perf-script.txt
> +++ b/tools/perf/Documentation/perf-script.txt
> @@ -444,6 +444,9 @@ include::itrace.txt[]
> [0x4007a0, 0x0x4007a9]:
> perf script -S 0x4007a0 --addr-range 10
>
> +--dsos=::
> + Only consider symbols in these dsos.
> +
> --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 e0feda33dbb9..f8d3d8582ea2 100644
> --- a/tools/perf/builtin-script.c
> +++ b/tools/perf/builtin-script.c
> @@ -3523,6 +3523,8 @@ int cmd_script(int argc, const char **argv)
> parse_output_fields),
> OPT_BOOLEAN('a', "all-cpus", &system_wide,
> "system-wide collection from all CPUs"),
> + OPT_STRING(0, "dsos", &symbol_conf.dso_list_str, "dso[,dso...]",
> + "only consider symbols in these dsos"),
> OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",
> "only consider these symbols"),
> OPT_INTEGER(0, "addr-range", &symbol_conf.addr_range,
> --
> 2.17.1
>

2021-01-28 13:17:50

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH 2/2] perf script: Support dso filter

Em Mon, Jan 25, 2021 at 07:27:50AM +0800, Jin Yao escreveu:
> Other perf tool builtins have already supported dso filter.
>
> For example,
> perf report --dso, which only considers symbols in these dsos.
>
> Now dso filter is supported for perf-script.
>
> root@kbl-ppc:~# ./perf script --dso "[kernel.kallsyms]"
> perf 18123 [000] 6142863.075104: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
> perf 18123 [000] 6142863.075107: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
> perf 18123 [000] 6142863.075108: 10 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
> perf 18123 [000] 6142863.075109: 273 cycles: ffffffff9ca7730a native_write_msr+0xa ([kernel.kallsyms])
> perf 18123 [000] 6142863.075110: 7684 cycles: ffffffff9ca3c9c0 native_sched_clock+0x50 ([kernel.kallsyms])
> perf 18123 [000] 6142863.075112: 213017 cycles: ffffffff9d765a92 syscall_exit_to_user_mode+0x32 ([kernel.kallsyms])
> perf 18123 [001] 6142863.075156: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
> perf 18123 [001] 6142863.075158: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
> perf 18123 [001] 6142863.075159: 17 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])

Applied, and in testing it I noticed this fix was also needed, added
just before it, please ack :-)

- Arnaldo

commit d4b6078bd58b799a8ea2a57842193504c867bee5
Author: Arnaldo Carvalho de Melo <[email protected]>
Date: Thu Jan 28 09:52:47 2021 -0300

perf tools: Fix DSO filtering when not finding a map for a sampled address

When we lookup an address and don't find a map we should filter that
sample if the user specified a list of --dso entries to filter on, fix
it.

Before:

$ perf script
sleep 274800 2843.556162: 1 cycles:u: ffffffffbb26bff4 [unknown] ([unknown])
sleep 274800 2843.556168: 1 cycles:u: ffffffffbb2b047d [unknown] ([unknown])
sleep 274800 2843.556171: 1 cycles:u: ffffffffbb2706b2 [unknown] ([unknown])
sleep 274800 2843.556174: 6 cycles:u: ffffffffbb2b0267 [unknown] ([unknown])
sleep 274800 2843.556176: 59 cycles:u: ffffffffbb2b03b1 [unknown] ([unknown])
sleep 274800 2843.556180: 691 cycles:u: ffffffffbb26bff4 [unknown] ([unknown])
sleep 274800 2843.556189: 9160 cycles:u: 7fa9550eeaa3 __GI___tunables_init+0xf3 (/usr/lib64/ld-2.32.so)
sleep 274800 2843.556312: 86937 cycles:u: 7fa9550e157b _dl_lookup_symbol_x+0x4b (/usr/lib64/ld-2.32.so)
$

So we have some samples we somehow didn't find in a map for, if we now
do:

$ perf report --stdio --dso /usr/lib64/ld-2.32.so
# dso: /usr/lib64/ld-2.32.so
#
# Total Lost Samples: 0
#
# Samples: 8 of event 'cycles:u'
# Event count (approx.): 96856
#
# Overhead Command Symbol
# ........ ....... ........................
#
89.76% sleep [.] _dl_lookup_symbol_x
9.46% sleep [.] __GI___tunables_init
0.71% sleep [k] 0xffffffffbb26bff4
0.06% sleep [k] 0xffffffffbb2b03b1
0.01% sleep [k] 0xffffffffbb2b0267
0.00% sleep [k] 0xffffffffbb2706b2
0.00% sleep [k] 0xffffffffbb2b047d
$

After this patch we get the right output with just entries for the DSOs
specified in --dso:

$ perf report --stdio --dso /usr/lib64/ld-2.32.so
# dso: /usr/lib64/ld-2.32.so
#
# Total Lost Samples: 0
#
# Samples: 8 of event 'cycles:u'
# Event count (approx.): 96856
#
# Overhead Command Symbol
# ........ ....... ........................
#
89.76% sleep [.] _dl_lookup_symbol_x
9.46% sleep [.] __GI___tunables_init
$

# To display the perf.data header info, please use --header/--header-only options.
#

Cc: Alexander Shishkin <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Jin Yao <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Kan Liang <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Fixes: 96415e4d3f5fdf9c ("perf symbols: Avoid unnecessary symbol loading when dso list is specified")
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>

diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index fbe8578e4c475773..208b6c141d98bb5d 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -692,6 +692,8 @@ int machine__resolve(struct machine *machine, struct addr_location *al,
}

al->sym = map__find_symbol(al->map, al->addr);
+ } else if (symbol_conf.dso_list) {
+ al->filtered |= (1 << HIST_FILTER__DSO);
}

if (symbol_conf.sym_list) {

2021-01-29 00:43:29

by Jin Yao

[permalink] [raw]
Subject: Re: [PATCH 2/2] perf script: Support dso filter

Hi Arnaldo,

On 1/28/2021 9:12 PM, Arnaldo Carvalho de Melo wrote:
> Em Mon, Jan 25, 2021 at 07:27:50AM +0800, Jin Yao escreveu:
>> Other perf tool builtins have already supported dso filter.
>>
>> For example,
>> perf report --dso, which only considers symbols in these dsos.
>>
>> Now dso filter is supported for perf-script.
>>
>> root@kbl-ppc:~# ./perf script --dso "[kernel.kallsyms]"
>> perf 18123 [000] 6142863.075104: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
>> perf 18123 [000] 6142863.075107: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
>> perf 18123 [000] 6142863.075108: 10 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
>> perf 18123 [000] 6142863.075109: 273 cycles: ffffffff9ca7730a native_write_msr+0xa ([kernel.kallsyms])
>> perf 18123 [000] 6142863.075110: 7684 cycles: ffffffff9ca3c9c0 native_sched_clock+0x50 ([kernel.kallsyms])
>> perf 18123 [000] 6142863.075112: 213017 cycles: ffffffff9d765a92 syscall_exit_to_user_mode+0x32 ([kernel.kallsyms])
>> perf 18123 [001] 6142863.075156: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
>> perf 18123 [001] 6142863.075158: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
>> perf 18123 [001] 6142863.075159: 17 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
>
> Applied, and in testing it I noticed this fix was also needed, added
> just before it, please ack :-)
>
> - Arnaldo
>
> commit d4b6078bd58b799a8ea2a57842193504c867bee5
> Author: Arnaldo Carvalho de Melo <[email protected]>
> Date: Thu Jan 28 09:52:47 2021 -0300
>
> perf tools: Fix DSO filtering when not finding a map for a sampled address
>
> When we lookup an address and don't find a map we should filter that
> sample if the user specified a list of --dso entries to filter on, fix
> it.
>
> Before:
>
> $ perf script
> sleep 274800 2843.556162: 1 cycles:u: ffffffffbb26bff4 [unknown] ([unknown])
> sleep 274800 2843.556168: 1 cycles:u: ffffffffbb2b047d [unknown] ([unknown])
> sleep 274800 2843.556171: 1 cycles:u: ffffffffbb2706b2 [unknown] ([unknown])
> sleep 274800 2843.556174: 6 cycles:u: ffffffffbb2b0267 [unknown] ([unknown])
> sleep 274800 2843.556176: 59 cycles:u: ffffffffbb2b03b1 [unknown] ([unknown])
> sleep 274800 2843.556180: 691 cycles:u: ffffffffbb26bff4 [unknown] ([unknown])
> sleep 274800 2843.556189: 9160 cycles:u: 7fa9550eeaa3 __GI___tunables_init+0xf3 (/usr/lib64/ld-2.32.so)
> sleep 274800 2843.556312: 86937 cycles:u: 7fa9550e157b _dl_lookup_symbol_x+0x4b (/usr/lib64/ld-2.32.so)
> $
>
> So we have some samples we somehow didn't find in a map for, if we now
> do:
>
> $ perf report --stdio --dso /usr/lib64/ld-2.32.so
> # dso: /usr/lib64/ld-2.32.so
> #
> # Total Lost Samples: 0
> #
> # Samples: 8 of event 'cycles:u'
> # Event count (approx.): 96856
> #
> # Overhead Command Symbol
> # ........ ....... ........................
> #
> 89.76% sleep [.] _dl_lookup_symbol_x
> 9.46% sleep [.] __GI___tunables_init
> 0.71% sleep [k] 0xffffffffbb26bff4
> 0.06% sleep [k] 0xffffffffbb2b03b1
> 0.01% sleep [k] 0xffffffffbb2b0267
> 0.00% sleep [k] 0xffffffffbb2706b2
> 0.00% sleep [k] 0xffffffffbb2b047d
> $
>
> After this patch we get the right output with just entries for the DSOs
> specified in --dso:
>
> $ perf report --stdio --dso /usr/lib64/ld-2.32.so
> # dso: /usr/lib64/ld-2.32.so
> #
> # Total Lost Samples: 0
> #
> # Samples: 8 of event 'cycles:u'
> # Event count (approx.): 96856
> #
> # Overhead Command Symbol
> # ........ ....... ........................
> #
> 89.76% sleep [.] _dl_lookup_symbol_x
> 9.46% sleep [.] __GI___tunables_init
> $
>
> # To display the perf.data header info, please use --header/--header-only options.
> #
>
> Cc: Alexander Shishkin <[email protected]>
> Cc: Andi Kleen <[email protected]>
> Cc: Ingo Molnar <[email protected]>
> Cc: Jin Yao <[email protected]>
> Cc: Jiri Olsa <[email protected]>
> Cc: Kan Liang <[email protected]>
> Cc: Namhyung Kim <[email protected]>
> Cc: Peter Zijlstra <[email protected]>
> Fixes: 96415e4d3f5fdf9c ("perf symbols: Avoid unnecessary symbol loading when dso list is specified")
> Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
>
> diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
> index fbe8578e4c475773..208b6c141d98bb5d 100644
> --- a/tools/perf/util/event.c
> +++ b/tools/perf/util/event.c
> @@ -692,6 +692,8 @@ int machine__resolve(struct machine *machine, struct addr_location *al,
> }
>
> al->sym = map__find_symbol(al->map, al->addr);
> + } else if (symbol_conf.dso_list) {
> + al->filtered |= (1 << HIST_FILTER__DSO);
> }
>
> if (symbol_conf.sym_list) {
>

This fix guarantees the "[unknown]" dso is filtered when we enable "--dso" option (whatever the dso
list in --dso).

Acked-by: Jin Yao ([email protected]>

Thanks
Jin Yao