Skip to content

Commit

Permalink
Include additional debugging info for 0% progress. #14
Browse files Browse the repository at this point in the history
  • Loading branch information
dstein64 committed Jul 27, 2022
1 parent da5464c commit 682c968
Showing 1 changed file with 41 additions and 24 deletions.
65 changes: 41 additions & 24 deletions autoload/startuptime.vim
Original file line number Diff line number Diff line change
Expand Up @@ -215,28 +215,7 @@ function! s:ExtractRequireArg(event) abort
return a:event[9:-3]
endfunction

function! s:Profile(onfinish, onprogress, options, tries, file, items) abort
if !a:onprogress(a:tries)
return
endif
" Extract data when it's available (i.e., after the first call to Profile).
if a:tries <# a:options.tries
while 1
try
let l:items = s:Extract(a:file, a:options)
break
catch /^Vim:Interrupt$/
" Ignore interrupts. The loop will result in re-attempting to extract.
" The plugin can be interrupted by closing the window.
endtry
endwhile
call extend(a:items, l:items)
call delete(a:file)
endif
if a:tries ==# 0
call a:onfinish()
return
endif
function! s:ProfileCmd(file) abort
" * If timer_start() is available, vim is quit with a timer. This retains
" all events up to the last event, '--- VIM STARTED ---'.
" * XXX: If timer_start() is not available, an autocmd is used. This retains
Expand All @@ -258,7 +237,7 @@ function! s:Profile(onfinish, onprogress, options, tries, file, items) abort
let l:quit_cmd_timer = 'call timer_start(0, {-> execute(''qall!'')})'
let l:quit_cmd_autocmd = 'autocmd VimEnter * qall!'
let l:quit_cmd = printf(
\ 'if exists(''*timer_start'') | %s | else | %s | endif',
\ 'if exists(''*timer_start'') | %s | else | %s | endif',
\ l:quit_cmd_timer,
\ l:quit_cmd_autocmd)
let l:command = [
Expand All @@ -267,6 +246,32 @@ function! s:Profile(onfinish, onprogress, options, tries, file, items) abort
\ '-c', l:quit_cmd
\ ]
call extend(l:command, g:startuptime_exe_args)
return l:command
endfunction

function! s:Profile(onfinish, onprogress, options, tries, file, items) abort
if !a:onprogress(a:tries)
return
endif
" Extract data when it's available (i.e., after the first call to Profile).
if a:tries <# a:options.tries
while 1
try
let l:items = s:Extract(a:file, a:options)
break
catch /^Vim:Interrupt$/
" Ignore interrupts. The loop will result in re-attempting to extract.
" The plugin can be interrupted by closing the window.
endtry
endwhile
call extend(a:items, l:items)
call delete(a:file)
endif
if a:tries ==# 0
call a:onfinish()
return
endif
let l:command = s:ProfileCmd(a:file)
" The 'tmp' dict is used so a local function can be created.
let l:tmp = {}
let l:args = [a:onfinish, a:onprogress, a:options, a:tries - 1, a:file, a:items]
Expand Down Expand Up @@ -1081,10 +1086,22 @@ function! s:OnProgress(winid, bufnr, total, pending) abort
\ ' ordinary startup, this could be problematic for vim-startuptime.',
\ ' Running :messages within the nested (n)vim may help identify the',
\ ' issue.',
\ '',
\ ' It may help to run a nested instance of (n)vim in a manner similar',
\ ' to vim-startuptime. The following lines show the shell-escaped',
\ ' program and arguments used by vim-startuptime. <OUTPUT> should be',
\ ' replaced with an output file.'
\ ]
let l:command = s:ProfileCmd('<OUTPUT>')
call add(l:lines, ' ' . shellescape(l:command[0]))
for l:line in l:command[1:]
call add(l:lines, ' ' . shellescape(l:line))
endfor
call extend(l:lines, [
\ '',
\ ' Try running vim-startuptime again once the problem is avoided via a',
\ ' configuration update.',
\ ]
\ ])
for l:line in l:lines
call s:SetBufLine(a:bufnr, line('$') + 1, l:line)
endfor
Expand Down

0 comments on commit 682c968

Please sign in to comment.