When scripts are sleeping, don't count that as execution time

Sleeping doesn't use the CPU.
This commit is contained in:
Oren Hurvitz
2015-08-06 09:54:20 +03:00
parent d24528b3bc
commit a568f06b7f
18 changed files with 95 additions and 49 deletions

View File

@@ -103,6 +103,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
/// <remarks>null if co-operative script termination is not active</remarks>
WaitHandle m_coopSleepHandle;
/// <summary>
/// The timer used by the ScriptInstance to measure how long the script has executed.
/// </summary>
private Stopwatch m_executionTimer;
/// <summary>
/// The item that hosts this script
/// </summary>
@@ -262,12 +267,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
};
public void Initialize(
IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item, WaitHandle coopSleepHandle)
IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item, WaitHandle coopSleepHandle,
Stopwatch executionTimer)
{
m_ScriptEngine = scriptEngine;
m_host = host;
m_item = item;
m_coopSleepHandle = coopSleepHandle;
m_executionTimer = executionTimer;
LoadConfig();
@@ -406,10 +413,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
protected virtual void Sleep(int delay)
{
if (m_coopSleepHandle == null)
System.Threading.Thread.Sleep(delay);
else
CheckForCoopTermination(delay);
if (m_executionTimer != null)
m_executionTimer.Stop(); // sleep time doesn't count as execution time, since it doesn't use the CPU
try
{
if (m_coopSleepHandle == null)
System.Threading.Thread.Sleep(delay);
else
CheckForCoopTermination(delay);
}
finally
{
if (m_executionTimer != null)
m_executionTimer.Start();
}
}
/// <summary>

View File

@@ -51,6 +51,7 @@ using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
using System.Diagnostics;
namespace OpenSim.Region.ScriptEngine.Shared.Api
{
@@ -63,7 +64,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
internal IScriptModuleComms m_comms = null;
public void Initialize(
IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item, WaitHandle coopSleepHandle)
IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item, WaitHandle coopSleepHandle,
Stopwatch executionTimer)
{
m_ScriptEngine = scriptEngine;
m_host = host;

View File

@@ -51,6 +51,7 @@ using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
using System.Diagnostics;
namespace OpenSim.Region.ScriptEngine.Shared.Api
{
@@ -66,7 +67,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
internal IScriptModuleComms m_comms = null;
public void Initialize(
IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item, WaitHandle coopSleepHandle)
IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item, WaitHandle coopSleepHandle,
Stopwatch executionTimer)
{
m_ScriptEngine = scriptEngine;
m_host = host;

View File

@@ -41,6 +41,7 @@ using OpenMetaverse.StructuredData;
using Nini.Config;
using OpenSim;
using OpenSim.Framework;
using System.Diagnostics;
using OpenSim.Framework.Console;
using OpenSim.Region.Framework.Interfaces;
@@ -142,14 +143,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
internal float m_ScriptDistanceFactor = 1.0f;
internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >();
/// <summary>
/// The timer used by the ScriptInstance to measure how long the script has executed.
/// </summary>
private Stopwatch m_executionTimer;
protected IUrlModule m_UrlModule = null;
public void Initialize(
IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item, WaitHandle coopSleepHandle)
IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item, WaitHandle coopSleepHandle,
Stopwatch executionTimer)
{
m_ScriptEngine = scriptEngine;
m_host = host;
m_item = item;
m_executionTimer = executionTimer;
m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>();
@@ -432,7 +440,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
delay = (int)((float)delay * m_ScriptDelayFactor);
if (delay == 0)
return;
System.Threading.Thread.Sleep(delay);
if (m_executionTimer != null)
m_executionTimer.Stop(); // sleep time doesn't count as execution time, since it doesn't use the CPU
try
{
System.Threading.Thread.Sleep(delay);
}
finally
{
if (m_executionTimer != null)
m_executionTimer.Start();
}
}
public LSL_Integer osSetTerrainHeight(int x, int y, double val)