fix: Adds back Average CPS to Admin Gump (#1573)
This commit is contained in:
parent
c32aa39931
commit
469b89370d
2 changed files with 23 additions and 10 deletions
|
|
@ -144,6 +144,7 @@ public static class Core
|
||||||
}
|
}
|
||||||
|
|
||||||
var timestamp = Stopwatch.GetTimestamp();
|
var timestamp = Stopwatch.GetTimestamp();
|
||||||
|
|
||||||
return timestamp > _maxTickCountBeforePrecisionLoss
|
return timestamp > _maxTickCountBeforePrecisionLoss
|
||||||
? timestamp / _ticksPerMillisecond
|
? timestamp / _ticksPerMillisecond
|
||||||
// No precision loss
|
// No precision loss
|
||||||
|
|
@ -167,10 +168,12 @@ public static class Core
|
||||||
|
|
||||||
public static long Uptime => Thread.CurrentThread != Thread ? 0 : TickCount - _firstTick;
|
public static long Uptime => Thread.CurrentThread != Thread ? 0 : TickCount - _firstTick;
|
||||||
|
|
||||||
private static long _cycleIndex = 1;
|
private static long _cycleIndex;
|
||||||
private static float[] _cyclesPerSecond = new float[128];
|
private static readonly double[] _cyclesPerSecond = new double[128];
|
||||||
|
|
||||||
public static float CyclesPerSecond => _cyclesPerSecond[(_cycleIndex - 1) % _cyclesPerSecond.Length];
|
public static double CyclesPerSecond => _cyclesPerSecond[_cycleIndex];
|
||||||
|
|
||||||
|
public static double AverageCPS => _cyclesPerSecond.Average();
|
||||||
|
|
||||||
public static bool MultiProcessor { get; private set; }
|
public static bool MultiProcessor { get; private set; }
|
||||||
|
|
||||||
|
|
@ -534,9 +537,10 @@ public static class Core
|
||||||
var idleCPU = ServerConfiguration.GetOrUpdateSetting("core.enableIdleCPU", false);
|
var idleCPU = ServerConfiguration.GetOrUpdateSetting("core.enableIdleCPU", false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
long last = TickCount;
|
var cycleCount = _cyclesPerSecond.Length;
|
||||||
|
long last = Stopwatch.GetTimestamp();
|
||||||
const int interval = 100;
|
const int interval = 100;
|
||||||
const float ticksPerSecond = 1000 * interval;
|
double frequency = Stopwatch.Frequency * interval;
|
||||||
|
|
||||||
int sample = 0;
|
int sample = 0;
|
||||||
|
|
||||||
|
|
@ -568,15 +572,20 @@ public static class Core
|
||||||
_tickCount = 0;
|
_tickCount = 0;
|
||||||
_now = DateTime.MinValue;
|
_now = DateTime.MinValue;
|
||||||
|
|
||||||
if (idleCPU && ++sample % interval == 0)
|
if (++sample % interval == 0)
|
||||||
{
|
{
|
||||||
var now = TickCount;
|
var now = Stopwatch.GetTimestamp();
|
||||||
|
|
||||||
|
var cyclesPerSecond = frequency / (now - last);
|
||||||
|
_cyclesPerSecond[_cycleIndex++] = cyclesPerSecond;
|
||||||
|
if (_cycleIndex == cycleCount)
|
||||||
|
{
|
||||||
|
_cycleIndex = 0;
|
||||||
|
}
|
||||||
|
|
||||||
var cyclesPerSecond = ticksPerSecond / (now - last);
|
|
||||||
_cyclesPerSecond[_cycleIndex++ % _cyclesPerSecond.Length] = cyclesPerSecond;
|
|
||||||
last = now;
|
last = now;
|
||||||
|
|
||||||
if (cyclesPerSecond > 80)
|
if (idleCPU && cyclesPerSecond > 125)
|
||||||
{
|
{
|
||||||
Thread.Sleep(2);
|
Thread.Sleep(2);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -226,6 +226,10 @@ namespace Server.Gumps
|
||||||
}
|
}
|
||||||
case AdminGumpPage.Information_Perf:
|
case AdminGumpPage.Information_Perf:
|
||||||
{
|
{
|
||||||
|
AddLabel(20, 130, LabelHue, "Cycles Per Second:");
|
||||||
|
AddLabel(40, 150, LabelHue, $"Current: {Core.CyclesPerSecond:N2}");
|
||||||
|
AddLabel(40, 170, LabelHue, $"Average: {Core.AverageCPS:N2}");
|
||||||
|
|
||||||
using var sb = ValueStringBuilder.Create();
|
using var sb = ValueStringBuilder.Create();
|
||||||
|
|
||||||
ThreadPool.GetAvailableThreads(out var curUser, out var curIOCP);
|
ThreadPool.GetAvailableThreads(out var curUser, out var curIOCP);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue