Rewrote the syscallbench app. It now will figure the overhead of a simple test loop,

then the overhead of a call into libroot, and finally the overhead of a syscall 
(using is_computer_on).
The numbers are totally abysmal right now. :(


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20070 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Travis Geiselbrecht
2007-02-04 21:12:54 +00:00
parent ea4ff0f689
commit bee597ebfb
+38 -20
View File
@@ -9,7 +9,9 @@
#include <sys/time.h> #include <sys/time.h>
#include <unistd.h> #include <unistd.h>
#define ITERATIONS 1000000 #include <OS.h>
#define ITERATIONS 500000
static void static void
usage(void) usage(void)
@@ -18,34 +20,50 @@ usage(void)
exit(1); exit(1);
} }
static int null_func(void)
{
return 0;
}
static unsigned long test_func(int (*func)(void))
{
struct timeval before, after;
unsigned long elapsed;
int i;
gettimeofday(&before, NULL);
for (i=0; i<ITERATIONS; i++) {
func();
}
gettimeofday(&after, NULL);
elapsed = 1000000 * (after.tv_sec - before.tv_sec);
elapsed += after.tv_usec - before.tv_usec;
return elapsed;
}
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
struct timeval before, after; unsigned long overhead;
unsigned long overhead, elapsed; unsigned long libcall;
int i; unsigned long syscall;
pid_t pid;
if (argc > 1) if (argc > 1)
usage(); usage();
gettimeofday(&before, NULL); overhead = test_func(&null_func);
for (i=0; i<ITERATIONS; i++) { libcall = test_func((void *)&getpid); // getpid is currently implemented as a library function returning the value of a global
} syscall = test_func((void *)&is_computer_on);
gettimeofday(&after, NULL);
overhead = 1000000 * (after.tv_sec - before.tv_sec); printf("overhead time: %ld microseconds\n",
overhead += after.tv_usec - before.tv_usec; (1000*(overhead))/ITERATIONS);
gettimeofday(&before, NULL); printf("libcall time: %ld microseconds\n",
for (i=0; i<ITERATIONS; i++) { (1000*(libcall-overhead))/ITERATIONS);
pid = getpid();
}
gettimeofday(&after, NULL);
elapsed = 1000000 * (after.tv_sec - before.tv_sec);
elapsed += after.tv_usec - before.tv_usec;
printf("syscall time: %ld microseconds\n", printf("syscall time: %ld microseconds\n",
(1000*(elapsed-overhead))/ITERATIONS); (1000*(syscall-overhead))/ITERATIONS);
return (0); return (0);
} }