diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs | 120 |
1 files changed, 117 insertions, 3 deletions
diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs index 93946ae..c773c05 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs | |||
@@ -27,6 +27,7 @@ | |||
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.IO; | ||
30 | using System.Net; | 31 | using System.Net; |
31 | using System.Net.Sockets; | 32 | using System.Net.Sockets; |
32 | using System.Reflection; | 33 | using System.Reflection; |
@@ -204,6 +205,31 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
204 | TextureSendLimit = 20; | 205 | TextureSendLimit = 20; |
205 | } | 206 | } |
206 | 207 | ||
208 | #region BinaryStats | ||
209 | config = configSource.Configs["Statistics.Binary"]; | ||
210 | m_shouldCollectStats = false; | ||
211 | if (config != null) | ||
212 | { | ||
213 | if (config.Contains("enabled") && config.GetBoolean("enabled")) | ||
214 | { | ||
215 | if (config.Contains("collect_packet_headers")) | ||
216 | m_shouldCollectStats = config.GetBoolean("collect_packet_headers"); | ||
217 | if (config.Contains("packet_headers_period_seconds")) | ||
218 | { | ||
219 | binStatsMaxFilesize = TimeSpan.FromSeconds(config.GetInt("region_stats_period_seconds")); | ||
220 | } | ||
221 | if (config.Contains("stats_dir")) | ||
222 | { | ||
223 | binStatsDir = config.GetString("stats_dir"); | ||
224 | } | ||
225 | } | ||
226 | else | ||
227 | { | ||
228 | m_shouldCollectStats = false; | ||
229 | } | ||
230 | } | ||
231 | #endregion BinaryStats | ||
232 | |||
207 | m_throttle = new TokenBucket(null, sceneThrottleBps, sceneThrottleBps); | 233 | m_throttle = new TokenBucket(null, sceneThrottleBps, sceneThrottleBps); |
208 | m_throttleRates = new ThrottleRates(configSource); | 234 | m_throttleRates = new ThrottleRates(configSource); |
209 | } | 235 | } |
@@ -359,9 +385,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
359 | } | 385 | } |
360 | else | 386 | else |
361 | { | 387 | { |
362 | m_log.Error("[LLUDPSERVER]: Packet exceeded buffer size! This could be an indication of packet assembly not obeying the MTU. Type=" + | 388 | bufferSize = dataLength; |
363 | type + ", DataLength=" + dataLength + ", BufferLength=" + buffer.Data.Length + ". Dropping packet"); | 389 | buffer = new UDPPacketBuffer(udpClient.RemoteEndPoint, bufferSize); |
364 | return; | 390 | |
391 | // m_log.Error("[LLUDPSERVER]: Packet exceeded buffer size! This could be an indication of packet assembly not obeying the MTU. Type=" + | ||
392 | // type + ", DataLength=" + dataLength + ", BufferLength=" + buffer.Data.Length + ". Dropping packet"); | ||
393 | Buffer.BlockCopy(data, 0, buffer.Data, 0, dataLength); | ||
365 | } | 394 | } |
366 | } | 395 | } |
367 | 396 | ||
@@ -676,6 +705,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
676 | 705 | ||
677 | #endregion Incoming Packet Accounting | 706 | #endregion Incoming Packet Accounting |
678 | 707 | ||
708 | #region BinaryStats | ||
709 | LogPacketHeader(true, udpClient.CircuitCode, 0, packet.Type, (ushort)packet.Length); | ||
710 | #endregion BinaryStats | ||
711 | |||
679 | #region Ping Check Handling | 712 | #region Ping Check Handling |
680 | 713 | ||
681 | if (packet.Type == PacketType.StartPingCheck) | 714 | if (packet.Type == PacketType.StartPingCheck) |
@@ -697,6 +730,87 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
697 | packetInbox.Enqueue(new IncomingPacket(udpClient, packet)); | 730 | packetInbox.Enqueue(new IncomingPacket(udpClient, packet)); |
698 | } | 731 | } |
699 | 732 | ||
733 | #region BinaryStats | ||
734 | |||
735 | public class PacketLogger | ||
736 | { | ||
737 | public DateTime StartTime; | ||
738 | public string Path = null; | ||
739 | public System.IO.BinaryWriter Log = null; | ||
740 | } | ||
741 | |||
742 | public static PacketLogger PacketLog; | ||
743 | |||
744 | protected static bool m_shouldCollectStats = false; | ||
745 | // Number of seconds to log for | ||
746 | static TimeSpan binStatsMaxFilesize = TimeSpan.FromSeconds(300); | ||
747 | static object binStatsLogLock = new object(); | ||
748 | static string binStatsDir = ""; | ||
749 | |||
750 | public static void LogPacketHeader(bool incoming, uint circuit, byte flags, PacketType packetType, ushort size) | ||
751 | { | ||
752 | if (!m_shouldCollectStats) return; | ||
753 | |||
754 | // Binary logging format is TTTTTTTTCCCCFPPPSS, T=Time, C=Circuit, F=Flags, P=PacketType, S=size | ||
755 | |||
756 | // Put the incoming bit into the least significant bit of the flags byte | ||
757 | if (incoming) | ||
758 | flags |= 0x01; | ||
759 | else | ||
760 | flags &= 0xFE; | ||
761 | |||
762 | // Put the flags byte into the most significant bits of the type integer | ||
763 | uint type = (uint)packetType; | ||
764 | type |= (uint)flags << 24; | ||
765 | |||
766 | // m_log.Debug("1 LogPacketHeader(): Outside lock"); | ||
767 | lock (binStatsLogLock) | ||
768 | { | ||
769 | DateTime now = DateTime.Now; | ||
770 | |||
771 | // m_log.Debug("2 LogPacketHeader(): Inside lock. now is " + now.Ticks); | ||
772 | try | ||
773 | { | ||
774 | if (PacketLog == null || (now > PacketLog.StartTime + binStatsMaxFilesize)) | ||
775 | { | ||
776 | if (PacketLog != null && PacketLog.Log != null) | ||
777 | { | ||
778 | PacketLog.Log.Close(); | ||
779 | } | ||
780 | |||
781 | // First log file or time has expired, start writing to a new log file | ||
782 | PacketLog = new PacketLogger(); | ||
783 | PacketLog.StartTime = now; | ||
784 | PacketLog.Path = (binStatsDir.Length > 0 ? binStatsDir + System.IO.Path.DirectorySeparatorChar.ToString() : "") | ||
785 | + String.Format("packets-{0}.log", now.ToString("yyyyMMddHHmmss")); | ||
786 | PacketLog.Log = new BinaryWriter(File.Open(PacketLog.Path, FileMode.Append, FileAccess.Write)); | ||
787 | } | ||
788 | |||
789 | // Serialize the data | ||
790 | byte[] output = new byte[18]; | ||
791 | Buffer.BlockCopy(BitConverter.GetBytes(now.Ticks), 0, output, 0, 8); | ||
792 | Buffer.BlockCopy(BitConverter.GetBytes(circuit), 0, output, 8, 4); | ||
793 | Buffer.BlockCopy(BitConverter.GetBytes(type), 0, output, 12, 4); | ||
794 | Buffer.BlockCopy(BitConverter.GetBytes(size), 0, output, 16, 2); | ||
795 | |||
796 | // Write the serialized data to disk | ||
797 | if (PacketLog != null && PacketLog.Log != null) | ||
798 | PacketLog.Log.Write(output); | ||
799 | } | ||
800 | catch (Exception ex) | ||
801 | { | ||
802 | m_log.Error("Packet statistics gathering failed: " + ex.Message, ex); | ||
803 | if (PacketLog.Log != null) | ||
804 | { | ||
805 | PacketLog.Log.Close(); | ||
806 | } | ||
807 | PacketLog = null; | ||
808 | } | ||
809 | } | ||
810 | } | ||
811 | |||
812 | #endregion BinaryStats | ||
813 | |||
700 | private void HandleUseCircuitCode(object o) | 814 | private void HandleUseCircuitCode(object o) |
701 | { | 815 | { |
702 | object[] array = (object[])o; | 816 | object[] array = (object[])o; |