diff options
Diffstat (limited to 'OpenSim/Region/ScriptEngine')
3 files changed, 88 insertions, 1 deletions
diff --git a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs index 8762642..11f54a2 100644 --- a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs | |||
@@ -78,6 +78,21 @@ namespace OpenSim.Region.ScriptEngine.Interfaces | |||
78 | /// </summary> | 78 | /// </summary> |
79 | string State { get; set; } | 79 | string State { get; set; } |
80 | 80 | ||
81 | /// <summary> | ||
82 | /// Time the script was last started | ||
83 | /// </summary> | ||
84 | DateTime TimeStarted { get; } | ||
85 | |||
86 | /// <summary> | ||
87 | /// Tick the last measurement period was started. | ||
88 | /// </summary> | ||
89 | long MeasurementPeriodTickStart { get; } | ||
90 | |||
91 | /// <summary> | ||
92 | /// Ticks spent executing in the last measurement period. | ||
93 | /// </summary> | ||
94 | long MeasurementPeriodExecutionTime { get; } | ||
95 | |||
81 | IScriptEngine Engine { get; } | 96 | IScriptEngine Engine { get; } |
82 | UUID AppDomain { get; set; } | 97 | UUID AppDomain { get; set; } |
83 | string PrimName { get; } | 98 | string PrimName { get; } |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index 968351b..b177287 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs | |||
@@ -172,6 +172,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
172 | 172 | ||
173 | public TaskInventoryItem ScriptTask { get; private set; } | 173 | public TaskInventoryItem ScriptTask { get; private set; } |
174 | 174 | ||
175 | public DateTime TimeStarted { get; private set; } | ||
176 | |||
177 | public long MeasurementPeriodTickStart { get; private set; } | ||
178 | |||
179 | public long MeasurementPeriodExecutionTime { get; private set; } | ||
180 | |||
181 | public static readonly long MaxMeasurementPeriod = 30 * TimeSpan.TicksPerMinute; | ||
182 | |||
175 | public void ClearQueue() | 183 | public void ClearQueue() |
176 | { | 184 | { |
177 | m_TimerQueued = false; | 185 | m_TimerQueued = false; |
@@ -458,6 +466,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
458 | 466 | ||
459 | Running = true; | 467 | Running = true; |
460 | 468 | ||
469 | TimeStarted = DateTime.Now; | ||
470 | MeasurementPeriodTickStart = Util.EnvironmentTickCount(); | ||
471 | MeasurementPeriodExecutionTime = 0; | ||
472 | |||
461 | if (EventQueue.Count > 0) | 473 | if (EventQueue.Count > 0) |
462 | { | 474 | { |
463 | if (m_CurrentWorkItem == null) | 475 | if (m_CurrentWorkItem == null) |
@@ -710,8 +722,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
710 | m_EventStart = DateTime.Now; | 722 | m_EventStart = DateTime.Now; |
711 | m_InEvent = true; | 723 | m_InEvent = true; |
712 | 724 | ||
725 | int start = Util.EnvironmentTickCount(); | ||
726 | |||
727 | // Reset the measurement period when we reach the end of the current one. | ||
728 | if (start - MeasurementPeriodTickStart > MaxMeasurementPeriod) | ||
729 | MeasurementPeriodTickStart = start; | ||
730 | |||
713 | m_Script.ExecuteEvent(State, data.EventName, data.Params); | 731 | m_Script.ExecuteEvent(State, data.EventName, data.Params); |
714 | 732 | ||
733 | MeasurementPeriodExecutionTime += Util.EnvironmentTickCount() - start; | ||
734 | |||
715 | m_InEvent = false; | 735 | m_InEvent = false; |
716 | m_CurrentEvent = String.Empty; | 736 | m_CurrentEvent = String.Empty; |
717 | 737 | ||
@@ -720,7 +740,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
720 | // This will be the very first event we deliver | 740 | // This will be the very first event we deliver |
721 | // (state_entry) in default state | 741 | // (state_entry) in default state |
722 | // | 742 | // |
723 | |||
724 | SaveState(m_Assembly); | 743 | SaveState(m_Assembly); |
725 | 744 | ||
726 | m_SaveState = false; | 745 | m_SaveState = false; |
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 105d97d..bddb1b9 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | |||
@@ -1891,6 +1891,59 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1891 | } | 1891 | } |
1892 | } | 1892 | } |
1893 | 1893 | ||
1894 | public Dictionary<uint, float> GetObjectScriptsExecutionTimes() | ||
1895 | { | ||
1896 | long tickNow = Util.EnvironmentTickCount(); | ||
1897 | Dictionary<uint, float> topScripts = new Dictionary<uint, float>(); | ||
1898 | |||
1899 | lock (m_Scripts) | ||
1900 | { | ||
1901 | foreach (IScriptInstance si in m_Scripts.Values) | ||
1902 | { | ||
1903 | if (!topScripts.ContainsKey(si.LocalID)) | ||
1904 | topScripts[si.LocalID] = 0; | ||
1905 | |||
1906 | // long ticksElapsed = tickNow - si.MeasurementPeriodTickStart; | ||
1907 | // float framesElapsed = ticksElapsed / (18.1818 * TimeSpan.TicksPerMillisecond); | ||
1908 | |||
1909 | // Execution time of the script adjusted by it's measurement period to make scripts started at | ||
1910 | // different times comparable. | ||
1911 | // float adjustedExecutionTime | ||
1912 | // = (float)si.MeasurementPeriodExecutionTime | ||
1913 | // / ((float)(tickNow - si.MeasurementPeriodTickStart) / ScriptInstance.MaxMeasurementPeriod) | ||
1914 | // / TimeSpan.TicksPerMillisecond; | ||
1915 | |||
1916 | long ticksElapsed = tickNow - si.MeasurementPeriodTickStart; | ||
1917 | |||
1918 | // Avoid divide by zerp | ||
1919 | if (ticksElapsed == 0) | ||
1920 | ticksElapsed = 1; | ||
1921 | |||
1922 | // Scale execution time to the ideal 55 fps frame time for these reasons. | ||
1923 | // | ||
1924 | // 1) XEngine does not execute scripts per frame, unlike other script engines. Hence, there is no | ||
1925 | // 'script execution time per frame', which is the original purpose of this value. | ||
1926 | // | ||
1927 | // 2) Giving the raw execution times is misleading since scripts start at different times, making | ||
1928 | // it impossible to compare scripts. | ||
1929 | // | ||
1930 | // 3) Scaling the raw execution time to the time that the script has been running is better but | ||
1931 | // is still misleading since a script that has just been rezzed may appear to have been running | ||
1932 | // for much longer. | ||
1933 | // | ||
1934 | // 4) Hence, we scale execution time to an idealised frame time (55 fps). This is also not perfect | ||
1935 | // since the figure does not represent actual execution time and very hard running scripts will | ||
1936 | // never exceed 18ms (though this is a very high number for script execution so is a warning sign). | ||
1937 | float adjustedExecutionTime | ||
1938 | = ((float)si.MeasurementPeriodExecutionTime / ticksElapsed) * 18.1818f; | ||
1939 | |||
1940 | topScripts[si.LocalID] += adjustedExecutionTime; | ||
1941 | } | ||
1942 | } | ||
1943 | |||
1944 | return topScripts; | ||
1945 | } | ||
1946 | |||
1894 | public void SuspendScript(UUID itemID) | 1947 | public void SuspendScript(UUID itemID) |
1895 | { | 1948 | { |
1896 | // m_log.DebugFormat("[XEngine]: Received request to suspend script with ID {0}", itemID); | 1949 | // m_log.DebugFormat("[XEngine]: Received request to suspend script with ID {0}", itemID); |