From 134f86e8d5c414409631b25b8c6f0ee45fbd8631 Mon Sep 17 00:00:00 2001
From: David Walter Seikel
Date: Thu, 3 Nov 2016 21:44:39 +1000
Subject: Initial update to OpenSim 0.8.2.1 source code.
---
OpenSim/Framework/Monitoring/Watchdog.cs | 106 ++++++++++++++-----------------
1 file changed, 49 insertions(+), 57 deletions(-)
(limited to 'OpenSim/Framework/Monitoring/Watchdog.cs')
diff --git a/OpenSim/Framework/Monitoring/Watchdog.cs b/OpenSim/Framework/Monitoring/Watchdog.cs
index 3f992b1..a644fa5 100644
--- a/OpenSim/Framework/Monitoring/Watchdog.cs
+++ b/OpenSim/Framework/Monitoring/Watchdog.cs
@@ -38,6 +38,8 @@ namespace OpenSim.Framework.Monitoring
///
public static class Watchdog
{
+ private static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
+
/// Timer interval in milliseconds for the watchdog timer
public const double WATCHDOG_INTERVAL_MS = 2500.0d;
@@ -82,12 +84,32 @@ namespace OpenSim.Framework.Monitoring
///
public Func AlarmMethod { get; set; }
- public ThreadWatchdogInfo(Thread thread, int timeout)
+ ///
+ /// Stat structure associated with this thread.
+ ///
+ public Stat Stat { get; set; }
+
+ public ThreadWatchdogInfo(Thread thread, int timeout, string name)
{
Thread = thread;
Timeout = timeout;
FirstTick = Environment.TickCount & Int32.MaxValue;
LastTick = FirstTick;
+
+ Stat
+ = new Stat(
+ name,
+ string.Format("Last update of thread {0}", name),
+ "",
+ "ms",
+ "server",
+ "thread",
+ StatType.Pull,
+ MeasuresOfInterest.None,
+ stat => stat.Value = Environment.TickCount & Int32.MaxValue - LastTick,
+ StatVerbosity.Debug);
+
+ StatsManager.RegisterStat(Stat);
}
public ThreadWatchdogInfo(ThreadWatchdogInfo previousTwi)
@@ -100,6 +122,11 @@ namespace OpenSim.Framework.Monitoring
AlarmIfTimeout = previousTwi.AlarmIfTimeout;
AlarmMethod = previousTwi.AlarmMethod;
}
+
+ public void Cleanup()
+ {
+ StatsManager.DeregisterStat(Stat);
+ }
}
///
@@ -116,7 +143,7 @@ namespace OpenSim.Framework.Monitoring
get { return m_enabled; }
set
{
-// m_log.DebugFormat("[MEMORY WATCHDOG]: Setting MemoryWatchdog.Enabled to {0}", value);
+ // m_log.DebugFormat("[MEMORY WATCHDOG]: Setting MemoryWatchdog.Enabled to {0}", value);
if (value == m_enabled)
return;
@@ -132,9 +159,8 @@ namespace OpenSim.Framework.Monitoring
m_watchdogTimer.Enabled = m_enabled;
}
}
- private static bool m_enabled;
- private static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
+ private static bool m_enabled;
private static Dictionary m_threads;
private static System.Timers.Timer m_watchdogTimer;
@@ -155,57 +181,19 @@ namespace OpenSim.Framework.Monitoring
}
///
- /// Start a new thread that is tracked by the watchdog timer.
- ///
- /// The method that will be executed in a new thread
- /// A name to give to the new thread
- /// Priority to run the thread at
- /// True to run this thread as a background thread, otherwise false
- /// Trigger an alarm function is we have timed out
- /// The newly created Thread object
- public static Thread StartThread(
- ThreadStart start, string name, ThreadPriority priority, bool isBackground, bool alarmIfTimeout)
- {
- return StartThread(start, name, priority, isBackground, alarmIfTimeout, null, DEFAULT_WATCHDOG_TIMEOUT_MS);
- }
-
- ///
- /// Start a new thread that is tracked by the watchdog timer
+ /// Add a thread to the watchdog tracker.
///
- /// The method that will be executed in a new thread
- /// A name to give to the new thread
- /// Priority to run the thread at
- /// True to run this thread as a background
- /// thread, otherwise false
- /// Trigger an alarm function is we have timed out
- ///
- /// Alarm method to call if alarmIfTimeout is true and there is a timeout.
- /// Normally, this will just return some useful debugging information.
- ///
- /// Number of milliseconds to wait until we issue a warning about timeout.
- /// The newly created Thread object
- public static Thread StartThread(
- ThreadStart start, string name, ThreadPriority priority, bool isBackground,
- bool alarmIfTimeout, Func alarmMethod, int timeout)
+ /// Information about the thread.
+ /// Name of the thread.
+ /// If true then creation of thread is logged.
+ public static void AddThread(ThreadWatchdogInfo info, string name, bool log = true)
{
- Thread thread = new Thread(start);
- thread.Name = name;
- thread.Priority = priority;
- thread.IsBackground = isBackground;
-
- ThreadWatchdogInfo twi
- = new ThreadWatchdogInfo(thread, timeout)
- { AlarmIfTimeout = alarmIfTimeout, AlarmMethod = alarmMethod };
-
- m_log.DebugFormat(
- "[WATCHDOG]: Started tracking thread {0}, ID {1}", twi.Thread.Name, twi.Thread.ManagedThreadId);
+ if (log)
+ m_log.DebugFormat(
+ "[WATCHDOG]: Started tracking thread {0}, ID {1}", name, info.Thread.ManagedThreadId);
lock (m_threads)
- m_threads.Add(twi.Thread.ManagedThreadId, twi);
-
- thread.Start();
-
- return thread;
+ m_threads.Add(info.Thread.ManagedThreadId, info);
}
///
@@ -219,25 +207,28 @@ namespace OpenSim.Framework.Monitoring
///
/// Stops watchdog tracking on the current thread
///
+ /// If true then normal events in thread removal are not logged.
///
/// True if the thread was removed from the list of tracked
/// threads, otherwise false
///
- public static bool RemoveThread()
+ public static bool RemoveThread(bool log = true)
{
- return RemoveThread(Thread.CurrentThread.ManagedThreadId);
+ return RemoveThread(Thread.CurrentThread.ManagedThreadId, log);
}
- private static bool RemoveThread(int threadID)
+ private static bool RemoveThread(int threadID, bool log = true)
{
lock (m_threads)
{
ThreadWatchdogInfo twi;
if (m_threads.TryGetValue(threadID, out twi))
{
- m_log.DebugFormat(
- "[WATCHDOG]: Removing thread {0}, ID {1}", twi.Thread.Name, twi.Thread.ManagedThreadId);
+ if (log)
+ m_log.DebugFormat(
+ "[WATCHDOG]: Removing thread {0}, ID {1}", twi.Thread.Name, twi.Thread.ManagedThreadId);
+ twi.Cleanup();
m_threads.Remove(threadID);
return true;
@@ -293,7 +284,7 @@ namespace OpenSim.Framework.Monitoring
}
catch { }
}
-
+
///
/// Get currently watched threads for diagnostic purposes
///
@@ -380,6 +371,7 @@ namespace OpenSim.Framework.Monitoring
if (MemoryWatchdog.Enabled)
MemoryWatchdog.Update();
+ ChecksManager.CheckChecks();
StatsManager.RecordStats();
m_watchdogTimer.Start();
--
cgit v1.1