Trigger an "on demand" freeze detection stack trace
Trigger an "on demand" freeze detection stack trace
Freeze detection is invaluable for finding where my program has gone when it has wandered off into the weeds. Is there any way I can trigger the freeze detection manually, i.e. carry out the same procedure that happens for a freeze detection, but arbitrarily-not waiting for the freeze detection delay to expire? I guess this is going to be more difficult if the application is not dealing with messages (i.e. I don't imaging it would be possible to have the traceback report triggered by a button or (even better) by a keystroke), but madExcept manages to do this for freeze detection.
Re: Trigger an "on demand" freeze detection stack trace
Code: Select all
function CreateFreezeReport : UnicodeString;
var exc : IMEException;
begin
exc := NewException(etFrozen, nil, nil, true, 0, 0, 0, nil, MESettings, esManual, nil, 0, '');
exc.ShowPleaseWaitBox := false;
exc.ListThreads := true;
result := exc.GetBugReport;
end;
Re: Trigger an "on demand" freeze detection stack trace
Thanks Mathias, but how would I trigger this from an application that was stuck in loop and wasn't calling Application.ProcessMessages, running timers, etc.?
How does MadExcept do it? I.e what happens when MadExcept is enabled and it detects that the freeze timeout has expired?
How does MadExcept do it? I.e what happens when MadExcept is enabled and it detects that the freeze timeout has expired?
Re: Trigger an "on demand" freeze detection stack trace
You would trigger this from a secondary thread, which maybe sleeps a lot of time and then checks (maybe once every 200ms or so) whether your application has frozen.
Re: Trigger an "on demand" freeze detection stack trace
OK, that's presumably how you do it in MadExcept but, let be explain the scenario: say I have an application that has MadExcept enabled and freeze detection set to 1 minute. There turns out to be a place during execution where it freezes for 10 seconds every now and then - not long enough to trigger ME's freeze detection, but long enough to be annoying. So I want some way of triggereing a freeze report while it is in this state. How would I do this with a secondary thread?
Thanks for your time Mathias.
Thanks for your time Mathias.
Re: Trigger an "on demand" freeze detection stack trace
I'm really not sure what you're asking. How to detect the freeze? Or how to tell madExcept to handle a freeze which you've detected? You said earlier that you know how to detect a freeze. So I didn't say anything more about that topic. If you just want to know how to tell madExcept to handle a freeze then refer to the code in my first post in this thread.
If you don't want the freeze report as a text file but instead want madExcept to display a freeze window, then simply replace "exc.GetBugReport" with "exc.Show". Or alternatively use the following line of code:
If you don't want the freeze report as a text file but instead want madExcept to display a freeze window, then simply replace "exc.GetBugReport" with "exc.Show". Or alternatively use the following line of code:
Code: Select all
HandleException(etFrozen, nil, nil, true, 0, 0, nil, esAntiFreezeCheck);
Re: Trigger an "on demand" freeze detection stack trace
Neither! Here is the scenario that I'm interested in covering.I'm really not sure what you're asking. How to detect the freeze? Or how to tell madExcept to handle a freeze which you've detected?
Say I have a project that uses ME, but has freeze detection disabled. Say I have a construct in that program like:
Code: Select all
repeat
do something
if exit condition true
break
Application.ProcessMessages
until false
procedure Form1.Form1OnKeydown
Code: Select all
case key of
27 : StrToFile ('freeze.txt', CreateFreezeReport)
What can I do if the repeat..until block doesn't call the message pump? How do I trigger the call to CreateFreezeReport when my program is REALLY hung. MadExcept is obviously able to do it when it's freeze timer counts down to zero. Does it do this by running the freeze detection in a separate thread?
The reason I am interested is this: I had an application that was spending much longer than I anticipated while it was initializing - like twenty seconds when it should have only taken around one second. There were various ways I could have traced this down, but I did it without needing to touch the code by temporarily setting the MadExcept freeze timeout to 10 seconds, running it, and waiting (Of course this method doesn't work if your program is stuck in a loop that IS calling the message pump...).
That's when it occurred to me that it would be good to have the ability to trigger a freeze report on demand. I know now how to generate the report - it's just the "on demand" I'm struggling with!
Re: Trigger an "on demand" freeze detection stack trace
> What can I do if the repeat..until block doesn't call the message pump?
Wait until madExcept's automatic freeze detection kicks in? Or run the madTraceProcess.exe tool?
> How do I trigger the call to CreateFreezeReport when my program is REALLY hung.
I already answered that in my 2nd post: By using a secondary thread, of course.
If you're asking how to detect a key press when the main thread is frozen: Key events are usually sent by the OS to top-level windows. But if your main thread is frozen, those messages won't arrive. So you may have to use a keyboard hook (e.g. SetWindowsHookEx(WH_KEYBOARD_LL)). But maybe manually starting madTraceProcess.exe is all you need?
Wait until madExcept's automatic freeze detection kicks in? Or run the madTraceProcess.exe tool?
> How do I trigger the call to CreateFreezeReport when my program is REALLY hung.
I already answered that in my 2nd post: By using a secondary thread, of course.
If you're asking how to detect a key press when the main thread is frozen: Key events are usually sent by the OS to top-level windows. But if your main thread is frozen, those messages won't arrive. So you may have to use a keyboard hook (e.g. SetWindowsHookEx(WH_KEYBOARD_LL)). But maybe manually starting madTraceProcess.exe is all you need?
Re: Trigger an "on demand" freeze detection stack trace
Brilliant!
MadTraceProcess32.exe is all I need. Wish I had noticed that a bit sooner.
Many thanks Mathias.
MadTraceProcess32.exe is all I need. Wish I had noticed that a bit sooner.
Many thanks Mathias.