aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2012-12-12 23:13:34 +0000
committerJustin Clark-Casey (justincc)2012-12-12 23:13:34 +0000
commit047270bdc83d029486215a418fada27b225dbab0 (patch)
tree8bb1b091b67d322a56ae1d25bb5511a23369c03a /OpenSim/Region/ScriptEngine
parentAdd asset id to "show script" and "show scripts" command output to make it ea... (diff)
downloadopensim-SC_OLD-047270bdc83d029486215a418fada27b225dbab0.zip
opensim-SC_OLD-047270bdc83d029486215a418fada27b225dbab0.tar.gz
opensim-SC_OLD-047270bdc83d029486215a418fada27b225dbab0.tar.bz2
opensim-SC_OLD-047270bdc83d029486215a418fada27b225dbab0.tar.xz
Add "debug script log" command to allow setting a numeric debug level on individual IScriptInstances for debugging purposes.
Current, state changes and event fires can be logged for individual scripts. See command help for more details.
Diffstat (limited to 'OpenSim/Region/ScriptEngine')
-rw-r--r--OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs12
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs37
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/XEngine.cs53
3 files changed, 89 insertions, 13 deletions
diff --git a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs
index 0cef550..00a99c3 100644
--- a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs
@@ -59,6 +59,18 @@ namespace OpenSim.Region.ScriptEngine.Interfaces
59 public interface IScriptInstance 59 public interface IScriptInstance
60 { 60 {
61 /// <summary> 61 /// <summary>
62 /// Debug level for this script instance.
63 /// </summary>
64 /// <remarks>
65 /// Level == 0, no extra data is logged.
66 /// Level >= 1, state changes are logged.
67 /// Level >= 2, event firing is logged.
68 /// <value>
69 /// The debug level.
70 /// </value>
71 int DebugLevel { get; set; }
72
73 /// <summary>
62 /// Is the script currently running? 74 /// Is the script currently running?
63 /// </summary> 75 /// </summary>
64 bool Running { get; set; } 76 bool Running { get; set; }
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
index 5ad6eeb..435e9dc 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
@@ -93,6 +93,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
93 private UUID m_CurrentStateHash; 93 private UUID m_CurrentStateHash;
94 private UUID m_RegionID; 94 private UUID m_RegionID;
95 95
96 public int DebugLevel { get; set; }
97
96 public Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> LineMap { get; set; } 98 public Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> LineMap { get; set; }
97 99
98 private Dictionary<string,IScriptApi> m_Apis = new Dictionary<string,IScriptApi>(); 100 private Dictionary<string,IScriptApi> m_Apis = new Dictionary<string,IScriptApi>();
@@ -703,21 +705,42 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
703 if (data.EventName == "collision") 705 if (data.EventName == "collision")
704 m_CollisionInQueue = false; 706 m_CollisionInQueue = false;
705 } 707 }
706 708
707// m_log.DebugFormat("[XEngine]: Processing event {0} for {1}", data.EventName, this); 709 SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
710
711 if (DebugLevel >= 2)
712 m_log.DebugFormat(
713 "[SCRIPT INSTANCE]: Processing event {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}",
714 data.EventName,
715 ScriptName,
716 part.Name,
717 part.LocalId,
718 part.ParentGroup.Name,
719 part.ParentGroup.UUID,
720 part.AbsolutePosition,
721 part.ParentGroup.Scene.Name);
708 722
709 m_DetectParams = data.DetectParams; 723 m_DetectParams = data.DetectParams;
710 724
711 if (data.EventName == "state") // Hardcoded state change 725 if (data.EventName == "state") // Hardcoded state change
712 { 726 {
713 // m_log.DebugFormat("[Script] Script {0}.{1} state set to {2}",
714 // PrimName, ScriptName, data.Params[0].ToString());
715 State = data.Params[0].ToString(); 727 State = data.Params[0].ToString();
728
729 if (DebugLevel >= 1)
730 m_log.DebugFormat(
731 "[SCRIPT INSTANCE]: Changing state to {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}",
732 State,
733 ScriptName,
734 part.Name,
735 part.LocalId,
736 part.ParentGroup.Name,
737 part.ParentGroup.UUID,
738 part.AbsolutePosition,
739 part.ParentGroup.Scene.Name);
740
716 AsyncCommandManager.RemoveScript(Engine, 741 AsyncCommandManager.RemoveScript(Engine,
717 LocalID, ItemID); 742 LocalID, ItemID);
718 743
719 SceneObjectPart part = Engine.World.GetSceneObjectPart(
720 LocalID);
721 if (part != null) 744 if (part != null)
722 { 745 {
723 part.SetScriptEvents(ItemID, 746 part.SetScriptEvents(ItemID,
@@ -729,8 +752,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
729 if (Engine.World.PipeEventsForScript(LocalID) || 752 if (Engine.World.PipeEventsForScript(LocalID) ||
730 data.EventName == "control") // Don't freeze avies! 753 data.EventName == "control") // Don't freeze avies!
731 { 754 {
732 SceneObjectPart part = Engine.World.GetSceneObjectPart(
733 LocalID);
734 // m_log.DebugFormat("[Script] Delivered event {2} in state {3} to {0}.{1}", 755 // m_log.DebugFormat("[Script] Delivered event {2} in state {3} to {0}.{1}",
735 // PrimName, ScriptName, data.EventName, State); 756 // PrimName, ScriptName, data.EventName, State);
736 757
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index 986f658..828f2fb 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -304,7 +304,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
304 304
305 MainConsole.Instance.Commands.AddCommand( 305 MainConsole.Instance.Commands.AddCommand(
306 "Scripts", false, "scripts show", "scripts show [<script-item-uuid>]", "Show script information", 306 "Scripts", false, "scripts show", "scripts show [<script-item-uuid>]", "Show script information",
307 "Show information on all scripts known to the script engine." 307 "Show information on all scripts known to the script engine.\n"
308 + "If a <script-item-uuid> is given then only information on that script will be shown.", 308 + "If a <script-item-uuid> is given then only information on that script will be shown.",
309 HandleShowScripts); 309 HandleShowScripts);
310 310
@@ -323,22 +323,30 @@ namespace OpenSim.Region.ScriptEngine.XEngine
323 MainConsole.Instance.Commands.AddCommand( 323 MainConsole.Instance.Commands.AddCommand(
324 "Scripts", false, "scripts resume", "scripts resume [<script-item-uuid>]", "Resumes all suspended scripts", 324 "Scripts", false, "scripts resume", "scripts resume [<script-item-uuid>]", "Resumes all suspended scripts",
325 "Resumes all currently suspended scripts.\n" 325 "Resumes all currently suspended scripts.\n"
326 + "Resumed scripts will process all events accumulated whilst suspended." 326 + "Resumed scripts will process all events accumulated whilst suspended.\n"
327 + "If a <script-item-uuid> is given then only that script will be resumed. Otherwise, all suitable scripts are resumed.", 327 + "If a <script-item-uuid> is given then only that script will be resumed. Otherwise, all suitable scripts are resumed.",
328 (module, cmdparams) => HandleScriptsAction(cmdparams, HandleResumeScript)); 328 (module, cmdparams) => HandleScriptsAction(cmdparams, HandleResumeScript));
329 329
330 MainConsole.Instance.Commands.AddCommand( 330 MainConsole.Instance.Commands.AddCommand(
331 "Scripts", false, "scripts stop", "scripts stop [<script-item-uuid>]", "Stops all running scripts", 331 "Scripts", false, "scripts stop", "scripts stop [<script-item-uuid>]", "Stops all running scripts",
332 "Stops all running scripts." 332 "Stops all running scripts.\n"
333 + "If a <script-item-uuid> is given then only that script will be stopped. Otherwise, all suitable scripts are stopped.", 333 + "If a <script-item-uuid> is given then only that script will be stopped. Otherwise, all suitable scripts are stopped.",
334 (module, cmdparams) => HandleScriptsAction(cmdparams, HandleStopScript)); 334 (module, cmdparams) => HandleScriptsAction(cmdparams, HandleStopScript));
335 335
336 MainConsole.Instance.Commands.AddCommand( 336 MainConsole.Instance.Commands.AddCommand(
337 "Scripts", false, "scripts start", "scripts start [<script-item-uuid>]", "Starts all stopped scripts", 337 "Scripts", false, "scripts start", "scripts start [<script-item-uuid>]", "Starts all stopped scripts",
338 "Starts all stopped scripts." 338 "Starts all stopped scripts.\n"
339 + "If a <script-item-uuid> is given then only that script will be started. Otherwise, all suitable scripts are started.", 339 + "If a <script-item-uuid> is given then only that script will be started. Otherwise, all suitable scripts are started.",
340 (module, cmdparams) => HandleScriptsAction(cmdparams, HandleStartScript)); 340 (module, cmdparams) => HandleScriptsAction(cmdparams, HandleStartScript));
341 341
342 MainConsole.Instance.Commands.AddCommand(
343 "Scripts", false, "debug script log", "debug scripts log <item-id> <log-level>", "Extra debug logging for a script",
344 "Activates or deactivates extra debug logging for the given script.\n"
345 + "Level == 0, deactivate extra debug logging.\n"
346 + "Level >= 1, log state changes.\n"
347 + "Level >= 2, log event invocations.\n",
348 HandleDebugScriptLogCommand);
349
342// MainConsole.Instance.Commands.AddCommand( 350// MainConsole.Instance.Commands.AddCommand(
343// "Debug", false, "debug xengine", "debug xengine [<level>]", 351// "Debug", false, "debug xengine", "debug xengine [<level>]",
344// "Turn on detailed xengine debugging.", 352// "Turn on detailed xengine debugging.",
@@ -347,6 +355,41 @@ namespace OpenSim.Region.ScriptEngine.XEngine
347// HandleDebugLevelCommand); 355// HandleDebugLevelCommand);
348 } 356 }
349 357
358 private void HandleDebugScriptLogCommand(string module, string[] args)
359 {
360 if (!(MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_Scene))
361 return;
362
363 if (args.Length != 5)
364 {
365 MainConsole.Instance.Output("Usage: debug script log <item-id> <log-level>");
366 return;
367 }
368
369 UUID itemId;
370
371 if (!ConsoleUtil.TryParseConsoleUuid(MainConsole.Instance, args[3], out itemId))
372 return;
373
374 int newLevel;
375
376 if (!ConsoleUtil.TryParseConsoleInt(MainConsole.Instance, args[4], out newLevel))
377 return;
378
379 IScriptInstance si;
380
381 lock (m_Scripts)
382 {
383 // XXX: We can't give the user feedback on a bad item id because this may apply to a different script
384 // engine
385 if (!m_Scripts.TryGetValue(itemId, out si))
386 return;
387 }
388
389 si.DebugLevel = newLevel;
390 MainConsole.Instance.OutputFormat("Set debug level of {0} {1} to {2}", si.ScriptName, si.ItemID, newLevel);
391 }
392
350 /// <summary> 393 /// <summary>
351 /// Change debug level 394 /// Change debug level
352 /// </summary> 395 /// </summary>
@@ -418,7 +461,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
418 461
419 if (!UUID.TryParse(rawItemId, out itemId)) 462 if (!UUID.TryParse(rawItemId, out itemId))
420 { 463 {
421 MainConsole.Instance.OutputFormat("Error - {0} is not a valid UUID", rawItemId); 464 MainConsole.Instance.OutputFormat("ERROR: {0} is not a valid UUID", rawItemId);
422 return; 465 return;
423 } 466 }
424 467