5 * syscall: Benchmark for system call performance
8 #include "../util/util.h"
9 #include <subcmd/parse-options.h>
10 #include "../builtin.h"
15 #include <sys/syscall.h>
16 #include <sys/types.h>
20 #define LOOPS_DEFAULT 10000000
21 static int loops
= LOOPS_DEFAULT
;
23 static const struct option options
[] = {
24 OPT_INTEGER('l', "loop", &loops
, "Specify number of loops"),
28 static const char * const bench_syscall_usage
[] = {
29 "perf bench syscall <options>",
33 int bench_syscall_basic(int argc
, const char **argv
)
35 struct timeval start
, stop
, diff
;
36 unsigned long long result_usec
= 0;
39 argc
= parse_options(argc
, argv
, options
, bench_syscall_usage
, 0);
41 gettimeofday(&start
, NULL
);
43 for (i
= 0; i
< loops
; i
++)
46 gettimeofday(&stop
, NULL
);
47 timersub(&stop
, &start
, &diff
);
49 switch (bench_format
) {
50 case BENCH_FORMAT_DEFAULT
:
51 printf("# Executed %'d getppid() calls\n", loops
);
53 result_usec
= diff
.tv_sec
* 1000000;
54 result_usec
+= diff
.tv_usec
;
56 printf(" %14s: %lu.%03lu [sec]\n\n", "Total time",
58 (unsigned long) (diff
.tv_usec
/1000));
60 printf(" %14lf usecs/op\n",
61 (double)result_usec
/ (double)loops
);
62 printf(" %'14d ops/sec\n",
64 ((double)result_usec
/ (double)1000000)));
67 case BENCH_FORMAT_SIMPLE
:
70 (unsigned long) (diff
.tv_usec
/ 1000));
74 /* reaching here is something disaster */
75 fprintf(stderr
, "Unknown format:%d\n", bench_format
);