【发布时间】:2019-05-21 09:16:49
【问题描述】:
有没有办法分析 emacs 中 shell 命令的阻塞时间?考虑以下程序:
(profiler-start 'cpu)
(shell-command "sleep 3")
(profiler-report)
(profiler-stop)
分析器报告将如下所示:
- 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%
如您所见,所花费的时间或多或少是均匀分布的。我有兴趣看到输出告诉我我将程序的重要部分花费在 shell 命令sleep 3 上,这可能吗?我知道sleep 3 在我的 CPU 上并不重 - 但我试图弄清楚从 magit 调用哪些 shell 命令需要很长时间 - 所以我也会对 IO 的东西感兴趣-绑定。
【问题讨论】:
-
您可以使用
perf来获取低级调用的调用堆栈,例如。Fcall_process_region等假设您的 emacs 二进制文件没有被剥离符号。这可以让您检查 emacs 在给定 CPU 上阻塞所花费的时间,但我不确定您将如何匹配特定的 elisp 调用。
标签: shell emacs profiling profiler