diff options
author | Melanie Thielker | 2014-06-21 00:39:55 +0200 |
---|---|---|
committer | Melanie Thielker | 2014-06-21 00:39:55 +0200 |
commit | 159fcbf150b7da0e229b29aa7b94793484543d12 (patch) | |
tree | b8c0ff3b4c758a3fba8315b556c923ef4c02a185 /OpenSim/Framework/Monitoring/Stats/Stat.cs | |
parent | Merge commit '68c8633ba18f0a11cfc0ed04d1d0c7c59e6cec76' (diff) | |
parent | Merge branch 'master' into careminster (diff) | |
download | opensim-SC-159fcbf150b7da0e229b29aa7b94793484543d12.zip opensim-SC-159fcbf150b7da0e229b29aa7b94793484543d12.tar.gz opensim-SC-159fcbf150b7da0e229b29aa7b94793484543d12.tar.bz2 opensim-SC-159fcbf150b7da0e229b29aa7b94793484543d12.tar.xz |
Merge branch 'master' of ssh://3dhosting.de/var/git/careminster
Conflicts:
OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
Diffstat (limited to 'OpenSim/Framework/Monitoring/Stats/Stat.cs')
-rw-r--r-- | OpenSim/Framework/Monitoring/Stats/Stat.cs | 79 |
1 files changed, 72 insertions, 7 deletions
diff --git a/OpenSim/Framework/Monitoring/Stats/Stat.cs b/OpenSim/Framework/Monitoring/Stats/Stat.cs index 2e7665f..e095801 100644 --- a/OpenSim/Framework/Monitoring/Stats/Stat.cs +++ b/OpenSim/Framework/Monitoring/Stats/Stat.cs | |||
@@ -27,8 +27,10 @@ | |||
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Linq; | ||
31 | using System.Reflection; | ||
30 | using System.Text; | 32 | using System.Text; |
31 | 33 | using log4net; | |
32 | using OpenMetaverse.StructuredData; | 34 | using OpenMetaverse.StructuredData; |
33 | 35 | ||
34 | namespace OpenSim.Framework.Monitoring | 36 | namespace OpenSim.Framework.Monitoring |
@@ -38,6 +40,10 @@ namespace OpenSim.Framework.Monitoring | |||
38 | /// </summary> | 40 | /// </summary> |
39 | public class Stat : IDisposable | 41 | public class Stat : IDisposable |
40 | { | 42 | { |
43 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
44 | |||
45 | public static readonly char[] DisallowedShortNameCharacters = { '.' }; | ||
46 | |||
41 | /// <summary> | 47 | /// <summary> |
42 | /// Category of this stat (e.g. cache, scene, etc). | 48 | /// Category of this stat (e.g. cache, scene, etc). |
43 | /// </summary> | 49 | /// </summary> |
@@ -95,7 +101,7 @@ namespace OpenSim.Framework.Monitoring | |||
95 | /// <remarks> | 101 | /// <remarks> |
96 | /// Will be null if no measures of interest require samples. | 102 | /// Will be null if no measures of interest require samples. |
97 | /// </remarks> | 103 | /// </remarks> |
98 | private static Queue<double> m_samples; | 104 | private Queue<double> m_samples; |
99 | 105 | ||
100 | /// <summary> | 106 | /// <summary> |
101 | /// Maximum number of statistical samples. | 107 | /// Maximum number of statistical samples. |
@@ -162,6 +168,12 @@ namespace OpenSim.Framework.Monitoring | |||
162 | throw new Exception( | 168 | throw new Exception( |
163 | string.Format("Stat cannot be in category '{0}' since this is reserved for a subcommand", category)); | 169 | string.Format("Stat cannot be in category '{0}' since this is reserved for a subcommand", category)); |
164 | 170 | ||
171 | foreach (char c in DisallowedShortNameCharacters) | ||
172 | { | ||
173 | if (shortName.IndexOf(c) != -1) | ||
174 | throw new Exception(string.Format("Stat name {0} cannot contain character {1}", shortName, c)); | ||
175 | } | ||
176 | |||
165 | ShortName = shortName; | 177 | ShortName = shortName; |
166 | Name = name; | 178 | Name = name; |
167 | Description = description; | 179 | Description = description; |
@@ -204,6 +216,8 @@ namespace OpenSim.Framework.Monitoring | |||
204 | if (m_samples.Count >= m_maxSamples) | 216 | if (m_samples.Count >= m_maxSamples) |
205 | m_samples.Dequeue(); | 217 | m_samples.Dequeue(); |
206 | 218 | ||
219 | // m_log.DebugFormat("[STAT]: Recording value {0} for {1}", newValue, Name); | ||
220 | |||
207 | m_samples.Enqueue(newValue); | 221 | m_samples.Enqueue(newValue); |
208 | } | 222 | } |
209 | } | 223 | } |
@@ -211,7 +225,13 @@ namespace OpenSim.Framework.Monitoring | |||
211 | public virtual string ToConsoleString() | 225 | public virtual string ToConsoleString() |
212 | { | 226 | { |
213 | StringBuilder sb = new StringBuilder(); | 227 | StringBuilder sb = new StringBuilder(); |
214 | sb.AppendFormat("{0}.{1}.{2} : {3} {4}", Category, Container, ShortName, Value, UnitName); | 228 | sb.AppendFormat( |
229 | "{0}.{1}.{2} : {3}{4}", | ||
230 | Category, | ||
231 | Container, | ||
232 | ShortName, | ||
233 | Value, | ||
234 | string.IsNullOrEmpty(UnitName) ? "" : string.Format(" {0}", UnitName)); | ||
215 | 235 | ||
216 | AppendMeasuresOfInterest(sb); | 236 | AppendMeasuresOfInterest(sb); |
217 | 237 | ||
@@ -221,6 +241,8 @@ namespace OpenSim.Framework.Monitoring | |||
221 | public virtual OSDMap ToOSDMap() | 241 | public virtual OSDMap ToOSDMap() |
222 | { | 242 | { |
223 | OSDMap ret = new OSDMap(); | 243 | OSDMap ret = new OSDMap(); |
244 | ret.Add("StatType", "Stat"); // used by overloading classes to denote type of stat | ||
245 | |||
224 | ret.Add("Category", OSD.FromString(Category)); | 246 | ret.Add("Category", OSD.FromString(Category)); |
225 | ret.Add("Container", OSD.FromString(Container)); | 247 | ret.Add("Container", OSD.FromString(Container)); |
226 | ret.Add("ShortName", OSD.FromString(ShortName)); | 248 | ret.Add("ShortName", OSD.FromString(ShortName)); |
@@ -229,31 +251,74 @@ namespace OpenSim.Framework.Monitoring | |||
229 | ret.Add("UnitName", OSD.FromString(UnitName)); | 251 | ret.Add("UnitName", OSD.FromString(UnitName)); |
230 | ret.Add("Value", OSD.FromReal(Value)); | 252 | ret.Add("Value", OSD.FromReal(Value)); |
231 | 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 | } | ||
260 | |||
232 | return ret; | 261 | return ret; |
233 | } | 262 | } |
234 | 263 | ||
235 | 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) | ||
236 | { | 267 | { |
237 | if ((MeasuresOfInterest & MeasuresOfInterest.AverageChangeOverTime) | 268 | bool ret = false; |
238 | == MeasuresOfInterest.AverageChangeOverTime) | 269 | lastChangeOverTime = 0; |
270 | averageChangeOverTime = 0; | ||
271 | |||
272 | if ((MeasuresOfInterest & MeasuresOfInterest.AverageChangeOverTime) == MeasuresOfInterest.AverageChangeOverTime) | ||
239 | { | 273 | { |
240 | double totalChange = 0; | 274 | double totalChange = 0; |
275 | double? penultimateSample = null; | ||
241 | double? lastSample = null; | 276 | double? lastSample = null; |
242 | 277 | ||
243 | lock (m_samples) | 278 | lock (m_samples) |
244 | { | 279 | { |
280 | // m_log.DebugFormat( | ||
281 | // "[STAT]: Samples for {0} are {1}", | ||
282 | // Name, string.Join(",", m_samples.Select(s => s.ToString()).ToArray())); | ||
283 | |||
245 | foreach (double s in m_samples) | 284 | foreach (double s in m_samples) |
246 | { | 285 | { |
247 | if (lastSample != null) | 286 | if (lastSample != null) |
248 | totalChange += s - (double)lastSample; | 287 | totalChange += s - (double)lastSample; |
249 | 288 | ||
289 | penultimateSample = lastSample; | ||
250 | lastSample = s; | 290 | lastSample = s; |
251 | } | 291 | } |
252 | } | 292 | } |
253 | 293 | ||
294 | if (lastSample != null && penultimateSample != null) | ||
295 | { | ||
296 | lastChangeOverTime | ||
297 | = ((double)lastSample - (double)penultimateSample) / (Watchdog.WATCHDOG_INTERVAL_MS / 1000); | ||
298 | } | ||
299 | |||
254 | int divisor = m_samples.Count <= 1 ? 1 : m_samples.Count - 1; | 300 | int divisor = m_samples.Count <= 1 ? 1 : m_samples.Count - 1; |
255 | 301 | ||
256 | sb.AppendFormat(", {0:0.##}{1}/s", totalChange / divisor / (Watchdog.WATCHDOG_INTERVAL_MS / 1000), UnitName); | 302 | averageChangeOverTime = totalChange / divisor / (Watchdog.WATCHDOG_INTERVAL_MS / 1000); |
303 | ret = true; | ||
304 | } | ||
305 | |||
306 | return ret; | ||
307 | } | ||
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 | { | ||
316 | sb.AppendFormat( | ||
317 | ", {0:0.##}{1}/s, {2:0.##}{3}/s", | ||
318 | lastChangeOverTime, | ||
319 | string.IsNullOrEmpty(UnitName) ? "" : string.Format(" {0}", UnitName), | ||
320 | averageChangeOverTime, | ||
321 | string.IsNullOrEmpty(UnitName) ? "" : string.Format(" {0}", UnitName)); | ||
257 | } | 322 | } |
258 | } | 323 | } |
259 | } | 324 | } |