Something in my configuration causes emacs to occasionally hang or enter a very long busy loop. I have been adding things to my .emacs for several decades, so figuring out what the problem is by removing things is complicated, especially since I generally need to be using emacs and taking out significant parts of its functionality makes that difficult.
Sometimes, C-g
does not break the loop and the only thing that I have found that is effective is to kill -9
the process.
I had the idea of writing a timer which runs once a minute and writes the current backtrace to a file. That is working, but timers only run at certain times (basically, when emacs is idle or waiting for input). So my timer does an excellent job of telling me what is happening when emacs is working like I want it to, but does not run when I actually care about the backtrace.
Is there a way to trigger code to run (automatically or manually via an external process like kill -USR1
) when emacs is busy?
I know about about debug-on-quit
and debug-on-signal
, but I have not been able to use them effectively in this case.
I also know that profiling functions exist, but if I understand them correctly, I need to specify the package to profile. I do not have specific packages that I suspect here (maybe it is font-lock on a large buffer, maybe it is some mode parsing a buffer in the background, maybe it is something I was totally unaware was happening). Profiling is also not useful if I cannot get back to a command prompt unless the profiler can automatically write out results from time to time.
Is there a good way to do what I am trying?
EDIT
This link How does emacs respond to Unix signals? might have useful information. I have set up USR1 to write a backtrace. Now I get to see if it works the next time it hangs.
It hung before I got around to updating, and it seems to be ignoring USR1 when busy but not when idle.