perf bench: Change the procps visible command-name of invididual benchmark tests
PATCH 1/1 perf bench: Change the procps visible command-name of invididual benchmark tests
Before this patch, looking at 'perf bench sched pipe' behavior over 'top' only told us that something related to perf is running:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
19934 mingo 20 0 54836 1296 952 R 18.6 0.0 0:00.56 perf
19935 mingo 20 0 54836 384 36 S 18.6 0.0 0:00.56 perfAfter the patch it's clearly visible what's going on:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
19744 mingo 20 0 125m 3536 2644 R 68.2 0.0 0:01.12 sched-pipe
19745 mingo 20 0 125m 1172 276 R 68.2 0.0 0:01.12 sched-pipeThe benchmark-subsystem name is concatenated with the individual testcase name.
Unfortunately 'perf top' does not show the reconfigured name, possibly because it caches ->comm[] values and does not recognize changes to them?
[ Also clean up a few bits in builtin-bench.c while at it. ]
--- tools/perf/builtin-bench.c | 58 +++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 17 deletions(-)
tools/perf/builtin-bench.c +41 -17
@@ -1,21 +1,18 @@/* -* * builtin-bench.c * * General benchmarking subsystem provided by perf * * Copyright (C) 2009, Hitoshi Mitake <[email protected]> -* */ /* -* * Available subsystem list: +* * sched ... scheduler and IPC mechanism * mem ... memory access performance -* +* numa ... NUMA placement performance measurements */ -#include "perf.h" #include "util/util.h" #include "util/parse-options.h"
@@ -25,11 +22,14 @@#include <stdio.h> #include <stdlib.h> #include <string.h> +#include <sys/prctl.h> + +typedef int (*bench_fn_t )(int argc,const char **argv,const char *prefix);struct bench_suite {const char *name;const char *summary; -int (*fn)(int ,const char **,const char *); +bench_fn_t fn; }; \/* sentinel: easy for help */
@@ -103,16 +103,14 @@ static void dump_suites(int subsys_index {int i; -printf ("# List of available suites for %s...\n\n" , - subsystems[subsys_index].name); +printf ("# List of available suites for %s...\n\n" , subsystems[subsys_index].name); -for (i =0 ; subsystems[subsys_index].suites[i].name; i++) +for (i =0 ; subsystems[subsys_index].suites[i].name; i++) {printf ("%14s: %s\n" , subsystems[subsys_index].suites[i].name, subsystems[subsys_index].suites[i].summary); - + }printf ("\n" ); -return ; }static const char *bench_format_str;
@@ -159,7 +157,34 @@ static int bench_str2int(const char *strreturn BENCH_FORMAT_UNKNOWN ; } -static void all_suite (struct bench_subsys *subsys)/* FROM HERE */ +/* +* Run a specific benchmark but first rename the running task's ->comm[] +* to something meaningful: +*/ +static int run_bench (const char *subsys_name,const char *bench_name,bench_fn_t fn,int argc,const char **argv,const char *prefix) +{ +int size; +char *name; +int ret; + + size =strlen (subsys_name) +1 +strlen (bench_name) +1 ; + + name =zalloc (size); +BUG_ON (!name); + +scnprintf (name, size,"%s-%s" , subsys_name, bench_name); + +prctl (PR_SET_NAME , name); + argv[0 ] = name; + + ret =fn (argc, argv, prefix); + +free (name); + +return ret; +} + +static void all_suites (struct bench_subsys *subsys)/* FROM HERE */ {int i;const char *argv[2 ];
@@ -179,7 +204,7 @@ static void all_suite(struct bench_subsyfflush (stdout); argv[1 ] = suites[i].name; - suites[i].fn (1 , argv,NULL ); +run_bench (subsys->name, suites[i].name, suites[i].fn,1 , argv,NULL );printf ("\n" ); } }
@@ -188,7 +213,7 @@ static void all_subsystem(void) {int i;for (i =0 ; subsystems[i].suites; i++) -all_suite (&subsystems[i]); +all_suites (&subsystems[i]); }int cmd_bench (int argc,const char **argv,const char *prefix__maybe_unused )
@@ -231,7 +256,7 @@ int cmd_bench(int argc, const char **arg }if (!strcmp (argv[1 ],"all" )) { -all_suite (&subsystems[i]); +all_suites (&subsystems[i]); goto end; }
@@ -244,8 +269,7 @@ int cmd_bench(int argc, const char **arg subsystems[i].name, subsystems[i].suites[j].name);fflush (stdout); - status = subsystems[i].suites[j].fn (argc -1 , - argv +1 , prefix); + status =run_bench (subsystems[i].name, subsystems[i].suites[j].name, subsystems[i].suites[j].fn, argc -1 , argv +1 , prefix); goto end; }
tools/perf/builtin-bench.c static int bench_str2int(const char *str · line 164
Quoted 5 lines · Ingo Molnar
tools/perf/builtin-bench.c +5
-0+/* +* Run a specific benchmark but first rename the running task's ->comm[] +* to something meaningful: +*/ +static int run_bench (const char *subsys_name,const char *bench_name,bench_fn_t fn,int argc,const char **argv,const char *prefix)
As I recall you are a fan of longer line lengths, but this seems excessive. ;-)
---8<---
tools/perf/builtin-bench.c static int bench_str2int(const char *str · line 187
Quoted 3 lines
tools/perf/builtin-bench.c +3
-0+} + +static void all_suites (struct bench_subsys *subsys)/* FROM HERE */
Might as well drop the /* FROM HERE */.
---8<---
tools/perf/builtin-bench.c int cmd_bench(int argc, const char **arg · line 272
Quoted 7 lines
tools/perf/builtin-bench.c +1
-2@@ -244,8 +269,7 @@ int cmd_bench(int argc, const char **arg subsystems[i].name, subsystems[i].suites[j].name);fflush (stdout); - status = subsystems[i].suites[j].fn (argc -1 , - argv +1 , prefix); + status =run_bench (subsystems[i].name, subsystems[i].suites[j].name, subsystems[i].suites[j].fn, argc -1 , argv +1 , prefix);
another one that is rather long.
David