improve ups counter output
This commit is contained in:
parent
b9508173b8
commit
a908979940
|
@ -33,12 +33,14 @@ internal sealed class GameTickWorker(
|
||||||
|
|
||||||
private async Task RunAsync()
|
private async Task RunAsync()
|
||||||
{
|
{
|
||||||
|
// the first tick is really short (< 0.01ms) if this line is directly above the while
|
||||||
|
var sw = Stopwatch.StartNew();
|
||||||
|
|
||||||
// do not block in StartAsync
|
// do not block in StartAsync
|
||||||
await Task.Delay(1).ConfigureAwait(false);
|
await Task.Delay(1).ConfigureAwait(false);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var sw = new Stopwatch();
|
|
||||||
while (!_cancellation.IsCancellationRequested)
|
while (!_cancellation.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
var delta = sw.Elapsed;
|
var delta = sw.Elapsed;
|
||||||
|
|
|
@ -4,6 +4,9 @@ namespace TanksServer.GameLogic;
|
||||||
|
|
||||||
internal sealed class UpdatesPerSecondCounter(ILogger<UpdatesPerSecondCounter> logger) : ITickStep
|
internal sealed class UpdatesPerSecondCounter(ILogger<UpdatesPerSecondCounter> logger) : ITickStep
|
||||||
{
|
{
|
||||||
|
private static readonly TimeSpan LongTime = TimeSpan.FromSeconds(5);
|
||||||
|
private static readonly TimeSpan CriticalUpdateTime = TimeSpan.FromMilliseconds(50);
|
||||||
|
|
||||||
private readonly Stopwatch _long = Stopwatch.StartNew();
|
private readonly Stopwatch _long = Stopwatch.StartNew();
|
||||||
private ulong _updatesSinceLongReset;
|
private ulong _updatesSinceLongReset;
|
||||||
private TimeSpan _minFrameTime = TimeSpan.MaxValue;
|
private TimeSpan _minFrameTime = TimeSpan.MaxValue;
|
||||||
|
@ -13,8 +16,12 @@ internal sealed class UpdatesPerSecondCounter(ILogger<UpdatesPerSecondCounter> l
|
||||||
{
|
{
|
||||||
if (logger.IsEnabled(LogLevel.Trace))
|
if (logger.IsEnabled(LogLevel.Trace))
|
||||||
logger.LogTrace("time since last update: {}", delta);
|
logger.LogTrace("time since last update: {}", delta);
|
||||||
if (delta.TotalSeconds > 1)
|
|
||||||
logger.LogCritical("single update took {}", delta);
|
if (delta > CriticalUpdateTime)
|
||||||
|
{
|
||||||
|
logger.LogCritical("a single update took {}, which is longer than the allowed {}",
|
||||||
|
delta, CriticalUpdateTime);
|
||||||
|
}
|
||||||
|
|
||||||
if (_minFrameTime > delta)
|
if (_minFrameTime > delta)
|
||||||
_minFrameTime = delta;
|
_minFrameTime = delta;
|
||||||
|
@ -23,7 +30,7 @@ internal sealed class UpdatesPerSecondCounter(ILogger<UpdatesPerSecondCounter> l
|
||||||
|
|
||||||
_updatesSinceLongReset++;
|
_updatesSinceLongReset++;
|
||||||
|
|
||||||
if (_long.Elapsed.TotalSeconds < 10)
|
if (_long.Elapsed < LongTime)
|
||||||
return ValueTask.CompletedTask;
|
return ValueTask.CompletedTask;
|
||||||
|
|
||||||
LogCounters();
|
LogCounters();
|
||||||
|
@ -37,11 +44,12 @@ internal sealed class UpdatesPerSecondCounter(ILogger<UpdatesPerSecondCounter> l
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var time = _long.Elapsed;
|
var time = _long.Elapsed;
|
||||||
var average = Math.Round(_updatesSinceLongReset / time.TotalSeconds);
|
var averageTime = Math.Round(time.TotalMilliseconds / _updatesSinceLongReset, 2);
|
||||||
var min = Math.Round(1 / _maxFrameTime.TotalSeconds);
|
var averageUps = Math.Round(_updatesSinceLongReset / time.TotalSeconds, 2);
|
||||||
var max = Math.Round(1 / _minFrameTime.TotalSeconds);
|
var min = Math.Round(_minFrameTime.TotalMilliseconds, 2);
|
||||||
logger.LogDebug("UPS stats for {} updates in {}: avg={}, min={}, max={}",
|
var max = Math.Round(_maxFrameTime.TotalMilliseconds, 2);
|
||||||
_updatesSinceLongReset, time, average, min, max);
|
logger.LogDebug("count={}, time={}, avg={}ms, ups={}, min={}ms, max={}ms",
|
||||||
|
_updatesSinceLongReset, time, averageTime, averageUps, min, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ResetCounters()
|
private void ResetCounters()
|
||||||
|
|
Loading…
Reference in a new issue