LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 1/2] perf probe: export get_real_path
@ 2015-02-26 7:12 Naohiro Aota
2015-02-26 7:12 ` [PATCH 2/2] perf probe: Find compilation directory path for lazy matching Naohiro Aota
` (2 more replies)
0 siblings, 3 replies; 18+ messages in thread
From: Naohiro Aota @ 2015-02-26 7:12 UTC (permalink / raw)
To: Peter Zijlstra, Arnaldo Carvalho de Melo, Masami Hiramatsu, Namhyung Kim
Cc: linux-kernel, Naohiro Aota
Export it to use from util/probe-finder.c
Signed-off-by: Naohiro Aota <naota@elisp.net>
---
tools/perf/util/probe-event.c | 2 +-
tools/perf/util/probe-event.h | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 919937e..1d0d505 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -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;
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index e01e994..30a3391 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -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
--
2.3.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 2/2] perf probe: Find compilation directory path for lazy matching
2015-02-26 7:12 [PATCH 1/2] perf probe: export get_real_path Naohiro Aota
@ 2015-02-26 7:12 ` Naohiro Aota
2015-02-26 8:08 ` Masami Hiramatsu
2015-02-26 7:50 ` [PATCH 1/2] perf probe: export get_real_path Masami Hiramatsu
2015-03-04 7:52 ` [PATCH v2] perf probe: Find compilation directory path for lazy matching Naohiro Aota
2 siblings, 1 reply; 18+ messages in thread
From: Naohiro Aota @ 2015-02-26 7:12 UTC (permalink / raw)
To: Peter Zijlstra, Arnaldo Carvalho de Melo, Masami Hiramatsu, Namhyung Kim
Cc: linux-kernel, 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 <naota@elisp.net>
---
tools/perf/util/probe-finder.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index b5247d7..8e0714c 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -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;
}
--
2.3.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 1/2] perf probe: export get_real_path
2015-02-26 7:12 [PATCH 1/2] perf probe: export get_real_path Naohiro Aota
2015-02-26 7:12 ` [PATCH 2/2] perf probe: Find compilation directory path for lazy matching Naohiro Aota
@ 2015-02-26 7:50 ` Masami Hiramatsu
2015-03-04 7:52 ` [PATCH v2] perf probe: Find compilation directory path for lazy matching Naohiro Aota
2 siblings, 0 replies; 18+ messages in thread
From: Masami Hiramatsu @ 2015-02-26 7:50 UTC (permalink / raw)
To: Naohiro Aota
Cc: Peter Zijlstra, Arnaldo Carvalho de Melo, Namhyung Kim, linux-kernel
(2015/02/26 16:12), Naohiro Aota wrote:
> 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,
>
> Signed-off-by: Naohiro Aota <naota@elisp.net>
> ---
> tools/perf/util/probe-event.c | 2 +-
> tools/perf/util/probe-event.h | 2 ++
> 2 files changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
> index 919937e..1d0d505 100644
> --- a/tools/perf/util/probe-event.c
> +++ b/tools/perf/util/probe-event.c
> @@ -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;
> diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
> index e01e994..30a3391 100644
> --- a/tools/perf/util/probe-event.h
> +++ b/tools/perf/util/probe-event.h
> @@ -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
>
--
Masami HIRAMATSU
Software Platform Research Dept. Linux Technology Research Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt@hitachi.com
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 2/2] perf probe: Find compilation directory path for lazy matching
2015-02-26 7:12 ` [PATCH 2/2] perf probe: Find compilation directory path for lazy matching Naohiro Aota
@ 2015-02-26 8:08 ` Masami Hiramatsu
2015-02-26 8:25 ` [PATCH perf/core ] [BUGFIX] perf-probe: Fix get_real_path to free allocated memory in error path Masami Hiramatsu
0 siblings, 1 reply; 18+ messages in thread
From: Masami Hiramatsu @ 2015-02-26 8:08 UTC (permalink / raw)
To: Naohiro Aota
Cc: Peter Zijlstra, Arnaldo Carvalho de Melo, Namhyung Kim, linux-kernel
(2015/02/26 16:12), Naohiro Aota wrote:
> 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 <naota@elisp.net>
> ---
> tools/perf/util/probe-finder.c | 15 ++++++++++++++-
> 1 file changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
> index b5247d7..8e0714c 100644
> --- a/tools/perf/util/probe-finder.c
> +++ b/tools/perf/util/probe-finder.c
> @@ -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);
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!
> + 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;
> }
>
--
Masami HIRAMATSU
Software Platform Research Dept. Linux Technology Research Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt@hitachi.com
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH perf/core ] [BUGFIX] perf-probe: Fix get_real_path to free allocated memory in error path
2015-02-26 8:08 ` Masami Hiramatsu
@ 2015-02-26 8:25 ` Masami Hiramatsu
2015-02-26 14:46 ` Arnaldo Carvalho de Melo
2015-02-28 9:31 ` [tip:perf/core] perf probe: " tip-bot for Masami Hiramatsu
0 siblings, 2 replies; 18+ messages in thread
From: Masami Hiramatsu @ 2015-02-26 8:25 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Peter Zijlstra, namhyung, Naohiro Aota, Ingo Molnar,
Linux Kernel Mailing List
Fix get_real_path to free allocated memory when comp_dir
is used for complementing path and getting an error.
Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
---
tools/perf/util/probe-event.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 9dfbed9..43cc534 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -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:
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH perf/core ] [BUGFIX] perf-probe: Fix get_real_path to free allocated memory in error path
2015-02-26 8:25 ` [PATCH perf/core ] [BUGFIX] perf-probe: Fix get_real_path to free allocated memory in error path Masami Hiramatsu
@ 2015-02-26 14:46 ` Arnaldo Carvalho de Melo
2015-02-27 0:58 ` Masami Hiramatsu
2015-02-28 9:31 ` [tip:perf/core] perf probe: " tip-bot for Masami Hiramatsu
1 sibling, 1 reply; 18+ messages in thread
From: Arnaldo Carvalho de Melo @ 2015-02-26 14:46 UTC (permalink / raw)
To: Masami Hiramatsu
Cc: Peter Zijlstra, namhyung, Naohiro Aota, Ingo Molnar,
Linux Kernel Mailing List
Em Thu, Feb 26, 2015 at 05:25:04PM +0900, Masami Hiramatsu escreveu:
> Fix get_real_path to free allocated memory when comp_dir
> is used for complementing path and getting an error.
While reviewing this patch I noticed this is needed, ack?
- Arnaldo
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 4a93bf433344..9526cf37682e 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -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;
}
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH perf/core ] [BUGFIX] perf-probe: Fix get_real_path to free allocated memory in error path
2015-02-26 14:46 ` Arnaldo Carvalho de Melo
@ 2015-02-27 0:58 ` Masami Hiramatsu
0 siblings, 0 replies; 18+ messages in thread
From: Masami Hiramatsu @ 2015-02-27 0:58 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Peter Zijlstra, namhyung, Naohiro Aota, Ingo Molnar,
Linux Kernel Mailing List
(2015/02/26 23:46), Arnaldo Carvalho de Melo wrote:
> Em Thu, Feb 26, 2015 at 05:25:04PM +0900, Masami Hiramatsu escreveu:
>> Fix get_real_path to free allocated memory when comp_dir
>> is used for complementing path and getting an error.
>
>
> While reviewing this patch I noticed this is needed, ack?
Ah, right!
Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Thank you,
>
> - Arnaldo
>
>
> diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
> index 4a93bf433344..9526cf37682e 100644
> --- a/tools/perf/util/probe-event.c
> +++ b/tools/perf/util/probe-event.c
> @@ -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
Software Platform Research Dept. Linux Technology Research Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt@hitachi.com
^ permalink raw reply [flat|nested] 18+ messages in thread
* [tip:perf/core] perf probe: Fix get_real_path to free allocated memory in error path
2015-02-26 8:25 ` [PATCH perf/core ] [BUGFIX] perf-probe: Fix get_real_path to free allocated memory in error path Masami Hiramatsu
2015-02-26 14:46 ` Arnaldo Carvalho de Melo
@ 2015-02-28 9:31 ` tip-bot for Masami Hiramatsu
1 sibling, 0 replies; 18+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2015-02-28 9:31 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, masami.hiramatsu.pt, mingo, naota, tglx, acme,
peterz, hpa, namhyung
Commit-ID: eb47cb2eb22dfacac9689708f5bd3cb0e975e290
Gitweb: http://git.kernel.org/tip/eb47cb2eb22dfacac9689708f5bd3cb0e975e290
Author: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
AuthorDate: Thu, 26 Feb 2015 17:25:04 +0900
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
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.
Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Naohiro Aota <naota@elisp.net>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20150226082504.28125.74506.stgit@localhost.localdomain
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/probe-event.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 662d454..4a93bf4 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -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:
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v2] perf probe: Find compilation directory path for lazy matching
2015-02-26 7:12 [PATCH 1/2] perf probe: export get_real_path Naohiro Aota
2015-02-26 7:12 ` [PATCH 2/2] perf probe: Find compilation directory path for lazy matching Naohiro Aota
2015-02-26 7:50 ` [PATCH 1/2] perf probe: export get_real_path Masami Hiramatsu
@ 2015-03-04 7:52 ` Naohiro Aota
2015-03-04 12:34 ` Masami Hiramatsu
2 siblings, 1 reply; 18+ messages in thread
From: Naohiro Aota @ 2015-03-04 7:52 UTC (permalink / raw)
To: Masami Hiramatsu
Cc: Naohiro Aota, Peter Zijlstra, Paul Mackerras, Ingo Molnar,
Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa,
open list:PERFORMANCE EVENT...
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 <naota@elisp.net>
---
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(-)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 1c570c2..adb8d1f 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -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
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 46f009a..e6c0262 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -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;
+ }
+ }
+}
diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h
index 92590b2..5ef82dd 100644
--- a/tools/perf/util/probe-finder.h
+++ b/tools/perf/util/probe-finder.h
@@ -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 */
--
2.3.1
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v2] perf probe: Find compilation directory path for lazy matching
2015-03-04 7:52 ` [PATCH v2] perf probe: Find compilation directory path for lazy matching Naohiro Aota
@ 2015-03-04 12:34 ` Masami Hiramatsu
2015-03-11 13:30 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 18+ messages in thread
From: Masami Hiramatsu @ 2015-03-04 12:34 UTC (permalink / raw)
To: Naohiro Aota
Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar,
Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa,
open list:PERFORMANCE EVENT...
(2015/03/04 16:52), Naohiro Aota wrote:
> 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 :)
Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Thank you!
> Signed-off-by: Naohiro Aota <naota@elisp.net>
> ---
> 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(-)
>
> diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
> index 1c570c2..adb8d1f 100644
> --- a/tools/perf/util/probe-event.c
> +++ b/tools/perf/util/probe-event.c
> @@ -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
>
> diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
> index 46f009a..e6c0262 100644
> --- a/tools/perf/util/probe-finder.c
> +++ b/tools/perf/util/probe-finder.c
> @@ -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;
> + }
> + }
> +}
> diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h
> index 92590b2..5ef82dd 100644
> --- a/tools/perf/util/probe-finder.h
> +++ b/tools/perf/util/probe-finder.h
> @@ -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 */
>
>
--
Masami HIRAMATSU
Software Platform Research Dept. Linux Technology Research Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt@hitachi.com
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v2] perf probe: Find compilation directory path for lazy matching
2015-03-04 12:34 ` Masami Hiramatsu
@ 2015-03-11 13:30 ` Arnaldo Carvalho de Melo
2015-03-12 1:42 ` Masami Hiramatsu
2015-03-13 5:18 ` [PATCH v3] " Naohiro Aota
0 siblings, 2 replies; 18+ messages in thread
From: Arnaldo Carvalho de Melo @ 2015-03-11 13:30 UTC (permalink / raw)
To: Naohiro Aota
Cc: Masami Hiramatsu, Peter Zijlstra, Paul Mackerras, Ingo Molnar,
Namhyung Kim, Jiri Olsa, open list:PERFORMANCE EVENT...
Em Wed, Mar 04, 2015 at 09:34:38PM +0900, Masami Hiramatsu escreveu:
> (2015/03/04 16:52), Naohiro Aota wrote:
> > 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 :)
>
> Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
This doesn't make sense... se below:
> Thank you!
>
> > diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
> > index 46f009a..e6c0262 100644
> > --- a/tools/perf/util/probe-finder.c
> > +++ b/tools/perf/util/probe-finder.c
> > @@ -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)
The function is marked "static"
> > +{
> > + 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;
> > + }
> > + }
> > +}
> > diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h
> > index 92590b2..5ef82dd 100644
> > --- a/tools/perf/util/probe-finder.h
> > +++ b/tools/perf/util/probe-finder.h
> > @@ -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);
> > +
And then you mark it "extern"? Have you tried to compile this? I tried:
CC /tmp/build/perf/tests/task-exit.o
util/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
> > struct probe_finder {
> > struct perf_probe_event *pev; /* Target probe event */
> >
> >
>
>
> --
> Masami HIRAMATSU
> Software Platform Research Dept. Linux Technology Research Center
> Hitachi, Ltd., Yokohama Research Laboratory
> E-mail: masami.hiramatsu.pt@hitachi.com
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Re: [PATCH v2] perf probe: Find compilation directory path for lazy matching
2015-03-11 13:30 ` Arnaldo Carvalho de Melo
@ 2015-03-12 1:42 ` Masami Hiramatsu
2015-03-13 5:13 ` Naohiro Aota
2015-03-13 5:18 ` [PATCH v3] " Naohiro Aota
1 sibling, 1 reply; 18+ messages in thread
From: Masami Hiramatsu @ 2015-03-12 1:42 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Naohiro Aota, Peter Zijlstra, Paul Mackerras, Ingo Molnar,
Namhyung Kim, Jiri Olsa, open list:PERFORMANCE EVENT...
(2015/03/11 22:30), Arnaldo Carvalho de Melo wrote:
> Em Wed, Mar 04, 2015 at 09:34:38PM +0900, Masami Hiramatsu escreveu:
>> (2015/03/04 16:52), Naohiro Aota wrote:
>>> 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 :)
>>
>> Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
>
> This doesn't make sense... se below:
>
>> Thank you!
>>
>>> diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
>>> index 46f009a..e6c0262 100644
>>> --- a/tools/perf/util/probe-finder.c
>>> +++ b/tools/perf/util/probe-finder.c
>>> @@ -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)
>
> The function is marked "static"
>
>>> +{
>>> + 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;
>>> + }
>>> + }
>>> +}
>>> diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h
>>> index 92590b2..5ef82dd 100644
>>> --- a/tools/perf/util/probe-finder.h
>>> +++ b/tools/perf/util/probe-finder.h
>>> @@ -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);
>>> +
>
> And then you mark it "extern"? Have you tried to compile this? I tried:
>
> CC /tmp/build/perf/tests/task-exit.o
> util/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.1
Ooops! Sorry, I missed this ...
Naohiro, could you fix this?
Thanks,
>
> - Arnaldo
>
>>> struct probe_finder {
>>> struct perf_probe_event *pev; /* Target probe event */
>>>
>>>
>>
>>
>> --
>> Masami HIRAMATSU
>> Software Platform Research Dept. Linux Technology Research Center
>> Hitachi, Ltd., Yokohama Research Laboratory
>> E-mail: masami.hiramatsu.pt@hitachi.com
>>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> 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: masami.hiramatsu.pt@hitachi.com
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Re: [PATCH v2] perf probe: Find compilation directory path for lazy matching
2015-03-12 1:42 ` Masami Hiramatsu
@ 2015-03-13 5:13 ` Naohiro Aota
0 siblings, 0 replies; 18+ messages in thread
From: Naohiro Aota @ 2015-03-13 5:13 UTC (permalink / raw)
To: Masami Hiramatsu
Cc: Arnaldo Carvalho de Melo, Peter Zijlstra, Paul Mackerras,
Ingo Molnar, Namhyung Kim, Jiri Olsa,
open list:PERFORMANCE EVENT...
On Thu, Mar 12, 2015 at 10:42 AM, Masami Hiramatsu
<masami.hiramatsu.pt@hitachi.com> wrote:
> (2015/03/11 22:30), Arnaldo Carvalho de Melo wrote:
>> Em Wed, Mar 04, 2015 at 09:34:38PM +0900, Masami Hiramatsu escreveu:
>>> (2015/03/04 16:52), Naohiro Aota wrote:
>>>> 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 :)
>>>
>>> Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
>>
>> This doesn't make sense... se below:
>>
>>> Thank you!
>>>
>>>> diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
>>>> index 46f009a..e6c0262 100644
>>>> --- a/tools/perf/util/probe-finder.c
>>>> +++ b/tools/perf/util/probe-finder.c
>>>> @@ -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)
>>
>> The function is marked "static"
>>
>>>> +{
>>>> + 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;
>>>> + }
>>>> + }
>>>> +}
>>>> diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h
>>>> index 92590b2..5ef82dd 100644
>>>> --- a/tools/perf/util/probe-finder.h
>>>> +++ b/tools/perf/util/probe-finder.h
>>>> @@ -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);
>>>> +
>>
>> And then you mark it "extern"? Have you tried to compile this? I tried:
>>
>> CC /tmp/build/perf/tests/task-exit.o
>> util/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.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.
>
>>
>> - Arnaldo
>>
>>>> struct probe_finder {
>>>> struct perf_probe_event *pev; /* Target probe event */
>>>>
>>>>
>>>
>>>
>>> --
>>> Masami HIRAMATSU
>>> Software Platform Research Dept. Linux Technology Research Center
>>> Hitachi, Ltd., Yokohama Research Laboratory
>>> E-mail: masami.hiramatsu.pt@hitachi.com
>>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>> the body of a message to majordomo@vger.kernel.org
>> 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: masami.hiramatsu.pt@hitachi.com
>
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v3] perf probe: Find compilation directory path for lazy matching
2015-03-11 13:30 ` Arnaldo Carvalho de Melo
2015-03-12 1:42 ` Masami Hiramatsu
@ 2015-03-13 5:18 ` Naohiro Aota
2015-03-13 12:21 ` Masami Hiramatsu
` (2 more replies)
1 sibling, 3 replies; 18+ messages in thread
From: Naohiro Aota @ 2015-03-13 5:18 UTC (permalink / raw)
To: Masami Hiramatsu, Arnaldo Carvalho de Melo
Cc: Naohiro Aota, Peter Zijlstra, Paul Mackerras, Ingo Molnar,
Namhyung Kim, He Kuang, Jiri Olsa, open list:PERFORMANCE EVENT...
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 <naota@elisp.net>
---
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(-)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index f272a71..32a429b 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -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
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 46f009a..0fd2df4 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -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;
+ }
+ }
+}
diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h
index 92590b2..ebf8c8c 100644
--- a/tools/perf/util/probe-finder.h
+++ b/tools/perf/util/probe-finder.h
@@ -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 */
--
2.3.1
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v3] perf probe: Find compilation directory path for lazy matching
2015-03-13 5:18 ` [PATCH v3] " Naohiro Aota
@ 2015-03-13 12:21 ` Masami Hiramatsu
2015-04-13 23:10 ` Arnaldo Carvalho de Melo
2015-04-14 12:17 ` [tip:perf/urgent] " tip-bot for Naohiro Aota
2 siblings, 0 replies; 18+ messages in thread
From: Masami Hiramatsu @ 2015-03-13 12:21 UTC (permalink / raw)
To: Naohiro Aota
Cc: Arnaldo Carvalho de Melo, Peter Zijlstra, Paul Mackerras,
Ingo Molnar, Namhyung Kim, He Kuang, Jiri Olsa,
open list:PERFORMANCE EVENT...
(2015/03/13 14:18), Naohiro Aota wrote:
> 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 :)
Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Thank you!
> Signed-off-by: Naohiro Aota <naota@elisp.net>
> ---
> 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(-)
>
> diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
> index f272a71..32a429b 100644
> --- a/tools/perf/util/probe-event.c
> +++ b/tools/perf/util/probe-event.c
> @@ -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
>
> diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
> index 46f009a..0fd2df4 100644
> --- a/tools/perf/util/probe-finder.c
> +++ b/tools/perf/util/probe-finder.c
> @@ -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;
> + }
> + }
> +}
> diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h
> index 92590b2..ebf8c8c 100644
> --- a/tools/perf/util/probe-finder.h
> +++ b/tools/perf/util/probe-finder.h
> @@ -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 */
>
>
--
Masami HIRAMATSU
Software Platform Research Dept. Linux Technology Research Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt@hitachi.com
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v3] perf probe: Find compilation directory path for lazy matching
2015-03-13 5:18 ` [PATCH v3] " Naohiro Aota
2015-03-13 12:21 ` Masami Hiramatsu
@ 2015-04-13 23:10 ` Arnaldo Carvalho de Melo
2015-04-14 6:35 ` Masami Hiramatsu
2015-04-14 12:17 ` [tip:perf/urgent] " tip-bot for Naohiro Aota
2 siblings, 1 reply; 18+ messages in thread
From: Arnaldo Carvalho de Melo @ 2015-04-13 23:10 UTC (permalink / raw)
To: Naohiro Aota
Cc: Masami Hiramatsu, Peter Zijlstra, Paul Mackerras, Ingo Molnar,
Namhyung Kim, He Kuang, Jiri Olsa, open list:PERFORMANCE EVENT...
Em Fri, Mar 13, 2015 at 02:18:40PM +0900, Naohiro Aota escreveu:
> 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
> 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 <naota@elisp.net>
> ---
> 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(-)
>
> diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
> index f272a71..32a429b 100644
> --- a/tools/perf/util/probe-event.c
> +++ b/tools/perf/util/probe-event.c
> @@ -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
>
> diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
> index 46f009a..0fd2df4 100644
> --- a/tools/perf/util/probe-finder.c
> +++ b/tools/perf/util/probe-finder.c
> @@ -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;
> + }
> + }
> +}
> diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h
> index 92590b2..ebf8c8c 100644
> --- a/tools/perf/util/probe-finder.h
> +++ b/tools/perf/util/probe-finder.h
> @@ -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 */
>
> --
> 2.3.1
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v3] perf probe: Find compilation directory path for lazy matching
2015-04-13 23:10 ` Arnaldo Carvalho de Melo
@ 2015-04-14 6:35 ` Masami Hiramatsu
0 siblings, 0 replies; 18+ messages in thread
From: Masami Hiramatsu @ 2015-04-14 6:35 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Naohiro Aota, Peter Zijlstra, Paul Mackerras, Ingo Molnar,
Namhyung Kim, He Kuang, Jiri Olsa, open list:PERFORMANCE EVENT...
(2015/04/14 8:10), Arnaldo Carvalho de Melo wrote:
> Em Fri, Mar 13, 2015 at 02:18:40PM +0900, Naohiro Aota escreveu:
>> 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!
>
> - Arnaldo
>
>> 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 <naota@elisp.net>
>> ---
>> 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(-)
>>
>> diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
>> index f272a71..32a429b 100644
>> --- a/tools/perf/util/probe-event.c
>> +++ b/tools/perf/util/probe-event.c
>> @@ -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
>>
>> diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
>> index 46f009a..0fd2df4 100644
>> --- a/tools/perf/util/probe-finder.c
>> +++ b/tools/perf/util/probe-finder.c
>> @@ -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;
>> + }
>> + }
>> +}
>> diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h
>> index 92590b2..ebf8c8c 100644
>> --- a/tools/perf/util/probe-finder.h
>> +++ b/tools/perf/util/probe-finder.h
>> @@ -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 */
>>
>> --
>> 2.3.1
>
--
Masami HIRAMATSU
Linux Technology Research Center, System Productivity Research Dept.
Center for Technology Innovation - Systems Engineering
Hitachi, Ltd., Research & Development Group
E-mail: masami.hiramatsu.pt@hitachi.com
^ permalink raw reply [flat|nested] 18+ messages in thread
* [tip:perf/urgent] perf probe: Find compilation directory path for lazy matching
2015-03-13 5:18 ` [PATCH v3] " Naohiro Aota
2015-03-13 12:21 ` Masami Hiramatsu
2015-04-13 23:10 ` Arnaldo Carvalho de Melo
@ 2015-04-14 12:17 ` tip-bot for Naohiro Aota
2 siblings, 0 replies; 18+ messages in thread
From: tip-bot for Naohiro Aota @ 2015-04-14 12:17 UTC (permalink / raw)
To: linux-tip-commits
Cc: hekuang, hpa, paulus, acme, tglx, a.p.zijlstra, naota,
linux-kernel, mingo, namhyung, jolsa, masami.hiramatsu.pt
Commit-ID: 09ed8975c4b13be4469899b210f0e0936021ee8f
Gitweb: http://git.kernel.org/tip/09ed8975c4b13be4469899b210f0e0936021ee8f
Author: Naohiro Aota <naota@elisp.net>
AuthorDate: Fri, 13 Mar 2015 14:18:40 +0900
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
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!
Signed-off-by: Naohiro Aota <naota@elisp.net>
Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1426223923-1493-1-git-send-email-naota@elisp.net
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
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(-)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 5483d98..d8bb616 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -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
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 7831e2d..ff7865c 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -855,11 +855,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;
}
@@ -1622,3 +1633,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;
+ }
+ }
+}
diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h
index 92590b2..ebf8c8c 100644
--- a/tools/perf/util/probe-finder.h
+++ b/tools/perf/util/probe-finder.h
@@ -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 */
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2015-04-14 12:19 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-26 7:12 [PATCH 1/2] perf probe: export get_real_path Naohiro Aota
2015-02-26 7:12 ` [PATCH 2/2] perf probe: Find compilation directory path for lazy matching Naohiro Aota
2015-02-26 8:08 ` Masami Hiramatsu
2015-02-26 8:25 ` [PATCH perf/core ] [BUGFIX] perf-probe: Fix get_real_path to free allocated memory in error path Masami Hiramatsu
2015-02-26 14:46 ` Arnaldo Carvalho de Melo
2015-02-27 0:58 ` Masami Hiramatsu
2015-02-28 9:31 ` [tip:perf/core] perf probe: " tip-bot for Masami Hiramatsu
2015-02-26 7:50 ` [PATCH 1/2] perf probe: export get_real_path Masami Hiramatsu
2015-03-04 7:52 ` [PATCH v2] perf probe: Find compilation directory path for lazy matching Naohiro Aota
2015-03-04 12:34 ` Masami Hiramatsu
2015-03-11 13:30 ` Arnaldo Carvalho de Melo
2015-03-12 1:42 ` Masami Hiramatsu
2015-03-13 5:13 ` Naohiro Aota
2015-03-13 5:18 ` [PATCH v3] " Naohiro Aota
2015-03-13 12:21 ` Masami Hiramatsu
2015-04-13 23:10 ` Arnaldo Carvalho de Melo
2015-04-14 6:35 ` Masami Hiramatsu
2015-04-14 12:17 ` [tip:perf/urgent] " tip-bot for Naohiro Aota
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).