"threads" command now works. I've added manual tracking of threads (only if compiled in DEBUG mode)... Its ugly and even requires a separate thread to track the treads, but it will be very valuable in debugging.

ThreadPoolClientBranch
Tedd Hansen 2008-02-21 10:43:24 +00:00
parent 4a621d106c
commit 7102ac7769
16 changed files with 149 additions and 7 deletions

View File

@ -171,6 +171,7 @@ namespace OpenSim.Framework.Communications.Cache
m_assetCacheThread.Name = "AssetCacheThread";
m_assetCacheThread.IsBackground = true;
m_assetCacheThread.Start();
OpenSim.Framework.ThreadTracker.Add(m_assetCacheThread);
}
/// <summary>

View File

@ -101,6 +101,7 @@ namespace OpenSim.Framework.Communications.Cache
m_localAssetServerThread.Name = "LocalAssetServerThread";
m_localAssetServerThread.IsBackground = true;
m_localAssetServerThread.Start();
OpenSim.Framework.ThreadTracker.Add(m_localAssetServerThread);
}
private void RunRequests()

View File

@ -550,6 +550,7 @@ namespace OpenSim.Framework.Servers
m_workerThread.Name = "HttpThread";
m_workerThread.IsBackground = true;
m_workerThread.Start();
OpenSim.Framework.ThreadTracker.Add(m_workerThread);
}
private void StartHTTP()

View File

@ -0,0 +1,106 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace OpenSim.Framework
{
public static class ThreadTracker
{
public static List<ThreadTrackerItem> m_Threads;
public static System.Threading.Thread ThreadTrackerThread;
private static readonly long ThreadTimeout = 30 * 10000000;
static ThreadTracker()
{
#if DEBUG
m_Threads = new List<ThreadTrackerItem>();
ThreadTrackerThread = new Thread(ThreadTrackerThreadLoop);
ThreadTrackerThread.Name = "ThreadTrackerThread";
ThreadTrackerThread.IsBackground = true;
ThreadTrackerThread.Priority = System.Threading.ThreadPriority.BelowNormal;
ThreadTrackerThread.Start();
#endif
}
private static void ThreadTrackerThreadLoop()
{
while (true)
{
Thread.Sleep(5000);
CleanUp();
}
}
public static void Add(System.Threading.Thread thread)
{
#if DEBUG
lock (m_Threads)
{
ThreadTrackerItem tti = new ThreadTrackerItem();
tti.Thread = thread;
tti.LastSeenActive = DateTime.Now.Ticks;
m_Threads.Add(tti);
}
#endif
}
public static void Remove(System.Threading.Thread thread)
{
#if DEBUG
lock (m_Threads)
{
foreach (ThreadTrackerItem tti in new ArrayList(m_Threads))
{
if (tti.Thread == thread)
m_Threads.Remove(tti);
}
}
#endif
}
public static void CleanUp()
{
lock (m_Threads)
{
foreach (ThreadTrackerItem tti in new ArrayList(m_Threads))
{
if (tti.Thread.IsAlive)
{
// Its active
tti.LastSeenActive = DateTime.Now.Ticks;
}
else
{
// Its not active -- if its expired then remove it
if (tti.LastSeenActive + ThreadTimeout < DateTime.Now.Ticks)
m_Threads.Remove(tti);
}
}
}
}
public static List<Thread> GetThreads()
{
if (m_Threads == null)
return null;
List<Thread> threads = new List<Thread>();
lock (m_Threads)
{
foreach (ThreadTrackerItem tti in new ArrayList(m_Threads))
{
threads.Add(tti.Thread);
}
}
return threads;
}
public class ThreadTrackerItem
{
public System.Threading.Thread Thread;
public long LastSeenActive;
}
}
}

View File

@ -61,6 +61,7 @@ namespace OpenSim.Grid.ScriptServer
listenThread.Name = "ListenThread";
listenThread.IsBackground = true;
listenThread.Start();
OpenSim.Framework.ThreadTracker.Add(listenThread);
}
/// <summary>

View File

@ -754,14 +754,29 @@ namespace OpenSim
break;
case "threads":
m_console.Notice("THREAD", Process.GetCurrentProcess().Threads.Count + " threads running:");
int _tc = 0;
//m_console.Notice("THREAD", Process.GetCurrentProcess().Threads.Count + " threads running:");
//int _tc = 0;
foreach (ProcessThread pt in Process.GetCurrentProcess().Threads)
//foreach (ProcessThread pt in Process.GetCurrentProcess().Threads)
//{
// _tc++;
// m_console.Notice("THREAD", _tc + ": ID: " + pt.Id + ", Started: " + pt.StartTime.ToString() + ", CPU time: " + pt.TotalProcessorTime + ", Pri: " + pt.BasePriority.ToString() + ", State: " + pt.ThreadState.ToString());
//}
List<Thread> threads = OpenSim.Framework.ThreadTracker.GetThreads();
if (threads == null)
{
m_console.Notice("THREAD", "Thread tracking is only enabled in DEBUG mode.");
}
else
{
int _tc = 0;
m_console.Notice("THREAD", threads.Count + " threads are being tracked:");
foreach (Thread t in threads)
{
_tc++;
m_console.Notice("THREAD", _tc + ": ID: " + pt.Id + ", Started: " + pt.StartTime.ToString() + ", CPU time: " + pt.TotalProcessorTime + ", Pri: " + pt.BasePriority.ToString() + ", State: " + pt.ThreadState.ToString());
m_console.Notice("THREAD", _tc + ": ID: " + t.ManagedThreadId.ToString() + ", Name: " + t.Name + ", Alive: " + t.IsAlive.ToString() + ", Pri: " + t.Priority.ToString() + ", State: " + t.ThreadState.ToString());
}
}

