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:
reaperrr
2021-03-21 23:14:09 +01:00
committed by teinarss
parent a1df91b665
commit aa834db1e3
12 changed files with 85 additions and 56 deletions

View File

@@ -11,7 +11,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using OpenRA.Support;
using OpenRA.Traits;
@@ -65,25 +64,16 @@ namespace OpenRA
public static void DoTimed<T>(this IEnumerable<T> e, Action<T> a, string text)
{
// 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: RunActivity
var longTickThresholdInStopwatchTicks = PerfTimer.LongTickThresholdInStopwatchTicks;
// PERF: This is a hot path and must run with minimal added overhead, so we enumerate manually
// to allow us to call PerfTickLogger only once per iteration in the normal case.
var perfLogger = new PerfTickLogger();
using (var enumerator = e.GetEnumerator())
{
var start = Stopwatch.GetTimestamp();
perfLogger.Start();
while (enumerator.MoveNext())
{
a(enumerator.Current);
var current = Stopwatch.GetTimestamp();
if (current - start > longTickThresholdInStopwatchTicks)
{
PerfTimer.LogLongTick(start, current, text, enumerator.Current);
start = Stopwatch.GetTimestamp();
}
else
start = current;
perfLogger.LogTickAndRestartTimer(text, enumerator.Current);
}
}
}