diff --git a/OpenSim/Framework/IClientAPI.cs b/OpenSim/Framework/IClientAPI.cs index 039526ba9e..046688fc11 100644 --- a/OpenSim/Framework/IClientAPI.cs +++ b/OpenSim/Framework/IClientAPI.cs @@ -398,6 +398,8 @@ namespace OpenSim.Framework public delegate void FriendActionDelegate(IClientAPI remoteClient,LLUUID agentID,LLUUID transactionID,List callingCardFolders); public delegate void FriendshipTermination(IClientAPI remoteClient,LLUUID agentID, LLUUID ExID); + + public delegate void PacketStats(int inPackets, int outPackets, int unAckedBytes); @@ -501,6 +503,7 @@ namespace OpenSim.Framework event FriendActionDelegate OnApproveFriendRequest; event FriendActionDelegate OnDenyFriendRequest; event FriendshipTermination OnTerminateFriendship; + event PacketStats OnPacketStats; LLVector3 StartPos { get; set; } diff --git a/OpenSim/Region/ClientStack/ClientView.cs b/OpenSim/Region/ClientStack/ClientView.cs index d3a8254825..c1f4126ab8 100644 --- a/OpenSim/Region/ClientStack/ClientView.cs +++ b/OpenSim/Region/ClientStack/ClientView.cs @@ -63,7 +63,14 @@ namespace OpenSim.Region.ClientStack // private InventoryCache m_inventoryCache; private int m_cachedTextureSerial = 0; private Timer m_clientPingTimer; + private int m_packetsReceived = 0; + private int m_lastpacketsSentToScene = 0; + private int m_unAckedBytes = 0; + + private int m_packetsSent = 0; + private int m_lastPacketsSent = 0; + private int m_probesWithNoIngressPackets = 0; private int m_lastPacketsReceived = 0; private byte[] ZeroOutBuffer = new byte[4096]; @@ -409,6 +416,7 @@ namespace OpenSim.Region.ClientStack { // this will normally trigger at least one packet (ping response) SendStartPingCheck(0); + } } else @@ -416,6 +424,7 @@ namespace OpenSim.Region.ClientStack // Something received in the meantime - we can reset the counters m_probesWithNoIngressPackets = 0; m_lastPacketsReceived = m_packetsReceived; + } } @@ -566,6 +575,9 @@ namespace OpenSim.Region.ClientStack public event FriendActionDelegate OnDenyFriendRequest; public event FriendshipTermination OnTerminateFriendship; + public event PacketStats OnPacketStats; + + #region Scene/Avatar to Client /// @@ -2245,6 +2257,7 @@ namespace OpenSim.Region.ClientStack try { m_needAck.Add(Pack.Header.Sequence, Pack); + m_unAckedBytes += Pack.ToBytes().Length; } catch (Exception) // HACKY { @@ -2298,6 +2311,7 @@ namespace OpenSim.Region.ClientStack if (Pack.Header.Reliable) //DIRTY HACK { AddAck(Pack); // this adds the need to ack this packet later + if (Pack.Type != PacketType.PacketAck && Pack.Type != PacketType.LogoutRequest) { @@ -2343,6 +2357,7 @@ namespace OpenSim.Region.ClientStack { foreach (uint ack in NewPack.Header.AckList) { + m_unAckedBytes -= m_needAck[ack].ToBytes().Length; m_needAck.Remove(ack); } } @@ -2358,6 +2373,7 @@ namespace OpenSim.Region.ClientStack { foreach (PacketAckPacket.PacketsBlock block in ackPacket.Packets) { + m_unAckedBytes -= m_needAck[block.ID].ToBytes().Length; m_needAck.Remove(block.ID); } } @@ -2387,6 +2403,7 @@ namespace OpenSim.Region.ClientStack item.Incoming = false; item.throttleType = throttlePacketType; // Packet throttle type m_packetQueue.Enqueue(item); + m_packetsSent++; } # region Low Level Packet Methods @@ -2472,8 +2489,21 @@ namespace OpenSim.Region.ClientStack protected void AckTimer_Elapsed(object sender, ElapsedEventArgs ea) { + SendAcks(); ResendUnacked(); + SendPacketStats(); + + } + + protected void SendPacketStats() + { + if (OnPacketStats != null) + { + OnPacketStats(m_packetsReceived - m_lastPacketsReceived, m_packetsSent - m_lastPacketsSent, m_unAckedBytes); + m_lastPacketsReceived = m_packetsReceived; + m_lastPacketsSent = m_packetsSent; + } } #endregion diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index 9af43f5c56..16055ded3c 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -1228,6 +1228,7 @@ namespace OpenSim.Region.Environment.Scenes client.OnGrabObject += ProcessObjectGrab; client.OnAvatarPickerRequest += ProcessAvatarPickerRequest; + client.OnPacketStats += AddPacketStats; EventManager.TriggerOnNewClient(client); } @@ -1759,6 +1760,13 @@ namespace OpenSim.Region.Environment.Scenes return CommsManager.GetUserFriendList(ownerID); } + public void AddPacketStats(int inPackets, int outPackets, int unAckedBytes) + { + m_statsReporter.AddInPackets(inPackets); + m_statsReporter.AddOutPackets(outPackets); + m_statsReporter.AddunAckedBytes(unAckedBytes); + } + #endregion #region Console Commands diff --git a/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs b/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs index 809a13b02b..ecc2df440a 100644 --- a/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs +++ b/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs @@ -142,6 +142,7 @@ namespace SimpleApp public event FriendActionDelegate OnApproveFriendRequest; public event FriendActionDelegate OnDenyFriendRequest; public event FriendshipTermination OnTerminateFriendship; + public event PacketStats OnPacketStats; #pragma warning restore 67