diff options
author | Tedd Hansen | 2008-02-21 10:43:24 +0000 |
---|---|---|
committer | Tedd Hansen | 2008-02-21 10:43:24 +0000 |
commit | 7102ac77698f4bfd7406d6e8871db7b006c2cae2 (patch) | |
tree | 7253775d1a6ae64e2469b1ef79863aaebe83e1d1 | |
parent | Remove a couple compiler warnings. (diff) | |
download | opensim-SC_OLD-7102ac77698f4bfd7406d6e8871db7b006c2cae2.zip opensim-SC_OLD-7102ac77698f4bfd7406d6e8871db7b006c2cae2.tar.gz opensim-SC_OLD-7102ac77698f4bfd7406d6e8871db7b006c2cae2.tar.bz2 opensim-SC_OLD-7102ac77698f4bfd7406d6e8871db7b006c2cae2.tar.xz |
"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.
16 files changed, 149 insertions, 7 deletions
diff --git a/OpenSim/Framework/Communications/Cache/AssetCache.cs b/OpenSim/Framework/Communications/Cache/AssetCache.cs index 8f8e362..15b52b0 100644 --- a/OpenSim/Framework/Communications/Cache/AssetCache.cs +++ b/OpenSim/Framework/Communications/Cache/AssetCache.cs | |||
@@ -171,6 +171,7 @@ namespace OpenSim.Framework.Communications.Cache | |||
171 | m_assetCacheThread.Name = "AssetCacheThread"; | 171 | m_assetCacheThread.Name = "AssetCacheThread"; |
172 | m_assetCacheThread.IsBackground = true; | 172 | m_assetCacheThread.IsBackground = true; |
173 | m_assetCacheThread.Start(); | 173 | m_assetCacheThread.Start(); |
174 | OpenSim.Framework.ThreadTracker.Add(m_assetCacheThread); | ||
174 | } | 175 | } |
175 | 176 | ||
176 | /// <summary> | 177 | /// <summary> |
diff --git a/OpenSim/Framework/Communications/Cache/AssetServerBase.cs b/OpenSim/Framework/Communications/Cache/AssetServerBase.cs index a3530bd..cae4231 100644 --- a/OpenSim/Framework/Communications/Cache/AssetServerBase.cs +++ b/OpenSim/Framework/Communications/Cache/AssetServerBase.cs | |||
@@ -101,6 +101,7 @@ namespace OpenSim.Framework.Communications.Cache | |||
101 | m_localAssetServerThread.Name = "LocalAssetServerThread"; | 101 | m_localAssetServerThread.Name = "LocalAssetServerThread"; |
102 | m_localAssetServerThread.IsBackground = true; | 102 | m_localAssetServerThread.IsBackground = true; |
103 | m_localAssetServerThread.Start(); | 103 | m_localAssetServerThread.Start(); |
104 | OpenSim.Framework.ThreadTracker.Add(m_localAssetServerThread); | ||
104 | } | 105 | } |
105 | 106 | ||
106 | private void RunRequests() | 107 | private void RunRequests() |
diff --git a/OpenSim/Framework/Servers/BaseHttpServer.cs b/OpenSim/Framework/Servers/BaseHttpServer.cs index 662eefd..dc540f9 100644 --- a/OpenSim/Framework/Servers/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/BaseHttpServer.cs | |||
@@ -550,6 +550,7 @@ namespace OpenSim.Framework.Servers | |||
550 | m_workerThread.Name = "HttpThread"; | 550 | m_workerThread.Name = "HttpThread"; |
551 | m_workerThread.IsBackground = true; | 551 | m_workerThread.IsBackground = true; |
552 | m_workerThread.Start(); | 552 | m_workerThread.Start(); |
553 | OpenSim.Framework.ThreadTracker.Add(m_workerThread); | ||
553 | } | 554 | } |
554 | 555 | ||
555 | private void StartHTTP() | 556 | private void StartHTTP() |
diff --git a/OpenSim/Framework/ThreadTracker.cs b/OpenSim/Framework/ThreadTracker.cs new file mode 100644 index 0000000..42e3879 --- /dev/null +++ b/OpenSim/Framework/ThreadTracker.cs | |||
@@ -0,0 +1,106 @@ | |||
1 | using System; | ||
2 | using System.Collections; | ||
3 | using System.Collections.Generic; | ||
4 | using System.Text; | ||
5 | using System.Threading; | ||
6 | |||
7 | namespace OpenSim.Framework | ||
8 | { | ||
9 | public static class ThreadTracker | ||
10 | { | ||
11 | public static List<ThreadTrackerItem> m_Threads; | ||
12 | public static System.Threading.Thread ThreadTrackerThread; | ||
13 | private static readonly long ThreadTimeout = 30 * 10000000; | ||
14 | |||
15 | static ThreadTracker() | ||
16 | { | ||
17 | #if DEBUG | ||
18 | m_Threads = new List<ThreadTrackerItem>(); | ||
19 | ThreadTrackerThread = new Thread(ThreadTrackerThreadLoop); | ||
20 | ThreadTrackerThread.Name = "ThreadTrackerThread"; | ||
21 | ThreadTrackerThread.IsBackground = true; | ||
22 | ThreadTrackerThread.Priority = System.Threading.ThreadPriority.BelowNormal; | ||
23 | ThreadTrackerThread.Start(); | ||
24 | #endif | ||
25 | } | ||
26 | |||
27 | private static void ThreadTrackerThreadLoop() | ||
28 | { | ||
29 | while (true) | ||
30 | { | ||
31 | Thread.Sleep(5000); | ||
32 | CleanUp(); | ||
33 | } | ||
34 | } | ||
35 | |||
36 | public static void Add(System.Threading.Thread thread) | ||
37 | { | ||
38 | #if DEBUG | ||
39 | lock (m_Threads) | ||
40 | { | ||
41 | ThreadTrackerItem tti = new ThreadTrackerItem(); | ||
42 | tti.Thread = thread; | ||
43 | tti.LastSeenActive = DateTime.Now.Ticks; | ||
44 | m_Threads.Add(tti); | ||
45 | } | ||
46 | #endif | ||
47 | } | ||
48 | |||
49 | public static void Remove(System.Threading.Thread thread) | ||
50 | { | ||
51 | #if DEBUG | ||
52 | lock (m_Threads) | ||
53 | { | ||
54 | foreach (ThreadTrackerItem tti in new ArrayList(m_Threads)) | ||
55 | { | ||
56 | if (tti.Thread == thread) | ||
57 | m_Threads.Remove(tti); | ||
58 | } | ||
59 | } | ||
60 | #endif | ||
61 | } | ||
62 | |||
63 | public static void CleanUp() | ||
64 | { | ||
65 | lock (m_Threads) | ||
66 | { | ||
67 | foreach (ThreadTrackerItem tti in new ArrayList(m_Threads)) | ||
68 | { | ||
69 | if (tti.Thread.IsAlive) | ||
70 | { | ||
71 | // Its active | ||
72 | tti.LastSeenActive = DateTime.Now.Ticks; | ||
73 | } | ||
74 | else | ||
75 | { | ||
76 | // Its not active -- if its expired then remove it | ||
77 | if (tti.LastSeenActive + ThreadTimeout < DateTime.Now.Ticks) | ||
78 | m_Threads.Remove(tti); | ||
79 | } | ||
80 | } | ||
81 | } | ||
82 | } | ||
83 | |||
84 | public static List<Thread> GetThreads() | ||
85 | { | ||
86 | if (m_Threads == null) | ||
87 | return null; | ||
88 | |||
89 | List<Thread> threads = new List<Thread>(); | ||
90 | lock (m_Threads) | ||
91 | { | ||
92 | foreach (ThreadTrackerItem tti in new ArrayList(m_Threads)) | ||
93 | { | ||
94 | threads.Add(tti.Thread); | ||
95 | } | ||
96 | } | ||
97 | return threads; | ||
98 | } | ||
99 | |||
100 | public class ThreadTrackerItem | ||
101 | { | ||
102 | public System.Threading.Thread Thread; | ||
103 | public long LastSeenActive; | ||
104 | } | ||
105 | } | ||
106 | } | ||
diff --git a/OpenSim/Grid/ScriptServer/ScriptServer/RegionCommManager.cs b/OpenSim/Grid/ScriptServer/ScriptServer/RegionCommManager.cs index cdddcc2..f37d289 100644 --- a/OpenSim/Grid/ScriptServer/ScriptServer/RegionCommManager.cs +++ b/OpenSim/Grid/ScriptServer/ScriptServer/RegionCommManager.cs | |||
@@ -61,6 +61,7 @@ namespace OpenSim.Grid.ScriptServer | |||
61 | listenThread.Name = "ListenThread"; | 61 | listenThread.Name = "ListenThread"; |
62 | listenThread.IsBackground = true; | 62 | listenThread.IsBackground = true; |
63 | listenThread.Start(); | 63 | listenThread.Start(); |
64 | OpenSim.Framework.ThreadTracker.Add(listenThread); | ||
64 | } | 65 | } |
65 | 66 | ||
66 | /// <summary> | 67 | /// <summary> |
diff --git a/OpenSim/Region/Application/OpenSimMain.cs b/OpenSim/Region/Application/OpenSimMain.cs index fc739d9..59f7c63 100644 --- a/OpenSim/Region/Application/OpenSimMain.cs +++ b/OpenSim/Region/Application/OpenSimMain.cs | |||
@@ -754,15 +754,30 @@ namespace OpenSim | |||
754 | break; | 754 | break; |
755 | 755 | ||
756 | case "threads": | 756 | case "threads": |
757 | m_console.Notice("THREAD", Process.GetCurrentProcess().Threads.Count + " threads running:"); | 757 | //m_console.Notice("THREAD", Process.GetCurrentProcess().Threads.Count + " threads running:"); |
758 | int _tc = 0; | 758 | //int _tc = 0; |
759 | 759 | ||
760 | foreach (ProcessThread pt in Process.GetCurrentProcess().Threads) | 760 | //foreach (ProcessThread pt in Process.GetCurrentProcess().Threads) |
761 | //{ | ||
762 | // _tc++; | ||
763 | // m_console.Notice("THREAD", _tc + ": ID: " + pt.Id + ", Started: " + pt.StartTime.ToString() + ", CPU time: " + pt.TotalProcessorTime + ", Pri: " + pt.BasePriority.ToString() + ", State: " + pt.ThreadState.ToString()); | ||
764 | |||
765 | //} | ||
766 | List<Thread> threads = OpenSim.Framework.ThreadTracker.GetThreads(); | ||
767 | if (threads == null) | ||
768 | { | ||
769 | m_console.Notice("THREAD", "Thread tracking is only enabled in DEBUG mode."); | ||
770 | } | ||
771 | else | ||
772 | { | ||
773 | int _tc = 0; | ||
774 | m_console.Notice("THREAD", threads.Count + " threads are being tracked:"); | ||
775 | foreach (Thread t in threads) | ||
761 | { | 776 | { |
762 | _tc++; | 777 | _tc++; |
763 | m_console.Notice("THREAD", _tc + ": ID: " + pt.Id + ", Started: " + pt.StartTime.ToString() + ", CPU time: " + pt.TotalProcessorTime + ", Pri: " + pt.BasePriority.ToString() + ", State: " + pt.ThreadState.ToString()); | 778 | m_console.Notice("THREAD", _tc + ": ID: " + t.ManagedThreadId.ToString() + ", Name: " + t.Name + ", Alive: " + t.IsAlive.ToString() + ", Pri: " + t.Priority.ToString() + ", State: " + t.ThreadState.ToString()); |
764 | |||
765 | } | 779 | } |
780 | } | ||
766 | 781 | ||
767 | 782 | ||
768 | break; | 783 | break; |
diff --git a/OpenSim/Region/ClientStack/ClientView.cs b/OpenSim/Region/ClientStack/ClientView.cs index 47cb582..848a08d 100644 --- a/OpenSim/Region/ClientStack/ClientView.cs +++ b/OpenSim/Region/ClientStack/ClientView.cs | |||
@@ -228,6 +228,7 @@ namespace OpenSim.Region.ClientStack | |||
228 | m_clientThread.Name = "ClientThread"; | 228 | m_clientThread.Name = "ClientThread"; |
229 | m_clientThread.IsBackground = true; | 229 | m_clientThread.IsBackground = true; |
230 | m_clientThread.Start(); | 230 | m_clientThread.Start(); |
231 | OpenSim.Framework.ThreadTracker.Add(m_clientThread); | ||
231 | } | 232 | } |
232 | 233 | ||
233 | public void SetDebug(int newDebug) | 234 | public void SetDebug(int newDebug) |
diff --git a/OpenSim/Region/Environment/Modules/ChatModule.cs b/OpenSim/Region/Environment/Modules/ChatModule.cs index 0510ad6..c146941 100644 --- a/OpenSim/Region/Environment/Modules/ChatModule.cs +++ b/OpenSim/Region/Environment/Modules/ChatModule.cs | |||
@@ -113,7 +113,10 @@ namespace OpenSim.Region.Environment.Modules | |||
113 | m_irc_connector.Name = "IRCConnectorThread"; | 113 | m_irc_connector.Name = "IRCConnectorThread"; |
114 | m_irc_connector.IsBackground = true; | 114 | m_irc_connector.IsBackground = true; |
115 | } | 115 | } |
116 | if (!m_irc_connector.IsAlive) { m_irc_connector.Start(); } | 116 | if (!m_irc_connector.IsAlive) { |
117 | m_irc_connector.Start(); | ||
118 | OpenSim.Framework.ThreadTracker.Add(m_irc_connector); | ||
119 | } | ||
117 | } | 120 | } |
118 | catch (Exception ex) | 121 | catch (Exception ex) |
119 | { | 122 | { |
@@ -260,7 +263,10 @@ namespace OpenSim.Region.Environment.Modules | |||
260 | m_irc_connector.Name = "IRCConnectorThread"; | 263 | m_irc_connector.Name = "IRCConnectorThread"; |
261 | m_irc_connector.IsBackground = true; | 264 | m_irc_connector.IsBackground = true; |
262 | } | 265 | } |
263 | if (!m_irc_connector.IsAlive) { m_irc_connector.Start(); } | 266 | if (!m_irc_connector.IsAlive) { |
267 | m_irc_connector.Start(); | ||
268 | OpenSim.Framework.ThreadTracker.Add(m_irc_connector); | ||
269 | } | ||
264 | } | 270 | } |
265 | catch (Exception ex) | 271 | catch (Exception ex) |
266 | { | 272 | { |
@@ -421,11 +427,13 @@ namespace OpenSim.Region.Environment.Modules | |||
421 | pingSender.Name = "PingSenderThread"; | 427 | pingSender.Name = "PingSenderThread"; |
422 | pingSender.IsBackground = true; | 428 | pingSender.IsBackground = true; |
423 | pingSender.Start(); | 429 | pingSender.Start(); |
430 | OpenSim.Framework.ThreadTracker.Add(pingSender); | ||
424 | 431 | ||
425 | listener = new Thread(new ThreadStart(ListenerRun)); | 432 | listener = new Thread(new ThreadStart(ListenerRun)); |
426 | listener.Name = "IRCChatModuleListenerThread"; | 433 | listener.Name = "IRCChatModuleListenerThread"; |
427 | listener.IsBackground = true; | 434 | listener.IsBackground = true; |
428 | listener.Start(); | 435 | listener.Start(); |
436 | OpenSim.Framework.ThreadTracker.Add(listener); | ||
429 | 437 | ||
430 | m_writer.WriteLine(m_user); | 438 | m_writer.WriteLine(m_user); |
431 | m_writer.Flush(); | 439 | m_writer.Flush(); |
diff --git a/OpenSim/Region/Environment/Modules/ScriptsHttpRequests.cs b/OpenSim/Region/Environment/Modules/ScriptsHttpRequests.cs index 47dd250..54a3bc0 100644 --- a/OpenSim/Region/Environment/Modules/ScriptsHttpRequests.cs +++ b/OpenSim/Region/Environment/Modules/ScriptsHttpRequests.cs | |||
@@ -287,6 +287,7 @@ namespace OpenSim.Region.Environment.Modules | |||
287 | httpThread.IsBackground = true; | 287 | httpThread.IsBackground = true; |
288 | finished = false; | 288 | finished = false; |
289 | httpThread.Start(); | 289 | httpThread.Start(); |
290 | OpenSim.Framework.ThreadTracker.Add(httpThread); | ||
290 | } | 291 | } |
291 | 292 | ||
292 | /* | 293 | /* |
diff --git a/OpenSim/Region/Environment/Modules/TextureDownloadModule.cs b/OpenSim/Region/Environment/Modules/TextureDownloadModule.cs index ecf44a6..c773f9e 100644 --- a/OpenSim/Region/Environment/Modules/TextureDownloadModule.cs +++ b/OpenSim/Region/Environment/Modules/TextureDownloadModule.cs | |||
@@ -75,6 +75,7 @@ namespace OpenSim.Region.Environment.Modules | |||
75 | m_thread.Name = "ProcessTextureSenderThread"; | 75 | m_thread.Name = "ProcessTextureSenderThread"; |
76 | m_thread.IsBackground = true; | 76 | m_thread.IsBackground = true; |
77 | m_thread.Start(); | 77 | m_thread.Start(); |
78 | OpenSim.Framework.ThreadTracker.Add(m_thread); | ||
78 | } | 79 | } |
79 | 80 | ||
80 | if (!m_scenes.Contains(scene)) | 81 | if (!m_scenes.Contains(scene)) |
diff --git a/OpenSim/Region/Environment/Modules/XMLRPCModule.cs b/OpenSim/Region/Environment/Modules/XMLRPCModule.cs index 3cdb576..6294a49 100644 --- a/OpenSim/Region/Environment/Modules/XMLRPCModule.cs +++ b/OpenSim/Region/Environment/Modules/XMLRPCModule.cs | |||
@@ -584,6 +584,7 @@ namespace OpenSim.Region.Environment.Modules | |||
584 | httpThread.IsBackground = true; | 584 | httpThread.IsBackground = true; |
585 | finished = false; | 585 | finished = false; |
586 | httpThread.Start(); | 586 | httpThread.Start(); |
587 | OpenSim.Framework.ThreadTracker.Add(httpThread); | ||
587 | 588 | ||
588 | return reqID; | 589 | return reqID; |
589 | 590 | ||
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncLSLCommandManager.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncLSLCommandManager.cs index 222b8f2..81e3438 100644 --- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncLSLCommandManager.cs +++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncLSLCommandManager.cs | |||
@@ -57,6 +57,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
57 | cmdHandlerThread.Priority = ThreadPriority.BelowNormal; | 57 | cmdHandlerThread.Priority = ThreadPriority.BelowNormal; |
58 | cmdHandlerThread.IsBackground = true; | 58 | cmdHandlerThread.IsBackground = true; |
59 | cmdHandlerThread.Start(); | 59 | cmdHandlerThread.Start(); |
60 | OpenSim.Framework.ThreadTracker.Add(cmdHandlerThread); | ||
60 | } | 61 | } |
61 | 62 | ||
62 | public void ReadConfig() | 63 | public void ReadConfig() |
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueThreadClass.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueThreadClass.cs index d4db935..6f96654 100644 --- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueThreadClass.cs +++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueThreadClass.cs | |||
@@ -117,6 +117,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
117 | EventQueueThread.Priority = MyThreadPriority; | 117 | EventQueueThread.Priority = MyThreadPriority; |
118 | EventQueueThread.Name = "EventQueueManagerThread_" + ThreadCount; | 118 | EventQueueThread.Name = "EventQueueManagerThread_" + ThreadCount; |
119 | EventQueueThread.Start(); | 119 | EventQueueThread.Start(); |
120 | OpenSim.Framework.ThreadTracker.Add(EventQueueThread); | ||
120 | 121 | ||
121 | // Look at this... Don't you wish everyone did that solid coding everywhere? :P | 122 | // Look at this... Don't you wish everyone did that solid coding everywhere? :P |
122 | if (ThreadCount == int.MaxValue) | 123 | if (ThreadCount == int.MaxValue) |
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/MaintenanceThread.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/MaintenanceThread.cs index 47446a3..4776ffe 100644 --- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/MaintenanceThread.cs +++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/MaintenanceThread.cs | |||
@@ -78,6 +78,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
78 | MaintenanceThreadThread.Name = "ScriptMaintenanceThread"; | 78 | MaintenanceThreadThread.Name = "ScriptMaintenanceThread"; |
79 | MaintenanceThreadThread.IsBackground = true; | 79 | MaintenanceThreadThread.IsBackground = true; |
80 | MaintenanceThreadThread.Start(); | 80 | MaintenanceThreadThread.Start(); |
81 | OpenSim.Framework.ThreadTracker.Add(MaintenanceThreadThread); | ||
81 | } | 82 | } |
82 | } | 83 | } |
83 | 84 | ||
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptManager.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptManager.cs index 43ff4ac..684d133 100644 --- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptManager.cs +++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptManager.cs | |||
@@ -160,6 +160,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
160 | t.IsBackground = true; | 160 | t.IsBackground = true; |
161 | t.Priority = ThreadPriority.Normal; | 161 | t.Priority = ThreadPriority.Normal; |
162 | t.Start(); | 162 | t.Start(); |
163 | OpenSim.Framework.ThreadTracker.Add(t); | ||
163 | return t; | 164 | return t; |
164 | } | 165 | } |
165 | 166 | ||
diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs index 1dc1dc1..36f3d7f 100644 --- a/OpenSim/Tools/pCampBot/BotManager.cs +++ b/OpenSim/Tools/pCampBot/BotManager.cs | |||
@@ -118,6 +118,7 @@ namespace pCampBot | |||
118 | m_td[pos].IsBackground = true; | 118 | m_td[pos].IsBackground = true; |
119 | m_td[pos].Start(); | 119 | m_td[pos].Start(); |
120 | m_lBot.Add(pb); | 120 | m_lBot.Add(pb); |
121 | OpenSim.Framework.ThreadTracker.Add(m_td[pos]); | ||
121 | } | 122 | } |
122 | 123 | ||
123 | /// <summary> | 124 | /// <summary> |