[PATCH 2/3] perf test: Introduce '-w --list' to list the available workloads

Arnaldo Carvalho de Melo posted 3 patches 1 month, 2 weeks ago
[PATCH 2/3] perf test: Introduce '-w --list' to list the available workloads
Posted by Arnaldo Carvalho de Melo 1 month, 2 weeks ago
From: Arnaldo Carvalho de Melo <acme@redhat.com>

Using it:

  $ perf test -w noplop
  No workload found: noplop
  $
  $ perf test -w
   Error: switch `w' requires a value
   Usage: perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]

      -w, --workload <work>
                            workload to run for testing, use '--list-workloads' to list the available ones.
  $
  $ perf test --list-workloads
  noploop
  thloop
  leafloop
  sqrtloop
  brstack
  datasym
  landlock
  $

Would be good at some point to have a description in 'struct test_workload'.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/tests/builtin-test.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 2201f7ed432ce9f2..cc43b9f366d09436 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -505,6 +505,17 @@ static int perf_test__list(int argc, const char **argv)
 	return 0;
 }
 
+static int workloads__fprintf_list(FILE *fp)
+{
+	struct test_workload *twl;
+	int printed = 0;
+
+	workloads__for_each(twl)
+		printed += fprintf(fp, "%s\n", twl->name);
+
+	return printed;
+}
+
 static int run_workload(const char *work, int argc, const char **argv)
 {
 	struct test_workload *twl;
@@ -535,6 +546,7 @@ int cmd_test(int argc, const char **argv)
 	};
 	const char *skip = NULL;
 	const char *workload = NULL;
+	bool list_workloads = false;
 	const struct option test_options[] = {
 	OPT_STRING('s', "skip", &skip, "tests", "tests to skip"),
 	OPT_INCR('v', "verbose", &verbose,
@@ -544,7 +556,8 @@ int cmd_test(int argc, const char **argv)
 	OPT_BOOLEAN('p', "parallel", &parallel, "Run the tests in parallel"),
 	OPT_BOOLEAN('S', "sequential", &sequential,
 		    "Run the tests one after another rather than in parallel"),
-	OPT_STRING('w', "workload", &workload, "work", "workload to run for testing"),
+	OPT_STRING('w', "workload", &workload, "work", "workload to run for testing, use '--list-workloads' to list the available ones."),
+	OPT_BOOLEAN(0, "list-workloads", &list_workloads, "List the available builtin workloads to use with -w/--workload"),
 	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"),
@@ -570,6 +583,11 @@ int cmd_test(int argc, const char **argv)
 	if (workload)
 		return run_workload(workload, argc, argv);
 
+	if (list_workloads) {
+		workloads__fprintf_list(stdout);
+		return 0;
+	}
+
 	if (dont_fork)
 		sequential = true;
 	else if (parallel)
-- 
2.47.0
Re: [PATCH 2/3] perf test: Introduce '-w --list' to list the available workloads
Posted by Namhyung Kim 1 month, 1 week ago
Hi Arnaldo,

The commit subject line should be changed to --list-workloads too.

Thanks,
Namhyung


On Fri, Oct 11, 2024 at 02:14:48PM -0300, Arnaldo Carvalho de Melo wrote:
> From: Arnaldo Carvalho de Melo <acme@redhat.com>
> 
> Using it:
> 
>   $ perf test -w noplop
>   No workload found: noplop
>   $
>   $ perf test -w
>    Error: switch `w' requires a value
>    Usage: perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]
> 
>       -w, --workload <work>
>                             workload to run for testing, use '--list-workloads' to list the available ones.
>   $
>   $ perf test --list-workloads
>   noploop
>   thloop
>   leafloop
>   sqrtloop
>   brstack
>   datasym
>   landlock
>   $
> 
> Would be good at some point to have a description in 'struct test_workload'.
> 
> Cc: Adrian Hunter <adrian.hunter@intel.com>
> Cc: Ian Rogers <irogers@google.com>
> Cc: James Clark <james.clark@linaro.org>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Kan Liang <kan.liang@linux.intel.com>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> ---
>  tools/perf/tests/builtin-test.c | 20 +++++++++++++++++++-
>  1 file changed, 19 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
> index 2201f7ed432ce9f2..cc43b9f366d09436 100644
> --- a/tools/perf/tests/builtin-test.c
> +++ b/tools/perf/tests/builtin-test.c
> @@ -505,6 +505,17 @@ static int perf_test__list(int argc, const char **argv)
>  	return 0;
>  }
>  
> +static int workloads__fprintf_list(FILE *fp)
> +{
> +	struct test_workload *twl;
> +	int printed = 0;
> +
> +	workloads__for_each(twl)
> +		printed += fprintf(fp, "%s\n", twl->name);
> +
> +	return printed;
> +}
> +
>  static int run_workload(const char *work, int argc, const char **argv)
>  {
>  	struct test_workload *twl;
> @@ -535,6 +546,7 @@ int cmd_test(int argc, const char **argv)
>  	};
>  	const char *skip = NULL;
>  	const char *workload = NULL;
> +	bool list_workloads = false;
>  	const struct option test_options[] = {
>  	OPT_STRING('s', "skip", &skip, "tests", "tests to skip"),
>  	OPT_INCR('v', "verbose", &verbose,
> @@ -544,7 +556,8 @@ int cmd_test(int argc, const char **argv)
>  	OPT_BOOLEAN('p', "parallel", &parallel, "Run the tests in parallel"),
>  	OPT_BOOLEAN('S', "sequential", &sequential,
>  		    "Run the tests one after another rather than in parallel"),
> -	OPT_STRING('w', "workload", &workload, "work", "workload to run for testing"),
> +	OPT_STRING('w', "workload", &workload, "work", "workload to run for testing, use '--list-workloads' to list the available ones."),
> +	OPT_BOOLEAN(0, "list-workloads", &list_workloads, "List the available builtin workloads to use with -w/--workload"),
>  	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"),
> @@ -570,6 +583,11 @@ int cmd_test(int argc, const char **argv)
>  	if (workload)
>  		return run_workload(workload, argc, argv);
>  
> +	if (list_workloads) {
> +		workloads__fprintf_list(stdout);
> +		return 0;
> +	}
> +
>  	if (dont_fork)
>  		sequential = true;
>  	else if (parallel)
> -- 
> 2.47.0
>