aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2012-03-16 00:34:30 +0000
committerJustin Clark-Casey (justincc)2012-03-16 00:34:30 +0000
commita4b01ef38a735ffe70b402061871a9c99f2757ed (patch)
treeb60dcc1cbfaeb0cb0184f4b9619a7e95afe0a4de /OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
parentMerge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff)
downloadopensim-SC_OLD-a4b01ef38a735ffe70b402061871a9c99f2757ed.zip
opensim-SC_OLD-a4b01ef38a735ffe70b402061871a9c99f2757ed.tar.gz
opensim-SC_OLD-a4b01ef38a735ffe70b402061871a9c99f2757ed.tar.bz2
opensim-SC_OLD-a4b01ef38a735ffe70b402061871a9c99f2757ed.tar.xz
Replace script-lines-per-second with the script execution time scaled by its measurement period and an idealised frame time.
The previous lines-per-second measurement used for top scripts report was inaccurate, since lines executed does not reflect time taken to execute. Also, every fetch of the report would reset all the numbers limiting its usefulness and we weren't even guaranteed to see the top 100. The actual measurement value should be script execution time per frame but XEngine does not work this way. Therefore, we use actual script execution time scaled by the measurement period and an idealised frame time. This is still not ideal but gives reasonable results and allows scripts to be compared. This commit moves script execution time calculations from SceneGraph into IScriptModule implementations.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/XEngine/XEngine.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/XEngine.cs53
1 files changed, 53 insertions, 0 deletions
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);