Karsten Hopp 33c265
To: vim-dev@vim.org
Karsten Hopp 33c265
Subject: Patch 7.2.269
Karsten Hopp 33c265
Fcc: outbox
Karsten Hopp 33c265
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 33c265
Mime-Version: 1.0
Karsten Hopp 33c265
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 33c265
Content-Transfer-Encoding: 8bit
Karsten Hopp 33c265
------------
Karsten Hopp 33c265
Karsten Hopp 33c265
Patch 7.2.269
Karsten Hopp 33c265
Problem:    Many people struggle to find out why Vim startup is slow.
Karsten Hopp 33c265
Solution:   Add the --startuptime command line flag.
Karsten Hopp 33c265
Files:	    runtime/doc/starting.txt, src/globals.h, src/feature.h,
Karsten Hopp 33c265
	    src/main.c, src/macros.h
Karsten Hopp 33c265
Karsten Hopp 33c265
Karsten Hopp 33c265
*** ../vim-7.2.268/runtime/doc/starting.txt	2008-11-09 13:43:25.000000000 +0100
Karsten Hopp 33c265
--- runtime/doc/starting.txt	2009-10-25 11:57:51.000000000 +0100
Karsten Hopp 33c265
***************
Karsten Hopp 33c265
*** 144,149 ****
Karsten Hopp 33c265
--- 144,156 ----
Karsten Hopp 33c265
  			-u NORC			no		    yes
Karsten Hopp 33c265
  			--noplugin		yes		    no
Karsten Hopp 33c265
  
Karsten Hopp 33c265
+ --startuptime={fname}					*--startuptime*
Karsten Hopp 33c265
+ 		During startup write timing messages to the file {fname}.
Karsten Hopp 33c265
+ 		This can be used to find out where time is spent while loading
Karsten Hopp 33c265
+ 		your .vimrc and plugins.
Karsten Hopp 33c265
+ 		When {fname} already exists new messages are appended.
Karsten Hopp 33c265
+ 		{only when compiled with this feature}
Karsten Hopp 33c265
+ 
Karsten Hopp 33c265
  							*--literal*
Karsten Hopp 33c265
  --literal	Take file names literally, don't expand wildcards.  Not needed
Karsten Hopp 33c265
  		for Unix, because Vim always takes file names literally (the
Karsten Hopp 33c265
***************
Karsten Hopp 33c265
*** 471,476 ****
Karsten Hopp 33c265
--- 487,493 ----
Karsten Hopp 33c265
  		window title and copy/paste using the X clipboard.  This
Karsten Hopp 33c265
  		avoids a long startup time when running Vim in a terminal
Karsten Hopp 33c265
  		emulator and the connection to the X server is slow.
Karsten Hopp 33c265
+ 		See |--startuptime| to find out if affects you.
Karsten Hopp 33c265
  		Only makes a difference on Unix or VMS, when compiled with the
Karsten Hopp 33c265
  		|+X11| feature.  Otherwise it's ignored.
Karsten Hopp 33c265
  		To disable the connection only for specific terminals, see the
Karsten Hopp 33c265
*** ../vim-7.2.268/src/globals.h	2009-07-29 12:09:49.000000000 +0200
Karsten Hopp 33c265
--- src/globals.h	2009-10-10 15:14:31.000000000 +0200
Karsten Hopp 33c265
***************
Karsten Hopp 33c265
*** 1567,1572 ****
Karsten Hopp 33c265
--- 1567,1576 ----
Karsten Hopp 33c265
  /* For undo we need to know the lowest time possible. */
Karsten Hopp 33c265
  EXTERN time_t starttime;
Karsten Hopp 33c265
  
Karsten Hopp 33c265
+ #ifdef STARTUPTIME
Karsten Hopp 33c265
+ EXTERN FILE *time_fd INIT(= NULL);  /* where to write startup timing */
Karsten Hopp 33c265
+ #endif
Karsten Hopp 33c265
+ 
Karsten Hopp 33c265
  /*
Karsten Hopp 33c265
   * Some compilers warn for not using a return value, but in some situations we
Karsten Hopp 33c265
   * can't do anything useful with the value.  Assign to this variable to avoid
Karsten Hopp 33c265
*** ../vim-7.2.268/src/feature.h	2008-11-09 13:43:25.000000000 +0100
Karsten Hopp 33c265
--- src/feature.h	2009-10-10 16:16:19.000000000 +0200
Karsten Hopp 33c265
***************
Karsten Hopp 33c265
*** 844,853 ****
Karsten Hopp 33c265
  /* #define DEBUG */
Karsten Hopp 33c265
  
Karsten Hopp 33c265
  /*
Karsten Hopp 33c265
!  * STARTUPTIME		Time the startup process.  Writes a "vimstartup" file
Karsten Hopp 33c265
!  *			with timestamps.
Karsten Hopp 33c265
   */
Karsten Hopp 33c265
! /* #define STARTUPTIME "vimstartup" */
Karsten Hopp 33c265
  
Karsten Hopp 33c265
  /*
Karsten Hopp 33c265
   * MEM_PROFILE		Debugging of memory allocation and freeing.
Karsten Hopp 33c265
--- 844,857 ----
Karsten Hopp 33c265
  /* #define DEBUG */
Karsten Hopp 33c265
  
Karsten Hopp 33c265
  /*
Karsten Hopp 33c265
!  * STARTUPTIME		Time the startup process.  Writes a file with
Karsten Hopp 33c265
!  *			timestamps.
Karsten Hopp 33c265
   */
Karsten Hopp 33c265
! #if defined(FEAT_NORMAL) \
Karsten Hopp 33c265
! 	&& ((defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H)) \
Karsten Hopp 33c265
! 		|| defined(WIN3264))
Karsten Hopp 33c265
! # define STARTUPTIME 1
Karsten Hopp 33c265
! #endif
Karsten Hopp 33c265
  
