2009-11-09 17:03:27

by Hitoshi Mitake

[permalink] [raw]
Subject: [PATCH 0/4] perf bench: Common option for specifying style formatting

This patch series adds new option "--format" to
bench subcommand of perf.

Users of perf bench will be able to specify
style formatting with this option in common way.

Hitoshi Mitake (4):
perf bench: Add stuffs to bench.h for unified output formatting
perf bench: Modify builtin-bench.c for processing common options
perf bench: Modified bench/bench-messaging.c to adopt unified output
formatting
perf bench: Modify builtin-pipe.c for processing common options

tools/perf/bench/bench.h | 9 ++++
tools/perf/bench/sched-messaging.c | 18 +++++---
tools/perf/bench/sched-pipe.c | 22 ++++++----
tools/perf/builtin-bench.c | 79 +++++++++++++++++++++++++++++------
4 files changed, 99 insertions(+), 29 deletions(-)


2009-11-09 17:03:33

by Hitoshi Mitake

[permalink] [raw]
Subject: [PATCH 1/4] perf bench: Add stuffs to bench.h for unified output formatting

This patch adds some constants and extern declaration to bench.h.
These stuffs are used for unified output formatting
of 'perf bench'.

Signed-off-by: Hitoshi Mitake <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Paul Mackerras <[email protected]>
---
tools/perf/bench/bench.h | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/tools/perf/bench/bench.h b/tools/perf/bench/bench.h
index 59adb27..42167ea 100644
--- a/tools/perf/bench/bench.h
+++ b/tools/perf/bench/bench.h
@@ -6,4 +6,13 @@ extern int bench_sched_messaging(int argc, const char **argv,
extern int bench_sched_pipe(int argc, const char **argv,
const char *prefix);

+#define BENCH_FORMAT_DEFAULT_STR "default"
+#define BENCH_FORMAT_DEFAULT 0
+#define BENCH_FORMAT_SIMPLE_STR "simple"
+#define BENCH_FORMAT_SIMPLE 1
+
+#define BENCH_FORMAT_UNKNOWN -1
+
+extern int bench_format;
+
#endif
--
1.5.6.5

2009-11-09 17:03:37

by Hitoshi Mitake

[permalink] [raw]
Subject: [PATCH 2/4] perf bench: Modify builtin-bench.c for processing common options

This patch modifies builtin-bench.c for processing common options.
The first option added is "--format".
Users of perf bench will be able to specify output style by --format.

Example of use:
% ./perf bench sched messaging # with no style specify
(20 sender and receiver processes per group)
(10 groups == 400 processes run)

Total time:1.431 sec
% ./perf bench --format=simple sched messaging # specified simple
1.431

Signed-off-by: Hitoshi Mitake <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Paul Mackerras <[email protected]>
---
tools/perf/builtin-bench.c | 79 ++++++++++++++++++++++++++++++++++++--------
1 files changed, 65 insertions(+), 14 deletions(-)

diff --git a/tools/perf/builtin-bench.c b/tools/perf/builtin-bench.c
index 31f4164..c7505ea 100644
--- a/tools/perf/builtin-bench.c
+++ b/tools/perf/builtin-bench.c
@@ -74,53 +74,104 @@ static void dump_suites(int subsys_index)
return;
}

