From 287096d826060d96454d2b186e082a95f1e5724a Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Mon, 27 Jul 2015 09:03:14 +0300 Subject: Improved calculation of Script Execution TimeStarted 1. Use a Stopwatch (a high-resolution timer) 2. Whenever we start a new measurement period, zero out the total execution time (previously it just kept accumulating) 3. Changed the measurement period from 30 minutes to 30 seconds. This is much more useful in the "Top Scripts" dialog, as it shows currently active scripts --- .../ScriptEngine/Shared/Instance/ScriptInstance.cs | 18 ++++++++++++------ OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index bae66e8..05dea5d 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs @@ -51,6 +51,7 @@ using OpenSim.Region.ScriptEngine.Shared.Api.Runtime; using OpenSim.Region.ScriptEngine.Shared.ScriptBase; using OpenSim.Region.ScriptEngine.Shared.CodeTools; using OpenSim.Region.ScriptEngine.Interfaces; +using System.Diagnostics; namespace OpenSim.Region.ScriptEngine.Shared.Instance { @@ -202,7 +203,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance public long MeasurementPeriodExecutionTime { get; private set; } - public static readonly long MaxMeasurementPeriod = 30 * (TimeSpan.TicksPerMinute / TimeSpan.TicksPerMillisecond); + public static readonly int MaxMeasurementPeriod = 30 * 1000; // show the *recent* time used by the script, to find currently active scripts private bool m_coopTermination; @@ -831,15 +832,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance m_EventStart = DateTime.Now; m_InEvent = true; - int start = Util.EnvironmentTickCount(); - // Reset the measurement period when we reach the end of the current one. - if (start - MeasurementPeriodTickStart > MaxMeasurementPeriod) - MeasurementPeriodTickStart = start; + if (Util.EnvironmentTickCountSubtract((int)MeasurementPeriodTickStart) > MaxMeasurementPeriod) + { + MeasurementPeriodTickStart = Util.EnvironmentTickCount(); + MeasurementPeriodExecutionTime = 0; + } + Stopwatch executionTime = new Stopwatch(); + executionTime.Start(); + m_Script.ExecuteEvent(State, data.EventName, data.Params); - MeasurementPeriodExecutionTime += Util.EnvironmentTickCount() - start; + executionTime.Stop(); + MeasurementPeriodExecutionTime += executionTime.ElapsedMilliseconds; m_InEvent = false; m_CurrentEvent = String.Empty; diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index e5e5698..ae02877 100755 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -2384,7 +2384,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine private float CalculateAdjustedExectionTime(IScriptInstance si, long tickNow) { - long ticksElapsed = tickNow - si.MeasurementPeriodTickStart; + long ticksElapsed = Util.EnvironmentTickCountSubtract((int)tickNow, (int)si.MeasurementPeriodTickStart); // Avoid divide by zero if (ticksElapsed == 0) -- cgit v1.1