View File

@ -228,6 +228,7 @@ namespace OpenSim.Region.ClientStack
m_clientThread.Name = "ClientThread";
m_clientThread.IsBackground = true;
m_clientThread.Start();
OpenSim.Framework.ThreadTracker.Add(m_clientThread);
}
public void SetDebug(int newDebug)

View File

@ -113,7 +113,10 @@ namespace OpenSim.Region.Environment.Modules
m_irc_connector.Name = "IRCConnectorThread";
m_irc_connector.IsBackground = true;
}
if (!m_irc_connector.IsAlive) { m_irc_connector.Start(); }
if (!m_irc_connector.IsAlive) {
m_irc_connector.Start();
OpenSim.Framework.ThreadTracker.Add(m_irc_connector);
}
}
catch (Exception ex)
{
@ -260,7 +263,10 @@ namespace OpenSim.Region.Environment.Modules
m_irc_connector.Name = "IRCConnectorThread";
m_irc_connector.IsBackground = true;
}
if (!m_irc_connector.IsAlive) { m_irc_connector.Start(); }
if (!m_irc_connector.IsAlive) {
m_irc_connector.Start();
OpenSim.Framework.ThreadTracker.Add(m_irc_connector);
}
}
catch (Exception ex)
{
@ -421,11 +427,13 @@ namespace OpenSim.Region.Environment.Modules
pingSender.Name = "PingSenderThread";
pingSender.IsBackground = true;
pingSender.Start();
OpenSim.Framework.ThreadTracker.Add(pingSender);
listener = new Thread(new ThreadStart(ListenerRun));
listener.Name = "IRCChatModuleListenerThread";
listener.IsBackground = true;
listener.Start();
OpenSim.Framework.ThreadTracker.Add(listener);
m_writer.WriteLine(m_user);
m_writer.Flush();

View File

@ -287,6 +287,7 @@ namespace OpenSim.Region.Environment.Modules
httpThread.IsBackground = true;
finished = false;
httpThread.Start();
OpenSim.Framework.ThreadTracker.Add(httpThread);
}
/*

View File

@ -75,6 +75,7 @@ namespace OpenSim.Region.Environment.Modules
m_thread.Name = "ProcessTextureSenderThread";
m_thread.IsBackground = true;
m_thread.Start();
OpenSim.Framework.ThreadTracker.Add(m_thread);
}
if (!m_scenes.Contains(scene))

View File

@ -584,6 +584,7 @@ namespace OpenSim.Region.Environment.Modules
httpThread.IsBackground = true;
finished = false;
httpThread.Start();
OpenSim.Framework.ThreadTracker.Add(httpThread);
return reqID;

View File

@ -57,6 +57,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
cmdHandlerThread.Priority = ThreadPriority.BelowNormal;
cmdHandlerThread.IsBackground = true;
cmdHandlerThread.Start();
OpenSim.Framework.ThreadTracker.Add(cmdHandlerThread);
}
public void ReadConfig()

View File

@ -117,6 +117,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
EventQueueThread.Priority = MyThreadPriority;
EventQueueThread.Name = "EventQueueManagerThread_" + ThreadCount;
EventQueueThread.Start();
OpenSim.Framework.ThreadTracker.Add(EventQueueThread);
// Look at this... Don't you wish everyone did that solid coding everywhere? :P
if (ThreadCount == int.MaxValue)

View File

@ -78,6 +78,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
MaintenanceThreadThread.Name = "ScriptMaintenanceThread";
MaintenanceThreadThread.IsBackground = true;
MaintenanceThreadThread.Start();
OpenSim.Framework.ThreadTracker.Add(MaintenanceThreadThread);
}
}

View File

@ -160,6 +160,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
t.IsBackground = true;
t.Priority = ThreadPriority.Normal;
t.Start();
OpenSim.Framework.ThreadTracker.Add(t);
return t;
}

View File

@ -118,6 +118,7 @@ namespace pCampBot
m_td[pos].IsBackground = true;
m_td[pos].Start();
m_lBot.Add(pb);
OpenSim.Framework.ThreadTracker.Add(m_td[pos]);
}
/// <summary>