Add "debug attachments" console command to allow highly verbose attachment logging to be switched on and off.

Default is off.
user_profiles
Justin Clark-Casey (justincc) 2013-03-28 23:09:35 +00:00
parent feffc8081d
commit 2b142f2f9e
1 changed files with 109 additions and 61 deletions

View File

@ -48,6 +48,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
{ {
#region INonSharedRegionModule #region INonSharedRegionModule
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public int DebugLevel { get; set; }
private Scene m_scene; private Scene m_scene;
private IInventoryAccessModule m_invAccessModule; private IInventoryAccessModule m_invAccessModule;
@ -79,11 +81,37 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
m_scene.EventManager.OnNewClient += SubscribeToClientEvents; m_scene.EventManager.OnNewClient += SubscribeToClientEvents;
m_scene.EventManager.OnStartScript += (localID, itemID) => HandleScriptStateChange(localID, true); m_scene.EventManager.OnStartScript += (localID, itemID) => HandleScriptStateChange(localID, true);
m_scene.EventManager.OnStopScript += (localID, itemID) => HandleScriptStateChange(localID, false); 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 // 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);
}
}
/// <summary> /// <summary>
/// Listen for client triggered running state changes so that we can persist the script's object if necessary. /// Listen for client triggered running state changes so that we can persist the script's object if necessary.
/// </summary> /// </summary>
@ -196,14 +224,16 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
if (sp.GetAttachments().Count > 0) if (sp.GetAttachments().Count > 0)
{ {
// m_log.DebugFormat( if (DebugLevel > 0)
// "[ATTACHMENTS MODULE]: Not doing simulator-side attachment rez for {0} in {1} as their viewer has already rezzed attachments", m_log.DebugFormat(
// m_scene.Name, sp.Name); "[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; 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<AvatarAttachment> attachments = sp.Appearance.GetAttachments(); List<AvatarAttachment> attachments = sp.Appearance.GetAttachments();
foreach (AvatarAttachment attach in attachments) foreach (AvatarAttachment attach in attachments)
@ -245,7 +275,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
if (!Enabled) if (!Enabled)
return; 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<SceneObjectGroup> attachments = sp.GetAttachments(); List<SceneObjectGroup> attachments = sp.GetAttachments();
@ -278,9 +309,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
if (!Enabled) if (!Enabled)
return; return;
// m_log.DebugFormat( if (DebugLevel > 0)
// "[ATTACHMENTS MODULE]: Deleting attachments from scene {0} for {1}, silent = {2}", m_log.DebugFormat(
// m_scene.RegionInfo.RegionName, sp.Name, silent); "[ATTACHMENTS MODULE]: Deleting attachments from scene {0} for {1}, silent = {2}",
m_scene.RegionInfo.RegionName, sp.Name, silent);
foreach (SceneObjectGroup sop in sp.GetAttachments()) foreach (SceneObjectGroup sop in sp.GetAttachments())
{ {
@ -313,9 +345,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
{ {
if (group.GetSittingAvatarsCount() != 0) if (group.GetSittingAvatarsCount() != 0)
{ {
// m_log.WarnFormat( if (DebugLevel > 0)
// "[ATTACHMENTS MODULE]: Ignoring request to attach {0} {1} to {2} on {3} since {4} avatars are still sitting on it", m_log.WarnFormat(
// group.Name, group.LocalId, sp.Name, attachmentPt, group.GetSittingAvatarsCount()); "[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; return false;
} }
@ -351,9 +384,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
if (attachments.Contains(group)) if (attachments.Contains(group))
{ {
// m_log.WarnFormat( if (DebugLevel > 0)
// "[ATTACHMENTS MODULE]: Ignoring request to attach {0} {1} to {2} on {3} since it's already attached", m_log.WarnFormat(
// group.Name, group.LocalId, sp.Name, AttachmentPt); "[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; return false;
} }
@ -418,9 +452,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
if (!Enabled) if (!Enabled)
return null; return null;
// m_log.DebugFormat( if (DebugLevel > 0)
// "[ATTACHMENTS MODULE]: RezSingleAttachmentFromInventory to point {0} from item {1} for {2} in {3}", m_log.DebugFormat(
// (AttachmentPoint)AttachmentPt, itemID, sp.Name, m_scene.Name); "[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; bool append = (AttachmentPt & 0x80) != 0;
AttachmentPt &= 0x7f; AttachmentPt &= 0x7f;
@ -444,9 +479,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
// if (sp.Appearance.GetAttachmentForItem(itemID) != null) // if (sp.Appearance.GetAttachmentForItem(itemID) != null)
if (alreadyOn) if (alreadyOn)
{ {
// m_log.WarnFormat( if (DebugLevel > 0)
// "[ATTACHMENTS MODULE]: Ignoring request by {0} to wear item {1} at {2} since it is already worn", m_log.DebugFormat(
// sp.Name, itemID, AttachmentPt); "[ATTACHMENTS MODULE]: Ignoring request by {0} to wear item {1} at {2} since it is already worn",
sp.Name, itemID, AttachmentPt);
return null; return null;
} }
@ -459,7 +495,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
if (!Enabled) if (!Enabled)
return; 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<UUID, uint> rez in rezlist) foreach (KeyValuePair<UUID, uint> rez in rezlist)
{ {
@ -477,9 +514,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
if (!Enabled) if (!Enabled)
return; return;
// m_log.DebugFormat( if (DebugLevel > 0)
// "[ATTACHMENTS MODULE]: DetachSingleAttachmentToGround() for {0}, object {1}", m_log.DebugFormat(
// sp.UUID, soLocalId); "[ATTACHMENTS MODULE]: DetachSingleAttachmentToGround() for {0}, object {1}",
sp.UUID, soLocalId);
SceneObjectGroup so = m_scene.GetGroupByPrim(soLocalId); SceneObjectGroup so = m_scene.GetGroupByPrim(soLocalId);
@ -495,9 +533,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
if (inventoryID == UUID.Zero) if (inventoryID == UUID.Zero)
return; return;
// m_log.DebugFormat( if (DebugLevel > 0)
// "[ATTACHMENTS MODULE]: In DetachSingleAttachmentToGround(), object is {0} {1}, associated item is {2}", m_log.DebugFormat(
// so.Name, so.LocalId, inventoryID); "[ATTACHMENTS MODULE]: In DetachSingleAttachmentToGround(), object is {0} {1}, associated item is {2}",
so.Name, so.LocalId, inventoryID);
lock (sp.AttachmentsSyncLock) lock (sp.AttachmentsSyncLock)
{ {
@ -552,9 +591,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
return; return;
} }
// m_log.DebugFormat( if (DebugLevel > 0)
// "[ATTACHMENTS MODULE]: Detaching object {0} {1} (FromItemID {2}) for {3} in {4}", m_log.DebugFormat(
// so.Name, so.LocalId, so.FromItemID, sp.Name, m_scene.Name); "[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 // Scripts MUST be snapshotted before the object is
// removed from the scene because doing otherwise will // 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 grp.HasGroupChanged = false; // Prevent it being saved over and over
} }
// else else if (DebugLevel > 0)
// { {
// m_log.DebugFormat( m_log.DebugFormat(
// "[ATTACHMENTS MODULE]: Don't need to update asset for unchanged attachment {0}, attachpoint {1}", "[ATTACHMENTS MODULE]: Don't need to update asset for unchanged attachment {0}, attachpoint {1}",
// grp.UUID, grp.AttachmentPoint); grp.UUID, grp.AttachmentPoint);
// } }
} }
/// <summary> /// <summary>
@ -703,9 +743,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
private void AttachToAgent( private void AttachToAgent(
IScenePresence sp, SceneObjectGroup so, uint attachmentpoint, Vector3 attachOffset, bool silent) IScenePresence sp, SceneObjectGroup so, uint attachmentpoint, Vector3 attachOffset, bool silent)
{ {
// m_log.DebugFormat( if (DebugLevel > 0)
// "[ATTACHMENTS MODULE]: Adding attachment {0} to avatar {1} in pt {2} pos {3} {4}", m_log.DebugFormat(
// so.Name, sp.Name, attachmentpoint, attachOffset, so.RootPart.AttachedPos); "[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(); so.DetachFromBackup();
@ -730,9 +771,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
{ {
if (so.HasPrivateAttachmentPoint) if (so.HasPrivateAttachmentPoint)
{ {
// m_log.DebugFormat( if (DebugLevel > 0)
// "[ATTACHMENTS MODULE]: Killing private HUD {0} for avatars other than {1} at attachment point {2}", m_log.DebugFormat(
// so.Name, sp.Name, so.AttachmentPoint); "[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 // 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. // scene that it's no longer in their awareness.
@ -766,9 +808,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
if (m_invAccessModule == null) if (m_invAccessModule == null)
return null; return null;
// m_log.DebugFormat( if (DebugLevel > 0)
// "[ATTACHMENTS MODULE]: Called AddSceneObjectAsAttachment for object {0} {1} for {2}", m_log.DebugFormat(
// grp.Name, grp.LocalId, remoteClient.Name); "[ATTACHMENTS MODULE]: Called AddSceneObjectAsAttachment for object {0} {1} for {2}",
grp.Name, grp.LocalId, sp.Name);
InventoryItemBase newItem InventoryItemBase newItem
= m_invAccessModule.CopyToInventory( = m_invAccessModule.CopyToInventory(
@ -877,9 +920,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
return null; return null;
} }
// m_log.DebugFormat( if (DebugLevel > 0)
// "[ATTACHMENTS MODULE]: Rezzed single object {0} for attachment to {1} on point {2} in {3}", m_log.DebugFormat(
// objatt.Name, sp.Name, attachmentPt, m_scene.Name); "[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. // HasGroupChanged is being set from within RezObject. Ideally it would be set by the caller.
objatt.HasGroupChanged = false; objatt.HasGroupChanged = false;
@ -949,9 +993,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
bool changed = sp.Appearance.SetAttachment((int)AttachmentPt | attFlag, itemID, item.AssetID); bool changed = sp.Appearance.SetAttachment((int)AttachmentPt | attFlag, itemID, item.AssetID);
if (changed && m_scene.AvatarFactory != null) if (changed && m_scene.AvatarFactory != null)
{ {
// m_log.DebugFormat( if (DebugLevel > 0)
// "[ATTACHMENTS MODULE]: Queueing appearance save for {0}, attachment {1} point {2} in ShowAttachInUserInventory()", m_log.DebugFormat(
// sp.Name, att.Name, AttachmentPt); "[ATTACHMENTS MODULE]: Queueing appearance save for {0}, attachment {1} point {2} in ShowAttachInUserInventory()",
sp.Name, att.Name, AttachmentPt);
m_scene.AvatarFactory.QueueAppearanceSave(sp.UUID); m_scene.AvatarFactory.QueueAppearanceSave(sp.UUID);
} }
@ -966,9 +1011,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
if (!Enabled) if (!Enabled)
return null; return null;
// m_log.DebugFormat( if (DebugLevel > 0)
// "[ATTACHMENTS MODULE]: Rezzing attachment to point {0} from item {1} for {2}", m_log.DebugFormat(
// (AttachmentPoint)AttachmentPt, itemID, remoteClient.Name); "[ATTACHMENTS MODULE]: Rezzing attachment to point {0} from item {1} for {2}",
(AttachmentPoint)AttachmentPt, itemID, remoteClient.Name);
ScenePresence sp = m_scene.GetScenePresence(remoteClient.AgentId); 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) private void Client_OnObjectAttach(IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt, bool silent)
{ {
// m_log.DebugFormat( if (DebugLevel > 0)
// "[ATTACHMENTS MODULE]: Attaching object local id {0} to {1} point {2} from ground (silent = {3})", m_log.DebugFormat(
// objectLocalID, remoteClient.Name, AttachmentPt, silent); "[ATTACHMENTS MODULE]: Attaching object local id {0} to {1} point {2} from ground (silent = {3})",
objectLocalID, remoteClient.Name, AttachmentPt, silent);
if (!Enabled) if (!Enabled)
return; return;
@ -1036,9 +1083,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
// Calls attach with a Zero position // Calls attach with a Zero position
if (AttachObject(sp, part.ParentGroup, AttachmentPt, false, false, append)) if (AttachObject(sp, part.ParentGroup, AttachmentPt, false, false, append))
{ {
// m_log.Debug( if (DebugLevel > 0)
// "[ATTACHMENTS MODULE]: Saving avatar attachment. AgentID: " + remoteClient.AgentId m_log.Debug(
// + ", AttachmentPoint: " + AttachmentPt); "[ATTACHMENTS MODULE]: Saving avatar attachment. AgentID: " + remoteClient.AgentId
+ ", AttachmentPoint: " + AttachmentPt);
// Save avatar attachment information // Save avatar attachment information
m_scene.EventManager.TriggerOnAttach(objectLocalID, part.ParentGroup.FromItemID, remoteClient.AgentId); m_scene.EventManager.TriggerOnAttach(objectLocalID, part.ParentGroup.FromItemID, remoteClient.AgentId);
@ -1095,4 +1143,4 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
#endregion #endregion
} }
} }