Fix issue 387 (#391)
authorSung Yoon Whang <suwhang@microsoft.com>
Thu, 11 Jul 2019 04:11:55 +0000 (21:11 -0700)
committerGitHub <noreply@github.com>
Thu, 11 Jul 2019 04:11:55 +0000 (21:11 -0700)
* Fix some issue in counters

* fix accidental bug

src/Tools/dotnet-counters/ConsoleWriter.cs
src/Tools/dotnet-counters/KnownData.cs

index e89d58a1b7daca8394876b8e1be0e98aa03d4238..0f2a5eaf47cd87cfe94a3b0af4dd2ac7e3ed04d7 100644 (file)
@@ -38,12 +38,20 @@ namespace Microsoft.Diagnostics.Tools.Counters
             displayLength = new Dictionary<string, int>();
             knownProvidersRowNum = new Dictionary<string, int>();
             unknownProvidersRowNum = new Dictionary<string, int>();
-            leftAlign = 45; // Width of counter names column
 
+            int maxNameWidth = -1;
             foreach(CounterProvider provider in KnownData.GetAllProviders())
             {
+                foreach(CounterProfile counterProfile in provider.GetAllCounters())
+                {
+                    if (counterProfile.DisplayName.Length > maxNameWidth)
+                    {
+                        maxNameWidth = counterProfile.DisplayName.Length;
+                    }
+                }
                 knownProvidersRowNum[provider.Name] = -1;
             }
+            leftAlign = maxNameWidth + 15;
         }
 
         public void InitializeDisplay()
@@ -103,7 +111,10 @@ namespace Microsoft.Diagnostics.Tools.Counters
             if (displayPosition.ContainsKey(keyName))
             {
                 (int left, int row) = displayPosition[keyName];
-                int clearLength = displayLength[keyName];
+                string payloadVal = payload.GetValue();
+
+                int clearLength = Math.Max(displayLength[keyName], payloadVal.Length); // Compute how long we need to clear out.
+                displayLength[keyName] = clearLength;
                 Console.SetCursorPosition(left, row); 
                 Console.Write(new String(' ', clearLength));
 
@@ -116,7 +127,7 @@ namespace Microsoft.Diagnostics.Tools.Counters
                 {
                     Console.SetCursorPosition(left, row);
                 }
-                Console.Write(payload.GetValue());  
+                Console.Write(payloadVal);
             }
             // Got a payload from a new counter that hasn't been written to the console yet.
             else
index d94f7e76622e710fbae8c19958fa18aa982ce064..00869e7853a66a4a0039e4014b8e0c561b5c52fb 100644 (file)
@@ -15,7 +15,6 @@ namespace Microsoft.Diagnostics.Tools.Counters
         private static readonly IReadOnlyDictionary<string, CounterProvider> _knownProviders =
             CreateKnownProviders().ToDictionary(p => p.Name, StringComparer.OrdinalIgnoreCase);
 
-
         private static IEnumerable<CounterProvider> CreateKnownProviders()
         {
             yield return new CounterProvider(