Skip to content

Commit

Permalink
Add all timings on startup to the log output.
Browse files Browse the repository at this point in the history
  • Loading branch information
CptMoore committed Dec 6, 2024
1 parent 1da6b03 commit a8f08a2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
23 changes: 14 additions & 9 deletions ModTek/Features/Logging/AppenderFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ internal AppenderFile(string path, AppenderSettings settings)
BufferSize,
FileOptions.None
);
WriteLine($"ModTek v{GitVersionInformation.InformationalVersion} ({GitVersionInformation.CommitDate})");
WriteLine(DateTimeOffset.Now.ToString("o", CultureInfo.InvariantCulture));
WriteLine(new string('-', 80));
WriteLine(VersionInfo.GetFormattedInfo());
}

private void WriteLine(string line)
{
Write(line + Environment.NewLine);
MTLoggerMessageDto.GetTimings(out var stopwatchTimestamp, out var dateTime, out var unityStartupTime);
Write(
$"""
ModTek v{GitVersionInformation.InformationalVersion} ({GitVersionInformation.CommitDate})
{dateTime.ToLocalTime().ToString("o", CultureInfo.InvariantCulture)} {nameof(unityStartupTime)}={unityStartupTime.ToString(null, CultureInfo.InvariantCulture)} {nameof(stopwatchTimestamp)}={stopwatchTimestamp}
{new string('-', 80)}
{VersionInfo.GetFormattedInfo()}
"""
);
}

internal static readonly MTStopwatch FiltersStopWatch = new();
Expand Down Expand Up @@ -70,13 +71,17 @@ internal void Append(MTLoggerMessageDto messageDto)
}

internal static readonly MTStopwatch GetBytesStopwatch = new();
internal static readonly MTStopwatch WriteStopwatch = new();
private void Write(string text)
{
GetBytesStopwatch.Start();
var bytes = System.Text.Encoding.UTF8.GetBytes(text);
GetBytesStopwatch.Stop();
Write(bytes);
}

internal static readonly MTStopwatch WriteStopwatch = new();
private void Write(byte[] bytes)
{
WriteStopwatch.Start();
try
{
Expand Down
13 changes: 10 additions & 3 deletions ModTek/Features/Logging/MTLoggerMessageDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@ namespace ModTek.Features.Logging;

internal struct MTLoggerMessageDto
{
private static long s_stopwatchTimestamp = Stopwatch.GetTimestamp();
private static DateTime s_dateTime = DateTime.UtcNow;
private static TimeSpan s_unityStartupTime = TimeSpan.FromSeconds(Time.realtimeSinceStartup);
private static readonly long s_stopwatchTimestamp = Stopwatch.GetTimestamp();
private static readonly DateTime s_dateTime = DateTime.UtcNow;
private static readonly TimeSpan s_unityStartupTime = TimeSpan.FromSeconds(Time.realtimeSinceStartup);

internal static void GetTimings(out long stopwatchTimestamp, out DateTime dateTime, out TimeSpan unityStartupTime)
{
stopwatchTimestamp = s_stopwatchTimestamp;
dateTime = s_dateTime;
unityStartupTime = s_unityStartupTime;
}

internal volatile bool CommittedToQueue;
internal long Timestamp;
Expand Down

0 comments on commit a8f08a2

Please sign in to comment.