From 2b142f2f9e888d5cb7317cc51c12ac7152c54459 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Thu, 28 Mar 2013 23:09:35 +0000
Subject: Add "debug attachments" console command to allow highly verbose
attachment logging to be switched on and off.
Default is off.
---
.../Avatar/Attachments/AttachmentsModule.cs | 170 +++++++++++++--------
1 file changed, 109 insertions(+), 61 deletions(-)
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
index 55c5422..c78f5b3 100644
--- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
@@ -48,6 +48,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
{
#region INonSharedRegionModule
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
+
+ public int DebugLevel { get; set; }
private Scene m_scene;
private IInventoryAccessModule m_invAccessModule;
@@ -79,11 +81,37 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
m_scene.EventManager.OnNewClient += SubscribeToClientEvents;
m_scene.EventManager.OnStartScript += (localID, itemID) => HandleScriptStateChange(localID, true);
m_scene.EventManager.OnStopScript += (localID, itemID) => HandleScriptStateChange(localID, false);
+
+ MainConsole.Instance.Commands.AddCommand(
+ "Debug",
+ false,
+ "debug attachments",
+ "debug attachments [0|1]",
+ "Turn on attachments debugging\n"
+ + " <= 0 - turns off debugging\n"
+ + " >= 1 - turns on attachment message logging\n",
+ HandleDebugAttachments);
}
// TODO: Should probably be subscribing to CloseClient too, but this doesn't yet give us IClientAPI
}
+ private void HandleDebugAttachments(string module, string[] args)
+ {
+ int debugLevel;
+
+ if (!(args.Length == 3 && int.TryParse(args[2], out debugLevel)))
+ {
+ MainConsole.Instance.OutputFormat("Usage: debug attachments [0|1]");
+ }
+ else
+ {
+ DebugLevel = debugLevel;
+ MainConsole.Instance.OutputFormat(
+ "Set event queue debug level to {0} in {1}", DebugLevel, m_scene.Name);
+ }
+ }
+
///
/// Listen for client triggered running state changes so that we can persist the script's object if necessary.
///
@@ -196,14 +224,16 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
if (sp.GetAttachments().Count > 0)
{
-// m_log.DebugFormat(
-// "[ATTACHMENTS MODULE]: Not doing simulator-side attachment rez for {0} in {1} as their viewer has already rezzed attachments",
-// m_scene.Name, sp.Name);
+ if (DebugLevel > 0)
+ m_log.DebugFormat(
+ "[ATTACHMENTS MODULE]: Not doing simulator-side attachment rez for {0} in {1} as their viewer has already rezzed attachments",
+ m_scene.Name, sp.Name);
return;
}
-// m_log.DebugFormat("[ATTACHMENTS MODULE]: Rezzing any attachments for {0} from simulator-side", sp.Name);
+ if (DebugLevel > 0)
+ m_log.DebugFormat("[ATTACHMENTS MODULE]: Rezzing any attachments for {0} from simulator-side", sp.Name);
List attachments = sp.Appearance.GetAttachments();
foreach (AvatarAttachment attach in attachments)
@@ -245,7 +275,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
if (!Enabled)
return;
-// m_log.DebugFormat("[ATTACHMENTS MODULE]: Saving changed attachments for {0}", sp.Name);
+ if (DebugLevel > 0)
+ m_log.DebugFormat("[ATTACHMENTS MODULE]: Saving changed attachments for {0}", sp.Name);
List attachments = sp.GetAttachments();
@@ -278,9 +309,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
if (!Enabled)
return;
-// m_log.DebugFormat(
-// "[ATTACHMENTS MODULE]: Deleting attachments from scene {0} for {1}, silent = {2}",
-// m_scene.RegionInfo.RegionName, sp.Name, silent);
+ if (DebugLevel > 0)
+ m_log.DebugFormat(
+ "[ATTACHMENTS MODULE]: Deleting attachments from scene {0} for {1}, silent = {2}",
+ m_scene.RegionInfo.RegionName, sp.Name, silent);
foreach (SceneObjectGroup sop in sp.GetAttachments())
{
@@ -313,9 +345,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
{
if (group.GetSittingAvatarsCount() != 0)
{
-// m_log.WarnFormat(
-// "[ATTACHMENTS MODULE]: Ignoring request to attach {0} {1} to {2} on {3} since {4} avatars are still sitting on it",
-// group.Name, group.LocalId, sp.Name, attachmentPt, group.GetSittingAvatarsCount());
+ if (DebugLevel > 0)
+ m_log.WarnFormat(
+ "[ATTACHMENTS MODULE]: Ignoring request to attach {0} {1} to {2} on {3} since {4} avatars are still sitting on it",
+ group.Name, group.LocalId, sp.Name, attachmentPt, group.GetSittingAvatarsCount());
return false;
}
@@ -351,9 +384,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
if (attachments.Contains(group))
{
-// m_log.WarnFormat(
-// "[ATTACHMENTS MODULE]: Ignoring request to attach {0} {1} to {2} on {3} since it's already attached",
-// group.Name, group.LocalId, sp.Name, AttachmentPt);
+ if (DebugLevel > 0)
+ m_log.WarnFormat(
+ "[ATTACHMENTS MODULE]: Ignoring request to attach {0} {1} to {2} on {3} since it's already attached",
+ group.Name, group.LocalId, sp.Name, attachmentPt);
return false;
}
@@ -418,9 +452,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
if (!Enabled)
return null;
-// m_log.DebugFormat(
-// "[ATTACHMENTS MODULE]: RezSingleAttachmentFromInventory to point {0} from item {1} for {2} in {3}",
-// (AttachmentPoint)AttachmentPt, itemID, sp.Name, m_scene.Name);
+ if (DebugLevel > 0)
+ m_log.DebugFormat(
+ "[ATTACHMENTS MODULE]: RezSingleAttachmentFromInventory to point {0} from item {1} for {2} in {3}",
+ (AttachmentPoint)AttachmentPt, itemID, sp.Name, m_scene.Name);
bool append = (AttachmentPt & 0x80) != 0;
AttachmentPt &= 0x7f;
@@ -444,9 +479,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
// if (sp.Appearance.GetAttachmentForItem(itemID) != null)
if (alreadyOn)
{
-// m_log.WarnFormat(
-// "[ATTACHMENTS MODULE]: Ignoring request by {0} to wear item {1} at {2} since it is already worn",
-// sp.Name, itemID, AttachmentPt);
+ if (DebugLevel > 0)
+ m_log.DebugFormat(
+ "[ATTACHMENTS MODULE]: Ignoring request by {0} to wear item {1} at {2} since it is already worn",
+ sp.Name, itemID, AttachmentPt);
return null;
}
@@ -459,7 +495,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
if (!Enabled)
return;
- // m_log.DebugFormat("[ATTACHMENTS MODULE]: Rezzing multiple attachments from inventory for {0}", sp.Name);
+ if (DebugLevel > 0)
+ m_log.DebugFormat("[ATTACHMENTS MODULE]: Rezzing multiple attachments from inventory for {0}", sp.Name);
foreach (KeyValuePair rez in rezlist)
{
@@ -477,9 +514,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
if (!Enabled)
return;
-// m_log.DebugFormat(
-// "[ATTACHMENTS MODULE]: DetachSingleAttachmentToGround() for {0}, object {1}",
-// sp.UUID, soLocalId);
+ if (DebugLevel > 0)
+ m_log.DebugFormat(
+ "[ATTACHMENTS MODULE]: DetachSingleAttachmentToGround() for {0}, object {1}",
+ sp.UUID, soLocalId);
SceneObjectGroup so = m_scene.GetGroupByPrim(soLocalId);
@@ -495,9 +533,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
if (inventoryID == UUID.Zero)
return;
-// m_log.DebugFormat(
-// "[ATTACHMENTS MODULE]: In DetachSingleAttachmentToGround(), object is {0} {1}, associated item is {2}",
-// so.Name, so.LocalId, inventoryID);
+ if (DebugLevel > 0)
+ m_log.DebugFormat(
+ "[ATTACHMENTS MODULE]: In DetachSingleAttachmentToGround(), object is {0} {1}, associated item is {2}",
+ so.Name, so.LocalId, inventoryID);
lock (sp.AttachmentsSyncLock)
{
@@ -552,9 +591,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
return;
}
-// m_log.DebugFormat(
-// "[ATTACHMENTS MODULE]: Detaching object {0} {1} (FromItemID {2}) for {3} in {4}",
-// so.Name, so.LocalId, so.FromItemID, sp.Name, m_scene.Name);
+ if (DebugLevel > 0)
+ m_log.DebugFormat(
+ "[ATTACHMENTS MODULE]: Detaching object {0} {1} (FromItemID {2}) for {3} in {4}",
+ so.Name, so.LocalId, so.FromItemID, sp.Name, m_scene.Name);
// Scripts MUST be snapshotted before the object is
// removed from the scene because doing otherwise will
@@ -680,12 +720,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
grp.HasGroupChanged = false; // Prevent it being saved over and over
}
-// else
-// {
-// m_log.DebugFormat(
-// "[ATTACHMENTS MODULE]: Don't need to update asset for unchanged attachment {0}, attachpoint {1}",
-// grp.UUID, grp.AttachmentPoint);
-// }
+ else if (DebugLevel > 0)
+ {
+ m_log.DebugFormat(
+ "[ATTACHMENTS MODULE]: Don't need to update asset for unchanged attachment {0}, attachpoint {1}",
+ grp.UUID, grp.AttachmentPoint);
+ }
}
///
@@ -703,9 +743,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
private void AttachToAgent(
IScenePresence sp, SceneObjectGroup so, uint attachmentpoint, Vector3 attachOffset, bool silent)
{
-// m_log.DebugFormat(
-// "[ATTACHMENTS MODULE]: Adding attachment {0} to avatar {1} in pt {2} pos {3} {4}",
-// so.Name, sp.Name, attachmentpoint, attachOffset, so.RootPart.AttachedPos);
+ if (DebugLevel > 0)
+ m_log.DebugFormat(
+ "[ATTACHMENTS MODULE]: Adding attachment {0} to avatar {1} in pt {2} pos {3} {4}",
+ so.Name, sp.Name, attachmentpoint, attachOffset, so.RootPart.AttachedPos);
so.DetachFromBackup();
@@ -730,9 +771,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
{
if (so.HasPrivateAttachmentPoint)
{
-// m_log.DebugFormat(
-// "[ATTACHMENTS MODULE]: Killing private HUD {0} for avatars other than {1} at attachment point {2}",
-// so.Name, sp.Name, so.AttachmentPoint);
+ if (DebugLevel > 0)
+ m_log.DebugFormat(
+ "[ATTACHMENTS MODULE]: Killing private HUD {0} for avatars other than {1} at attachment point {2}",
+ so.Name, sp.Name, so.AttachmentPoint);
// As this scene object can now only be seen by the attaching avatar, tell everybody else in the
// scene that it's no longer in their awareness.
@@ -766,9 +808,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
if (m_invAccessModule == null)
return null;
- // m_log.DebugFormat(
- // "[ATTACHMENTS MODULE]: Called AddSceneObjectAsAttachment for object {0} {1} for {2}",
- // grp.Name, grp.LocalId, remoteClient.Name);
+ if (DebugLevel > 0)
+ m_log.DebugFormat(
+ "[ATTACHMENTS MODULE]: Called AddSceneObjectAsAttachment for object {0} {1} for {2}",
+ grp.Name, grp.LocalId, sp.Name);
InventoryItemBase newItem
= m_invAccessModule.CopyToInventory(
@@ -877,9 +920,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
return null;
}
-// m_log.DebugFormat(
-// "[ATTACHMENTS MODULE]: Rezzed single object {0} for attachment to {1} on point {2} in {3}",
-// objatt.Name, sp.Name, attachmentPt, m_scene.Name);
+ if (DebugLevel > 0)
+ m_log.DebugFormat(
+ "[ATTACHMENTS MODULE]: Rezzed single object {0} for attachment to {1} on point {2} in {3}",
+ objatt.Name, sp.Name, attachmentPt, m_scene.Name);
// HasGroupChanged is being set from within RezObject. Ideally it would be set by the caller.
objatt.HasGroupChanged = false;
@@ -949,9 +993,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
bool changed = sp.Appearance.SetAttachment((int)AttachmentPt | attFlag, itemID, item.AssetID);
if (changed && m_scene.AvatarFactory != null)
{
-// m_log.DebugFormat(
-// "[ATTACHMENTS MODULE]: Queueing appearance save for {0}, attachment {1} point {2} in ShowAttachInUserInventory()",
-// sp.Name, att.Name, AttachmentPt);
+ if (DebugLevel > 0)
+ m_log.DebugFormat(
+ "[ATTACHMENTS MODULE]: Queueing appearance save for {0}, attachment {1} point {2} in ShowAttachInUserInventory()",
+ sp.Name, att.Name, AttachmentPt);
m_scene.AvatarFactory.QueueAppearanceSave(sp.UUID);
}
@@ -966,9 +1011,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
if (!Enabled)
return null;
- // m_log.DebugFormat(
- // "[ATTACHMENTS MODULE]: Rezzing attachment to point {0} from item {1} for {2}",
- // (AttachmentPoint)AttachmentPt, itemID, remoteClient.Name);
+ if (DebugLevel > 0)
+ m_log.DebugFormat(
+ "[ATTACHMENTS MODULE]: Rezzing attachment to point {0} from item {1} for {2}",
+ (AttachmentPoint)AttachmentPt, itemID, remoteClient.Name);
ScenePresence sp = m_scene.GetScenePresence(remoteClient.AgentId);
@@ -999,9 +1045,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
private void Client_OnObjectAttach(IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt, bool silent)
{
-// m_log.DebugFormat(
-// "[ATTACHMENTS MODULE]: Attaching object local id {0} to {1} point {2} from ground (silent = {3})",
-// objectLocalID, remoteClient.Name, AttachmentPt, silent);
+ if (DebugLevel > 0)
+ m_log.DebugFormat(
+ "[ATTACHMENTS MODULE]: Attaching object local id {0} to {1} point {2} from ground (silent = {3})",
+ objectLocalID, remoteClient.Name, AttachmentPt, silent);
if (!Enabled)
return;
@@ -1036,9 +1083,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
// Calls attach with a Zero position
if (AttachObject(sp, part.ParentGroup, AttachmentPt, false, false, append))
{
-// m_log.Debug(
-// "[ATTACHMENTS MODULE]: Saving avatar attachment. AgentID: " + remoteClient.AgentId
-// + ", AttachmentPoint: " + AttachmentPt);
+ if (DebugLevel > 0)
+ m_log.Debug(
+ "[ATTACHMENTS MODULE]: Saving avatar attachment. AgentID: " + remoteClient.AgentId
+ + ", AttachmentPoint: " + AttachmentPt);
// Save avatar attachment information
m_scene.EventManager.TriggerOnAttach(objectLocalID, part.ParentGroup.FromItemID, remoteClient.AgentId);
@@ -1095,4 +1143,4 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
#endregion
}
-}
+}
\ No newline at end of file
--
cgit v1.1