Changed logging in DoTimed/RunActivity to create less overhead.

- Refactored PerfTimer to use less memory.
- Avoid using the PerfTimer in highly called methods DoTimed and RunActivity, instead tracking long ticks manually to reduce overhead and avoid memory allocations.
- Added some helper methods in PerfTimer to output information when a tick takes too long.
- Changed PerfTimer logging to output the time at the start of the line, and no longer truncate output per line.
- Settings.LongTickThreshold changed from TimeSpan to float and renamed to LongTickThresholdMs.
This commit is contained in:
RoosterDragon
2014-05-23 06:01:46 +01:00
parent 446884fec2
commit d1b3d77662
5 changed files with 73 additions and 60 deletions

View File

@@ -172,13 +172,28 @@ namespace OpenRA
}
}
public static void DoTimed<T>(this IEnumerable<T> e, Action<T> a, string text, TimeSpan time)
public static void DoTimed<T>(this IEnumerable<T> e, Action<T> a, string text)
{
e.Do(x =>
// Note - manual enumeration here for performance due to high call volume.
var longTickThresholdInStopwatchTicks = PerfTimer.LongTickThresholdInStopwatchTicks;
using (var enumerator = e.GetEnumerator())
{
using (new PerfTimer("[{0}] {1}: {2}".F(Game.LocalTick, text, x), (int)time.TotalMilliseconds))
a(x);
});
var start = Stopwatch.GetTimestamp();
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;
}
}
}
}
public static bool AreMutualAllies( Player a, Player b )