aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/XEngine/XEngine.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/XEngine.cs92
1 files changed, 55 insertions, 37 deletions
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index 1e0f01f..5a02d4c 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -1089,11 +1089,18 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1089 1089
1090 AppDomain sandbox; 1090 AppDomain sandbox;
1091 if (m_AppDomainLoading) 1091 if (m_AppDomainLoading)
1092 {
1092 sandbox = AppDomain.CreateDomain( 1093 sandbox = AppDomain.CreateDomain(
1093 m_Scene.RegionInfo.RegionID.ToString(), 1094 m_Scene.RegionInfo.RegionID.ToString(),
1094 evidence, appSetup); 1095 evidence, appSetup);
1096 m_AppDomains[appDomain].AssemblyResolve +=
1097 new ResolveEventHandler(
1098 AssemblyResolver.OnAssemblyResolve);
1099 }
1095 else 1100 else
1101 {
1096 sandbox = AppDomain.CurrentDomain; 1102 sandbox = AppDomain.CurrentDomain;
1103 }
1097 1104
1098 //PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel(); 1105 //PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel();
1099 //AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition(); 1106 //AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition();
@@ -1105,9 +1112,6 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1105 1112
1106 m_AppDomains[appDomain] = sandbox; 1113 m_AppDomains[appDomain] = sandbox;
1107 1114
1108 m_AppDomains[appDomain].AssemblyResolve +=
1109 new ResolveEventHandler(
1110 AssemblyResolver.OnAssemblyResolve);
1111 m_DomainScripts[appDomain] = new List<UUID>(); 1115 m_DomainScripts[appDomain] = new List<UUID>();
1112 } 1116 }
1113 catch (Exception e) 1117 catch (Exception e)
@@ -1997,45 +2001,59 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1997 if (!topScripts.ContainsKey(si.LocalID)) 2001 if (!topScripts.ContainsKey(si.LocalID))
1998 topScripts[si.RootLocalID] = 0; 2002 topScripts[si.RootLocalID] = 0;
1999 2003
2000// long ticksElapsed = tickNow - si.MeasurementPeriodTickStart; 2004 topScripts[si.RootLocalID] += CalculateAdjustedExectionTime(si, tickNow);
2001// float framesElapsed = ticksElapsed / (18.1818 * TimeSpan.TicksPerMillisecond); 2005 }
2002 2006 }
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 2007
2016 // Scale execution time to the ideal 55 fps frame time for these reasons. 2008 return topScripts;
2017 // 2009 }
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 2010
2034 topScripts[si.RootLocalID] += adjustedExecutionTime; 2011 public float GetScriptExecutionTime(List<UUID> itemIDs)
2012 {
2013 if (itemIDs == null|| itemIDs.Count == 0)
2014 {
2015 return 0.0f;
2016 }
2017 float time = 0.0f;
2018 long tickNow = Util.EnvironmentTickCount();
2019 IScriptInstance si;
2020 // Calculate the time for all scripts that this engine is executing
2021 // Ignore any others
2022 foreach (UUID id in itemIDs)
2023 {
2024 si = GetInstance(id);
2025 if (si != null && si.Running)
2026 {
2027 time += CalculateAdjustedExectionTime(si, tickNow);
2035 } 2028 }
2036 } 2029 }
2030 return time;
2031 }
2037 2032
2038 return topScripts; 2033 private float CalculateAdjustedExectionTime(IScriptInstance si, long tickNow)
2034 {
2035 long ticksElapsed = tickNow - si.MeasurementPeriodTickStart;
2036
2037 // Avoid divide by zero
2038 if (ticksElapsed == 0)
2039 ticksElapsed = 1;
2040
2041 // Scale execution time to the ideal 55 fps frame time for these reasons.
2042 //
2043 // 1) XEngine does not execute scripts per frame, unlike other script engines. Hence, there is no
2044 // 'script execution time per frame', which is the original purpose of this value.
2045 //
2046 // 2) Giving the raw execution times is misleading since scripts start at different times, making
2047 // it impossible to compare scripts.
2048 //
2049 // 3) Scaling the raw execution time to the time that the script has been running is better but
2050 // is still misleading since a script that has just been rezzed may appear to have been running
2051 // for much longer.
2052 //
2053 // 4) Hence, we scale execution time to an idealised frame time (55 fps). This is also not perfect
2054 // since the figure does not represent actual execution time and very hard running scripts will
2055 // never exceed 18ms (though this is a very high number for script execution so is a warning sign).
2056 return ((float)si.MeasurementPeriodExecutionTime / ticksElapsed) * 18.1818f;
2039 } 2057 }
2040 2058
2041 public void SuspendScript(UUID itemID) 2059 public void SuspendScript(UUID itemID)