aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
diff options
context:
space:
mode:
authorTalun2012-04-10 21:25:05 +0100
committernebadon2012-04-12 18:44:00 -0700
commit08e509978d81cb3451c205ed59648e3f5da91344 (patch)
treee8fb382ef1661c2d370c64915a05376b295c551e /OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
parentmake changes to FlotsamCache.ini.example as noted in mantis #5960 (diff)
downloadopensim-SC_OLD-08e509978d81cb3451c205ed59648e3f5da91344.zip
opensim-SC_OLD-08e509978d81cb3451c205ed59648e3f5da91344.tar.gz
opensim-SC_OLD-08e509978d81cb3451c205ed59648e3f5da91344.tar.bz2
opensim-SC_OLD-08e509978d81cb3451c205ed59648e3f5da91344.tar.xz
Mantis 55025 Implement script time.
Signed-off-by: nebadon <michael@osgrid.org>
Diffstat (limited to 'OpenSim/Region/ScriptEngine/XEngine/XEngine.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/XEngine.cs82
1 files changed, 48 insertions, 34 deletions
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index 7712076..b7903d5 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -1907,45 +1907,59 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1907 if (!topScripts.ContainsKey(si.LocalID)) 1907 if (!topScripts.ContainsKey(si.LocalID))
1908 topScripts[si.RootLocalID] = 0; 1908 topScripts[si.RootLocalID] = 0;
1909 1909
1910// long ticksElapsed = tickNow - si.MeasurementPeriodTickStart; 1910 topScripts[si.RootLocalID] += CalculateAdjustedExectionTime(si, tickNow);
1911// float framesElapsed = ticksElapsed / (18.1818 * TimeSpan.TicksPerMillisecond); 1911 }
1912 1912 }
1913 // Execution time of the script adjusted by it's measurement period to make scripts started at
1914 // different times comparable.
1915// float adjustedExecutionTime
1916// = (float)si.MeasurementPeriodExecutionTime
1917// / ((float)(tickNow - si.MeasurementPeriodTickStart) / ScriptInstance.MaxMeasurementPeriod)
1918// / TimeSpan.TicksPerMillisecond;
1919
1920 long ticksElapsed = tickNow - si.MeasurementPeriodTickStart;
1921
1922 // Avoid divide by zerp
1923 if (ticksElapsed == 0)
1924 ticksElapsed = 1;
1925 1913
1926 // Scale execution time to the ideal 55 fps frame time for these reasons. 1914 return topScripts;
1927 // 1915 }
1928 // 1) XEngine does not execute scripts per frame, unlike other script engines. Hence, there is no
1929 // 'script execution time per frame', which is the original purpose of this value.
1930 //
1931 // 2) Giving the raw execution times is misleading since scripts start at different times, making
1932 // it impossible to compare scripts.
1933 //
1934 // 3) Scaling the raw execution time to the time that the script has been running is better but
1935 // is still misleading since a script that has just been rezzed may appear to have been running
1936 // for much longer.
1937 //
1938 // 4) Hence, we scale execution time to an idealised frame time (55 fps). This is also not perfect
1939 // since the figure does not represent actual execution time and very hard running scripts will
1940 // never exceed 18ms (though this is a very high number for script execution so is a warning sign).
1941 float adjustedExecutionTime
1942 = ((float)si.MeasurementPeriodExecutionTime / ticksElapsed) * 18.1818f;
1943 1916
1944 topScripts[si.RootLocalID] += adjustedExecutionTime; 1917 public float GetScriptExecutionTime(List<UUID> itemIDs)
1918 {
1919 if (itemIDs == null|| itemIDs.Count == 0)
1920 {
1921 return 0.0f;
1922 }
1923 float time = 0.0f;
1924 long tickNow = Util.EnvironmentTickCount();
1925 IScriptInstance si;
1926 // Calculate the time for all scripts that this engine is executing
1927 // Ignore any others
1928 foreach (UUID id in itemIDs)
1929 {
1930 si = GetInstance(id);
1931 if (si != null && si.Running)
1932 {
1933 time += CalculateAdjustedExectionTime(si, tickNow);
1945 } 1934 }
1946 } 1935 }
1936 return time;
1937 }
1947 1938
1948 return topScripts; 1939 private float CalculateAdjustedExectionTime(IScriptInstance si, long tickNow)
1940 {
1941 long ticksElapsed = tickNow - si.MeasurementPeriodTickStart;
1942
1943 // Avoid divide by zero
1944 if (ticksElapsed == 0)
1945 ticksElapsed = 1;
1946
1947 // Scale execution time to the ideal 55 fps frame time for these reasons.
1948 //
1949 // 1) XEngine does not execute scripts per frame, unlike other script engines. Hence, there is no
1950 // 'script execution time per frame', which is the original purpose of this value.
1951 //
1952 // 2) Giving the raw execution times is misleading since scripts start at different times, making
1953 // it impossible to compare scripts.
1954 //
1955 // 3) Scaling the raw execution time to the time that the script has been running is better but
1956 // is still misleading since a script that has just been rezzed may appear to have been running
1957 // for much longer.
1958 //
1959 // 4) Hence, we scale execution time to an idealised frame time (55 fps). This is also not perfect
1960 // since the figure does not represent actual execution time and very hard running scripts will
1961 // never exceed 18ms (though this is a very high number for script execution so is a warning sign).
1962 return ((float)si.MeasurementPeriodExecutionTime / ticksElapsed) * 18.1818f;
1949 } 1963 }
1950 1964
1951 public void SuspendScript(UUID itemID) 1965 public void SuspendScript(UUID itemID)