Browse Source

Adds another Benchmark switch - Help diagnose #3865 (#3870)

* Initial commit

* Expanded benchmark with timeout command line
Tig 7 tháng trước cách đây
mục cha
commit
287e0503db

+ 5 - 5
Terminal.Gui/View/View.Keyboard.cs

@@ -690,11 +690,11 @@ public partial class View // Keyboard APIs
 
 #if DEBUG
 
-        if (Application.KeyBindings.TryGet (key, out KeyBinding b))
-        {
-            Debug.WriteLine (
-                             $"WARNING: InvokeKeyBindings ({key}) - An Application scope binding exists for this key. The registered view will not invoke Command.");
-        }
+        //if (Application.KeyBindings.TryGet (key, out KeyBinding b))
+        //{
+        //    Debug.WriteLine (
+        //                     $"WARNING: InvokeKeyBindings ({key}) - An Application scope binding exists for this key. The registered view will not invoke Command.");
+        //}
 
         // TODO: This is a "prototype" debug check. It may be too annoying vs. useful.
         // Scour the bindings up our View hierarchy

+ 3 - 2
Terminal.Gui/View/View.Layout.cs

@@ -561,8 +561,9 @@ public partial class View // Layout APIs
             {
                 SuperView?.SetNeedsDraw ();
             }
-            else
+            else if (Application.TopLevels.Count == 1)
             {
+                // If this is the only TopLevel, we need to redraw the screen
                 Application.ClearScreenNextIteration = true;
             }
         }
@@ -801,7 +802,7 @@ public partial class View // Layout APIs
         {
             foreach (Toplevel tl in Application.TopLevels)
             {
-               // tl.SetNeedsDraw ();
+                // tl.SetNeedsDraw ();
             }
         }
 

+ 1 - 1
UICatalog/Properties/launchSettings.json

