Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Log warning if time between invocations of the watchdog thread is twi…

…ce the timer setting.

This is to help detect situations where thread timeout warnings are being generated because of general machine issues rather than deadlock, network or other problems.
  • Loading branch information...
commit 7e73f609e5f61040358ec247d371306165945ca1 1 parent db9616f
Justin Clark-Casey authored July 05, 2012

Showing 1 changed file with 22 additions and 2 deletions. Show diff stats Hide diff stats

  1. 24  OpenSim/Framework/Watchdog.cs
24  OpenSim/Framework/Watchdog.cs
@@ -101,12 +101,24 @@ public ThreadWatchdogInfo(Thread thread, int timeout)
101 101
         private static Dictionary<int, ThreadWatchdogInfo> m_threads;
102 102
         private static System.Timers.Timer m_watchdogTimer;
103 103
 
  104
+        /// <summary>
  105
+        /// Last time the watchdog thread ran.
  106
+        /// </summary>
  107
+        /// <remarks>
  108
+        /// Should run every WATCHDOG_INTERVAL_MS
  109
+        /// </remarks>
  110
+        public static int LastWatchdogThreadTick { get; private set; }
  111
+
104 112
         static Watchdog()
105 113
         {
106 114
             m_threads = new Dictionary<int, ThreadWatchdogInfo>();
107 115
             m_watchdogTimer = new System.Timers.Timer(WATCHDOG_INTERVAL_MS);
108 116
             m_watchdogTimer.AutoReset = false;
109 117
             m_watchdogTimer.Elapsed += WatchdogTimerElapsed;
  118
+
  119
+            // Set now so we don't get alerted on the first run
  120
+            LastWatchdogThreadTick = Environment.TickCount & Int32.MaxValue;
  121
+
110 122
             m_watchdogTimer.Start();
111 123
         }
112 124
 
@@ -264,6 +276,16 @@ public static ThreadWatchdogInfo GetCurrentThreadInfo()
264 276
         /// <param name="e"></param>
265 277
         private static void WatchdogTimerElapsed(object sender, System.Timers.ElapsedEventArgs e)
266 278
         {
  279
+            int now = Environment.TickCount & Int32.MaxValue;
  280
+            int msElapsed = now - LastWatchdogThreadTick;
  281
+
  282
+            if (msElapsed > WATCHDOG_INTERVAL_MS * 2)
  283
+                m_log.WarnFormat(
  284
+                    "[WATCHDOG]: {0} ms since Watchdog last ran.  Interval should be approximately {1} ms",
  285
+                    msElapsed, WATCHDOG_INTERVAL_MS);
  286
+
  287
+            LastWatchdogThreadTick = Environment.TickCount & Int32.MaxValue;
  288
+
267 289
             Action<ThreadWatchdogInfo> callback = OnWatchdogTimeout;
268 290
 
269 291
             if (callback != null)
@@ -272,8 +294,6 @@ private static void WatchdogTimerElapsed(object sender, System.Timers.ElapsedEve
272 294
 
273 295
                 lock (m_threads)
274 296
                 {
275  
-                    int now = Environment.TickCount & Int32.MaxValue;
276  
-
277 297
                     foreach (ThreadWatchdogInfo threadInfo in m_threads.Values)
278 298
                     {
279 299
                         if (threadInfo.Thread.ThreadState == ThreadState.Stopped)

0 notes on commit 7e73f60

Please sign in to comment.
Something went wrong with that request. Please try again.