On Sun, Aug 16, 2009 at 08:56:59PM +0400, Dmitry V. Levin wrote:
> On Fri, Aug 14, 2009 at 12:06:51AM +0200, Adrien Krunch Kunysz wrote:
> > On Fri, Aug 14, 2009 at 12:56:12AM +0400, Dmitry V. Levin wrote:
> > > Your patch introduces new variable (Cflag) which behaves similar to
> > > already existing variable (cflag).  More simple approach would be to reuse
> > > the cflag variable.
> > 
> > If that means changing behaviour of -c and breaks compatibility,
> 
> No, my suggestion was just to change cflag from boolean to tristate.

OK, I think I got it. New patch attached. Not sure whether a new enum
is OK for this but it seems appropriate to me.
From e6c92f6913dcc53230ad9e2fdce680661e8a5707 Mon Sep 17 00:00:00 2001
From: Adrien Kunysz <[email protected]>
Date: Mon, 17 Aug 2009 20:17:00 +0200
Subject: [PATCH] Implement -C option to combine regular output and -c output.

This implementation reuses the existing cflag variable rather
than introduce a new variable. However we introduce a new enum
type cflag_t in order to track the state of the cflag variable
in a readable way.
---
 defs.h    |    9 ++++++++-
 strace.1  |    5 ++++-
 strace.c  |   24 ++++++++++++++++--------
 syscall.c |   12 ++++++++----
 4 files changed, 36 insertions(+), 14 deletions(-)

diff --git a/defs.h b/defs.h
index 769ed22..52739d1 100644
--- a/defs.h
+++ b/defs.h
@@ -450,10 +450,17 @@ extern const struct xlat open_access_modes[];
 #define TRACE_SIGNAL	020	/* Trace signal-related syscalls. */
 #define TRACE_DESC	040	/* Trace file descriptor-related syscalls. */
 
+typedef enum {
+	CFLAG_NONE = 0,
+	CFLAG_ONLY_STATS,
+	CFLAG_BOTH
+} cflag_t;
+
 extern struct tcb **tcbtab;
 extern int *qual_flags;
 extern int debug, followfork;
-extern int dtime, cflag, xflag, qflag;
+extern int dtime, xflag, qflag;
+extern cflag_t 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..1e38f9f 100644
--- a/strace.c
+++ b/strace.c
@@ -83,7 +83,8 @@ extern char *optarg;
 
 
 int debug = 0, followfork = 0;
-int dtime = 0, cflag = 0, xflag = 0, qflag = 0;
+int dtime = 0, xflag = 0, qflag = 0;
+cflag_t cflag = CFLAG_NONE;
 static int iflag = 0, interactive = 0, pflag_seen = 0, rflag = 0, tflag = 0;
 /*
  * daemonized_tracer supports -D option.
@@ -711,14 +712,18 @@ main(int argc, char *argv[])
 	qualify("verbose=all");
 	qualify("signal=all");
 	while ((c = getopt(argc, argv,
-		"+cdfFhiqrtTvVxz"
+		"+cCdfFhiqrtTvVxz"
 #ifndef USE_PROCFS
 		"D"
 #endif
 		"a:e:o:O:p:s:S:u:E:")) != EOF) {
 		switch (c) {
 		case 'c':
-			cflag++;
+			cflag = CFLAG_ONLY_STATS;
+			dtime++;
+			break;
+		case 'C':
+			cflag = CFLAG_BOTH;
 			dtime++;
 			break;
 		case 'd':
@@ -830,7 +835,8 @@ main(int argc, char *argv[])
 
 	if (followfork > 1 && cflag) {
 		fprintf(stderr,
-			"%s: -c and -ff are mutually exclusive options\n",
+			"%s: (-c or -C) and -ff are mutually exclusive options"
+			"\n",
 			progname);
 		exit(1);
 	}
@@ -2143,7 +2149,8 @@ trace()
 			}
 			break;
 		case PR_SIGNALLED:
-			if (!cflag && (qual_flags[what] & QUAL_SIGNAL)) {
+			if (cflag != CFLAG_ONLY_STATS
+			    && (qual_flags[what] & QUAL_SIGNAL)) {
 				printleader(tcp);
 				tprintf("--- %s (%s) ---",
 					signame(what), strsignal(what));
@@ -2159,7 +2166,8 @@ trace()
 			}
 			break;
 		case PR_FAULTED:
-			if (!cflag && (qual_flags[what] & QUAL_FAULT)) {
+			if (cflag != CFLAGS_ONLY_STATS
+			    && (qual_flags[what] & QUAL_FAULT)) {
 				printleader(tcp);
 				tprintf("=== FAULT %d ===", what);
 				printtrailer();
@@ -2385,7 +2393,7 @@ Process %d attached (waiting for parent)\n",
 		if (WIFSIGNALED(status)) {
 			if (pid == strace_child)
 				exit_code = 0x100 | WTERMSIG(status);
-			if (!cflag
+			if (cflag != CFLAG_ONLY_STATS
 			    && (qual_flags[WTERMSIG(status)] & QUAL_SIGNAL)) {
 				printleader(tcp);
 				tprintf("+++ killed by %s %s+++",
@@ -2481,7 +2489,7 @@ Process %d attached (waiting for parent)\n",
 				}
 				continue;
 			}
-			if (!cflag
+			if (cflag != CFLAG_ONLY_STATS
 			    && (qual_flags[WSTOPSIG(status)] & QUAL_SIGNAL)) {
 				unsigned long addr = 0;
 				long pc = 0;
diff --git a/syscall.c b/syscall.c
index 26b1a9d..00b0e09 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) {
+			res = count_syscall(tcp, &tv);
+			if (cflag == CFLAG_ONLY_STATS) {
+				return res;
+			}
+		}
 
 		if (res != 1) {
 			tprintf(") ");
@@ -2635,7 +2639,7 @@ trace_syscall(struct tcb *tcp)
 		return 0;
 	}
 
-	if (cflag) {
+	if (cflag == CFLAG_ONLY_STATS) {
 		gettimeofday(&tcp->etime, NULL);
 		tcp->flags |= TCB_INSYSCALL;
 		return 0;
@@ -2657,7 +2661,7 @@ trace_syscall(struct tcb *tcp)
 		return -1;
 	tcp->flags |= TCB_INSYSCALL;
 	/* Measure the entrance time as late as possible to avoid errors. */
-	if (dtime)
+	if (dtime || cflag)
 		gettimeofday(&tcp->etime, NULL);
 	return sys_res;
 }
-- 
1.5.4.3

Attachment: 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

Reply via email to