mirror of
https://github.com/opensim/opensim.git
synced 2026-08-04 16:22:50 +08:00
Merge branch 'master' into careminster
Conflicts: OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs OpenSim/Region/Framework/Scenes/Scene.cs
This commit is contained in:
@@ -78,12 +78,38 @@ namespace OpenSim.Region.ScriptEngine.Interfaces
|
||||
/// </summary>
|
||||
string State { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Time the script was last started
|
||||
/// </summary>
|
||||
DateTime TimeStarted { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Tick the last measurement period was started.
|
||||
/// </summary>
|
||||
long MeasurementPeriodTickStart { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Ticks spent executing in the last measurement period.
|
||||
/// </summary>
|
||||
long MeasurementPeriodExecutionTime { get; }
|
||||
|
||||
IScriptEngine Engine { get; }
|
||||
UUID AppDomain { get; set; }
|
||||
string PrimName { get; }
|
||||
string ScriptName { get; }
|
||||
UUID ItemID { get; }
|
||||
UUID ObjectID { get; }
|
||||
|
||||
/// <summary>
|
||||
/// UUID of the root object for the linkset that the script is in.
|
||||
/// </summary>
|
||||
UUID RootObjectID { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Local id of the root object for the linkset that the script is in.
|
||||
/// </summary>
|
||||
uint RootLocalID { get; }
|
||||
|
||||
uint LocalID { get; }
|
||||
UUID AssetID { get; }
|
||||
Queue EventQueue { get; }
|
||||
|
||||
@@ -116,6 +116,115 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||
wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="fname">The name of the function to invoke</param>
|
||||
/// <param name="fname">List of parameters</param>
|
||||
/// <returns>string result of the invocation</returns>
|
||||
public string modInvokeS(string fname, params object[] parms)
|
||||
{
|
||||
Type returntype = m_comms.LookupReturnType(fname);
|
||||
if (returntype != typeof(string))
|
||||
MODError(String.Format("return type mismatch for {0}",fname));
|
||||
|
||||
return (string)modInvoke(fname,parms);
|
||||
}
|
||||
|
||||
public int modInvokeI(string fname, params object[] parms)
|
||||
{
|
||||
Type returntype = m_comms.LookupReturnType(fname);
|
||||
if (returntype != typeof(int))
|
||||
MODError(String.Format("return type mismatch for {0}",fname));
|
||||
|
||||
return (int)modInvoke(fname,parms);
|
||||
}
|
||||
|
||||
public float modInvokeF(string fname, params object[] parms)
|
||||
{
|
||||
Type returntype = m_comms.LookupReturnType(fname);
|
||||
if (returntype != typeof(float))
|
||||
MODError(String.Format("return type mismatch for {0}",fname));
|
||||
|
||||
return (float)modInvoke(fname,parms);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes a preregistered function through the ScriptModuleComms class
|
||||
/// </summary>
|
||||
/// <param name="fname">The name of the function to invoke</param>
|
||||
/// <param name="fname">List of parameters</param>
|
||||
/// <returns>string result of the invocation</returns>
|
||||
protected object modInvoke(string fname, params object[] parms)
|
||||
{
|
||||
if (!m_MODFunctionsEnabled)
|
||||
{
|
||||
MODShoutError("Module command functions not enabled");
|
||||
return "";
|
||||
}
|
||||
|
||||
Type[] signature = m_comms.LookupTypeSignature(fname);
|
||||
if (signature.Length != parms.Length)
|
||||
MODError(String.Format("wrong number of parameters to function {0}",fname));
|
||||
|
||||
object[] convertedParms = new object[parms.Length];
|
||||
|
||||
for (int i = 0; i < parms.Length; i++)
|
||||
{
|
||||
if (parms[i] is LSL_String)
|
||||
{
|
||||
if (signature[i] != typeof(string))
|
||||
MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
|
||||
|
||||
convertedParms[i] = (string)(LSL_String)parms[i];
|
||||
}
|
||||
else if (parms[i] is LSL_Integer)
|
||||
{
|
||||
if (signature[i] != typeof(int))
|
||||
MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
|
||||
|
||||
convertedParms[i] = (int)(LSL_Integer)parms[i];
|
||||
}
|
||||
else if (parms[i] is LSL_Float)
|
||||
{
|
||||
if (signature[i] != typeof(float))
|
||||
MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
|
||||
|
||||
convertedParms[i] = (float)(LSL_Float)parms[i];
|
||||
}
|
||||
else if (parms[i] is LSL_Key)
|
||||
{
|
||||
if (signature[i] != typeof(string))
|
||||
MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
|
||||
|
||||
convertedParms[i] = (string)(LSL_Key)parms[i];
|
||||
}
|
||||
else if (parms[i] is LSL_Rotation)
|
||||
{
|
||||
if (signature[i] != typeof(string))
|
||||
MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
|
||||
|
||||
convertedParms[i] = (string)(LSL_Rotation)parms[i];
|
||||
}
|
||||
else if (parms[i] is LSL_Vector)
|
||||
{
|
||||
if (signature[i] != typeof(string))
|
||||
MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
|
||||
|
||||
convertedParms[i] = (string)(LSL_Vector)parms[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (signature[i] != parms[i].GetType())
|
||||
MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
|
||||
|
||||
convertedParms[i] = parms[i];
|
||||
}
|
||||
}
|
||||
|
||||
return m_comms.InvokeOperation(m_itemID,fname,convertedParms);
|
||||
}
|
||||
|
||||
public string modSendCommand(string module, string command, string k)
|
||||
{
|
||||
if (!m_MODFunctionsEnabled)
|
||||
|
||||
@@ -3003,5 +3003,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||
|
||||
return date.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the description from an inventory item
|
||||
/// </summary>
|
||||
/// <param name="inventoryName"></param>
|
||||
/// <returns>Item description</returns>
|
||||
public LSL_String osGetInventoryDesc(string item)
|
||||
{
|
||||
m_host.AddScriptLPS(1);
|
||||
|
||||
lock (m_host.TaskInventory)
|
||||
{
|
||||
foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
|
||||
{
|
||||
if (inv.Value.Name == item)
|
||||
{
|
||||
return inv.Value.Description.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return String.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
|
||||
{
|
||||
public interface IMOD_Api
|
||||
{
|
||||
// Invocation functions
|
||||
string modInvokeS(string fname, params object[] parms);
|
||||
int modInvokeI(string fname, params object[] parms);
|
||||
float modInvokeF(string fname, params object[] parms);
|
||||
// vector modInvokeV(string fname, params object[] parms);
|
||||
// rotation modInvokeV(string fname, params object[] parms);
|
||||
// key modInvokeK(string fname, params object[] parms);
|
||||
// list modInvokeL(string fname, params object[] parms);
|
||||
|
||||
//Module functions
|
||||
string modSendCommand(string modules, string command, string k);
|
||||
}
|
||||
|
||||
@@ -229,5 +229,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
|
||||
LSL_List osGetAvatarList();
|
||||
|
||||
LSL_String osUnixTimeToTimestamp(long time);
|
||||
|
||||
LSL_String osGetInventoryDesc(string item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +58,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
|
||||
m_MOD_Functions = (IMOD_Api)api;
|
||||
}
|
||||
|
||||
public string modInvokeS(string fname, params object[] parms)
|
||||
{
|
||||
return m_MOD_Functions.modInvokeS(fname, parms);
|
||||
}
|
||||
|
||||
public int modInvokeI(string fname, params object[] parms)
|
||||
{
|
||||
return m_MOD_Functions.modInvokeI(fname, parms);
|
||||
}
|
||||
|
||||
public float modInvokeF(string fname, params object[] parms)
|
||||
{
|
||||
return m_MOD_Functions.modInvokeF(fname, parms);
|
||||
}
|
||||
|
||||
public string modSendCommand(string module, string command, string k)
|
||||
{
|
||||
return m_MOD_Functions.modSendCommand(module, command, k);
|
||||
|
||||
@@ -863,5 +863,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
|
||||
{
|
||||
return m_OSSL_Functions.osUnixTimeToTimestamp(time);
|
||||
}
|
||||
|
||||
public LSL_String osGetInventoryDesc(string item)
|
||||
{
|
||||
return m_OSSL_Functions.osGetInventoryDesc(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ using System.Reflection;
|
||||
using log4net;
|
||||
using Tools;
|
||||
|
||||
using OpenSim.Region.Framework.Interfaces;
|
||||
|
||||
namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||
{
|
||||
public class CSCodeGenerator : ICodeConverter
|
||||
@@ -45,12 +47,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||
private int m_CSharpLine; // the current line of generated C# code
|
||||
private int m_CSharpCol; // the current column of generated C# code
|
||||
private List<string> m_warnings = new List<string>();
|
||||
private IScriptModuleComms m_comms = null;
|
||||
|
||||
/// <summary>
|
||||
/// Creates an 'empty' CSCodeGenerator instance.
|
||||
/// </summary>
|
||||
public CSCodeGenerator()
|
||||
{
|
||||
m_comms = null;
|
||||
ResetCounters();
|
||||
}
|
||||
|
||||
public CSCodeGenerator(IScriptModuleComms comms)
|
||||
{
|
||||
m_comms = comms;
|
||||
ResetCounters();
|
||||
}
|
||||
|
||||
@@ -866,8 +876,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||
{
|
||||
string retstr = String.Empty;
|
||||
|
||||
retstr += Generate(String.Format("{0}(", CheckName(fc.Id)), fc);
|
||||
|
||||
string modinvoke = null;
|
||||
if (m_comms != null)
|
||||
modinvoke = m_comms.LookupModInvocation(fc.Id);
|
||||
|
||||
if (modinvoke != null)
|
||||
{
|
||||
if (fc.kids[0] is ArgumentList)
|
||||
{
|
||||
if ((fc.kids[0] as ArgumentList).kids.Count == 0)
|
||||
retstr += Generate(String.Format("{0}(\"{1}\"",modinvoke,fc.Id), fc);
|
||||
else
|
||||
retstr += Generate(String.Format("{0}(\"{1}\",",modinvoke,fc.Id), fc);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
retstr += Generate(String.Format("{0}(", CheckName(fc.Id)), fc);
|
||||
}
|
||||
|
||||
foreach (SYMBOL kid in fc.kids)
|
||||
retstr += GenerateNode(kid);
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ using Microsoft.CSharp;
|
||||
//using Microsoft.JScript;
|
||||
using Microsoft.VisualBasic;
|
||||
using log4net;
|
||||
|
||||
using OpenSim.Region.Framework.Interfaces;
|
||||
using OpenSim.Region.ScriptEngine.Interfaces;
|
||||
using OpenMetaverse;
|
||||
@@ -293,6 +294,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||
{
|
||||
// m_log.DebugFormat("[Compiler]: Compiling script\n{0}", Script);
|
||||
|
||||
IScriptModuleComms comms = m_scriptEngine.World.RequestModuleInterface<IScriptModuleComms>();
|
||||
|
||||
linemap = null;
|
||||
m_warnings.Clear();
|
||||
|
||||
@@ -382,7 +385,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||
if (language == enumCompileType.lsl)
|
||||
{
|
||||
// Its LSL, convert it to C#
|
||||
LSL_Converter = (ICodeConverter)new CSCodeGenerator();
|
||||
LSL_Converter = (ICodeConverter)new CSCodeGenerator(comms);
|
||||
compileScript = LSL_Converter.Convert(Script);
|
||||
|
||||
// copy converter warnings into our warnings.
|
||||
|
||||
@@ -165,6 +165,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
||||
|
||||
public uint LocalID { get; private set; }
|
||||
|
||||
public UUID RootObjectID { get; private set; }
|
||||
|
||||
public uint RootLocalID { get; private set; }
|
||||
|
||||
public UUID AssetID { get; private set; }
|
||||
|
||||
public Queue EventQueue { get; private set; }
|
||||
@@ -173,6 +177,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
||||
|
||||
public TaskInventoryItem ScriptTask { get; private set; }
|
||||
|
||||
public DateTime TimeStarted { get; private set; }
|
||||
|
||||
public long MeasurementPeriodTickStart { get; private set; }
|
||||
|
||||
public long MeasurementPeriodExecutionTime { get; private set; }
|
||||
|
||||
public static readonly long MaxMeasurementPeriod = 30 * TimeSpan.TicksPerMinute;
|
||||
|
||||
public void ClearQueue()
|
||||
{
|
||||
m_TimerQueued = false;
|
||||
@@ -191,6 +203,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
||||
Engine = engine;
|
||||
LocalID = part.LocalId;
|
||||
ObjectID = part.UUID;
|
||||
RootLocalID = part.ParentGroup.LocalId;
|
||||
RootObjectID = part.ParentGroup.UUID;
|
||||
ItemID = itemID;
|
||||
AssetID = assetID;
|
||||
PrimName = primName;
|
||||
@@ -459,6 +473,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
||||
|
||||
Running = true;
|
||||
|
||||
TimeStarted = DateTime.Now;
|
||||
MeasurementPeriodTickStart = Util.EnvironmentTickCount();
|
||||
MeasurementPeriodExecutionTime = 0;
|
||||
|
||||
if (EventQueue.Count > 0)
|
||||
{
|
||||
if (m_CurrentWorkItem == null)
|
||||
@@ -712,8 +730,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
||||
m_EventStart = DateTime.Now;
|
||||
m_InEvent = true;
|
||||
|
||||
int start = Util.EnvironmentTickCount();
|
||||
|
||||
// Reset the measurement period when we reach the end of the current one.
|
||||
if (start - MeasurementPeriodTickStart > MaxMeasurementPeriod)
|
||||
MeasurementPeriodTickStart = start;
|
||||
|
||||
m_Script.ExecuteEvent(State, data.EventName, data.Params);
|
||||
|
||||
MeasurementPeriodExecutionTime += Util.EnvironmentTickCount() - start;
|
||||
|
||||
m_InEvent = false;
|
||||
m_CurrentEvent = String.Empty;
|
||||
|
||||
@@ -722,7 +748,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
||||
// This will be the very first event we deliver
|
||||
// (state_entry) in default state
|
||||
//
|
||||
|
||||
SaveState(m_Assembly);
|
||||
|
||||
m_SaveState = false;
|
||||
|
||||
@@ -448,6 +448,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
||||
if (!(MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_Scene))
|
||||
return;
|
||||
|
||||
MainConsole.Instance.OutputFormat(GetStatusReport());
|
||||
}
|
||||
|
||||
public string GetStatusReport()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendFormat("Status of XEngine instance for {0}\n", m_Scene.RegionInfo.RegionName);
|
||||
|
||||
@@ -475,7 +480,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
||||
Listener l = AsyncCommandManager.GetListenerPlugin(this);
|
||||
sb.AppendFormat("Listeners : {0}\n", l.ListenerCount);
|
||||
|
||||
MainConsole.Instance.OutputFormat(sb.ToString());
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public void HandleShowScripts(string module, string[] cmdparams)
|
||||
@@ -1154,7 +1159,6 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
||||
|
||||
if (!m_PrimObjects[localID].Contains(itemID))
|
||||
m_PrimObjects[localID].Add(itemID);
|
||||
|
||||
}
|
||||
|
||||
if (!m_Assemblies.ContainsKey(assetID))
|
||||
@@ -1981,6 +1985,59 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<uint, float> GetObjectScriptsExecutionTimes()
|
||||
{
|
||||
long tickNow = Util.EnvironmentTickCount();
|
||||
Dictionary<uint, float> topScripts = new Dictionary<uint, float>();
|
||||
|
||||
lock (m_Scripts)
|
||||
{
|
||||
foreach (IScriptInstance si in m_Scripts.Values)
|
||||
{
|
||||
if (!topScripts.ContainsKey(si.LocalID))
|
||||
topScripts[si.RootLocalID] = 0;
|
||||
|
||||
// long ticksElapsed = tickNow - si.MeasurementPeriodTickStart;
|
||||
// float framesElapsed = ticksElapsed / (18.1818 * TimeSpan.TicksPerMillisecond);
|
||||
|
||||
// Execution time of the script adjusted by it's measurement period to make scripts started at
|
||||
// different times comparable.
|
||||
// float adjustedExecutionTime
|
||||
// = (float)si.MeasurementPeriodExecutionTime
|
||||
// / ((float)(tickNow - si.MeasurementPeriodTickStart) / ScriptInstance.MaxMeasurementPeriod)
|
||||
// / TimeSpan.TicksPerMillisecond;
|
||||
|
||||
long ticksElapsed = tickNow - si.MeasurementPeriodTickStart;
|
||||
|
||||
// Avoid divide by zerp
|
||||
if (ticksElapsed == 0)
|
||||
ticksElapsed = 1;
|
||||
|
||||
// Scale execution time to the ideal 55 fps frame time for these reasons.
|
||||
//
|
||||
// 1) XEngine does not execute scripts per frame, unlike other script engines. Hence, there is no
|
||||
// 'script execution time per frame', which is the original purpose of this value.
|
||||
//
|
||||
// 2) Giving the raw execution times is misleading since scripts start at different times, making
|
||||
// it impossible to compare scripts.
|
||||
//
|
||||
// 3) Scaling the raw execution time to the time that the script has been running is better but
|
||||
// is still misleading since a script that has just been rezzed may appear to have been running
|
||||
// for much longer.
|
||||
//
|
||||
// 4) Hence, we scale execution time to an idealised frame time (55 fps). This is also not perfect
|
||||
// since the figure does not represent actual execution time and very hard running scripts will
|
||||
// never exceed 18ms (though this is a very high number for script execution so is a warning sign).
|
||||
float adjustedExecutionTime
|
||||
= ((float)si.MeasurementPeriodExecutionTime / ticksElapsed) * 18.1818f;
|
||||
|
||||
topScripts[si.RootLocalID] += adjustedExecutionTime;
|
||||
}
|
||||
}
|
||||
|
||||
return topScripts;
|
||||
}
|
||||
|
||||
public void SuspendScript(UUID itemID)
|
||||
{
|
||||
// m_log.DebugFormat("[XEngine]: Received request to suspend script with ID {0}", itemID);
|
||||
|
||||
Reference in New Issue
Block a user