Timer: better histogram formatting. bin into 10% intervals instead of 5%

GitOrigin-RevId: 9729f04bd650e530d6e60efbed348d6269608f16
This commit is contained in:
Colin McMillen 2020-02-03 18:39:24 -05:00
parent 9e4d863bcf
commit 80f1104d82

View File

@ -8,7 +8,7 @@ namespace SemiColinGames {
private readonly double targetTime; private readonly double targetTime;
private readonly string name; private readonly string name;
private double startTime = 0.0; private double startTime = 0.0;
private int[] histogram = new int[41]; private int[] histogram = new int[21];
private int totalFrames = 0; private int totalFrames = 0;
public Timer(double targetTime, string name) { public Timer(double targetTime, string name) {
@ -25,7 +25,7 @@ namespace SemiColinGames {
stopwatch.Stop(); stopwatch.Stop();
totalFrames++; totalFrames++;
double frameTime = stopwatch.Elapsed.TotalSeconds - startTime; double frameTime = stopwatch.Elapsed.TotalSeconds - startTime;
int bucket = FMath.Clamp((int) (5.0f * frameTime / targetTime), 0, 40); int bucket = FMath.Clamp((int) (10.0f * frameTime / targetTime), 0, 20);
histogram[bucket]++; histogram[bucket]++;
if (totalFrames % 100 == 0) { if (totalFrames % 100 == 0) {
DumpStats(); DumpStats();
@ -34,13 +34,20 @@ namespace SemiColinGames {
public void DumpStats() { public void DumpStats() {
Debug.WriteLine(name + ".DumpStats():"); Debug.WriteLine(name + ".DumpStats():");
for (int i = 0; i < histogram.Length - 1; i++) { for (int i = 0; i < histogram.Length; i++) {
int value = histogram[i]; int value = histogram[i];
if (value > 0) { if (value == 0) {
Debug.WriteLine($"{i * 5}-{(i + 1) * 5}%: {histogram[i]}"); continue;
} }
// Every star is one percent.
int numStars = FMath.Clamp(100 * value / totalFrames, 1, 100);
string prefix = String.Format("{0,3}-{1,3}%: ", i * 10, (i + 1) * 10);
if (i == histogram.Length - 1) {
prefix = " 200%+: ";
}
string stars = new string('*', numStars);
Debug.WriteLine(String.Format("{0}{1,-100} {2}", prefix, stars, value));
} }
Debug.WriteLine($"200+%: {histogram[histogram.Length - 1]}");
} }
} }
} }