From 60cdc98a1af6d0b98a6dd4a41830ed5701dc4aa0 Mon Sep 17 00:00:00 2001 From: ghord Date: Fri, 16 Dec 2022 02:57:42 +0100 Subject: [PATCH] Change metrics parsing to use InvariantCulture (#3558) --- src/Tools/dotnet-counters/CounterMonitor.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Tools/dotnet-counters/CounterMonitor.cs b/src/Tools/dotnet-counters/CounterMonitor.cs index 696d180b57..beb1e009c4 100644 --- a/src/Tools/dotnet-counters/CounterMonitor.cs +++ b/src/Tools/dotnet-counters/CounterMonitor.cs @@ -22,6 +22,7 @@ using System.Threading; using System.Threading.Tasks; using System.Runtime.InteropServices; +using System.Globalization; namespace Microsoft.Diagnostics.Tools.Counters { @@ -165,7 +166,7 @@ private void HandleCounterRate(TraceEvent obj) MeterInstrumentEventObserved(meterName, instrumentName, obj.TimeStamp); // the value might be an empty string indicating no measurement was provided this collection interval - if (double.TryParse(rateText, out double rate)) + if (double.TryParse(rateText, NumberStyles.Number | NumberStyles.Float, CultureInfo.InvariantCulture, out double rate)) { CounterPayload payload = new RatePayload(meterName, instrumentName, null, unit, tags, rate, _interval, obj.TimeStamp); _renderer.CounterPayloadReceived(payload, _pauseCmdSet); @@ -189,7 +190,7 @@ private void HandleGauge(TraceEvent obj) MeterInstrumentEventObserved(meterName, instrumentName, obj.TimeStamp); // the value might be an empty string indicating no measurement was provided this collection interval - if (double.TryParse(lastValueText, out double lastValue)) + if (double.TryParse(lastValueText, NumberStyles.Number | NumberStyles.Float, CultureInfo.InvariantCulture, out double lastValue)) { CounterPayload payload = new GaugePayload(meterName, instrumentName, null, unit, tags, lastValue, obj.TimeStamp); _renderer.CounterPayloadReceived(payload, _pauseCmdSet); @@ -305,11 +306,11 @@ private static KeyValuePair[] ParseQuantiles(string quantileList { continue; } - if (!double.TryParse(keyValParts[0], out double key)) + if (!double.TryParse(keyValParts[0], NumberStyles.Number | NumberStyles.Float, CultureInfo.InvariantCulture, out double key)) { continue; } - if (!double.TryParse(keyValParts[1], out double val)) + if (!double.TryParse(keyValParts[1], NumberStyles.Number | NumberStyles.Float, CultureInfo.InvariantCulture, out double val)) { continue; }