aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/XEngine
diff options
context:
space:
mode:
authorMelanie2012-04-13 03:00:48 +0100
committerMelanie2012-04-13 03:00:48 +0100
commitfe65b518765a8c88c1f3067b47d775b9b1142961 (patch)
tree3a97f13715090d8c925543ae49ecae1930578d5d /OpenSim/Region/ScriptEngine/XEngine
parentMerge branch 'master' into careminster (diff)
parentMantis 55025 Implement script time. (diff)
downloadopensim-SC-fe65b518765a8c88c1f3067b47d775b9b1142961.zip
opensim-SC-fe65b518765a8c88c1f3067b47d775b9b1142961.tar.gz
opensim-SC-fe65b518765a8c88c1f3067b47d775b9b1142961.tar.bz2
opensim-SC-fe65b518765a8c88c1f3067b47d775b9b1142961.tar.xz
Merge branch 'master' into careminster
Conflicts: OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
Diffstat (limited to 'OpenSim/Region/ScriptEngine/XEngine')
-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 1e0f01f..bfe7418 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -1997,45 +1997,59 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1997 if (!topScripts.ContainsKey(si.LocalID)) 1997 if (!topScripts.ContainsKey(si.LocalID))
1998 topScripts[si.RootLocalID] = 0; 1998 topScripts[si.RootLocalID] = 0;
1999 1999
2000// long ticksElapsed = tickNow - si.MeasurementPeriodTickStart; 2000 topScripts[si.RootLocalID] += CalculateAdjustedExectionTime(si, tickNow);
2001// float framesElapsed = ticksElapsed / (18.1818 * TimeSpan.TicksPerMillisecond); 2001 }
2002 2002 }
2003 // Execution time of the script adjusted by it's measurement period to make scripts started at
2004 // different times comparable.
2005// float adjustedExecutionTime
2006// = (float)si.MeasurementPeriodExecutionTime
2007// / ((float)(tickNow - si.MeasurementPeriodTickStart) / ScriptInstance.MaxMeasurementPeriod)
2008// / TimeSpan.TicksPerMillisecond;
2009
2010 long ticksElapsed = tickNow - si.MeasurementPeriodTickStart;
2011
2012 // Avoid divide by zerp
2013 if (ticksElapsed == 0)
2014 ticksElapsed = 1;
2015 2003
2016 // Scale execution time to the ideal 55 fps frame time for these reasons. 2004 return topScripts;
2017 // 2005 }
2018 // 1) XEngine does not execute scripts per frame, unlike other script engines. Hence, there is no
2019 // 'script execution time per frame', which is the original purpose of this value.
2020 //
2021 // 2) Giving the raw execution times is misleading since scripts start at different times, making
2022 // it impossible to compare scripts.
2023 //
2024 // 3) Scaling the raw execution time to the time that the script has been running is better but
2025 // is still misleading since a script that has just been rezzed may appear to have been running
2026 // for much longer.
2027 //
2028 // 4) Hence, we scale execution time to an idealised frame time (55 fps). This is also not perfect
2029 // since the figure does not represent actual execution time and very hard running scripts will
2030 // never exceed 18ms (though this is a very high number for script execution so is a warning sign).
2031 float adjustedExecutionTime
2032 = ((float)si.MeasurementPeriodExecutionTime / ticksElapsed) * 18.1818f;
2033 2006
2034 topScripts[si.RootLocalID] += adjustedExecutionTime; 2007 public float GetScriptExecutionTime(List<UUID> itemIDs)
2008 {
2009 if (itemIDs == null|| itemIDs.Count == 0)
2010 {
2011 return 0.0f;
2012 }
2013 float time = 0.0f;
2014 long tickNow = Util.EnvironmentTickCount();
2015 IScriptInstance si;
2016 // Calculate the time for all scripts that this engine is executing
2017 // Ignore any others
2018 foreach (UUID id in itemIDs)
2019 {
2020 si = GetInstance(id);
2021 if (si != null && si.Running)
2022 {
2023 time += CalculateAdjustedExectionTime(si, tickNow);
2035 } 2024 }
2036 } 2025 }
2026 return time;
2027 }
2037 2028
2038 return topScripts; 2029 private float CalculateAdjustedExectionTime(IScriptInstance si, long tickNow)
2030 {
2031 long ticksElapsed = tickNow - si.MeasurementPeriodTickStart;
2032
2033 // Avoid divide by zero
2034 if (ticksElapsed == 0)
2035 ticksElapsed = 1;
2036
2037 // Scale execution time to the ideal 55 fps frame time for these reasons.
2038 //
2039 // 1) XEngine does not execute scripts per frame, unlike other script engines. Hence, there is no
2040 // 'script execution time per frame', which is the original purpose of this value.
2041 //
2042 // 2) Giving the raw execution times is misleading since scripts start at different times, making
2043 // it impossible to compare scripts.
2044 //
2045 // 3) Scaling the raw execution time to the time that the script has been running is better but
2046 // is still misleading since a script that has just been rezzed may appear to have been running
2047 // for much longer.
2048 //
2049 // 4) Hence, we scale execution time to an idealised frame time (55 fps). This is also not perfect
2050 // since the figure does not represent actual execution time and very hard running scripts will
2051 // never exceed 18ms (though this is a very high number for script execution so is a warning sign).
2052 return ((float)si.MeasurementPeriodExecutionTime / ticksElapsed) * 18.1818f;
2039 } 2053 }
2040 2054
2041 public void SuspendScript(UUID itemID) 2055 public void SuspendScript(UUID itemID)