Hello, Back in August I posted this patch that implements a new -C option. I got some feedback and reworked the patch accordingly but I got no follow up after the third iteration. Can you please consider this again or tell me what's wrong with this? This version applies cleanly against the current master branch.
This combine regular output with -c. I would find that useful to be integrated in the master branch in order to get rid of some custom, unreliable scripts I (and doubtlessy others) use to analyze regular strace output. Please CC me in reply as I am not subscribed to the list. Thanks, Adrien Kunysz
diff --git a/defs.h b/defs.h
index 4797e96..62b3719 100644
--- a/defs.h
+++ b/defs.h
@@ -456,10 +456,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 2fb75c9..b0eefe0 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.
@@ -719,14 +720,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':
@@ -838,7 +843,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);
}
@@ -2144,7 +2150,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));
@@ -2160,7 +2167,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();
@@ -2383,7 +2391,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+++",
@@ -2482,7 +2490,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 a56d7df..735416f 100644
--- a/syscall.c
+++ b/syscall.c
@@ -2407,8 +2407,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(") ");
@@ -2647,7 +2651,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;
@@ -2669,7 +2673,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;
}
signature.asc
Description: Digital signature
------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev
_______________________________________________ Strace-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/strace-devel
