diff options
Diffstat (limited to 'src/Godosa.Core/Diagnostics/PerfCsv.cs')
| -rw-r--r-- | src/Godosa.Core/Diagnostics/PerfCsv.cs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/Godosa.Core/Diagnostics/PerfCsv.cs b/src/Godosa.Core/Diagnostics/PerfCsv.cs new file mode 100644 index 0000000..6c4ef0d --- /dev/null +++ b/src/Godosa.Core/Diagnostics/PerfCsv.cs @@ -0,0 +1,27 @@ +using System.Globalization; + +namespace Godosa.Core.Diagnostics; + +/// <summary>Per-frame CSV rows for perf-log stall hunts. Fixed columns first, then the +/// caller's own (<see cref="Header"/> names, <see cref="Row"/> values, same order). +/// Invariant culture; times in ms with 3 decimals; blank = unknown (e.g. GPU before a +/// timer query reports).</summary> +public static class PerfCsv +{ + public const string BaseHeader = "t_s,frame_ms,work_ms,sim_ticks,sim_ms,gpu_ms"; + + public static string Header(params string[] extraColumns) => + extraColumns.Length == 0 ? BaseHeader : BaseHeader + "," + string.Join(',', extraColumns); + + public static string Row(double timeSeconds, double frameSeconds, double workSeconds, int simTicks, + double simSeconds, double? gpuSeconds, params string[] extraValues) + { + string row = string.Create(CultureInfo.InvariantCulture, + $"{timeSeconds:F3},{frameSeconds * 1000:F3},{workSeconds * 1000:F3},{simTicks},{simSeconds * 1000:F3},{Ms(gpuSeconds)}"); + return extraValues.Length == 0 ? row : row + "," + string.Join(',', extraValues); + } + + /// <summary>Seconds → ms with 3 decimals (invariant); blank for null.</summary> + public static string Ms(double? seconds) => + seconds is { } s ? (s * 1000).ToString("F3", CultureInfo.InvariantCulture) : ""; +} |
