Writing benchmark data at the end of the game

This commit is contained in:
teinarss
2019-04-30 22:41:45 +02:00
committed by abcdefg30
parent 982291119c
commit 4fae77ed1c
5 changed files with 116 additions and 18 deletions

View File

@@ -51,13 +51,12 @@ namespace OpenRA
public static Sound Sound;
public static bool HasInputFocus = false;
public static bool BenchmarkMode = false;
public static string EngineVersion { get; private set; }
public static LocalPlayerProfile LocalPlayerProfile;
static Task discoverNat;
static bool takeScreenshot = false;
static Benchmark benchmark = null;
public static event Action OnShellmapLoaded = () => { };
@@ -167,6 +166,8 @@ namespace OpenRA
using (new PerfTimer("NewWorld"))
OrderManager.World = new World(ModData, map, OrderManager, type);
OrderManager.World.GameOver += FinishBenchmark;
worldRenderer = new WorldRenderer(ModData, OrderManager.World);
GC.Collect();
@@ -593,9 +594,6 @@ namespace OpenRA
Log.Write("debug", "--Tick: {0} ({1})", LocalTick, isNetTick ? "net" : "local");
if (BenchmarkMode)
Log.Write("cpu", "{0};{1}".F(LocalTick, PerfHistory.Items["tick_time"].LastValue));
if (isNetTick)
orderManager.Tick();
@@ -615,6 +613,9 @@ namespace OpenRA
if (orderManager.LocalFrameNumber > 0)
Sync.RunUnsynced(Settings.Debug.SyncCheckUnsyncedCode, world, () => world.TickRender(worldRenderer));
}
if (benchmark != null)
benchmark.Tick(LocalTick);
}
}
@@ -691,9 +692,6 @@ namespace OpenRA
PerfHistory.Items["batches"].Tick();
PerfHistory.Items["render_widgets"].Tick();
PerfHistory.Items["render_flip"].Tick();
if (BenchmarkMode)
Log.Write("render", "{0};{1}".F(RenderFrame, PerfHistory.Items["render"].LastValue));
}
static void Loop()
@@ -904,5 +902,37 @@ namespace OpenRA
{
return Renderer.Window.SetClipboardText(text);
}
public static void BenchmarkMode(string prefix)
{
benchmark = new Benchmark(prefix);
}
public static void LoadMap(string launchMap)
{
var orders = new List<Order>
{
Order.Command("option gamespeed {0}".F("default")),
Order.Command("state {0}".F(Session.ClientState.Ready))
};
var path = Platform.ResolvePath(launchMap);
var map = ModData.MapCache.SingleOrDefault(m => m.Uid == launchMap) ??
ModData.MapCache.SingleOrDefault(m => m.Package.Name == path);
if (map == null)
throw new InvalidOperationException("Could not find map '{0}'.".F(launchMap));
CreateAndStartLocalServer(map.Uid, orders);
}
public static void FinishBenchmark()
{
if (benchmark != null)
{
benchmark.Write();
Exit();
}
}
}
}

View File

@@ -0,0 +1,62 @@
#region Copyright & License Information
/*
* Copyright 2007-2019 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, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System.Collections.Generic;
namespace OpenRA.Support
{
class Benchmark
{
readonly string prefix;
readonly Dictionary<string, List<BenchmarkPoint>> samples = new Dictionary<string, List<BenchmarkPoint>>();
public Benchmark(string prefix)
{
this.prefix = prefix;
}
public void Tick(int localTick)
{
foreach (var item in PerfHistory.Items)
samples.GetOrAdd(item.Key).Add(new BenchmarkPoint(localTick, item.Value.LastValue));
}
class BenchmarkPoint
{
public int Tick { get; private set; }
public double Value { get; private set; }
public BenchmarkPoint(int tick, double value)
{
Tick = tick;
Value = value;
}
}
public void Write()
{
foreach (var sample in samples)
{
var name = sample.Key;
Log.AddChannel(name, "{0}{1}.csv".F(prefix, name));
Log.Write(name, "tick,time [ms]");
foreach (var point in sample.Value)
Log.Write(name, "{0},{1}".F(point.Tick, point.Value));
}
}
public void Reset()
{
samples.Clear();
}
}
}

View File

@@ -22,8 +22,11 @@ namespace OpenRA
[Desc("Automatically start playing the given replay file.")]
public string Replay;
[Desc("Dump performance data into cpu.csv and render.csv in the logs folder.")]
public bool Benchmark;
[Desc("Dump performance data into cpu.csv and render.csv in the logs folder with the given prefix.")]
public string Benchmark;
[Desc("Automatically start playing the given map.")]
public string Map;
public LaunchArguments(Arguments args)
{

View File

@@ -565,6 +565,8 @@ namespace OpenRA
// Actor disposals are done in a FrameEndTask
while (frameEndActions.Count != 0)
frameEndActions.Dequeue()(this);
Game.FinishBenchmark();
}
}