diff options
author | Matthew N. Dodd <mdodd@FreeBSD.org> | 2002-08-04 01:27:31 +0000 |
---|---|---|
committer | Matthew N. Dodd <mdodd@FreeBSD.org> | 2002-08-04 01:27:31 +0000 |
commit | 0d0bd00edddd5ee241f216996ae473a5d44ac32c (patch) | |
tree | 1ea381bca59453aef6677708cd85d541a2dc4c3e /usr.bin/truss | |
parent | 9ccba881d953d60acb7096c7661e0f1a8581b3b8 (diff) | |
download | src-0d0bd00edddd5ee241f216996ae473a5d44ac32c.tar.gz src-0d0bd00edddd5ee241f216996ae473a5d44ac32c.zip |
Add options to print absolute and relative timestamps.
PR: bin/25587 (in part)
MFC after: 3 weeks
Notes
Notes:
svn path=/head/; revision=101285
Diffstat (limited to 'usr.bin/truss')
-rw-r--r-- | usr.bin/truss/main.c | 16 | ||||
-rw-r--r-- | usr.bin/truss/syscalls.c | 19 | ||||
-rw-r--r-- | usr.bin/truss/truss.1 | 10 | ||||
-rw-r--r-- | usr.bin/truss/truss.h | 6 |
4 files changed, 46 insertions, 5 deletions
diff --git a/usr.bin/truss/main.c b/usr.bin/truss/main.c index d1a236a7992a..0a31993fa1e6 100644 --- a/usr.bin/truss/main.c +++ b/usr.bin/truss/main.c @@ -67,8 +67,8 @@ static __inline void usage(void) { fprintf(stderr, "%s\n%s\n", - "usage: truss [-fS] [-o file] -p pid", - " truss [-fS] [-o file] command [args]"); + "usage: truss [-fdDS] [-o file] -p pid", + " truss [-fdDS] [-o file] command [args]"); exit(1); } @@ -145,7 +145,7 @@ main(int ac, char **av) { bzero(trussinfo, sizeof(struct trussinfo)); trussinfo->outfile = stderr; - while ((c = getopt(ac, av, "p:o:fS")) != -1) { + while ((c = getopt(ac, av, "p:o:fdDS")) != -1) { switch (c) { case 'p': /* specified pid */ trussinfo->pid = atoi(optarg); @@ -153,6 +153,12 @@ main(int ac, char **av) { case 'f': /* Follow fork()'s */ trussinfo->flags |= FOLLOWFORKS; break; + case 'd': /* Absolute timestamps */ + trussinfo->flags |= ABSOLUTETIMESTAMPS; + break; + case 'D': /* Relative timestamps */ + trussinfo->flags |= RELATIVETIMESTAMPS; + break; case 'o': /* Specified output file */ fname = optarg; break; @@ -215,6 +221,8 @@ START_TRACE: * All of the grunt work is done in the support routines. */ + gettimeofday(&trussinfo->start_time, (struct timezone *)NULL); + do { int val = 0; @@ -224,8 +232,10 @@ START_TRACE: switch(i = pfs.why) { case S_SCE: funcs->enter_syscall(trussinfo, pfs.val); + gettimeofday(&trussinfo->before, (struct timezone *)NULL); break; case S_SCX: + gettimeofday(&trussinfo->after, (struct timezone *)NULL); /* * 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 8056aa122270..1ad7fe1b14f7 100644 --- a/usr.bin/truss/syscalls.c +++ b/usr.bin/truss/syscalls.c @@ -40,6 +40,7 @@ static const char rcsid[] = */ #include <sys/types.h> +#include <sys/time.h> #include <sys/socket.h> #include <sys/un.h> #include <netinet/in.h> @@ -358,9 +359,27 @@ print_syscall(struct trussinfo *trussinfo, const char *name, int nargs, char **s int i; int len = 0; + struct timeval 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); + } + + if (trussinfo->flags & ABSOLUTETIMESTAMPS) { + timersub(&trussinfo->after, &trussinfo->start_time, &timediff); + len += fprintf(trussinfo->outfile, "%d.%0.7d ", + timediff.tv_sec, timediff.tv_usec); + } + + if (trussinfo->flags & RELATIVETIMESTAMPS) { + timersub(&trussinfo->after, &trussinfo->before, &timediff); + len += fprintf(trussinfo->outfile, "%d.%0.7d ", + timediff.tv_sec, timediff.tv_usec); + } + len += fprintf(trussinfo->outfile, "%s(", name); for (i = 0; i < nargs; i++) { diff --git a/usr.bin/truss/truss.1 b/usr.bin/truss/truss.1 index 58f9ac53d820..d4cbb6acfd30 100644 --- a/usr.bin/truss/truss.1 +++ b/usr.bin/truss/truss.1 @@ -8,11 +8,11 @@ .Nd trace system calls .Sh SYNOPSIS .Nm -.Op Fl fS +.Op Fl fdDS .Op Fl o Ar file .Fl p Ar pid .Nm -.Op Fl fS +.Op Fl fdDS .Op Fl o Ar file command .Op args @@ -29,6 +29,12 @@ The options are as follows: .It Fl f Trace decendants of the original traced process created by fork(), vfork, etc. +.It Fl d +Include timestamps in the output showing the time elapsed +since the trace was started. +.It Fl D +Include timestamps in the output showing the time elapsed +since the last recorded event. .It Fl S Do not display information about signals received by the process. (Normally, diff --git a/usr.bin/truss/truss.h b/usr.bin/truss/truss.h index f77202aec264..2bb5c8566e09 100644 --- a/usr.bin/truss/truss.h +++ b/usr.bin/truss/truss.h @@ -26,6 +26,8 @@ */ #define FOLLOWFORKS 0x00000001 +#define RELATIVETIMESTAMPS 0x00000002 +#define ABSOLUTETIMESTAMPS 0x00000004 #define NOSIGS 0x00000008 struct trussinfo @@ -34,4 +36,8 @@ struct trussinfo int flags; int in_fork; FILE *outfile; + + struct timeval start_time; + struct timeval before; + struct timeval after; }; |