From bea63f2169976b2254c53843e9b89e787efeb6c0 Mon Sep 17 00:00:00 2001 From: dds Date: Tue, 12 May 2009 20:42:12 +0000 Subject: Add -c option to summarize number of calls, errors, and system time. Reviewed by: alfred --- usr.bin/truss/main.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'usr.bin/truss/main.c') 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); } -- cgit v1.1