Commit 4157922a authored by Ingo Molnar's avatar Ingo Molnar Committed by Arnaldo Carvalho de Melo

perf bench: Change the procps visible command-name of invididual benchmark tests plus cleanups

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 perf

After 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-pipe

The 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 and reorganize
the code and the output strings to be consistent.

Use iterators to access the various arrays. Rename 'suites' concept to
'benchmark collection' and the 'bench_suite' to 'benchmark/bench'. The
many repetitions of 'suite' made the code harder to read and understand.

The new output is:

  comet:~/tip/tools/perf> ./perf bench
  Usage:
        perf bench [<common options>] <collection> <benchmark> [<options>]

        # List of all available benchmark collections:

         sched: Scheduler and IPC benchmarks
           mem: Memory access benchmarks
          numa: NUMA scheduling and MM benchmarks
           all: All benchmarks

  comet:~/tip/tools/perf> ./perf bench sched

        # List of available benchmarks for collection 'sched':

     messaging: Benchmark for scheduling and IPC
          pipe: Benchmark for pipe() between two processes
           all: Test all scheduler benchmarks

  comet:~/tip/tools/perf> ./perf bench mem

        # List of available benchmarks for collection 'mem':

        memcpy: Benchmark for memcpy()
        memset: Benchmark for memset() tests
           all: Test all memory benchmarks

  comet:~/tip/tools/perf> ./perf bench numa

        # List of available benchmarks for collection 'numa':

           mem: Benchmark for NUMA workloads
           all: Test all NUMA benchmarks

