fre*_*fox 8 emacs shell profiler profiling
有没有一种方法可以分析emacs中对shell命令的阻塞时间?考虑以下程序:
(profiler-start 'cpu)
(shell-command "sleep 3")
(profiler-report)
(profiler-stop)
Run Code Online (Sandbox Code Playgroud)
探查器报告将如下所示:
- command-execute 371 95%
- call-interactively 371 95%
- funcall-interactively 329 84%
- execute-extended-command 175 44%
- execute-extended-command--shorter 157 40%
- completion-try-completion 149 38%
- completion--nth-completion 149 38%
- completion--some 143 36%
- #<compiled 0x438307f1> 143 36%
- completion-pcm-try-completion 102 26%
- completion-pcm--find-all-completions 98 25%
completion-pcm--all-completions 98 25%
+ completion-pcm--merge-try 4 1%
completion-basic-try-completion 41 10%
+ sit-for 16 4%
- eval-expression 154 39%
- eval 154 39%
- profiler-start 154 39%
- debug 154 39%
- recursive-edit 141 36%
- command-execute 114 29%
- call-interactively 114 29%
- byte-code 107 27%
+ read--expression 64 16%
+ read-extended-command 43 11%
+ funcall-interactively 7 1%
+ byte-code 42 10%
+ ... 19 4%
Run Code Online (Sandbox Code Playgroud)
如您所见,花费的时间或多或少是均匀分配的。我有兴趣看到输出告诉我,我在shell命令上花费了程序阻塞的大部分时间sleep 3
,这有可能吗?我知道这sleep 3
对我的CPU 来说并不算很重-但是我试图弄清楚从那里调用哪个shell命令magit
花费了很长时间-所以我也会对受IO限制的东西感兴趣。
请注意,这profiler.el
是一个采样分析器。您可能想尝试检测分析器,例如elp.el
您是否对挂墙时间感兴趣。
在您的情况下,您可能希望magit
使用M-x elp-instrument-package
RET magit
RET. 运行 magit 命令后,您可以使用M-x elp-results
RET.
因为magit
您可能会发现该功能magit-process-file
占用了大量时间。为了进一步研究特定的函数调用,您可以简单地检测该函数或任何其他函数,方法是添加一个建议函数,将运行时与函数的参数一起记录到每个单独函数调用的消息缓冲区中,如下所示。
(defun log-function-time (f &rest args)
(let ((time-start (current-time)))
(prog1
(apply f args)
(message "%s seconds used in (magit-process-file %s)"
(time-to-seconds (time-subtract (current-time) time-start))
args))))
(advice-add 'magit-process-file :around 'log-function-time)
Run Code Online (Sandbox Code Playgroud)