Document the 'perf test -w' workloads functionality
Arnaldo Carvalho de Melo
maintainercover Document the 'perf test -w' workloads functionality
From: Arnaldo Carvalho de Melo <[email protected]>
Hi,
I noticed that the 'perf test -w' code wasn't well exposed, so
add a '-w --list' option to list the existing workloads and document it in the 'perf test' man page.
- Arnaldo
Arnaldo Carvalho de Melo (3):
perf test: Introduce workloads__for_each()
perf test: Introduce '-w --list' to list the available workloads perf test: Document the -w/--workload option
tools/perf/Documentation/perf-test.txt | 6 ++++++ tools/perf/tests/builtin-test.c | 25 +++++++++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-)
Signature · 1 line
2.47.0
Arnaldo Carvalho de Melo
maintainerPATCH 1/3 perf test: Introduce workloads__for_each()
From: Arnaldo Carvalho de Melo <[email protected]>
And use it in run_workload().
Testing it:
root@x1:~# perf trace -e *landlock* perf test -w landlock
0.000 ( 0.015 ms): :1274331/1274331 landlock_add_rule(ruleset_fd: 11, rule_type: LANDLOCK_RULE_PATH_BENEATH, rule_attr: 0x7ffd3fea55e0, flags: 45) = -1 EINVAL (Invalid argument)
0.018 ( 0.003 ms): :1274331/1274331 landlock_add_rule(ruleset_fd: 11, rule_type: LANDLOCK_RULE_NET_PORT, rule_attr: 0x7ffd3fea55f0, flags: 45) = -1 EINVAL (Invalid argument)
root@x1:~# perf test -w bla
No workload found: bla
root@x1:~#--- tools/perf/tests/builtin-test.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
tools/perf/tests/builtin-test.c +4 -3
@@ -155,6 +155,9 @@ static struct test_workload *workloads[] = { &workload__landlock, }; +#define workloads__for_each (workload) \ + for (unsigned i = 0; i < ARRAY_SIZE(workloads) && ({ workload = workloads[i]; 1; }); i++) +static int num_subtests (const struct test_suite *t) {int num;
@@ -504,11 +507,9 @@ static int perf_test__list(int argc, const char **argv)static int run_workload (const char *work,int argc,const char **argv) { -unsigned int i =0 ;struct test_workload *twl; -for (i =0 ; i <ARRAY_SIZE (workloads); i++) { - twl = workloads[i]; +workloads__for_each (twl) {if (!strcmp (twl->name, work))return twl->func (argc, argv); }
Signature · 1 line
2.47.0
Arnaldo Carvalho de Melo
maintainerPATCH 2/3 perf test: Introduce '-w --list' to list the available workloads
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
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 '-w --list' to list the available ones.
$
$ perf test -w --list noploop thloop leafloop sqrtloop brstack datasym landlock $
Would be good at some point to have a description in 'struct test_workload'.
--- tools/perf/tests/builtin-test.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
tools/perf/tests/builtin-test.c +17 -1
@@ -505,10 +505,26 @@ 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; +if (!strcmp (work,"--list" )) { +workloads__fprintf_list (stdout); +return 0 ; + } +workloads__for_each (twl) {if (!strcmp (twl->name, work))return twl->func (argc, argv);
@@ -544,7 +560,7 @@ int cmd_test(int argc, const char **argv)OPT_BOOLEAN ('p' ,"parallel" , ¶llel,"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 '-w --list' to list the available ones." ),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"),
Signature · 1 line
2.47.0
James Clark
reviewerRe: [PATCH 2/3] perf test: Introduce '-w --list' to list the available workloads
Quoted 54 lines · Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <[email protected]>
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 '-w --list' to list the available ones.
$$ perf test -w --list noploop thloop leafloop sqrtloop brstack datasym landlock $Would be good at some point to have a description in 'struct
test_workload'.Cc Adrian Hunter <[email protected]>Cc Ian Rogers <[email protected]>Cc Jiri Olsa <[email protected]>Cc Kan Liang <[email protected]>Cc Namhyung Kim <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>--- tools/perf/tests/builtin-test.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)tools/perf/tests/builtin-test.c +10
-0@@ -505,10 +505,26 @@ 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; +}
tools/perf/tests/builtin-test.c static int perf_test__list(int argc, const char **argv) · line 527
Quoted 10 lines
tools/perf/tests/builtin-test.c +6
-0+static int run_workload (const char *work,int argc,const char **argv) {struct test_workload *twl; +if (!strcmp (work,"--list" )) { +workloads__fprintf_list (stdout); +return 0 ; + } +
Very minor nit, but I think searching the workload name for an argument instead of having a 'proper' toplevel argument seems a bit weird, but I can see why you did it that way.
But maybe something like this might be a bit more readable especially when searching in the usual places for an argument. And in the future might survive auto doc attempts of known arguments:
$ perf test --list-workloads
And add it with OPT_BOOLEAN() etc.
Quoted 12 lines
tools/perf/tests/builtin-test.c +1
-1workloads__for_each (twl) {if (!strcmp (twl->name, work))return twl->func (argc, argv);@@ -544,7 +560,7 @@ int cmd_test(int argc, const char **argv)OPT_BOOLEAN ('p' ,"parallel" , ¶llel,"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 '-w --list' to list the available ones." ),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"),
Arnaldo Carvalho de Melo
maintainerPATCH 3/3 perf test: Document the -w/--workload option
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Wasn't documented so far, mention that it is mostly used in the shell regression tests.
--- tools/perf/Documentation/perf-test.txt | 6 ++++++ 1 file changed, 6 insertions(+)
tools/perf/Documentation/perf-test.txt +6 -0
@@ -48,3 +48,9 @@ OPTIONS --dso:: Specify a DSO for the "Symbols" test. + +-w:: +--workload=:: + Run a built-in workload, to list them use '-w --list', current ones include: + noploop, thloop, leafloop, sqrtloop, brstack, datasym and landlock. + Used with the shell script regression tests.
Signature · 1 line
2.47.0