diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs
index e7b89e8261..9c949622c7 100644
--- a/OpenRA.Game/Game.cs
+++ b/OpenRA.Game/Game.cs
@@ -246,11 +246,18 @@ namespace OpenRA
{
BeforeGameStart();
- var map = modData.PrepareMap(mapUID);
+ Map map;
+ using (new PerfTimer("PrepareMap"))
+ {
+ map = modData.PrepareMap(mapUID);
+ }
orderManager.world = new World(modData.Manifest, map, orderManager, isShellmap);
orderManager.world.Timestep = Timestep;
worldRenderer = new WorldRenderer(orderManager.world);
- orderManager.world.LoadComplete(worldRenderer);
+ using (new PerfTimer("LoadComplete"))
+ {
+ orderManager.world.LoadComplete(worldRenderer);
+ }
if (orderManager.GameStarted)
return;
@@ -385,7 +392,10 @@ namespace OpenRA
modData = new ModData(mod);
Renderer.InitializeFonts(modData.Manifest);
modData.InitializeLoaders();
- modData.MapCache.LoadMaps();
+ using (new PerfTimer("LoadMaps"))
+ {
+ modData.MapCache.LoadMaps();
+ }
PerfHistory.items["render"].hasNormalTick = false;
PerfHistory.items["batches"].hasNormalTick = false;
@@ -436,7 +446,12 @@ namespace OpenRA
public static void LoadShellMap()
{
- StartGame(ChooseShellmap(), true);
+ string shellMap = ChooseShellmap();
+
+ using (new PerfTimer("StartGame"))
+ {
+ StartGame(shellMap, true);
+ }
}
static string ChooseShellmap()
diff --git a/OpenRA.Game/ModData.cs b/OpenRA.Game/ModData.cs
index b65d8ed0d3..0ca48529f3 100755
--- a/OpenRA.Game/ModData.cs
+++ b/OpenRA.Game/ModData.cs
@@ -118,11 +118,17 @@ namespace OpenRA
// Mount map package so custom assets can be used. TODO: check priority.
GlobalFileSystem.Mount(GlobalFileSystem.OpenPackage(map.Path, null, int.MaxValue));
- Rules.LoadRules(Manifest, map);
+ using (new Support.PerfTimer("LoadRules"))
+ {
+ Rules.LoadRules(Manifest, map);
+ }
SpriteLoader = new SpriteLoader(Rules.TileSets[map.Tileset].Extensions, SheetBuilder);
- // TODO: Don't load the sequences for assets that are not used in this tileset. Maybe use the existing EditorTilesetFilters.
- SequenceProvider.Initialize(Manifest.Sequences, map.Sequences);
+ using (new Support.PerfTimer("SequenceProvider.Initialize"))
+ {
+ // TODO: Don't load the sequences for assets that are not used in this tileset. Maybe use the existing EditorTilesetFilters.
+ SequenceProvider.Initialize(Manifest.Sequences, map.Sequences);
+ }
VoxelProvider.Initialize(Manifest.VoxelSequences, map.VoxelSequences);
return map;
}
diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj
index 4d5b9a6e57..3447fecd9c 100644
--- a/OpenRA.Game/OpenRA.Game.csproj
+++ b/OpenRA.Game/OpenRA.Game.csproj
@@ -293,7 +293,7 @@
-
+
diff --git a/OpenRA.Game/Support/PerfTimer.cs b/OpenRA.Game/Support/PerfTimer.cs
new file mode 100755
index 0000000000..c674d55fe5
--- /dev/null
+++ b/OpenRA.Game/Support/PerfTimer.cs
@@ -0,0 +1,42 @@
+#region Copyright & License Information
+/*
+ * Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
+ * This file is part of OpenRA, which is free software. It is made
+ * available to you under the terms of the GNU General Public License
+ * as published by the Free Software Foundation. For more information,
+ * see COPYING.
+ */
+#endregion
+
+using System;
+
+namespace OpenRA.Support
+{
+ public class PerfTimer : IDisposable
+ {
+ readonly Stopwatch sw = new Stopwatch();
+ readonly string Name;
+ static System.Threading.ThreadLocal depth = new System.Threading.ThreadLocal();
+
+ public PerfTimer(string name)
+ {
+ this.Name = name;
+ depth.Value++;
+ }
+
+ public void Dispose()
+ {
+ string indentation;
+
+ if (--depth.Value >= 0)
+ indentation = new string('\t', depth.Value);
+ else
+ {
+ depth.Value = 0;
+ indentation = string.Empty;
+ }
+
+ Log.Write("perf", "{0}{1}: {2} ms", indentation, this.Name, Math.Round(this.sw.Elapsed.TotalMilliseconds));
+ }
+ }
+}
diff --git a/OpenRA.Game/Support/Timer.cs b/OpenRA.Game/Support/Timer.cs
deleted file mode 100755
index 9b3b42ee93..0000000000
--- a/OpenRA.Game/Support/Timer.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-#region Copyright & License Information
-/*
- * Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
- * This file is part of OpenRA, which is free software. It is made
- * available to you under the terms of the GNU General Public License
- * as published by the Free Software Foundation. For more information,
- * see COPYING.
- */
-#endregion
-
-namespace OpenRA.Support
-{
- public static class Timer
- {
- static Stopwatch sw = new Stopwatch();
- static System.TimeSpan lastTime;
-
- public static void Time( string message )
- {
- var time = sw.Elapsed;
- var dt = time - lastTime;
- if( dt.TotalSeconds > 0.0001 )
- Log.Write("perf", message, dt.TotalSeconds );
- lastTime = time;
- }
- }
-}