When using the command strace with the flag -T, I would like to know what is the time unit used to display time spent in syscalls? I assume it should be in seconds, but I am not quite sure and it seems to be omitted from the manual.
Asked
Active
Viewed 8,689 times
12
user311285
- 131
- 1
- 4
4 Answers
26
From the source code:
if (Tflag) {
ts_sub(ts, ts, &tcp->etime);
tprintf(" <%ld.%06ld>",
(long) ts->tv_sec, (long) ts->tv_nsec / 1000);
}
This means that the time is shown in seconds, with microseconds (calculated from the nanosecond value) after the decimal point.
Stephen Kitt
- 411,918
- 54
- 1,065
- 1,164
13
If you run
strace -T sleep 2
you will see
nanosleep({tv_sec=2, tv_nsec=0}, NULL) = 0 <2.000230>
so it looks like the time spent is in seconds.
meuh
- 49,672
- 2
- 52
- 114
6
If you run the command strace using the "flag -c" it will show you a table and the time is reported in seconds:
strace -c -p 3569 # 3569 is PID
strace: Process 3569 attached
^Cstrace: Process 3569 detached
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
99.73 0.016000 8 1971 poll
0.16 0.000025 0 509 75 futex
0.06 0.000010 0 1985 1966 recvmsg
0.06 0.000009 0 2336 mprotect
0.00 0.000000 0 478 read
0.00 0.000000 0 13 write
0.00 0.000000 0 29 mmap
0.00 0.000000 0 9 munmap
0.00 0.000000 0 18 writev
0.00 0.000000 0 351 madvise
0.00 0.000000 0 1 restart_syscall
------ ----------- ----------- --------- --------- ----------------
100.00 0.016044 7700 2041 total
-c
Count time, calls, and errors for each system call and report a summary on 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.
0
This can be seen from strace summary. e.g.:
$ strace -ce trace=write -p $(pidof app)
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
100.00 0.061558 17 3544 write
------ ----------- ----------- --------- --------- ----------------
100.00 0.061558 3544 total
- total time of write syscall = 0.061558 sec. or 0.061558*1000000 = 61558 microseconds(usec)
- usec/calls = 61558 usec / 3544 calls = 17.778
Zstack
- 121
- 1