strace 很好,但是

strace 很好,但是

gvim 程序在打开任何文件之前卡住了 3 秒。这个问题与gvim无关,vim打开得很好。因此,原因一定是 X 或某些相关服务中的某个地方,而不是 vim。

我尝试禁用所有 vim 插件和 vimrc 文件。

这是症状:

$ time strace -o strace.gvim -f -yy -T gvim -c q 
time: Real 0m3.5s  User 0m0.0s  System 0m0.1s

虽然 vim 运行良好:

$ time strace -o strace.vim -f -yy -T vim -c q 
time: Real 0m0.2s  User 0m0.0s  System 0m0.0s

为了弄清楚这一点,我正在寻找花费了这么长时间的原因:

...看起来它与 dbus 服务有某种关系。

$ grep '<3\.[0-9]' -C 2 strace.gvim 

-

4907  exit_group(0)                     = ?
4907  +++ exited with 0 +++
4848  <... nanosleep resumed> 0x7ffcaa8f8670) = 0 <3.000198>
4848  kill(4907, SIGKILL)               = -1 ESRCH (No such process) <0.000061>
4848  write(1<pipe:[29773]>, "unix:abstract=/tmp/dbus-8t4OQuvB"..., 73) = 73 <0.000071>
@@@@@@@@ 4586  <... read resumed> "unix:abstract=/tmp/dbus-8t4OQuvB"..., 1024) = 73 <3.038342>
4848  write(1<pipe:[29773]>, "+\23\0\0", 4 <unfinished ...>
4586  read(7<pipe:[29773]>,  <unfinished ...>
--
4586  <... read resumed> "", 1024)      = 0 <0.000038>
4586  wait4(4848,  <unfinished ...>
@@@@@@@@ 4900  <... read resumed> "", 4)         = 0 <3.017352>
4848  +++ exited with 0 +++
4900  write(2</dev/null<char 1:3>>, "EOF in dbus-launch reading PID f"..., 47) = 47 <0.000003>
--
4586  close(4<pipe:[30791]>)            = 0 <0.000003>
4586  poll([{fd=5<UNIX:[29772]>, events=POLLIN}, {fd=6<anon_inode:[eventfd]>, events=POLLIN}], 2, 0 <unfinished ...>
@@@@@@@@ 4579  <... read resumed> "ok\0", 9)     = 3 <3.368490>
4586  <... poll resumed> )              = 0 (Timeout) <0.000006>
4586  poll([{fd=5<UNIX:[29772]>, events=POLLIN}, {fd=6<anon_inode:[eventfd]>, events=POLLIN}], 2, 0 <unfinished ...>

进一步查看,我发现该~/.dbus文件夹归 root 所有:

4848  mkdir("/home/jaroslav/.dbus", 0700) = -1 EEXIST (File exists) <0.000005>
4848  mkdir("/home/jaroslav/.dbus/session-bus", 0700) = -1 EACCES (Permission denied) <0.000003>
4848  write(2<pipe:[29774]>, "Unable to create /home/jaroslav/"..., 50) = 50 <0.000004>

-

$ ls -ld ~/.dbus 
drwx------ 1 root root 1 191206 18:50 /home/jaroslav/.dbus

更改所有者解决了问题,gvim 立即启动。

strace 很好,但是

是否有可能以某种方式跟踪所有耗时超过 3 秒的内核调用并打印其堆栈(Linux 4.19.72)?

相关内容