perf script: Support filtering by hex address
PATCH 1/2 perf script: Support filtering by hex address
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 0xffffffff9ca77308
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 [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])
perf 18123 [002] 6142863.075202: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [002] 6142863.075204: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [002] 6142863.075205: 16 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [003] 6142863.075250: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [003] 6142863.075252: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [003] 6142863.075253: 16 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])Filter the traced records by hex address 0xffffffff9ca77308.
Easy to use, we support the hex address without '0x' prefix, e.g.
./perf script -S ffffffff9ca77308
It has the same effect.
We also support to filter trace records by a address range.
root@kbl-ppc:~# ./perf script -S ffffffff9ca77304 --addr-range 16
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 [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])
perf 18123 [001] 6142863.075160: 456 cycles: ffffffff9ca7730f native_write_msr+0xf ([kernel.kallsyms])
perf 18123 [002] 6142863.075202: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [002] 6142863.075204: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [002] 6142863.075205: 16 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [002] 6142863.075206: 436 cycles: ffffffff9ca7730f native_write_msr+0xf ([kernel.kallsyms])
perf 18123 [003] 6142863.075250: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [003] 6142863.075252: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [003] 6142863.075253: 16 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [003] 6142863.075254: 436 cycles: ffffffff9ca7730f native_write_msr+0xf ([kernel.kallsyms])
perf 18123 [004] 6142863.075299: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [004] 6142863.075301: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [004] 6142863.075302: 16 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [004] 6142863.075303: 431 cycles: ffffffff9ca7730f native_write_msr+0xf ([kernel.kallsyms])
perf 18123 [005] 6142863.075348: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [005] 6142863.075349: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [005] 6142863.075351: 17 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [005] 6142863.075352: 454 cycles: ffffffff9ca7730f native_write_msr+0xf ([kernel.kallsyms])
perf 18123 [006] 6142863.075390: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [006] 6142863.075392: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [006] 6142863.075393: 17 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [006] 6142863.075394: 459 cycles: ffffffff9ca7730f native_write_msr+0xf ([kernel.kallsyms])
perf 18123 [007] 6142863.075438: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [007] 6142863.075440: 1 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [007] 6142863.075441: 17 cycles: ffffffff9ca77308 native_write_msr+0x8 ([kernel.kallsyms])
perf 18123 [007] 6142863.075442: 466 cycles: ffffffff9ca7730f native_write_msr+0xf ([kernel.kallsyms])Filter the traced records from address range [0xffffffff9ca77304, 0xffffffff9ca77304 + 15].
--- tools/perf/Documentation/perf-script.txt | 19 +++++++++++++ tools/perf/builtin-script.c | 2 ++ tools/perf/util/event.c | 36 ++++++++++++++++++++++++ tools/perf/util/symbol_conf.h | 1 + 4 files changed, 58 insertions(+)
tools/perf/Documentation/perf-script.txt +19 -0
@@ -422,9 +422,28 @@ include::itrace.txt[] Only consider the listed symbols. Symbols are typically a name but they may also be hexadecimal address. + The hexadecimal address may be the start address of a symbol or + any other address to filter the trace records. + For example, to select the symbol noploop or the address 0x4007a0: 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.
tools/perf/builtin-script.c +2 -0
@@ -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,
tools/perf/util/event.c +36 -0
@@ -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); + } + +if (!ret && symbol_conf.addr_range) { + ret =check_address_range (symbol_conf.sym_list, + symbol_conf.addr_range, + al); + } + } +if (!ret) al->filtered |= (1 <<HIST_FILTER__SYMBOL ); }
tools/perf/util/symbol_conf.h +1 -0
@@ -75,6 +75,7 @@ struct symbol_conf {int res_sample;int pad_output_len_dso;int group_sort_idx; +int addr_range; };extern struct symbol_conf symbol_conf;
Signature · 1 line
2.17.1
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])--- tools/perf/Documentation/perf-script.txt | 3 +++ tools/perf/builtin-script.c | 2 ++ 2 files changed, 5 insertions(+)
tools/perf/Documentation/perf-script.txt +3 -0
@@ -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.
tools/perf/builtin-script.c +2 -0
@@ -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,
Signature · 1 line
2.17.1
Re: [PATCH 2/2] perf script: Support dso filter
Quoted 18 lines · Jin Yao
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])
Quoted 1 line
Signed-off-by Jin Yao <[email protected]>
thanks,
jirka
Quoted 35 lines
--- tools/perf/Documentation/perf-script.txt | 3 +++ tools/perf/builtin-script.c | 2 ++ 2 files changed, 5 insertions(+)tools/perf/Documentation/perf-script.txt +3
-0@@ -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.tools/perf/builtin-script.c +2
-0@@ -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,Signature · 1 line
2.17.1
Arnaldo Carvalho de Melo
maintainerRe: [PATCH 2/2] perf script: Support dso filter
In reply to Jin YaoEm Mon, Jan 25, 2021 at 07:27:50AM +0800, Jin Yao escreveu:
Quoted 7 lines
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.
Quoted 10 lines
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]>tools/perf/util/event.c +2 -0
@@ -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) {
Jin, Yao
Acked-byRe: [PATCH 2/2] perf script: Support dso filter
Hi Arnaldo,
Quoted 108 lines · Arnaldo Carvalho de Melo
Em Mon, Jan 25, 2021 at 07:27:50AM +0800, Jin Yao escreveu:
Quoted 7 lines
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.
Quoted 10 lines
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
d4b6078bd58b799a8ea2a57842193504c867bee5Author: Arnaldo Carvalho de Melo <[email protected]> Date: Thu Jan 28 09:52:47 2021 -0300perf 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]>tools/perf/util/event.c +0
-0
tools/perf/util/event.c int machine__resolve(struct machine *machine, struct addr_location *al, · line 699
Quoted 8 lines
tools/perf/util/event.c +2
-0@@ -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).
Thanks
Jin Yao
On Mon, Jan 25, 2021 at 07:27:49AM +0800, Jin Yao wrote:
SNIP
Quoted 67 lines
tools/perf/Documentation/perf-script.txt +16
-0perf 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.tools/perf/builtin-script.c +2
-0@@ -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,tools/perf/util/event.c +18
-0@@ -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,
tools/perf/util/event.c int machine__resolve(struct machine *machine, struct addr_location *al, · line 739
Quoted 10 lines
tools/perf/util/event.c +10
-0+ 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
Hi Jiri,
Quoted 19 lines · Jiri Olsa
Quoted 6 lines
tools/perf/util/event.c +2
-0@@ -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,tools/perf/util/event.c int machine__resolve(struct machine *machine, struct addr_location *al, · line 739
Quoted 10 lines
tools/perf/util/event.c +10
-0+ 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
Quoted 5 lines
we could move all 'address' entries from
sym_listto new intlist (insymbol__init) and use it for this searchjirka
intlist now only supports 'int' type.
I'm considering to use 'long' to replace original 'int' in struct int_node.
struct int_node {
struct rb_node rb_node;
- int i;
+ long i;
void *priv;
};On 32 bits platform, sizeof(long) is 4, and on 64 bits platform, sizeof(long) is 8. So that should be OK for storing the values such as pid/tid and address.
I'm not very clear why currently it uses 'int' for i in struct int_node, maybe something I don't understand correctly. Please correct me if my understanding is wrong.
Thanks
Jin Yao
Arnaldo Carvalho de Melo
maintainerEm Thu, Jan 28, 2021 at 11:31:26AM +0800, Jin, Yao escreveu:
Quoted 33 lines · Jiri Olsa
Quoted 18 lines
Quoted 5 lines
tools/perf/util/event.c +2
-0@@ -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,tools/perf/util/event.c int machine__resolve(struct machine *machine, struct addr_location *al, · line 738
Quoted 10 lines
tools/perf/util/event.c +10
-0+ 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
Quoted 2 lines
we could move all 'address' entries from
sym_listto new intlist (insymbol__init) and use it for this searchintlist now only supports 'int' type.
I'm considering to use 'long' to replace original 'int' in struct
int_node.struct int_node { struct rb_node rb_node;(quoted diff) +1
-1- int i; + long i;void *priv; };
Quoted 7 lines
On 32 bits platform, sizeof(long) is 4, and on 64 bits platform, sizeof(long) is 8. So that should be OK for storing the values such as pid/tid and address.
I'm not very clear why currently it uses 'int' for i in struct
int_node, maybe something I don't understand correctly. Please correct me if my understanding is wrong.
I think its ok to make it a long, it won't even enlarge the struct because:
[acme@quaco pahole]$ pahole -C int_node ~/bin/perf
struct int_node {
struct rb_node rb_node __attribute__((__aligned__(8))); /* 0 24 */
int i; /* 24 4 */
/* XXX 4 bytes hole, try to pack */
void * priv; /* 32 8 */
/* size: 40, cachelines: 1, members: 3 */
/* sum members: 36, holes: 1, sum holes: 4 */
/* forced alignments: 1 */
/* last cacheline: 40 bytes */
} __attribute__((__aligned__(8)));[acme@quaco pahole]$
:-)
- Arnaldo
Quoted 59 lines · Arnaldo Carvalho de Melo
Em Thu, Jan 28, 2021 at 11:31:26AM +0800, Jin, Yao escreveu:
Quoted 33 lines · Jiri Olsa
Quoted 18 lines
Quoted 5 lines
tools/perf/util/event.c +2
-0@@ -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,tools/perf/util/event.c int machine__resolve(struct machine *machine, struct addr_location *al, · line 738
Quoted 10 lines
tools/perf/util/event.c +10
-0+ 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
Quoted 2 lines
we could move all 'address' entries from
sym_listto new intlist (insymbol__init) and use it for this searchintlist now only supports 'int' type.
I'm considering to use 'long' to replace original 'int' in struct
int_node.struct int_node { struct rb_node rb_node;(quoted diff) +1
-1- int i; + long i;void *priv; };Quoted 7 lines
On 32 bits platform, sizeof(long) is 4, and on 64 bits platform, sizeof(long) is 8. So that should be OK for storing the values such as pid/tid and address.
I'm not very clear why currently it uses 'int' for i in struct
int_node, maybe something I don't understand correctly. Please correct me if my understanding is wrong.I think its ok to make it a long, it won't even enlarge the struct because:
[acme@quaco pahole]$ pahole -C
int_node~/bin/perfstruct int_node { struct rb_node rb_node __attribute__((__aligned__(8))); /* 0 24 */ int i; /* 24 4 */ /* XXX 4 bytes hole, try to pack */ void * priv; /* 32 8 */ /* size: 40, cachelines: 1, members: 3 */ /* sum members: 36, holes: 1, sum holes: 4 */ /* forced alignments: 1 */ /* last cacheline: 40 bytes */ } __attribute__((__aligned__(8)));
Quoted 6 lines
[acme@quaco pahole]$
:-)
- Arnaldo
Thanks Arnaldo!
OK, let me try to improve the intlist.
Thanks
Jin Yao