aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Watchdog.cs
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2012-02-24 05:02:33 +0000
committerJustin Clark-Casey (justincc)2012-02-24 05:02:33 +0000
commitf67f37074f3f7e0602b66aa66a044dd9fd107f6a (patch)
treef4e592451ab205b23075d423dab1a2a94dee5629 /OpenSim/Framework/Watchdog.cs
parentIn osSetSpeed(), if no avatar for a uuid is found then don't attempt to set s... (diff)
downloadopensim-SC-f67f37074f3f7e0602b66aa66a044dd9fd107f6a.zip
opensim-SC-f67f37074f3f7e0602b66aa66a044dd9fd107f6a.tar.gz
opensim-SC-f67f37074f3f7e0602b66aa66a044dd9fd107f6a.tar.bz2
opensim-SC-f67f37074f3f7e0602b66aa66a044dd9fd107f6a.tar.xz
Stop spurious scene loop startup timeout alarms for scenes with many prims.
On the first frame, all startup scene objects are added to the physics scene. This can cause a considerable delay, so we don't start raising the alarm on scene loop timeouts until the second frame. This commit also slightly changes the behaviour of timeout reporting. Previously, a report was made for the very first timed out thread, ignoring all others until the next watchdog check. Instead, we now report every timed out thread, though we still only do this once no matter how long the timeout.
Diffstat (limited to 'OpenSim/Framework/Watchdog.cs')
-rw-r--r--OpenSim/Framework/Watchdog.cs57
1 files changed, 40 insertions, 17 deletions
diff --git a/OpenSim/Framework/Watchdog.cs b/OpenSim/Framework/Watchdog.cs
index 2dd6ebe..e443f0a 100644
--- a/OpenSim/Framework/Watchdog.cs
+++ b/OpenSim/Framework/Watchdog.cs
@@ -72,6 +72,11 @@ namespace OpenSim.Framework
72 /// </summary> 72 /// </summary>
73 public bool IsTimedOut { get; set; } 73 public bool IsTimedOut { get; set; }
74 74
75 /// <summary>
76 /// Will this thread trigger the alarm function if it has timed out?
77 /// </summary>
78 public bool AlarmIfTimeout { get; set; }
79
75 public ThreadWatchdogInfo(Thread thread, int timeout) 80 public ThreadWatchdogInfo(Thread thread, int timeout)
76 { 81 {
77 Thread = thread; 82 Thread = thread;
@@ -112,12 +117,13 @@ namespace OpenSim.Framework
112 /// <param name="start">The method that will be executed in a new thread</param> 117 /// <param name="start">The method that will be executed in a new thread</param>
113 /// <param name="name">A name to give to the new thread</param> 118 /// <param name="name">A name to give to the new thread</param>
114 /// <param name="priority">Priority to run the thread at</param> 119 /// <param name="priority">Priority to run the thread at</param>
115 /// <param name="isBackground">True to run this thread as a background 120 /// <param name="isBackground">True to run this thread as a background thread, otherwise false</param>
116 /// thread, otherwise false</param> 121 /// <param name="alarmIfTimeout">Trigger an alarm function is we have timed out</param>
117 /// <returns>The newly created Thread object</returns> 122 /// <returns>The newly created Thread object</returns>
118 public static Thread StartThread(ThreadStart start, string name, ThreadPriority priority, bool isBackground) 123 public static Thread StartThread(
124 ThreadStart start, string name, ThreadPriority priority, bool isBackground, bool alarmIfTimeout)
119 { 125 {
120 return StartThread(start, name, priority, isBackground, WATCHDOG_TIMEOUT_MS); 126 return StartThread(start, name, priority, isBackground, alarmIfTimeout, WATCHDOG_TIMEOUT_MS);
121 } 127 }
122 128
123 /// <summary> 129 /// <summary>
@@ -128,21 +134,21 @@ namespace OpenSim.Framework
128 /// <param name="priority">Priority to run the thread at</param> 134 /// <param name="priority">Priority to run the thread at</param>
129 /// <param name="isBackground">True to run this thread as a background 135 /// <param name="isBackground">True to run this thread as a background
130 /// thread, otherwise false</param> 136 /// thread, otherwise false</param>
131 /// <param name="timeout"> 137 /// <param name="alarmIfTimeout">Trigger an alarm function is we have timed out</param>
132 /// Number of milliseconds to wait until we issue a warning about timeout. 138 /// <param name="timeout">Number of milliseconds to wait until we issue a warning about timeout.</param>
133 /// </para>
134 /// <returns>The newly created Thread object</returns> 139 /// <returns>The newly created Thread object</returns>
135 public static Thread StartThread( 140 public static Thread StartThread(
136 ThreadStart start, string name, ThreadPriority priority, bool isBackground, int timeout) 141 ThreadStart start, string name, ThreadPriority priority, bool isBackground, bool alarmIfTimeout, int timeout)
137 { 142 {
138 Thread thread = new Thread(start); 143 Thread thread = new Thread(start);
139 thread.Name = name; 144 thread.Name = name;
140 thread.Priority = priority; 145 thread.Priority = priority;
141 thread.IsBackground = isBackground; 146 thread.IsBackground = isBackground;
142 147
143 ThreadWatchdogInfo twi = new ThreadWatchdogInfo(thread, timeout); 148 ThreadWatchdogInfo twi = new ThreadWatchdogInfo(thread, timeout) { AlarmIfTimeout = alarmIfTimeout };
144 149
145 m_log.Debug("[WATCHDOG]: Started tracking thread \"" + twi.Thread.Name + "\" (ID " + twi.Thread.ManagedThreadId + ")"); 150 m_log.DebugFormat(
151 "[WATCHDOG]: Started tracking thread {0}, ID {1}", twi.Thread.Name, twi.Thread.ManagedThreadId);
146 152
147 lock (m_threads) 153 lock (m_threads)
148 m_threads.Add(twi.Thread.ManagedThreadId, twi); 154 m_threads.Add(twi.Thread.ManagedThreadId, twi);
@@ -230,6 +236,26 @@ namespace OpenSim.Framework
230 return m_threads.Values.ToArray(); 236 return m_threads.Values.ToArray();
231 } 237 }
232 238
239 /// <summary>
240 /// Return the current thread's watchdog info.
241 /// </summary>
242 /// <returns>The watchdog info. null if the thread isn't being monitored.</returns>
243 public static ThreadWatchdogInfo GetCurrentThreadInfo()
244 {
245 lock (m_threads)
246 {
247 if (m_threads.ContainsKey(Thread.CurrentThread.ManagedThreadId))
248 return m_threads[Thread.CurrentThread.ManagedThreadId];
249 }
250
251 return null;
252 }
253
254 /// <summary>
255 /// Check watched threads. Fire alarm if appropriate.
256 /// </summary>
257 /// <param name="sender"></param>
258 /// <param name="e"></param>
233 private static void WatchdogTimerElapsed(object sender, System.Timers.ElapsedEventArgs e) 259 private static void WatchdogTimerElapsed(object sender, System.Timers.ElapsedEventArgs e)
234 { 260 {
235 WatchdogTimeout callback = OnWatchdogTimeout; 261 WatchdogTimeout callback = OnWatchdogTimeout;
@@ -246,21 +272,18 @@ namespace OpenSim.Framework
246 { 272 {
247 if (threadInfo.Thread.ThreadState == ThreadState.Stopped) 273 if (threadInfo.Thread.ThreadState == ThreadState.Stopped)
248 { 274 {
249 timedOut = threadInfo;
250 RemoveThread(threadInfo.Thread.ManagedThreadId); 275 RemoveThread(threadInfo.Thread.ManagedThreadId);
251 break; 276 callback(threadInfo.Thread, threadInfo.LastTick);
252 } 277 }
253 else if (!threadInfo.IsTimedOut && now - threadInfo.LastTick >= threadInfo.Timeout) 278 else if (!threadInfo.IsTimedOut && now - threadInfo.LastTick >= threadInfo.Timeout)
254 { 279 {
255 threadInfo.IsTimedOut = true; 280 threadInfo.IsTimedOut = true;
256 timedOut = threadInfo; 281
257 break; 282 if (threadInfo.AlarmIfTimeout)
283 callback(threadInfo.Thread, threadInfo.LastTick);
258 } 284 }
259 } 285 }
260 } 286 }
261
262 if (timedOut != null)
263 callback(timedOut.Thread, timedOut.LastTick);
264 } 287 }
265 288
266 m_watchdogTimer.Start(); 289 m_watchdogTimer.Start();