Skip to content

Commit 287e050

Browse files
authored
Adds another Benchmark switch - Help diagnose #3865 (#3870)
* Initial commit * Expanded benchmark with timeout command line
1 parent d4d0675 commit 287e050

File tree

5 files changed

+32
-20
lines changed

5 files changed

+32
-20
lines changed

Terminal.Gui/View/View.Keyboard.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -690,11 +690,11 @@ public bool IsHotKeyBound (Key key, out View? boundView)
690690

691691
#if DEBUG
692692

693-
if (Application.KeyBindings.TryGet (key, out KeyBinding b))
694-
{
695-
Debug.WriteLine (
696-
$"WARNING: InvokeKeyBindings ({key}) - An Application scope binding exists for this key. The registered view will not invoke Command.");
697-
}
693+
//if (Application.KeyBindings.TryGet (key, out KeyBinding b))
694+
//{
695+
// Debug.WriteLine (
696+
// $"WARNING: InvokeKeyBindings ({key}) - An Application scope binding exists for this key. The registered view will not invoke Command.");
697+
//}
698698

699699
// TODO: This is a "prototype" debug check. It may be too annoying vs. useful.
700700
// Scour the bindings up our View hierarchy

Terminal.Gui/View/View.Layout.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,9 @@ public bool SetRelativeLayout (Size superviewContentSize)
561561
{
562562
SuperView?.SetNeedsDraw ();
563563
}
564-
else
564+
else if (Application.TopLevels.Count == 1)
565565
{
566+
// If this is the only TopLevel, we need to redraw the screen
566567
Application.ClearScreenNextIteration = true;
567568
}
568569
}
@@ -801,7 +802,7 @@ public void SetNeedsLayout ()
801802
{
802803
foreach (Toplevel tl in Application.TopLevels)
803804
{
804-
// tl.SetNeedsDraw ();
805+
// tl.SetNeedsDraw ();
805806
}
806807
}
807808

