diff options
author | Justin Clark-Casey (justincc) | 2012-11-16 05:02:06 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2012-11-16 05:02:06 +0000 |
commit | 55f889cc66d78268c530c65a5fd111395cc26dc5 (patch) | |
tree | 8b8ba657ec3c7d9f213c90652844795d615bb4e8 /OpenSim/Framework/Monitoring/StatsManager.cs | |
parent | Merge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff) | |
download | opensim-SC-55f889cc66d78268c530c65a5fd111395cc26dc5.zip opensim-SC-55f889cc66d78268c530c65a5fd111395cc26dc5.tar.gz opensim-SC-55f889cc66d78268c530c65a5fd111395cc26dc5.tar.bz2 opensim-SC-55f889cc66d78268c530c65a5fd111395cc26dc5.tar.xz |
refactor: Move stat classes out of StatManager and into their own files for clarity.
Diffstat (limited to 'OpenSim/Framework/Monitoring/StatsManager.cs')
-rw-r--r-- | OpenSim/Framework/Monitoring/StatsManager.cs | 260 |
1 files changed, 0 insertions, 260 deletions
diff --git a/OpenSim/Framework/Monitoring/StatsManager.cs b/OpenSim/Framework/Monitoring/StatsManager.cs index eae7505..0762b01 100644 --- a/OpenSim/Framework/Monitoring/StatsManager.cs +++ b/OpenSim/Framework/Monitoring/StatsManager.cs | |||
@@ -301,264 +301,4 @@ namespace OpenSim.Framework.Monitoring | |||
301 | Debug, | 301 | Debug, |
302 | Info | 302 | Info |
303 | } | 303 | } |
304 | |||
305 | /// <summary> | ||
306 | /// Holds individual static details | ||
307 | /// </summary> | ||
308 | public class Stat | ||
309 | { | ||
310 | /// <summary> | ||
311 | /// Category of this stat (e.g. cache, scene, etc). | ||
312 | /// </summary> | ||
313 | public string Category { get; private set; } | ||
314 | |||
315 | /// <summary> | ||
316 | /// Containing name for this stat. | ||
317 | /// FIXME: In the case of a scene, this is currently the scene name (though this leaves | ||
318 | /// us with a to-be-resolved problem of non-unique region names). | ||
319 | /// </summary> | ||
320 | /// <value> | ||
321 | /// The container. | ||
322 | /// </value> | ||
323 | public string Container { get; private set; } | ||
324 | |||
325 | public StatType StatType { get; private set; } | ||
326 | |||
327 | public MeasuresOfInterest MeasuresOfInterest { get; private set; } | ||
328 | |||
329 | /// <summary> | ||
330 | /// Action used to update this stat when the value is requested if it's a pull type. | ||
331 | /// </summary> | ||
332 | public Action<Stat> PullAction { get; private set; } | ||
333 | |||
334 | public StatVerbosity Verbosity { get; private set; } | ||
335 | public string ShortName { get; private set; } | ||
336 | public string Name { get; private set; } | ||
337 | public string Description { get; private set; } | ||
338 | public virtual string UnitName { get; private set; } | ||
339 | |||
340 | public virtual double Value | ||
341 | { | ||
342 | get | ||
343 | { | ||
344 | // Asking for an update here means that the updater cannot access this value without infinite recursion. | ||
345 | // XXX: A slightly messy but simple solution may be to flick a flag so we can tell if this is being | ||
346 | // called by the pull action and just return the value. | ||
347 | if (StatType == StatType.Pull) | ||
348 | PullAction(this); | ||
349 | |||
350 | return m_value; | ||
351 | } | ||
352 | |||
353 | set | ||
354 | { | ||
355 | m_value = value; | ||
356 | } | ||
357 | } | ||
358 | |||
359 | private double m_value; | ||
360 | |||
361 | /// <summary> | ||
362 | /// Historical samples for calculating measures of interest average. | ||
363 | /// </summary> | ||
364 | /// <remarks> | ||
365 | /// Will be null if no measures of interest require samples. | ||
366 | /// </remarks> | ||
367 | private static Queue<double> m_samples; | ||
368 | |||
369 | /// <summary> | ||
370 | /// Maximum number of statistical samples. | ||
371 | /// </summary> | ||
372 | /// <remarks> | ||
373 | /// At the moment this corresponds to 1 minute since the sampling rate is every 2.5 seconds as triggered from | ||
374 | /// the main Watchdog. | ||
375 | /// </remarks> | ||
376 | private static int m_maxSamples = 24; | ||
377 | |||
378 | public Stat( | ||
379 | string shortName, | ||
380 | string name, | ||
381 | string description, | ||
382 | string unitName, | ||
383 | string category, | ||
384 | string container, | ||
385 | StatType type, | ||
386 | Action<Stat> pullAction, | ||
387 | StatVerbosity verbosity) | ||
388 | : this( | ||
389 | shortName, | ||
390 | name, | ||
391 | description, | ||
392 | unitName, | ||
393 | category, | ||
394 | container, | ||
395 | type, | ||
396 | MeasuresOfInterest.None, | ||
397 | pullAction, | ||
398 | verbosity) | ||
399 | { | ||
400 | } | ||
401 | |||
402 | /// <summary> | ||
403 | /// Constructor | ||
404 | /// </summary> | ||
405 | /// <param name='shortName'>Short name for the stat. Must not contain spaces. e.g. "LongFrames"</param> | ||
406 | /// <param name='name'>Human readable name for the stat. e.g. "Long frames"</param> | ||
407 | /// <param name='description'>Description of stat</param> | ||
408 | /// <param name='unitName'> | ||
409 | /// Unit name for the stat. Should be preceeded by a space if the unit name isn't normally appeneded immediately to the value. | ||
410 | /// e.g. " frames" | ||
411 | /// </param> | ||
412 | /// <param name='category'>Category under which this stat should appear, e.g. "scene". Do not capitalize.</param> | ||
413 | /// <param name='container'>Entity to which this stat relates. e.g. scene name if this is a per scene stat.</param> | ||
414 | /// <param name='type'>Push or pull</param> | ||
415 | /// <param name='pullAction'>Pull stats need an action to update the stat on request. Push stats should set null here.</param> | ||
416 | /// <param name='moi'>Measures of interest</param> | ||
417 | /// <param name='verbosity'>Verbosity of stat. Controls whether it will appear in short stat display or only full display.</param> | ||
418 | public Stat( | ||
419 | string shortName, | ||
420 | string name, | ||
421 | string description, | ||
422 | string unitName, | ||
423 | string category, | ||
424 | string container, | ||
425 | StatType type, | ||
426 | MeasuresOfInterest moi, | ||
427 | Action<Stat> pullAction, | ||
428 | StatVerbosity verbosity) | ||
429 | { | ||
430 | if (StatsManager.SubCommands.Contains(category)) | ||
431 | throw new Exception( | ||
432 | string.Format("Stat cannot be in category '{0}' since this is reserved for a subcommand", category)); | ||
433 | |||
434 | ShortName = shortName; | ||
435 | Name = name; | ||
436 | Description = description; | ||
437 | UnitName = unitName; | ||
438 | Category = category; | ||
439 | Container = container; | ||
440 | StatType = type; | ||
441 | |||
442 | if (StatType == StatType.Push && pullAction != null) | ||
443 | throw new Exception("A push stat cannot have a pull action"); | ||
444 | else | ||
445 | PullAction = pullAction; | ||
446 | |||
447 | MeasuresOfInterest = moi; | ||
448 | |||
449 | if ((moi & MeasuresOfInterest.AverageChangeOverTime) == MeasuresOfInterest.AverageChangeOverTime) | ||
450 | m_samples = new Queue<double>(m_maxSamples); | ||
451 | |||
452 | Verbosity = verbosity; | ||
453 | } | ||
454 | |||
455 | /// <summary> | ||
456 | /// Record a value in the sample set. | ||
457 | /// </summary> | ||
458 | /// <remarks> | ||
459 | /// Do not call this if MeasuresOfInterest.None | ||
460 | /// </remarks> | ||
461 | public void RecordValue() | ||
462 | { | ||
463 | double newValue = Value; | ||
464 | |||
465 | lock (m_samples) | ||
466 | { | ||
467 | if (m_samples.Count >= m_maxSamples) | ||
468 | m_samples.Dequeue(); | ||
469 | |||
470 | m_samples.Enqueue(newValue); | ||
471 | } | ||
472 | } | ||
473 | |||
474 | public virtual string ToConsoleString() | ||
475 | { | ||
476 | StringBuilder sb = new StringBuilder(); | ||
477 | sb.AppendFormat("{0}.{1}.{2} : {3}{4}", Category, Container, ShortName, Value, UnitName); | ||
478 | |||
479 | AppendMeasuresOfInterest(sb); | ||
480 | |||
481 | return sb.ToString(); | ||
482 | } | ||
483 | |||
484 | protected void AppendMeasuresOfInterest(StringBuilder sb) | ||
485 | { | ||
486 | if ((MeasuresOfInterest & MeasuresOfInterest.AverageChangeOverTime) | ||
487 | == MeasuresOfInterest.AverageChangeOverTime) | ||
488 | { | ||
489 | double totalChange = 0; | ||
490 | double? lastSample = null; | ||
491 | |||
492 | lock (m_samples) | ||
493 | { | ||
494 | foreach (double s in m_samples) | ||
495 | { | ||
496 | if (lastSample != null) | ||
497 | totalChange += s - (double)lastSample; | ||
498 | |||
499 | lastSample = s; | ||
500 | } | ||
501 | } | ||
502 | |||
503 | int divisor = m_samples.Count <= 1 ? 1 : m_samples.Count - 1; | ||
504 | |||
505 | sb.AppendFormat(", {0:0.##}{1}/s", totalChange / divisor / (Watchdog.WATCHDOG_INTERVAL_MS / 1000), UnitName); | ||
506 | } | ||
507 | } | ||
508 | } | ||
509 | |||
510 | public class PercentageStat : Stat | ||
511 | { | ||
512 | public long Antecedent { get; set; } | ||
513 | public long Consequent { get; set; } | ||
514 | |||
515 | public override double Value | ||
516 | { | ||
517 | get | ||
518 | { | ||
519 | // Asking for an update here means that the updater cannot access this value without infinite recursion. | ||
520 | // XXX: A slightly messy but simple solution may be to flick a flag so we can tell if this is being | ||
521 | // called by the pull action and just return the value. | ||
522 | if (StatType == StatType.Pull) | ||
523 | PullAction(this); | ||
524 | |||
525 | long c = Consequent; | ||
526 | |||
527 | // Avoid any chance of a multi-threaded divide-by-zero | ||
528 | if (c == 0) | ||
529 | return 0; | ||
530 | |||
531 | return (double)Antecedent / c * 100; | ||
532 | } | ||
533 | |||
534 | set | ||
535 | { | ||
536 | throw new InvalidOperationException("Cannot set value on a PercentageStat"); | ||
537 | } | ||
538 | } | ||
539 | |||
540 | public PercentageStat( | ||
541 | string shortName, | ||
542 | string name, | ||
543 | string description, | ||
544 | string category, | ||
545 | string container, | ||
546 | StatType type, | ||
547 | Action<Stat> pullAction, | ||
548 | StatVerbosity verbosity) | ||
549 | : base(shortName, name, description, "%", category, container, type, pullAction, verbosity) {} | ||
550 | |||
551 | public override string ToConsoleString() | ||
552 | { | ||
553 | StringBuilder sb = new StringBuilder(); | ||
554 | |||
555 | sb.AppendFormat( | ||
556 | "{0}.{1}.{2} : {3:0.##}{4} ({5}/{6})", | ||
557 | Category, Container, ShortName, Value, UnitName, Antecedent, Consequent); | ||
558 | |||
559 | AppendMeasuresOfInterest(sb); | ||
560 | |||
561 | return sb.ToString(); | ||
562 | } | ||
563 | } | ||
564 | } \ No newline at end of file | 304 | } \ No newline at end of file |