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:
@@ -78,17 +78,26 @@ namespace OpenRA.Traits
|
||||
|
||||
public static Activity RunActivity(Actor self, Activity act)
|
||||
{
|
||||
// Note - manual iteration here for performance due to high call volume.
|
||||
var longTickThresholdInStopwatchTicks = PerfTimer.LongTickThresholdInStopwatchTicks;
|
||||
var start = Stopwatch.GetTimestamp();
|
||||
while (act != null)
|
||||
{
|
||||
var prev = act;
|
||||
|
||||
using (new PerfTimer("[{0}] Activity: {1}".F(Game.LocalTick, prev), (int)Game.Settings.Debug.LongTickThreshold.TotalMilliseconds))
|
||||
act = act.Tick(self);
|
||||
|
||||
act = act.Tick(self);
|
||||
var current = Stopwatch.GetTimestamp();
|
||||
if (current - start > longTickThresholdInStopwatchTicks)
|
||||
{
|
||||
PerfTimer.LogLongTick(start, current, "Activity", prev);
|
||||
start = Stopwatch.GetTimestamp();
|
||||
}
|
||||
else
|
||||
{
|
||||
start = current;
|
||||
}
|
||||
if (prev == act)
|
||||
break;
|
||||
}
|
||||
|
||||
return act;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user