From 1577f736e868a82e505f4b37095292146f6164cb Mon Sep 17 00:00:00 2001 From: Daniel Ramos Date: Tue, 30 Aug 2022 14:35:18 -0700 Subject: [PATCH 1/9] Updated ConsolWriter formatting --- .../Exporters/ConsoleWriter.cs | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs b/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs index ce13d87c71..5a425fe9db 100644 --- a/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs +++ b/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs @@ -69,6 +69,9 @@ public ObservedTagSet(string tags) private int _maxRow = -1; private bool _useAnsi = false; + private int _consoleHeight = -1; + private int _consoleWidth = -1; + public ConsoleWriter(bool useAnsi) { this._useAnsi = useAnsi; @@ -126,6 +129,16 @@ public void AssignRowsAndInitializeDisplay() { Clear(); + _consoleWidth = Console.WindowWidth; + _consoleHeight = Console.WindowHeight; + _maxNameLength = _consoleWidth < 80 ? (int)Math.Round(_consoleWidth * 0.5) : 60; + //_maxNameLength = (int)Math.Round(_consoleWidth * 0.8); + + if(_consoleWidth < 100) + { + _maxNameLength = (int)Math.Round(_consoleWidth * 0.5); + } + int row = Console.CursorTop; _topRow = row; Console.WriteLine("Press p to pause, r to resume, q to quit."); row++; @@ -178,7 +191,7 @@ public void ToggleStatus(bool pauseCmdSet) public void CounterPayloadReceived(CounterPayload payload, bool pauseCmdSet) { lock (_lock) - { + { if (!_initialized) { _initialized = true; @@ -222,6 +235,11 @@ public void CounterPayloadReceived(CounterPayload payload, bool pauseCmdSet) redraw = true; } + if(Console.WindowWidth != _consoleWidth || Console.WindowHeight != _consoleHeight) + { + redraw=true; + } + if (redraw) { AssignRowsAndInitializeDisplay(); From 7de8e5bb231e1bb1793097c437cffcae695ea8d7 Mon Sep 17 00:00:00 2001 From: dramos020 Date: Wed, 31 Aug 2022 17:39:44 -0700 Subject: [PATCH 2/9] Fixed the issue of large fonts by using the fixed length of formatted values. --- .../dotnet-counters/Exporters/ConsoleWriter.cs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs b/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs index 5a425fe9db..87070bdf4c 100644 --- a/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs +++ b/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs @@ -58,7 +58,7 @@ public ObservedTagSet(string tags) private readonly object _lock = new object(); private readonly Dictionary _providers = new Dictionary(); // Tracks observed providers and counters. private const int Indent = 4; // Counter name indent size. - private int _maxNameLength = 40; // Allow room for 40 character counter names by default. + private int _maxNameLength = 60; // Allow room for 60 character counter names by default. private int _statusRow; // Row # of where we print the status of dotnet-counters private int _topRow; @@ -72,6 +72,8 @@ public ObservedTagSet(string tags) private int _consoleHeight = -1; private int _consoleWidth = -1; + private int _consoleWidthThreshold = 80; // Threshold of width of console at which name begins to scale down. + private int _nameDefaultLength = 60; public ConsoleWriter(bool useAnsi) { this._useAnsi = useAnsi; @@ -131,13 +133,7 @@ public void AssignRowsAndInitializeDisplay() _consoleWidth = Console.WindowWidth; _consoleHeight = Console.WindowHeight; - _maxNameLength = _consoleWidth < 80 ? (int)Math.Round(_consoleWidth * 0.5) : 60; - //_maxNameLength = (int)Math.Round(_consoleWidth * 0.8); - - if(_consoleWidth < 100) - { - _maxNameLength = (int)Math.Round(_consoleWidth * 0.5); - } + _maxNameLength = _consoleWidth < _consoleWidthThreshold ? _consoleWidth - 20: _nameDefaultLength; int row = Console.CursorTop; _topRow = row; @@ -159,6 +155,7 @@ public void AssignRowsAndInitializeDisplay() counter.Row = row++; if (counter.RenderValueInline) { + Console.WriteLine($"{name} {FormatValue(counter.LastValue)}"); } else From 3ecd9528546d1e0051ecbb01cf35c4598354f9a7 Mon Sep 17 00:00:00 2001 From: dramos020 Date: Thu, 1 Sep 2022 11:19:02 -0700 Subject: [PATCH 3/9] Should now only print the numerical values when the window width is less than 20 --- src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs b/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs index 87070bdf4c..2967bc9f6c 100644 --- a/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs +++ b/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs @@ -74,6 +74,7 @@ public ObservedTagSet(string tags) private int _consoleWidthThreshold = 80; // Threshold of width of console at which name begins to scale down. private int _nameDefaultLength = 60; + public ConsoleWriter(bool useAnsi) { this._useAnsi = useAnsi; @@ -155,8 +156,7 @@ public void AssignRowsAndInitializeDisplay() counter.Row = row++; if (counter.RenderValueInline) { - - Console.WriteLine($"{name} {FormatValue(counter.LastValue)}"); + Console.WriteLine((_consoleWidth > 20) ? $"{name} {FormatValue(counter.LastValue)}" : $"{FormatValue(counter.LastValue)}"); } else { From ceab27b03e1588d6834964b2ebe063008525ee09 Mon Sep 17 00:00:00 2001 From: dramos020 Date: Thu, 1 Sep 2022 17:19:59 -0700 Subject: [PATCH 4/9] Truncate the instruction string at the top of output based on the console width --- .../dotnet-counters/Exporters/ConsoleWriter.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs b/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs index 2967bc9f6c..1002c664ed 100644 --- a/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs +++ b/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs @@ -58,6 +58,8 @@ public ObservedTagSet(string tags) private readonly object _lock = new object(); private readonly Dictionary _providers = new Dictionary(); // Tracks observed providers and counters. private const int Indent = 4; // Counter name indent size. + private const int CounterValueLength= 20; + private int _maxNameLength = 60; // Allow room for 60 character counter names by default. private int _statusRow; // Row # of where we print the status of dotnet-counters @@ -72,9 +74,7 @@ public ObservedTagSet(string tags) private int _consoleHeight = -1; private int _consoleWidth = -1; - private int _consoleWidthThreshold = 80; // Threshold of width of console at which name begins to scale down. - private int _nameDefaultLength = 60; - + public ConsoleWriter(bool useAnsi) { this._useAnsi = useAnsi; @@ -134,11 +134,13 @@ public void AssignRowsAndInitializeDisplay() _consoleWidth = Console.WindowWidth; _consoleHeight = Console.WindowHeight; - _maxNameLength = _consoleWidth < _consoleWidthThreshold ? _consoleWidth - 20: _nameDefaultLength; + _maxNameLength = _consoleWidth < 80 ? _consoleWidth - CounterValueLength: 60; // truncate the display name when the window width is less than 80 int row = Console.CursorTop; _topRow = row; - Console.WriteLine("Press p to pause, r to resume, q to quit."); row++; + + string instructions = "Press p to pause, r to resume, q to quit."; + Console.WriteLine((instructions.Length < _consoleWidth) ? instructions : instructions.Substring(0, _consoleWidth)); row++; Console.WriteLine($" Status: {GetStatus()}"); _statusRow = row++; if (_errorText != null) { @@ -156,7 +158,7 @@ public void AssignRowsAndInitializeDisplay() counter.Row = row++; if (counter.RenderValueInline) { - Console.WriteLine((_consoleWidth > 20) ? $"{name} {FormatValue(counter.LastValue)}" : $"{FormatValue(counter.LastValue)}"); + Console.WriteLine((_consoleWidth > CounterValueLength) ? $"{name} {FormatValue(counter.LastValue)}" : $"{FormatValue(counter.LastValue)}"); } else { From c97259d9caa4656dde7c115c55091f3075e5aacb Mon Sep 17 00:00:00 2001 From: dramos020 Date: Fri, 2 Sep 2022 14:02:58 -0700 Subject: [PATCH 5/9] Updated coding style changes --- src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs b/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs index 1002c664ed..8c446d4f54 100644 --- a/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs +++ b/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs @@ -61,7 +61,6 @@ public ObservedTagSet(string tags) private const int CounterValueLength= 20; private int _maxNameLength = 60; // Allow room for 60 character counter names by default. - private int _statusRow; // Row # of where we print the status of dotnet-counters private int _topRow; private bool _paused = false; @@ -74,7 +73,6 @@ public ObservedTagSet(string tags) private int _consoleHeight = -1; private int _consoleWidth = -1; - public ConsoleWriter(bool useAnsi) { this._useAnsi = useAnsi; @@ -190,7 +188,7 @@ public void ToggleStatus(bool pauseCmdSet) public void CounterPayloadReceived(CounterPayload payload, bool pauseCmdSet) { lock (_lock) - { + { if (!_initialized) { _initialized = true; From 64129f84643c3f76518bed40b75e62c27831464e Mon Sep 17 00:00:00 2001 From: dramos020 Date: Wed, 7 Sep 2022 11:11:49 -0700 Subject: [PATCH 6/9] Added fix for change in console height --- src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs b/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs index 8c446d4f54..de2d991f46 100644 --- a/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs +++ b/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs @@ -150,13 +150,22 @@ public void AssignRowsAndInitializeDisplay() foreach (ObservedProvider provider in _providers.Values.OrderBy(p => p.KnownProvider == null).ThenBy(p => p.Name)) // Known providers first. { Console.WriteLine($"[{provider.Name}]"); row++; + int rowCount = 0; + foreach (ObservedCounter counter in provider.Counters.Values.OrderBy(c => c.DisplayName)) { + if(rowCount >= _consoleHeight - 5) + { + break; + } + + string name = MakeFixedWidth($"{new string(' ', Indent)}{counter.DisplayName}", Indent + _maxNameLength); counter.Row = row++; if (counter.RenderValueInline) { Console.WriteLine((_consoleWidth > CounterValueLength) ? $"{name} {FormatValue(counter.LastValue)}" : $"{FormatValue(counter.LastValue)}"); + rowCount += 1; } else { @@ -166,6 +175,7 @@ public void AssignRowsAndInitializeDisplay() string tagName = MakeFixedWidth($"{new string(' ', 2 * Indent)}{tagSet.Tags}", Indent + _maxNameLength); Console.WriteLine($"{tagName} {FormatValue(tagSet.LastValue)}"); tagSet.Row = row++; + rowCount += 1; } } } From 5c0b595cf809978bde1cec338ff05d06edfab824 Mon Sep 17 00:00:00 2001 From: dramos020 Date: Thu, 8 Sep 2022 10:54:21 -0700 Subject: [PATCH 7/9] Added fix for change in console height and multidimensional metrics. --- .../Exporters/ConsoleWriter.cs | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs b/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs index de2d991f46..5077a4bb03 100644 --- a/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs +++ b/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs @@ -58,7 +58,7 @@ public ObservedTagSet(string tags) private readonly object _lock = new object(); private readonly Dictionary _providers = new Dictionary(); // Tracks observed providers and counters. private const int Indent = 4; // Counter name indent size. - private const int CounterValueLength= 20; + private const int CounterValueLength = 15; private int _maxNameLength = 60; // Allow room for 60 character counter names by default. private int _statusRow; // Row # of where we print the status of dotnet-counters @@ -131,8 +131,7 @@ public void AssignRowsAndInitializeDisplay() Clear(); _consoleWidth = Console.WindowWidth; - _consoleHeight = Console.WindowHeight; - _maxNameLength = _consoleWidth < 80 ? _consoleWidth - CounterValueLength: 60; // truncate the display name when the window width is less than 80 + _consoleHeight = Console.WindowHeight; int row = Console.CursorTop; _topRow = row; @@ -151,7 +150,7 @@ public void AssignRowsAndInitializeDisplay() { Console.WriteLine($"[{provider.Name}]"); row++; int rowCount = 0; - + foreach (ObservedCounter counter in provider.Counters.Values.OrderBy(c => c.DisplayName)) { if(rowCount >= _consoleHeight - 5) @@ -159,23 +158,30 @@ public void AssignRowsAndInitializeDisplay() break; } - + _maxNameLength = Math.Max(Math.Min(80, _consoleWidth) - (CounterValueLength + Indent + 1), 0); string name = MakeFixedWidth($"{new string(' ', Indent)}{counter.DisplayName}", Indent + _maxNameLength); counter.Row = row++; if (counter.RenderValueInline) { - Console.WriteLine((_consoleWidth > CounterValueLength) ? $"{name} {FormatValue(counter.LastValue)}" : $"{FormatValue(counter.LastValue)}"); - rowCount += 1; + Console.WriteLine($"{name} {FormatValue(counter.LastValue)}"); + rowCount++; } else { Console.WriteLine(name); + rowCount++; foreach (ObservedTagSet tagSet in counter.TagSets.Values.OrderBy(t => t.Tags)) { + if(rowCount >= _consoleHeight - 5) + { + break; + } + + _maxNameLength = Math.Max(Math.Min(80, _consoleWidth) - (CounterValueLength + Indent + 1), 0); string tagName = MakeFixedWidth($"{new string(' ', 2 * Indent)}{tagSet.Tags}", Indent + _maxNameLength); Console.WriteLine($"{tagName} {FormatValue(tagSet.LastValue)}"); tagSet.Row = row++; - rowCount += 1; + rowCount++; } } } From 13755a4d544657585def0cc7a4d27dec46b35a15 Mon Sep 17 00:00:00 2001 From: dramos020 Date: Fri, 9 Sep 2022 12:05:59 -0700 Subject: [PATCH 8/9] Added comments and fixed height checker --- .../Exporters/ConsoleWriter.cs | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs b/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs index 5077a4bb03..9494c31994 100644 --- a/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs +++ b/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs @@ -131,7 +131,9 @@ public void AssignRowsAndInitializeDisplay() Clear(); _consoleWidth = Console.WindowWidth; - _consoleHeight = Console.WindowHeight; + _consoleHeight = Console.WindowHeight; + _maxNameLength = Math.Max(Math.Min(80, _consoleWidth) - (CounterValueLength + Indent + 1), 0); // Truncate the name to prevent line wrapping as long as the console width is >= CounterValueLength + Indent + 1 characters + int row = Console.CursorTop; _topRow = row; @@ -149,39 +151,33 @@ public void AssignRowsAndInitializeDisplay() foreach (ObservedProvider provider in _providers.Values.OrderBy(p => p.KnownProvider == null).ThenBy(p => p.Name)) // Known providers first. { Console.WriteLine($"[{provider.Name}]"); row++; - int rowCount = 0; foreach (ObservedCounter counter in provider.Counters.Values.OrderBy(c => c.DisplayName)) { - if(rowCount >= _consoleHeight - 5) - { - break; - } - - _maxNameLength = Math.Max(Math.Min(80, _consoleWidth) - (CounterValueLength + Indent + 1), 0); + string name = MakeFixedWidth($"{new string(' ', Indent)}{counter.DisplayName}", Indent + _maxNameLength); counter.Row = row++; if (counter.RenderValueInline) { + if(row >= _consoleHeight) // prevents from displaying more counters than vertical space available + { + break; + } Console.WriteLine($"{name} {FormatValue(counter.LastValue)}"); - rowCount++; } else { Console.WriteLine(name); - rowCount++; foreach (ObservedTagSet tagSet in counter.TagSets.Values.OrderBy(t => t.Tags)) { - if(rowCount >= _consoleHeight - 5) + if(row >= _consoleHeight) { break; } - _maxNameLength = Math.Max(Math.Min(80, _consoleWidth) - (CounterValueLength + Indent + 1), 0); string tagName = MakeFixedWidth($"{new string(' ', 2 * Indent)}{tagSet.Tags}", Indent + _maxNameLength); Console.WriteLine($"{tagName} {FormatValue(tagSet.LastValue)}"); tagSet.Row = row++; - rowCount++; } } } From 4f59900fbbecc6822ced3c15c7f1322e684aa91b Mon Sep 17 00:00:00 2001 From: dramos020 Date: Mon, 12 Sep 2022 11:43:07 -0700 Subject: [PATCH 9/9] Changed the default value for _maxNameLength --- src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs b/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs index 9494c31994..b6ff55040b 100644 --- a/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs +++ b/src/Tools/dotnet-counters/Exporters/ConsoleWriter.cs @@ -60,7 +60,7 @@ public ObservedTagSet(string tags) private const int Indent = 4; // Counter name indent size. private const int CounterValueLength = 15; - private int _maxNameLength = 60; // Allow room for 60 character counter names by default. + private int _maxNameLength = 0; private int _statusRow; // Row # of where we print the status of dotnet-counters private int _topRow; private bool _paused = false;