aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack
diff options
context:
space:
mode:
authorJohn Hurliman2009-11-05 12:01:40 -0800
committerJohn Hurliman2009-11-05 12:01:40 -0800
commite6d7303b296468a06ada761706e25d49587b308f (patch)
tree3739865dcf478eaadf9b75a58a9e9615b64c6afa /OpenSim/Region/ClientStack
parentChange the permissions module to use the friend list cache already in the (diff)
downloadopensim-SC_OLD-e6d7303b296468a06ada761706e25d49587b308f.zip
opensim-SC_OLD-e6d7303b296468a06ada761706e25d49587b308f.tar.gz
opensim-SC_OLD-e6d7303b296468a06ada761706e25d49587b308f.tar.bz2
opensim-SC_OLD-e6d7303b296468a06ada761706e25d49587b308f.tar.xz
Applying #4332, optional packet statistics logging
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs4
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs111
2 files changed, 115 insertions, 0 deletions
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
4905 /// <param name="throttlePacketType">Throttling category for the packet</param> 4905 /// <param name="throttlePacketType">Throttling category for the packet</param>
4906 protected void OutPacket(Packet packet, ThrottleOutPacketType throttlePacketType) 4906 protected void OutPacket(Packet packet, ThrottleOutPacketType throttlePacketType)
4907 { 4907 {
4908 #region BinaryStats
4909 LLUDPServer.LogPacketHeader(false, m_circuitCode, 0, packet.Type, (ushort)packet.Length);
4910 #endregion BinaryStats
4911
4908 m_udpServer.SendPacket(m_udpClient, packet, throttlePacketType, true); 4912 m_udpServer.SendPacket(m_udpClient, packet, throttlePacketType, true);
4909 } 4913 }
4910 4914
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 @@
27 27
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.IO;
30using System.Net; 31using System.Net;
31using System.Net.Sockets; 32using System.Net.Sockets;
32using System.Reflection; 33using 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 }
@@ -679,6 +705,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
679 705
680 #endregion Incoming Packet Accounting 706 #endregion Incoming Packet Accounting
681 707
708 #region BinaryStats
709 LogPacketHeader(true, udpClient.CircuitCode, 0, packet.Type, (ushort)packet.Length);
710 #endregion BinaryStats
711
682 #region Ping Check Handling 712 #region Ping Check Handling
683 713
684 if (packet.Type == PacketType.StartPingCheck) 714 if (packet.Type == PacketType.StartPingCheck)
@@ -700,6 +730,87 @@ namespace OpenSim.Region.ClientStack.LindenUDP
700 packetInbox.Enqueue(new IncomingPacket(udpClient, packet)); 730 packetInbox.Enqueue(new IncomingPacket(udpClient, packet));
701 } 731 }
702 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
703 private void HandleUseCircuitCode(object o) 814 private void HandleUseCircuitCode(object o)
704 { 815 {
705 object[] array = (object[])o; 816 object[] array = (object[])o;