aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/Instance
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Instance')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs29
1 files changed, 12 insertions, 17 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
index 05dea5d..d8ad62c 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
@@ -199,11 +199,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
199 199
200 public DateTime TimeStarted { get; private set; } 200 public DateTime TimeStarted { get; private set; }
201 201
202 public long MeasurementPeriodTickStart { get; private set; } 202 public MetricsCollectorTime ExecutionTime { get; private set; }
203 203
204 public long MeasurementPeriodExecutionTime { get; private set; } 204 private static readonly int MeasurementWindow = 30 * 1000; // show the *recent* time used by the script, to find currently active scripts
205
206 public static readonly int MaxMeasurementPeriod = 30 * 1000; // show the *recent* time used by the script, to find currently active scripts
207 205
208 private bool m_coopTermination; 206 private bool m_coopTermination;
209 207
@@ -246,6 +244,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
246 244
247 m_SaveState = StatePersistedHere; 245 m_SaveState = StatePersistedHere;
248 246
247 ExecutionTime = new MetricsCollectorTime(MeasurementWindow, 10);
248
249// m_log.DebugFormat( 249// m_log.DebugFormat(
250// "[SCRIPT INSTANCE]: Instantiated script instance {0} (id {1}) in part {2} (id {3}) in object {4} attached avatar {5} in {6}", 250// "[SCRIPT INSTANCE]: Instantiated script instance {0} (id {1}) in part {2} (id {3}) in object {4} attached avatar {5} in {6}",
251// ScriptTask.Name, ScriptTask.ItemID, Part.Name, Part.UUID, Part.ParentGroup.Name, m_AttachedAvatar, Engine.World.Name); 251// ScriptTask.Name, ScriptTask.ItemID, Part.Name, Part.UUID, Part.ParentGroup.Name, m_AttachedAvatar, Engine.World.Name);
@@ -505,8 +505,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
505 Running = true; 505 Running = true;
506 506
507 TimeStarted = DateTime.Now; 507 TimeStarted = DateTime.Now;
508 MeasurementPeriodTickStart = Util.EnvironmentTickCount(); 508
509 MeasurementPeriodExecutionTime = 0; 509 // Note: we don't reset ExecutionTime. The reason is that runaway scripts are stopped and restarted
510 // automatically, and we *do* want to show that they had high CPU in that case. If we had reset
511 // ExecutionTime here then runaway scripts, paradoxically, would never show up in the "Top Scripts" dialog.
510 512
511 if (EventQueue.Count > 0) 513 if (EventQueue.Count > 0)
512 { 514 {
@@ -832,20 +834,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
832 m_EventStart = DateTime.Now; 834 m_EventStart = DateTime.Now;
833 m_InEvent = true; 835 m_InEvent = true;
834 836
835 // Reset the measurement period when we reach the end of the current one. 837 Stopwatch timer = new Stopwatch();
836 if (Util.EnvironmentTickCountSubtract((int)MeasurementPeriodTickStart) > MaxMeasurementPeriod) 838 timer.Start();
837 {
838 MeasurementPeriodTickStart = Util.EnvironmentTickCount();
839 MeasurementPeriodExecutionTime = 0;
840 }
841 839
842 Stopwatch executionTime = new Stopwatch();
843 executionTime.Start();
844
845 m_Script.ExecuteEvent(State, data.EventName, data.Params); 840 m_Script.ExecuteEvent(State, data.EventName, data.Params);
846 841
847 executionTime.Stop(); 842 timer.Stop();
848 MeasurementPeriodExecutionTime += executionTime.ElapsedMilliseconds; 843 ExecutionTime.AddSample(timer);
849 844
850 m_InEvent = false; 845 m_InEvent = false;
851 m_CurrentEvent = String.Empty; 846 m_CurrentEvent = String.Empty;