* [PATCH v8 1/3] perf report: compile tips.txt in perf binary
@ 2021-05-24 11:15 Denys Zagorui
2021-05-24 11:15 ` [PATCH v8 2/3] perf tests: avoid storing an absolute path " Denys Zagorui
` (4 more replies)
0 siblings, 5 replies; 10+ messages in thread
From: Denys Zagorui @ 2021-05-24 11:15 UTC (permalink / raw)
To: jolsa, linux-kernel, peterz, mingo, acme, mark.rutland,
alexander.shishkin, namhyung
It seems there is some need to have an ability to invoke perf from
build directory without installation
(84cfac7f05e1: perf tools: Set and pass DOCDIR to builtin-report.c)
DOCDIR definition contains an absolute path to kernel source directory.
It is build machine related info and it makes perf binary unreproducible.
This can be avoided by compiling tips.txt in perf directly.
Signed-off-by: Denys Zagorui <dzagorui@cisco.com>
---
tools/perf/Build | 2 +-
tools/perf/Documentation/Build | 9 +++++++++
tools/perf/builtin-report.c | 34 +++++++++++++++++++++++++---------
tools/perf/util/util.c | 28 ----------------------------
tools/perf/util/util.h | 2 --
5 files changed, 35 insertions(+), 40 deletions(-)
create mode 100644 tools/perf/Documentation/Build
diff --git a/tools/perf/Build b/tools/perf/Build
index db61dbe2b543..3a2e768d7576 100644
--- a/tools/perf/Build
+++ b/tools/perf/Build
@@ -45,12 +45,12 @@ CFLAGS_perf.o += -DPERF_HTML_PATH="BUILD_STR($(htmldir_SQ))" \
-DPREFIX="BUILD_STR($(prefix_SQ))"
CFLAGS_builtin-trace.o += -DSTRACE_GROUPS_DIR="BUILD_STR($(STRACE_GROUPS_DIR_SQ))"
CFLAGS_builtin-report.o += -DTIPDIR="BUILD_STR($(tipdir_SQ))"
-CFLAGS_builtin-report.o += -DDOCDIR="BUILD_STR($(srcdir_SQ)/Documentation)"
perf-y += util/
perf-y += arch/
perf-y += ui/
perf-y += scripts/
perf-$(CONFIG_TRACE) += trace/beauty/
+perf-y += Documentation/
gtk-y += ui/gtk/
diff --git a/tools/perf/Documentation/Build b/tools/perf/Documentation/Build
new file mode 100644
index 000000000000..83e16764caa4
--- /dev/null
+++ b/tools/perf/Documentation/Build
@@ -0,0 +1,9 @@
+perf-y += tips.o
+
+quiet_cmd_ld_tips = LD $@
+ cmd_ld_tips = $(LD) -r -b binary -o $@ $<
+
+$(OUTPUT)Documentation/tips.o: Documentation/tips.txt FORCE
+ $(call rule_mkdir)
+ $(call if_changed,ld_tips)
+
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 36f9ccfeb38a..4f2c7ee8fea1 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -47,7 +47,6 @@
#include "util/time-utils.h"
#include "util/auxtrace.h"
#include "util/units.h"
-#include "util/util.h" // perf_tip()
#include "ui/ui.h"
#include "ui/progress.h"
#include "util/block-info.h"
@@ -109,6 +108,9 @@ struct report {
int nr_block_reports;
};
+extern char _binary_Documentation_tips_txt_start[];
+extern char _binary_Documentation_tips_txt_end[];
+
static int report__config(const char *var, const char *value, void *cb)
{
struct report *rep = cb;
@@ -614,19 +616,33 @@ static int report__gtk_browse_hists(struct report *rep, const char *help)
return hist_browser(rep->session->evlist, help, NULL, rep->min_percent);
}
+static const char *perf_tip(void)
+{
+ char *start = _binary_Documentation_tips_txt_start;
+ char *tok, *tmp, *prev;
+ int pick, size;
+
+ size = _binary_Documentation_tips_txt_end - start;
+ pick = random() % size;
+
+ _binary_Documentation_tips_txt_start[size - 1] = 0;
+
+ for (tok = strtok_r(start, "\n", &tmp); tok;
+ tok = strtok_r(NULL, "\n", &tmp)) {
+ if (pick < (tok - start))
+ return prev;
+ prev = tok;
+ }
+
+ return prev;
+}
+
static int report__browse_hists(struct report *rep)
{
int ret;
struct perf_session *session = rep->session;
struct evlist *evlist = session->evlist;
- const char *help = perf_tip(system_path(TIPDIR));
-
- if (help == NULL) {
- /* fallback for people who don't install perf ;-) */
- help = perf_tip(DOCDIR);
- if (help == NULL)
- help = "Cannot load tips.txt file, please install perf!";
- }
+ const char *help = perf_tip();
switch (use_browser) {
case 1:
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 37a9492edb3e..3bba74e431ed 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -379,34 +379,6 @@ fetch_kernel_version(unsigned int *puint, char *str,
return 0;
}
-const char *perf_tip(const char *dirpath)
-{
- struct strlist *tips;
- struct str_node *node;
- char *tip = NULL;
- struct strlist_config conf = {
- .dirname = dirpath,
- .file_only = true,
- };
-
- tips = strlist__new("tips.txt", &conf);
- if (tips == NULL)
- return errno == ENOENT ? NULL :
- "Tip: check path of tips.txt or get more memory! ;-p";
-
- if (strlist__nr_entries(tips) == 0)
- goto out;
-
- node = strlist__entry(tips, random() % strlist__nr_entries(tips));
- if (asprintf(&tip, "Tip: %s", node->s) < 0)
- tip = (char *)"Tip: get more memory! ;-)";
-
-out:
- strlist__delete(tips);
-
- return tip;
-}
-
char *perf_exe(char *buf, int len)
{
int n = readlink("/proc/self/exe", buf, len);
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index ad737052e597..80b194ee6c7d 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -39,8 +39,6 @@ int fetch_kernel_version(unsigned int *puint,
#define KVER_FMT "%d.%d.%d"
#define KVER_PARAM(x) KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x)
-const char *perf_tip(const char *dirpath);
-
#ifndef HAVE_SCHED_GETCPU_SUPPORT
int sched_getcpu(void);
#endif
--
2.26.2.Cisco
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v8 2/3] perf tests: avoid storing an absolute path in perf binary
2021-05-24 11:15 [PATCH v8 1/3] perf report: compile tips.txt in perf binary Denys Zagorui
@ 2021-05-24 11:15 ` Denys Zagorui
2021-05-27 16:53 ` Arnaldo Carvalho de Melo
2021-05-24 11:15 ` [PATCH v8 3/3] perf parse-events: add bison --file-prefix-map option Denys Zagorui
` (3 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: Denys Zagorui @ 2021-05-24 11:15 UTC (permalink / raw)
To: jolsa, linux-kernel, peterz, mingo, acme, mark.rutland,
alexander.shishkin, namhyung
python binding test uses PYTHONPATH definition to find python/perf.so
library. This definition is an absolute path that makes perf binary
unreproducible. This path can be found during runtime execution.
Signed-off-by: Denys Zagorui <dzagorui@cisco.com>
---
tools/perf/tests/Build | 2 +-
tools/perf/tests/python-use.c | 25 ++++++++++++++++++++++---
2 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
index 650aec19d490..a20098dcdbc4 100644
--- a/tools/perf/tests/Build
+++ b/tools/perf/tests/Build
@@ -98,5 +98,5 @@ perf-$(CONFIG_DWARF_UNWIND) += dwarf-unwind.o
endif
CFLAGS_attr.o += -DBINDIR="BUILD_STR($(bindir_SQ))" -DPYTHON="BUILD_STR($(PYTHON_WORD))"
-CFLAGS_python-use.o += -DPYTHONPATH="BUILD_STR($(OUTPUT)python)" -DPYTHON="BUILD_STR($(PYTHON_WORD))"
+CFLAGS_python-use.o += -DPYTHON="BUILD_STR($(PYTHON_WORD))"
CFLAGS_dwarf-unwind.o += -fno-optimize-sibling-calls
diff --git a/tools/perf/tests/python-use.c b/tools/perf/tests/python-use.c
index 98c6d474aa6f..32af71300aa3 100644
--- a/tools/perf/tests/python-use.c
+++ b/tools/perf/tests/python-use.c
@@ -8,18 +8,37 @@
#include <linux/compiler.h>
#include "tests.h"
#include "util/debug.h"
+#include "util/util.h"
+#include <sys/stat.h>
+#include <limits.h>
+#include <libgen.h>
int test__python_use(struct test *test __maybe_unused, int subtest __maybe_unused)
{
char *cmd;
- int ret;
+ int ret = -1;
+ char *exec_path;
+ char buf[PATH_MAX];
+ char *pythonpath;
+ struct stat sb;
+
+ perf_exe(buf, PATH_MAX);
+ exec_path = dirname(buf);
+
+ if (asprintf(&pythonpath, "%s/python", exec_path) < 0)
+ return ret;
+
+ if (stat(pythonpath, &sb) || !S_ISDIR(sb.st_mode))
+ pythonpath[0] = 0;
if (asprintf(&cmd, "echo \"import sys ; sys.path.append('%s'); import perf\" | %s %s",
- PYTHONPATH, PYTHON, verbose > 0 ? "" : "2> /dev/null") < 0)
- return -1;
+ pythonpath, PYTHON, verbose > 0 ? "" : "2> /dev/null") < 0)
+ goto out;
pr_debug("python usage test: \"%s\"\n", cmd);
ret = system(cmd) ? -1 : 0;
free(cmd);
+out:
+ free(pythonpath);
return ret;
}
--
2.26.2.Cisco
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v8 3/3] perf parse-events: add bison --file-prefix-map option
2021-05-24 11:15 [PATCH v8 1/3] perf report: compile tips.txt in perf binary Denys Zagorui
2021-05-24 11:15 ` [PATCH v8 2/3] perf tests: avoid storing an absolute path " Denys Zagorui
@ 2021-05-24 11:15 ` Denys Zagorui
2021-05-25 4:34 ` [PATCH v8 1/3] perf report: compile tips.txt in perf binary Namhyung Kim
` (2 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: Denys Zagorui @ 2021-05-24 11:15 UTC (permalink / raw)
To: jolsa, linux-kernel, peterz, mingo, acme, mark.rutland,
alexander.shishkin, namhyung
During perf build with O= bison stores full paths in generated files and
those paths are stored in resulting perf binary. Starting from v3.7.1.
those paths can be remapped by using --file-prefix-map option. Use this
option if it possible to make perf binary more reproducible.
Signed-off-by: Denys Zagorui <dzagorui@cisco.com>
---
tools/perf/Makefile.config | 9 +++++++++
tools/perf/util/Build | 6 +++---
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 406a9519145e..dacd16874d3d 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -202,6 +202,12 @@ ifeq ($(call get-executable,$(BISON)),)
dummy := $(error Error: $(BISON) is missing on this system, please install it)
endif
+ifneq ($(OUTPUT),)
+ ifeq ($(shell expr $(shell $(BISON) --version | grep bison | sed -e 's/.\+ \([0-9]\+\).\([0-9]\+\).\([0-9]\+\)/\1\2\3/g') \>\= 371), 1)
+ BISON_FILE_PREFIX_MAP := --file-prefix-map=$(OUTPUT)=
+ endif
+endif
+
# Treat warnings as errors unless directed not to
ifneq ($(WERROR),0)
CORE_CFLAGS += -Werror
@@ -1228,6 +1234,9 @@ $(call detected_var,LIBDIR)
$(call detected_var,GTK_CFLAGS)
$(call detected_var,PERL_EMBED_CCOPTS)
$(call detected_var,PYTHON_EMBED_CCOPTS)
+ifneq ($(BISON_FILE_PREFIX_MAP),)
+$(call detected_var,BISON_FILE_PREFIX_MAP)
+endif
# re-generate FEATURE-DUMP as we may have called feature_check, found out
# extra libraries to add to LDFLAGS of some other test and then redo those
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index b64bdc1a7026..95e15d1035ab 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -216,7 +216,7 @@ $(OUTPUT)util/parse-events-flex.c $(OUTPUT)util/parse-events-flex.h: util/parse-
$(OUTPUT)util/parse-events-bison.c $(OUTPUT)util/parse-events-bison.h: util/parse-events.y
$(call rule_mkdir)
- $(Q)$(call echo-cmd,bison)$(BISON) -v $< -d $(PARSER_DEBUG_BISON) \
+ $(Q)$(call echo-cmd,bison)$(BISON) -v $< -d $(PARSER_DEBUG_BISON) $(BISON_FILE_PREFIX_MAP) \
-o $(OUTPUT)util/parse-events-bison.c -p parse_events_
$(OUTPUT)util/expr-flex.c $(OUTPUT)util/expr-flex.h: util/expr.l $(OUTPUT)util/expr-bison.c
@@ -226,7 +226,7 @@ $(OUTPUT)util/expr-flex.c $(OUTPUT)util/expr-flex.h: util/expr.l $(OUTPUT)util/e
$(OUTPUT)util/expr-bison.c $(OUTPUT)util/expr-bison.h: util/expr.y
$(call rule_mkdir)
- $(Q)$(call echo-cmd,bison)$(BISON) -v $< -d $(PARSER_DEBUG_BISON) \
+ $(Q)$(call echo-cmd,bison)$(BISON) -v $< -d $(PARSER_DEBUG_BISON) $(BISON_FILE_PREFIX_MAP) \
-o $(OUTPUT)util/expr-bison.c -p expr_
$(OUTPUT)util/pmu-flex.c $(OUTPUT)util/pmu-flex.h: util/pmu.l $(OUTPUT)util/pmu-bison.c
@@ -236,7 +236,7 @@ $(OUTPUT)util/pmu-flex.c $(OUTPUT)util/pmu-flex.h: util/pmu.l $(OUTPUT)util/pmu-
$(OUTPUT)util/pmu-bison.c $(OUTPUT)util/pmu-bison.h: util/pmu.y
$(call rule_mkdir)
- $(Q)$(call echo-cmd,bison)$(BISON) -v $< -d $(PARSER_DEBUG_BISON) \
+ $(Q)$(call echo-cmd,bison)$(BISON) -v $< -d $(PARSER_DEBUG_BISON) $(BISON_FILE_PREFIX_MAP) \
-o $(OUTPUT)util/pmu-bison.c -p perf_pmu_
FLEX_GE_26 := $(shell expr $(shell $(FLEX) --version | sed -e 's/flex \([0-9]\+\).\([0-9]\+\)/\1\2/g') \>\= 26)
--
2.26.2.Cisco
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v8 1/3] perf report: compile tips.txt in perf binary
2021-05-24 11:15 [PATCH v8 1/3] perf report: compile tips.txt in perf binary Denys Zagorui
2021-05-24 11:15 ` [PATCH v8 2/3] perf tests: avoid storing an absolute path " Denys Zagorui
2021-05-24 11:15 ` [PATCH v8 3/3] perf parse-events: add bison --file-prefix-map option Denys Zagorui
@ 2021-05-25 4:34 ` Namhyung Kim
2021-05-26 11:54 ` Jiri Olsa
2021-05-26 12:41 ` Arnaldo Carvalho de Melo
4 siblings, 0 replies; 10+ messages in thread
From: Namhyung Kim @ 2021-05-25 4:34 UTC (permalink / raw)
To: Denys Zagorui
Cc: Jiri Olsa, linux-kernel, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin
Hello,
On Mon, May 24, 2021 at 4:15 AM Denys Zagorui <dzagorui@cisco.com> wrote:
>
> It seems there is some need to have an ability to invoke perf from
> build directory without installation
> (84cfac7f05e1: perf tools: Set and pass DOCDIR to builtin-report.c)
> DOCDIR definition contains an absolute path to kernel source directory.
> It is build machine related info and it makes perf binary unreproducible.
>
> This can be avoided by compiling tips.txt in perf directly.
>
> Signed-off-by: Denys Zagorui <dzagorui@cisco.com>
For all three patches,
Acked-by: Namhyung Kim <namhyung@kernel.org>
Thanks,
Namhyung
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v8 1/3] perf report: compile tips.txt in perf binary
2021-05-24 11:15 [PATCH v8 1/3] perf report: compile tips.txt in perf binary Denys Zagorui
` (2 preceding siblings ...)
2021-05-25 4:34 ` [PATCH v8 1/3] perf report: compile tips.txt in perf binary Namhyung Kim
@ 2021-05-26 11:54 ` Jiri Olsa
2021-05-26 12:46 ` Arnaldo Carvalho de Melo
2021-05-26 12:41 ` Arnaldo Carvalho de Melo
4 siblings, 1 reply; 10+ messages in thread
From: Jiri Olsa @ 2021-05-26 11:54 UTC (permalink / raw)
To: Denys Zagorui
Cc: linux-kernel, peterz, mingo, acme, mark.rutland,
alexander.shishkin, namhyung
On Mon, May 24, 2021 at 04:15:12AM -0700, Denys Zagorui wrote:
> It seems there is some need to have an ability to invoke perf from
> build directory without installation
> (84cfac7f05e1: perf tools: Set and pass DOCDIR to builtin-report.c)
> DOCDIR definition contains an absolute path to kernel source directory.
> It is build machine related info and it makes perf binary unreproducible.
>
> This can be avoided by compiling tips.txt in perf directly.
>
> Signed-off-by: Denys Zagorui <dzagorui@cisco.com>
for patchset
Acked-by: Jiri Olsa <jolsa@redhat.com>
thanks,
jirka
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v8 1/3] perf report: compile tips.txt in perf binary
2021-05-24 11:15 [PATCH v8 1/3] perf report: compile tips.txt in perf binary Denys Zagorui
` (3 preceding siblings ...)
2021-05-26 11:54 ` Jiri Olsa
@ 2021-05-26 12:41 ` Arnaldo Carvalho de Melo
4 siblings, 0 replies; 10+ messages in thread
From: Arnaldo Carvalho de Melo @ 2021-05-26 12:41 UTC (permalink / raw)
To: Denys Zagorui
Cc: jolsa, linux-kernel, peterz, mingo, mark.rutland,
alexander.shishkin, namhyung
Em Mon, May 24, 2021 at 04:15:12AM -0700, Denys Zagorui escreveu:
> diff --git a/tools/perf/Documentation/Build b/tools/perf/Documentation/Build
> new file mode 100644
> index 000000000000..83e16764caa4
> --- /dev/null
> +++ b/tools/perf/Documentation/Build
> @@ -0,0 +1,9 @@
> +perf-y += tips.o
> +
> +quiet_cmd_ld_tips = LD $@
> + cmd_ld_tips = $(LD) -r -b binary -o $@ $<
> +
> +$(OUTPUT)Documentation/tips.o: Documentation/tips.txt FORCE
> + $(call rule_mkdir)
> + $(call if_changed,ld_tips)
> +
> diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
⬢[acme@toolbox perf]$ git am ./v8_20210524_dzagorui_perf_report_compile_tips_txt_in_perf_binary.mbx
Applying: perf report: compile tips.txt in perf binary
.git/rebase-apply/patch:42: new blank line at EOF.
+
warning: 1 line adds whitespace errors.
tools/perf/Documentation/Build:9: new blank line at EOF.
⬢[acme@toolbox perf]$
I'm fixing this up.
- Arnaldo
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v8 1/3] perf report: compile tips.txt in perf binary
2021-05-26 11:54 ` Jiri Olsa
@ 2021-05-26 12:46 ` Arnaldo Carvalho de Melo
0 siblings, 0 replies; 10+ messages in thread
From: Arnaldo Carvalho de Melo @ 2021-05-26 12:46 UTC (permalink / raw)
To: Jiri Olsa
Cc: Denys Zagorui, linux-kernel, peterz, mingo, mark.rutland,
alexander.shishkin, namhyung
Em Wed, May 26, 2021 at 01:54:26PM +0200, Jiri Olsa escreveu:
> On Mon, May 24, 2021 at 04:15:12AM -0700, Denys Zagorui wrote:
> > It seems there is some need to have an ability to invoke perf from
> > build directory without installation
> > (84cfac7f05e1: perf tools: Set and pass DOCDIR to builtin-report.c)
> > DOCDIR definition contains an absolute path to kernel source directory.
> > It is build machine related info and it makes perf binary unreproducible.
> >
> > This can be avoided by compiling tips.txt in perf directly.
> >
> > Signed-off-by: Denys Zagorui <dzagorui@cisco.com>
>
> for patchset
>
> Acked-by: Jiri Olsa <jolsa@redhat.com>
Thanks, applied.
- Arnaldo
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v8 2/3] perf tests: avoid storing an absolute path in perf binary
2021-05-24 11:15 ` [PATCH v8 2/3] perf tests: avoid storing an absolute path " Denys Zagorui
@ 2021-05-27 16:53 ` Arnaldo Carvalho de Melo
2021-05-28 11:13 ` Denys Zagorui -X (dzagorui - GLOBALLOGIC INC at Cisco)
0 siblings, 1 reply; 10+ messages in thread
From: Arnaldo Carvalho de Melo @ 2021-05-27 16:53 UTC (permalink / raw)
To: Denys Zagorui
Cc: jolsa, linux-kernel, peterz, mingo, mark.rutland,
alexander.shishkin, namhyung
Em Mon, May 24, 2021 at 04:15:13AM -0700, Denys Zagorui escreveu:
> python binding test uses PYTHONPATH definition to find python/perf.so
> library. This definition is an absolute path that makes perf binary
> unreproducible. This path can be found during runtime execution.
>
> Signed-off-by: Denys Zagorui <dzagorui@cisco.com>
> ---
> tools/perf/tests/Build | 2 +-
> tools/perf/tests/python-use.c | 25 ++++++++++++++++++++++---
> 2 files changed, 23 insertions(+), 4 deletions(-)
>
> diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
> index 650aec19d490..a20098dcdbc4 100644
> --- a/tools/perf/tests/Build
> +++ b/tools/perf/tests/Build
> @@ -98,5 +98,5 @@ perf-$(CONFIG_DWARF_UNWIND) += dwarf-unwind.o
> endif
>
> CFLAGS_attr.o += -DBINDIR="BUILD_STR($(bindir_SQ))" -DPYTHON="BUILD_STR($(PYTHON_WORD))"
> -CFLAGS_python-use.o += -DPYTHONPATH="BUILD_STR($(OUTPUT)python)" -DPYTHON="BUILD_STR($(PYTHON_WORD))"
> +CFLAGS_python-use.o += -DPYTHON="BUILD_STR($(PYTHON_WORD))"
> CFLAGS_dwarf-unwind.o += -fno-optimize-sibling-calls
> diff --git a/tools/perf/tests/python-use.c b/tools/perf/tests/python-use.c
> index 98c6d474aa6f..32af71300aa3 100644
> --- a/tools/perf/tests/python-use.c
> +++ b/tools/perf/tests/python-use.c
> @@ -8,18 +8,37 @@
> #include <linux/compiler.h>
> #include "tests.h"
> #include "util/debug.h"
> +#include "util/util.h"
> +#include <sys/stat.h>
> +#include <limits.h>
> +#include <libgen.h>
>
> int test__python_use(struct test *test __maybe_unused, int subtest __maybe_unused)
> {
> char *cmd;
> - int ret;
> + int ret = -1;
> + char *exec_path;
> + char buf[PATH_MAX];
> + char *pythonpath;
> + struct stat sb;
> +
> + perf_exe(buf, PATH_MAX);
> + exec_path = dirname(buf);
> +
> + if (asprintf(&pythonpath, "%s/python", exec_path) < 0)
> + return ret;
> +
> + if (stat(pythonpath, &sb) || !S_ISDIR(sb.st_mode))
> + pythonpath[0] = 0;
>
> if (asprintf(&cmd, "echo \"import sys ; sys.path.append('%s'); import perf\" | %s %s",
> - PYTHONPATH, PYTHON, verbose > 0 ? "" : "2> /dev/null") < 0)
> - return -1;
> + pythonpath, PYTHON, verbose > 0 ? "" : "2> /dev/null") < 0)
> + goto out;
>
> pr_debug("python usage test: \"%s\"\n", cmd);
> ret = system(cmd) ? -1 : 0;
> free(cmd);
> +out:
> + free(pythonpath);
> return ret;
> }
> --
> 2.26.2.Cisco
>
I noticed this is failing the test, nothing is being appended. I'll
investigate later. Can you try to reproduce this? I build perf with:
alias m='perf stat -e cycles:u,instructions:u make -k CORESIGHT=1 BUILD_BPF_SKEL=1 PYTHON=python3 O=/tmp/build/perf -C tools/perf install-bin && perf test python'
⬢[acme@toolbox perf]$ perf test python
19: 'import perf' in python : FAILED!
⬢[acme@toolbox perf]$ perf test -v python
Couldn't bump rlimit(MEMLOCK), failures may take place when creating BPF maps, etc
19: 'import perf' in python :
--- start ---
test child forked, pid 347155
python usage test: "echo "import sys ; sys.path.append(''); import perf" | '/usr/bin/python3' "
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'perf'
test child finished with -1
---- end ----
'import perf' in python: FAILED!
⬢[acme@toolbox perf]$ git log --oneline -3
60cdbfd0586e53c3 (HEAD) perf tests: Avoid storing an absolute path in perf binary
f7fc0d1c915a74ff perf inject: Do not inject BUILD_ID record if MMAP2 has it
0c3f7b38d72b9247 perf inject: Call dso__put() even if dso->hit is set
⬢[acme@toolbox perf]$
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v8 2/3] perf tests: avoid storing an absolute path in perf binary
2021-05-27 16:53 ` Arnaldo Carvalho de Melo
@ 2021-05-28 11:13 ` Denys Zagorui -X (dzagorui - GLOBALLOGIC INC at Cisco)
2021-05-28 12:48 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 10+ messages in thread
From: Denys Zagorui -X (dzagorui - GLOBALLOGIC INC at Cisco) @ 2021-05-28 11:13 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: jolsa, linux-kernel, peterz, mingo, mark.rutland,
alexander.shishkin, namhyung
> I noticed this is failing the test, nothing is being appended. I'll
> investigate later. Can you try to reproduce this? I build perf with:
Maybe this test should fail. Path is being appended only if perf is invoked from the build directory (basically if there is python dir near perf binary
this path will be added to sys.path)
I'm not sure if install-bin task installs perf.so to system i mean before this patch python binary contains an absolute path to its build directory
and if this build dir is deleted this test also will fail.
Maybe we should use export PYTHONPATH=<build dir>/python for such test
Thanks,
Denys
> alias m='perf stat -e cycles:u,instructions:u make -k CORESIGHT=1 BUILD_BPF_SKEL=1 PYTHON=python3 O=/tmp/build/perf -C tools/perf install-bin && perf test python'
>
>
> ⬢[acme@toolbox perf]$ perf test python
> 19: 'import perf' in python : FAILED!
> ⬢[acme@toolbox perf]$ perf test -v python
> Couldn't bump rlimit(MEMLOCK), failures may take place when creating BPF maps, etc
> 19: 'import perf' in python :
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v8 2/3] perf tests: avoid storing an absolute path in perf binary
2021-05-28 11:13 ` Denys Zagorui -X (dzagorui - GLOBALLOGIC INC at Cisco)
@ 2021-05-28 12:48 ` Arnaldo Carvalho de Melo
0 siblings, 0 replies; 10+ messages in thread
From: Arnaldo Carvalho de Melo @ 2021-05-28 12:48 UTC (permalink / raw)
To: Denys Zagorui -X (dzagorui - GLOBALLOGIC INC at Cisco)
Cc: jolsa, linux-kernel, peterz, mingo, mark.rutland,
alexander.shishkin, namhyung
Em Fri, May 28, 2021 at 11:13:09AM +0000, Denys Zagorui -X (dzagorui - GLOBALLOGIC INC at Cisco) escreveu:
>
> > I noticed this is failing the test, nothing is being appended. I'll
> > investigate later. Can you try to reproduce this? I build perf with:
>
> Maybe this test should fail.
I don't think so :-)
> Path is being appended only if perf is invoked from the build
> directory (basically if there is python dir near perf binary this path
> will be added to sys.path)
And that is ok for a developer, but I agree with you, we shouldn't have
such hardcoded build directories in a production binary.
> I'm not sure if install-bin task installs perf.so to system i mean
> before this patch python binary contains an absolute path to its build
> directory and if this build dir is deleted this test also will fail.
That is what is happening, yes.
> Maybe we should use export PYTHONPATH=<build dir>/python for such test
Agreed, can you cook up a patch that does that in the Makefile that
runs the 'perf python' in tools/perf/tests/?
One other suggestion: When the test fails, say when we run 'perf test
python' directly, it could check if PYTHONPATH is set and if not, warn
the user, something like:
⬢[acme@toolbox perf]$ perf test python
19: 'import perf' in python : FAILED! (Please set the PYTHONPATH env variable)
> Thanks,
> Denys
>
> > alias m='perf stat -e cycles:u,instructions:u make -k CORESIGHT=1 BUILD_BPF_SKEL=1 PYTHON=python3 O=/tmp/build/perf -C tools/perf install-bin && perf test python'
> >
> >
> > ⬢[acme@toolbox perf]$ perf test python
> > 19: 'import perf' in python : FAILED!
> > ⬢[acme@toolbox perf]$ perf test -v python
> > Couldn't bump rlimit(MEMLOCK), failures may take place when creating BPF maps, etc
> > 19: 'import perf' in python :
--
- Arnaldo
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2021-05-28 12:48 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-24 11:15 [PATCH v8 1/3] perf report: compile tips.txt in perf binary Denys Zagorui
2021-05-24 11:15 ` [PATCH v8 2/3] perf tests: avoid storing an absolute path " Denys Zagorui
2021-05-27 16:53 ` Arnaldo Carvalho de Melo
2021-05-28 11:13 ` Denys Zagorui -X (dzagorui - GLOBALLOGIC INC at Cisco)
2021-05-28 12:48 ` Arnaldo Carvalho de Melo
2021-05-24 11:15 ` [PATCH v8 3/3] perf parse-events: add bison --file-prefix-map option Denys Zagorui
2021-05-25 4:34 ` [PATCH v8 1/3] perf report: compile tips.txt in perf binary Namhyung Kim
2021-05-26 11:54 ` Jiri Olsa
2021-05-26 12:46 ` Arnaldo Carvalho de Melo
2021-05-26 12:41 ` Arnaldo Carvalho de Melo
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.