Karsten Hopp 33c265
  /*
Karsten Hopp 33c265
   * MEM_PROFILE		Debugging of memory allocation and freeing.
Karsten Hopp 33c265
*** ../vim-7.2.268/src/main.c	2009-05-26 22:58:43.000000000 +0200
Karsten Hopp 33c265
--- src/main.c	2009-10-10 16:18:32.000000000 +0200
Karsten Hopp 33c265
***************
Karsten Hopp 33c265
*** 130,139 ****
Karsten Hopp 33c265
  #endif
Karsten Hopp 33c265
  
Karsten Hopp 33c265
  
Karsten Hopp 33c265
- #ifdef STARTUPTIME
Karsten Hopp 33c265
- static FILE *time_fd = NULL;
Karsten Hopp 33c265
- #endif
Karsten Hopp 33c265
- 
Karsten Hopp 33c265
  /*
Karsten Hopp 33c265
   * Different types of error messages.
Karsten Hopp 33c265
   */
Karsten Hopp 33c265
--- 130,135 ----
Karsten Hopp 33c265
***************
Karsten Hopp 33c265
*** 173,178 ****
Karsten Hopp 33c265
--- 169,177 ----
Karsten Hopp 33c265
      char_u	*fname = NULL;		/* file name from command line */
Karsten Hopp 33c265
      mparm_T	params;			/* various parameters passed between
Karsten Hopp 33c265
  					 * main() and other functions. */
Karsten Hopp 33c265
+ #ifdef STARTUPTIME
Karsten Hopp 33c265
+     int		i;
Karsten Hopp 33c265
+ #endif
Karsten Hopp 33c265
  