UICatalog/Properties/launchSettings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
},
4343
"All Views Tester": {
4444
"commandName": "Project",
45-
"commandLineArgs": "\"All Views Tester\" -b"
45+
"commandLineArgs": "\"All Views Tester\" -b -t 5000"
4646
},
4747
"Charmap": {
4848
"commandName": "Project",

UICatalog/Scenario.cs

+10-9
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,15 @@ public static ObservableCollection<Scenario> GetScenarios ()
148148
/// </summary>
149149
public virtual void Main () { }
150150

151-
private const uint MAX_NATURAL_ITERATIONS = 500; // not including needed for demo keys
152-
private const uint ABORT_TIMEOUT_MS = 2500;
153-
private const int DEMO_KEY_PACING_MS = 1; // Must be non-zero
151+
private const uint BENCHMARK_MAX_NATURAL_ITERATIONS = 500; // not including needed for demo keys
152+
private const int BENCHMARK_KEY_PACING = 1; // Must be non-zero
153+
154+
public static uint BenchmarkTimeout { get; set; } = 2500;
154155

155156
private readonly object _timeoutLock = new ();
156157
private object? _timeout;
157158
private Stopwatch? _stopwatch;
158-
private readonly BenchmarkResults _benchmarkResults = new BenchmarkResults ();
159+
private readonly BenchmarkResults _benchmarkResults = new ();
159160

160161
public void StartBenchmark ()
161162
{
@@ -178,7 +179,7 @@ public BenchmarkResults EndBenchmark ()
178179
return _benchmarkResults;
179180
}
180181

181-
private List<Key> _demoKeys;
182+
private List<Key>? _demoKeys;
182183
private int _currentDemoKey = 0;
183184

184185
private void OnApplicationOnInitializedChanged (object? s, EventArgs<bool> a)
@@ -187,7 +188,7 @@ private void OnApplicationOnInitializedChanged (object? s, EventArgs<bool> a)
187188
{
188189
lock (_timeoutLock!)
189190
{
190-
_timeout = Application.AddTimeout (TimeSpan.FromMilliseconds (ABORT_TIMEOUT_MS), ForceCloseCallback);
191+
_timeout = Application.AddTimeout (TimeSpan.FromMilliseconds (BenchmarkTimeout), ForceCloseCallback);
191192
}
192193

193194
Application.Iteration += OnApplicationOnIteration;
@@ -218,7 +219,7 @@ private void OnApplicationOnInitializedChanged (object? s, EventArgs<bool> a)
218219
private void OnApplicationOnIteration (object? s, IterationEventArgs a)
219220
{
220221
BenchmarkResults.IterationCount++;
221-
if (BenchmarkResults.IterationCount > MAX_NATURAL_ITERATIONS + (_demoKeys.Count* DEMO_KEY_PACING_MS))
222+
if (BenchmarkResults.IterationCount > BENCHMARK_MAX_NATURAL_ITERATIONS + (_demoKeys.Count * BENCHMARK_KEY_PACING))
222223
{
223224
Application.RequestStop ();
224225
}
@@ -232,7 +233,7 @@ private void OnApplicationNotifyNewRunState (object? sender, RunStateEventArgs e
232233
_demoKeys = GetDemoKeyStrokes ();
233234

234235
Application.AddTimeout (
235-
new TimeSpan (0, 0, 0, 0, DEMO_KEY_PACING_MS),
236+
new TimeSpan (0, 0, 0, 0, BENCHMARK_KEY_PACING),
236237
() =>
237238
{
238239
if (_currentDemoKey >= _demoKeys.Count)
@@ -271,7 +272,7 @@ private bool ForceCloseCallback ()
271272
}
272273
}
273274

274-
Debug.WriteLine ($@" Failed to Quit with {Application.QuitKey} after {ABORT_TIMEOUT_MS}ms and {BenchmarkResults.IterationCount} iterations. Force quit.");
275+
Debug.WriteLine ($@" Failed to Quit with {Application.QuitKey} after {BenchmarkTimeout}ms and {BenchmarkResults.IterationCount} iterations. Force quit.");
275276

276277
Application.RequestStop ();
277278

UICatalog/UICatalog.cs

+13-3
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ private static int Main (string [] args)
148148
benchmarkFlag.AddAlias ("-b");
149149
benchmarkFlag.AddAlias ("--b");
150150

151+
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.");
152+
benchmarkTimeout.AddAlias ("-t");
153+
benchmarkTimeout.AddAlias ("--t");
154+
151155
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.");
152156
resultsFile.AddAlias ("-f");
153157
resultsFile.AddAlias ("--f");
@@ -165,7 +169,7 @@ private static int Main (string [] args)
165169

166170
var rootCommand = new RootCommand ("A comprehensive sample library for Terminal.Gui")
167171
{
168-
scenarioArgument, benchmarkFlag, resultsFile, driverOption,
172+
scenarioArgument, benchmarkFlag, benchmarkTimeout, resultsFile, driverOption,
169173
};
170174

171175
rootCommand.SetHandler (
@@ -176,6 +180,7 @@ private static int Main (string [] args)
176180
Scenario = context.ParseResult.GetValueForArgument (scenarioArgument),
177181
Driver = context.ParseResult.GetValueForOption (driverOption) ?? string.Empty,
178182
Benchmark = context.ParseResult.GetValueForOption (benchmarkFlag),
183+
BenchmarkTimeout = context.ParseResult.GetValueForOption (benchmarkTimeout),
179184
ResultsFile = context.ParseResult.GetValueForOption (resultsFile) ?? string.Empty,
180185
/* etc. */
181186
};
@@ -197,6 +202,8 @@ private static int Main (string [] args)
197202
return 0;
198203
}
199204

205+
Scenario.BenchmarkTimeout = _options.BenchmarkTimeout;
206+
200207
UICatalogMain (_options);
201208

202209
return 0;
@@ -332,6 +339,7 @@ private static void UICatalogMain (Options options)
332339
// regardless of what's in a config file.
333340
Application.ForceDriver = _forceDriver = options.Driver;
334341

342+
335343
// If a Scenario name has been provided on the commandline
336344
// run it and exit when done.
337345
if (options.Scenario != "none")
@@ -788,7 +796,7 @@ public UICatalogTopLevel ()
788796
{
789797
if (_statusBar.NeedsLayout)
790798
{
791-
// throw new LayoutException ("DimFunc.Fn aborted because dependent View needs layout.");
799+
// throw new LayoutException ("DimFunc.Fn aborted because dependent View needs layout.");
792800
}
793801
return _statusBar.Frame.Height;
794802
})),
@@ -817,7 +825,7 @@ public UICatalogTopLevel ()
817825
{
818826
if (_statusBar.NeedsLayout)
819827
{
820-
// throw new LayoutException ("DimFunc.Fn aborted because dependent View needs layout.");
828+
// throw new LayoutException ("DimFunc.Fn aborted because dependent View needs layout.");
821829
}
822830
return _statusBar.Frame.Height;
823831
})),
@@ -1378,6 +1386,8 @@ private struct Options
13781386

13791387
public string Scenario;
13801388

1389+
public uint BenchmarkTimeout;
1390+
13811391
public bool Benchmark;
13821392

13831393
public string ResultsFile;

0 commit comments

Comments
 (0)