diff options
Diffstat (limited to 'OpenSim/Framework/Servers/ServerBase.cs')
-rw-r--r-- | OpenSim/Framework/Servers/ServerBase.cs | 100 |
1 files changed, 99 insertions, 1 deletions
diff --git a/OpenSim/Framework/Servers/ServerBase.cs b/OpenSim/Framework/Servers/ServerBase.cs index 1ff8aca..eb8c9f8 100644 --- a/OpenSim/Framework/Servers/ServerBase.cs +++ b/OpenSim/Framework/Servers/ServerBase.cs | |||
@@ -62,6 +62,8 @@ namespace OpenSim.Framework.Servers | |||
62 | 62 | ||
63 | protected string m_pidFile = String.Empty; | 63 | protected string m_pidFile = String.Empty; |
64 | 64 | ||
65 | protected ServerStatsCollector m_serverStatsCollector; | ||
66 | |||
65 | /// <summary> | 67 | /// <summary> |
66 | /// Server version information. Usually VersionInfo + information about git commit, operating system, etc. | 68 | /// Server version information. Usually VersionInfo + information about git commit, operating system, etc. |
67 | /// </summary> | 69 | /// </summary> |
@@ -76,6 +78,11 @@ namespace OpenSim.Framework.Servers | |||
76 | 78 | ||
77 | protected void CreatePIDFile(string path) | 79 | protected void CreatePIDFile(string path) |
78 | { | 80 | { |
81 | if (File.Exists(path)) | ||
82 | m_log.ErrorFormat( | ||
83 | "[SERVER BASE]: Previous pid file {0} still exists on startup. Possibly previously unclean shutdown.", | ||
84 | path); | ||
85 | |||
79 | try | 86 | try |
80 | { | 87 | { |
81 | string pidstring = System.Diagnostics.Process.GetCurrentProcess().Id.ToString(); | 88 | string pidstring = System.Diagnostics.Process.GetCurrentProcess().Id.ToString(); |
@@ -254,6 +261,25 @@ namespace OpenSim.Framework.Servers | |||
254 | "force gc", | 261 | "force gc", |
255 | "Manually invoke runtime garbage collection. For debugging purposes", | 262 | "Manually invoke runtime garbage collection. For debugging purposes", |
256 | HandleForceGc); | 263 | HandleForceGc); |
264 | |||
265 | m_console.Commands.AddCommand( | ||
266 | "General", false, "quit", | ||
267 | "quit", | ||
268 | "Quit the application", (mod, args) => Shutdown()); | ||
269 | |||
270 | m_console.Commands.AddCommand( | ||
271 | "General", false, "shutdown", | ||
272 | "shutdown", | ||
273 | "Quit the application", (mod, args) => Shutdown()); | ||
274 | |||
275 | StatsManager.RegisterConsoleCommands(m_console); | ||
276 | } | ||
277 | |||
278 | public void RegisterCommonComponents(IConfigSource configSource) | ||
279 | { | ||
280 | m_serverStatsCollector = new ServerStatsCollector(); | ||
281 | m_serverStatsCollector.Initialise(configSource); | ||
282 | m_serverStatsCollector.Start(); | ||
257 | } | 283 | } |
258 | 284 | ||
259 | private void HandleForceGc(string module, string[] args) | 285 | private void HandleForceGc(string module, string[] args) |
@@ -641,7 +667,68 @@ namespace OpenSim.Framework.Servers | |||
641 | sb.AppendFormat("Total threads active: {0}\n\n", totalThreads); | 667 | sb.AppendFormat("Total threads active: {0}\n\n", totalThreads); |
642 | 668 | ||
643 | sb.Append("Main threadpool (excluding script engine pools)\n"); | 669 | sb.Append("Main threadpool (excluding script engine pools)\n"); |
644 | sb.Append(Util.GetThreadPoolReport()); | 670 | sb.Append(GetThreadPoolReport()); |
671 | |||
672 | return sb.ToString(); | ||
673 | } | ||
674 | |||
675 | /// <summary> | ||
676 | /// Get a thread pool report. | ||
677 | /// </summary> | ||
678 | /// <returns></returns> | ||
679 | public static string GetThreadPoolReport() | ||
680 | { | ||
681 | string threadPoolUsed = null; | ||
682 | int maxThreads = 0; | ||
683 | int minThreads = 0; | ||
684 | int allocatedThreads = 0; | ||
685 | int inUseThreads = 0; | ||
686 | int waitingCallbacks = 0; | ||
687 | int completionPortThreads = 0; | ||
688 | |||
689 | StringBuilder sb = new StringBuilder(); | ||
690 | if (Util.FireAndForgetMethod == FireAndForgetMethod.SmartThreadPool) | ||
691 | { | ||
692 | STPInfo stpi = Util.GetSmartThreadPoolInfo(); | ||
693 | |||
694 | // ROBUST currently leaves this the FireAndForgetMethod but never actually initializes the threadpool. | ||
695 | if (stpi != null) | ||
696 | { | ||
697 | threadPoolUsed = "SmartThreadPool"; | ||
698 | maxThreads = stpi.MaxThreads; | ||
699 | minThreads = stpi.MinThreads; | ||
700 | inUseThreads = stpi.InUseThreads; | ||
701 | allocatedThreads = stpi.ActiveThreads; | ||
702 | waitingCallbacks = stpi.WaitingCallbacks; | ||
703 | } | ||
704 | } | ||
705 | else if ( | ||
706 | Util.FireAndForgetMethod == FireAndForgetMethod.QueueUserWorkItem | ||
707 | || Util.FireAndForgetMethod == FireAndForgetMethod.UnsafeQueueUserWorkItem) | ||
708 | { | ||
709 | threadPoolUsed = "BuiltInThreadPool"; | ||
710 | ThreadPool.GetMaxThreads(out maxThreads, out completionPortThreads); | ||
711 | ThreadPool.GetMinThreads(out minThreads, out completionPortThreads); | ||
712 | int availableThreads; | ||
713 | ThreadPool.GetAvailableThreads(out availableThreads, out completionPortThreads); | ||
714 | inUseThreads = maxThreads - availableThreads; | ||
715 | allocatedThreads = -1; | ||
716 | waitingCallbacks = -1; | ||
717 | } | ||
718 | |||
719 | if (threadPoolUsed != null) | ||
720 | { | ||
721 | sb.AppendFormat("Thread pool used : {0}\n", threadPoolUsed); | ||
722 | sb.AppendFormat("Max threads : {0}\n", maxThreads); | ||
723 | sb.AppendFormat("Min threads : {0}\n", minThreads); | ||
724 | sb.AppendFormat("Allocated threads : {0}\n", allocatedThreads < 0 ? "not applicable" : allocatedThreads.ToString()); | ||
725 | sb.AppendFormat("In use threads : {0}\n", inUseThreads); | ||
726 | sb.AppendFormat("Work items waiting : {0}\n", waitingCallbacks < 0 ? "not available" : waitingCallbacks.ToString()); | ||
727 | } | ||
728 | else | ||
729 | { | ||
730 | sb.AppendFormat("Thread pool not used\n"); | ||
731 | } | ||
645 | 732 | ||
646 | return sb.ToString(); | 733 | return sb.ToString(); |
647 | } | 734 | } |
@@ -693,5 +780,16 @@ namespace OpenSim.Framework.Servers | |||
693 | if (m_console != null) | 780 | if (m_console != null) |
694 | m_console.OutputFormat(format, components); | 781 | m_console.OutputFormat(format, components); |
695 | } | 782 | } |
783 | |||
784 | public virtual void Shutdown() | ||
785 | { | ||
786 | m_serverStatsCollector.Close(); | ||
787 | ShutdownSpecific(); | ||
788 | } | ||
789 | |||
790 | /// <summary> | ||
791 | /// Should be overriden and referenced by descendents if they need to perform extra shutdown processing | ||
792 | /// </summary> | ||
793 | protected virtual void ShutdownSpecific() {} | ||
696 | } | 794 | } |
697 | } | 795 | } |