Karsten Hopp 33c265
      /*
Karsten Hopp 33c265
       * Do any system-specific initialisations.  These can NOT use IObuff or
Karsten Hopp 33c265
***************
Karsten Hopp 33c265
*** 203,210 ****
Karsten Hopp 33c265
  #endif
Karsten Hopp 33c265
  
Karsten Hopp 33c265
  #ifdef STARTUPTIME
Karsten Hopp 33c265
!     time_fd = mch_fopen(STARTUPTIME, "a");
Karsten Hopp 33c265
!     TIME_MSG("--- VIM STARTING ---");
Karsten Hopp 33c265
  #endif
Karsten Hopp 33c265
      starttime = time(NULL);
Karsten Hopp 33c265
  
Karsten Hopp 33c265
--- 202,216 ----
Karsten Hopp 33c265
  #endif
Karsten Hopp 33c265
  
Karsten Hopp 33c265
  #ifdef STARTUPTIME
Karsten Hopp 33c265
!     for (i = 1; i < argc; ++i)
Karsten Hopp 33c265
!     {
Karsten Hopp 33c265
! 	if (STRNICMP(argv[i], "--startuptime=", 14) == 0)
Karsten Hopp 33c265
! 	{
Karsten Hopp 33c265
! 	    time_fd = mch_fopen(argv[i] + 14, "a");
Karsten Hopp 33c265
! 	    TIME_MSG("--- VIM STARTING ---");
Karsten Hopp 33c265
! 	    break;
Karsten Hopp 33c265
! 	}
Karsten Hopp 33c265
!     }
Karsten Hopp 33c265
  #endif
Karsten Hopp 33c265
      starttime = time(NULL);
Karsten Hopp 33c265
  
Karsten Hopp 33c265
***************
Karsten Hopp 33c265
*** 1150,1155 ****
Karsten Hopp 33c265
--- 1156,1173 ----
Karsten Hopp 33c265
  	    cursor_on();
Karsten Hopp 33c265
  
Karsten Hopp 33c265
  	    do_redraw = FALSE;
Karsten Hopp 33c265
+ 
Karsten Hopp 33c265
+ #ifdef STARTUPTIME
Karsten Hopp 33c265
+ 	    /* Now that we have drawn the first screen all the startup stuff
Karsten Hopp 33c265
+ 	     * has been done, close any file for startup messages. */
Karsten Hopp 33c265
+ 	    if (time_fd != NULL)
Karsten Hopp 33c265
+ 	    {
Karsten Hopp 33c265
+ 		TIME_MSG("first screen update");
Karsten Hopp 33c265
+ 		TIME_MSG("--- VIM STARTED ---");
Karsten Hopp 33c265
+ 		fclose(time_fd);
Karsten Hopp 33c265
+ 		time_fd = NULL;
Karsten Hopp 33c265
+ 	    }
Karsten Hopp 33c265
+ #endif
Karsten Hopp 33c265
  	}
Karsten Hopp 33c265
  #ifdef FEAT_GUI
Karsten Hopp 33c265
  	if (need_mouse_correct)
Karsten Hopp 33c265
***************
Karsten Hopp 33c265
*** 1743,1748 ****
Karsten Hopp 33c265
--- 1761,1770 ----
Karsten Hopp 33c265
  		    /* already processed, skip */
Karsten Hopp 33c265
  		}
Karsten Hopp 33c265
  #endif
Karsten Hopp 33c265
+ 		else if (STRNICMP(argv[0] + argv_idx, "startuptime", 11) == 0)
Karsten Hopp 33c265
+ 		{
Karsten Hopp 33c265
+ 		    /* already processed, skip */
Karsten Hopp 33c265
+ 		}
Karsten Hopp 33c265
  		else
