From 2ba9baa8d34bdbfbcef656a6a190236269bc1baf Mon Sep 17 00:00:00 2001 From: mdodd Date: Mon, 5 Aug 2002 12:22:55 +0000 Subject: Use timespec not timeval. --- usr.bin/truss/main.c | 6 +++--- usr.bin/truss/syscalls.c | 27 ++++++++++++++++++--------- usr.bin/truss/truss.h | 6 +++--- 3 files changed, 24 insertions(+), 15 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/truss/main.c b/usr.bin/truss/main.c index dc35184..31a067c 100644 --- a/usr.bin/truss/main.c +++ b/usr.bin/truss/main.c @@ -232,7 +232,7 @@ START_TRACE: * All of the grunt work is done in the support routines. */ - gettimeofday(&trussinfo->start_time, (struct timezone *)NULL); + clock_gettime(CLOCK_REALTIME, &trussinfo->start_time); do { int val = 0; @@ -243,10 +243,10 @@ START_TRACE: switch(i = pfs.why) { case S_SCE: funcs->enter_syscall(trussinfo, pfs.val); - gettimeofday(&trussinfo->before, (struct timezone *)NULL); + clock_gettime(CLOCK_REALTIME, &trussinfo->before); break; case S_SCX: - gettimeofday(&trussinfo->after, (struct timezone *)NULL); + clock_gettime(CLOCK_REALTIME, &trussinfo->after); /* * This is so we don't get two messages for an exec -- one * for the S_EXEC, and one for the syscall exit. It also, diff --git a/usr.bin/truss/syscalls.c b/usr.bin/truss/syscalls.c index 18c486e..aa5e088 100644 --- a/usr.bin/truss/syscalls.c +++ b/usr.bin/truss/syscalls.c @@ -385,6 +385,16 @@ print_arg(int fd, struct syscall_args *sc, unsigned long *args) { return tmp; } +#define timespecsubt(tvp, uvp, vvp) \ + do { \ + (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ + (vvp)->tv_nsec = (tvp)->tv_nsec - (uvp)->tv_nsec; \ + if ((vvp)->tv_nsec < 0) { \ + (vvp)->tv_sec--; \ + (vvp)->tv_nsec += 1000000000; \ + } \ + } while (0) + /* * print_syscall * Print (to outfile) the system call and its arguments. Note that @@ -396,26 +406,25 @@ void print_syscall(struct trussinfo *trussinfo, const char *name, int nargs, char **s_args) { int i; int len = 0; - - struct timeval timediff; + struct timespec timediff; if (trussinfo->flags & FOLLOWFORKS) len += fprintf(trussinfo->outfile, "%5d: ", trussinfo->pid); if (!strcmp(name, "execve") || !strcmp(name, "exit")) { - gettimeofday(&trussinfo->after, (struct timezone *)NULL); + clock_gettime(CLOCK_REALTIME, &trussinfo->after); } if (trussinfo->flags & ABSOLUTETIMESTAMPS) { - timersub(&trussinfo->after, &trussinfo->start_time, &timediff); - len += fprintf(trussinfo->outfile, "%d.%0.7d ", - timediff.tv_sec, timediff.tv_usec); + timespecsubt(&trussinfo->after, &trussinfo->start_time, &timediff); + len += fprintf(trussinfo->outfile, "%d.%0.9d ", + timediff.tv_sec, timediff.tv_nsec); } if (trussinfo->flags & RELATIVETIMESTAMPS) { - timersub(&trussinfo->after, &trussinfo->before, &timediff); - len += fprintf(trussinfo->outfile, "%d.%0.7d ", - timediff.tv_sec, timediff.tv_usec); + timespecsubt(&trussinfo->after, &trussinfo->before, &timediff); + len += fprintf(trussinfo->outfile, "%d.%0.9d ", + timediff.tv_sec, timediff.tv_nsec); } len += fprintf(trussinfo->outfile, "%s(", name); diff --git a/usr.bin/truss/truss.h b/usr.bin/truss/truss.h index e8da036..00df4d6 100644 --- a/usr.bin/truss/truss.h +++ b/usr.bin/truss/truss.h @@ -39,7 +39,7 @@ struct trussinfo int in_fork; FILE *outfile; - struct timeval start_time; - struct timeval before; - struct timeval after; + struct timespec start_time; + struct timespec before; + struct timespec after; }; -- cgit v1.1