From 609375bf3723b6bd33c22dff60176b5ba8f2f81c Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Tue, 14 Sep 2010 22:24:11 +0100
Subject: Fix "show threads" to show threads now being managed by
OpenSim.Framework.Watchdog
---
OpenSim/Framework/Servers/BaseOpenSimServer.cs | 26 ++++++++++----------------
OpenSim/Framework/Watchdog.cs | 14 ++++++++++++--
2 files changed, 22 insertions(+), 18 deletions(-)
(limited to 'OpenSim')
diff --git a/OpenSim/Framework/Servers/BaseOpenSimServer.cs b/OpenSim/Framework/Servers/BaseOpenSimServer.cs
index f0f8d01..cbab2db 100644
--- a/OpenSim/Framework/Servers/BaseOpenSimServer.cs
+++ b/OpenSim/Framework/Servers/BaseOpenSimServer.cs
@@ -37,6 +37,7 @@ using log4net;
using log4net.Appender;
using log4net.Core;
using log4net.Repository;
+using OpenSim.Framework;
using OpenSim.Framework.Console;
using OpenSim.Framework.Servers;
using OpenSim.Framework.Servers.HttpServer;
@@ -234,26 +235,19 @@ namespace OpenSim.Framework.Servers
protected string GetThreadsReport()
{
StringBuilder sb = new StringBuilder();
+ Watchdog.ThreadWatchdogInfo[] threads = Watchdog.GetThreads();
- ProcessThreadCollection threads = ThreadTracker.GetThreads();
- if (threads == null)
+ sb.Append(threads.Length + " threads are being tracked:" + Environment.NewLine);
+ foreach (Watchdog.ThreadWatchdogInfo twi in threads)
{
- sb.Append("OpenSim thread tracking is only enabled in DEBUG mode.");
+ Thread t = twi.Thread;
+
+ sb.Append(
+ "ID: " + t.ManagedThreadId + ", Name: " + t.Name + ", TimeRunning: "
+ + "Pri: " + t.Priority + ", State: " + t.ThreadState);
+ sb.Append(Environment.NewLine);
}
- else
- {
- sb.Append(threads.Count + " threads are being tracked:" + Environment.NewLine);
- foreach (ProcessThread t in threads)
- {
- sb.Append("ID: " + t.Id + ", TotalProcessorTime: " + t.TotalProcessorTime + ", TimeRunning: " +
- (DateTime.Now - t.StartTime) + ", Pri: " + t.CurrentPriority + ", State: " + t.ThreadState);
- if (t.ThreadState == System.Diagnostics.ThreadState.Wait)
- sb.Append(", Reason: " + t.WaitReason + Environment.NewLine);
- else
- sb.Append(Environment.NewLine);
- }
- }
int workers = 0, ports = 0, maxWorkers = 0, maxPorts = 0;
ThreadPool.GetAvailableThreads(out workers, out ports);
ThreadPool.GetMaxThreads(out maxWorkers, out maxPorts);
diff --git a/OpenSim/Framework/Watchdog.cs b/OpenSim/Framework/Watchdog.cs
index 5d46905..0f34e83 100644
--- a/OpenSim/Framework/Watchdog.cs
+++ b/OpenSim/Framework/Watchdog.cs
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
@@ -27,6 +27,7 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Threading;
using log4net;
@@ -43,7 +44,7 @@ namespace OpenSim.Framework
const int WATCHDOG_TIMEOUT_MS = 5000;
[System.Diagnostics.DebuggerDisplay("{Thread.Name}")]
- private class ThreadWatchdogInfo
+ public class ThreadWatchdogInfo
{
public Thread Thread;
public int LastTick;
@@ -149,6 +150,15 @@ namespace OpenSim.Framework
}
catch { }
}
+
+ ///
+ /// Get currently watched threads for diagnostic purposes
+ ///
+ ///
+ public static ThreadWatchdogInfo[] GetThreads()
+ {
+ return m_threads.Values.ToArray();
+ }
private static void WatchdogTimerElapsed(object sender, System.Timers.ElapsedEventArgs e)
{
--
cgit v1.1