Bug report and patch for strace's -O option

Cai Fei caifei at cn.fujitsu.com
Thu Jun 28 02:10:31 UTC 2007


Hi, everyone

I found a bug of strace when I was testing the -O option with the
following steps:

$ strace -V
strace -- version 4.5.15
$ strace -c -O 50000 ls
......
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
1.24 -1.950452 -2358 21 read
1.25 -1.950174 -49826 1 execve
1.25 -1.950018 -49982 1 _sysctl
1.25 -1.950014 -49986 1 rt_sigprocmask
1.25 -1.950014 -49986 1 fcntl
1.25 -1.950014 -49986 1 arch_prctl
1.25 -1.950014 -49986 1 set_tid_address
1.25 -1.950013 -49987 1 uname
1.25 -1.950013 -49987 1 getrlimit
2.50 -1.900085 -49957 2 getdents64
2.50 -1.900037 -49981 2 1 access
2.50 -1.900032 -49983 2 ioctl
2.50 -1.900029 -49985 2 rt_sigaction
3.75 -1.850324 -6507 23 close
3.75 -1.850042 -49985 3 brk
6.25 -1.750136 -49972 5 write
6.25 -1.750101 -49979 5 munmap
7.47 -1.701585 -3469 86 63 open
8.76 -1.650108 -49984 7 mprotect
10.00 -1.600451 -14269 28 mmap
15.00 -1.400487 -18734 32 24 stat
17.51 -1.300186 -49986 14 fstat
------ ----------- ----------- --------- --------- ----------------
100.00 -4.004329 240 88 total

Apparently, the usecs/call values of read,close,open,mmap,stat are
strange. I checked the code and found that there's something wrong
in the util.c. The bug can be fixed with the following patch:

Signed-off-by: "Cai Fei" <caifei at cn.fujitsu.com>

--- util.c	2007-06-28 09:48:34.000000000 +0800
+++ util.c.new	2007-06-28 09:49:10.000000000 +0800
@@ -227,7 +227,7 @@ struct timeval *tv, *a;
 int n;
 {
 	tv->tv_usec = a->tv_usec * n;
-	tv->tv_sec = a->tv_sec * n + a->tv_usec / 1000000;
+	tv->tv_sec = a->tv_sec * n + tv->tv_usec / 1000000;
 	tv->tv_usec %= 1000000;
 }
 


Regards,
CaiFei






More information about the Strace-devel mailing list