首页 > 代码库 > symlink在ln的过程中究竟占用了多少耗时

symlink在ln的过程中究竟占用了多少耗时

今天看到群里的童鞋们在讨论ln命令的使用,天花乱坠说到了symlink,有同学用估算的口气说symlink耗时很低的,肯定ln总耗时是symlink的好几百倍,他猜中了吗?

现在针对ln -s ~/install install来验证下strace -tt -T输出:

14:08:20.190334 execve("/bin/ln", ["ln", "-s", "/home/linxp/install", "install"], ["XDG_VTNR=7", "SSH_AGENT_PID=2251", "XDG_SESSION_ID=c2", "CLUTTER_IM_MODULE=xim", "SESSION=ubuntu", "TERM=xterm", "XDG_MENU_PREFIX=gnome-", "SHELL=/bin/bash", "VTE_VERSION=3406", "WINDOWID=65011719", "UPSTART_SESSION=unix:abstract=/c"..., "GNOME_KEYRING_CONTROL=/run/user/"..., "GTK_MODULES=overlay-scrollbar:un"..., "USER=linxp", "LS_COLORS=rs=0:di=01;34:ln=01;36"..., "XDG_SESSION_PATH=/org/freedeskto"..., "XDG_SEAT_PATH=/org/freedesktop/D"..., "SSH_AUTH_SOCK=/run/user/1000/key"..., "SESSION_MANAGER=local/ubuntu:@/t"..., "DEFAULTS_PATH=/usr/share/gconf/u"..., "XDG_CONFIG_DIRS=/etc/xdg/xdg-ubu"..., "PATH=/usr/lib/lightdm/lightdm:/u"..., "DESKTOP_SESSION=ubuntu", "JOB=dbus", "PWD=/tmp", "XMODIFIERS=@im=fcitx", "GNOME_KEYRING_PID=2190", "LANG=en_US.UTF-8", "GDM_LANG=en_US", "MANDATORY_PATH=/usr/share/gconf/"..., "UBUNTU_MENUPROXY=1", "IM_CONFIG_PHASE=1", "COMPIZ_CONFIG_PROFILE=ubuntu", "GDMSESSION=ubuntu", "SESSIONTYPE=gnome-session", "SHLVL=1", "XDG_SEAT=seat0", "HOME=/home/linxp", "LANGUAGE=en_US", "GNOME_DESKTOP_SESSION_ID=this-is"..., "UPSTART_INSTANCE=", "UPSTART_EVENTS=started xsession", "LOGNAME=linxp", "COMPIZ_BIN_PATH=/usr/bin/", "QT4_IM_MODULE=fcitx", "XDG_DATA_DIRS=/usr/share/ubuntu:"..., "DBUS_SESSION_BUS_ADDRESS=unix:ab"..., "LESSOPEN=| /usr/bin/lesspipe %s", "INSTANCE=", "UPSTART_JOB=gnome-session", "TEXTDOMAIN=im-config", "XDG_RUNTIME_DIR=/run/user/1000", "DISPLAY=:0", "XDG_CURRENT_DESKTOP=Unity", "GTK_IM_MODULE=fcitx", "LESSCLOSE=/usr/bin/lesspipe %s %"..., "TEXTDOMAINDIR=/usr/share/locale/", "COLORTERM=gnome-terminal", "XAUTHORITY=/home/linxp/.Xauthori"..., "_=/usr/bin/strace", "OLDPWD=/home/linxp/test"]) = 0 <0.000402>
14:08:20.192273 brk(0)                  = 0x954a000 <0.000022>
... ...
14:08:20.239693 symlink("/home/linxp/install", "install/install") = -1 EEXIST (File exists) <0.000032>
... ...
14:08:20.243516 close(2)                = 0 <0.000021>
14:08:20.243626 exit_group(1)           = ?
14:08:20.243825 +++ exited with 1 +++

总微秒耗时 T = 243825 - 190334 =>  0.053491

symlink耗时 t = 0.000032

可见symlink耗时之低,那主要的操作耗时在哪里呢:(-tt -v -c)

% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
  0.00    0.000000           0         3           read
  0.00    0.000000           0         4           write
  0.00    0.000000           0        13         8 open
  0.00    0.000000           0         8           close
  0.00    0.000000           0         1           execve
  0.00    0.000000           0         3         3 access
  0.00    0.000000           0         3           brk
  0.00    0.000000           0         1         1 symlink
  0.00    0.000000           0         2           munmap
  0.00    0.000000           0         3           mprotect
  0.00    0.000000           0         1         1 _llseek
  0.00    0.000000           0        10           mmap2
  0.00    0.000000           0         1           stat64
  0.00    0.000000           0         5           fstat64
  0.00    0.000000           0         1           set_thread_area
------ ----------- ----------- --------- --------- ----------------

主要都还是在中断、io操作上多操作多耗时居!

symlink在ln的过程中究竟占用了多少耗时