Advertisement
RandomClear

How to create hang/deadlock report on demand

Aug 4th, 2014
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.26 KB | None | 0 0
  1. // EurekaLog has hang detection feature (see: http://www.eurekalog.com/help/eurekalog/hang_detection_page.php )
  2. // However, this feature will work only for main thread on XP and older systems (see: http://www.eurekalog.com/help/eurekalog/hangs_and_deadlocks.php ).
  3.  
  4. // Sometimes, you need to debug problems with hanged/deadlock threads, or threads eating 100% of CPU core.
  5. // You can create a bug report with call stacks for such threads on demand.
  6.  
  7. // See also: http://pastebin.com/rdNbEwPH - "how to get call stack on demand"
  8.  
  9. // Option 1: mark certain thread as "hang".
  10.  
  11. uses
  12.   EFreeze;
  13.  
  14. var
  15.   ThreadID: Cardinal;
  16. // ...
  17.   ThreadID := { get ID of handed/deadlocked thread };
  18.   RaiseFreezeException(ThreadID);
  19. // ...
  20.  
  21. // Note: EurekaLog uses this method inside its freeze detection feature (ThreadID matches MainThreadID).
  22.  
  23.  
  24. // Alternative (preferred solution when you have thread handle available):
  25.  
  26. uses
  27.   EFreeze;
  28.  
  29. var
  30.   ThreadID: Cardinal;
  31.   ThreadHandle: THandle;
  32. // ...
  33.   ThreadID     := { get ID of handed/deadlocked thread };
  34.   ThreadHandle := { get handle of handed/deadlocked thread };
  35.   RaiseFreezeException(ThreadID, ThreadHandle);
  36. // ...
  37.  
  38.  
  39. // The above examples will trigger EFrozenApplication exception inside CURRENT thread, but exception information will contain the specified thread. If you do not catch this exception - it will generate usual EurekaLog's bug report. Hanged thread will be included as "exception thread" in this report (with full call stack). Other threads may or may be not included in the bug report - depending on your options (see "Capture stack of ..." options: http://www.eurekalog.com/help/eurekalog/multi_threading_page.php ).
  40.  
  41.  
  42. // Option 2: generate full bug report
  43.  
  44. uses
  45.   EModules,
  46.   EExceptionManager;
  47.  
  48. // ...
  49.   CurrentEurekaLogOptions.csoShowELThreads := True;  // <- enable "Capture stack of EurekaLog threads"
  50.   ExceptionManager.StandardEurekaError('Application seems to be frozen');
  51.  
  52.  
  53. // The above solution will create bug report inside current thread. Current thread will be used as "exception thread". However, hanged/deadlocked thread will appear in the bug report - because we enabled corresponding option (your thread must be EurekaLog-enabled thread, otherwise you should use another csoShowXYZ option).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement