From 768e8e363bfb0aedc6edc2e6c1dbf35e1e66b531 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Tue, 18 Jun 2013 22:49:49 +0100
Subject: Fix issue where stat samples were accidentally static, so that any
additional stat with sampling would produce wrong results
---
OpenSim/Framework/Monitoring/Stats/Stat.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'OpenSim/Framework/Monitoring/Stats')
diff --git a/OpenSim/Framework/Monitoring/Stats/Stat.cs b/OpenSim/Framework/Monitoring/Stats/Stat.cs
index 2e7665f..69ac0a5 100644
--- a/OpenSim/Framework/Monitoring/Stats/Stat.cs
+++ b/OpenSim/Framework/Monitoring/Stats/Stat.cs
@@ -95,7 +95,7 @@ namespace OpenSim.Framework.Monitoring
///
/// Will be null if no measures of interest require samples.
///
- private static Queue m_samples;
+ private Queue m_samples;
///
/// Maximum number of statistical samples.
--
cgit v1.1
From 9501a583cbc8fd819d2b13db4f9ad76958520ce7 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Tue, 18 Jun 2013 23:07:18 +0100
Subject: Make number of inbound http requests handled available as a
httpserver..IncomingHTTPRequestsProcessed stat
---
OpenSim/Framework/Monitoring/Stats/Stat.cs | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
(limited to 'OpenSim/Framework/Monitoring/Stats')
diff --git a/OpenSim/Framework/Monitoring/Stats/Stat.cs b/OpenSim/Framework/Monitoring/Stats/Stat.cs
index 69ac0a5..ca71911 100644
--- a/OpenSim/Framework/Monitoring/Stats/Stat.cs
+++ b/OpenSim/Framework/Monitoring/Stats/Stat.cs
@@ -27,8 +27,9 @@
using System;
using System.Collections.Generic;
+using System.Reflection;
using System.Text;
-
+using log4net;
using OpenMetaverse.StructuredData;
namespace OpenSim.Framework.Monitoring
@@ -38,6 +39,8 @@ namespace OpenSim.Framework.Monitoring
///
public class Stat : IDisposable
{
+// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
+
///
/// Category of this stat (e.g. cache, scene, etc).
///
@@ -204,6 +207,8 @@ namespace OpenSim.Framework.Monitoring
if (m_samples.Count >= m_maxSamples)
m_samples.Dequeue();
+// m_log.DebugFormat("[STAT]: Recording value {0} for {1}", newValue, Name);
+
m_samples.Enqueue(newValue);
}
}
--
cgit v1.1
From dda44e31e3f649875a7fc7438c4a6880c56dbb31 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Tue, 18 Jun 2013 23:10:50 +0100
Subject: minor: tidy up spacing if display a unit for additional stat
information
---
OpenSim/Framework/Monitoring/Stats/Stat.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'OpenSim/Framework/Monitoring/Stats')
diff --git a/OpenSim/Framework/Monitoring/Stats/Stat.cs b/OpenSim/Framework/Monitoring/Stats/Stat.cs
index ca71911..eb5599f 100644
--- a/OpenSim/Framework/Monitoring/Stats/Stat.cs
+++ b/OpenSim/Framework/Monitoring/Stats/Stat.cs
@@ -258,7 +258,7 @@ namespace OpenSim.Framework.Monitoring
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);
+ sb.AppendFormat(", {0:0.##} {1}/s", totalChange / divisor / (Watchdog.WATCHDOG_INTERVAL_MS / 1000), UnitName);
}
}
}
--
cgit v1.1
From 84af1cab9ba991b2356f1025cab7f58433e2ec19 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Wed, 19 Jun 2013 20:48:12 +0100
Subject: Display existing statistic of how many http requests a server is
making as server.network.HTTPRequestsMade in "show stats all"
---
OpenSim/Framework/Monitoring/Stats/Stat.cs | 5 +++++
1 file changed, 5 insertions(+)
(limited to 'OpenSim/Framework/Monitoring/Stats')
diff --git a/OpenSim/Framework/Monitoring/Stats/Stat.cs b/OpenSim/Framework/Monitoring/Stats/Stat.cs
index eb5599f..85d1a78 100644
--- a/OpenSim/Framework/Monitoring/Stats/Stat.cs
+++ b/OpenSim/Framework/Monitoring/Stats/Stat.cs
@@ -27,6 +27,7 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Reflection;
using System.Text;
using log4net;
@@ -247,6 +248,10 @@ namespace OpenSim.Framework.Monitoring
lock (m_samples)
{
+// m_log.DebugFormat(
+// "[STAT]: Samples for {0} are {1}",
+// Name, string.Join(",", m_samples.Select(s => s.ToString()).ToArray()));
+
foreach (double s in m_samples)
{
if (lastSample != null)
--
cgit v1.1
From 086fd70a5fdfd9b3a0e56201596f6d6bb20f391e Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Thu, 20 Jun 2013 00:00:39 +0100
Subject: Make it possible to specify display of stats in a particular
'container' by separating category and container with a period.
e.g. "show stats server.network"
I failed to realize this had already been implemented without the period in the show stats command (as the command help had not been updated).
However, I would prefer the . approach as it will allow specifying multiple stats, easier wildcarding, etc.
This commit also prevents any stat from having a period in its short name.
---
OpenSim/Framework/Monitoring/Stats/Stat.cs | 8 ++++++++
1 file changed, 8 insertions(+)
(limited to 'OpenSim/Framework/Monitoring/Stats')
diff --git a/OpenSim/Framework/Monitoring/Stats/Stat.cs b/OpenSim/Framework/Monitoring/Stats/Stat.cs
index 85d1a78..c57ee0c 100644
--- a/OpenSim/Framework/Monitoring/Stats/Stat.cs
+++ b/OpenSim/Framework/Monitoring/Stats/Stat.cs
@@ -42,6 +42,8 @@ namespace OpenSim.Framework.Monitoring
{
// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
+ public static readonly char[] DisallowedShortNameCharacters = { '.' };
+
///
/// Category of this stat (e.g. cache, scene, etc).
///
@@ -166,6 +168,12 @@ namespace OpenSim.Framework.Monitoring
throw new Exception(
string.Format("Stat cannot be in category '{0}' since this is reserved for a subcommand", category));
+ foreach (char c in DisallowedShortNameCharacters)
+ {
+ if (shortName.IndexOf(c) != -1)
+ throw new Exception(string.Format("Stat name {0} cannot contain character {1}", shortName, c));
+ }
+
ShortName = shortName;
Name = name;
Description = description;
--
cgit v1.1
From fa02f28dbfef9b9dc3621f5bbd6b026c827459a5 Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Fri, 12 Jul 2013 14:04:14 -0700
Subject: Add ToOSDMap() overrides to the Stat subclass CounterStat. Add a
GetStatsAsOSDMap method to StatsManager which allows the filtered fetching of
stats for eventual returning over the internets.
---
OpenSim/Framework/Monitoring/Stats/CounterStat.cs | 21 +++++++++++++++++++++
OpenSim/Framework/Monitoring/Stats/Stat.cs | 1 +
2 files changed, 22 insertions(+)
(limited to 'OpenSim/Framework/Monitoring/Stats')
diff --git a/OpenSim/Framework/Monitoring/Stats/CounterStat.cs b/OpenSim/Framework/Monitoring/Stats/CounterStat.cs
index caea30d..04442c3 100755
--- a/OpenSim/Framework/Monitoring/Stats/CounterStat.cs
+++ b/OpenSim/Framework/Monitoring/Stats/CounterStat.cs
@@ -224,5 +224,26 @@ public class CounterStat : Stat
}
}
}
+
+ // CounterStat is a basic stat plus histograms
+ public override OSDMap ToOSDMap()
+ {
+ // Get the foundational instance
+ OSDMap map = base.ToOSDMap();
+
+ map["StatType"] = "CounterStat";
+
+ // If there are any histograms, add a new field that is an array of histograms as OSDMaps
+ if (m_histograms.Count > 0)
+ {
+ OSDArray histos = new OSDArray();
+ foreach (EventHistogram histo in m_histograms.Values)
+ {
+ histos.Add(histo.GetHistogramAsOSDMap());
+ }
+ map.Add("Histograms", histos);
+ }
+ return map;
+ }
}
}
diff --git a/OpenSim/Framework/Monitoring/Stats/Stat.cs b/OpenSim/Framework/Monitoring/Stats/Stat.cs
index c57ee0c..9629b6e 100644
--- a/OpenSim/Framework/Monitoring/Stats/Stat.cs
+++ b/OpenSim/Framework/Monitoring/Stats/Stat.cs
@@ -242,6 +242,7 @@ namespace OpenSim.Framework.Monitoring
ret.Add("Description", OSD.FromString(Description));
ret.Add("UnitName", OSD.FromString(UnitName));
ret.Add("Value", OSD.FromReal(Value));
+ ret.Add("StatType", "Stat"); // used by overloading classes to denote type of stat
return ret;
}
--
cgit v1.1
From 90528c23d991cd1fc77823be49e4135cf412b92e Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Tue, 23 Jul 2013 01:13:13 +0100
Subject: For stats which can show average change over time, show the last
sample as well as the average.
This is somewhat cryptic at the moment, need to improve documentation.
---
OpenSim/Framework/Monitoring/Stats/Stat.cs | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
(limited to 'OpenSim/Framework/Monitoring/Stats')
diff --git a/OpenSim/Framework/Monitoring/Stats/Stat.cs b/OpenSim/Framework/Monitoring/Stats/Stat.cs
index 9629b6e..cc2c947 100644
--- a/OpenSim/Framework/Monitoring/Stats/Stat.cs
+++ b/OpenSim/Framework/Monitoring/Stats/Stat.cs
@@ -253,6 +253,8 @@ namespace OpenSim.Framework.Monitoring
== MeasuresOfInterest.AverageChangeOverTime)
{
double totalChange = 0;
+ double lastChangeOverTime = 0;
+ double? penultimateSample = null;
double? lastSample = null;
lock (m_samples)
@@ -266,13 +268,21 @@ namespace OpenSim.Framework.Monitoring
if (lastSample != null)
totalChange += s - (double)lastSample;
+ penultimateSample = lastSample;
lastSample = s;
}
}
+ if (lastSample != null && penultimateSample != null)
+ lastChangeOverTime = (double)lastSample - (double)penultimateSample;
+
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);
+ double averageChangeOverTime = totalChange / divisor / (Watchdog.WATCHDOG_INTERVAL_MS / 1000);
+
+ sb.AppendFormat(
+ ", {0:0.##} {1}/s, {2:0.##} {3}/s",
+ lastChangeOverTime, UnitName, averageChangeOverTime, UnitName);
}
}
}
--
cgit v1.1
From 76e46d0158461a29e6ef358ba8cb7b7323cc0c05 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Tue, 23 Jul 2013 17:23:16 +0100
Subject: Improve spacing between data and units on console stats display
---
OpenSim/Framework/Monitoring/Stats/Stat.cs | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
(limited to 'OpenSim/Framework/Monitoring/Stats')
diff --git a/OpenSim/Framework/Monitoring/Stats/Stat.cs b/OpenSim/Framework/Monitoring/Stats/Stat.cs
index cc2c947..f2329ce 100644
--- a/OpenSim/Framework/Monitoring/Stats/Stat.cs
+++ b/OpenSim/Framework/Monitoring/Stats/Stat.cs
@@ -225,7 +225,13 @@ namespace OpenSim.Framework.Monitoring
public virtual string ToConsoleString()
{
StringBuilder sb = new StringBuilder();
- sb.AppendFormat("{0}.{1}.{2} : {3} {4}", Category, Container, ShortName, Value, UnitName);
+ sb.AppendFormat(
+ "{0}.{1}.{2} : {3}{4}",
+ Category,
+ Container,
+ ShortName,
+ Value,
+ UnitName == null || UnitName == "" ? "" : string.Format(" {0}", UnitName));
AppendMeasuresOfInterest(sb);
@@ -281,8 +287,11 @@ namespace OpenSim.Framework.Monitoring
double averageChangeOverTime = totalChange / divisor / (Watchdog.WATCHDOG_INTERVAL_MS / 1000);
sb.AppendFormat(
- ", {0:0.##} {1}/s, {2:0.##} {3}/s",
- lastChangeOverTime, UnitName, averageChangeOverTime, UnitName);
+ ", {0:0.##}{1}/s, {2:0.##}{3}/s",
+ lastChangeOverTime,
+ UnitName == null || UnitName == "" ? "" : string.Format(" {0}", UnitName),
+ averageChangeOverTime,
+ UnitName == null || UnitName == "" ? "" : string.Format(" {0}", UnitName));
}
}
}
--
cgit v1.1
From 9a4a513b5e4e2496b32113dcffbeeae776eabb89 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Tue, 23 Jul 2013 23:31:35 +0100
Subject: Correct issue where the last instance of a sampled stat was shown 3x
larger than it should have been (though internal use was correct)
---
OpenSim/Framework/Monitoring/Stats/Stat.cs | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'OpenSim/Framework/Monitoring/Stats')
diff --git a/OpenSim/Framework/Monitoring/Stats/Stat.cs b/OpenSim/Framework/Monitoring/Stats/Stat.cs
index f2329ce..ffd5132 100644
--- a/OpenSim/Framework/Monitoring/Stats/Stat.cs
+++ b/OpenSim/Framework/Monitoring/Stats/Stat.cs
@@ -280,7 +280,8 @@ namespace OpenSim.Framework.Monitoring
}
if (lastSample != null && penultimateSample != null)
- lastChangeOverTime = (double)lastSample - (double)penultimateSample;
+ lastChangeOverTime
+ = ((double)lastSample - (double)penultimateSample) / (Watchdog.WATCHDOG_INTERVAL_MS / 1000);
int divisor = m_samples.Count <= 1 ? 1 : m_samples.Count - 1;
--
cgit v1.1
From 216f5afe54576c4852974b8479ac95654dc9e08e Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Sat, 10 Aug 2013 09:09:52 -0700
Subject: Stats treaking. Update ToOSDMap for Stat and PercentageStat to return
all the various numbers that have been added to the console output. Break out
EventHistogram from CounterStat.
---
OpenSim/Framework/Monitoring/Stats/CounterStat.cs | 150 ++----------------
.../Framework/Monitoring/Stats/EventHistogram.cs | 173 +++++++++++++++++++++
.../Framework/Monitoring/Stats/PercentageStat.cs | 16 ++
OpenSim/Framework/Monitoring/Stats/Stat.cs | 46 ++++--
4 files changed, 235 insertions(+), 150 deletions(-)
create mode 100755 OpenSim/Framework/Monitoring/Stats/EventHistogram.cs
(limited to 'OpenSim/Framework/Monitoring/Stats')
diff --git a/OpenSim/Framework/Monitoring/Stats/CounterStat.cs b/OpenSim/Framework/Monitoring/Stats/CounterStat.cs
index 04442c3..318cf1c 100755
--- a/OpenSim/Framework/Monitoring/Stats/CounterStat.cs
+++ b/OpenSim/Framework/Monitoring/Stats/CounterStat.cs
@@ -34,142 +34,6 @@ using OpenMetaverse.StructuredData;
namespace OpenSim.Framework.Monitoring
{
-// Create a time histogram of events. The histogram is built in a wrap-around
-// array of equally distributed buckets.
-// For instance, a minute long histogram of second sized buckets would be:
-// new EventHistogram(60, 1000)
-public class EventHistogram
-{
- private int m_timeBase;
- private int m_numBuckets;
- private int m_bucketMilliseconds;
- private int m_lastBucket;
- private int m_totalHistogramMilliseconds;
- private long[] m_histogram;
- private object histoLock = new object();
-
- public EventHistogram(int numberOfBuckets, int millisecondsPerBucket)
- {
- m_numBuckets = numberOfBuckets;
- m_bucketMilliseconds = millisecondsPerBucket;
- m_totalHistogramMilliseconds = m_numBuckets * m_bucketMilliseconds;
-
- m_histogram = new long[m_numBuckets];
- Zero();
- m_lastBucket = 0;
- m_timeBase = Util.EnvironmentTickCount();
- }
-
- public void Event()
- {
- this.Event(1);
- }
-
- // Record an event at time 'now' in the histogram.
- public void Event(int cnt)
- {
- lock (histoLock)
- {
- // The time as displaced from the base of the histogram
- int bucketTime = Util.EnvironmentTickCountSubtract(m_timeBase);
-
- // If more than the total time of the histogram, we just start over
- if (bucketTime > m_totalHistogramMilliseconds)
- {
- Zero();
- m_lastBucket = 0;
- m_timeBase = Util.EnvironmentTickCount();
- }
- else
- {
- // To which bucket should we add this event?
- int bucket = bucketTime / m_bucketMilliseconds;
-
- // Advance m_lastBucket to the new bucket. Zero any buckets skipped over.
- while (bucket != m_lastBucket)
- {
- // Zero from just after the last bucket to the new bucket or the end
- for (int jj = m_lastBucket + 1; jj <= Math.Min(bucket, m_numBuckets - 1); jj++)
- {
- m_histogram[jj] = 0;
- }
- m_lastBucket = bucket;
- // If the new bucket is off the end, wrap around to the beginning
- if (bucket > m_numBuckets)
- {
- bucket -= m_numBuckets;
- m_lastBucket = 0;
- m_histogram[m_lastBucket] = 0;
- m_timeBase += m_totalHistogramMilliseconds;
- }
- }
- }
- m_histogram[m_lastBucket] += cnt;
- }
- }
-
- // Get a copy of the current histogram
- public long[] GetHistogram()
- {
- long[] ret = new long[m_numBuckets];
- lock (histoLock)
- {
- int indx = m_lastBucket + 1;
- for (int ii = 0; ii < m_numBuckets; ii++, indx++)
- {
- if (indx >= m_numBuckets)
- indx = 0;
- ret[ii] = m_histogram[indx];
- }
- }
- return ret;
- }
-
- public OSDMap GetHistogramAsOSDMap()
- {
- OSDMap ret = new OSDMap();
-
- ret.Add("Buckets", OSD.FromInteger(m_numBuckets));
- ret.Add("BucketMilliseconds", OSD.FromInteger(m_bucketMilliseconds));
- ret.Add("TotalMilliseconds", OSD.FromInteger(m_totalHistogramMilliseconds));
-
- // Compute a number for the first bucket in the histogram.
- // This will allow readers to know how this histogram relates to any previously read histogram.
- int baseBucketNum = (m_timeBase / m_bucketMilliseconds) + m_lastBucket + 1;
- ret.Add("BaseNumber", OSD.FromInteger(baseBucketNum));
-
- ret.Add("Values", GetHistogramAsOSDArray());
-
- return ret;
- }
- // Get a copy of the current histogram
- public OSDArray GetHistogramAsOSDArray()
- {
- OSDArray ret = new OSDArray(m_numBuckets);
- lock (histoLock)
- {
- int indx = m_lastBucket + 1;
- for (int ii = 0; ii < m_numBuckets; ii++, indx++)
- {
- if (indx >= m_numBuckets)
- indx = 0;
- ret[ii] = OSD.FromLong(m_histogram[indx]);
- }
- }
- return ret;
- }
-
- // Zero out the histogram
- public void Zero()
- {
- lock (histoLock)
- {
- for (int ii = 0; ii < m_numBuckets; ii++)
- m_histogram[ii] = 0;
- }
- }
-}
-
// A statistic that wraps a counter.
// Built this way mostly so histograms and history can be created.
public class CounterStat : Stat
@@ -236,12 +100,18 @@ public class CounterStat : Stat
// If there are any histograms, add a new field that is an array of histograms as OSDMaps
if (m_histograms.Count > 0)
{
- OSDArray histos = new OSDArray();
- foreach (EventHistogram histo in m_histograms.Values)
+ lock (counterLock)
{
- histos.Add(histo.GetHistogramAsOSDMap());
+ if (m_histograms.Count > 0)
+ {
+ OSDArray histos = new OSDArray();
+ foreach (EventHistogram histo in m_histograms.Values)
+ {
+ histos.Add(histo.GetHistogramAsOSDMap());
+ }
+ map.Add("Histograms", histos);
+ }
}
- map.Add("Histograms", histos);
}
return map;
}
diff --git a/OpenSim/Framework/Monitoring/Stats/EventHistogram.cs b/OpenSim/Framework/Monitoring/Stats/EventHistogram.cs
new file mode 100755
index 0000000..f51f322
--- /dev/null
+++ b/OpenSim/Framework/Monitoring/Stats/EventHistogram.cs
@@ -0,0 +1,173 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+using OpenMetaverse.StructuredData;
+
+namespace OpenSim.Framework.Monitoring
+{
+// Create a time histogram of events. The histogram is built in a wrap-around
+// array of equally distributed buckets.
+// For instance, a minute long histogram of second sized buckets would be:
+// new EventHistogram(60, 1000)
+public class EventHistogram
+{
+ private int m_timeBase;
+ private int m_numBuckets;
+ private int m_bucketMilliseconds;
+ private int m_lastBucket;
+ private int m_totalHistogramMilliseconds;
+ private long[] m_histogram;
+ private object histoLock = new object();
+
+ public EventHistogram(int numberOfBuckets, int millisecondsPerBucket)
+ {
+ m_numBuckets = numberOfBuckets;
+ m_bucketMilliseconds = millisecondsPerBucket;
+ m_totalHistogramMilliseconds = m_numBuckets * m_bucketMilliseconds;
+
+ m_histogram = new long[m_numBuckets];
+ Zero();
+ m_lastBucket = 0;
+ m_timeBase = Util.EnvironmentTickCount();
+ }
+
+ public void Event()
+ {
+ this.Event(1);
+ }
+
+ // Record an event at time 'now' in the histogram.
+ public void Event(int cnt)
+ {
+ lock (histoLock)
+ {
+ // The time as displaced from the base of the histogram
+ int bucketTime = Util.EnvironmentTickCountSubtract(m_timeBase);
+
+ // If more than the total time of the histogram, we just start over
+ if (bucketTime > m_totalHistogramMilliseconds)
+ {
+ Zero();
+ m_lastBucket = 0;
+ m_timeBase = Util.EnvironmentTickCount();
+ }
+ else
+ {
+ // To which bucket should we add this event?
+ int bucket = bucketTime / m_bucketMilliseconds;
+
+ // Advance m_lastBucket to the new bucket. Zero any buckets skipped over.
+ while (bucket != m_lastBucket)
+ {
+ // Zero from just after the last bucket to the new bucket or the end
+ for (int jj = m_lastBucket + 1; jj <= Math.Min(bucket, m_numBuckets - 1); jj++)
+ {
+ m_histogram[jj] = 0;
+ }
+ m_lastBucket = bucket;
+ // If the new bucket is off the end, wrap around to the beginning
+ if (bucket > m_numBuckets)
+ {
+ bucket -= m_numBuckets;
+ m_lastBucket = 0;
+ m_histogram[m_lastBucket] = 0;
+ m_timeBase += m_totalHistogramMilliseconds;
+ }
+ }
+ }
+ m_histogram[m_lastBucket] += cnt;
+ }
+ }
+
+ // Get a copy of the current histogram
+ public long[] GetHistogram()
+ {
+ long[] ret = new long[m_numBuckets];
+ lock (histoLock)
+ {
+ int indx = m_lastBucket + 1;
+ for (int ii = 0; ii < m_numBuckets; ii++, indx++)
+ {
+ if (indx >= m_numBuckets)
+ indx = 0;
+ ret[ii] = m_histogram[indx];
+ }
+ }
+ return ret;
+ }
+
+ public OSDMap GetHistogramAsOSDMap()
+ {
+ OSDMap ret = new OSDMap();
+
+ ret.Add("Buckets", OSD.FromInteger(m_numBuckets));
+ ret.Add("BucketMilliseconds", OSD.FromInteger(m_bucketMilliseconds));
+ ret.Add("TotalMilliseconds", OSD.FromInteger(m_totalHistogramMilliseconds));
+
+ // Compute a number for the first bucket in the histogram.
+ // This will allow readers to know how this histogram relates to any previously read histogram.
+ int baseBucketNum = (m_timeBase / m_bucketMilliseconds) + m_lastBucket + 1;
+ ret.Add("BaseNumber", OSD.FromInteger(baseBucketNum));
+
+ ret.Add("Values", GetHistogramAsOSDArray());
+
+ return ret;
+ }
+ // Get a copy of the current histogram
+ public OSDArray GetHistogramAsOSDArray()
+ {
+ OSDArray ret = new OSDArray(m_numBuckets);
+ lock (histoLock)
+ {
+ int indx = m_lastBucket + 1;
+ for (int ii = 0; ii < m_numBuckets; ii++, indx++)
+ {
+ if (indx >= m_numBuckets)
+ indx = 0;
+ ret[ii] = OSD.FromLong(m_histogram[indx]);
+ }
+ }
+ return ret;
+ }
+
+ // Zero out the histogram
+ public void Zero()
+ {
+ lock (histoLock)
+ {
+ for (int ii = 0; ii < m_numBuckets; ii++)
+ m_histogram[ii] = 0;
+ }
+ }
+}
+
+}
diff --git a/OpenSim/Framework/Monitoring/Stats/PercentageStat.cs b/OpenSim/Framework/Monitoring/Stats/PercentageStat.cs
index 60bed55..55ddf06 100644
--- a/OpenSim/Framework/Monitoring/Stats/PercentageStat.cs
+++ b/OpenSim/Framework/Monitoring/Stats/PercentageStat.cs
@@ -29,6 +29,8 @@ using System;
using System.Collections.Generic;
using System.Text;
+using OpenMetaverse.StructuredData;
+
namespace OpenSim.Framework.Monitoring
{
public class PercentageStat : Stat
@@ -84,5 +86,19 @@ namespace OpenSim.Framework.Monitoring
return sb.ToString();
}
+
+ // PercentageStat is a basic stat plus percent calc
+ public override OSDMap ToOSDMap()
+ {
+ // Get the foundational instance
+ OSDMap map = base.ToOSDMap();
+
+ map["StatType"] = "PercentageStat";
+
+ map.Add("Antecedent", OSD.FromLong(Antecedent));
+ map.Add("Consequent", OSD.FromLong(Consequent));
+
+ return map;
+ }
}
}
\ No newline at end of file
diff --git a/OpenSim/Framework/Monitoring/Stats/Stat.cs b/OpenSim/Framework/Monitoring/Stats/Stat.cs
index ffd5132..2b34493 100644
--- a/OpenSim/Framework/Monitoring/Stats/Stat.cs
+++ b/OpenSim/Framework/Monitoring/Stats/Stat.cs
@@ -241,6 +241,8 @@ namespace OpenSim.Framework.Monitoring
public virtual OSDMap ToOSDMap()
{
OSDMap ret = new OSDMap();
+ ret.Add("StatType", "Stat"); // used by overloading classes to denote type of stat
+
ret.Add("Category", OSD.FromString(Category));
ret.Add("Container", OSD.FromString(Container));
ret.Add("ShortName", OSD.FromString(ShortName));
@@ -248,26 +250,36 @@ namespace OpenSim.Framework.Monitoring
ret.Add("Description", OSD.FromString(Description));
ret.Add("UnitName", OSD.FromString(UnitName));
ret.Add("Value", OSD.FromReal(Value));
- ret.Add("StatType", "Stat"); // used by overloading classes to denote type of stat
+
+ double lastChangeOverTime, averageChangeOverTime;
+ if (ComputeMeasuresOfInterest(out lastChangeOverTime, out averageChangeOverTime))
+ {
+ ret.Add("LastChangeOverTime", OSD.FromReal(lastChangeOverTime));
+ ret.Add("AverageChangeOverTime", OSD.FromReal(averageChangeOverTime));
+ }
return ret;
}
- protected void AppendMeasuresOfInterest(StringBuilder sb)
+ // Compute the averages over time and return same.
+ // Return 'true' if averages were actually computed. 'false' if no average info.
+ public bool ComputeMeasuresOfInterest(out double lastChangeOverTime, out double averageChangeOverTime)
{
- if ((MeasuresOfInterest & MeasuresOfInterest.AverageChangeOverTime)
- == MeasuresOfInterest.AverageChangeOverTime)
+ bool ret = false;
+ lastChangeOverTime = 0;
+ averageChangeOverTime = 0;
+
+ if ((MeasuresOfInterest & MeasuresOfInterest.AverageChangeOverTime) == MeasuresOfInterest.AverageChangeOverTime)
{
double totalChange = 0;
- double lastChangeOverTime = 0;
double? penultimateSample = null;
double? lastSample = null;
lock (m_samples)
{
-// m_log.DebugFormat(
-// "[STAT]: Samples for {0} are {1}",
-// Name, string.Join(",", m_samples.Select(s => s.ToString()).ToArray()));
+ // m_log.DebugFormat(
+ // "[STAT]: Samples for {0} are {1}",
+ // Name, string.Join(",", m_samples.Select(s => s.ToString()).ToArray()));
foreach (double s in m_samples)
{
@@ -280,13 +292,27 @@ namespace OpenSim.Framework.Monitoring
}
if (lastSample != null && penultimateSample != null)
- lastChangeOverTime
+ {
+ lastChangeOverTime
= ((double)lastSample - (double)penultimateSample) / (Watchdog.WATCHDOG_INTERVAL_MS / 1000);
+ }
int divisor = m_samples.Count <= 1 ? 1 : m_samples.Count - 1;
- double averageChangeOverTime = totalChange / divisor / (Watchdog.WATCHDOG_INTERVAL_MS / 1000);
+ averageChangeOverTime = totalChange / divisor / (Watchdog.WATCHDOG_INTERVAL_MS / 1000);
+ ret = true;
+ }
+
+ return ret;
+ }
+ protected void AppendMeasuresOfInterest(StringBuilder sb)
+ {
+ double lastChangeOverTime = 0;
+ double averageChangeOverTime = 0;
+
+ if (ComputeMeasuresOfInterest(out lastChangeOverTime, out averageChangeOverTime))
+ {
sb.AppendFormat(
", {0:0.##}{1}/s, {2:0.##}{3}/s",
lastChangeOverTime,
--
cgit v1.1
From 7cab41f4223b7febd3fdd42fa7cfefef25e4a9c9 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 15 Nov 2013 21:45:08 +0000
Subject: refactor: replace verbose checks with String.IsNullOrEmpty where
applicable.
Thanks to Kira for this patch from http://opensimulator.org/mantis/view.php?id=6845
---
OpenSim/Framework/Monitoring/Stats/Stat.cs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'OpenSim/Framework/Monitoring/Stats')
diff --git a/OpenSim/Framework/Monitoring/Stats/Stat.cs b/OpenSim/Framework/Monitoring/Stats/Stat.cs
index 2b34493..e095801 100644
--- a/OpenSim/Framework/Monitoring/Stats/Stat.cs
+++ b/OpenSim/Framework/Monitoring/Stats/Stat.cs
@@ -231,7 +231,7 @@ namespace OpenSim.Framework.Monitoring
Container,
ShortName,
Value,
- UnitName == null || UnitName == "" ? "" : string.Format(" {0}", UnitName));
+ string.IsNullOrEmpty(UnitName) ? "" : string.Format(" {0}", UnitName));
AppendMeasuresOfInterest(sb);
@@ -316,9 +316,9 @@ namespace OpenSim.Framework.Monitoring
sb.AppendFormat(
", {0:0.##}{1}/s, {2:0.##}{3}/s",
lastChangeOverTime,
- UnitName == null || UnitName == "" ? "" : string.Format(" {0}", UnitName),
+ string.IsNullOrEmpty(UnitName) ? "" : string.Format(" {0}", UnitName),
averageChangeOverTime,
- UnitName == null || UnitName == "" ? "" : string.Format(" {0}", UnitName));
+ string.IsNullOrEmpty(UnitName) ? "" : string.Format(" {0}", UnitName));
}
}
}
--
cgit v1.1