diff options
author | dds <dds@FreeBSD.org> | 2009-05-12 20:42:12 +0000 |
---|---|---|
committer | dds <dds@FreeBSD.org> | 2009-05-12 20:42:12 +0000 |
commit | bea63f2169976b2254c53843e9b89e787efeb6c0 (patch) | |
tree | 2ea5e736f24721832545f1c7f970fcd55dd11387 /usr.bin/truss/main.c | |
parent | 855c3dbe902b8404b5675dffea0c0642a9ac228a (diff) | |
download | FreeBSD-src-bea63f2169976b2254c53843e9b89e787efeb6c0.zip FreeBSD-src-bea63f2169976b2254c53843e9b89e787efeb6c0.tar.gz |
Add -c option to summarize number of calls, errors, and system time.
Reviewed by: alfred
Diffstat (limited to 'usr.bin/truss/main.c')
-rw-r--r-- | usr.bin/truss/main.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/usr.bin/truss/main.c b/usr.bin/truss/main.c index 9c1589b..4333f2d 100644 --- a/usr.bin/truss/main.c +++ b/usr.bin/truss/main.c @@ -58,6 +58,7 @@ __FBSDID("$FreeBSD$"); #include "truss.h" #include "extern.h" +#include "syscall.h" #define MAXARGS 6 @@ -65,8 +66,8 @@ static void usage(void) { fprintf(stderr, "%s\n%s\n", - "usage: truss [-faedDS] [-o file] [-s strsize] -p pid", - " truss [-faedDS] [-o file] [-s strsize] command [args]"); + "usage: truss [-cfaedDS] [-o file] [-s strsize] -p pid", + " truss [-cfaedDS] [-o file] [-s strsize] command [args]"); exit(1); } @@ -188,7 +189,7 @@ main(int ac, char **av) trussinfo->pr_why = S_NONE; trussinfo->curthread = NULL; SLIST_INIT(&trussinfo->threadlist); - while ((c = getopt(ac, av, "p:o:faedDs:S")) != -1) { + while ((c = getopt(ac, av, "p:o:facedDs:S")) != -1) { switch (c) { case 'p': /* specified pid */ trussinfo->pid = atoi(optarg); @@ -204,6 +205,9 @@ main(int ac, char **av) case 'a': /* Print execve() argument strings. */ trussinfo->flags |= EXECVEARGS; break; + case 'c': /* Count number of system calls and time. */ + trussinfo->flags |= COUNTONLY; + break; case 'e': /* Print execve() environment strings. */ trussinfo->flags |= EXECVEENVS; break; @@ -337,6 +341,8 @@ START_TRACE: free(signame); break; case S_EXIT: + if (trussinfo->flags & COUNTONLY) + break; if (trussinfo->flags & FOLLOWFORKS) fprintf(trussinfo->outfile, "%5d: ", trussinfo->pid); @@ -360,12 +366,16 @@ START_TRACE: break; } } while (trussinfo->pr_why != S_EXIT); - fflush(trussinfo->outfile); if (trussinfo->flags & FOLLOWFORKS) do { childpid = wait(&status); } while (childpid != -1); + if (trussinfo->flags & COUNTONLY) + print_summary(trussinfo); + + fflush(trussinfo->outfile); + return (0); } |