Fix "show threads" to show threads now being managed by OpenSim.Framework.Watchdog

viewer-2-initial-appearance
Justin Clark-Casey (justincc) 2010-09-14 22:24:11 +01:00
parent 095d400f5b
commit 609375bf37
2 changed files with 22 additions and 18 deletions

View File

@ -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);

View File

@ -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 { }
}
/// <summary>
/// Get currently watched threads for diagnostic purposes
/// </summary>
/// <returns></returns>
public static ThreadWatchdogInfo[] GetThreads()
{
return m_threads.Values.ToArray();
}
private static void WatchdogTimerElapsed(object sender, System.Timers.ElapsedEventArgs e)
{