aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
diff options
context:
space:
mode:
authorOren Hurvitz2015-07-27 12:16:21 +0300
committerOren Hurvitz2015-08-11 08:42:26 +0100
commita3bed1fbcbcbe19681aa57733f260ef647a33d8e (patch)
tree2092c169cd80ed3db70f1b03d88406f48dc20f44 /OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
parentImproved calculation of Script Execution TimeStarted (diff)
downloadopensim-SC-a3bed1fbcbcbe19681aa57733f260ef647a33d8e.zip
opensim-SC-a3bed1fbcbcbe19681aa57733f260ef647a33d8e.tar.gz
opensim-SC-a3bed1fbcbcbe19681aa57733f260ef647a33d8e.tar.bz2
opensim-SC-a3bed1fbcbcbe19681aa57733f260ef647a33d8e.tar.xz
Report "Script Execution Time" as the time spent executing the script in the last 30 seconds. Use a sliding window to calculate this.
Notes: - This metric provides a better indication of which scripts are taking up a lot of CPU (and therefore should be optimized). - Previously the execution time was reset to 0 in every new measurement period, causing the reported time to fluctuate for no reason. This has been fixed by using a sliding window.
Diffstat (limited to '')
-rwxr-xr-xOpenSim/Region/ScriptEngine/XEngine/XEngine.cs31
1 files changed, 4 insertions, 27 deletions
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index ae02877..5071884 100755
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -2343,7 +2343,6 @@ namespace OpenSim.Region.ScriptEngine.XEngine
2343 2343
2344 public Dictionary<uint, float> GetObjectScriptsExecutionTimes() 2344 public Dictionary<uint, float> GetObjectScriptsExecutionTimes()
2345 { 2345 {
2346 long tickNow = Util.EnvironmentTickCount();
2347 Dictionary<uint, float> topScripts = new Dictionary<uint, float>(); 2346 Dictionary<uint, float> topScripts = new Dictionary<uint, float>();
2348 2347
2349 lock (m_Scripts) 2348 lock (m_Scripts)
@@ -2353,7 +2352,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
2353 if (!topScripts.ContainsKey(si.LocalID)) 2352 if (!topScripts.ContainsKey(si.LocalID))
2354 topScripts[si.RootLocalID] = 0; 2353 topScripts[si.RootLocalID] = 0;
2355 2354
2356 topScripts[si.RootLocalID] += CalculateAdjustedExectionTime(si, tickNow); 2355 topScripts[si.RootLocalID] += GetExectionTime(si);
2357 } 2356 }
2358 } 2357 }
2359 2358
@@ -2367,7 +2366,6 @@ namespace OpenSim.Region.ScriptEngine.XEngine
2367 return 0.0f; 2366 return 0.0f;
2368 } 2367 }
2369 float time = 0.0f; 2368 float time = 0.0f;
2370 long tickNow = Util.EnvironmentTickCount();
2371 IScriptInstance si; 2369 IScriptInstance si;
2372 // Calculate the time for all scripts that this engine is executing 2370 // Calculate the time for all scripts that this engine is executing
2373 // Ignore any others 2371 // Ignore any others
@@ -2376,36 +2374,15 @@ namespace OpenSim.Region.ScriptEngine.XEngine
2376 si = GetInstance(id); 2374 si = GetInstance(id);
2377 if (si != null && si.Running) 2375 if (si != null && si.Running)
2378 { 2376 {
2379 time += CalculateAdjustedExectionTime(si, tickNow); 2377 time += GetExectionTime(si);
2380 } 2378 }
2381 } 2379 }
2382 return time; 2380 return time;
2383 } 2381 }
2384 2382
2385 private float CalculateAdjustedExectionTime(IScriptInstance si, long tickNow) 2383 private float GetExectionTime(IScriptInstance si)
2386 { 2384 {
2387 long ticksElapsed = Util.EnvironmentTickCountSubtract((int)tickNow, (int)si.MeasurementPeriodTickStart); 2385 return (float)si.ExecutionTime.GetSumTime().TotalMilliseconds;
2388
2389 // Avoid divide by zero
2390 if (ticksElapsed == 0)
2391 ticksElapsed = 1;
2392
2393 // Scale execution time to the ideal 55 fps frame time for these reasons.
2394 //
2395 // 1) XEngine does not execute scripts per frame, unlike other script engines. Hence, there is no
2396 // 'script execution time per frame', which is the original purpose of this value.
2397 //
2398 // 2) Giving the raw execution times is misleading since scripts start at different times, making
2399 // it impossible to compare scripts.
2400 //
2401 // 3) Scaling the raw execution time to the time that the script has been running is better but
2402 // is still misleading since a script that has just been rezzed may appear to have been running
2403 // for much longer.
2404 //
2405 // 4) Hence, we scale execution time to an idealised frame time (55 fps). This is also not perfect
2406 // since the figure does not represent actual execution time and very hard running scripts will
2407 // never exceed 18ms (though this is a very high number for script execution so is a warning sign).
2408 return ((float)si.MeasurementPeriodExecutionTime / ticksElapsed) * 18.1818f;
2409 } 2386 }
2410 2387
2411 public void SuspendScript(UUID itemID) 2388 public void SuspendScript(UUID itemID)