perf probe: export get_real_path
PATCH 1/2 perf probe: export get_real_path
Export it to use from util/probe-finder.c
--- tools/perf/util/probe-event.c | 2 +- tools/perf/util/probe-event.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
tools/perf/util/probe-event.c +1 -1
@@ -520,7 +520,7 @@ static int try_to_find_probe_trace_events(struct perf_probe_event *pev,* 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,const char *comp_dir, +int get_real_path (const char *raw_path,const char *comp_dir,char **new_path) {const char *prefix = symbol_conf.source_prefix;
tools/perf/util/probe-event.h +2 -0
@@ -135,6 +135,8 @@ extern int show_available_vars(struct perf_probe_event *pevs, int npevs, struct strfilter *filter, bool externs);extern int show_available_funcs (const char *module,struct strfilter *filter,bool user); +extern int get_real_path (const char *raw_path,const char *comp_dir, +char **new_path);/* Maximum index number of event-name postfix */ #define MAX_EVENT_INDEX 1024
Signature · 1 line
2.3.0
PATCH 2/2 perf probe: Find compilation directory path for lazy matching
If we use lazy matching, it failed to open a souce file if perf command is invoked outside of compilation directory:
$ perf probe -a '__schedule;clear_*' Failed to open kernel/sched/core.c: No such file or directory Error: Failed to add events. (-2)
OTOH, other commands like "probe -L" can solve the souce directory by themselves. Let's make it possible for lazy matching too!
--- tools/perf/util/probe-finder.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
tools/perf/util/probe-finder.c +14 -1
@@ -39,6 +39,7 @@#include "util.h" #include "symbol.h" #include "probe-finder.h" +#include "probe-event.h" /* Kprobe tracer basic type is up to u64 */ #define MAX_BASIC_TYPE_BITS 64
@@ -849,11 +850,23 @@ static int probe_point_lazy_walker(const char *fname, int lineno,static int find_probe_point_lazy (Dwarf_Die *sp_die,struct probe_finder *pf) {int ret =0 ; +char *fpath;if (intlist__empty (pf->lcache)) { +const char *comp_dir; + + comp_dir =cu_get_comp_dir (&pf->cu_die); + ret =get_real_path (pf->fname, comp_dir, &fpath); +if (ret <0 ) { +free (fpath); +pr_warning ("Failed to find source file path.\n" ); +return ret; + } +/* Matching lazy line pattern */ - ret =find_lazy_match_lines (pf->lcache, pf->fname, + ret =find_lazy_match_lines (pf->lcache, fpath, pf->pev->point.lazy_line); +free (fpath);if (ret <=0 )return ret; }
Signature · 1 line
2.3.0
Re: [PATCH 2/2] perf probe: Find compilation directory path for lazy matching
Quoted 30 lines · Naohiro Aota
If we use lazy matching, it failed to open a souce file if perf command is invoked outside of compilation directory:
$ perf probe -a '__schedule;clear_*' Failed to open kernel/sched/core.c: No such file or directory Error: Failed to add events. (-2)OTOH, other commands like "probe -L" can solve the souce directory by themselves. Let's make it possible for lazy matching too!
Signed-off-by Naohiro Aota <[email protected]>--- tools/perf/util/probe-finder.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)tools/perf/util/probe-finder.c +1
-0@@ -39,6 +39,7 @@#include "util.h" #include "symbol.h" #include "probe-finder.h" +#include "probe-event.h" /* Kprobe tracer basic type is up to u64 */ #define MAX_BASIC_TYPE_BITS 64@@ -849,11 +850,23 @@ static int probe_point_lazy_walker(const char *fname, int lineno,static int find_probe_point_lazy (Dwarf_Die *sp_die,struct probe_finder *pf) {
tools/perf/util/probe-finder.c static int probe_point_lazy_walker(const char *fname, int lineno, · line 861
Quoted 10 lines
tools/perf/util/probe-finder.c +7
-0int ret =0 ; +char *fpath;if (intlist__empty (pf->lcache)) { +const char *comp_dir; + + comp_dir =cu_get_comp_dir (&pf->cu_die); + ret =get_real_path (pf->fname, comp_dir, &fpath); +if (ret <0 ) { +free (fpath);
Here, if the get_real_path is failed, fpath should be freed before returning. If not, there is a bug, and yeah, there is a bug...
Thank you!
Quoted 13 lines
tools/perf/util/probe-finder.c +6
-1+pr_warning ("Failed to find source file path.\n" ); +return ret; + } +/* Matching lazy line pattern */ - ret =find_lazy_match_lines (pf->lcache, pf->fname, + ret =find_lazy_match_lines (pf->lcache, fpath, pf->pev->point.lazy_line); +free (fpath);if (ret <=0 )return ret; }
Signature · 4 lines
Masami HIRAMATSU Software Platform Research Dept. Linux Technology Research Center Hitachi, Ltd., Yokohama Research Laboratory E-mail: [email protected]
PATCH 1/1 perf-probe: Fix get_real_path to free allocated memory in error path
Fix get_real_path to free allocated memory when comp_dir is used for complementing path and getting an error.
--- tools/perf/util/probe-event.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/util/probe-event.c +3 -1
@@ -549,9 +549,11 @@ static int get_real_path(const char *raw_path, const char *comp_dir,if (access (*new_path,R_OK ) ==0 )return 0 ; -if (!symbol_conf.source_prefix) +if (!symbol_conf.source_prefix) {/* In case of searching comp_dir, don't retry */ +zfree (new_path);return -errno; + }switch (errno) {case ENAMETOOLONG :
Arnaldo Carvalho de Melo
maintainerRe: [PATCH perf/core ] [BUGFIX] perf-probe: Fix get_real_path to free allocated memory in error path
Em Thu, Feb 26, 2015 at 05:25:04PM +0900, Masami Hiramatsu escreveu:
Quoted 2 lines
Fix
get_real_pathto free allocated memory whencomp_diris used for complementing path and getting an error.
While reviewing this patch I noticed this is needed, ack?
- Arnaldo
tools/perf/util/probe-event.c +1 -1
@@ -533,7 +533,7 @@ static int get_real_path(const char *raw_path, const char *comp_dir,else {if (access (raw_path,R_OK ) ==0 ) { *new_path =strdup (raw_path); -return 0 ; +return *new_path ?0 : -ENOMEM ; }else return -errno; }
Masami Hiramatsu
Acked-byRe: [PATCH perf/core ] [BUGFIX] perf-probe: Fix get_real_path to free allocated memory in error path
Quoted 6 lines · Arnaldo Carvalho de Melo
Em Thu, Feb 26, 2015 at 05:25:04PM +0900, Masami Hiramatsu escreveu:
Quoted 2 lines
Fix
get_real_pathto free allocated memory whencomp_diris used for complementing path and getting an error.While reviewing this patch I noticed this is needed, ack?
Ah, right!
Thank you,
Quoted 18 lines
- Arnaldo
tools/perf/util/probe-event.c +1
-1@@ -533,7 +533,7 @@ static int get_real_path(const char *raw_path, const char *comp_dir,else {if (access (raw_path,R_OK ) ==0 ) { *new_path =strdup (raw_path); -return 0 ; +return *new_path ?0 : -ENOMEM ; }else return -errno; }
Signature · 4 lines
Masami HIRAMATSU Software Platform Research Dept. Linux Technology Research Center Hitachi, Ltd., Yokohama Research Laboratory E-mail: [email protected]
tip-bot for Masami Hiramatsu
merge bot[tip:perf/core] perf probe: Fix get_real_path to free allocated memory in error path
In reply to Masami Hiramatsuperf probe: Fix get_real_path to free allocated memory in error path
Commit-ID: eb47cb2eb22dfacac9689708f5bd3cb0e975e290 Gitweb: http://git.kernel.org/tip/eb47cb2eb22dfacac9689708f5bd3cb0e975e290 Author: Masami Hiramatsu <[email protected]> AuthorDate: Thu, 26 Feb 2015 17:25:04 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 26 Feb 2015 11:59:05 -0300
perf probe: Fix get_real_path to free allocated memory in error path
Fix get_real_path to free allocated memory when comp_dir is used for complementing path and getting an error.
--- tools/perf/util/probe-event.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/util/probe-event.c +3 -1
@@ -549,9 +549,11 @@ static int get_real_path(const char *raw_path, const char *comp_dir,if (access (*new_path,R_OK ) ==0 )return 0 ; -if (!symbol_conf.source_prefix) +if (!symbol_conf.source_prefix) {/* In case of searching comp_dir, don't retry */ +zfree (new_path);return -errno; + }switch (errno) {case ENAMETOOLONG :
Quoted 1 line · Naohiro Aota
Export it to use from
util/probe-finder.c
Please fold this in to the next patch, since this exported symbol is not used until applying the next one.
BTW, since get_real_path is compiled only when HAVE_DWARF_SUPPORT=y, we can also move it into probe-finder.c.
Could you also move it into probe-finder.c and export it at probe-finder.h?
Thank you,
Quoted 34 lines
Signed-off-by Naohiro Aota <[email protected]>--- tools/perf/util/probe-event.c | 2 +- tools/perf/util/probe-event.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)tools/perf/util/probe-event.c +1
-1@@ -520,7 +520,7 @@ static int try_to_find_probe_trace_events(struct perf_probe_event *pev,* 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,const char *comp_dir, +int get_real_path (const char *raw_path,const char *comp_dir,char **new_path) {const char *prefix = symbol_conf.source_prefix;tools/perf/util/probe-event.h +2
-0@@ -135,6 +135,8 @@ extern int show_available_vars(struct perf_probe_event *pevs, int npevs, struct strfilter *filter, bool externs);extern int show_available_funcs (const char *module,struct strfilter *filter,bool user); +extern int get_real_path (const char *raw_path,const char *comp_dir, +char **new_path);/* Maximum index number of event-name postfix */ #define MAX_EVENT_INDEX 1024
Signature · 4 lines
Masami HIRAMATSU Software Platform Research Dept. Linux Technology Research Center Hitachi, Ltd., Yokohama Research Laboratory E-mail: [email protected]
PATCH v2 1/1 perf probe: Find compilation directory path for lazy matching
In reply to Naohiro AotaIf we use lazy matching, it failed to open a souce file if perf command is invoked outside of compilation directory:
$ perf probe -a '__schedule;clear_*' Failed to open kernel/sched/core.c: No such file or directory Error: Failed to add events. (-2)
OTOH, other commands like "probe -L" can solve the souce directory by themselves. Let's make it possible for lazy matching too!
--- tools/perf/util/probe-event.c | 59 ----------------------------------- tools/perf/util/probe-finder.c | 71 +++++++++++++++++++++++++++++++++++++++++- tools/perf/util/probe-finder.h | 4 +++ 3 files changed, 74 insertions(+), 60 deletions(-)
tools/perf/util/probe-event.c +0 -59
@@ -515,65 +515,6 @@ static int try_to_find_probe_trace_events(struct perf_probe_event *pev,return ntevs; } -/* -* 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,const char *comp_dir, -char **new_path) -{ -const char *prefix = symbol_conf.source_prefix; - -if (!prefix) { -if (raw_path[0 ] !='/' && comp_dir) -/* If not an absolute path, try to use comp_dir */ - prefix = comp_dir; -else { -if (access (raw_path,R_OK ) ==0 ) { - *new_path =strdup (raw_path); -return *new_path ?0 : -ENOMEM ; - }else -return -errno; - } - } - - *new_path =malloc ((strlen (prefix) +strlen (raw_path) +2 )); -if (!*new_path) -return -ENOMEM ; - -for (;;) { -sprintf (*new_path,"%s/%s" , prefix, raw_path); - -if (access (*new_path,R_OK ) ==0 ) -return 0 ; - -if (!symbol_conf.source_prefix) { -/* In case of searching comp_dir, don't retry */ -zfree (new_path); -return -errno; - } - -switch (errno) { -case ENAMETOOLONG : -case ENOENT : -case EROFS : -case EFAULT : - raw_path =strchr (++raw_path,'/' ); -if (!raw_path) { -zfree (new_path); -return -ENOENT ; - } -continue ; - -default : -zfree (new_path); -return -errno; - } - } -} -#define LINEBUF_SIZE 256#define NR_ADDITIONAL_LINES 2
tools/perf/util/probe-finder.c +70 -1
84 lines not on this page · raw message
tools/perf/util/probe-finder.h +4 -0
@@ -55,6 +55,10 @@ extern int debuginfo__find_available_vars_at(struct debuginfo *dbg,struct variable_list **vls, int max_points, bool externs); +/* Find a src file from a DWARF tag path */ +extern int get_real_path (const char *raw_path,const char *comp_dir, +char **new_path); +struct probe_finder {struct perf_probe_event *pev;/* Target probe event */
Signature · 1 line
2.3.1
Re: [PATCH v2] perf probe: Find compilation directory path for lazy matching
Quoted 10 lines · Naohiro Aota
If we use lazy matching, it failed to open a souce file if perf command is invoked outside of compilation directory:
$ perf probe -a '__schedule;clear_*' Failed to open kernel/sched/core.c: No such file or directory Error: Failed to add events. (-2)OTOH, other commands like "probe -L" can solve the souce directory by themselves. Let's make it possible for lazy matching too!
Looks good to me :)
Thank you!
Quoted 183 lines
Signed-off-by Naohiro Aota <[email protected]>--- tools/perf/util/probe-event.c | 59 ----------------------------------- tools/perf/util/probe-finder.c | 71 +++++++++++++++++++++++++++++++++++++++++- tools/perf/util/probe-finder.h | 4 +++ 3 files changed, 74 insertions(+), 60 deletions(-)tools/perf/util/probe-event.c +0
-59@@ -515,65 +515,6 @@ static int try_to_find_probe_trace_events(struct perf_probe_event *pev,return ntevs; } -/* -* 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,const char *comp_dir, -char **new_path) -{ -const char *prefix = symbol_conf.source_prefix; - -if (!prefix) { -if (raw_path[0 ] !='/' && comp_dir) -/* If not an absolute path, try to use comp_dir */ - prefix = comp_dir; -else { -if (access (raw_path,R_OK ) ==0 ) { - *new_path =strdup (raw_path); -return *new_path ?0 : -ENOMEM ; - }else -return -errno; - } - } - - *new_path =malloc ((strlen (prefix) +strlen (raw_path) +2 )); -if (!*new_path) -return -ENOMEM ; - -for (;;) { -sprintf (*new_path,"%s/%s" , prefix, raw_path); - -if (access (*new_path,R_OK ) ==0 ) -return 0 ; - -if (!symbol_conf.source_prefix) { -/* In case of searching comp_dir, don't retry */ -zfree (new_path); -return -errno; - } - -switch (errno) { -case ENAMETOOLONG : -case ENOENT : -case EROFS : -case EFAULT : - raw_path =strchr (++raw_path,'/' ); -if (!raw_path) { -zfree (new_path); -return -ENOENT ; - } -continue ; - -default : -zfree (new_path); -return -errno; - } - } -} -#define LINEBUF_SIZE 256#define NR_ADDITIONAL_LINES 2tools/perf/util/probe-finder.c +70
-1@@ -849,11 +849,22 @@ static int probe_point_lazy_walker(const char *fname, int lineno,static int find_probe_point_lazy (Dwarf_Die *sp_die,struct probe_finder *pf) {int ret =0 ; +char *fpath;if (intlist__empty (pf->lcache)) { +const char *comp_dir; + + comp_dir =cu_get_comp_dir (&pf->cu_die); + ret =get_real_path (pf->fname, comp_dir, &fpath); +if (ret <0 ) { +pr_warning ("Failed to find source file path.\n" ); +return ret; + } +/* Matching lazy line pattern */ - ret =find_lazy_match_lines (pf->lcache, pf->fname, + ret =find_lazy_match_lines (pf->lcache, fpath, pf->pev->point.lazy_line); +free (fpath);if (ret <=0 )return ret; }@@ -1616,3 +1627,61 @@ found:return (ret <0 ) ? ret : lf.found; } +/* +* 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,const char *comp_dir, +char **new_path) +{ +const char *prefix = symbol_conf.source_prefix; + +if (!prefix) { +if (raw_path[0 ] !='/' && comp_dir) +/* If not an absolute path, try to use comp_dir */ + prefix = comp_dir; +else { +if (access (raw_path,R_OK ) ==0 ) { + *new_path =strdup (raw_path); +return *new_path ?0 : -ENOMEM ; + }else +return -errno; + } + } + + *new_path =malloc ((strlen (prefix) +strlen (raw_path) +2 )); +if (!*new_path) +return -ENOMEM ; + +for (;;) { +sprintf (*new_path,"%s/%s" , prefix, raw_path); + +if (access (*new_path,R_OK ) ==0 ) +return 0 ; + +if (!symbol_conf.source_prefix) { +/* In case of searching comp_dir, don't retry */ +zfree (new_path); +return -errno; + } + +switch (errno) { +case ENAMETOOLONG : +case ENOENT : +case EROFS : +case EFAULT : + raw_path =strchr (++raw_path,'/' ); +if (!raw_path) { +zfree (new_path); +return -ENOENT ; + } +continue ; + +default : +zfree (new_path); +return -errno; + } + } +}tools/perf/util/probe-finder.h +4
-0@@ -55,6 +55,10 @@ extern int debuginfo__find_available_vars_at(struct debuginfo *dbg,struct variable_list **vls, int max_points, bool externs); +/* Find a src file from a DWARF tag path */ +extern int get_real_path (const char *raw_path,const char *comp_dir, +char **new_path); +struct probe_finder {struct perf_probe_event *pev;/* Target probe event */
Signature · 4 lines
Masami HIRAMATSU Software Platform Research Dept. Linux Technology Research Center Hitachi, Ltd., Yokohama Research Laboratory E-mail: [email protected]
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v2] perf probe: Find compilation directory path for lazy matching
Em Wed, Mar 04, 2015 at 09:34:38PM +0900, Masami Hiramatsu escreveu:
Quoted 8 lines
Quoted 7 lines · Naohiro Aota
If we use lazy matching, it failed to open a souce file if perf command is invoked outside of compilation directory:
$ perf probe -a '__schedule;clear_*' Failed to open kernel/sched/core.c: No such file or directory Error: Failed to add events. (-2)
Quoted 7 lines
Quoted 3 lines
OTOH, other commands like "probe -L" can solve the souce directory by themselves. Let's make it possible for lazy matching too!
Looks good to me :)
Acked-by Masami Hiramatsu <[email protected]>
This doesn't make sense... se below:
Quoted 34 lines
Thank you!
Quoted 32 lines
tools/perf/util/probe-finder.c +12
-1@@ -849,11 +849,22 @@ static int probe_point_lazy_walker(const char *fname, int lineno,static int find_probe_point_lazy (Dwarf_Die *sp_die,struct probe_finder *pf) {int ret =0 ; +char *fpath;if (intlist__empty (pf->lcache)) { +const char *comp_dir; + + comp_dir =cu_get_comp_dir (&pf->cu_die); + ret =get_real_path (pf->fname, comp_dir, &fpath); +if (ret <0 ) { +pr_warning ("Failed to find source file path.\n" ); +return ret; + } +/* Matching lazy line pattern */ - ret =find_lazy_match_lines (pf->lcache, pf->fname, + ret =find_lazy_match_lines (pf->lcache, fpath, pf->pev->point.lazy_line); +free (fpath);if (ret <=0 )return ret; }@@ -1616,3 +1627,61 @@ found:return (ret <0 ) ? ret : lf.found; }
Quoted 8 lines
tools/perf/util/probe-finder.c found: · line 1637
Quoted 8 lines
tools/perf/util/probe-finder.c +8
-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,const char *comp_dir, +char **new_path)
The function is marked "static"
Quoted 58 lines
Quoted 58 lines
tools/perf/util/probe-finder.c +50
-0+{ +const char *prefix = symbol_conf.source_prefix; + +if (!prefix) { +if (raw_path[0 ] !='/' && comp_dir) +/* If not an absolute path, try to use comp_dir */ + prefix = comp_dir; +else { +if (access (raw_path,R_OK ) ==0 ) { + *new_path =strdup (raw_path); +return *new_path ?0 : -ENOMEM ; + }else +return -errno; + } + } + + *new_path =malloc ((strlen (prefix) +strlen (raw_path) +2 )); +if (!*new_path) +return -ENOMEM ; + +for (;;) { +sprintf (*new_path,"%s/%s" , prefix, raw_path); + +if (access (*new_path,R_OK ) ==0 ) +return 0 ; + +if (!symbol_conf.source_prefix) { +/* In case of searching comp_dir, don't retry */ +zfree (new_path); +return -errno; + } + +switch (errno) { +case ENAMETOOLONG : +case ENOENT : +case EROFS : +case EFAULT : + raw_path =strchr (++raw_path,'/' ); +if (!raw_path) { +zfree (new_path); +return -ENOENT ; + } +continue ; + +default : +zfree (new_path); +return -errno; + } + } +}tools/perf/util/probe-finder.h +0
-0@@ -55,6 +55,10 @@ extern int debuginfo__find_available_vars_at(struct debuginfo *dbg,struct variable_list **vls, int max_points, bool externs);
Quoted 4 lines
tools/perf/util/probe-finder.h extern int debuginfo__find_available_vars_at(struct debuginfo *dbg, · line 61
Quoted 4 lines
tools/perf/util/probe-finder.h +4
-0+/* Find a src file from a DWARF tag path */ +extern int get_real_path (const char *raw_path,const char *comp_dir, +char **new_path); +
And then you mark it "extern"? Have you tried to compile this? I tried:
CC /tmp/build/perf/tests/task-exit.outil/probe-finder.c:1636:12: error: static declaration of ‘get_real_path’ follows non-static declaration
static int get_real_path(const char *raw_path, const char *comp_dir,
^
In file included from util/probe-finder.c:41:0:
util/probe-finder.h:59:12: note: previous declaration of ‘get_real_path’ was here
extern int get_real_path(const char *raw_path, const char *comp_dir,
^
util/probe-finder.c:1636:12: error: ‘get_real_path’ defined but not used [-Werror=unused-function]
static int get_real_path(const char *raw_path, const char *comp_dir,
^cc1: all warnings being treated as errors make[3]: *** [/tmp/build/perf/util/probe-finder.o] Error 1 make[3]: *** Waiting for unfinished jobs....
CC /tmp/build/perf/tests/sw-clock.o
Also please refrain from using 'extern' in front of function prototypes, its just noise.
- Arnaldo
Quoted 12 lines
Quoted 4 lines
tools/perf/util/probe-finder.h +0
-0struct probe_finder {struct perf_probe_event *pev;/* Target probe event */ Signature · 4 lines
Masami HIRAMATSU Software Platform Research Dept. Linux Technology Research Center Hitachi, Ltd., Yokohama Research Laboratory E-mail: [email protected]
Re: Re: [PATCH v2] perf probe: Find compilation directory path for lazy matching
Quoted 140 lines · Arnaldo Carvalho de Melo
Em Wed, Mar 04, 2015 at 09:34:38PM +0900, Masami Hiramatsu escreveu:
Quoted 8 lines
Quoted 7 lines · Naohiro Aota
If we use lazy matching, it failed to open a souce file if perf command is invoked outside of compilation directory:
$ perf probe -a '__schedule;clear_*' Failed to open kernel/sched/core.c: No such file or directory Error: Failed to add events. (-2)Quoted 7 lines
Quoted 3 lines
OTOH, other commands like "probe -L" can solve the souce directory by themselves. Let's make it possible for lazy matching too!
Looks good to me :)
Acked-by Masami Hiramatsu <[email protected]>This doesn't make sense... se below:
Quoted 34 lines
Thank you!
Quoted 32 lines
tools/perf/util/probe-finder.c +12
-1@@ -849,11 +849,22 @@ static int probe_point_lazy_walker(const char *fname, int lineno,static int find_probe_point_lazy (Dwarf_Die *sp_die,struct probe_finder *pf) {int ret =0 ; +char *fpath;if (intlist__empty (pf->lcache)) { +const char *comp_dir; + + comp_dir =cu_get_comp_dir (&pf->cu_die); + ret =get_real_path (pf->fname, comp_dir, &fpath); +if (ret <0 ) { +pr_warning ("Failed to find source file path.\n" ); +return ret; + } +/* Matching lazy line pattern */ - ret =find_lazy_match_lines (pf->lcache, pf->fname, + ret =find_lazy_match_lines (pf->lcache, fpath, pf->pev->point.lazy_line); +free (fpath);if (ret <=0 )return ret; }@@ -1616,3 +1627,61 @@ found:return (ret <0 ) ? ret : lf.found; }Quoted 8 lines
tools/perf/util/probe-finder.c found: · line 1637
Quoted 8 lines
tools/perf/util/probe-finder.c +8
-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,const char *comp_dir, +char **new_path)The function is marked "static"
Quoted 58 lines
Quoted 58 lines
tools/perf/util/probe-finder.c +50
-0+{ +const char *prefix = symbol_conf.source_prefix; + +if (!prefix) { +if (raw_path[0 ] !='/' && comp_dir) +/* If not an absolute path, try to use comp_dir */ + prefix = comp_dir; +else { +if (access (raw_path,R_OK ) ==0 ) { + *new_path =strdup (raw_path); +return *new_path ?0 : -ENOMEM ; + }else +return -errno; + } + } + + *new_path =malloc ((strlen (prefix) +strlen (raw_path) +2 )); +if (!*new_path) +return -ENOMEM ; + +for (;;) { +sprintf (*new_path,"%s/%s" , prefix, raw_path); + +if (access (*new_path,R_OK ) ==0 ) +return 0 ; + +if (!symbol_conf.source_prefix) { +/* In case of searching comp_dir, don't retry */ +zfree (new_path); +return -errno; + } + +switch (errno) { +case ENAMETOOLONG : +case ENOENT : +case EROFS : +case EFAULT : + raw_path =strchr (++raw_path,'/' ); +if (!raw_path) { +zfree (new_path); +return -ENOENT ; + } +continue ; + +default : +zfree (new_path); +return -errno; + } + } +}tools/perf/util/probe-finder.h +0
-0@@ -55,6 +55,10 @@ extern int debuginfo__find_available_vars_at(struct debuginfo *dbg,struct variable_list **vls, int max_points, bool externs);Quoted 4 lines
tools/perf/util/probe-finder.h extern int debuginfo__find_available_vars_at(struct debuginfo *dbg, · line 61
Quoted 4 lines
tools/perf/util/probe-finder.h +4
-0+/* Find a src file from a DWARF tag path */ +extern int get_real_path (const char *raw_path,const char *comp_dir, +char **new_path); +And then you mark it "extern"? Have you tried to compile this? I tried:
CC
/tmp/build/perf/tests/task-exit.outil/probe-finder.c:1636:12: error: static declaration of ‘get_real_path’ follows non-static declaration
static int get_real_path(const char*raw_path, const char*comp_dir,^ In file included from util/probe-finder.c:41:0: util/probe-finder.h:59:12: note: previous declaration of ‘get_real_path’ was here extern int get_real_path(const char *raw_path, const char *comp_dir, ^ util/probe-finder.c:1636:12: error: ‘get_real_path’ defined but not used [-Werror=unused-function] static int get_real_path(const char *raw_path, const char *comp_dir, ^
Quoted 6 lines
cc1: all warnings being treated as errors make[3]: *** [
/tmp/build/perf/util/probe-finder.o] Error 1 make[3]: *** Waiting for unfinished jobs....
CC/tmp/build/perf/tests/sw-clock.oAlso please refrain from using 'extern' in front of function prototypes, its just noise.1
Ooops! Sorry, I missed this ...
Naohiro, could you fix this?
Thanks,
Quoted 21 lines
- Arnaldo
Quoted 12 lines
Quoted 4 lines
tools/perf/util/probe-finder.h +0
-0struct probe_finder {struct perf_probe_event *pev;/* Target probe event */ Signature · 4 lines
Masami HIRAMATSU Software Platform Research Dept. Linux Technology Research Center Hitachi, Ltd., Yokohama Research Laboratory E-mail: [email protected]--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Signature · 4 lines
Masami HIRAMATSU Software Platform Research Dept. Linux Technology Research Center Hitachi, Ltd., Yokohama Research Laboratory E-mail: [email protected]
Re: Re: [PATCH v2] perf probe: Find compilation directory path for lazy matching
Quoted 146 lines · Masami Hiramatsu
Quoted 145 lines · Arnaldo Carvalho de Melo
Em Wed, Mar 04, 2015 at 09:34:38PM +0900, Masami Hiramatsu escreveu:
Quoted 8 lines
Quoted 7 lines · Naohiro Aota
If we use lazy matching, it failed to open a souce file if perf command is invoked outside of compilation directory:
$ perf probe -a '__schedule;clear_*' Failed to open kernel/sched/core.c: No such file or directory Error: Failed to add events. (-2)Quoted 7 lines
Quoted 3 lines
OTOH, other commands like "probe -L" can solve the souce directory by themselves. Let's make it possible for lazy matching too!
Looks good to me :)
Acked-by Masami Hiramatsu <[email protected]>This doesn't make sense... se below:
Quoted 34 lines
Thank you!
Quoted 32 lines
tools/perf/util/probe-finder.c +12
-1@@ -849,11 +849,22 @@ static int probe_point_lazy_walker(const char *fname, int lineno,static int find_probe_point_lazy (Dwarf_Die *sp_die,struct probe_finder *pf) {int ret =0 ; +char *fpath;if (intlist__empty (pf->lcache)) { +const char *comp_dir; + + comp_dir =cu_get_comp_dir (&pf->cu_die); + ret =get_real_path (pf->fname, comp_dir, &fpath); +if (ret <0 ) { +pr_warning ("Failed to find source file path.\n" ); +return ret; + } +/* Matching lazy line pattern */ - ret =find_lazy_match_lines (pf->lcache, pf->fname, + ret =find_lazy_match_lines (pf->lcache, fpath, pf->pev->point.lazy_line); +free (fpath);if (ret <=0 )return ret; }@@ -1616,3 +1627,61 @@ found:return (ret <0 ) ? ret : lf.found; }Quoted 8 lines
tools/perf/util/probe-finder.c found: · line 1637
Quoted 8 lines
tools/perf/util/probe-finder.c +8
-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,const char *comp_dir, +char **new_path)The function is marked "static"
Quoted 58 lines
Quoted 58 lines
tools/perf/util/probe-finder.c +50
-0+{ +const char *prefix = symbol_conf.source_prefix; + +if (!prefix) { +if (raw_path[0 ] !='/' && comp_dir) +/* If not an absolute path, try to use comp_dir */ + prefix = comp_dir; +else { +if (access (raw_path,R_OK ) ==0 ) { + *new_path =strdup (raw_path); +return *new_path ?0 : -ENOMEM ; + }else +return -errno; + } + } + + *new_path =malloc ((strlen (prefix) +strlen (raw_path) +2 )); +if (!*new_path) +return -ENOMEM ; + +for (;;) { +sprintf (*new_path,"%s/%s" , prefix, raw_path); + +if (access (*new_path,R_OK ) ==0 ) +return 0 ; + +if (!symbol_conf.source_prefix) { +/* In case of searching comp_dir, don't retry */ +zfree (new_path); +return -errno; + } + +switch (errno) { +case ENAMETOOLONG : +case ENOENT : +case EROFS : +case EFAULT : + raw_path =strchr (++raw_path,'/' ); +if (!raw_path) { +zfree (new_path); +return -ENOENT ; + } +continue ; + +default : +zfree (new_path); +return -errno; + } + } +}tools/perf/util/probe-finder.h +0
-0@@ -55,6 +55,10 @@ extern int debuginfo__find_available_vars_at(struct debuginfo *dbg,struct variable_list **vls, int max_points, bool externs);Quoted 4 lines
tools/perf/util/probe-finder.h extern int debuginfo__find_available_vars_at(struct debuginfo *dbg, · line 61
Quoted 4 lines
tools/perf/util/probe-finder.h +4
-0+/* Find a src file from a DWARF tag path */ +extern int get_real_path (const char *raw_path,const char *comp_dir, +char **new_path); +And then you mark it "extern"? Have you tried to compile this? I tried:
CC
/tmp/build/perf/tests/task-exit.outil/probe-finder.c:1636:12: error: static declaration of 'get_real_path' follows non-static declaration
static int get_real_path(const char*raw_path, const char*comp_dir,^ In file included from util/probe-finder.c:41:0: util/probe-finder.h:59:12: note: previous declaration of 'get_real_path' was here extern int get_real_path(const char *raw_path, const char *comp_dir, ^ util/probe-finder.c:1636:12: error: 'get_real_path' defined but not used [-Werror=unused-function] static int get_real_path(const char *raw_path, const char *comp_dir, ^cc1: all warnings being treated as errors make[3]: *** [
/tmp/build/perf/util/probe-finder.o] Error 1 make[3]: *** Waiting for unfinished jobs....
CC/tmp/build/perf/tests/sw-clock.o
Quoted 7 lines
Quoted 1 line
Also please refrain from using 'extern' in front of function prototypes, its just noise.1
Ooops! Sorry, I missed this ...
Naohiro, could you fix this?
Thanks,
Ooops, I must have messed the things up during rebasing. I'll soon send fix.
Quoted 31 lines
Quoted 16 lines
- Arnaldo
Quoted 6 lines
tools/perf/util/probe-finder.h extern int debuginfo__find_available_vars_at(struct debuginfo *dbg, · line 64
Quoted 4 lines
tools/perf/util/probe-finder.h +0
-0struct probe_finder {struct perf_probe_event *pev;/* Target probe event */ Quoted 6 lines
--
Masami HIRAMATSU
Software Platform Research Dept. Linux Technology Research Center Hitachi, Ltd., Yokohama Research Laboratory
E-mail: [email protected]Quoted 6 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/--
Masami HIRAMATSU
Software Platform Research Dept. Linux Technology Research Center Hitachi, Ltd., Yokohama Research Laboratory
E-mail: [email protected]
PATCH v3 1/1 perf probe: Find compilation directory path for lazy matching
In reply to Arnaldo Carvalho de MeloIf we use lazy matching, it failed to open a souce file if perf command is invoked outside of compilation directory:
$ perf probe -a '__schedule;clear_*' Failed to open kernel/sched/core.c: No such file or directory Error: Failed to add events. (-2)
OTOH, other commands like "probe -L" can solve the souce directory by themselves. Let's make it possible for lazy matching too!
--- tools/perf/util/probe-event.c | 59 ----------------------------------- tools/perf/util/probe-finder.c | 71 +++++++++++++++++++++++++++++++++++++++++- tools/perf/util/probe-finder.h | 4 +++ 3 files changed, 74 insertions(+), 60 deletions(-)
tools/perf/util/probe-event.c +0 -59
@@ -648,65 +648,6 @@ static int try_to_find_probe_trace_events(struct perf_probe_event *pev,return ntevs; } -/* -* 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,const char *comp_dir, -char **new_path) -{ -const char *prefix = symbol_conf.source_prefix; - -if (!prefix) { -if (raw_path[0 ] !='/' && comp_dir) -/* If not an absolute path, try to use comp_dir */ - prefix = comp_dir; -else { -if (access (raw_path,R_OK ) ==0 ) { - *new_path =strdup (raw_path); -return *new_path ?0 : -ENOMEM ; - }else -return -errno; - } - } - - *new_path =malloc ((strlen (prefix) +strlen (raw_path) +2 )); -if (!*new_path) -return -ENOMEM ; - -for (;;) { -sprintf (*new_path,"%s/%s" , prefix, raw_path); - -if (access (*new_path,R_OK ) ==0 ) -return 0 ; - -if (!symbol_conf.source_prefix) { -/* In case of searching comp_dir, don't retry */ -zfree (new_path); -return -errno; - } - -switch (errno) { -case ENAMETOOLONG : -case ENOENT : -case EROFS : -case EFAULT : - raw_path =strchr (++raw_path,'/' ); -if (!raw_path) { -zfree (new_path); -return -ENOENT ; - } -continue ; - -default : -zfree (new_path); -return -errno; - } - } -} -#define LINEBUF_SIZE 256#define NR_ADDITIONAL_LINES 2
tools/perf/util/probe-finder.c +70 -1
84 lines not on this page · raw message
tools/perf/util/probe-finder.h +4 -0
@@ -55,6 +55,10 @@ extern int debuginfo__find_available_vars_at(struct debuginfo *dbg,struct variable_list **vls, int max_points, bool externs); +/* Find a src file from a DWARF tag path */ +int get_real_path (const char *raw_path,const char *comp_dir, +char **new_path); +struct probe_finder {struct perf_probe_event *pev;/* Target probe event */
Signature · 1 line
2.3.1
Re: [PATCH v3] perf probe: Find compilation directory path for lazy matching
Quoted 10 lines · Naohiro Aota
If we use lazy matching, it failed to open a souce file if perf command is invoked outside of compilation directory:
$ perf probe -a '__schedule;clear_*' Failed to open kernel/sched/core.c: No such file or directory Error: Failed to add events. (-2)OTOH, other commands like "probe -L" can solve the souce directory by themselves. Let's make it possible for lazy matching too!
Ok, I've built and tested it.
----
[mhiramat@localhost opt]$ sudo /home/mhiramat/ksrc/linux-3/tools/perf/perf probe -fna '__schedule;clear_*' Added new event:
probe:__schedule (on __schedule)
You can now use it in all perf tools, such as:
perf record -e probe:__schedule -aR sleep 1
----
So now it can go :)
Thank you!
Quoted 183 lines
Signed-off-by Naohiro Aota <[email protected]>--- tools/perf/util/probe-event.c | 59 ----------------------------------- tools/perf/util/probe-finder.c | 71 +++++++++++++++++++++++++++++++++++++++++- tools/perf/util/probe-finder.h | 4 +++ 3 files changed, 74 insertions(+), 60 deletions(-)tools/perf/util/probe-event.c +0
-59@@ -648,65 +648,6 @@ static int try_to_find_probe_trace_events(struct perf_probe_event *pev,return ntevs; } -/* -* 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,const char *comp_dir, -char **new_path) -{ -const char *prefix = symbol_conf.source_prefix; - -if (!prefix) { -if (raw_path[0 ] !='/' && comp_dir) -/* If not an absolute path, try to use comp_dir */ - prefix = comp_dir; -else { -if (access (raw_path,R_OK ) ==0 ) { - *new_path =strdup (raw_path); -return *new_path ?0 : -ENOMEM ; - }else -return -errno; - } - } - - *new_path =malloc ((strlen (prefix) +strlen (raw_path) +2 )); -if (!*new_path) -return -ENOMEM ; - -for (;;) { -sprintf (*new_path,"%s/%s" , prefix, raw_path); - -if (access (*new_path,R_OK ) ==0 ) -return 0 ; - -if (!symbol_conf.source_prefix) { -/* In case of searching comp_dir, don't retry */ -zfree (new_path); -return -errno; - } - -switch (errno) { -case ENAMETOOLONG : -case ENOENT : -case EROFS : -case EFAULT : - raw_path =strchr (++raw_path,'/' ); -if (!raw_path) { -zfree (new_path); -return -ENOENT ; - } -continue ; - -default : -zfree (new_path); -return -errno; - } - } -} -#define LINEBUF_SIZE 256#define NR_ADDITIONAL_LINES 2tools/perf/util/probe-finder.c +70
-1@@ -849,11 +849,22 @@ static int probe_point_lazy_walker(const char *fname, int lineno,static int find_probe_point_lazy (Dwarf_Die *sp_die,struct probe_finder *pf) {int ret =0 ; +char *fpath;if (intlist__empty (pf->lcache)) { +const char *comp_dir; + + comp_dir =cu_get_comp_dir (&pf->cu_die); + ret =get_real_path (pf->fname, comp_dir, &fpath); +if (ret <0 ) { +pr_warning ("Failed to find source file path.\n" ); +return ret; + } +/* Matching lazy line pattern */ - ret =find_lazy_match_lines (pf->lcache, pf->fname, + ret =find_lazy_match_lines (pf->lcache, fpath, pf->pev->point.lazy_line); +free (fpath);if (ret <=0 )return ret; }@@ -1616,3 +1627,61 @@ found:return (ret <0 ) ? ret : lf.found; } +/* +* 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. +*/ +int get_real_path (const char *raw_path,const char *comp_dir, +char **new_path) +{ +const char *prefix = symbol_conf.source_prefix; + +if (!prefix) { +if (raw_path[0 ] !='/' && comp_dir) +/* If not an absolute path, try to use comp_dir */ + prefix = comp_dir; +else { +if (access (raw_path,R_OK ) ==0 ) { + *new_path =strdup (raw_path); +return *new_path ?0 : -ENOMEM ; + }else +return -errno; + } + } + + *new_path =malloc ((strlen (prefix) +strlen (raw_path) +2 )); +if (!*new_path) +return -ENOMEM ; + +for (;;) { +sprintf (*new_path,"%s/%s" , prefix, raw_path); + +if (access (*new_path,R_OK ) ==0 ) +return 0 ; + +if (!symbol_conf.source_prefix) { +/* In case of searching comp_dir, don't retry */ +zfree (new_path); +return -errno; + } + +switch (errno) { +case ENAMETOOLONG : +case ENOENT : +case EROFS : +case EFAULT : + raw_path =strchr (++raw_path,'/' ); +if (!raw_path) { +zfree (new_path); +return -ENOENT ; + } +continue ; + +default : +zfree (new_path); +return -errno; + } + } +}tools/perf/util/probe-finder.h +4
-0@@ -55,6 +55,10 @@ extern int debuginfo__find_available_vars_at(struct debuginfo *dbg,struct variable_list **vls, int max_points, bool externs); +/* Find a src file from a DWARF tag path */ +int get_real_path (const char *raw_path,const char *comp_dir, +char **new_path); +struct probe_finder {struct perf_probe_event *pev;/* Target probe event */
Signature · 4 lines
Masami HIRAMATSU Software Platform Research Dept. Linux Technology Research Center Hitachi, Ltd., Yokohama Research Laboratory E-mail: [email protected]
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v3] perf probe: Find compilation directory path for lazy matching
In reply to Naohiro AotaEm Fri, Mar 13, 2015 at 02:18:40PM +0900, Naohiro Aota escreveu:
Quoted 6 lines
If we use lazy matching, it failed to open a souce file if perf command is invoked outside of compilation directory:
$ perf probe -a '__schedule;clear_*' Failed to open kernel/sched/core.c: No such file or directory Error: Failed to add events. (-2)
Masami, you mean this one, right?
- Arnaldo
Quoted 187 lines
OTOH, other commands like "probe -L" can solve the souce directory by themselves. Let's make it possible for lazy matching too!
Signed-off-by Naohiro Aota <[email protected]>--- tools/perf/util/probe-event.c | 59 ----------------------------------- tools/perf/util/probe-finder.c | 71 +++++++++++++++++++++++++++++++++++++++++- tools/perf/util/probe-finder.h | 4 +++ 3 files changed, 74 insertions(+), 60 deletions(-)tools/perf/util/probe-event.c +0
-59@@ -648,65 +648,6 @@ static int try_to_find_probe_trace_events(struct perf_probe_event *pev,return ntevs; } -/* -* 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,const char *comp_dir, -char **new_path) -{ -const char *prefix = symbol_conf.source_prefix; - -if (!prefix) { -if (raw_path[0 ] !='/' && comp_dir) -/* If not an absolute path, try to use comp_dir */ - prefix = comp_dir; -else { -if (access (raw_path,R_OK ) ==0 ) { - *new_path =strdup (raw_path); -return *new_path ?0 : -ENOMEM ; - }else -return -errno; - } - } - - *new_path =malloc ((strlen (prefix) +strlen (raw_path) +2 )); -if (!*new_path) -return -ENOMEM ; - -for (;;) { -sprintf (*new_path,"%s/%s" , prefix, raw_path); - -if (access (*new_path,R_OK ) ==0 ) -return 0 ; - -if (!symbol_conf.source_prefix) { -/* In case of searching comp_dir, don't retry */ -zfree (new_path); -return -errno; - } - -switch (errno) { -case ENAMETOOLONG : -case ENOENT : -case EROFS : -case EFAULT : - raw_path =strchr (++raw_path,'/' ); -if (!raw_path) { -zfree (new_path); -return -ENOENT ; - } -continue ; - -default : -zfree (new_path); -return -errno; - } - } -} -#define LINEBUF_SIZE 256#define NR_ADDITIONAL_LINES 2tools/perf/util/probe-finder.c +70
-1@@ -849,11 +849,22 @@ static int probe_point_lazy_walker(const char *fname, int lineno,static int find_probe_point_lazy (Dwarf_Die *sp_die,struct probe_finder *pf) {int ret =0 ; +char *fpath;if (intlist__empty (pf->lcache)) { +const char *comp_dir; + + comp_dir =cu_get_comp_dir (&pf->cu_die); + ret =get_real_path (pf->fname, comp_dir, &fpath); +if (ret <0 ) { +pr_warning ("Failed to find source file path.\n" ); +return ret; + } +/* Matching lazy line pattern */ - ret =find_lazy_match_lines (pf->lcache, pf->fname, + ret =find_lazy_match_lines (pf->lcache, fpath, pf->pev->point.lazy_line); +free (fpath);if (ret <=0 )return ret; }@@ -1616,3 +1627,61 @@ found:return (ret <0 ) ? ret : lf.found; } +/* +* 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. +*/ +int get_real_path (const char *raw_path,const char *comp_dir, +char **new_path) +{ +const char *prefix = symbol_conf.source_prefix; + +if (!prefix) { +if (raw_path[0 ] !='/' && comp_dir) +/* If not an absolute path, try to use comp_dir */ + prefix = comp_dir; +else { +if (access (raw_path,R_OK ) ==0 ) { + *new_path =strdup (raw_path); +return *new_path ?0 : -ENOMEM ; + }else +return -errno; + } + } + + *new_path =malloc ((strlen (prefix) +strlen (raw_path) +2 )); +if (!*new_path) +return -ENOMEM ; + +for (;;) { +sprintf (*new_path,"%s/%s" , prefix, raw_path); + +if (access (*new_path,R_OK ) ==0 ) +return 0 ; + +if (!symbol_conf.source_prefix) { +/* In case of searching comp_dir, don't retry */ +zfree (new_path); +return -errno; + } + +switch (errno) { +case ENAMETOOLONG : +case ENOENT : +case EROFS : +case EFAULT : + raw_path =strchr (++raw_path,'/' ); +if (!raw_path) { +zfree (new_path); +return -ENOENT ; + } +continue ; + +default : +zfree (new_path); +return -errno; + } + } +}tools/perf/util/probe-finder.h +4
-0@@ -55,6 +55,10 @@ extern int debuginfo__find_available_vars_at(struct debuginfo *dbg,struct variable_list **vls, int max_points, bool externs); +/* Find a src file from a DWARF tag path */ +int get_real_path (const char *raw_path,const char *comp_dir, +char **new_path); +struct probe_finder {struct perf_probe_event *pev;/* Target probe event */ Signature · 1 line
2.3.1
Re: [PATCH v3] perf probe: Find compilation directory path for lazy matching
Quoted 9 lines · Arnaldo Carvalho de Melo
Em Fri, Mar 13, 2015 at 02:18:40PM +0900, Naohiro Aota escreveu:
Quoted 6 lines
If we use lazy matching, it failed to open a souce file if perf command is invoked outside of compilation directory:
$ perf probe -a '__schedule;clear_*' Failed to open kernel/sched/core.c: No such file or directory Error: Failed to add events. (-2)Masami, you mean this one, right?
Yes, this is what I meant :)
Thank you!
Quoted 191 lines
- Arnaldo
Quoted 187 lines
OTOH, other commands like "probe -L" can solve the souce directory by themselves. Let's make it possible for lazy matching too!
Signed-off-by Naohiro Aota <[email protected]>--- tools/perf/util/probe-event.c | 59 ----------------------------------- tools/perf/util/probe-finder.c | 71 +++++++++++++++++++++++++++++++++++++++++- tools/perf/util/probe-finder.h | 4 +++ 3 files changed, 74 insertions(+), 60 deletions(-)tools/perf/util/probe-event.c +0
-59@@ -648,65 +648,6 @@ static int try_to_find_probe_trace_events(struct perf_probe_event *pev,return ntevs; } -/* -* 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,const char *comp_dir, -char **new_path) -{ -const char *prefix = symbol_conf.source_prefix; - -if (!prefix) { -if (raw_path[0 ] !='/' && comp_dir) -/* If not an absolute path, try to use comp_dir */ - prefix = comp_dir; -else { -if (access (raw_path,R_OK ) ==0 ) { - *new_path =strdup (raw_path); -return *new_path ?0 : -ENOMEM ; - }else -return -errno; - } - } - - *new_path =malloc ((strlen (prefix) +strlen (raw_path) +2 )); -if (!*new_path) -return -ENOMEM ; - -for (;;) { -sprintf (*new_path,"%s/%s" , prefix, raw_path); - -if (access (*new_path,R_OK ) ==0 ) -return 0 ; - -if (!symbol_conf.source_prefix) { -/* In case of searching comp_dir, don't retry */ -zfree (new_path); -return -errno; - } - -switch (errno) { -case ENAMETOOLONG : -case ENOENT : -case EROFS : -case EFAULT : - raw_path =strchr (++raw_path,'/' ); -if (!raw_path) { -zfree (new_path); -return -ENOENT ; - } -continue ; - -default : -zfree (new_path); -return -errno; - } - } -} -#define LINEBUF_SIZE 256#define NR_ADDITIONAL_LINES 2tools/perf/util/probe-finder.c +70
-1@@ -849,11 +849,22 @@ static int probe_point_lazy_walker(const char *fname, int lineno,static int find_probe_point_lazy (Dwarf_Die *sp_die,struct probe_finder *pf) {int ret =0 ; +char *fpath;if (intlist__empty (pf->lcache)) { +const char *comp_dir; + + comp_dir =cu_get_comp_dir (&pf->cu_die); + ret =get_real_path (pf->fname, comp_dir, &fpath); +if (ret <0 ) { +pr_warning ("Failed to find source file path.\n" ); +return ret; + } +/* Matching lazy line pattern */ - ret =find_lazy_match_lines (pf->lcache, pf->fname, + ret =find_lazy_match_lines (pf->lcache, fpath, pf->pev->point.lazy_line); +free (fpath);if (ret <=0 )return ret; }@@ -1616,3 +1627,61 @@ found:return (ret <0 ) ? ret : lf.found; } +/* +* 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. +*/ +int get_real_path (const char *raw_path,const char *comp_dir, +char **new_path) +{ +const char *prefix = symbol_conf.source_prefix; + +if (!prefix) { +if (raw_path[0 ] !='/' && comp_dir) +/* If not an absolute path, try to use comp_dir */ + prefix = comp_dir; +else { +if (access (raw_path,R_OK ) ==0 ) { + *new_path =strdup (raw_path); +return *new_path ?0 : -ENOMEM ; + }else +return -errno; + } + } + + *new_path =malloc ((strlen (prefix) +strlen (raw_path) +2 )); +if (!*new_path) +return -ENOMEM ; + +for (;;) { +sprintf (*new_path,"%s/%s" , prefix, raw_path); + +if (access (*new_path,R_OK ) ==0 ) +return 0 ; + +if (!symbol_conf.source_prefix) { +/* In case of searching comp_dir, don't retry */ +zfree (new_path); +return -errno; + } + +switch (errno) { +case ENAMETOOLONG : +case ENOENT : +case EROFS : +case EFAULT : + raw_path =strchr (++raw_path,'/' ); +if (!raw_path) { +zfree (new_path); +return -ENOENT ; + } +continue ; + +default : +zfree (new_path); +return -errno; + } + } +}tools/perf/util/probe-finder.h +4
-0@@ -55,6 +55,10 @@ extern int debuginfo__find_available_vars_at(struct debuginfo *dbg,struct variable_list **vls, int max_points, bool externs); +/* Find a src file from a DWARF tag path */ +int get_real_path (const char *raw_path,const char *comp_dir, +char **new_path); +struct probe_finder {struct perf_probe_event *pev;/* Target probe event */ Signature · 1 line
2.3.1
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]
tip-bot for Naohiro Aota
merge bot[tip:perf/urgent] perf probe: Find compilation directory path for lazy matching
In reply to Naohiro Aotaperf probe: Find compilation directory path for lazy matching
Commit-ID: 09ed8975c4b13be4469899b210f0e0936021ee8f Gitweb: http://git.kernel.org/tip/09ed8975c4b13be4469899b210f0e0936021ee8f Author: Naohiro Aota <[email protected]> AuthorDate: Fri, 13 Mar 2015 14:18:40 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 13 Apr 2015 20:11:05 -0300
perf probe: Find compilation directory path for lazy matching
If we use lazy matching, it failed to open a souce file if perf command is invoked outside of compilation directory:
$ perf probe -a '__schedule;clear_*' Failed to open kernel/sched/core.c: No such file or directory Error: Failed to add events. (-2)
OTOH, other commands like "probe -L" can solve the souce directory by themselves. Let's make it possible for lazy matching too!
--- tools/perf/util/probe-event.c | 59 ----------------------------------- tools/perf/util/probe-finder.c | 71 +++++++++++++++++++++++++++++++++++++++++- tools/perf/util/probe-finder.h | 4 +++ 3 files changed, 74 insertions(+), 60 deletions(-)
tools/perf/util/probe-event.c +0 -59
@@ -655,65 +655,6 @@ static int try_to_find_probe_trace_events(struct perf_probe_event *pev,return ntevs; } -/* -* 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,const char *comp_dir, -char **new_path) -{ -const char *prefix = symbol_conf.source_prefix; - -if (!prefix) { -if (raw_path[0 ] !='/' && comp_dir) -/* If not an absolute path, try to use comp_dir */ - prefix = comp_dir; -else { -if (access (raw_path,R_OK ) ==0 ) { - *new_path =strdup (raw_path); -return *new_path ?0 : -ENOMEM ; - }else -return -errno; - } - } - - *new_path =malloc ((strlen (prefix) +strlen (raw_path) +2 )); -if (!*new_path) -return -ENOMEM ; - -for (;;) { -sprintf (*new_path,"%s/%s" , prefix, raw_path); - -if (access (*new_path,R_OK ) ==0 ) -return 0 ; - -if (!symbol_conf.source_prefix) { -/* In case of searching comp_dir, don't retry */ -zfree (new_path); -return -errno; - } - -switch (errno) { -case ENAMETOOLONG : -case ENOENT : -case EROFS : -case EFAULT : - raw_path =strchr (++raw_path,'/' ); -if (!raw_path) { -zfree (new_path); -return -ENOENT ; - } -continue ; - -default : -zfree (new_path); -return -errno; - } - } -} -#define LINEBUF_SIZE 256#define NR_ADDITIONAL_LINES 2
tools/perf/util/probe-finder.c +70 -1
84 lines not on this page · raw message
tools/perf/util/probe-finder.h +4 -0
@@ -55,6 +55,10 @@ extern int debuginfo__find_available_vars_at(struct debuginfo *dbg,struct variable_list **vls, int max_points, bool externs); +/* Find a src file from a DWARF tag path */ +int get_real_path (const char *raw_path,const char *comp_dir, +char **new_path); +struct probe_finder {struct perf_probe_event *pev;/* Target probe event */