Changeset View
Changeset View
Standalone View
Standalone View
tools/tools/syscall_timing/syscall_timing.c
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
static struct timespec ts_start, ts_end; | static struct timespec ts_start, ts_end; | ||||
static int alarm_timeout; | static int alarm_timeout; | ||||
static volatile int alarm_fired; | static volatile int alarm_fired; | ||||
#define timespecsub(vvp, uvp) \ | |||||
do { \ | |||||
(vvp)->tv_sec -= (uvp)->tv_sec; \ | |||||
(vvp)->tv_nsec -= (uvp)->tv_nsec; \ | |||||
if ((vvp)->tv_nsec < 0) { \ | |||||
(vvp)->tv_sec--; \ | |||||
(vvp)->tv_nsec += 1000000000; \ | |||||
} \ | |||||
} while (0) | |||||
static void | static void | ||||
alarm_handler(int signum) | alarm_handler(int signum) | ||||
{ | { | ||||
alarm_fired = 1; | alarm_fired = 1; | ||||
} | } | ||||
static void | static void | ||||
▲ Show 20 Lines • Show All 831 Lines • ▼ Show 20 Lines | for (j = 0; j < argc; j++) { | ||||
/* | /* | ||||
* Run one warmup, then do the real thing (loops) times. | * Run one warmup, then do the real thing (loops) times. | ||||
*/ | */ | ||||
the_test->t_func(iterations, the_test->t_int, path); | the_test->t_func(iterations, the_test->t_int, path); | ||||
calls = 0; | calls = 0; | ||||
for (k = 0; k < loops; k++) { | for (k = 0; k < loops; k++) { | ||||
calls = the_test->t_func(iterations, the_test->t_int, | calls = the_test->t_func(iterations, the_test->t_int, | ||||
path); | path); | ||||
timespecsub(&ts_end, &ts_start); | timespecsub(&ts_end, &ts_start, &ts_end); | ||||
printf("%s\t%d\t", the_test->t_name, k); | printf("%s\t%d\t", the_test->t_name, k); | ||||
printf("%ju.%09ju\t%ju\t", (uintmax_t)ts_end.tv_sec, | printf("%ju.%09ju\t%ju\t", (uintmax_t)ts_end.tv_sec, | ||||
(uintmax_t)ts_end.tv_nsec, calls); | (uintmax_t)ts_end.tv_nsec, calls); | ||||
/* | /* | ||||
* Note. This assumes that each iteration takes less than | * Note. This assumes that each iteration takes less than | ||||
* a second, and that our total nanoseconds doesn't exceed | * a second, and that our total nanoseconds doesn't exceed | ||||
* the room in our arithmetic unit. Fine for system calls, | * the room in our arithmetic unit. Fine for system calls, | ||||
Show All 20 Lines |