I'm having problems where Xorg server suddenly gets very slow and its CPU usage goes to 100%. Googling about this suggest that the "state of art" debugging method for this issue is to start randomly killing X clients until the problem goes away and then you know which client was the problematic one (good luck trying to debug the process after killing it). None of the X clients are eating lots of CPU (around max 1% of CPU each). And the system still has 2GB of available RAM.
Does anybody know a method to better diagnose the problem? Basically I'm looking for top replacement for Xorg which would directly point me to the client process that is causing most CPU usage for Xorg. I already know about xrestop which is the same thing for the Xorg memory usage but this question is specifically about CPU usage.
Another cause for this slowdown might be running out of GPU memory which might cause pushing bitmaps over PCI-express bus instead of rendering directly from GPU memory to display. If this shows as CPU usage on the kernel level (e.g. top), it might be the problem I'm seeing but I would like to understand the cause better. As I'm writing this from the problematic system it seems that most slowdown occurs in input handling or font rendering but I dont know how to diagnose the thing any better.
I know it's possible to use another computer and connect with ssh, attach a gdb process to the problematic Xorg server and start digging but I'm hoping for something a bit easier.
If I got PID or even window handle for the problematic client, figuring out the root cause would be easier (e.g. https://unix.stackexchange.com/q/5478). And I wouldn't need to kill well-behaving processes as a side-effect.