aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers/BaseOpenSimServer.cs
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2012-11-23 04:40:49 +0000
committerJustin Clark-Casey (justincc)2012-11-23 04:40:49 +0000
commit999cb4b20cc20a24c7b9fbce4c31b13f8bf36cb5 (patch)
treea73ecf998adad5920e94c570743e6897ae1a87f4 /OpenSim/Framework/Servers/BaseOpenSimServer.cs
parentMake "force gc" console command available across all servers (diff)
downloadopensim-SC-999cb4b20cc20a24c7b9fbce4c31b13f8bf36cb5.zip
opensim-SC-999cb4b20cc20a24c7b9fbce4c31b13f8bf36cb5.tar.gz
opensim-SC-999cb4b20cc20a24c7b9fbce4c31b13f8bf36cb5.tar.bz2
opensim-SC-999cb4b20cc20a24c7b9fbce4c31b13f8bf36cb5.tar.xz
Make "show threads" and "thread abort" console commands available on all servers
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Servers/BaseOpenSimServer.cs103
1 files changed, 1 insertions, 102 deletions
diff --git a/OpenSim/Framework/Servers/BaseOpenSimServer.cs b/OpenSim/Framework/Servers/BaseOpenSimServer.cs
index 3f66ab5..c0dc907 100644
--- a/OpenSim/Framework/Servers/BaseOpenSimServer.cs
+++ b/OpenSim/Framework/Servers/BaseOpenSimServer.cs
@@ -27,7 +27,6 @@
27 27
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Diagnostics;
31using System.IO; 30using System.IO;
32using System.Reflection; 31using System.Reflection;
33using System.Text; 32using System.Text;
@@ -99,19 +98,6 @@ namespace OpenSim.Framework.Servers
99 m_console.Commands.AddCommand("General", false, "shutdown", 98 m_console.Commands.AddCommand("General", false, "shutdown",
100 "shutdown", 99 "shutdown",
101 "Quit the application", HandleQuit); 100 "Quit the application", HandleQuit);
102
103 m_console.Commands.AddCommand("General", false, "show threads",
104 "show threads",
105 "Show thread status", HandleShow);
106
107 m_console.Commands.AddCommand("General", false, "threads abort",
108 "threads abort <thread-id>",
109 "Abort a managed thread. Use \"show threads\" to find possible threads.", HandleThreadsAbort);
110
111 m_console.Commands.AddCommand("General", false, "threads show",
112 "threads show",
113 "Show thread status. Synonym for \"show threads\"",
114 (string module, string[] args) => Notice(GetThreadsReport()));
115 } 101 }
116 102
117 /// <summary> 103 /// <summary>
@@ -144,54 +130,6 @@ namespace OpenSim.Framework.Servers
144 } 130 }
145 131
146 /// <summary> 132 /// <summary>
147 /// Get a report about the registered threads in this server.
148 /// </summary>
149 protected string GetThreadsReport()
150 {
151 // This should be a constant field.
152 string reportFormat = "{0,6} {1,35} {2,16} {3,13} {4,10} {5,30}";
153
154 StringBuilder sb = new StringBuilder();
155 Watchdog.ThreadWatchdogInfo[] threads = Watchdog.GetThreadsInfo();
156
157 sb.Append(threads.Length + " threads are being tracked:" + Environment.NewLine);
158
159 int timeNow = Environment.TickCount & Int32.MaxValue;
160
161 sb.AppendFormat(reportFormat, "ID", "NAME", "LAST UPDATE (MS)", "LIFETIME (MS)", "PRIORITY", "STATE");
162 sb.Append(Environment.NewLine);
163
164 foreach (Watchdog.ThreadWatchdogInfo twi in threads)
165 {
166 Thread t = twi.Thread;
167
168 sb.AppendFormat(
169 reportFormat,
170 t.ManagedThreadId,
171 t.Name,
172 timeNow - twi.LastTick,
173 timeNow - twi.FirstTick,
174 t.Priority,
175 t.ThreadState);
176
177 sb.Append("\n");
178 }
179
180 sb.Append("\n");
181
182 // For some reason mono 2.6.7 returns an empty threads set! Not going to confuse people by reporting
183 // zero active threads.
184 int totalThreads = Process.GetCurrentProcess().Threads.Count;
185 if (totalThreads > 0)
186 sb.AppendFormat("Total threads active: {0}\n\n", totalThreads);
187
188 sb.Append("Main threadpool (excluding script engine pools)\n");
189 sb.Append(Util.GetThreadPoolReport());
190
191 return sb.ToString();
192 }
193
194 /// <summary>
195 /// Performs initialisation of the scene, such as loading configuration from disk. 133 /// Performs initialisation of the scene, such as loading configuration from disk.
196 /// </summary> 134 /// </summary>
197 public virtual void Startup() 135 public virtual void Startup()
@@ -231,46 +169,7 @@ namespace OpenSim.Framework.Servers
231 private void HandleQuit(string module, string[] args) 169 private void HandleQuit(string module, string[] args)
232 { 170 {
233 Shutdown(); 171 Shutdown();
234 } 172 }
235
236 public override void HandleShow(string module, string[] cmd)
237 {
238 base.HandleShow(module, cmd);
239
240 List<string> args = new List<string>(cmd);
241
242 args.RemoveAt(0);
243
244 string[] showParams = args.ToArray();
245
246 switch (showParams[0])
247 {
248 case "threads":
249 Notice(GetThreadsReport());
250 break;
251 }
252 }
253
254 public virtual void HandleThreadsAbort(string module, string[] cmd)
255 {
256 if (cmd.Length != 3)
257 {
258 MainConsole.Instance.Output("Usage: threads abort <thread-id>");
259 return;
260 }
261
262 int threadId;
263 if (!int.TryParse(cmd[2], out threadId))
264 {
265 MainConsole.Instance.Output("ERROR: Thread id must be an integer");
266 return;
267 }
268
269 if (Watchdog.AbortThread(threadId))
270 MainConsole.Instance.OutputFormat("Aborted thread with id {0}", threadId);
271 else
272 MainConsole.Instance.OutputFormat("ERROR - Thread with id {0} not found in managed threads", threadId);
273 }
274 173
275 public string osSecret { 174 public string osSecret {
276 // Secret uuid for the simulator 175 // Secret uuid for the simulator