1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-12-27 10:39:24 +01:00
MLEM/MLEM.Ui/UiMetrics.cs

121 lines
6 KiB
C#
Raw Normal View History

2021-12-12 12:32:09 +01:00
using System;
using MLEM.Ui.Elements;
namespace MLEM.Ui {
/// <summary>
/// A snapshot of update and rendering statistics from <see cref="UiSystem.Metrics"/> to be used for runtime debugging and profiling.
/// </summary>
public struct UiMetrics {
/// <summary>
/// The amount of time that <see cref="Element.ForceUpdateArea"/> took.
/// Can be divided by <see cref="ForceAreaUpdates"/> to get an average per area update.
/// </summary>
public TimeSpan ForceAreaUpdateTime { get; internal set; }
/// <summary>
/// The amount of time that <see cref="Element.Update"/> took.
/// Can be divided by <see cref="Updates"/> to get an average per update.
/// </summary>
public TimeSpan UpdateTime { get; internal set; }
/// <summary>
/// The amount of times that <see cref="Element.ForceUpdateArea"/> was called.
/// </summary>
public uint ForceAreaUpdates { get; internal set; }
/// <summary>
/// The amount of times that <see cref="Element.SetAreaAndUpdateChildren"/> was called.
/// </summary>
public uint ActualAreaUpdates { get; internal set; }
/// <summary>
/// The amount of times that <see cref="Element.Update"/> was called.
/// </summary>
public uint Updates { get; internal set; }
/// <summary>
/// The total amount of recursions that <see cref="Element.ForceUpdateArea"/> went through.
/// Can be divided by <see cref="ForceAreaUpdates"/> to get an average.
/// </summary>
public uint SummedRecursionDepth { get; internal set; }
/// <summary>
/// The maximum recursion depth that <see cref="Element.ForceUpdateArea"/> went through in a single call.
/// </summary>
public int MaxRecursionDepth { get; internal set; }
2021-12-12 12:32:09 +01:00
/// <summary>
2022-04-25 15:25:58 +02:00
/// The amount of time that <see cref="Element.Draw(Microsoft.Xna.Framework.GameTime,Microsoft.Xna.Framework.Graphics.SpriteBatch,float,MLEM.Graphics.SpriteBatchContext)"/> took.
2021-12-12 12:32:09 +01:00
/// Can be divided by <see cref="Draws"/> to get an average per draw.
/// </summary>
public TimeSpan DrawTime { get; internal set; }
/// <summary>
2022-04-25 15:25:58 +02:00
/// The amount of times that <see cref="Element.Draw(Microsoft.Xna.Framework.GameTime,Microsoft.Xna.Framework.Graphics.SpriteBatch,float,MLEM.Graphics.SpriteBatchContext)"/> was called.
2021-12-12 12:32:09 +01:00
/// </summary>
public uint Draws { get; internal set; }
/// <summary>
/// Resets all update-related metrics to 0.
/// </summary>
public void ResetUpdates() {
this.ForceAreaUpdateTime = TimeSpan.Zero;
this.UpdateTime = TimeSpan.Zero;
this.ForceAreaUpdates = 0;
this.ActualAreaUpdates = 0;
this.Updates = 0;
this.SummedRecursionDepth = 0;
this.MaxRecursionDepth = 0;
2021-12-12 12:32:09 +01:00
}
/// <summary>
/// Resets all rendering-related metrics to 0.
/// </summary>
public void ResetDraws() {
this.DrawTime = TimeSpan.Zero;
this.Draws = 0;
}
/// <summary>Returns the fully qualified type name of this instance.</summary>
/// <returns>The fully qualified type name.</returns>
public override string ToString() {
return $"{nameof(this.ForceAreaUpdateTime)}: {this.ForceAreaUpdateTime}, {nameof(this.UpdateTime)}: {this.UpdateTime}, {nameof(this.ForceAreaUpdates)}: {this.ForceAreaUpdates}, {nameof(this.ActualAreaUpdates)}: {this.ActualAreaUpdates}, {nameof(this.Updates)}: {this.Updates}, {nameof(this.SummedRecursionDepth)}: {this.SummedRecursionDepth}, {nameof(this.MaxRecursionDepth)}: {this.MaxRecursionDepth}, {nameof(this.DrawTime)}: {this.DrawTime}, {nameof(this.Draws)}: {this.Draws}";
2021-12-12 12:32:09 +01:00
}
/// <summary>
/// Adds two ui metrics together, causing all of their values to be combined.
/// </summary>
/// <param name="left">The left metrics</param>
/// <param name="right">The right metrics</param>
/// <returns>The sum of both metrics</returns>
public static UiMetrics operator +(UiMetrics left, UiMetrics right) {
return new UiMetrics {
ForceAreaUpdateTime = left.ForceAreaUpdateTime + right.ForceAreaUpdateTime,
UpdateTime = left.UpdateTime + right.UpdateTime,
ForceAreaUpdates = left.ForceAreaUpdates + right.ForceAreaUpdates,
ActualAreaUpdates = left.ActualAreaUpdates + right.ActualAreaUpdates,
Updates = left.Updates + right.Updates,
SummedRecursionDepth = left.SummedRecursionDepth + right.SummedRecursionDepth,
MaxRecursionDepth = left.MaxRecursionDepth + right.MaxRecursionDepth,
2021-12-12 12:32:09 +01:00
DrawTime = left.DrawTime + right.DrawTime,
Draws = left.Draws + right.Draws
};
}
/// <summary>
/// Subtracts two ui metrics from each other, causing their values to be subtracted.
/// </summary>
/// <param name="left">The left metrics</param>
/// <param name="right">The right metrics</param>
/// <returns>The difference of both metrics</returns>
public static UiMetrics operator -(UiMetrics left, UiMetrics right) {
return new UiMetrics {
ForceAreaUpdateTime = left.ForceAreaUpdateTime - right.ForceAreaUpdateTime,
UpdateTime = left.UpdateTime - right.UpdateTime,
ForceAreaUpdates = left.ForceAreaUpdates - right.ForceAreaUpdates,
ActualAreaUpdates = left.ActualAreaUpdates - right.ActualAreaUpdates,
Updates = left.Updates - right.Updates,
SummedRecursionDepth = left.SummedRecursionDepth - right.SummedRecursionDepth,
MaxRecursionDepth = left.MaxRecursionDepth - right.MaxRecursionDepth,
2021-12-12 12:32:09 +01:00
DrawTime = left.DrawTime - right.DrawTime,
Draws = left.Draws - right.Draws
};
}
}
2022-06-17 18:23:47 +02:00
}