diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/Monitoring/Stats/Stat.cs | 46 |
1 files changed, 36 insertions, 10 deletions
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 | |||
241 | public virtual OSDMap ToOSDMap() | 241 | public virtual OSDMap ToOSDMap() |
242 | { | 242 | { |
243 | OSDMap ret = new OSDMap(); | 243 | OSDMap ret = new OSDMap(); |
244 | ret.Add("StatType", "Stat"); // used by overloading classes to denote type of stat | ||
245 | |||
244 | ret.Add("Category", OSD.FromString(Category)); | 246 | ret.Add("Category", OSD.FromString(Category)); |
245 | ret.Add("Container", OSD.FromString(Container)); | 247 | ret.Add("Container", OSD.FromString(Container)); |
246 | ret.Add("ShortName", OSD.FromString(ShortName)); | 248 | ret.Add("ShortName", OSD.FromString(ShortName)); |
@@ -248,26 +250,36 @@ namespace OpenSim.Framework.Monitoring | |||
248 | ret.Add("Description", OSD.FromString(Description)); | 250 | ret.Add("Description", OSD.FromString(Description)); |
249 | ret.Add("UnitName", OSD.FromString(UnitName)); | 251 | ret.Add("UnitName", OSD.FromString(UnitName)); |
250 | ret.Add("Value", OSD.FromReal(Value)); | 252 | ret.Add("Value", OSD.FromReal(Value)); |
251 | ret.Add("StatType", "Stat"); // used by overloading classes to denote type of stat | 253 | |
254 | double lastChangeOverTime, averageChangeOverTime; | ||
255 | if (ComputeMeasuresOfInterest(out lastChangeOverTime, out averageChangeOverTime)) | ||
256 | { | ||
257 | ret.Add("LastChangeOverTime", OSD.FromReal(lastChangeOverTime)); | ||
258 | ret.Add("AverageChangeOverTime", OSD.FromReal(averageChangeOverTime)); | ||
259 | } | ||
252 | 260 | ||
253 | return ret; | 261 | return ret; |
254 | } | 262 | } |
255 | 263 | ||
256 | protected void AppendMeasuresOfInterest(StringBuilder sb) | 264 | // Compute the averages over time and return same. |
265 | // Return 'true' if averages were actually computed. 'false' if no average info. | ||
266 | public bool ComputeMeasuresOfInterest(out double lastChangeOverTime, out double averageChangeOverTime) | ||
257 | { | 267 | { |
258 | if ((MeasuresOfInterest & MeasuresOfInterest.AverageChangeOverTime) | 268 | bool ret = false; |
259 | == MeasuresOfInterest.AverageChangeOverTime) | 269 | lastChangeOverTime = 0; |
270 | averageChangeOverTime = 0; | ||
271 | |||
272 | if ((MeasuresOfInterest & MeasuresOfInterest.AverageChangeOverTime) == MeasuresOfInterest.AverageChangeOverTime) | ||
260 | { | 273 | { |
261 | double totalChange = 0; | 274 | double totalChange = 0; |
262 | double lastChangeOverTime = 0; | ||
263 | double? penultimateSample = null; | 275 | double? penultimateSample = null; |
264 | double? lastSample = null; | 276 | double? lastSample = null; |
265 | 277 | ||
266 | lock (m_samples) | 278 | lock (m_samples) |
267 | { | 279 | { |
268 | // m_log.DebugFormat( | 280 | // m_log.DebugFormat( |
269 | // "[STAT]: Samples for {0} are {1}", | 281 | // "[STAT]: Samples for {0} are {1}", |
270 | // Name, string.Join(",", m_samples.Select(s => s.ToString()).ToArray())); | 282 | // Name, string.Join(",", m_samples.Select(s => s.ToString()).ToArray())); |
271 | 283 | ||
272 | foreach (double s in m_samples) | 284 | foreach (double s in m_samples) |
273 | { | 285 | { |
@@ -280,13 +292,27 @@ namespace OpenSim.Framework.Monitoring | |||
280 | } | 292 | } |
281 | 293 | ||
282 | if (lastSample != null && penultimateSample != null) | 294 | if (lastSample != null && penultimateSample != null) |
283 | lastChangeOverTime | 295 | { |
296 | lastChangeOverTime | ||
284 | = ((double)lastSample - (double)penultimateSample) / (Watchdog.WATCHDOG_INTERVAL_MS / 1000); | 297 | = ((double)lastSample - (double)penultimateSample) / (Watchdog.WATCHDOG_INTERVAL_MS / 1000); |
298 | } | ||
285 | 299 | ||
286 | int divisor = m_samples.Count <= 1 ? 1 : m_samples.Count - 1; | 300 | int divisor = m_samples.Count <= 1 ? 1 : m_samples.Count - 1; |
287 | 301 | ||
288 | double averageChangeOverTime = totalChange / divisor / (Watchdog.WATCHDOG_INTERVAL_MS / 1000); | 302 | averageChangeOverTime = totalChange / divisor / (Watchdog.WATCHDOG_INTERVAL_MS / 1000); |
303 | ret = true; | ||
304 | } | ||
305 | |||
306 | return ret; | ||
307 | } | ||
289 | 308 | ||
309 | protected void AppendMeasuresOfInterest(StringBuilder sb) | ||
310 | { | ||
311 | double lastChangeOverTime = 0; | ||
312 | double averageChangeOverTime = 0; | ||
313 | |||
314 | if (ComputeMeasuresOfInterest(out lastChangeOverTime, out averageChangeOverTime)) | ||
315 | { | ||
290 | sb.AppendFormat( | 316 | sb.AppendFormat( |
291 | ", {0:0.##}{1}/s, {2:0.##}{3}/s", | 317 | ", {0:0.##}{1}/s, {2:0.##}{3}/s", |
292 | lastChangeOverTime, | 318 | lastChangeOverTime, |