From cd088757e96217defc9a2b0bf323747615c3255e Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 16 Nov 2012 04:36:22 +0000 Subject: Add a first draft mechanism for the IncomingPacketsProcessedStat to show the delta over time. The chief motivation for this is to be able to tell whether there's any impact on incoming packet processing from enabling extra packet pooling. --- OpenSim/Framework/Monitoring/StatsManager.cs | 139 ++++++++++++++++++++- OpenSim/Framework/Monitoring/Watchdog.cs | 4 +- .../Region/ClientStack/Linden/UDP/LLUDPServer.cs | 1 + 3 files changed, 140 insertions(+), 4 deletions(-) diff --git a/OpenSim/Framework/Monitoring/StatsManager.cs b/OpenSim/Framework/Monitoring/StatsManager.cs index cebe905..eae7505 100644 --- a/OpenSim/Framework/Monitoring/StatsManager.cs +++ b/OpenSim/Framework/Monitoring/StatsManager.cs @@ -27,6 +27,7 @@ using System; using System.Collections.Generic; +using System.Text; namespace OpenSim.Framework.Monitoring { @@ -246,6 +247,24 @@ namespace OpenSim.Framework.Monitoring return false; } + + public static void RecordStats() + { + lock (RegisteredStats) + { + foreach (Dictionary> category in RegisteredStats.Values) + { + foreach (Dictionary container in category.Values) + { + foreach (Stat stat in container.Values) + { + if (stat.MeasuresOfInterest != MeasuresOfInterest.None) + stat.RecordValue(); + } + } + } + } + } } /// @@ -262,6 +281,16 @@ namespace OpenSim.Framework.Monitoring } /// + /// Measures of interest for this stat. + /// + [Flags] + public enum MeasuresOfInterest + { + None, + AverageChangeOverTime + } + + /// /// Verbosity of stat. /// /// @@ -295,6 +324,8 @@ namespace OpenSim.Framework.Monitoring public StatType StatType { get; private set; } + public MeasuresOfInterest MeasuresOfInterest { get; private set; } + /// /// Action used to update this stat when the value is requested if it's a pull type. /// @@ -328,6 +359,47 @@ namespace OpenSim.Framework.Monitoring private double m_value; /// + /// Historical samples for calculating measures of interest average. + /// + /// + /// Will be null if no measures of interest require samples. + /// + private static Queue m_samples; + + /// + /// Maximum number of statistical samples. + /// + /// + /// At the moment this corresponds to 1 minute since the sampling rate is every 2.5 seconds as triggered from + /// the main Watchdog. + /// + private static int m_maxSamples = 24; + + public Stat( + string shortName, + string name, + string description, + string unitName, + string category, + string container, + StatType type, + Action pullAction, + StatVerbosity verbosity) + : this( + shortName, + name, + description, + unitName, + category, + container, + type, + MeasuresOfInterest.None, + pullAction, + verbosity) + { + } + + /// /// Constructor /// /// Short name for the stat. Must not contain spaces. e.g. "LongFrames" @@ -341,6 +413,7 @@ namespace OpenSim.Framework.Monitoring /// Entity to which this stat relates. e.g. scene name if this is a per scene stat. /// Push or pull /// Pull stats need an action to update the stat on request. Push stats should set null here. + /// Measures of interest /// Verbosity of stat. Controls whether it will appear in short stat display or only full display. public Stat( string shortName, @@ -350,6 +423,7 @@ namespace OpenSim.Framework.Monitoring string category, string container, StatType type, + MeasuresOfInterest moi, Action pullAction, StatVerbosity verbosity) { @@ -370,13 +444,66 @@ namespace OpenSim.Framework.Monitoring else PullAction = pullAction; + MeasuresOfInterest = moi; + + if ((moi & MeasuresOfInterest.AverageChangeOverTime) == MeasuresOfInterest.AverageChangeOverTime) + m_samples = new Queue(m_maxSamples); + Verbosity = verbosity; } + /// + /// Record a value in the sample set. + /// + /// + /// Do not call this if MeasuresOfInterest.None + /// + public void RecordValue() + { + double newValue = Value; + + lock (m_samples) + { + if (m_samples.Count >= m_maxSamples) + m_samples.Dequeue(); + + m_samples.Enqueue(newValue); + } + } + public virtual string ToConsoleString() { - return string.Format( - "{0}.{1}.{2} : {3}{4}", Category, Container, ShortName, Value, UnitName); + StringBuilder sb = new StringBuilder(); + sb.AppendFormat("{0}.{1}.{2} : {3}{4}", Category, Container, ShortName, Value, UnitName); + + AppendMeasuresOfInterest(sb); + + return sb.ToString(); + } + + protected void AppendMeasuresOfInterest(StringBuilder sb) + { + if ((MeasuresOfInterest & MeasuresOfInterest.AverageChangeOverTime) + == MeasuresOfInterest.AverageChangeOverTime) + { + double totalChange = 0; + double? lastSample = null; + + lock (m_samples) + { + foreach (double s in m_samples) + { + if (lastSample != null) + totalChange += s - (double)lastSample; + + lastSample = s; + } + } + + int divisor = m_samples.Count <= 1 ? 1 : m_samples.Count - 1; + + sb.AppendFormat(", {0:0.##}{1}/s", totalChange / divisor / (Watchdog.WATCHDOG_INTERVAL_MS / 1000), UnitName); + } } } @@ -423,9 +550,15 @@ namespace OpenSim.Framework.Monitoring public override string ToConsoleString() { - return string.Format( + StringBuilder sb = new StringBuilder(); + + sb.AppendFormat( "{0}.{1}.{2} : {3:0.##}{4} ({5}/{6})", Category, Container, ShortName, Value, UnitName, Antecedent, Consequent); + + AppendMeasuresOfInterest(sb); + + return sb.ToString(); } } } \ No newline at end of file diff --git a/OpenSim/Framework/Monitoring/Watchdog.cs b/OpenSim/Framework/Monitoring/Watchdog.cs index a20326d..3f992b1 100644 --- a/OpenSim/Framework/Monitoring/Watchdog.cs +++ b/OpenSim/Framework/Monitoring/Watchdog.cs @@ -39,7 +39,7 @@ namespace OpenSim.Framework.Monitoring public static class Watchdog { /// Timer interval in milliseconds for the watchdog timer - const double WATCHDOG_INTERVAL_MS = 2500.0d; + public const double WATCHDOG_INTERVAL_MS = 2500.0d; /// Default timeout in milliseconds before a thread is considered dead public const int DEFAULT_WATCHDOG_TIMEOUT_MS = 5000; @@ -380,6 +380,8 @@ namespace OpenSim.Framework.Monitoring if (MemoryWatchdog.Enabled) MemoryWatchdog.Update(); + StatsManager.RecordStats(); + m_watchdogTimer.Start(); } } diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs index fcc69c0..a7628d2 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs @@ -80,6 +80,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP "clientstack", scene.Name, StatType.Pull, + MeasuresOfInterest.AverageChangeOverTime, stat => stat.Value = m_udpServer.IncomingPacketsProcessed, StatVerbosity.Debug)); } -- cgit v1.1