diff --git a/OpenSim/Framework/Monitoring/BaseStatsCollector.cs b/OpenSim/Framework/Monitoring/BaseStatsCollector.cs index b5df94baea..7119964fdd 100644 --- a/OpenSim/Framework/Monitoring/BaseStatsCollector.cs +++ b/OpenSim/Framework/Monitoring/BaseStatsCollector.cs @@ -52,21 +52,21 @@ namespace OpenSim.Framework.Monitoring Math.Round((MemoryWatchdog.LastHeapAllocationRate * 1000) / 1048576.0, 3), Math.Round((MemoryWatchdog.AverageHeapAllocationRate * 1000) / 1048576.0, 3)); - Process myprocess = Process.GetCurrentProcess(); -// if (!myprocess.HasExited) try { - myprocess.Refresh(); - sb.AppendFormat( - "Process memory: Physical {0} MB \t Paged {1} MB \t Virtual {2} MB\n", - Math.Round(myprocess.WorkingSet64 / 1024.0 / 1024.0), - Math.Round(myprocess.PagedMemorySize64 / 1024.0 / 1024.0), - Math.Round(myprocess.VirtualMemorySize64 / 1024.0 / 1024.0)); - sb.AppendFormat( - "Peak process memory: Physical {0} MB \t Paged {1} MB \t Virtual {2} MB\n", - Math.Round(myprocess.PeakWorkingSet64 / 1024.0 / 1024.0), - Math.Round(myprocess.PeakPagedMemorySize64 / 1024.0 / 1024.0), - Math.Round(myprocess.PeakVirtualMemorySize64 / 1024.0 / 1024.0)); + using (Process myprocess = Process.GetCurrentProcess()) + { + sb.AppendFormat( + "Process memory: Physical {0} MB \t Paged {1} MB \t Virtual {2} MB\n", + Math.Round(myprocess.WorkingSet64 / 1024.0 / 1024.0), + Math.Round(myprocess.PagedMemorySize64 / 1024.0 / 1024.0), + Math.Round(myprocess.VirtualMemorySize64 / 1024.0 / 1024.0)); + sb.AppendFormat( + "Peak process memory: Physical {0} MB \t Paged {1} MB \t Virtual {2} MB\n", + Math.Round(myprocess.PeakWorkingSet64 / 1024.0 / 1024.0), + Math.Round(myprocess.PeakPagedMemorySize64 / 1024.0 / 1024.0), + Math.Round(myprocess.PeakVirtualMemorySize64 / 1024.0 / 1024.0)); + } } catch { } diff --git a/OpenSim/Framework/Monitoring/SimExtraStatsCollector.cs b/OpenSim/Framework/Monitoring/SimExtraStatsCollector.cs index 88a02973fe..c41c4b9af3 100755 --- a/OpenSim/Framework/Monitoring/SimExtraStatsCollector.cs +++ b/OpenSim/Framework/Monitoring/SimExtraStatsCollector.cs @@ -435,21 +435,19 @@ Asset service request failures: {3}" + Environment.NewLine, // Get the amount of physical memory, allocated with the instance of this program, in kilobytes; // the working set is the set of memory pages currently visible to this program in physical RAM // memory and includes both shared (e.g. system libraries) and private data - double memUsage = Process.GetCurrentProcess().WorkingSet64 / 1024.0; - - // Get the number of threads from the system that are currently - // running int numberThreadsRunning = 0; - foreach (ProcessThread currentThread in - Process.GetCurrentProcess().Threads) + double memUsage = 0; + using(Process p = Process.GetCurrentProcess()) { - // A known issue with the current process .Threads property is - // that it can return null threads, thus don't count those as - // running threads and prevent the program function from failing - if (currentThread != null && - currentThread.ThreadState == ThreadState.Running) + memUsage = p.WorkingSet64 / 1024.0; + + // Get the number of threads from the system that are currently + // running + + foreach (ProcessThread currentThread in p.Threads) { - numberThreadsRunning++; + if (currentThread != null && currentThread.ThreadState == ThreadState.Running) + numberThreadsRunning++; } } diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 03e885239f..e0e35db874 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -2485,7 +2485,10 @@ namespace OpenSim.Framework case FireAndForgetMethod.SmartThreadPool: return m_ThreadPool.MaxThreads - m_ThreadPool.InUseThreads; case FireAndForgetMethod.Thread: - return MAX_SYSTEM_THREADS - System.Diagnostics.Process.GetCurrentProcess().Threads.Count; + { + using(Process p = System.Diagnostics.Process.GetCurrentProcess()) + return MAX_SYSTEM_THREADS - p.Threads.Count; + } default: throw new NotImplementedException(); } @@ -2972,7 +2975,8 @@ namespace OpenSim.Framework public static long GetPhysicalMemUse() { - return System.Diagnostics.Process.GetCurrentProcess().WorkingSet64; + using (Process p = System.Diagnostics.Process.GetCurrentProcess()) + return p.WorkingSet64; } // returns a timestamp in ms as double diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs index 07b2a8ec80..fa49546ee6 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs @@ -684,7 +684,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer if(destinationHandle == sourceRegion.RegionHandle) { - sp.ControllingClient.SendTeleportFailed("Can't teleport to a region on same map position. Try going other region first, then retry"); + sp.ControllingClient.SendTeleportFailed("Can't teleport to a region on same map position. Try going to another region first, then retry from there"); return; } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 3cb0fe7918..eb7049e4de 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -3689,7 +3689,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { CheckThreatLevel(ThreatLevel.Moderate, "osGetSimulatorMemory"); - long pws = System.Diagnostics.Process.GetCurrentProcess().WorkingSet64; + long pws = Util.GetPhysicalMemUse(); if (pws > Int32.MaxValue) return Int32.MaxValue; @@ -3703,9 +3703,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { CheckThreatLevel(ThreatLevel.Moderate, "osGetSimulatorMemoryKB"); - long pws = System.Diagnostics.Process.GetCurrentProcess().WorkingSet64; + long pws = Util.GetPhysicalMemUse(); - if((pws & 0x3FFL) != 0) + if ((pws & 0x3FFL) != 0) pws += 0x400L; pws >>= 10;