Technical Articles => Operating System =>  Linux/Unix

How to check why Vim is slow

Source : sonic0002    Date : 2012-11-26 11:54:35  

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/

Save as PDF Mark as read Mark as important
By clicking the "Mark as read" button, this article will be marked as read. It will be removed from the homepage's latest news and the article list on the "Technical article" page in following visits and it will be put to your read list which you can find in "Amin->Article read list". There you can unmark the read articles.
By clicking the "Mark as important" button, this article will be put to your important article list which you can find in "Amin->Article important list". Later when you want reread this article, it's easier for you to find it by checking the "Article important list".

Tags:vim, truss, linux   Read(444) Comment(0)

Share on Facebook  Share on Twitter  Share on Google+  Share on Weibo  Share on Digg  Share on Tumblr    Delicious 

 Previous : 5 million units of Galaxy Note II are sold until now
 Next : Gmail supports 10 GB attachment after integrating with Google Drive

  ::Related Articles

  ::Comment List

No comment for this article.

  ::Comment

Nickname  
Email 
Comment

:: Users edited this page

No users edited this page yet.

:: Recent articles

:: Most read

:: Most commented

:: Find us

Back to top