diff options
| author | godosa <godosa@godosa.eu> | 2026-10-06 23:39:36 +0200 |
|---|---|---|
| committer | godosa <godosa@godosa.eu> | 2026-10-06 23:39:36 +0200 |
| commit | 39066900773e7857faf2d02e7ed51b71d219d97d (patch) | |
| tree | ffab8e4ddd971626776c3b1f4ce1da2c186c2187 /src/Godosa.Core/Diagnostics/PerfCsv.cs | |
| download | godosa-engine-39066900773e7857faf2d02e7ed51b71d219d97d.tar.gz godosa-engine-39066900773e7857faf2d02e7ed51b71d219d97d.zip | |
godosa-engine: initial public history
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) : ""; +} |
