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.cs100
1 files changed, 60 insertions, 40 deletions
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index 1e0f01f..eeb125e 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)
@@ -1898,9 +1902,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1898 // if there already exists a file at that location, it may be locked. 1902 // if there already exists a file at that location, it may be locked.
1899 m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", path, ex.Message); 1903 m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", path, ex.Message);
1900 } 1904 }
1905
1906 string textpath = path + ".text";
1901 try 1907 try
1902 { 1908 {
1903 using (FileStream fs = File.Create(path + ".text")) 1909 using (FileStream fs = File.Create(textpath))
1904 { 1910 {
1905 using (StreamWriter sw = new StreamWriter(fs)) 1911 using (StreamWriter sw = new StreamWriter(fs))
1906 { 1912 {
@@ -1913,7 +1919,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1913 catch (IOException ex) 1919 catch (IOException ex)
1914 { 1920 {
1915 // if there already exists a file at that location, it may be locked. 1921 // if there already exists a file at that location, it may be locked.
1916 m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", path, ex.Message); 1922 m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", textpath, ex.Message);
1917 } 1923 }
1918 } 1924 }
1919 } 1925 }
@@ -1962,7 +1968,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1962 catch (IOException ex) 1968 catch (IOException ex)
1963 { 1969 {
1964 // if there already exists a file at that location, it may be locked. 1970 // if there already exists a file at that location, it may be locked.
1965 m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", statepath, ex.Message); 1971 m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", mappath, ex.Message);
1966 } 1972 }
1967 } 1973 }
1968 1974
@@ -1997,45 +2003,59 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1997 if (!topScripts.ContainsKey(si.LocalID)) 2003 if (!topScripts.ContainsKey(si.LocalID))
1998 topScripts[si.RootLocalID] = 0; 2004 topScripts[si.RootLocalID] = 0;
1999 2005
2000// long ticksElapsed = tickNow - si.MeasurementPeriodTickStart; 2006 topScripts[si.RootLocalID] += CalculateAdjustedExectionTime(si, tickNow);
2001// float framesElapsed = ticksElapsed / (18.1818 * TimeSpan.TicksPerMillisecond); 2007 }
2002 2008 }
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 2009
2016 // Scale execution time to the ideal 55 fps frame time for these reasons. 2010 return topScripts;
2017 // 2011 }
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 2012
2034 topScripts[si.RootLocalID] += adjustedExecutionTime; 2013 public float GetScriptExecutionTime(List<UUID> itemIDs)
2014 {
2015 if (itemIDs == null|| itemIDs.Count == 0)
2016 {
2017 return 0.0f;
2018 }
2019 float time = 0.0f;
2020 long tickNow = Util.EnvironmentTickCount();
2021 IScriptInstance si;
2022 // Calculate the time for all scripts that this engine is executing
2023 // Ignore any others
2024 foreach (UUID id in itemIDs)
2025 {
2026 si = GetInstance(id);
2027 if (si != null && si.Running)
2028 {
2029 time += CalculateAdjustedExectionTime(si, tickNow);
2035 } 2030 }
2036 } 2031 }
2032 return time;
2033 }
2037 2034
2038 return topScripts; 2035 private float CalculateAdjustedExectionTime(IScriptInstance si, long tickNow)
2036 {
2037 long ticksElapsed = tickNow - si.MeasurementPeriodTickStart;
2038
2039 // Avoid divide by zero
2040 if (ticksElapsed == 0)
2041 ticksElapsed = 1;
2042
2043 // Scale execution time to the ideal 55 fps frame time for these reasons.
2044 //
2045 // 1) XEngine does not execute scripts per frame, unlike other script engines. Hence, there is no
2046 // 'script execution time per frame', which is the original purpose of this value.
2047 //
2048 // 2) Giving the raw execution times is misleading since scripts start at different times, making
2049 // it impossible to compare scripts.
2050 //
2051 // 3) Scaling the raw execution time to the time that the script has been running is better but
2052 // is still misleading since a script that has just been rezzed may appear to have been running
2053 // for much longer.
2054 //
2055 // 4) Hence, we scale execution time to an idealised frame time (55 fps). This is also not perfect
2056 // since the figure does not represent actual execution time and very hard running scripts will
2057 // never exceed 18ms (though this is a very high number for script execution so is a warning sign).
2058 return ((float)si.MeasurementPeriodExecutionTime / ticksElapsed) * 18.1818f;
2039 } 2059 }
2040 2060
2041 public void SuspendScript(UUID itemID) 2061 public void SuspendScript(UUID itemID)