How to check why Vim is slow

  sonic0002        2012-11-26 11:54:35       5,190        0    

On *nix, some processes may not be able to start up, software runs very slowly suddenly and software's "Segment Fault" are some issues faced by many *nix users. Here we show you how to use truss to trace why Vim becomes slow suddenly.

Operating system : FreeBSD-5.2.1-releas

vim version is 6.2.154, after typing vim on command line, sometimes we need to wait for a few minutes to get into the edit interface and there is no error output. After carefully checking .vimrc and all vim settings, there are no error configuration. Also there are no similar solutions online. Do we need to hack the source code? Not necessary, we can use truss to find the issue:

# truss -f -D -o vim.truss vim

Here the meaning of -D is : Add timestamp offset at beginning of each line of output, i.e the time spent for each line of command, We only need to trace which system calls take long time, use less command to show the vim.truss file:

735: 0.000021511 socket(0x2,0x1,0x0)       = 4 (0x4)
735: 0.000014248 setsockopt(0x4,0x6,0x1,0xbfbfe3c8,0x4) = 0 (0x0)
735: 0.000013688 setsockopt(0x4,0xffff,0x8,0xbfbfe2ec,0x4) = 0 (0x0)
735: 0.000203657 connect(0x4,{ AF_INET 10.57.18.27:6000 },16) ERR#61 'Connection refused'
735: 0.000017042 close(4)          = 0 (0x0)
735: 1.009366553 nanosleep(0xbfbfe468,0xbfbfe460) = 0 (0x0)
735: 0.000019556 socket(0x2,0x1,0x0)       = 4 (0x4)
735: 0.000013409 setsockopt(0x4,0x6,0x1,0xbfbfe3c8,0x4) = 0 (0x0)
735: 0.000013130 setsockopt(0x4,0xffff,0x8,0xbfbfe2ec,0x4) = 0 (0x0)
735: 0.000272102 connect(0x4,{ AF_INET 10.57.18.27:6000 },16) ERR#61 'Connection refused'
735: 0.000015924 close(4)          = 0 (0x0)
735: 1.009338338 nanosleep(0xbfbfe468,0xbfbfe460) = 0 (0x0)

From above output, we can find vim is trying to connect to the host 10.57.18.27 at port 6000(connect() in line 4), after failure, it sleeps one second and try it again. This process continues for over 10 times, each time it will take more than 1 second. This is the reason why vim becomes slow. But you may have a doubt why vim will connect to other host at its port 6000. Please think about what service uses port 6000, that's X Server, it seems that vim is redirecting its output to a remote X Server. Now we only need to check the DISPLAY variable in Shell, check cshrc, there may be one line like setenv DISPLAY  ${REMOTEHOST}:0, comment this line and try to run vim again.

You can use truss to trace other issues as well when launching programs.

Reference : http://www.ibm.com/developerworks/cn/linux/l-tsl/

VIM  TRUSS  LINUX 

       

  RELATED


  0 COMMENT


No comment for this article.



  RANDOM FUN

6 stages of debugging