下面是一个脚本,用于确定是否是某个客户机导致了问题(尽管没有帮助解决我的问题):
#!/bin/bash
WINDOW_IDS=$(xwininfo -tree -root | grep -o -P '\b0x[0-9a-f]+' | sort -u)
PIDS=""
for ID in $WINDOW_IDS
do
if [ "$ID" = "0x0" ]
then
continue
fi
#printf "Window %s PID=" "$ID"
PID=$(LC_ALL=C xprop -id "$ID" _NET_WM_PID | cut -d' ' -f3-)
if [ "$PID" = "not found." ]
then
# printf "%s\n" "(unknown)"
# See also: https://unix.stackexchange.com/a/84981
true
else
# printf "%s\n" "$PID"
PIDS="$PIDS $PID"
fi
done
PIDS=$(printf "%s\n" $PIDS | sort -u)
# go through the list of processes connected to Xorg:
for PID in $PIDS
do
printf "%s: %s\n" "$PID" "$(cat /proc/$PID/cmdline)"
sleep 0.1s # wait for the previous line to get on the screen before stopping e.g. compositing manager
# Stop the process for 5 secs and let the process continue after that.
kill -STOP "$PID" && sleep 1s && kill -CONT "$PID"
done
我们的想法是依次停止每个客户机5秒钟,如果这能解决问题5秒钟,你就发现了问题。这个脚本发送
SIGSTOP
无法忽略的目标进程,并阻止目标进程获得CPU时间,因此它也无法向Xorg发送任何事件。请注意,如果中途终止此脚本,可能会导致某个进程处于停止状态。邮寄
SIGCONT
来解决这个问题。如果你等脚本完成,一切都会好起来。(另见:
https://unix.stackexchange.com/a/298650
)
在我的例子中,无论哪个客户端被停止,Xorg都会一直运行缓慢,所以我想我看到的问题是Xorg内部的问题,我需要使用FlameGraphs(
http://www.brendangregg.com/FlameGraphs/cpuflamegraphs.html
)找出问题的真正原因。