Collecting debug information when your GPU hangs

After having my i965 hang) twice this morning, I decided to create a small script to make it easier to capture the relevant information when this sort of bug happens. Because the X server stops running, the display is useless, and it’s convenient to be able to get the relevant information by running a single command (I do this using ConnectBot on my phone).

It’s designed to be invoked manually by the user while the system is hung, but if we can somehow detect that it’s locked up, then we could run it automatically.

It collects dmesg, /proc/interrupts, /proc/dri and (for Intel cards) intel_gpu_dump output at the time of the hang. It then leaves behind a crash report in /var/crash, so that after the user recovers their system, apport will collect the usual information and submit a bug on the appropriate package.

Where do you suggest it be added? It could be useful with more than one X driver, and they’re all shipped separately. Since it uses the apport libraries to collect and store the system state, I could submit it upstream to apport, but I don’t think that’s what you meant.