perf bench: Add format constants to bench.h for unified output formatting
[deliverable/linux.git] / tools / perf / builtin-bench.c
CommitLineData
629cc356
HM
1/*
2 *
3 * builtin-bench.c
4 *
5 * General benchmarking subsystem provided by perf
6 *
7 * Copyright (C) 2009, Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp>
8 *
9 */
10
11/*
12 *
13 * Available subsystem list:
14 * sched ... scheduler and IPC mechanism
15 *
16 */
17
18#include "perf.h"
19#include "util/util.h"
20#include "util/parse-options.h"
21#include "builtin.h"
22#include "bench/bench.h"
23
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27
28struct bench_suite {
29 const char *name;
30 const char *summary;
31 int (*fn)(int, const char **, const char *);
32};
33
34static struct bench_suite sched_suites[] = {
35 { "messaging",
36 "Benchmark for scheduler and IPC mechanisms",
37 bench_sched_messaging },
38 { "pipe",
39 "Flood of communication over pipe() between two processes",
40 bench_sched_pipe },
41 { NULL,
42 NULL,
43 NULL }
44};
45
46struct bench_subsys {
47 const char *name;
48 const char *summary;
49 struct bench_suite *suites;
50};
51
52static struct bench_subsys subsystems[] = {
53 { "sched",
54 "scheduler and IPC mechanism",
55 sched_suites },
56 { NULL,
57 NULL,
58 NULL }
59};
60
61static void dump_suites(int subsys_index)
62{
63 int i;
64
65 printf("List of available suites for %s...\n\n",
66 subsystems[subsys_index].name);
67
68 for (i = 0; subsystems[subsys_index].suites[i].name; i++)
69 printf("\t%s: %s\n",
70 subsystems[subsys_index].suites[i].name,
71 subsystems[subsys_index].suites[i].summary);
72
73 printf("\n");
74 return;
75}
76
77int cmd_bench(int argc, const char **argv, const char *prefix __used)
78{
79 int i, j, status = 0;
80
81 if (argc < 2) {
82 /* No subsystem specified. */
83 printf("Usage: perf bench <subsystem> <suite> [<options>]\n\n");
84 printf("List of available subsystems...\n\n");
85
86 for (i = 0; subsystems[i].name; i++)
87 printf("\t%s: %s\n",
88 subsystems[i].name, subsystems[i].summary);
89 printf("\n");
90
91 goto end;
92 }
93
94 for (i = 0; subsystems[i].name; i++) {
95 if (strcmp(subsystems[i].name, argv[1]))
96 continue;
97
98 if (argc < 3) {
99 /* No suite specified. */
100 dump_suites(i);
101 goto end;
102 }
103
104 for (j = 0; subsystems[i].suites[j].name; j++) {
105 if (strcmp(subsystems[i].suites[j].name, argv[2]))
106 continue;
107
108 status = subsystems[i].suites[j].fn(argc - 2,
109 argv + 2, prefix);
110 goto end;
111 }
112
113 if (!strcmp(argv[2], "-h") || !strcmp(argv[2], "--help")) {
114 dump_suites(i);
115 goto end;
116 }
117
118 printf("Unknown suite:%s for %s\n", argv[2], argv[1]);
119 status = 1;
120 goto end;
121 }
122
123 printf("Unknown subsystem:%s\n", argv[1]);
124 status = 1;
125
126end:
127 return status;
128}
This page took 0.02788 seconds and 5 git commands to generate.