From e6d7303b296468a06ada761706e25d49587b308f Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Thu, 5 Nov 2009 12:01:40 -0800 Subject: Applying #4332, optional packet statistics logging --- .../Region/ClientStack/LindenUDP/LLClientView.cs | 4 + .../Region/ClientStack/LindenUDP/LLUDPServer.cs | 111 +++++++++++++++++++++ 2 files changed, 115 insertions(+) (limited to 'OpenSim/Region/ClientStack') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index 34cad7b..101a44b 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -4905,6 +4905,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP /// Throttling category for the packet protected void OutPacket(Packet packet, ThrottleOutPacketType throttlePacketType) { + #region BinaryStats + LLUDPServer.LogPacketHeader(false, m_circuitCode, 0, packet.Type, (ushort)packet.Length); + #endregion BinaryStats + m_udpServer.SendPacket(m_udpClient, packet, throttlePacketType, true); } diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs index 6165984..c773c05 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs @@ -27,6 +27,7 @@ using System; using System.Collections.Generic; +using System.IO; using System.Net; using System.Net.Sockets; using System.Reflection; @@ -204,6 +205,31 @@ namespace OpenSim.Region.ClientStack.LindenUDP TextureSendLimit = 20; } + #region BinaryStats + config = configSource.Configs["Statistics.Binary"]; + m_shouldCollectStats = false; + if (config != null) + { + if (config.Contains("enabled") && config.GetBoolean("enabled")) + { + if (config.Contains("collect_packet_headers")) + m_shouldCollectStats = config.GetBoolean("collect_packet_headers"); + if (config.Contains("packet_headers_period_seconds")) + { + binStatsMaxFilesize = TimeSpan.FromSeconds(config.GetInt("region_stats_period_seconds")); + } + if (config.Contains("stats_dir")) + { + binStatsDir = config.GetString("stats_dir"); + } + } + else + { + m_shouldCollectStats = false; + } + } + #endregion BinaryStats + m_throttle = new TokenBucket(null, sceneThrottleBps, sceneThrottleBps); m_throttleRates = new ThrottleRates(configSource); } @@ -679,6 +705,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP #endregion Incoming Packet Accounting + #region BinaryStats + LogPacketHeader(true, udpClient.CircuitCode, 0, packet.Type, (ushort)packet.Length); + #endregion BinaryStats + #region Ping Check Handling if (packet.Type == PacketType.StartPingCheck) @@ -700,6 +730,87 @@ namespace OpenSim.Region.ClientStack.LindenUDP packetInbox.Enqueue(new IncomingPacket(udpClient, packet)); } + #region BinaryStats + + public class PacketLogger + { + public DateTime StartTime; + public string Path = null; + public System.IO.BinaryWriter Log = null; + } + + public static PacketLogger PacketLog; + + protected static bool m_shouldCollectStats = false; + // Number of seconds to log for + static TimeSpan binStatsMaxFilesize = TimeSpan.FromSeconds(300); + static object binStatsLogLock = new object(); + static string binStatsDir = ""; + + public static void LogPacketHeader(bool incoming, uint circuit, byte flags, PacketType packetType, ushort size) + { + if (!m_shouldCollectStats) return; + + // Binary logging format is TTTTTTTTCCCCFPPPSS, T=Time, C=Circuit, F=Flags, P=PacketType, S=size + + // Put the incoming bit into the least significant bit of the flags byte + if (incoming) + flags |= 0x01; + else + flags &= 0xFE; + + // Put the flags byte into the most significant bits of the type integer + uint type = (uint)packetType; + type |= (uint)flags << 24; + + // m_log.Debug("1 LogPacketHeader(): Outside lock"); + lock (binStatsLogLock) + { + DateTime now = DateTime.Now; + + // m_log.Debug("2 LogPacketHeader(): Inside lock. now is " + now.Ticks); + try + { + if (PacketLog == null || (now > PacketLog.StartTime + binStatsMaxFilesize)) + { + if (PacketLog != null && PacketLog.Log != null) + { + PacketLog.Log.Close(); + } + + // First log file or time has expired, start writing to a new log file + PacketLog = new PacketLogger(); + PacketLog.StartTime = now; + PacketLog.Path = (binStatsDir.Length > 0 ? binStatsDir + System.IO.Path.DirectorySeparatorChar.ToString() : "") + + String.Format("packets-{0}.log", now.ToString("yyyyMMddHHmmss")); + PacketLog.Log = new BinaryWriter(File.Open(PacketLog.Path, FileMode.Append, FileAccess.Write)); + } + + // Serialize the data + byte[] output = new byte[18]; + Buffer.BlockCopy(BitConverter.GetBytes(now.Ticks), 0, output, 0, 8); + Buffer.BlockCopy(BitConverter.GetBytes(circuit), 0, output, 8, 4); + Buffer.BlockCopy(BitConverter.GetBytes(type), 0, output, 12, 4); + Buffer.BlockCopy(BitConverter.GetBytes(size), 0, output, 16, 2); + + // Write the serialized data to disk + if (PacketLog != null && PacketLog.Log != null) + PacketLog.Log.Write(output); + } + catch (Exception ex) + { + m_log.Error("Packet statistics gathering failed: " + ex.Message, ex); + if (PacketLog.Log != null) + { + PacketLog.Log.Close(); + } + PacketLog = null; + } + } + } + + #endregion BinaryStats + private void HandleUseCircuitCode(object o) { object[] array = (object[])o; -- cgit v1.1 From afef1ac191d32e9c1514c294b17e404b1d4ae217 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Thu, 5 Nov 2009 13:10:58 -0800 Subject: Changing the AssetBase constructors to avoid initializing assets with an unknown asset type, and log an error if it ever does happen --- OpenSim/Region/ClientStack/LindenUDP/LLFileTransfer.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'OpenSim/Region/ClientStack') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLFileTransfer.cs b/OpenSim/Region/ClientStack/LindenUDP/LLFileTransfer.cs index 697bbe6..adf171e 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLFileTransfer.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLFileTransfer.cs @@ -197,11 +197,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP private void Initialise(UUID fileID, string fileName) { - m_asset = new AssetBase(); - m_asset.FullID = fileID; - m_asset.Type = type; + m_asset = new AssetBase(fileID, fileName, type); m_asset.Data = new byte[0]; - m_asset.Name = fileName; m_asset.Description = "empty"; m_asset.Local = true; m_asset.Temporary = true; -- cgit v1.1 From 6ed57814c1db72463acc3c5fca154a289eee433e Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Thu, 5 Nov 2009 23:50:17 -0800 Subject: * Clamp the CoarseLocationUpdate packet at a maximum of 60 positions per packet. This is a limitation of LLUDP, nothing we can really do about it * Marking CoarseLocationUpdate as *not* zerocoded. Zerocoding can only save space when a packet contains three or more contiguous zeroes, and will use more space if it contains single zeroes randomly scattered through the packet (which is what you see when you send a long list of UUIDs) --- OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'OpenSim/Region/ClientStack') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index 101a44b..35ccad9 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -3196,12 +3196,17 @@ namespace OpenSim.Region.ClientStack.LindenUDP if (!IsActive) return; // We don't need to update inactive clients. CoarseLocationUpdatePacket loc = (CoarseLocationUpdatePacket)PacketPool.Instance.GetPacket(PacketType.CoarseLocationUpdate); - // TODO: don't create new blocks if recycling an old packet - int total = CoarseLocations.Count; - CoarseLocationUpdatePacket.IndexBlock ib = - new CoarseLocationUpdatePacket.IndexBlock(); + loc.Header.Reliable = false; + + // Each packet can only hold around 62 avatar positions and the client clears the mini-map each time + // a CoarseLocationUpdate packet is received. Oh well. + int total = Math.Min(CoarseLocations.Count, 60); + + CoarseLocationUpdatePacket.IndexBlock ib = new CoarseLocationUpdatePacket.IndexBlock(); + loc.Location = new CoarseLocationUpdatePacket.LocationBlock[total]; loc.AgentData = new CoarseLocationUpdatePacket.AgentDataBlock[total]; + int selfindex = -1; for (int i = 0; i < total; i++) { @@ -3211,18 +3216,17 @@ namespace OpenSim.Region.ClientStack.LindenUDP lb.X = (byte)CoarseLocations[i].X; lb.Y = (byte)CoarseLocations[i].Y; - lb.Z = CoarseLocations[i].Z > 1024 ? (byte)0 : (byte)(CoarseLocations[i].Z * 0.25); + lb.Z = CoarseLocations[i].Z > 1024 ? (byte)0 : (byte)(CoarseLocations[i].Z * 0.25f); loc.Location[i] = lb; loc.AgentData[i] = new CoarseLocationUpdatePacket.AgentDataBlock(); loc.AgentData[i].AgentID = users[i]; if (users[i] == AgentId) selfindex = i; } + ib.You = (short)selfindex; ib.Prey = -1; loc.Index = ib; - loc.Header.Reliable = false; - loc.Header.Zerocoded = true; OutPacket(loc, ThrottleOutPacketType.Task); } -- cgit v1.1 From aff5fe10b0ad95489909f74f9ee2f6bb85f3d338 Mon Sep 17 00:00:00 2001 From: Melanie Date: Sun, 8 Nov 2009 22:29:36 +0000 Subject: test commit with debug output per folder fetch. NOT FOR PRODUCTION, SPEWY --- OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs | 1 + 1 file changed, 1 insertion(+) (limited to 'OpenSim/Region/ClientStack') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index 35ccad9..06ce79d 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -1255,6 +1255,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP List folders, int version, bool fetchFolders, bool fetchItems) { + m_log.DebugFormat("[CLIENT]: Request folder details for folder {0}", folderID.ToString()); // An inventory descendents packet consists of a single agent section and an inventory details // section for each inventory item. The size of each inventory item is approximately 550 bytes. // In theory, UDP has a maximum packet size of 64k, so it should be possible to send descendent -- cgit v1.1 From f8bcbe5492330bd14ecec76f11e3a33ea4fd6ef6 Mon Sep 17 00:00:00 2001 From: Melanie Date: Sun, 8 Nov 2009 22:39:00 +0000 Subject: remove the debug stuff --- OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs | 1 - 1 file changed, 1 deletion(-) (limited to 'OpenSim/Region/ClientStack') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index 06ce79d..35ccad9 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -1255,7 +1255,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP List folders, int version, bool fetchFolders, bool fetchItems) { - m_log.DebugFormat("[CLIENT]: Request folder details for folder {0}", folderID.ToString()); // An inventory descendents packet consists of a single agent section and an inventory details // section for each inventory item. The size of each inventory item is approximately 550 bytes. // In theory, UDP has a maximum packet size of 64k, so it should be possible to send descendent -- cgit v1.1