Use timespec not timeval.

This commit is contained in:
Matthew N. Dodd 2002-08-05 12:22:55 +00:00
parent 677adc79c2
commit 203098d816
3 changed files with 24 additions and 15 deletions

View File

@ -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,

View File

@ -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);

View File

@ -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;
};