Repurpose unused Timer.cs and add some loading perf metrics

This commit is contained in:
Pavlos Touboulidis
2014-04-23 01:58:30 +03:00
parent 035834978d
commit 60732bd9bd
5 changed files with 71 additions and 35 deletions

View File

@@ -246,11 +246,18 @@ namespace OpenRA
{ {
BeforeGameStart(); 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 = new World(modData.Manifest, map, orderManager, isShellmap);
orderManager.world.Timestep = Timestep; orderManager.world.Timestep = Timestep;
worldRenderer = new WorldRenderer(orderManager.world); worldRenderer = new WorldRenderer(orderManager.world);
orderManager.world.LoadComplete(worldRenderer); using (new PerfTimer("LoadComplete"))
{
orderManager.world.LoadComplete(worldRenderer);
}
if (orderManager.GameStarted) if (orderManager.GameStarted)
return; return;
@@ -385,7 +392,10 @@ namespace OpenRA
modData = new ModData(mod); modData = new ModData(mod);
Renderer.InitializeFonts(modData.Manifest); Renderer.InitializeFonts(modData.Manifest);
modData.InitializeLoaders(); modData.InitializeLoaders();
modData.MapCache.LoadMaps(); using (new PerfTimer("LoadMaps"))
{
modData.MapCache.LoadMaps();
}
PerfHistory.items["render"].hasNormalTick = false; PerfHistory.items["render"].hasNormalTick = false;
PerfHistory.items["batches"].hasNormalTick = false; PerfHistory.items["batches"].hasNormalTick = false;
@@ -436,7 +446,12 @@ namespace OpenRA
public static void LoadShellMap() public static void LoadShellMap()
{ {
StartGame(ChooseShellmap(), true); string shellMap = ChooseShellmap();
using (new PerfTimer("StartGame"))
{
StartGame(shellMap, true);
}
} }
static string ChooseShellmap() static string ChooseShellmap()

View File

@@ -118,11 +118,17 @@ namespace OpenRA
// Mount map package so custom assets can be used. TODO: check priority. // Mount map package so custom assets can be used. TODO: check priority.
GlobalFileSystem.Mount(GlobalFileSystem.OpenPackage(map.Path, null, int.MaxValue)); 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); 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. using (new Support.PerfTimer("SequenceProvider.Initialize"))
SequenceProvider.Initialize(Manifest.Sequences, map.Sequences); {
// 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); VoxelProvider.Initialize(Manifest.VoxelSequences, map.VoxelSequences);
return map; return map;
} }

View File

@@ -293,7 +293,7 @@
<Compile Include="Primitives\Set.cs" /> <Compile Include="Primitives\Set.cs" />
<Compile Include="Support\Log.cs" /> <Compile Include="Support\Log.cs" />
<Compile Include="Support\Stopwatch.cs" /> <Compile Include="Support\Stopwatch.cs" />
<Compile Include="Support\Timer.cs" /> <Compile Include="Support\PerfTimer.cs" />
<Compile Include="Exts.cs" /> <Compile Include="Exts.cs" />
<Compile Include="Hotkey.cs" /> <Compile Include="Hotkey.cs" />
<Compile Include="Keycode.cs" /> <Compile Include="Keycode.cs" />

View File

@@ -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<int> depth = new System.Threading.ThreadLocal<int>();
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));
}
}
}

View File

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