diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 61b998c275..9f28d4bc7f 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -45,6 +45,8 @@ namespace OpenRA public static Sound Sound; public static bool HasInputFocus = false; + public static bool BenchmarkMode = false; + public static GlobalChat GlobalChat; public static OrderManager JoinServer(string host, int port, string password, bool recordReplay = true) @@ -493,6 +495,9 @@ 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(); @@ -578,6 +583,9 @@ 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() diff --git a/OpenRA.Game/Support/LaunchArguments.cs b/OpenRA.Game/Support/LaunchArguments.cs index 659fde15d9..6663544bb4 100644 --- a/OpenRA.Game/Support/LaunchArguments.cs +++ b/OpenRA.Game/Support/LaunchArguments.cs @@ -21,6 +21,9 @@ 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; + public LaunchArguments(Arguments args) { if (args == null) diff --git a/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs b/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs index 1408a50686..ef0964e987 100644 --- a/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs +++ b/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs @@ -8,6 +8,7 @@ */ #endregion +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -39,6 +40,19 @@ namespace OpenRA.Mods.Common.LoadScreens Ui.ResetAll(); Game.Settings.Save(); + if (Launch.Benchmark) + { + Log.AddChannel("cpu", "cpu.csv"); + Log.Write("cpu", "tick;time [ms]"); + + Log.AddChannel("render", "render.csv"); + Log.Write("render", "frame;time [ms]"); + + Console.WriteLine("Saving benchmark data into {0}".F(Path.Combine(Platform.SupportDir, "Logs"))); + + Game.BenchmarkMode = true; + } + // Join a server directly var connect = Launch.GetConnectAddress(); if (!string.IsNullOrEmpty(connect))