JD2022-TU1/main/tools/apps/TempoBlaster/Source/FrameVideo/FrameDebugInfo.cs

45 lines
1.7 KiB
C#

using System.Diagnostics;
using System.Drawing;
using System.Linq;
using JD.Collections.Extensions;
using TeaBox;
namespace TempoBlaster.FrameVideo
{
internal partial class FrameCache
{
class FrameDebugInfo
{
private readonly FrameCache _frameCache;
public readonly Stopwatch PaintTimer = new Stopwatch();
public readonly Font DebugFont = new Font(FontFamily.GenericMonospace, 12);
public long TotalLoadTime = 0;
public long TotalLoadFrameCount = 1;
public FrameDebugInfo(FrameCache frameCache)
{
this._frameCache = frameCache;
}
public void Paint(Graphics graphics)
{
double averageLoadTime = (double)TotalLoadTime / TotalLoadFrameCount;
var debugText = $"Average frame load time {averageLoadTime:0.0} ms";
debugText += $"\n Queue Size: {_frameCache.ToBeLoaded.Count:0.0}";
debugText += $"\n Paint duration: {PaintTimer.Elapsed.TotalMilliseconds:0.0} ms";
var loadingFrames = _frameCache._workers.Select(x => x.FrameCurrentlyLoading).NotNulls().ToArray();
debugText += $"\n Active thread count: {loadingFrames.Length}";
debugText += $"\n Current Frame: {_frameCache.CurrentFrame} Ranges: {_frameCache.FramesAliveRanges.Join(" ")}";
if (loadingFrames.Any())
{
debugText += $"\n Frames loading: {loadingFrames.Min(x => x.FrameNumber)} - {loadingFrames.Max(x => x.FrameNumber)}";
}
graphics.DrawString(debugText, DebugFont, Brushes.Red, 0, 0);
}
}
}
}