strace ã使ãéã« -c ãã¤ããã¨ãã·ã¹ãã ã³ã¼ã«å¼ã³åºãã®çµ±è¨ãåãã
vagrant@xenial:~$ strace -c find >/dev/null % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 47.43 0.033697 145 232 getdents 46.00 0.032676 141 232 newfstatat 6.08 0.004320 9 474 close 0.49 0.000349 0 1045 fcntl 0.00 0.000000 0 10 read 0.00 0.000000 0 4 write 0.00 0.000000 0 15 4 open 0.00 0.000000 0 129 fstat 0.00 0.000000 0 21 mmap 0.00 0.000000 0 14 mprotect 0.00 0.000000 0 1 munmap 0.00 0.000000 0 3 brk 0.00 0.000000 0 2 rt_sigaction 0.00 0.000000 0 1 rt_sigprocmask 0.00 0.000000 0 3 2 ioctl 0.00 0.000000 0 8 8 access 0.00 0.000000 0 1 execve 0.00 0.000000 0 1 uname 0.00 0.000000 0 1 fchdir 0.00 0.000000 0 1 getrlimit 0.00 0.000000 0 2 2 statfs 0.00 0.000000 0 1 arch_prctl 0.00 0.000000 0 1 set_tid_address 0.00 0.000000 0 118 openat 0.00 0.000000 0 1 set_robust_list ------ ----------- ----------- --------- --------- ---------------- 100.00 0.071042 2321 16 total
-c ãè¨ä¸ããã®ã¯ system time ã 㨠man ã«æ¸ãã¦ããã¾ã
-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) indeâ pendent of wall clock time. If -c is used with -f or -F (below), only aggregate totals for all traced processes are kept.
-w ãä¸ç·ã«ã¤ãã
strace -c ã¨ä¸ç·ã« -w ãã¤ããã¨ãã·ã¹ãã ã³ã¼ã«å¼ã³åºãã«ããã£ãæéãè¨æ¸¬ã§ããã
-w Summarise the time difference between the beginning and end of each system call. The default is to summarise the system time.
-w
ãä»ããå ´åã«ã©ãå¤åãã§ãã㯠sleep 1
ã strace ã㦠nanosleep(2) ãè¦ãã¨ç解ãæ©ã
vagrant@xenial:~$ strace -c -w sleep 1 % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 99.76 1.042157 1042157 1 nanosleep ð 0.05 0.000525 66 8 mmap 0.04 0.000419 419 1 execve 0.03 0.000327 109 3 brk 0.02 0.000251 63 4 mprotect 0.02 0.000219 73 3 open 0.02 0.000211 70 3 fstat 0.02 0.000200 67 3 3 access 0.02 0.000190 38 5 close 0.01 0.000064 64 1 read 0.01 0.000062 62 1 arch_prctl 0.00 0.000050 50 1 munmap ------ ----------- ----------- --------- --------- ---------------- 100.00 1.044675 34 3 total
-w
ãå¤ããå ´å
vagrant@xenial:~$ strace -c sleep 1 % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 0.00 0.000000 0 1 read 0.00 0.000000 0 3 open 0.00 0.000000 0 5 close 0.00 0.000000 0 3 fstat 0.00 0.000000 0 8 mmap 0.00 0.000000 0 4 mprotect 0.00 0.000000 0 1 munmap 0.00 0.000000 0 3 brk 0.00 0.000000 0 3 3 access 0.00 0.000000 0 1 nanosleep ð 0.00 0.000000 0 1 execve 0.00 0.000000 0 1 arch_prctl ------ ----------- ----------- --------- --------- ---------------- 100.00 0.000000 34 3 total
ã? ãããã¯ããæéãé·ãã·ã¹ãã ã³ã¼ã«å¼ã³åºãã追ããããéã«ä¾¿å©ãã
ã½ã¼ã¹
-w ãªãã·ã§ã³ãå®è£ ãããã®ã¯ä¸è¨ã®ã³ãããã§ã 4.9 ã§ãªãªã¼ã¹ãããããã
æéã®è¨æ¸¬æ¹æ³
ãã£ãã調ã¹ãã ããªã®ã§è©³ç´°ã¯æ¸ããªãã®ã ã ...
-w ä»ããå ´å㯠clock_gettime(2) + CLOCK_MONOTONIC ã§ã·ã¹ãã ã³ã¼ã«ãéå§ããæéãè¨é²ãè¨æ¸¬ãã¦ããããã
void syscall_entering_finish(struct tcb *tcp, int res) { ... /* Measure the entrance time as late as possible to avoid errors. */ if ((Tflag || cflag) && !filtered(tcp)) clock_gettime(CLOCK_MONOTONIC, &tcp->etime); ð
-w ãã¤ããªãå ´åã® system time ã¯ãã©ããã wait4(2) ã®ç¬¬ä¸å¼æ° struct rusage *rusage
ãéãã¦åã£ã¦ããããã
static const struct tcb_wait_data * next_event(void) { ... next_event_wait_next: pid = wait4(-1, &status, __WALL | WNOHANG, (cflag ? &ru : NULL)); wait_errno = errno; wait_nohang = true;
ã¾ã¨ã
- å®ã¯
-c
ãåºãæéã system time ã ã¨ãããã¨ãé·ããã¡ããã¨ç解ããã«ä½¿ã£ã¦ãã - ç´é¢ãã¦ããåé¡ã«åãã㦠-w ãä»ãããå¤ããããã¦ã観測/è¨æ¸¬ãã¦ããã¨ããã ãã
- ã¨ããã§
-c
ã¯ãããã ã 㨠pyama ããããããã使ãåãã¦ãã
CentOS6 㯠4.8 ã§ã¾ã 使ããªãã£ãã¿ããã ãã CentOS7 ã§ã¯ 4.12 ãªã®ã§ä½¿ããã¯ã. ãã é·ããæ°ãã¤ããã«éããã¦ãã¾ã£ããããç¥ã£ã¦ãã°è§£æ±ºã«å°ããmåé¡ãå¤ãã£ããããªã ... ã¨ããææ³