Make perf.log output for ticking things opt-in
Both writing to perf.log frequently as well as GetTimestamp aren't free and hurt performance particularly on slower systems (which can have notably higher output to perf.log, further amplifying the problem). Therefore we make simulation perf logging opt-in. Additionally, logging of the current tick and tick type (local/net) is removed from debug.log, and some remnant debug logging for kills and pips is removed to keep performance-sensitive logging limited to perf.log.
This commit is contained in:
@@ -9,8 +9,6 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Diagnostics;
|
||||
using OpenRA.Activities;
|
||||
using OpenRA.Support;
|
||||
using Activity = OpenRA.Activities.Activity;
|
||||
|
||||
@@ -20,29 +18,18 @@ namespace OpenRA.Traits
|
||||
{
|
||||
public static Activity RunActivity(Actor self, Activity act)
|
||||
{
|
||||
// PERF: If there are no activities we can bail straight away and save ourselves a call to
|
||||
// Stopwatch.GetTimestamp.
|
||||
// PERF: This is a hot path and must run with minimal added overhead.
|
||||
// If there are no activities we can bail straight away and save ourselves the overhead of setting up the perf logging.
|
||||
if (act == null)
|
||||
return act;
|
||||
|
||||
// PERF: This is a hot path and must run with minimal added overhead.
|
||||
// Calling Stopwatch.GetTimestamp is a bit expensive, so we enumerate manually to allow us to call it only
|
||||
// once per iteration in the normal case.
|
||||
// See also: DoTimed
|
||||
var longTickThresholdInStopwatchTicks = PerfTimer.LongTickThresholdInStopwatchTicks;
|
||||
var start = Stopwatch.GetTimestamp();
|
||||
var perfLogger = new PerfTickLogger();
|
||||
perfLogger.Start();
|
||||
while (act != null)
|
||||
{
|
||||
var prev = act;
|
||||
act = act.TickOuter(self);
|
||||
var current = Stopwatch.GetTimestamp();
|
||||
if (current - start > longTickThresholdInStopwatchTicks)
|
||||
{
|
||||
PerfTimer.LogLongTick(start, current, "Activity", prev);
|
||||
start = Stopwatch.GetTimestamp();
|
||||
}
|
||||
else
|
||||
start = current;
|
||||
perfLogger.LogTickAndRestartTimer("Activity", prev);
|
||||
|
||||
if (act == prev)
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user