@@ -42,7 +42,7 @@
     },
     "All Views Tester": {
       "commandName": "Project",
-      "commandLineArgs": "\"All Views Tester\" -b"
+      "commandLineArgs": "\"All Views Tester\" -b -t 5000"
     },
     "Charmap": {
       "commandName": "Project",

+ 10 - 9
UICatalog/Scenario.cs

@@ -148,14 +148,15 @@ public class Scenario : IDisposable
     /// </summary>
     public virtual void Main () { }
 
-    private const uint MAX_NATURAL_ITERATIONS = 500; // not including needed for demo keys
-    private const uint ABORT_TIMEOUT_MS = 2500;
-    private const int DEMO_KEY_PACING_MS = 1; // Must be non-zero
+    private const uint BENCHMARK_MAX_NATURAL_ITERATIONS = 500; // not including needed for demo keys
+    private const int BENCHMARK_KEY_PACING = 1; // Must be non-zero
+
+    public static uint BenchmarkTimeout { get; set; } = 2500;
 
     private readonly object _timeoutLock = new ();
     private object? _timeout;
     private Stopwatch? _stopwatch;
-    private readonly BenchmarkResults _benchmarkResults = new BenchmarkResults ();
+    private readonly BenchmarkResults _benchmarkResults = new ();
 
     public void StartBenchmark ()
     {
@@ -178,7 +179,7 @@ public class Scenario : IDisposable
         return _benchmarkResults;
     }
 
-    private List<Key> _demoKeys;
+    private List<Key>? _demoKeys;
     private int _currentDemoKey = 0;
 
     private void OnApplicationOnInitializedChanged (object? s, EventArgs<bool> a)
@@ -187,7 +188,7 @@ public class Scenario : IDisposable
         {
             lock (_timeoutLock!)
             {
-                _timeout = Application.AddTimeout (TimeSpan.FromMilliseconds (ABORT_TIMEOUT_MS), ForceCloseCallback);
+                _timeout = Application.AddTimeout (TimeSpan.FromMilliseconds (BenchmarkTimeout), ForceCloseCallback);
             }
 
             Application.Iteration += OnApplicationOnIteration;
@@ -218,7 +219,7 @@ public class Scenario : IDisposable
     private void OnApplicationOnIteration (object? s, IterationEventArgs a)
     {
         BenchmarkResults.IterationCount++;
-        if (BenchmarkResults.IterationCount > MAX_NATURAL_ITERATIONS + (_demoKeys.Count* DEMO_KEY_PACING_MS))
+        if (BenchmarkResults.IterationCount > BENCHMARK_MAX_NATURAL_ITERATIONS + (_demoKeys.Count * BENCHMARK_KEY_PACING))
         {
             Application.RequestStop ();
         }
@@ -232,7 +233,7 @@ public class Scenario : IDisposable
         _demoKeys = GetDemoKeyStrokes ();
 
         Application.AddTimeout (
-                                new TimeSpan (0, 0, 0, 0, DEMO_KEY_PACING_MS),
+                                new TimeSpan (0, 0, 0, 0, BENCHMARK_KEY_PACING),
                                 () =>
                                 {
                                     if (_currentDemoKey >= _demoKeys.Count)
@@ -271,7 +272,7 @@ public class Scenario : IDisposable
             }
         }
 
-        Debug.WriteLine ($@"  Failed to Quit with {Application.QuitKey} after {ABORT_TIMEOUT_MS}ms and {BenchmarkResults.IterationCount} iterations. Force quit.");
+        Debug.WriteLine ($@"  Failed to Quit with {Application.QuitKey} after {BenchmarkTimeout}ms and {BenchmarkResults.IterationCount} iterations. Force quit.");
 
         Application.RequestStop ();
 

+ 13 - 3
UICatalog/UICatalog.cs

@@ -148,6 +148,10 @@ public class UICatalogApp
         benchmarkFlag.AddAlias ("-b");
         benchmarkFlag.AddAlias ("--b");
 
+        Option<uint> benchmarkTimeout = new Option<uint> ("--timeout", getDefaultValue: () => Scenario.BenchmarkTimeout, $"The maximum time in milliseconds to run a benchmark for. Default is {Scenario.BenchmarkTimeout}ms.");
+        benchmarkTimeout.AddAlias ("-t");
+        benchmarkTimeout.AddAlias ("--t");
+
         Option<string> resultsFile = new Option<string> ("--file", "The file to save benchmark results to. If not specified, the results will be displayed in a TableView.");
         resultsFile.AddAlias ("-f");
         resultsFile.AddAlias ("--f");
@@ -165,7 +169,7 @@ public class UICatalogApp
 
         var rootCommand = new RootCommand ("A comprehensive sample library for Terminal.Gui")
         {
-            scenarioArgument, benchmarkFlag, resultsFile, driverOption,
+            scenarioArgument, benchmarkFlag, benchmarkTimeout, resultsFile, driverOption,
         };
 
         rootCommand.SetHandler (
@@ -176,6 +180,7 @@ public class UICatalogApp
                                         Scenario = context.ParseResult.GetValueForArgument (scenarioArgument),
                                         Driver = context.ParseResult.GetValueForOption (driverOption) ?? string.Empty,
                                         Benchmark = context.ParseResult.GetValueForOption (benchmarkFlag),
+                                        BenchmarkTimeout = context.ParseResult.GetValueForOption (benchmarkTimeout),
                                         ResultsFile = context.ParseResult.GetValueForOption (resultsFile) ?? string.Empty,
                                         /* etc. */
                                     };
@@ -197,6 +202,8 @@ public class UICatalogApp
             return 0;
         }
 
+        Scenario.BenchmarkTimeout = _options.BenchmarkTimeout;
+
         UICatalogMain (_options);
 
         return 0;
@@ -332,6 +339,7 @@ public class UICatalogApp
         // regardless of what's in a config file.
         Application.ForceDriver = _forceDriver = options.Driver;
 
+
         // If a Scenario name has been provided on the commandline
         // run it and exit when done.
         if (options.Scenario != "none")
@@ -788,7 +796,7 @@ public class UICatalogApp
                                              {
                                                  if (_statusBar.NeedsLayout)
                                                  {
-                                                   //  throw new LayoutException ("DimFunc.Fn aborted because dependent View needs layout.");
+                                                     //  throw new LayoutException ("DimFunc.Fn aborted because dependent View needs layout.");
                                                  }
                                                  return _statusBar.Frame.Height;
                                              })),
@@ -817,7 +825,7 @@ public class UICatalogApp
                                              {
                                                  if (_statusBar.NeedsLayout)
                                                  {
-                                                    // throw new LayoutException ("DimFunc.Fn aborted because dependent View needs layout.");
+                                                     // throw new LayoutException ("DimFunc.Fn aborted because dependent View needs layout.");
                                                  }
                                                  return _statusBar.Frame.Height;
                                              })),
@@ -1378,6 +1386,8 @@ public class UICatalogApp
 
         public string Scenario;
 
+        public uint BenchmarkTimeout;
+
         public bool Benchmark;
 
         public string ResultsFile;