From c7ee613ca07b4355c2f6441c8621b62cbc67a955 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Fri, 22 Apr 2011 11:12:50 +1245 Subject: [PATCH] add trait query report on disconnect --- OpenRA.Game/Game.cs | 2 ++ OpenRA.Game/TraitDictionary.cs | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 8c2a67d76a..bbdf8cb506 100755 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -326,6 +326,8 @@ namespace OpenRA public static void Disconnect() { + orderManager.world.traitDict.PrintReport(); + if (IsHost && server != null) server.Shutdown(); diff --git a/OpenRA.Game/TraitDictionary.cs b/OpenRA.Game/TraitDictionary.cs index e1f89d09c9..107bf53b84 100755 --- a/OpenRA.Game/TraitDictionary.cs +++ b/OpenRA.Game/TraitDictionary.cs @@ -23,6 +23,12 @@ namespace OpenRA { return traits.GetOrAdd( t, doCreateTraitContainer ); } + + public void PrintReport() + { + foreach( var t in traits.OrderByDescending(t => t.Value.Queries).TakeWhile(t => t.Value.Queries > 0) ) + Console.WriteLine ("{0}: {1}", t.Key.Name, t.Value.Queries ); + } // construct this delegate once. static Func doCreateTraitContainer = CreateTraitContainer; @@ -90,12 +96,17 @@ namespace OpenRA { void Add( Actor actor, object trait ); void RemoveActor( uint actor ); + + int Queries { get; } } class TraitContainer : ITraitContainer { List actors = new List(); List traits = new List(); + int queries; + + public int Queries { get { return queries; } } public void Add( Actor actor, object trait ) { @@ -106,6 +117,7 @@ namespace OpenRA public T Get( uint actor ) { + ++queries; var index = actors.BinarySearchMany( actor ); if( index >= actors.Count || actors[ index ].ActorID != actor ) throw new InvalidOperationException( string.Format( "TraitDictionary does not contain instance of type `{0}`", typeof( T ) ) ); @@ -117,6 +129,7 @@ namespace OpenRA public T GetOrDefault( uint actor ) { + ++queries; var index = actors.BinarySearchMany( actor ); if( index >= actors.Count || actors[ index ].ActorID != actor ) return default( T ); @@ -127,6 +140,7 @@ namespace OpenRA public IEnumerable GetMultiple( uint actor ) { + ++queries; var index = actors.BinarySearchMany( actor ); while( index < actors.Count && actors[ index ].ActorID == actor ) { @@ -137,6 +151,7 @@ namespace OpenRA public IEnumerable> All() { + ++queries; for( int i = 0 ; i < actors.Count ; i++ ) yield return new TraitPair { Actor = actors[ i ], Trait = traits[ i ] }; }