From 863c9440a130e1287190dcfd7a2f3f4f9b3dd138 Mon Sep 17 00:00:00 2001 From: Ionite Date: Wed, 27 Sep 2023 20:52:28 -0400 Subject: [PATCH] Show app startup time in logs --- StabilityMatrix.Avalonia/Program.cs | 4 ++++ StabilityMatrix.Avalonia/ViewModels/MainWindowViewModel.cs | 5 +++++ StabilityMatrix.Core/Helper/CodeTimer.cs | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/StabilityMatrix.Avalonia/Program.cs b/StabilityMatrix.Avalonia/Program.cs index 11f001c5..b8c0cd00 100644 --- a/StabilityMatrix.Avalonia/Program.cs +++ b/StabilityMatrix.Avalonia/Program.cs @@ -38,12 +38,16 @@ public class Program public static bool IsDebugBuild { get; private set; } + public static Stopwatch StartupTimer { get; } = new(); + // Initialization code. Don't use any Avalonia, third-party APIs or any // SynchronizationContext-reliant code before AppMain is called: things aren't initialized // yet and stuff might break. [STAThread] public static void Main(string[] args) { + StartupTimer.Start(); + Args.DebugExceptionDialog = args.Contains("--debug-exception-dialog"); Args.DebugSentry = args.Contains("--debug-sentry"); Args.DebugOneClickInstall = args.Contains("--debug-one-click-install"); diff --git a/StabilityMatrix.Avalonia/ViewModels/MainWindowViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/MainWindowViewModel.cs index 431d4f53..1abe5f17 100644 --- a/StabilityMatrix.Avalonia/ViewModels/MainWindowViewModel.cs +++ b/StabilityMatrix.Avalonia/ViewModels/MainWindowViewModel.cs @@ -103,6 +103,11 @@ public partial class MainWindowViewModel : ViewModelBase Task.Run(() => settingsManager.IndexCheckpoints()).SafeFireAndForget(); PreloadPages(); + + Program.StartupTimer.Stop(); + var startupTime = CodeTimer.FormatTime(Program.StartupTimer.Elapsed); + Logger.Info($"App started ({startupTime})"); + if (Program.Args.DebugOneClickInstall || !settingsManager.Settings.InstalledPackages.Any()) { var viewModel = dialogFactory.Get(); diff --git a/StabilityMatrix.Core/Helper/CodeTimer.cs b/StabilityMatrix.Core/Helper/CodeTimer.cs index 702bc98a..f881c4c5 100644 --- a/StabilityMatrix.Core/Helper/CodeTimer.cs +++ b/StabilityMatrix.Core/Helper/CodeTimer.cs @@ -52,7 +52,7 @@ public class CodeTimer : IDisposable /// /// Formats a TimeSpan into a string. Chooses the most appropriate unit of time. /// - private static string FormatTime(TimeSpan duration) + public static string FormatTime(TimeSpan duration) { if (duration.TotalSeconds < 1) {