From c20f7d6171a9df151c3ccde063336338da9ae322 Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Sun, 25 May 2008 20:50:45 +0000 Subject: * A hacky Top Scripts display. It isn't accurate as far as ms accounting, however you can use it to help find out what scripts are causing your simulator to cry. * Access it from the Estate tools/Debug tab. --- OpenSim/Region/Environment/Scenes/EventManager.cs | 15 ++++++++++ OpenSim/Region/Environment/Scenes/InnerScene.cs | 31 +++++++++++++++++++++ .../Region/Environment/Scenes/SceneObjectGroup.cs | 5 ++++ .../Region/Environment/Scenes/SceneObjectPart.cs | 32 ++++++++++++++++++++++ 4 files changed, 83 insertions(+) (limited to 'OpenSim/Region/Environment/Scenes') diff --git a/OpenSim/Region/Environment/Scenes/EventManager.cs b/OpenSim/Region/Environment/Scenes/EventManager.cs index a3f5d2f..1c345ba 100644 --- a/OpenSim/Region/Environment/Scenes/EventManager.cs +++ b/OpenSim/Region/Environment/Scenes/EventManager.cs @@ -174,6 +174,9 @@ namespace OpenSim.Region.Environment.Scenes public event AvatarKillData OnAvatarKilled; + public delegate void ScriptTimerEvent(uint localID, double timerinterval); + + public event ScriptTimerEvent OnScriptTimerEvent; public delegate void ObjectBeingRemovedFromScene(SceneObjectGroup obj); @@ -332,6 +335,7 @@ namespace OpenSim.Region.Environment.Scenes private RequestParcelPrimCountUpdate handlerRequestParcelPrimCountUpdate = null; private ParcelPrimCountTainted handlerParcelPrimCountTainted = null; private ObjectBeingRemovedFromScene handlerObjectBeingRemovedFromScene = null; + private ScriptTimerEvent handlerScriptTimerEvent = null; public void TriggerOnScriptChangedEvent(uint localID, uint change) { @@ -755,5 +759,16 @@ namespace OpenSim.Region.Environment.Scenes } } + // this lets us keep track of nasty script events like timer, etc. + public void TriggerTimerEvent(uint objLocalID, double Interval) + { + handlerScriptTimerEvent = OnScriptTimerEvent; + if (handlerScriptTimerEvent != null) + { + handlerScriptTimerEvent(objLocalID, Interval); + + } + + } } } diff --git a/OpenSim/Region/Environment/Scenes/InnerScene.cs b/OpenSim/Region/Environment/Scenes/InnerScene.cs index 84de71f..d6e905b 100644 --- a/OpenSim/Region/Environment/Scenes/InnerScene.cs +++ b/OpenSim/Region/Environment/Scenes/InnerScene.cs @@ -846,6 +846,37 @@ namespace OpenSim.Region.Environment.Scenes return result; } + public Dictionary GetTopScripts() + { + Dictionary topScripts = new Dictionary(); + + List EntityList = GetEntities(); + int limit = 0; + foreach (EntityBase ent in EntityList) + { + if (ent is SceneObjectGroup) + { + SceneObjectGroup grp = (SceneObjectGroup)ent; + if ((grp.RootPart.GetEffectiveObjectFlags() & (uint)LLObject.ObjectFlags.Scripted) != 0) + { + if (grp.scriptScore >= 0.01) + { + topScripts.Add(grp.LocalId, grp.scriptScore); + limit++; + if (limit >= 100) + { + break; + } + + } + grp.scriptScore = 0; + } + } + } + + return topScripts; + } + #endregion #region Other Methods diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs index 25b3d16..cd4be99 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs @@ -90,6 +90,7 @@ namespace OpenSim.Region.Environment.Scenes /// since the group's last persistent backup /// public bool HasGroupChanged = false; + public float scriptScore = 0f; @@ -959,6 +960,10 @@ namespace OpenSim.Region.Environment.Scenes public void AddScriptLPS(int count) { + if (scriptScore + count >= float.MaxValue - count) + scriptScore = 0; + + scriptScore += (float)count; InnerScene d = m_scene.m_innerScene; d.AddToScriptLPS(count); } diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs index b724bda..c6b3059 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs @@ -2752,6 +2752,14 @@ namespace OpenSim.Region.Environment.Scenes PhysActor.OnCollisionUpdate -= PhysicsCollision; } } + if ((GetEffectiveObjectFlags() & (uint)LLObject.ObjectFlags.Scripted) != 0) + { + m_parentGroup.Scene.EventManager.OnScriptTimerEvent += handleTimerAccounting; + } + else + { + m_parentGroup.Scene.EventManager.OnScriptTimerEvent -= handleTimerAccounting; + } LocalFlags=(LLObject.ObjectFlags)objectflagupdate; @@ -2812,6 +2820,30 @@ namespace OpenSim.Region.Environment.Scenes GetProperties(client); m_updateFlag = 2; } + private void handleTimerAccounting(uint localID, double interval) + { + if (localID == LocalId) + { + + float sec = (float)interval; + if (m_parentGroup != null) + { + if (sec == 0) + { + if (m_parentGroup.scriptScore + 0.001f >= float.MaxValue - 0.001) + m_parentGroup.scriptScore = 0; + + m_parentGroup.scriptScore += 0.001f; + return; + } + + if (m_parentGroup.scriptScore + (0.001f / sec) >= float.MaxValue - (0.001f / sec)) + m_parentGroup.scriptScore = 0; + m_parentGroup.scriptScore += (0.001f / sec); + } + + } + } } } -- cgit v1.1