1 using Microsoft.Xna.Framework;
2 using System.Collections.Generic;
3 using System.Diagnostics;
10 private readonly
object mutex =
new object();
19 private readonly Queue<double> sampleBuffer =
new Queue<double>();
21 private readonly Queue<double> averageFramesPerSecondBuffer =
new Queue<double>();
23 private readonly Stopwatch timer =
new Stopwatch();
24 private long lastSecondMark = 0;
25 private long lastMinuteMark = 0;
33 private readonly Dictionary<string, Queue<long>> elapsedTicks =
new Dictionary<string, Queue<long>>();
34 private readonly Dictionary<string, long> avgTicksPerFrame =
new Dictionary<string, long>();
37 internal Graph UpdateTimeGraph =
new Graph(500), DrawTimeGraph =
new Graph(500);
40 private readonly List<string> tempSavedIdentifiers =
new List<string>();
48 tempSavedIdentifiers.Clear();
49 tempSavedIdentifiers.AddRange(avgTicksPerFrame.Keys);
51 return tempSavedIdentifiers;
64 if (!elapsedTicks.ContainsKey(identifier)) { elapsedTicks.Add(identifier,
new Queue<long>()); }
65 elapsedTicks[identifier].Enqueue(ticks);
69 elapsedTicks[identifier].Dequeue();
70 avgTicksPerFrame[identifier] = (long)elapsedTicks[identifier].Average(i => i);
77 long ticksPerFrame = 0;
80 avgTicksPerFrame.TryGetValue(identifier, out ticksPerFrame);
82 return ticksPerFrame * 1000.0f / Stopwatch.Frequency;
87 if (deltaTime == 0.0f) {
return false; }
94 sampleBuffer.Dequeue();
102 long currentTime = timer.ElapsedMilliseconds;
103 long currentSecond = currentTime / 1000;
106 if (currentSecond > lastSecondMark)
109 lastSecondMark = currentSecond;
112 if (currentTime - lastMinuteMark >= 60 * 1000)
115 const int MaxFPS = 144;
117 GameAnalyticsManager.AddDesignEvent($
"FPS:{MathHelper.Clamp((int)AverageFramesPerSecondInPastMinute, 0, MaxFPS)}");
118 GameAnalyticsManager.AddDesignEvent($
"FPSLowest:{MathHelper.Clamp((int)averageFramesPerSecondBuffer.Min(), 0, MaxFPS)}");
119 averageFramesPerSecondBuffer.Clear();
120 lastMinuteMark = currentTime;