Karsten Hopp 33c265
  		{
Karsten Hopp 33c265
  		    if (argv[0][argv_idx])
Karsten Hopp 33c265
***************
Karsten Hopp 33c265
*** 3211,3216 ****
Karsten Hopp 33c265
--- 3233,3252 ----
Karsten Hopp 33c265
  
Karsten Hopp 33c265
  static struct timeval	prev_timeval;
Karsten Hopp 33c265
  
Karsten Hopp 33c265
+ # ifdef WIN3264
Karsten Hopp 33c265
+ /*
Karsten Hopp 33c265
+  * Windows doesn't have gettimeofday(), although it does have struct timeval.
Karsten Hopp 33c265
+  */
Karsten Hopp 33c265
+     static int
Karsten Hopp 33c265
+ gettimeofday(struct timeval *tv, char *dummy)
Karsten Hopp 33c265
+ {
Karsten Hopp 33c265
+     long t = clock();
Karsten Hopp 33c265
+     tv->tv_sec = t / CLOCKS_PER_SEC;
Karsten Hopp 33c265
+     tv->tv_usec = (t - tv->tv_sec * CLOCKS_PER_SEC) * 1000000 / CLOCKS_PER_SEC;
Karsten Hopp 33c265
+     return 0;
Karsten Hopp 33c265
+ }
Karsten Hopp 33c265
+ # endif
Karsten Hopp 33c265
+ 
Karsten Hopp 33c265
  /*
Karsten Hopp 33c265
   * Save the previous time before doing something that could nest.
Karsten Hopp 33c265
   * set "*tv_rel" to the time elapsed so far.
Karsten Hopp 33c265
***************
Karsten Hopp 33c265
*** 3299,3318 ****
Karsten Hopp 33c265
      }
Karsten Hopp 33c265
  }
Karsten Hopp 33c265
  
Karsten Hopp 33c265
- # ifdef WIN3264
Karsten Hopp 33c265
- /*
Karsten Hopp 33c265
-  * Windows doesn't have gettimeofday(), although it does have struct timeval.
Karsten Hopp 33c265
-  */
Karsten Hopp 33c265
-     int
Karsten Hopp 33c265
- gettimeofday(struct timeval *tv, char *dummy)
Karsten Hopp 33c265
- {
Karsten Hopp 33c265
-     long t = clock();
Karsten Hopp 33c265
-     tv->tv_sec = t / CLOCKS_PER_SEC;
Karsten Hopp 33c265
-     tv->tv_usec = (t - tv->tv_sec * CLOCKS_PER_SEC) * 1000000 / CLOCKS_PER_SEC;
Karsten Hopp 33c265
-     return 0;
Karsten Hopp 33c265
- }
Karsten Hopp 33c265
- # endif
Karsten Hopp 33c265
- 
Karsten Hopp 33c265
  #endif
Karsten Hopp 33c265
  
Karsten Hopp 33c265
  #if defined(FEAT_CLIENTSERVER) || defined(PROTO)
Karsten Hopp 33c265
--- 3335,3340 ----
Karsten Hopp 33c265
*** ../vim-7.2.268/src/macros.h	2009-05-17 13:30:58.000000000 +0200
Karsten Hopp 33c265
--- src/macros.h	2009-10-10 15:19:07.000000000 +0200
Karsten Hopp 33c265
***************
Karsten Hopp 33c265
*** 243,249 ****
Karsten Hopp 33c265
  #endif
Karsten Hopp 33c265
  
Karsten Hopp 33c265
  #ifdef STARTUPTIME
Karsten Hopp 33c265
! # define TIME_MSG(s) time_msg(s, NULL)
Karsten Hopp 33c265
  #else
Karsten Hopp 33c265
  # define TIME_MSG(s)
Karsten Hopp 33c265
  #endif
Karsten Hopp 33c265
--- 243,249 ----
Karsten Hopp 33c265
  #endif
Karsten Hopp 33c265
  
Karsten Hopp 33c265
  #ifdef STARTUPTIME
Karsten Hopp 33c265
! # define TIME_MSG(s) { if (time_fd != NULL) time_msg(s, NULL); }
Karsten Hopp 33c265
  #else
Karsten Hopp 33c265
  # define TIME_MSG(s)
Karsten Hopp 33c265
  #endif
Karsten Hopp 33c265
*** ../vim-7.2.268/src/version.c	2009-11-03 11:43:05.000000000 +0100
Karsten Hopp 33c265
--- src/version.c	2009-11-03 12:06:31.000000000 +0100
Karsten Hopp 33c265
***************
Karsten Hopp 33c265
*** 678,679 ****
Karsten Hopp 33c265
--- 678,681 ----
Karsten Hopp 33c265
  {   /* Add new patch number below this line */
Karsten Hopp 33c265
+ /**/
Karsten Hopp 33c265
+     269,
Karsten Hopp 33c265
  /**/
Karsten Hopp 33c265
Karsten Hopp 33c265
-- 
Karsten Hopp 33c265
BEDEVERE: Look!  It's the old man from scene 24 - what's he Doing here?
Karsten Hopp 33c265
ARTHUR:   He is the keeper of the Bridge.  He asks each traveler five
Karsten Hopp 33c265
          questions ...
Karsten Hopp 33c265
GALAHAD:  Three questions.
Karsten Hopp 33c265
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
Karsten Hopp 33c265
Karsten Hopp 33c265
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 33c265
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 33c265
\\\        download, build and distribute -- http://www.A-A-P.org        ///
Karsten Hopp 33c265
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///