perf record: Use %ld for long type sample counter
PATCH 1/4 perf record: Use %ld for long type sample counter
Since we post-process and count (long rec->samples) to show precise number of samples instead of estimate on (u64 rec->bytes_written), the format string of that should be changed to %ld accordingly, otherwise the value don't show right on 32bit machine.
Before this patch:
$ perf record -e syscalls:sys_enter_write -- dd if=/dev/zero of=/dev/null bs=4k count=1000 1000+0 records in 1000+0 records out [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.077 MB perf.data (1 samples) ]
After this patch:
$ perf record -e syscalls:sys_enter_write -- dd if=/dev/zero of=/dev/null bs=4k count=1000 1000+0 records in 1000+0 records out [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.077 MB perf.data (1001 samples) ]
--- tools/perf/builtin-record.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-record.c +1 -1
@@ -737,7 +737,7 @@ out_child:if (rec->samples && !rec->opts.full_auxtrace)scnprintf (samples,sizeof (samples), -" (%" PRIu64" samples)" , rec->samples); +" (%ld samples)" , rec->samples);else samples[0 ] ='\0' ;
Signature · 1 line
1.8.5.2
PATCH 2/4 perf probe: Fix failure to probe online module
Kernel module has the type DSO_TYPE_USER, the check on dso type in kernel_get_module_dso() disable openning debuginfo of online kernel modules.
Problem can be reproduced as:
$ insmod test_bpf.ko
$ perf probe -v -m test_bpf --add='skb_is_nonlinear'
probe-definition(0): skb_is_nonlinear
symbol:skb_is_nonlinear file:(null) line:0 offset:0 return:0 lazy:(null) 0 arguments
Failed to find module test_bpf.
Could not open debuginfo. Try to use symbols.
Failed to find symbol skb_is_nonlinear in test_bpf
Error: Failed to add events. Reason: No such file or directory (Code: -2)
Infact kernel_get_module_dso() function is called in perf-probe, in this condition, machine->dsos list contains only dsos which is either kmod or kernel loaded by machine__create_kernel_maps(), so there's no need to pick away the non-kmod user type dsos.
This patch removes the check.
After this patch:
$ perf probe -v -m test_bpf --add='skb_is_nonlinear'
probe-definition(0): skb_is_nonlinear symbol:skb_is_nonlinear file:(null) line:0 offset:0 return:0 lazy:(null) 0 arguments
Open Debuginfo file: /lib/modules/4.1.0+/test_bpf.ko
Try to find probe point from debuginfo.
Matched function: skb_is_nonlinear
found inline addr: 0x10ab3
Probe point found: test_bpf_init+585
Found 1 probe_trace_events.
Opening /sys/kernel/debug/tracing/kprobe_events write=1 Added new event:
Writing event: p:probe/skb_is_nonlinear test_bpf:test_bpf_init+585
probe:skb_is_nonlinear (on skb_is_nonlinear in test_bpf)
You can now use it in all perf tools, such as:
perf record -e probe:skb_is_nonlinear -aR sleep 1
--- tools/perf/util/probe-event.c | 2 -- 1 file changed, 2 deletions(-)
tools/perf/util/probe-event.c +0 -2
@@ -275,8 +275,6 @@ static int kernel_get_module_dso(const char *module, struct dso **pdso)if (module) {list_for_each_entry (dso, &host_machine->dsos.head, node) { -if (!dso->kernel) -continue ;if (strncmp (dso->short_name +1 , module, dso->short_name_len -2 ) ==0 ) goto found;
Signature · 1 line
1.8.5.2
Re: [PATCH 2/4] perf probe: Fix failure to probe online module
Quoted 43 lines · He Kuang
Kernel module has the type
DSO_TYPE_USER, the check on dso type inkernel_get_module_dso()disable openning debuginfo of online kernel modules.Problem can be reproduced as:
$ insmod test_bpf.ko$ perf probe -v -m test_bpf --add='skb_is_nonlinear'probe-definition(0):
skb_is_nonlinear
symbol:skb_is_nonlinear file:(null) line:0 offset:0 return:0 lazy:(null) 0 arguments
Failed to find moduletest_bpf.
Could not open debuginfo. Try to use symbols.
Failed to find symbolskb_is_nonlinearintest_bpf
Error: Failed to add events. Reason: No such file or directory (Code: -2)Infact
kernel_get_module_dso()function is called in perf-probe, in this condition,machine->dsoslist contains only dsos which is either kmod or kernel loaded bymachine__create_kernel_maps(), so there's no need to pick away the non-kmod user type dsos.This patch removes the check.
After this patch:
$ perf probe -v -m test_bpf --add='skb_is_nonlinear'probe-definition(0):
skb_is_nonlinearsymbol:skb_is_nonlinear file:(null) line:0 offset:0 return:0 lazy:(null) 0 arguments
Open Debuginfo file:/lib/modules/4.1.0+/test_bpf.ko
Try to find probe point from debuginfo.
Matched function:skb_is_nonlinear
found inline addr:0x10ab3
Probe point found: test_bpf_init+585
Found 1probe_trace_events.
Opening/sys/kernel/debug/tracing/kprobe_eventswrite=1 Added new event:
Writing event: p:probe/skb_is_nonlinear test_bpf:test_bpf_init+585
probe:skb_is_nonlinear (onskb_is_nonlinearintest_bpf)
Quoted 3 lines
You can now use it in all perf tools, such as:
perf record -e probe:skb_is_nonlinear -aR sleep 1
Oops, OK. Without debuginfo, that always fails. I've tested on my machine.
Thank you!
Quoted 20 lines
Signed-off-by He Kuang <[email protected]>--- tools/perf/util/probe-event.c | 2 -- 1 file changed, 2 deletions(-)tools/perf/util/probe-event.c +0
-2@@ -275,8 +275,6 @@ static int kernel_get_module_dso(const char *module, struct dso **pdso)if (module) {list_for_each_entry (dso, &host_machine->dsos.head, node) { -if (!dso->kernel) -continue ;if (strncmp (dso->short_name +1 , module, dso->short_name_len -2 ) ==0 ) goto found;
Signature · 5 lines
Masami HIRAMATSU Linux Technology Research Center, System Productivity Research Dept. Center for Technology Innovation - Systems Engineering Hitachi, Ltd., Research & Development Group E-mail: [email protected]
PATCH 3/4 perf probe: Enable --range option according to libdw version
In reply to He KuangThe option --range uses functions in libdw (elfutils version >= 1.57), this patch check if elfutils version meets the requirements before enable this feature, so that perf can be built with old libdw.
--- tools/perf/builtin-probe.c | 2 ++ tools/perf/util/dwarf-aux.c | 2 ++ tools/perf/util/dwarf-aux.h | 13 ++++++++++++- 3 files changed, 16 insertions(+), 1 deletion(-)
tools/perf/builtin-probe.c +2 -0
@@ -372,8 +372,10 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused) "Show accessible variables on PROBEDEF", opt_show_vars), OPT_BOOLEAN('\0', "externs", &probe_conf.show_ext_vars, "Show external variables too (with --vars only)"), +#if _ELFUTILS_PREREQ (0 ,157 )OPT_BOOLEAN ('\0' ,"range" , &probe_conf.show_location_range,"Show variables location range in scope (with --vars only)" ), +#endifOPT_STRING ('k' ,"vmlinux" , &symbol_conf.vmlinux_name,"file" ,"vmlinux pathname" ), OPT_STRING('s', "source", &symbol_conf.source_prefix,
tools/perf/util/dwarf-aux.c +2 -0
@@ -950,6 +950,7 @@ int die_get_varname(Dwarf_Die *vr_die, struct strbuf *buf)return 0 ; } +#if _ELFUTILS_PREREQ (0 ,157 )/** * die_get_var_innermost_scope - Get innermost scope range of given variable DIE * @sp_die: a subprogram DIE
@@ -1071,3 +1072,4 @@ int die_get_var_range(Dwarf_Die *sp_die, Dwarf_Die *vr_die, struct strbuf *buf) return ret; } +#endif /* _ELFUTILS_PREREQ(0, 157) */
tools/perf/util/dwarf-aux.h +12 -1
@@ -125,6 +125,17 @@ extern int die_get_typename(Dwarf_Die *vr_die, struct strbuf *buf);/* Get the name and type of given variable DIE, stored as "type\tname" */ extern int die_get_varname (Dwarf_Die *vr_die,struct strbuf *buf); +#if _ELFUTILS_PREREQ (0 ,157 )extern int die_get_var_range (Dwarf_Die *sp_die,Dwarf_Die *vr_die, -struct strbuf *buf); +struct strbuf *buf); +#else +static inline +int die_get_var_range (Dwarf_Die *sp_die__maybe_unused , +Dwarf_Die *vr_die__maybe_unused , +struct strbuf *buf__maybe_unused ) +{ +return -ENOTSUP ; +} + +#endif /* _ELFUTILS_PREREQ(0, 157) */ #endif
Signature · 1 line
1.8.5.2
Re: [PATCH 3/4] perf probe: Enable --range option according to libdw version
Quoted 3 lines · He Kuang
The option --range uses functions in libdw (elfutils version >= 1.57), this patch check if elfutils version meets the requirements before enable this feature, so that perf can be built with old libdw.
Is that related to any libdw bug ? or you need to use newer API? Please tell us more precise report or actual URL/bug number.
Thank you,
Quoted 65 lines
Reported-by Alexei Starovoitov <[email protected]>Signed-off-by He Kuang <[email protected]>--- tools/perf/builtin-probe.c | 2 ++ tools/perf/util/dwarf-aux.c | 2 ++ tools/perf/util/dwarf-aux.h | 13 ++++++++++++- 3 files changed, 16 insertions(+), 1 deletion(-)tools/perf/builtin-probe.c +2
-0@@ -372,8 +372,10 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused) "Show accessible variables on PROBEDEF", opt_show_vars), OPT_BOOLEAN('\0', "externs", &probe_conf.show_ext_vars, "Show external variables too (with --vars only)"), +#if _ELFUTILS_PREREQ (0 ,157 )OPT_BOOLEAN ('\0' ,"range" , &probe_conf.show_location_range,"Show variables location range in scope (with --vars only)" ), +#endifOPT_STRING ('k' ,"vmlinux" , &symbol_conf.vmlinux_name,"file" ,"vmlinux pathname" ), OPT_STRING('s', "source", &symbol_conf.source_prefix,tools/perf/util/dwarf-aux.c +2
-0@@ -950,6 +950,7 @@ int die_get_varname(Dwarf_Die *vr_die, struct strbuf *buf)return 0 ; } +#if _ELFUTILS_PREREQ (0 ,157 )/** * die_get_var_innermost_scope - Get innermost scope range of given variable DIE * @sp_die: a subprogram DIE @@ -1071,3 +1072,4 @@ int die_get_var_range(Dwarf_Die *sp_die, Dwarf_Die *vr_die, struct strbuf *buf) return ret; } +#endif /* _ELFUTILS_PREREQ(0, 157) */ tools/perf/util/dwarf-aux.h +12
-1@@ -125,6 +125,17 @@ extern int die_get_typename(Dwarf_Die *vr_die, struct strbuf *buf);/* Get the name and type of given variable DIE, stored as "type\tname" */ extern int die_get_varname (Dwarf_Die *vr_die,struct strbuf *buf); +#if _ELFUTILS_PREREQ (0 ,157 )extern int die_get_var_range (Dwarf_Die *sp_die,Dwarf_Die *vr_die, -struct strbuf *buf); +struct strbuf *buf); +#else +static inline +int die_get_var_range (Dwarf_Die *sp_die__maybe_unused , +Dwarf_Die *vr_die__maybe_unused , +struct strbuf *buf__maybe_unused ) +{ +return -ENOTSUP ; +} + +#endif /* _ELFUTILS_PREREQ(0, 157) */ #endif
Signature · 5 lines
Masami HIRAMATSU Linux Technology Research Center, System Productivity Research Dept. Center for Technology Innovation - Systems Engineering Hitachi, Ltd., Research & Development Group E-mail: [email protected]
PATCH 4/4 perf probe: Add failure check when show variable range
In reply to He KuangChange improper type size_t to diffptr_t to make consistent with libdw and handle error code.
--- tools/perf/util/dwarf-aux.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
tools/perf/util/dwarf-aux.c +8 -2
@@ -965,7 +965,7 @@ static int die_get_var_innermost_scope(Dwarf_Die *sp_die, Dwarf_Die *vr_die, {Dwarf_Die *scopes;int count; -size_t offset =0 ; +ptrdiff_t offset =0 ;Dwarf_Addr base;Dwarf_Addr start, end;Dwarf_Addr entry;
@@ -991,6 +991,9 @@ static int die_get_var_innermost_scope(Dwarf_Die *sp_die, Dwarf_Die *vr_die,while ((offset =dwarf_ranges (&scopes[1 ], offset, &base, &start, &end)) >0 ) { +if (offset <0 ) + goto out; + start -= entry; end -= entry;
@@ -1029,7 +1032,7 @@ int die_get_var_range(Dwarf_Die *sp_die, Dwarf_Die *vr_die, struct strbuf *buf)Dwarf_Addr entry;Dwarf_Op *op;size_t nops; -size_t offset =0 ; +ptrdiff_t offset =0 ;Dwarf_Attribute attr;bool first = true;const char *name;
@@ -1048,6 +1051,9 @@ int die_get_var_range(Dwarf_Die *sp_die, Dwarf_Die *vr_die, struct strbuf *buf)while ((offset =dwarf_getlocations ( &attr, offset, &base, &start, &end, &op, &nops)) >0 ) { +if (offset <0 ) +return offset; +if (start ==0 ) {/* Single Location Descriptions */ ret =die_get_var_innermost_scope (sp_die, vr_die, buf);
Signature · 1 line
1.8.5.2
Re: [PATCH 4/4] perf probe: Add failure check when show variable range
Quoted 22 lines · He Kuang
Change improper type
size_ttodiffptr_tto make consistent with libdw and handle error code.Signed-off-by He Kuang <[email protected]>--- tools/perf/util/dwarf-aux.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)tools/perf/util/dwarf-aux.c +1
-1@@ -965,7 +965,7 @@ static int die_get_var_innermost_scope(Dwarf_Die *sp_die, Dwarf_Die *vr_die, {Dwarf_Die *scopes;int count; -size_t offset =0 ; +ptrdiff_t offset =0 ;Dwarf_Addr base;Dwarf_Addr start, end;Dwarf_Addr entry;
tools/perf/util/dwarf-aux.c static int die_get_var_innermost_scope(Dwarf_Die *sp_die, Dwarf_Die *vr_die, · line 995
Quoted 5 lines
tools/perf/util/dwarf-aux.c +2
-0@@ -991,6 +991,9 @@ static int die_get_var_innermost_scope(Dwarf_Die *sp_die, Dwarf_Die *vr_die,while ((offset =dwarf_ranges (&scopes[1 ], offset, &base, &start, &end)) >0 ) { +if (offset <0 ) + goto out;
Hmm, here offset always > 0, see the condition carefully. Perhaps, this should be placed at the right after the while loop.
Quoted 14 lines
tools/perf/util/dwarf-aux.c +2
-1+ start -= entry; end -= entry;@@ -1029,7 +1032,7 @@ int die_get_var_range(Dwarf_Die *sp_die, Dwarf_Die *vr_die, struct strbuf *buf)Dwarf_Addr entry;Dwarf_Op *op;size_t nops; -size_t offset =0 ; +ptrdiff_t offset =0 ;Dwarf_Attribute attr;bool first = true;const char *name;
tools/perf/util/dwarf-aux.c int die_get_var_range(Dwarf_Die *sp_die, Dwarf_Die *vr_die, struct strbuf *buf) · line 1055
Quoted 5 lines
tools/perf/util/dwarf-aux.c +2
-0@@ -1048,6 +1051,9 @@ int die_get_var_range(Dwarf_Die *sp_die, Dwarf_Die *vr_die, struct strbuf *buf)while ((offset =dwarf_getlocations ( &attr, offset, &base, &start, &end, &op, &nops)) >0 ) { +if (offset <0 ) +return offset;
Ditto.
Thanks,
Quoted 5 lines
tools/perf/util/dwarf-aux.c +1
-0+if (start ==0 ) {/* Single Location Descriptions */ ret =die_get_var_innermost_scope (sp_die, vr_die, buf);
Signature · 5 lines
Masami HIRAMATSU Linux Technology Research Center, System Productivity Research Dept. Center for Technology Innovation - Systems Engineering Hitachi, Ltd., Research & Development Group E-mail: [email protected]
PATCH v2 1/2 perf probe: Enable --range option according to libdw version
The option --range uses function dwarf_getlocations() which was first introduced to libdw in elfutils version 0.157. Without this API, there's no easy way to get locations ranges by the givin attribute.
This patch check if elfutils version meets the requirements before enable this feature, so that perf can be built with old libdw.
--- tools/perf/builtin-probe.c | 2 ++ tools/perf/util/dwarf-aux.c | 2 ++ tools/perf/util/dwarf-aux.h | 13 ++++++++++++- 3 files changed, 16 insertions(+), 1 deletion(-)
tools/perf/builtin-probe.c +2 -0
@@ -372,8 +372,10 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused) "Show accessible variables on PROBEDEF", opt_show_vars), OPT_BOOLEAN('\0', "externs", &probe_conf.show_ext_vars, "Show external variables too (with --vars only)"), +#if _ELFUTILS_PREREQ (0 ,157 )OPT_BOOLEAN ('\0' ,"range" , &probe_conf.show_location_range,"Show variables location range in scope (with --vars only)" ), +#endifOPT_STRING ('k' ,"vmlinux" , &symbol_conf.vmlinux_name,"file" ,"vmlinux pathname" ), OPT_STRING('s', "source", &symbol_conf.source_prefix,
tools/perf/util/dwarf-aux.c +2 -0
@@ -950,6 +950,7 @@ int die_get_varname(Dwarf_Die *vr_die, struct strbuf *buf)return 0 ; } +#if _ELFUTILS_PREREQ (0 ,157 )/** * die_get_var_innermost_scope - Get innermost scope range of given variable DIE * @sp_die: a subprogram DIE
@@ -1071,3 +1072,4 @@ int die_get_var_range(Dwarf_Die *sp_die, Dwarf_Die *vr_die, struct strbuf *buf) return ret; } +#endif /* _ELFUTILS_PREREQ(0, 157) */
tools/perf/util/dwarf-aux.h +12 -1
@@ -125,6 +125,17 @@ extern int die_get_typename(Dwarf_Die *vr_die, struct strbuf *buf);/* Get the name and type of given variable DIE, stored as "type\tname" */ extern int die_get_varname (Dwarf_Die *vr_die,struct strbuf *buf); +#if _ELFUTILS_PREREQ (0 ,157 )extern int die_get_var_range (Dwarf_Die *sp_die,Dwarf_Die *vr_die, -struct strbuf *buf); +struct strbuf *buf); +#else +static inline +int die_get_var_range (Dwarf_Die *sp_die__maybe_unused , +Dwarf_Die *vr_die__maybe_unused , +struct strbuf *buf__maybe_unused ) +{ +return -ENOTSUP ; +} + +#endif /* _ELFUTILS_PREREQ(0, 157) */ #endif
Signature · 1 line
1.8.5.2
PATCH v2 2/2 perf probe: Add failure check when show variable range
Change improper type size_t to diffptr_t to make consistent with libdw and handle error code.
--- tools/perf/util/dwarf-aux.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
tools/perf/util/dwarf-aux.c +11 -2
@@ -965,7 +965,7 @@ static int die_get_var_innermost_scope(Dwarf_Die *sp_die, Dwarf_Die *vr_die, {Dwarf_Die *scopes;int count; -size_t offset =0 ; +ptrdiff_t offset =0 ;Dwarf_Addr base;Dwarf_Addr start, end;Dwarf_Addr entry;
@@ -991,6 +991,7 @@ static int die_get_var_innermost_scope(Dwarf_Die *sp_die, Dwarf_Die *vr_die,while ((offset =dwarf_ranges (&scopes[1 ], offset, &base, &start, &end)) >0 ) { + start -= entry; end -= entry;
@@ -1004,6 +1005,11 @@ static int die_get_var_innermost_scope(Dwarf_Die *sp_die, Dwarf_Die *vr_die, } } +if (offset <0 ) { + ret = -EINVAL ; + goto out; + } +if (!first)strbuf_addf (buf,"]>" );
@@ -1029,7 +1035,7 @@ int die_get_var_range(Dwarf_Die *sp_die, Dwarf_Die *vr_die, struct strbuf *buf)Dwarf_Addr entry;Dwarf_Op *op;size_t nops; -size_t offset =0 ; +ptrdiff_t offset =0 ;Dwarf_Attribute attr;bool first = true;const char *name;
@@ -1067,6 +1073,9 @@ int die_get_var_range(Dwarf_Die *sp_die, Dwarf_Die *vr_die, struct strbuf *buf) } } +if (offset <0 ) +return -EINVAL ; +if (!first)strbuf_addf (buf,"]>" );
Signature · 1 line
1.8.5.2
Re: [PATCH 4/4] perf probe: Add failure check when show variable range
In reply to Masami Hiramatsuhi, Masami
Quoted 24 lines · Masami Hiramatsu
Quoted 23 lines · He Kuang
Change improper type
size_ttodiffptr_tto make consistent with libdw and handle error code.Signed-off-by He Kuang <[email protected]>--- tools/perf/util/dwarf-aux.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)tools/perf/util/dwarf-aux.c +1
-1@@ -965,7 +965,7 @@ static int die_get_var_innermost_scope(Dwarf_Die *sp_die, Dwarf_Die *vr_die, {Dwarf_Die *scopes;int count; -size_t offset =0 ; +ptrdiff_t offset =0 ;Dwarf_Addr base;Dwarf_Addr start, end;Dwarf_Addr entry;@@ -991,6 +991,9 @@ static int die_get_var_innermost_scope(Dwarf_Die *sp_die, Dwarf_Die *vr_die,
Quoted 7 lines
tools/perf/util/dwarf-aux.c static int die_get_var_innermost_scope(Dwarf_Die *sp_die, Dwarf_Die *vr_die, · line 995
Quoted 4 lines
tools/perf/util/dwarf-aux.c +2
-0while ((offset =dwarf_ranges (&scopes[1 ], offset, &base, &start, &end)) >0 ) { +if (offset <0 ) + goto out;Hmm, here offset always > 0, see the condition carefully. Perhaps, this should be placed at the right after the while loop.
Sorry for this silly mistake. Modified and resent with patch 3/4, more info is added in commit message of that patch.
Thank you.
Quoted 32 lines
Quoted 15 lines
tools/perf/util/dwarf-aux.c +2
-1+ start -= entry; end -= entry;@@ -1029,7 +1032,7 @@ int die_get_var_range(Dwarf_Die *sp_die, Dwarf_Die *vr_die, struct strbuf *buf)Dwarf_Addr entry;Dwarf_Op *op;size_t nops; -size_t offset =0 ; +ptrdiff_t offset =0 ;Dwarf_Attribute attr;bool first = true;const char *name;tools/perf/util/dwarf-aux.c int die_get_var_range(Dwarf_Die *sp_die, Dwarf_Die *vr_die, struct strbuf *buf) · line 1055
Quoted 5 lines
tools/perf/util/dwarf-aux.c +2
-0@@ -1048,6 +1051,9 @@ int die_get_var_range(Dwarf_Die *sp_die, Dwarf_Die *vr_die, struct strbuf *buf)while ((offset =dwarf_getlocations ( &attr, offset, &base, &start, &end, &op, &nops)) >0 ) { +if (offset <0 ) +return offset;Ditto.
Thanks,
Quoted 5 lines
tools/perf/util/dwarf-aux.c +1
-0+if (start ==0 ) {/* Single Location Descriptions */ ret =die_get_var_innermost_scope (sp_die, vr_die, buf);