From: Sung Yoon Whang Date: Tue, 11 Jun 2019 04:45:16 +0000 (-0700) Subject: Clear out correct length for counter value (#320) X-Git-Tag: submit/tizen/20190813.035844~6^2^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2b5c9323ff378dc7f6680fd1235fb5630713d1f2;p=platform%2Fcore%2Fdotnet%2Fdiagnostics.git Clear out correct length for counter value (#320) --- diff --git a/src/Tools/dotnet-counters/ConsoleWriter.cs b/src/Tools/dotnet-counters/ConsoleWriter.cs index 602cd073d..0e11001e7 100644 --- a/src/Tools/dotnet-counters/ConsoleWriter.cs +++ b/src/Tools/dotnet-counters/ConsoleWriter.cs @@ -11,6 +11,7 @@ namespace Microsoft.Diagnostics.Tools.Counters public class ConsoleWriter { private Dictionary displayPosition; // Display position (x-y coordiates) of each counter values. + private Dictionary displayLength; // Length of the counter values displayed for each counter. private int origRow; private int origCol; private int maxRow; // Running maximum of row number @@ -33,6 +34,7 @@ namespace Microsoft.Diagnostics.Tools.Counters public ConsoleWriter() { displayPosition = new Dictionary(); + displayLength = new Dictionary(); knownProvidersRowNum = new Dictionary(); unknownProvidersRowNum = new Dictionary(); @@ -72,6 +74,12 @@ namespace Microsoft.Diagnostics.Tools.Counters paused = pauseCmdSet; } + // Generates a string using providerName and counterName that can be used as a dictionary key to prevent key collision + private string CounterNameString(string providerName, string counterName) + { + return $"{providerName}:{counterName}"; + } + public void Update(string providerName, ICounterPayload payload, bool pauseCmdSet) { @@ -86,13 +94,14 @@ namespace Microsoft.Diagnostics.Tools.Counters return; } string name = payload.GetName(); - + string keyName = CounterNameString(providerName, name); // We already know what this counter is! Just update the value string on the console. - if (displayPosition.ContainsKey(name)) + if (displayPosition.ContainsKey(keyName)) { - (int left, int row) = displayPosition[name]; + (int left, int row) = displayPosition[keyName]; + int clearLength = displayLength[keyName]; Console.SetCursorPosition(left, row); - Console.Write(new String(' ', 8)); + Console.Write(new String(' ', clearLength)); Console.SetCursorPosition(left, row); Console.Write(payload.GetValue()); @@ -121,8 +130,10 @@ namespace Microsoft.Diagnostics.Tools.Counters int left = displayName.Length + 7; // displayName + " : " int row = maxRow; - displayPosition[name] = (left, row); - Console.WriteLine($" {displayName} : {payload.GetValue()}"); + string val = payload.GetValue(); + displayPosition[keyName] = (left, row); + displayLength[keyName] = val.Length; + Console.WriteLine($" {displayName} : {val}"); maxRow += 1; } else @@ -143,8 +154,10 @@ namespace Microsoft.Diagnostics.Tools.Counters } int left = displayName.Length + 7; // displayName + " : " int row = maxRow; - displayPosition[name] = (left, row); - Console.WriteLine($" {displayName} : {payload.GetValue()}"); + string val = payload.GetValue(); + displayPosition[keyName] = (left, row); + displayLength[keyName] = val.Length; + Console.WriteLine($" {displayName} : {val}"); maxRow += 1; } }