0001
0002
0003
0004
0005
0006
0007 #include "../perf.h"
0008 #include "../util/util.h"
0009 #include <subcmd/parse-options.h>
0010 #include "../builtin.h"
0011 #include "bench.h"
0012
0013 #include <stdio.h>
0014 #include <sys/time.h>
0015 #include <sys/syscall.h>
0016 #include <sys/types.h>
0017 #include <unistd.h>
0018 #include <stdlib.h>
0019
0020 #define LOOPS_DEFAULT 10000000
0021 static int loops = LOOPS_DEFAULT;
0022
0023 static const struct option options[] = {
0024 OPT_INTEGER('l', "loop", &loops, "Specify number of loops"),
0025 OPT_END()
0026 };
0027
0028 static const char * const bench_syscall_usage[] = {
0029 "perf bench syscall <options>",
0030 NULL
0031 };
0032
0033 int bench_syscall_basic(int argc, const char **argv)
0034 {
0035 struct timeval start, stop, diff;
0036 unsigned long long result_usec = 0;
0037 int i;
0038
0039 argc = parse_options(argc, argv, options, bench_syscall_usage, 0);
0040
0041 gettimeofday(&start, NULL);
0042
0043 for (i = 0; i < loops; i++)
0044 getppid();
0045
0046 gettimeofday(&stop, NULL);
0047 timersub(&stop, &start, &diff);
0048
0049 switch (bench_format) {
0050 case BENCH_FORMAT_DEFAULT:
0051 printf("# Executed %'d getppid() calls\n", loops);
0052
0053 result_usec = diff.tv_sec * 1000000;
0054 result_usec += diff.tv_usec;
0055
0056 printf(" %14s: %lu.%03lu [sec]\n\n", "Total time",
0057 (unsigned long) diff.tv_sec,
0058 (unsigned long) (diff.tv_usec/1000));
0059
0060 printf(" %14lf usecs/op\n",
0061 (double)result_usec / (double)loops);
0062 printf(" %'14d ops/sec\n",
0063 (int)((double)loops /
0064 ((double)result_usec / (double)1000000)));
0065 break;
0066
0067 case BENCH_FORMAT_SIMPLE:
0068 printf("%lu.%03lu\n",
0069 (unsigned long) diff.tv_sec,
0070 (unsigned long) (diff.tv_usec / 1000));
0071 break;
0072
0073 default:
0074
0075 fprintf(stderr, "Unknown format:%d\n", bench_format);
0076 exit(1);
0077 break;
0078 }
0079
0080 return 0;
0081 }