+static char *bench_format_str;
+int bench_format = BENCH_FORMAT_DEFAULT;
+
+static const struct option bench_options[] = {
+ OPT_STRING('f', "format", &bench_format_str, "default",
+ "Specify format style"),
+ OPT_END()
+};
+
+static const char * const bench_usage[] = {
+ "perf bench [<common options>] <subsystem> <suite> [<options>]",
+ NULL
+};
+
+static void print_usage(void)
+{
+ int i;
+
+ printf("Usage: \n");
+ for (i = 0; bench_usage[i]; i++)
+ printf("\t%s\n", bench_usage[i]);
+ printf("\n");
+
+ printf("List of available subsystems...\n\n");
+
+ for (i = 0; subsystems[i].name; i++)
+ printf("\t%s: %s\n",
+ subsystems[i].name, subsystems[i].summary);
+ printf("\n");
+}
+
+static int bench_str2int(char *str)
+{
+ if (!str)
+ return BENCH_FORMAT_DEFAULT;
+
+ if (!strcmp(str, BENCH_FORMAT_DEFAULT_STR))
+ return BENCH_FORMAT_DEFAULT;
+ else if (!strcmp(str, BENCH_FORMAT_SIMPLE_STR))
+ return BENCH_FORMAT_SIMPLE;
+
+ return BENCH_FORMAT_UNKNOWN;
+}
+
int cmd_bench(int argc, const char **argv, const char *prefix __used)
{
int i, j, status = 0;

if (argc < 2) {
/* No subsystem specified. */
- printf("Usage: perf bench <subsystem> <suite> [<options>]\n\n");
- printf("List of available subsystems...\n\n");
+ print_usage();
+ goto end;
+ }

- for (i = 0; subsystems[i].name; i++)
- printf("\t%s: %s\n",
- subsystems[i].name, subsystems[i].summary);
- printf("\n");
+ argc = parse_options(argc, argv, bench_options, bench_usage,
+ PARSE_OPT_STOP_AT_NON_OPTION);
+
+ bench_format = bench_str2int(bench_format_str);
+ if (bench_format == BENCH_FORMAT_UNKNOWN) {
+ printf("Unknown format descriptor:%s\n", bench_format_str);
+ goto end;
+ }

+ if (argc < 1) {
+ print_usage();
goto end;
}

for (i = 0; subsystems[i].name; i++) {
- if (strcmp(subsystems[i].name, argv[1]))
+ if (strcmp(subsystems[i].name, argv[0]))
continue;

- if (argc < 3) {
+ if (argc < 2) {
/* No suite specified. */
dump_suites(i);
goto end;
}

for (j = 0; subsystems[i].suites[j].name; j++) {
- if (strcmp(subsystems[i].suites[j].name, argv[2]))
+ if (strcmp(subsystems[i].suites[j].name, argv[1]))
continue;

- status = subsystems[i].suites[j].fn(argc - 2,
- argv + 2, prefix);
+ status = subsystems[i].suites[j].fn(argc - 1,
+ argv + 1, prefix);
goto end;
}

- if (!strcmp(argv[2], "-h") || !strcmp(argv[2], "--help")) {
+ if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
dump_suites(i);
goto end;
}

- printf("Unknown suite:%s for %s\n", argv[2], argv[1]);
+ printf("Unknown suite:%s for %s\n", argv[1], argv[0]);
status = 1;
goto end;
}

- printf("Unknown subsystem:%s\n", argv[1]);
+ printf("Unknown subsystem:%s\n", argv[0]);
status = 1;

end:
--
1.5.6.5

2009-11-09 17:03:37

by Hitoshi Mitake

[permalink] [raw]
Subject: [PATCH 3/4] perf bench: Modified bench/bench-messaging.c to adopt unified output formatting

This patch modifies bench/bench-messaging.c to adopt
unified output formatting: --format option.

Example of use:
% ./perf bench sched messaging # with no style specify
(20 sender and receiver processes per group)
(10 groups == 400 processes run)

Total time:1.431 sec
% ./perf bench --format=simple sched messaging # specified simple
1.431

Signed-off-by: Hitoshi Mitake <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Paul Mackerras <[email protected]>
---
tools/perf/bench/sched-messaging.c | 18 +++++++++++-------
1 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/tools/perf/bench/sched-messaging.c b/tools/perf/bench/sched-messaging.c
index 36b62c5..2cc5edc 100644
--- a/tools/perf/bench/sched-messaging.c
+++ b/tools/perf/bench/sched-messaging.c
@@ -35,7 +35,6 @@ static int use_pipes = 0;
static unsigned int loops = 100;
static unsigned int thread_mode = 0;
static unsigned int num_groups = 10;
-static int simple = 0;

struct sender_context {
unsigned int num_fds;
@@ -261,9 +260,6 @@ static const struct option options[] = {
"Specify number of groups"),
OPT_INTEGER('l', "loop", &loops,
"Specify number of loops"),
- OPT_BOOLEAN('s', "simple-output", &simple,
- "Do simple output (this maybe useful for"
- "processing by scripts or graph tools like gnuplot)"),
OPT_END()
};

@@ -316,9 +312,8 @@ int bench_sched_messaging(int argc, const char **argv,

timersub(&stop, &start, &diff);

- if (simple)
- printf("%lu.%03lu\n", diff.tv_sec, diff.tv_usec/1000);
- else {
+ switch (bench_format) {
+ case BENCH_FORMAT_DEFAULT:
printf("(%d sender and receiver %s per group)\n",
num_fds, thread_mode ? "threads" : "processes");
printf("(%d groups == %d %s run)\n\n",
@@ -326,6 +321,15 @@ int bench_sched_messaging(int argc, const char **argv,
thread_mode ? "threads" : "processes");
printf("\tTotal time:%lu.%03lu sec\n",
diff.tv_sec, diff.tv_usec/1000);
+ break;
+ case BENCH_FORMAT_SIMPLE:
+ printf("%lu.%03lu\n", diff.tv_sec, diff.tv_usec/1000);
+ break;
+ default:
+ /* reaching here is something disaster */
+ fprintf(stderr, "Unknown format:%d\n", bench_format);
+ exit(1);
+ break;
}

return 0;
--
1.5.6.5

2009-11-09 17:03:36

by Hitoshi Mitake

[permalink] [raw]
Subject: [PATCH 4/4] perf bench: Modify builtin-pipe.c for processing common options

This patch modifies builtin-pipe.c for processing common options.
The first option added is "--format".
Users of perf bench will be able to specify output style by --format.

Example of use:
% ./perf bench sched pipe # with no style specify
(executing 1000000 pipe operations between two tasks)

Total time:5.855 sec
5.855061 usecs/op
170792 ops/sec
% ./perf bench --format=simple sched pipe # specified simple
5.988

Signed-off-by: Hitoshi Mitake <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Paul Mackerras <[email protected]>
---
tools/perf/bench/sched-pipe.c | 22 ++++++++++++++--------
1 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/tools/perf/bench/sched-pipe.c b/tools/perf/bench/sched-pipe.c
index 6a29100..a9ac186 100644
--- a/tools/perf/bench/sched-pipe.c
+++ b/tools/perf/bench/sched-pipe.c
@@ -30,14 +30,10 @@

#define LOOPS_DEFAULT 1000000
static int loops = LOOPS_DEFAULT;
-static int simple = 0;

static const struct option options[] = {
OPT_INTEGER('l', "loop", &loops,
"Specify number of loops"),
- OPT_BOOLEAN('s', "simple-output", &simple,
- "Do simple output (this maybe useful for"
- "processing by scripts or graph tools like gnuplot)"),
OPT_END()
};

@@ -94,10 +90,8 @@ int bench_sched_pipe(int argc, const char **argv,
return 0;
}

- if (simple)
- printf("%lu.%03lu\n",
- diff.tv_sec, diff.tv_usec / 1000);
- else {
+ switch (bench_format) {
+ case BENCH_FORMAT_DEFAULT:
printf("(executing %d pipe operations between two tasks)\n\n",
loops);

@@ -111,6 +105,18 @@ int bench_sched_pipe(int argc, const char **argv,
printf("\t\t%d ops/sec\n",
(int)((double)loops /
((double)result_usec / (double)1000000)));
+ break;
+
+ case BENCH_FORMAT_SIMPLE:
+ printf("%lu.%03lu\n",
+ diff.tv_sec, diff.tv_usec / 1000);
+ break;
+
+ default:
+ /* reaching here is something disaster */
+ fprintf(stderr, "Unknown format:%d\n", bench_format);
+ exit(1);
+ break;
}

return 0;
--
1.5.6.5

2009-11-09 17:59:23

by Peter Zijlstra

[permalink] [raw]
Subject: Re: [PATCH 0/4] perf bench: Common option for specifying style formatting

On Tue, 2009-11-10 at 02:03 +0900, Hitoshi Mitake wrote:
> Mailer:
> git-send-email 1.6.5.2

Please teach your git-send-email thing to use --no-chain-reply-to.

2009-11-09 23:19:33

by Hitoshi Mitake

[permalink] [raw]
Subject: Re: [PATCH 0/4] perf bench: Common option for specifying style formatting

From: Peter Zijlstra <[email protected]>
Subject: Re: [PATCH 0/4] perf bench: Common option for specifying style formatting
Date: Mon, 09 Nov 2009 18:59:15 +0100

> On Tue, 2009-11-10 at 02:03 +0900, Hitoshi Mitake wrote:
> > Mailer:
> > git-send-email 1.6.5.2
>
> Please teach your git-send-email thing to use --no-chain-reply-to.

Sorry, I'll send version 2 with --no-chain-reply-to.