2023-11-06 15:11:35

by James Clark

[permalink] [raw]
Subject: [PATCH v2 0/2] perf test: Add option to change objdump binary

Changes since V1:

* Add perf config option

James Clark (2):
perf test: Add option to change objdump binary
perf test: Add support for setting objdump binary via perf config

tools/perf/Documentation/perf-config.txt | 4 ++++
tools/perf/tests/builtin-test.c | 15 +++++++++++++++
tools/perf/tests/code-reading.c | 2 +-
tools/perf/tests/tests.h | 1 +
4 files changed, 21 insertions(+), 1 deletion(-)

--
2.34.1


2023-11-06 15:11:47

by James Clark

[permalink] [raw]
Subject: [PATCH v2 2/2] perf test: Add support for setting objdump binary via perf config

Add a perf config variable that does the same thing as "perf test
--objdump <x>".

Also update the man page.

Signed-off-by: James Clark <[email protected]>
---
tools/perf/Documentation/perf-config.txt | 4 ++++
tools/perf/tests/builtin-test.c | 12 ++++++++++++
2 files changed, 16 insertions(+)

diff --git a/tools/perf/Documentation/perf-config.txt b/tools/perf/Documentation/perf-config.txt
index 0b4e79dbd3f6..16398babd1ef 100644
--- a/tools/perf/Documentation/perf-config.txt
+++ b/tools/perf/Documentation/perf-config.txt
@@ -722,6 +722,10 @@ session-<NAME>.*::
Defines new record session for daemon. The value is record's
command line without the 'record' keyword.

+test.*::
+
+ test.objdump::
+ objdump binary to use for disassembly and annotations.

SEE ALSO
--------
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index a8d17dd50588..113e92119e1d 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -14,6 +14,7 @@
#include <sys/wait.h>
#include <sys/stat.h>
#include "builtin.h"
+#include "config.h"
#include "hist.h"
#include "intlist.h"
#include "tests.h"
@@ -514,6 +515,15 @@ static int run_workload(const char *work, int argc, const char **argv)
return -1;
}

+static int perf_test__config(const char *var, const char *value,
+ void *data __maybe_unused)
+{
+ if (!strcmp(var, "test.objdump"))
+ test_objdump_path = value;
+
+ return 0;
+}
+
int cmd_test(int argc, const char **argv)
{
const char *test_usage[] = {
@@ -541,6 +551,8 @@ int cmd_test(int argc, const char **argv)
if (ret < 0)
return ret;

+ perf_config(perf_test__config, NULL);
+
/* Unbuffered output */
setvbuf(stdout, NULL, _IONBF, 0);

--
2.34.1

2023-11-06 15:11:50

by James Clark

[permalink] [raw]
Subject: [PATCH v2 1/2] perf test: Add option to change objdump binary

All of the other Perf subcommands that use objdump have an option to
specify the binary, so add the same option to perf test.

This is useful if you have built the kernel with a different toolchain
to the system one, where the system objdump may fail to disassemble
vmlinux.

Now this can be fixed with something like this:

$ perf test --objdump llvm-objdump "object code reading"

Reviewed-by: Ian Rogers <[email protected]>
Signed-off-by: James Clark <[email protected]>
---
tools/perf/tests/builtin-test.c | 3 +++
tools/perf/tests/code-reading.c | 2 +-
tools/perf/tests/tests.h | 1 +
3 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index cb6f1dd00dc4..a8d17dd50588 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -32,6 +32,7 @@

static bool dont_fork;
const char *dso_to_test;
+const char *test_objdump_path = "objdump";

/*
* List of architecture specific tests. Not a weak symbol as the array length is
@@ -529,6 +530,8 @@ int cmd_test(int argc, const char **argv)
"Do not fork for testcase"),
OPT_STRING('w', "workload", &workload, "work", "workload to run for testing"),
OPT_STRING(0, "dso", &dso_to_test, "dso", "dso to test"),
+ OPT_STRING(0, "objdump", &test_objdump_path, "path",
+ "objdump binary to use for disassembly and annotations"),
OPT_END()
};
const char * const test_subcommands[] = { "list", NULL };
diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index 3af81012014e..b353358acc3a 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -185,7 +185,7 @@ static int read_via_objdump(const char *filename, u64 addr, void *buf,
int ret;

fmt = "%s -z -d --start-address=0x%"PRIx64" --stop-address=0x%"PRIx64" %s";
- ret = snprintf(cmd, sizeof(cmd), fmt, "objdump", addr, addr + len,
+ ret = snprintf(cmd, sizeof(cmd), fmt, test_objdump_path, addr, addr + len,
filename);
if (ret <= 0 || (size_t)ret >= sizeof(cmd))
return -1;
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index b394f3ac2d66..dad3d7414142 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -207,5 +207,6 @@ DECLARE_WORKLOAD(brstack);
DECLARE_WORKLOAD(datasym);

extern const char *dso_to_test;
+extern const char *test_objdump_path;

#endif /* TESTS_H */
--
2.34.1