perf probe: add kernel source path option
PATCH RESEND v2 1/1 perf probe: add kernel source path option
The probe plugin requires access to the source code for some operations. The source code must be in the exact same location as specified by the DWARF tags, but sometimes the location is an absolute path that cannot be replicated by a normal user. This change adds the -s|--source option to allow the user to specify the root of the kernel source tree.
--- tools/perf/Documentation/perf-probe.txt | 4 ++ tools/perf/builtin-probe.c | 2 + tools/perf/util/probe-finder.c | 58 +++++++++++++++++++++++++++++-- tools/perf/util/symbol.h | 1 + 4 files changed, 62 insertions(+), 3 deletions(-)
tools/perf/Documentation/perf-probe.txt +4 -0
@@ -31,6 +31,10 @@ OPTIONS --vmlinux=PATH:: Specify vmlinux path which has debuginfo (Dwarf binary). +-s:: +--source=PATH:: + Specify path to kernel source. + -v:: --verbose:: Be more verbose (show parsed arguments, etc).
tools/perf/builtin-probe.c +2 -0
@@ -182,6 +182,8 @@ static const struct option options[] = { "Show source code lines.", opt_show_lines),OPT_STRING ('k' ,"vmlinux" , &symbol_conf.vmlinux_name,"file" ,"vmlinux pathname" ), +OPT_STRING ('s' ,"source" , &symbol_conf.source_prefix, +"directory" ,"path to kernel source" ), #endifOPT__DRY_RUN (&probe_event_dry_run), OPT_INTEGER('\0', "max-probes", ¶ms.max_probe_points,
tools/perf/util/probe-finder.c +55 -3
78 lines not on this page · raw message
tools/perf/util/symbol.h +1 -0
@@ -71,6 +71,7 @@ struct symbol_conf { full_paths, show_cpu_utilization;const char *vmlinux_name, + *source_prefix, *field_sep;const char *default_guest_vmlinux_name, *default_guest_kallsyms,
Signature · 1 line
1.7.0.4
Em Mon, Jun 14, 2010 at 03:26:30PM -0400, Chase Douglas escreveu:
Quoted 7 lines
The probe plugin requires access to the source code for some operations. The source code must be in the exact same location as specified by the DWARF tags, but sometimes the location is an absolute path that cannot be replicated by a normal user. This change adds the -s|--source option to allow the user to specify the root of the kernel source tree.
Signed-off-by Chase Douglas <[email protected]>
Thanks, I saw it but didn't manage to test it yet, will try probably tomorrow.
- Arnaldo
Quoted 5 lines · Chase Douglas
The probe plugin requires access to the source code for some operations. The source code must be in the exact same location as specified by the DWARF tags, but sometimes the location is an absolute path that cannot be replicated by a normal user. This change adds the -s|--source option to allow the user to specify the root of the kernel source tree.
Thanks, it looks very good to me :) and works!
Thank you,
Quoted 134 lines
Signed-off-by Chase Douglas <[email protected]>--- tools/perf/Documentation/perf-probe.txt | 4 ++ tools/perf/builtin-probe.c | 2 + tools/perf/util/probe-finder.c | 58 +++++++++++++++++++++++++++++-- tools/perf/util/symbol.h | 1 + 4 files changed, 62 insertions(+), 3 deletions(-)tools/perf/Documentation/perf-probe.txt +4
-0@@ -31,6 +31,10 @@ OPTIONS --vmlinux=PATH:: Specify vmlinux path which has debuginfo (Dwarf binary). +-s:: +--source=PATH:: + Specify path to kernel source. + -v:: --verbose:: Be more verbose (show parsed arguments, etc).tools/perf/builtin-probe.c +2
-0@@ -182,6 +182,8 @@ static const struct option options[] = { "Show source code lines.", opt_show_lines),OPT_STRING ('k' ,"vmlinux" , &symbol_conf.vmlinux_name,"file" ,"vmlinux pathname" ), +OPT_STRING ('s' ,"source" , &symbol_conf.source_prefix, +"directory" ,"path to kernel source" ), #endifOPT__DRY_RUN (&probe_event_dry_run), OPT_INTEGER('\0', "max-probes", ¶ms.max_probe_points,tools/perf/util/probe-finder.c +55
-3@@ -37,6 +37,7 @@#include "event.h" #include "debug.h" #include "util.h" +#include "symbol.h" #include "probe-finder.h" /* Kprobe tracer basic type is up to u64 */ @@ -57,6 +58,55 @@ static int strtailcmp(const char *s1, const char *s2)return 0 ; } +/* +* Find a src file from a DWARF tag path. Prepend optional source path prefix +* and chop off leading directories that do not exist. Result is passed back as +* a newly allocated path on success. +* Return 0 if file was found and readable, -errno otherwise. +*/ +static int get_real_path (const char *raw_path,char **new_path) +{ +if (!symbol_conf.source_prefix) { +if (access (raw_path,R_OK ) ==0 ) { + *new_path =strdup (raw_path); +return 0 ; + }else +return -errno; + } + + *new_path =malloc (strlen (symbol_conf.source_prefix) + +strlen (raw_path) +2 ); +if (!*new_path) +return -ENOMEM ; + +for (;;) { +sprintf (*new_path,"%s/%s" , symbol_conf.source_prefix, + raw_path); + +if (access (*new_path,R_OK ) ==0 ) +return 0 ; + +switch (errno) { +case ENAMETOOLONG : +case ENOENT : +case EROFS : +case EFAULT : + raw_path =strchr (++raw_path,'/' ); +if (!raw_path) { +free (*new_path); + *new_path =NULL ; +return -ENOENT ; + } +continue ; + +default : +free (*new_path); + *new_path =NULL ; +return -errno; + } + } +} +/* Line number list operations */ /* Add a line to line number list */ @@ -1096,11 +1146,13 @@ end:static int line_range_add_line (const char *src,unsigned int lineno,struct line_range *lr) { +int ret; +/* Copy real path */ if (!lr->path) { - lr->path =strdup (src); -if (lr->path ==NULL ) -return -ENOMEM ; + ret =get_real_path (src, &lr->path); +if (ret !=0 ) +return ret; }return line_list__add_line (&lr->line_list, lineno); }tools/perf/util/symbol.h +1
-0@@ -71,6 +71,7 @@ struct symbol_conf { full_paths, show_cpu_utilization;const char *vmlinux_name, + *source_prefix, *field_sep;const char *default_guest_vmlinux_name, *default_guest_kallsyms,
Corrected Masami-san address,
Em Mon, Jun 14, 2010 at 03:26:30PM -0400, Chase Douglas escreveu:
Quoted 7 lines
The probe plugin requires access to the source code for some operations. The source code must be in the exact same location as specified by the DWARF tags, but sometimes the location is an absolute path that cannot be replicated by a normal user. This change adds the -s|--source option to allow the user to specify the root of the kernel source tree.
Signed-off-by Chase Douglas <[email protected]>
Just tested it, works as advertised:
[root@emilia mingo]# perf probe -L __schedule | head -22
Debuginfo analysis failed. (-2)
Error: Failed to show lines. (-2)
[root@emilia mingo]# perf probe -s /usr/src/debug/kernel-rt-2.6.33.4-rt20.19.el5rt/linux-2.6.33.4.x86_64 -L __schedule | head -22 <__schedule:0>
0 {
struct task_struct *prev, *next;
unsigned long *switch_count;
struct rq *rq;
int cpu;
6 cpu = smp_processor_id();
7 rq = cpu_rq(cpu);
8 rcu_sched_qs(cpu);
9 prev = rq->curr;
10 switch_count = &prev->nivcsw;
12 release_kernel_lock(prev);
schedule_debug(prev);
16 preempt_disable();
18 if (sched_feat(HRTICK))
19 hrtick_clear(rq);[root@emilia mingo]# cat /sys/kernel/debug/sched_featuresFAIR_SLEEPERS GENTLE_FAIR_SLEEPERS NO_NORMALIZED_SLEEPER START_DEBIT WAKEUP_PREEMPT ADAPTIVE_GRAN ASYM_GRAN NO_WAKEUP_SYNC NO_WAKEUP_OVERLAP SYNC_WAKEUPS AFFINE_WAKEUPS SYNC_LESS NO_SYNC_MORE NO_NEXT_BUDDY LAST_BUDDY CACHE_HOT_BUDDY NO_ARCH_POWER NO_HRTICK NO_DOUBLE_TICK LB_BIAS LB_SHARES_UPDATE ASYM_EFF_LOAD OWNER_SPIN [root@emilia mingo]# perf probe __schedule:19
Add new event:
probe:__schedule (on __schedule:19)
You can now use it on all perf tools, such as:
perf record -e probe:__schedule -aR sleep 1
[root@emilia mingo]# perf record -e probe:__schedule -aR sleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.061 MB perf.data (~2684 samples) ]
[root@emilia mingo]# perf report | head -15
#
# (For a higher level overview, try: perf report --sort comm,dso)
#
[root@emilia mingo]# echo HRTICK > /sys/kernel/debug/sched_features
[root@emilia mingo]# cat /sys/kernel/debug/sched_featuresFAIR_SLEEPERS GENTLE_FAIR_SLEEPERS NO_NORMALIZED_SLEEPER START_DEBIT WAKEUP_PREEMPT ADAPTIVE_GRAN ASYM_GRAN NO_WAKEUP_SYNC NO_WAKEUP_OVERLAP SYNC_WAKEUPS AFFINE_WAKEUPS SYNC_LESS NO_SYNC_MORE NO_NEXT_BUDDY LAST_BUDDY CACHE_HOT_BUDDY NO_ARCH_POWER HRTICK NO_DOUBLE_TICK LB_BIAS LB_SHARES_UPDATE ASYM_EFF_LOAD OWNER_SPIN [root@emilia mingo]# perf record -e probe:__schedule -aR sleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 1.528 MB perf.data (~66766 samples) ]
[root@emilia mingo]# perf report | head -15
# Events: 19K cycles
#
# Overhead Command Shared Object Symbol
# ........ ............... .................. ......
#
38.42% init 0 [k] 0000000000000000
5.42% sirq-timer/0 [kernel.kallsyms] [k] kernel_thread_helper
5.41% sirq-timer/5 [kernel.kallsyms] [k] kernel_thread_helper
5.41% sirq-timer/4 [kernel.kallsyms] [k] kernel_thread_helper
5.41% sirq-timer/3 [kernel.kallsyms] [k] kernel_thread_helper
5.41% sirq-timer/2 [kernel.kallsyms] [k] kernel_thread_helper
5.41% sirq-timer/1 [kernel.kallsyms] [k] kernel_thread_helper
5.40% sirq-timer/7 [kernel.kallsyms] [k] kernel_thread_helper
5.40% sirq-timer/6 [kernel.kallsyms] [k] kernel_thread_helper
5.26% swapper 0 [k] 0000000000000000
[root@emilia mingo]#Really cool stuff, thanks for your patch and to Masami for his amazing work on 'perf probe'.
I think we should look at usual places like debuginfo packages and /usr/src/linux-uname, ~/git/linux-2.6/, etc, but that is something for a follow on patch.
Best Regards,
- Arnaldo
[tip:perf/core] perf probe: Add kernel source path option
In reply to Chase DouglasCommit-ID: 9ed7e1b85cd55dc46cb9410a23086bdaa2ff3eb9 Gitweb: http://git.kernel.org/tip/9ed7e1b85cd55dc46cb9410a23086bdaa2ff3eb9 Author: Chase Douglas <[email protected]> AuthorDate: Mon, 14 Jun 2010 15:26:30 -0400 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 17 Jun 2010 10:27:57 -0300
perf probe: Add kernel source path option
The probe plugin requires access to the source code for some operations. The source code must be in the exact same location as specified by the DWARF tags, but sometimes the location is an absolute path that cannot be replicated by a normal user. This change adds the -s|--source option to allow the user to specify the root of the kernel source tree.
Cc: Ingo Molnar <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Masami Hiramatsu <[email protected]>
LKML-Reference: <[email protected]>
--- tools/perf/Documentation/perf-probe.txt | 4 ++ tools/perf/builtin-probe.c | 2 + tools/perf/util/probe-finder.c | 58 +++++++++++++++++++++++++++++-- tools/perf/util/symbol.h | 1 + 4 files changed, 62 insertions(+), 3 deletions(-)
tools/perf/Documentation/perf-probe.txt +4 -0
@@ -31,6 +31,10 @@ OPTIONS --vmlinux=PATH:: Specify vmlinux path which has debuginfo (Dwarf binary). +-s:: +--source=PATH:: + Specify path to kernel source. + -v:: --verbose:: Be more verbose (show parsed arguments, etc).
tools/perf/builtin-probe.c +2 -0
@@ -182,6 +182,8 @@ static const struct option options[] = { "Show source code lines.", opt_show_lines),OPT_STRING ('k' ,"vmlinux" , &symbol_conf.vmlinux_name,"file" ,"vmlinux pathname" ), +OPT_STRING ('s' ,"source" , &symbol_conf.source_prefix, +"directory" ,"path to kernel source" ), #endifOPT__DRY_RUN (&probe_event_dry_run), OPT_INTEGER('\0', "max-probes", ¶ms.max_probe_points,
tools/perf/util/probe-finder.c +55 -3
78 lines not on this page · raw message
tools/perf/util/symbol.h +1 -0
@@ -71,6 +71,7 @@ struct symbol_conf { full_paths, show_cpu_utilization;const char *vmlinux_name, + *source_prefix, *field_sep;const char *default_guest_vmlinux_name, *default_guest_kallsyms,