diff options
author | Justin Clark-Casey (justincc) | 2012-03-16 00:34:30 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2012-03-19 21:31:38 +0000 |
commit | a9a77bb3ab73b96e95daafa6dccfe438439f1aef (patch) | |
tree | 0e3e7491b97a1a390e80e618bef9b18f93397bbf /OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | |
parent | Remove property/field duplication in ScriptInstance where it's unnecessary. (diff) | |
download | opensim-SC_OLD-a9a77bb3ab73b96e95daafa6dccfe438439f1aef.zip opensim-SC_OLD-a9a77bb3ab73b96e95daafa6dccfe438439f1aef.tar.gz opensim-SC_OLD-a9a77bb3ab73b96e95daafa6dccfe438439f1aef.tar.bz2 opensim-SC_OLD-a9a77bb3ab73b96e95daafa6dccfe438439f1aef.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 '')
-rw-r--r-- | OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index e776f5a..9214942 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); |