如何剖析用python编写的vim插件

时间:2018-12-13 17:52:45

标签: python-3.x vim profiling vim-plugin

Vim提供了:profile命令,非常方便。但这仅限于Vim脚本-当涉及到以python实现的插件时,它没有帮助。

目前,我正在尝试了解是什么原因导致Denite上的大量延迟。由于它不是在香草Vim中发生,而是仅在某些我不确定如何重现的特定条件下,我才找不到哪个设置/插件在干扰。

所以我转向了剖析,这就是我从:profile获得的:

FUNCTION  denite#vim#_start()
    Defined: ~/.vim/bundle/denite.nvim/autoload/denite/vim.vim line 33
Called 1 time
Total time:   5.343388
 Self time:   4.571928

count  total (s)   self (s)
    1              0.000006   python3 << EOF
                            def _temporary_scope():
                                nvim = denite.rplugin.Neovim(vim)
                                try:
                                    buffer_name = nvim.eval('a:context')['buffer_name']
                                    if nvim.eval('a:context')['buffer_name'] not in denite__uis:
                                        denite__uis[buffer_name] = denite.ui.default.Default(nvim)
                                    denite__uis[buffer_name].start(
                                        denite.rplugin.reform_bytes(nvim.eval('a:sources')),
                                        denite.rplugin.reform_bytes(nvim.eval('a:context')),
                                    )
                                except Exception as e:
                                    import traceback
                                    for line in traceback.format_exc().splitlines():
                                        denite.util.error(nvim, line)
                                    denite.util.error(nvim, 'Please execute :messages command.')
                            _temporary_scope()
                            if _temporary_scope in dir():
                                del _temporary_scope
                            EOF
    1              0.000017   return []


(...)

FUNCTIONS SORTED ON TOTAL TIME
count  total (s)   self (s)  function
    1   5.446612   0.010563  denite#helper#call_denite()
    1   5.396337   0.000189  denite#start()
    1   5.396148   0.000195  <SNR>237_start()
    1   5.343388   4.571928  denite#vim#_start()
(...)

我尝试通过换行来使用the python profiler directly

import cProfile
cProfile.run(_temporary_scope(), '/path/to/log/file')

,但没有运气-只是cProfile中的一堆错误。也许是因为hinted here是从Vim启动python的方式,所以它只能在主线程上工作。

我想应该有一种更简单的方法。

1 个答案:

答案 0 :(得分:0)

python探查器通过封装整个代码来工作,

cProfile.run("""
(...)
""", '/path/to/log/file')

,但不是那么有用。也许这就是所有可能。

相关问题