Use SortedDictionary in StatsManager instead of regular Dictionary so stats will interate and print in a defined order

user_profiles
Dan Lake 2013-02-14 20:05:42 -08:00
parent d3b2cdc2b4
commit afeb5d4917
2 changed files with 22 additions and 22 deletions

View File

@ -359,11 +359,11 @@ Asset service request failures: {3}" + Environment.NewLine,
inPacketsPerSecond, outPacketsPerSecond, pendingDownloads, pendingUploads, unackedBytes, totalFrameTime, inPacketsPerSecond, outPacketsPerSecond, pendingDownloads, pendingUploads, unackedBytes, totalFrameTime,
netFrameTime, physicsFrameTime, otherFrameTime, agentFrameTime, imageFrameTime)); netFrameTime, physicsFrameTime, otherFrameTime, agentFrameTime, imageFrameTime));
Dictionary<string, Dictionary<string, Stat>> sceneStats; SortedDictionary<string, SortedDictionary<string, Stat>> sceneStats;
if (StatsManager.TryGetStats("scene", out sceneStats)) if (StatsManager.TryGetStats("scene", out sceneStats))
{ {
foreach (KeyValuePair<string, Dictionary<string, Stat>> kvp in sceneStats) foreach (KeyValuePair<string, SortedDictionary<string, Stat>> kvp in sceneStats)
{ {
foreach (Stat stat in kvp.Value.Values) foreach (Stat stat in kvp.Value.Values)
{ {

View File

@ -51,8 +51,8 @@ namespace OpenSim.Framework.Monitoring
/// <remarks> /// <remarks>
/// Do not add or remove directly from this dictionary. /// Do not add or remove directly from this dictionary.
/// </remarks> /// </remarks>
public static Dictionary<string, Dictionary<string, Dictionary<string, Stat>>> RegisteredStats public static SortedDictionary<string, SortedDictionary<string, SortedDictionary<string, Stat>>> RegisteredStats
= new Dictionary<string, Dictionary<string, Dictionary<string, Stat>>>(); = new SortedDictionary<string, SortedDictionary<string, SortedDictionary<string, Stat>>>();
private static AssetStatsCollector assetStats; private static AssetStatsCollector assetStats;
private static UserStatsCollector userStats; private static UserStatsCollector userStats;
@ -101,7 +101,7 @@ namespace OpenSim.Framework.Monitoring
} }
else else
{ {
Dictionary<string, Dictionary<string, Stat>> category; SortedDictionary<string, SortedDictionary<string, Stat>> category;
if (!RegisteredStats.TryGetValue(categoryName, out category)) if (!RegisteredStats.TryGetValue(categoryName, out category))
{ {
con.OutputFormat("No such category as {0}", categoryName); con.OutputFormat("No such category as {0}", categoryName);
@ -120,7 +120,7 @@ namespace OpenSim.Framework.Monitoring
} }
private static void OutputCategoryStatsToConsole( private static void OutputCategoryStatsToConsole(
ICommandConsole con, Dictionary<string, Dictionary<string, Stat>> category) ICommandConsole con, SortedDictionary<string, SortedDictionary<string, Stat>> category)
{ {
foreach (var container in category.Values) foreach (var container in category.Values)
{ {
@ -160,8 +160,8 @@ namespace OpenSim.Framework.Monitoring
/// <returns></returns> /// <returns></returns>
public static bool RegisterStat(Stat stat) public static bool RegisterStat(Stat stat)
{ {
Dictionary<string, Dictionary<string, Stat>> category = null, newCategory; SortedDictionary<string, SortedDictionary<string, Stat>> category = null, newCategory;
Dictionary<string, Stat> container = null, newContainer; SortedDictionary<string, Stat> container = null, newContainer;
lock (RegisteredStats) lock (RegisteredStats)
{ {
@ -175,14 +175,14 @@ namespace OpenSim.Framework.Monitoring
// This means that we don't need to lock or copy them on iteration, which will be a much more // This means that we don't need to lock or copy them on iteration, which will be a much more
// common operation after startup. // common operation after startup.
if (container != null) if (container != null)
newContainer = new Dictionary<string, Stat>(container); newContainer = new SortedDictionary<string, Stat>(container);
else else
newContainer = new Dictionary<string, Stat>(); newContainer = new SortedDictionary<string, Stat>();
if (category != null) if (category != null)
newCategory = new Dictionary<string, Dictionary<string, Stat>>(category); newCategory = new SortedDictionary<string, SortedDictionary<string, Stat>>(category);
else else
newCategory = new Dictionary<string, Dictionary<string, Stat>>(); newCategory = new SortedDictionary<string, SortedDictionary<string, Stat>>();
newContainer[stat.ShortName] = stat; newContainer[stat.ShortName] = stat;
newCategory[stat.Container] = newContainer; newCategory[stat.Container] = newContainer;
@ -196,21 +196,21 @@ namespace OpenSim.Framework.Monitoring
/// Deregister a statistic /// Deregister a statistic
/// </summary>> /// </summary>>
/// <param name='stat'></param> /// <param name='stat'></param>
/// <returns></returns /// <returns></returns>
public static bool DeregisterStat(Stat stat) public static bool DeregisterStat(Stat stat)
{ {
Dictionary<string, Dictionary<string, Stat>> category = null, newCategory; SortedDictionary<string, SortedDictionary<string, Stat>> category = null, newCategory;
Dictionary<string, Stat> container = null, newContainer; SortedDictionary<string, Stat> container = null, newContainer;
lock (RegisteredStats) lock (RegisteredStats)
{ {
if (!TryGetStat(stat, out category, out container)) if (!TryGetStat(stat, out category, out container))
return false; return false;
newContainer = new Dictionary<string, Stat>(container); newContainer = new SortedDictionary<string, Stat>(container);
newContainer.Remove(stat.ShortName); newContainer.Remove(stat.ShortName);
newCategory = new Dictionary<string, Dictionary<string, Stat>>(category); newCategory = new SortedDictionary<string, SortedDictionary<string, Stat>>(category);
newCategory.Remove(stat.Container); newCategory.Remove(stat.Container);
newCategory[stat.Container] = newContainer; newCategory[stat.Container] = newContainer;
@ -220,15 +220,15 @@ namespace OpenSim.Framework.Monitoring
} }
} }
public static bool TryGetStats(string category, out Dictionary<string, Dictionary<string, Stat>> stats) public static bool TryGetStats(string category, out SortedDictionary<string, SortedDictionary<string, Stat>> stats)
{ {
return RegisteredStats.TryGetValue(category, out stats); return RegisteredStats.TryGetValue(category, out stats);
} }
public static bool TryGetStat( public static bool TryGetStat(
Stat stat, Stat stat,
out Dictionary<string, Dictionary<string, Stat>> category, out SortedDictionary<string, SortedDictionary<string, Stat>> category,
out Dictionary<string, Stat> container) out SortedDictionary<string, Stat> container)
{ {
category = null; category = null;
container = null; container = null;
@ -252,9 +252,9 @@ namespace OpenSim.Framework.Monitoring
{ {
lock (RegisteredStats) lock (RegisteredStats)
{ {
foreach (Dictionary<string, Dictionary<string, Stat>> category in RegisteredStats.Values) foreach (SortedDictionary<string, SortedDictionary<string, Stat>> category in RegisteredStats.Values)
{ {
foreach (Dictionary<string, Stat> container in category.Values) foreach (SortedDictionary<string, Stat> container in category.Values)
{ {
foreach (Stat stat in container.Values) foreach (Stat stat in container.Values)
{ {