WIP FPC-III support
[linux/fpc-iii.git] / tools / perf / bench / syscall.c
blob5fe621cff8e9330f1fb1dc46d4c4c6edbcac2e4f
1 /*
3 * syscall.c
5 * syscall: Benchmark for system call performance
6 */
7 #include "../perf.h"
8 #include "../util/util.h"
9 #include <subcmd/parse-options.h>
10 #include "../builtin.h"
11 #include "bench.h"
13 #include <stdio.h>
14 #include <sys/time.h>
15 #include <sys/syscall.h>
16 #include <sys/types.h>
17 #include <unistd.h>
18 #include <stdlib.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"),
25 OPT_END()
28 static const char * const bench_syscall_usage[] = {
29 "perf bench syscall <options>",
30 NULL
33 int bench_syscall_basic(int argc, const char **argv)
35 struct timeval start, stop, diff;
36 unsigned long long result_usec = 0;
37 int i;
39 argc = parse_options(argc, argv, options, bench_syscall_usage, 0);
41 gettimeofday(&start, NULL);
43 for (i = 0; i < loops; i++)
44 getppid();
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",
57 diff.tv_sec,
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",
63 (int)((double)loops /
64 ((double)result_usec / (double)1000000)));
65 break;
67 case BENCH_FORMAT_SIMPLE:
68 printf("%lu.%03lu\n",
69 diff.tv_sec,
70 (unsigned long) (diff.tv_usec / 1000));
71 break;
73 default:
74 /* reaching here is something disaster */
75 fprintf(stderr, "Unknown format:%d\n", bench_format);
76 exit(1);
77 break;
80 return 0;