]> granicus.if.org Git - strace/commitdiff
strace.c: support simultaneous usage of -r and -t options
authorEugene Syromyatnikov <evgsyr@gmail.com>
Wed, 28 Mar 2018 14:22:04 +0000 (16:22 +0200)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 4 Apr 2018 20:32:42 +0000 (20:32 +0000)
* 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 <josh@freedesktop.org>
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
Closes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=466195
NEWS
strace.1.in
strace.c
tests/options-syntax.test

diff --git a/NEWS b/NEWS
index 2816f64e6a731995539c7c5e9273ace23549408f..171c657b28b13377a6c232af921f84e959753bb1 100644 (file)
--- 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
index caa88244f5837630d093a0b100ba1cd9909bd27c..3f47cbea8e5117ebf4292689e87fec8a870b9a5e 100644 (file)
@@ -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
index 314fe0bea6513bcc56170877466b605af9fd2e05..af2e99045b7b3d2e1c1b9338013fd7239e59070e 100644 (file)
--- 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';
index f81dd992d35280c99b59ce829e588673c300a917..7b4a620e646e5108f2c9a9f1bc75e0664943d892 100755 (executable)
@@ -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'