Pārlūkot izejas kodu

Added stopwatch

Tig 11 mēneši atpakaļ
vecāks
revīzija
4f683d33b1

+ 8 - 2
Terminal.Gui/Application/Application.Initialization.cs

@@ -198,10 +198,16 @@ public static partial class Application // Initialization (Init/Shutdown)
     public static void Shutdown ()
     {
         // TODO: Throw an exception if Init hasn't been called.
+
+        bool wasInitialized = IsInitialized;
         ResetState ();
         PrintJsonErrors ();
-        bool init = IsInitialized;
-        InitializedChanged?.Invoke (null, new (in init));
+
+        if (wasInitialized)
+        {
+            bool init = IsInitialized;
+            InitializedChanged?.Invoke (null, new (in init));
+        }
     }
 
     /// <summary>

+ 30 - 0
UICatalog/UICatalog.cs

@@ -13,6 +13,7 @@ using System.Runtime.InteropServices;
 using System.Text;
 using System.Text.Json.Serialization;
 using Terminal.Gui;
+using UICatalog.Scenarios;
 using static Terminal.Gui.ConfigurationManager;
 using Command = Terminal.Gui.Command;
 using RuntimeEnvironment = Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment;
@@ -337,6 +338,14 @@ public class UICatalogApp
             Apply ();
             scenario.Theme = _cachedTheme;
             scenario.TopLevelColorScheme = _topLevelColorScheme;
+
+#if DEBUG_IDISPOSABLE
+            // Measure how long it takes for the app to shut down
+            var sw = new Stopwatch ();
+            string scenarioName = scenario.GetName ();
+            Application.InitializedChanged += ApplicationOnInitializedChanged;
+#endif
+
             scenario.Main ();
             scenario.Dispose ();
 
@@ -345,10 +354,31 @@ public class UICatalogApp
             // TODO: Throw if shutdown was not called already
             Application.Shutdown ();
             VerifyObjectsWereDisposed ();
+
+#if DEBUG_IDISPOSABLE
+            Application.InitializedChanged -= ApplicationOnInitializedChanged;
+
+            void ApplicationOnInitializedChanged (object? sender, EventArgs<bool> e)
+            {
+                if (e.CurrentValue)
+                {
+                    sw.Start ();
+                }
+                else
+                {
+                    sw.Stop ();
+                    Debug.WriteLine ($"Shutdown of {scenarioName} Scenario took {sw.ElapsedMilliseconds}ms");
+                }
+            }
+#endif
         }
 
         StopConfigFileWatcher ();
         VerifyObjectsWereDisposed ();
+
+        return;
+
+
     }
 
     private static void VerifyObjectsWereDisposed ()