Repurpose unused Timer.cs and add some loading perf metrics
This commit is contained in:
@@ -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);
|
||||
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();
|
||||
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()
|
||||
|
||||
@@ -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));
|
||||
|
||||
using (new Support.PerfTimer("LoadRules"))
|
||||
{
|
||||
Rules.LoadRules(Manifest, map);
|
||||
}
|
||||
SpriteLoader = new SpriteLoader(Rules.TileSets[map.Tileset].Extensions, SheetBuilder);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@
|
||||
<Compile Include="Primitives\Set.cs" />
|
||||
<Compile Include="Support\Log.cs" />
|
||||
<Compile Include="Support\Stopwatch.cs" />
|
||||
<Compile Include="Support\Timer.cs" />
|
||||
<Compile Include="Support\PerfTimer.cs" />
|
||||
<Compile Include="Exts.cs" />
|
||||
<Compile Include="Hotkey.cs" />
|
||||
<Compile Include="Keycode.cs" />
|
||||
|
||||
42
OpenRA.Game/Support/PerfTimer.cs
Executable file
42
OpenRA.Game/Support/PerfTimer.cs
Executable 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user