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
0.8.2-post-fixes
Oren Hurvitz 2015-07-27 09:03:14 +03:00
parent 20af31f18e
commit 287096d826
2 changed files with 13 additions and 7 deletions

View File

@ -51,6 +51,7 @@ using OpenSim.Region.ScriptEngine.Shared.Api.Runtime;
using OpenSim.Region.ScriptEngine.Shared.ScriptBase; using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
using OpenSim.Region.ScriptEngine.Shared.CodeTools; using OpenSim.Region.ScriptEngine.Shared.CodeTools;
using OpenSim.Region.ScriptEngine.Interfaces; using OpenSim.Region.ScriptEngine.Interfaces;
using System.Diagnostics;
namespace OpenSim.Region.ScriptEngine.Shared.Instance namespace OpenSim.Region.ScriptEngine.Shared.Instance
{ {
@ -202,7 +203,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
public long MeasurementPeriodExecutionTime { get; private set; } 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; private bool m_coopTermination;
@ -831,15 +832,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
m_EventStart = DateTime.Now; m_EventStart = DateTime.Now;
m_InEvent = true; m_InEvent = true;
int start = Util.EnvironmentTickCount();
// Reset the measurement period when we reach the end of the current one. // Reset the measurement period when we reach the end of the current one.
if (start - MeasurementPeriodTickStart > MaxMeasurementPeriod) if (Util.EnvironmentTickCountSubtract((int)MeasurementPeriodTickStart) > MaxMeasurementPeriod)
MeasurementPeriodTickStart = start; {
MeasurementPeriodTickStart = Util.EnvironmentTickCount();
MeasurementPeriodExecutionTime = 0;
}
Stopwatch executionTime = new Stopwatch();
executionTime.Start();
m_Script.ExecuteEvent(State, data.EventName, data.Params); m_Script.ExecuteEvent(State, data.EventName, data.Params);
MeasurementPeriodExecutionTime += Util.EnvironmentTickCount() - start; executionTime.Stop();
MeasurementPeriodExecutionTime += executionTime.ElapsedMilliseconds;
m_InEvent = false; m_InEvent = false;
m_CurrentEvent = String.Empty; m_CurrentEvent = String.Empty;

View File

@ -2384,7 +2384,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
private float CalculateAdjustedExectionTime(IScriptInstance si, long tickNow) 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 // Avoid divide by zero
if (ticksElapsed == 0) if (ticksElapsed == 0)