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.
cpu-performance
Robert Adams 2013-07-12 14:04:14 -07:00
parent 3d700bb42c
commit fa02f28dbf
3 changed files with 88 additions and 0 deletions

View File

@ -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;
}
}
}

View File

@ -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;
}

View File

@ -30,6 +30,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenMetaverse.StructuredData;
namespace OpenSim.Framework.Monitoring
{
/// <summary>
@ -168,6 +170,70 @@ namespace OpenSim.Framework.Monitoring
}
}
// Creates an OSDMap of the format:
// { categoryName: {
// containerName: {
// statName: {
// "Name": name,
// "ShortName": shortName,
// ...
// },
// statName: {
// "Name": name,
// "ShortName": shortName,
// ...
// },
// ...
// },
// containerName: {
// ...
// },
// ...
// },
// categoryName: {
// ...
// },
// ...
// }
// The passed in parameters will filter the categories, containers and stats returned. If any of the
// parameters are either EmptyOrNull or the AllSubCommand value, all of that type will be returned.
// Case matters.
public static OSDMap GetStatsAsOSDMap(string pCategoryName, string pContainerName, string pStatName)
{
OSDMap map = new OSDMap();
foreach (string catName in RegisteredStats.Keys)
{
// Do this category if null spec, "all" subcommand or category name matches passed parameter.
// Skip category if none of the above.
if (!(String.IsNullOrEmpty(pCategoryName) || pCategoryName == AllSubCommand || pCategoryName == catName))
continue;
OSDMap contMap = new OSDMap();
foreach (string contName in RegisteredStats[catName].Keys)
{
if (!(string.IsNullOrEmpty(pContainerName) || pContainerName == AllSubCommand || pContainerName == contName))
continue;
OSDMap statMap = new OSDMap();
SortedDictionary<string, Stat> theStats = RegisteredStats[catName][contName];
foreach (string statName in theStats.Keys)
{
if (!(String.IsNullOrEmpty(pStatName) || pStatName == AllSubCommand || pStatName == statName))
continue;
statMap.Add(statName, theStats[statName].ToOSDMap());
}
contMap.Add(contName, statMap);
}
map.Add(catName, contMap);
}
return map;
}
// /// <summary>
// /// Start collecting statistics related to assets.
// /// Should only be called once.