aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine
diff options
context:
space:
mode:
authorMelanie2012-03-18 20:44:56 +0000
committerMelanie2012-03-18 20:44:56 +0000
commitc7e302864a2eef7f9587ed22286c96a6074ac5b3 (patch)
tree8f0df2f66811309fd790966770434fa3ff68bfdf /OpenSim/Region/ScriptEngine
parentMerge branch 'ubitwork' (diff)
parentAmend to previous commit: normalize strings ToLower. (diff)
downloadopensim-SC_OLD-c7e302864a2eef7f9587ed22286c96a6074ac5b3.zip
opensim-SC_OLD-c7e302864a2eef7f9587ed22286c96a6074ac5b3.tar.gz
opensim-SC_OLD-c7e302864a2eef7f9587ed22286c96a6074ac5b3.tar.bz2
opensim-SC_OLD-c7e302864a2eef7f9587ed22286c96a6074ac5b3.tar.xz
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
Diffstat (limited to 'OpenSim/Region/ScriptEngine')
-rw-r--r--OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs26
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs109
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs23
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs9
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs15
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs5
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs31
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs5
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs27
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/XEngine.cs61
11 files changed, 307 insertions, 6 deletions
diff --git a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs
index 8762642..b04f6b6 100644
--- a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs
@@ -78,12 +78,38 @@ namespace OpenSim.Region.ScriptEngine.Interfaces
78 /// </summary> 78 /// </summary>
79 string State { get; set; } 79 string State { get; set; }
80 80
81 /// <summary>
82 /// Time the script was last started
83 /// </summary>
84 DateTime TimeStarted { get; }
85
86 /// <summary>
87 /// Tick the last measurement period was started.
88 /// </summary>
89 long MeasurementPeriodTickStart { get; }
90
91 /// <summary>
92 /// Ticks spent executing in the last measurement period.
93 /// </summary>
94 long MeasurementPeriodExecutionTime { get; }
95
81 IScriptEngine Engine { get; } 96 IScriptEngine Engine { get; }
82 UUID AppDomain { get; set; } 97 UUID AppDomain { get; set; }
83 string PrimName { get; } 98 string PrimName { get; }
84 string ScriptName { get; } 99 string ScriptName { get; }
85 UUID ItemID { get; } 100 UUID ItemID { get; }
86 UUID ObjectID { get; } 101 UUID ObjectID { get; }
102
103 /// <summary>
104 /// UUID of the root object for the linkset that the script is in.
105 /// </summary>
106 UUID RootObjectID { get; }
107
108 /// <summary>
109 /// Local id of the root object for the linkset that the script is in.
110 /// </summary>
111 uint RootLocalID { get; }
112
87 uint LocalID { get; } 113 uint LocalID { get; }
88 UUID AssetID { get; } 114 UUID AssetID { get; }
89 Queue EventQueue { get; } 115 Queue EventQueue { get; }
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
index d4facdd..2942104 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
@@ -116,6 +116,115 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
116 wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message); 116 wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message);
117 } 117 }
118 118
119 /// <summary>
120 ///
121 /// </summary>
122 /// <param name="fname">The name of the function to invoke</param>
123 /// <param name="fname">List of parameters</param>
124 /// <returns>string result of the invocation</returns>
125 public string modInvokeS(string fname, params object[] parms)
126 {
127 Type returntype = m_comms.LookupReturnType(fname);
128 if (returntype != typeof(string))
129 MODError(String.Format("return type mismatch for {0}",fname));
130
131 return (string)modInvoke(fname,parms);
132 }
133
134 public int modInvokeI(string fname, params object[] parms)
135 {
136 Type returntype = m_comms.LookupReturnType(fname);
137 if (returntype != typeof(int))
138 MODError(String.Format("return type mismatch for {0}",fname));
139
140 return (int)modInvoke(fname,parms);
141 }
142
143 public float modInvokeF(string fname, params object[] parms)
144 {
145 Type returntype = m_comms.LookupReturnType(fname);
146 if (returntype != typeof(float))
147 MODError(String.Format("return type mismatch for {0}",fname));
148
149 return (float)modInvoke(fname,parms);
150 }
151
152 /// <summary>
153 /// Invokes a preregistered function through the ScriptModuleComms class
154 /// </summary>
155 /// <param name="fname">The name of the function to invoke</param>
156 /// <param name="fname">List of parameters</param>
157 /// <returns>string result of the invocation</returns>
158 protected object modInvoke(string fname, params object[] parms)
159 {
160 if (!m_MODFunctionsEnabled)
161 {
162 MODShoutError("Module command functions not enabled");
163 return "";
164 }
165
166 Type[] signature = m_comms.LookupTypeSignature(fname);
167 if (signature.Length != parms.Length)
168 MODError(String.Format("wrong number of parameters to function {0}",fname));
169
170 object[] convertedParms = new object[parms.Length];
171
172 for (int i = 0; i < parms.Length; i++)
173 {
174 if (parms[i] is LSL_String)
175 {
176 if (signature[i] != typeof(string))
177 MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
178
179 convertedParms[i] = (string)(LSL_String)parms[i];
180 }
181 else if (parms[i] is LSL_Integer)
182 {
183 if (signature[i] != typeof(int))
184 MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
185
186 convertedParms[i] = (int)(LSL_Integer)parms[i];
187 }
188 else if (parms[i] is LSL_Float)
189 {
190 if (signature[i] != typeof(float))
191 MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
192
193 convertedParms[i] = (float)(LSL_Float)parms[i];
194 }
195 else if (parms[i] is LSL_Key)
196 {
197 if (signature[i] != typeof(string))
198 MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
199
200 convertedParms[i] = (string)(LSL_Key)parms[i];
201 }
202 else if (parms[i] is LSL_Rotation)
203 {
204 if (signature[i] != typeof(string))
205 MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
206
207 convertedParms[i] = (string)(LSL_Rotation)parms[i];
208 }
209 else if (parms[i] is LSL_Vector)
210 {
211 if (signature[i] != typeof(string))
212 MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
213
214 convertedParms[i] = (string)(LSL_Vector)parms[i];
215 }
216 else
217 {
218 if (signature[i] != parms[i].GetType())
219 MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
220
221 convertedParms[i] = parms[i];
222 }
223 }
224
225 return m_comms.InvokeOperation(m_itemID,fname,convertedParms);
226 }
227
119 public string modSendCommand(string module, string command, string k) 228 public string modSendCommand(string module, string command, string k)
120 { 229 {
121 if (!m_MODFunctionsEnabled) 230 if (!m_MODFunctionsEnabled)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 8dfc7d2..d140c26 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -3003,5 +3003,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3003 3003
3004 return date.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ"); 3004 return date.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ");
3005 } 3005 }
3006
3007 /// <summary>
3008 /// Get the description from an inventory item
3009 /// </summary>
3010 /// <param name="inventoryName"></param>
3011 /// <returns>Item description</returns>
3012 public LSL_String osGetInventoryDesc(string item)
3013 {
3014 m_host.AddScriptLPS(1);
3015
3016 lock (m_host.TaskInventory)
3017 {
3018 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3019 {
3020 if (inv.Value.Name == item)
3021 {
3022 return inv.Value.Description.ToString();
3023 }
3024 }
3025 }
3026
3027 return String.Empty;
3028 }
3006 } 3029 }
3007} 3030}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs
index e08eca5..756a59f 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs
@@ -40,6 +40,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
40{ 40{
41 public interface IMOD_Api 41 public interface IMOD_Api
42 { 42 {
43 // Invocation functions
44 string modInvokeS(string fname, params object[] parms);
45 int modInvokeI(string fname, params object[] parms);
46 float modInvokeF(string fname, params object[] parms);
47 // vector modInvokeV(string fname, params object[] parms);
48 // rotation modInvokeV(string fname, params object[] parms);
49 // key modInvokeK(string fname, params object[] parms);
50 // list modInvokeL(string fname, params object[] parms);
51
43 //Module functions 52 //Module functions
44 string modSendCommand(string modules, string command, string k); 53 string modSendCommand(string modules, string command, string k);
45 } 54 }
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index e59d3a8..1f4c4b1 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -229,5 +229,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
229 LSL_List osGetAvatarList(); 229 LSL_List osGetAvatarList();
230 230
231 LSL_String osUnixTimeToTimestamp(long time); 231 LSL_String osUnixTimeToTimestamp(long time);
232
233 LSL_String osGetInventoryDesc(string item);
232 } 234 }
233} 235}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs
index 6525c76..04b7f14 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs
@@ -58,6 +58,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
58 m_MOD_Functions = (IMOD_Api)api; 58 m_MOD_Functions = (IMOD_Api)api;
59 } 59 }
60 60
61 public string modInvokeS(string fname, params object[] parms)
62 {
63 return m_MOD_Functions.modInvokeS(fname, parms);
64 }
65
66 public int modInvokeI(string fname, params object[] parms)
67 {
68 return m_MOD_Functions.modInvokeI(fname, parms);
69 }
70
71 public float modInvokeF(string fname, params object[] parms)
72 {
73 return m_MOD_Functions.modInvokeF(fname, parms);
74 }
75
61 public string modSendCommand(string module, string command, string k) 76 public string modSendCommand(string module, string command, string k)
62 { 77 {
63 return m_MOD_Functions.modSendCommand(module, command, k); 78 return m_MOD_Functions.modSendCommand(module, command, k);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
index e048da2..09e5992 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -863,5 +863,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
863 { 863 {
864 return m_OSSL_Functions.osUnixTimeToTimestamp(time); 864 return m_OSSL_Functions.osUnixTimeToTimestamp(time);
865 } 865 }
866
867 public LSL_String osGetInventoryDesc(string item)
868 {
869 return m_OSSL_Functions.osGetInventoryDesc(item);
870 }
866 } 871 }
867} 872}
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs
index 65d3b9b..b24f016 100644
--- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs
@@ -32,6 +32,8 @@ using System.Reflection;
32using log4net; 32using log4net;
33using Tools; 33using Tools;
34 34
35using OpenSim.Region.Framework.Interfaces;
36
35namespace OpenSim.Region.ScriptEngine.Shared.CodeTools 37namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
36{ 38{
37 public class CSCodeGenerator : ICodeConverter 39 public class CSCodeGenerator : ICodeConverter
@@ -45,12 +47,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
45 private int m_CSharpLine; // the current line of generated C# code 47 private int m_CSharpLine; // the current line of generated C# code
46 private int m_CSharpCol; // the current column of generated C# code 48 private int m_CSharpCol; // the current column of generated C# code
47 private List<string> m_warnings = new List<string>(); 49 private List<string> m_warnings = new List<string>();
50 private IScriptModuleComms m_comms = null;
48 51
49 /// <summary> 52 /// <summary>
50 /// Creates an 'empty' CSCodeGenerator instance. 53 /// Creates an 'empty' CSCodeGenerator instance.
51 /// </summary> 54 /// </summary>
52 public CSCodeGenerator() 55 public CSCodeGenerator()
53 { 56 {
57 m_comms = null;
58 ResetCounters();
59 }
60
61 public CSCodeGenerator(IScriptModuleComms comms)
62 {
63 m_comms = comms;
54 ResetCounters(); 64 ResetCounters();
55 } 65 }
56 66
@@ -866,8 +876,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
866 { 876 {
867 string retstr = String.Empty; 877 string retstr = String.Empty;
868 878
869 retstr += Generate(String.Format("{0}(", CheckName(fc.Id)), fc); 879 string modinvoke = null;
870 880 if (m_comms != null)
881 modinvoke = m_comms.LookupModInvocation(fc.Id);
882
883 if (modinvoke != null)
884 {
885 if (fc.kids[0] is ArgumentList)
886 {
887 if ((fc.kids[0] as ArgumentList).kids.Count == 0)
888 retstr += Generate(String.Format("{0}(\"{1}\"",modinvoke,fc.Id), fc);
889 else
890 retstr += Generate(String.Format("{0}(\"{1}\",",modinvoke,fc.Id), fc);
891 }
892 }
893 else
894 {
895 retstr += Generate(String.Format("{0}(", CheckName(fc.Id)), fc);
896 }
897
871 foreach (SYMBOL kid in fc.kids) 898 foreach (SYMBOL kid in fc.kids)
872 retstr += GenerateNode(kid); 899 retstr += GenerateNode(kid);
873 900
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
index c10143b..8f2ec49 100644
--- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
@@ -35,6 +35,7 @@ using Microsoft.CSharp;
35//using Microsoft.JScript; 35//using Microsoft.JScript;
36using Microsoft.VisualBasic; 36using Microsoft.VisualBasic;
37using log4net; 37using log4net;
38
38using OpenSim.Region.Framework.Interfaces; 39using OpenSim.Region.Framework.Interfaces;
39using OpenSim.Region.ScriptEngine.Interfaces; 40using OpenSim.Region.ScriptEngine.Interfaces;
40using OpenMetaverse; 41using OpenMetaverse;
@@ -293,6 +294,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
293 { 294 {
294// m_log.DebugFormat("[Compiler]: Compiling script\n{0}", Script); 295// m_log.DebugFormat("[Compiler]: Compiling script\n{0}", Script);
295 296
297 IScriptModuleComms comms = m_scriptEngine.World.RequestModuleInterface<IScriptModuleComms>();
298
296 linemap = null; 299 linemap = null;
297 m_warnings.Clear(); 300 m_warnings.Clear();
298 301
@@ -382,7 +385,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
382 if (language == enumCompileType.lsl) 385 if (language == enumCompileType.lsl)
383 { 386 {
384 // Its LSL, convert it to C# 387 // Its LSL, convert it to C#
385 LSL_Converter = (ICodeConverter)new CSCodeGenerator(); 388 LSL_Converter = (ICodeConverter)new CSCodeGenerator(comms);
386 compileScript = LSL_Converter.Convert(Script); 389 compileScript = LSL_Converter.Convert(Script);
387 390
388 // copy converter warnings into our warnings. 391 // copy converter warnings into our warnings.
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
index f40da01..ff1f277 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
@@ -165,6 +165,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
165 165
166 public uint LocalID { get; private set; } 166 public uint LocalID { get; private set; }
167 167
168 public UUID RootObjectID { get; private set; }
169
170 public uint RootLocalID { get; private set; }
171
168 public UUID AssetID { get; private set; } 172 public UUID AssetID { get; private set; }
169 173
170 public Queue EventQueue { get; private set; } 174 public Queue EventQueue { get; private set; }
@@ -173,6 +177,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
173 177
174 public TaskInventoryItem ScriptTask { get; private set; } 178 public TaskInventoryItem ScriptTask { get; private set; }
175 179
180 public DateTime TimeStarted { get; private set; }
181
182 public long MeasurementPeriodTickStart { get; private set; }
183
184 public long MeasurementPeriodExecutionTime { get; private set; }
185
186 public static readonly long MaxMeasurementPeriod = 30 * TimeSpan.TicksPerMinute;
187
176 public void ClearQueue() 188 public void ClearQueue()
177 { 189 {
178 m_TimerQueued = false; 190 m_TimerQueued = false;
@@ -191,6 +203,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
191 Engine = engine; 203 Engine = engine;
192 LocalID = part.LocalId; 204 LocalID = part.LocalId;
193 ObjectID = part.UUID; 205 ObjectID = part.UUID;
206 RootLocalID = part.ParentGroup.LocalId;
207 RootObjectID = part.ParentGroup.UUID;
194 ItemID = itemID; 208 ItemID = itemID;
195 AssetID = assetID; 209 AssetID = assetID;
196 PrimName = primName; 210 PrimName = primName;
@@ -459,6 +473,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
459 473
460 Running = true; 474 Running = true;
461 475
476 TimeStarted = DateTime.Now;
477 MeasurementPeriodTickStart = Util.EnvironmentTickCount();
478 MeasurementPeriodExecutionTime = 0;
479
462 if (EventQueue.Count > 0) 480 if (EventQueue.Count > 0)
463 { 481 {
464 if (m_CurrentWorkItem == null) 482 if (m_CurrentWorkItem == null)
@@ -712,8 +730,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
712 m_EventStart = DateTime.Now; 730 m_EventStart = DateTime.Now;
713 m_InEvent = true; 731 m_InEvent = true;
714 732
733 int start = Util.EnvironmentTickCount();
734
735 // Reset the measurement period when we reach the end of the current one.
736 if (start - MeasurementPeriodTickStart > MaxMeasurementPeriod)
737 MeasurementPeriodTickStart = start;
738
715 m_Script.ExecuteEvent(State, data.EventName, data.Params); 739 m_Script.ExecuteEvent(State, data.EventName, data.Params);
716 740
741 MeasurementPeriodExecutionTime += Util.EnvironmentTickCount() - start;
742
717 m_InEvent = false; 743 m_InEvent = false;
718 m_CurrentEvent = String.Empty; 744 m_CurrentEvent = String.Empty;
719 745
@@ -722,7 +748,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
722 // This will be the very first event we deliver 748 // This will be the very first event we deliver
723 // (state_entry) in default state 749 // (state_entry) in default state
724 // 750 //
725
726 SaveState(m_Assembly); 751 SaveState(m_Assembly);
727 752
728 m_SaveState = false; 753 m_SaveState = false;
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index ee5f519..eb10975 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -448,6 +448,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine
448 if (!(MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_Scene)) 448 if (!(MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_Scene))
449 return; 449 return;
450 450
451 MainConsole.Instance.OutputFormat(GetStatusReport());
452 }
453
454 public string GetStatusReport()
455 {
451 StringBuilder sb = new StringBuilder(); 456 StringBuilder sb = new StringBuilder();
452 sb.AppendFormat("Status of XEngine instance for {0}\n", m_Scene.RegionInfo.RegionName); 457 sb.AppendFormat("Status of XEngine instance for {0}\n", m_Scene.RegionInfo.RegionName);
453 458
@@ -475,7 +480,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
475 Listener l = AsyncCommandManager.GetListenerPlugin(this); 480 Listener l = AsyncCommandManager.GetListenerPlugin(this);
476 sb.AppendFormat("Listeners : {0}\n", l.ListenerCount); 481 sb.AppendFormat("Listeners : {0}\n", l.ListenerCount);
477 482
478 MainConsole.Instance.OutputFormat(sb.ToString()); 483 return sb.ToString();
479 } 484 }
480 485
481 public void HandleShowScripts(string module, string[] cmdparams) 486 public void HandleShowScripts(string module, string[] cmdparams)
@@ -1154,7 +1159,6 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1154 1159
1155 if (!m_PrimObjects[localID].Contains(itemID)) 1160 if (!m_PrimObjects[localID].Contains(itemID))
1156 m_PrimObjects[localID].Add(itemID); 1161 m_PrimObjects[localID].Add(itemID);
1157
1158 } 1162 }
1159 1163
1160 if (!m_Assemblies.ContainsKey(assetID)) 1164 if (!m_Assemblies.ContainsKey(assetID))
@@ -1981,6 +1985,59 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1981 } 1985 }
1982 } 1986 }
1983 1987
1988 public Dictionary<uint, float> GetObjectScriptsExecutionTimes()
1989 {
1990 long tickNow = Util.EnvironmentTickCount();
1991 Dictionary<uint, float> topScripts = new Dictionary<uint, float>();
1992
1993 lock (m_Scripts)
1994 {
1995 foreach (IScriptInstance si in m_Scripts.Values)
1996 {
1997 if (!topScripts.ContainsKey(si.LocalID))
1998 topScripts[si.RootLocalID] = 0;
1999
2000// long ticksElapsed = tickNow - si.MeasurementPeriodTickStart;
2001// float framesElapsed = ticksElapsed / (18.1818 * TimeSpan.TicksPerMillisecond);
2002
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
2016 // Scale execution time to the ideal 55 fps frame time for these reasons.
2017 //
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
2034 topScripts[si.RootLocalID] += adjustedExecutionTime;
2035 }
2036 }
2037
2038 return topScripts;
2039 }
2040
1984 public void SuspendScript(UUID itemID) 2041 public void SuspendScript(UUID itemID)
1985 { 2042 {
1986// m_log.DebugFormat("[XEngine]: Received request to suspend script with ID {0}", itemID); 2043// m_log.DebugFormat("[XEngine]: Received request to suspend script with ID {0}", itemID);