Hello, As everybody and their dog tend to write Perl scripts to reimplement strace -c from regular strace output, I think it could be interesting to make strace able to print both regular output and statistics at the end. Attached is a patch adding option -C that does just that. Please consider it for inclusion.
Please CC me in reply as I am not registered to this list. Thanks, Adrien Kunysz
From 7f78a8fd69a27403ba43edb3f3a2931e6766976b Mon Sep 17 00:00:00 2001 From: Adrien Kunysz <[email protected]> Date: Wed, 12 Aug 2009 18:32:28 +0200 Subject: [PATCH] Implement -C option to combine regular output and -c output. --- defs.h | 2 +- strace.1 | 5 ++++- strace.c | 31 +++++++++++++++++++++---------- syscall.c | 8 ++++++-- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/defs.h b/defs.h index 769ed22..f3aa204 100644 --- a/defs.h +++ b/defs.h @@ -453,7 +453,7 @@ extern const struct xlat open_access_modes[]; extern struct tcb **tcbtab; extern int *qual_flags; extern int debug, followfork; -extern int dtime, cflag, xflag, qflag; +extern int dtime, cflag, xflag, qflag, Cflag; extern int acolumn; extern unsigned int nprocs, tcbtabsize; extern int max_strlen; diff --git a/strace.1 b/strace.1 index d35a74e..3b6efa5 100644 --- a/strace.1 +++ b/strace.1 @@ -43,7 +43,7 @@ strace \- trace system calls and signals .SH SYNOPSIS .B strace [ -.B \-dffhiqrtttTvxx +.B \-CdffhiqrtttTvxx ] [ .BI \-a column @@ -243,6 +243,9 @@ program exit. On Linux, this attempts to show system time (CPU time spent running in the kernel) independent of wall clock time. If -c is used with -f or -F (below), only aggregate totals for all traced processes are kept. .TP +.B \-C +Like -c but also print regular output while processes are running. +.TP .B \-d Show some debugging output of .B strace diff --git a/strace.c b/strace.c index da8cc4a..222bfec 100644 --- a/strace.c +++ b/strace.c @@ -83,7 +83,7 @@ extern char *optarg; int debug = 0, followfork = 0; -int dtime = 0, cflag = 0, xflag = 0, qflag = 0; +int dtime = 0, cflag = 0, xflag = 0, qflag = 0, Cflag = 0; static int iflag = 0, interactive = 0, pflag_seen = 0, rflag = 0, tflag = 0; /* * daemonized_tracer supports -D option. @@ -711,7 +711,7 @@ main(int argc, char *argv[]) qualify("verbose=all"); qualify("signal=all"); while ((c = getopt(argc, argv, - "+cdfFhiqrtTvVxz" + "+cCdfFhiqrtTvVxz" #ifndef USE_PROCFS "D" #endif @@ -721,6 +721,10 @@ main(int argc, char *argv[]) cflag++; dtime++; break; + case 'C': + Cflag++; + dtime++; + break; case 'd': debug++; break; @@ -834,6 +838,12 @@ main(int argc, char *argv[]) progname); exit(1); } + if (followfork > 1 && Cflag) { + fprintf(stderr, + "%s: -C and -ff are mutually exclusive options\n", + progname); + exit(1); + } /* See if they want to run as another user. */ if (username != NULL) { @@ -1083,7 +1093,7 @@ proc_open(struct tcb *tcp, int attaching) perror("strace: open(\"/proc/.../regs\", ...)"); return -1; } - if (cflag) { + if (cflag || Cflag) { sprintf(proc, "/proc/%d/status", tcp->pid); if ((tcp->pfd_status = open(proc, O_RDONLY)) < 0) { perror("strace: open(\"/proc/.../status\", ...)"); @@ -1691,7 +1701,7 @@ cleanup() kill(tcp->pid, SIGTERM); } } - if (cflag) + if (cflag || Cflag) call_summary(outf); } @@ -2099,7 +2109,7 @@ trace() /* set current output file */ outf = tcp->outf; - if (cflag) { + if (cflag || Cflag) { struct timeval stime; #ifdef FREEBSD char buf[1024]; @@ -2271,25 +2281,26 @@ trace() sigprocmask(SIG_SETMASK, &empty_set, NULL); #ifdef LINUX #ifdef __WALL - pid = wait4(-1, &status, wait4_options, cflag ? &ru : NULL); + pid = wait4(-1, &status, wait4_options, + (cflag || Cflag) ? &ru : NULL); if (pid < 0 && (wait4_options & __WALL) && errno == EINVAL) { /* this kernel does not support __WALL */ wait4_options &= ~__WALL; errno = 0; pid = wait4(-1, &status, wait4_options, - cflag ? &ru : NULL); + (cflag || Cflag) ? &ru : NULL); } if (pid < 0 && !(wait4_options & __WALL) && errno == ECHILD) { /* most likely a "cloned" process */ pid = wait4(-1, &status, __WCLONE, - cflag ? &ru : NULL); + (cflag || Cflag) ? &ru : NULL); if (pid == -1) { fprintf(stderr, "strace: clone wait4 " "failed: %s\n", strerror(errno)); } } #else - pid = wait4(-1, &status, 0, cflag ? &ru : NULL); + pid = wait4(-1, &status, 0, (cflag || Cflag) ? &ru : NULL); #endif /* __WALL */ #endif /* LINUX */ #ifdef SUNOS4 @@ -2364,7 +2375,7 @@ Process %d attached (waiting for parent)\n", } /* set current output file */ outf = tcp->outf; - if (cflag) { + if (cflag || Cflag) { #ifdef LINUX tv_sub(&tcp->dtime, &ru.ru_stime, &tcp->stime); tcp->stime = ru.ru_stime; diff --git a/syscall.c b/syscall.c index 26b1a9d..2c90b18 100644 --- a/syscall.c +++ b/syscall.c @@ -2389,8 +2389,12 @@ trace_syscall(struct tcb *tcp) tprintf(" resumed> "); } - if (cflag) - return count_syscall(tcp, &tv); + if (cflag || Cflag) { + res = count_syscall(tcp, &tv); + if (cflag) { + return res; + } + } if (res != 1) { tprintf(") "); -- 1.5.4.3
signature.asc
Description: Digital signature
------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________ Strace-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/strace-devel
