From: Eugene Syromyatnikov Date: Wed, 28 Mar 2018 14:22:04 +0000 (+0200) Subject: strace.c: support simultaneous usage of -r and -t options X-Git-Tag: v4.22~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=698e9c30d4f31cc5ee850c03a693769affe461a1;p=strace strace.c: support simultaneous usage of -r and -t options * strace.c (init): Do not set tflag when rflag is set. (printleader): Handle rflag and tflag separately. * strace.1.in (.SH OPTIONS): Add a note about differences between the monotonic clock time and the wall clock time. * tests/options-syntax.test: Remove the check for "-tt has no effect with -r" warning. * NEWS: Mention this. Suggested-by: Josh Triplett Co-Authored-by: Dmitry V. Levin Closes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=466195 --- diff --git a/NEWS b/NEWS index 2816f64e..171c657b 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,8 @@ Noteworthy changes in release ?.?? (????-??-??) in the output of paths associated with file descriptors. * Data dump for write syscalls (-e write) is performed regardless of successfulness of these syscall (addresses Debian bug #436284). + * -r and -t options are now affect output independently. Previously, + -r option led to ignoring of the -t option (addresses Debian bug #466195). * Improvements * Implemented delay injection (-e inject=SET:delay_enter= and diff --git a/strace.1.in b/strace.1.in index caa88244..3f47cbea 100644 --- a/strace.1.in +++ b/strace.1.in @@ -287,6 +287,13 @@ If given twice, suppress messages about process exit status. Print a relative timestamp upon entry to each system call. This records the time difference between the beginning of successive system calls. +Note that since +.B \-r +option uses the monotonic clock time for measuring time difference and not the +wall clock time, its measurements can differ from the difference in time +reported by the +.B \-t +option. .TP .BI "\-s " strsize Specify the maximum string size to print (the default is 32). Note diff --git a/strace.c b/strace.c index 314fe0be..af2e9904 100644 --- a/strace.c +++ b/strace.c @@ -646,20 +646,9 @@ printleader(struct tcb *tcp) if (tflag) { struct timespec ts; - clock_gettime(rflag ? CLOCK_MONOTONIC : CLOCK_REALTIME, &ts); + clock_gettime(CLOCK_REALTIME, &ts); - if (rflag) { - static struct timespec ots; - if (ots.tv_sec == 0) - ots = ts; - - struct timespec dts; - ts_sub(&dts, &ts, &ots); - ots = ts; - - tprintf("%6ld.%06ld ", - (long) dts.tv_sec, (long) dts.tv_nsec / 1000); - } else if (tflag > 2) { + if (tflag > 2) { tprintf("%lld.%06ld ", (long long) ts.tv_sec, (long) ts.tv_nsec / 1000); } else { @@ -678,6 +667,25 @@ printleader(struct tcb *tcp) tprintf("%s ", str); } } + + if (rflag) { + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + + static struct timespec ots; + if (ots.tv_sec == 0) + ots = ts; + + struct timespec dts; + ts_sub(&dts, &ts, &ots); + ots = ts; + + tprintf("%s%6ld.%06ld%s ", + tflag ? "(+" : "", + (long) dts.tv_sec, (long) dts.tv_nsec / 1000, + tflag ? ")" : ""); + } + if (iflag) print_pc(tcp); } @@ -1756,12 +1764,6 @@ init(int argc, char *argv[]) error_msg("-%c has no effect with -c", 'y'); } - if (rflag) { - if (tflag > 1) - error_msg("-tt has no effect with -r"); - tflag = 1; - } - acolumn_spaces = xmalloc(acolumn + 1); memset(acolumn_spaces, ' ', acolumn); acolumn_spaces[acolumn] = '\0'; diff --git a/tests/options-syntax.test b/tests/options-syntax.test index f81dd992..7b4a620e 100755 --- a/tests/options-syntax.test +++ b/tests/options-syntax.test @@ -92,9 +92,6 @@ $STRACE_EXE: -t has no effect with -c $STRACE_EXE: -T has no effect with -c $STRACE_EXE: -y has no effect with -c $STRACE_EXE: $umsg" -u :nosuchuser: -cirtTy true - - check_e "-tt has no effect with -r -$STRACE_EXE: $umsg" -u :nosuchuser: -r -tt true fi args='-p 2147483647'