Individual benchmark modules were not touched.
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Hitoshi Mitake <h.mitake@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung.kim@lge.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/20131023123756.GA17871@gmail.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 3d918a12
/* /*
*
* builtin-bench.c * builtin-bench.c
* *
* General benchmarking subsystem provided by perf * General benchmarking collections provided by perf
* *
* Copyright (C) 2009, Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp> * Copyright (C) 2009, Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp>
*
*/ */
/* /*
* Available benchmark collection list:
* *
* Available subsystem list: * sched ... scheduler and IPC performance
* sched ... scheduler and IPC mechanism
* mem ... memory access performance * mem ... memory access performance
* * numa ... NUMA scheduling and MM performance
*/ */
#include "perf.h" #include "perf.h"
#include "util/util.h" #include "util/util.h"
#include "util/parse-options.h" #include "util/parse-options.h"
...@@ -25,112 +22,92 @@ ...@@ -25,112 +22,92 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/prctl.h>
struct bench_suite { typedef int (*bench_fn_t)(int argc, const char **argv, const char *prefix);
const char *name;
const char *summary; struct bench {
int (*fn)(int, const char **, const char *); const char *name;
const char *summary;
bench_fn_t fn;
}; };
\
/* sentinel: easy for help */
#define suite_all { "all", "Test all benchmark suites", NULL }
#ifdef HAVE_LIBNUMA_SUPPORT #ifdef HAVE_LIBNUMA_SUPPORT
static struct bench_suite numa_suites[] = { static struct bench numa_benchmarks[] = {
{ "mem", { "mem", "Benchmark for NUMA workloads", bench_numa },
"Benchmark for NUMA workloads", { "all", "Test all NUMA benchmarks", NULL },
bench_numa }, { NULL, NULL, NULL }
suite_all,
{ NULL,
NULL,
NULL }
}; };
#endif #endif
static struct bench_suite sched_suites[] = { static struct bench sched_benchmarks[] = {
{ "messaging", { "messaging", "Benchmark for scheduling and IPC", bench_sched_messaging },
"Benchmark for scheduler and IPC mechanisms", { "pipe", "Benchmark for pipe() between two processes", bench_sched_pipe },
bench_sched_messaging }, { "all", "Test all scheduler benchmarks", NULL },
{ "pipe", { NULL, NULL, NULL }
"Flood of communication over pipe() between two processes",
bench_sched_pipe },
suite_all,
{ NULL,
NULL,
NULL }
}; };
static struct bench_suite mem_suites[] = { static struct bench mem_benchmarks[] = {
{ "memcpy", { "memcpy", "Benchmark for memcpy()", bench_mem_memcpy },
"Simple memory copy in various ways", { "memset", "Benchmark for memset() tests", bench_mem_memset },
bench_mem_memcpy }, { "all", "Test all memory benchmarks", NULL },
{ "memset", { NULL, NULL, NULL }
"Simple memory set in various ways",
bench_mem_memset },
suite_all,
{ NULL,
NULL,
NULL }
}; };
struct bench_subsys { struct collection {
const char *name; const char *name;
const char *summary; const char *summary;
struct bench_suite *suites; struct bench *benchmarks;
}; };
static struct bench_subsys subsystems[] = { static struct collection collections[] = {
{ "sched", "Scheduler and IPC benchmarks", sched_benchmarks },
{ "mem", "Memory access benchmarks", mem_benchmarks },
#ifdef HAVE_LIBNUMA_SUPPORT #ifdef HAVE_LIBNUMA_SUPPORT
{ "numa", { "numa", "NUMA scheduling and MM benchmarks", numa_benchmarks },
"NUMA scheduling and MM behavior",
numa_suites },
#endif #endif
{ "sched", { "all", "All benchmarks", NULL },
"scheduler and IPC mechanism", { NULL, NULL, NULL }
sched_suites },
{ "mem",
"memory access performance",
mem_suites },
{ "all", /* sentinel: easy for help */
"all benchmark subsystem",
NULL },
{ NULL,
NULL,
NULL }
}; };
static void dump_suites(int subsys_index) /* Iterate over all benchmark collections: */
#define for_each_collection(coll) \
for (coll = collections; coll->name; coll++)
/* Iterate over all benchmarks within a collection: */
#define for_each_bench(coll, bench) \
for (bench = coll->benchmarks; bench->name; bench++)
static void dump_benchmarks(struct collection *coll)
{ {
int i; struct bench *bench;
printf("# List of available suites for %s...\n\n", printf("\n # List of available benchmarks for collection '%s':\n\n", coll->name);
subsystems[subsys_index].name);
for (i = 0; subsystems[subsys_index].suites[i].name; i++) for_each_bench(coll, bench)
printf("%14s: %s\n", printf("%14s: %s\n", bench->name, bench->summary);
subsystems[subsys_index].suites[i].name,
subsystems[subsys_index].suites[i].summary);
printf("\n"); printf("\n");
return;
} }
static const char *bench_format_str; static const char *bench_format_str;
/* Output/formatting style, exported to benchmark modules: */
int bench_format = BENCH_FORMAT_DEFAULT; int bench_format = BENCH_FORMAT_DEFAULT;
static const struct option bench_options[] = { static const struct option bench_options[] = {
OPT_STRING('f', "format", &bench_format_str, "default", OPT_STRING('f', "format", &bench_format_str, "default", "Specify format style"),
"Specify format style"),
OPT_END() OPT_END()
}; };
static const char * const bench_usage[] = { static const char * const bench_usage[] = {
"perf bench [<common options>] <subsystem> <suite> [<options>]", "perf bench [<common options>] <collection> <benchmark> [<options>]",
NULL NULL
}; };
static void print_usage(void) static void print_usage(void)
{ {
struct collection *coll;
int i; int i;
printf("Usage: \n"); printf("Usage: \n");
...@@ -138,11 +115,10 @@ static void print_usage(void) ...@@ -138,11 +115,10 @@ static void print_usage(void)
printf("\t%s\n", bench_usage[i]); printf("\t%s\n", bench_usage[i]);
printf("\n"); printf("\n");
printf("# List of available subsystems...\n\n"); printf(" # List of all available benchmark collections:\n\n");
for (i = 0; subsystems[i].name; i++) for_each_collection(coll)
printf("%14s: %s\n", printf("%14s: %s\n", coll->name, coll->summary);
subsystems[i].name, subsystems[i].summary);
printf("\n"); printf("\n");
} }
...@@ -159,44 +135,74 @@ static int bench_str2int(const char *str) ...@@ -159,44 +135,74 @@ static int bench_str2int(const char *str)
return BENCH_FORMAT_UNKNOWN; return 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 *coll_name, const char *bench_name, bench_fn_t fn,
int argc, const char **argv, const char *prefix)
{ {
int i; int size;
char *name;
int ret;
size = strlen(coll_name) + 1 + strlen(bench_name) + 1;
name = zalloc(size);
BUG_ON(!name);
scnprintf(name, size, "%s-%s", coll_name, bench_name);
prctl(PR_SET_NAME, name);
argv[0] = name;
ret = fn(argc, argv, prefix);
free(name);
return ret;
}
static void run_collection(struct collection *coll)
{
struct bench *bench;
const char *argv[2]; const char *argv[2];
struct bench_suite *suites = subsys->suites;
argv[1] = NULL; argv[1] = NULL;
/* /*
* TODO: * TODO:
* preparing preset parameters for *
* Preparing preset parameters for
* embedded, ordinary PC, HPC, etc... * embedded, ordinary PC, HPC, etc...
* will be helpful * would be helpful.
*/ */
for (i = 0; suites[i].fn; i++) { for_each_bench(coll, bench) {
printf("# Running %s/%s benchmark...\n", if (!bench->fn)
subsys->name, break;
suites[i].name); printf("# Running %s/%s benchmark...\n", coll->name, bench->name);
fflush(stdout); fflush(stdout);
argv[1] = suites[i].name; argv[1] = bench->name;
suites[i].fn(1, argv, NULL); run_bench(coll->name, bench->name, bench->fn, 1, argv, NULL);
printf("\n"); printf("\n");
} }
} }
static void all_subsystem(void) static void run_all_collections(void)
{ {
int i; struct collection *coll;
for (i = 0; subsystems[i].suites; i++)
all_suite(&subsystems[i]); for_each_collection(coll)
run_collection(coll);
} }
int cmd_bench(int argc, const char **argv, const char *prefix __maybe_unused) int cmd_bench(int argc, const char **argv, const char *prefix __maybe_unused)
{ {
int i, j, status = 0; struct collection *coll;
int ret = 0;
if (argc < 2) { if (argc < 2) {
/* No subsystem specified. */ /* No collection specified. */
print_usage(); print_usage();
goto end; goto end;
} }
...@@ -206,7 +212,7 @@ int cmd_bench(int argc, const char **argv, const char *prefix __maybe_unused) ...@@ -206,7 +212,7 @@ int cmd_bench(int argc, const char **argv, const char *prefix __maybe_unused)
bench_format = bench_str2int(bench_format_str); bench_format = bench_str2int(bench_format_str);
if (bench_format == BENCH_FORMAT_UNKNOWN) { if (bench_format == BENCH_FORMAT_UNKNOWN) {
printf("Unknown format descriptor:%s\n", bench_format_str); printf("Unknown format descriptor: '%s'\n", bench_format_str);
goto end; goto end;
} }
...@@ -216,52 +222,51 @@ int cmd_bench(int argc, const char **argv, const char *prefix __maybe_unused) ...@@ -216,52 +222,51 @@ int cmd_bench(int argc, const char **argv, const char *prefix __maybe_unused)
} }
if (!strcmp(argv[0], "all")) { if (!strcmp(argv[0], "all")) {
all_subsystem(); run_all_collections();
goto end; goto end;
} }
for (i = 0; subsystems[i].name; i++) { for_each_collection(coll) {
if (strcmp(subsystems[i].name, argv[0])) struct bench *bench;
if (strcmp(coll->name, argv[0]))
continue; continue;
if (argc < 2) { if (argc < 2) {
/* No suite specified. */ /* No bench specified. */
dump_suites(i); dump_benchmarks(coll);
goto end; goto end;
} }
if (!strcmp(argv[1], "all")) { if (!strcmp(argv[1], "all")) {
all_suite(&subsystems[i]); run_collection(coll);
goto end; goto end;
} }
for (j = 0; subsystems[i].suites[j].name; j++) { for_each_bench(coll, bench) {
if (strcmp(subsystems[i].suites[j].name, argv[1])) if (strcmp(bench->name, argv[1]))
continue; continue;
if (bench_format == BENCH_FORMAT_DEFAULT) if (bench_format == BENCH_FORMAT_DEFAULT)
printf("# Running %s/%s benchmark...\n", printf("# Running '%s/%s' benchmark:\n", coll->name, bench->name);
subsystems[i].name,
subsystems[i].suites[j].name);
fflush(stdout); fflush(stdout);
status = subsystems[i].suites[j].fn(argc - 1, ret = run_bench(coll->name, bench->name, bench->fn, argc-1, argv+1, prefix);
argv + 1, prefix);
goto end; goto end;
} }
if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) { if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
dump_suites(i); dump_benchmarks(coll);
goto end; goto end;
} }
printf("Unknown suite:%s for %s\n", argv[1], argv[0]); printf("Unknown benchmark: '%s' for collection '%s'\n", argv[1], argv[0]);
status = 1; ret = 1;
goto end; goto end;
} }
printf("Unknown subsystem:%s\n", argv[0]); printf("Unknown collection: '%s'\n", argv[0]);
status = 1; ret = 1;
end: end:
return status; return ret;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment