From c53eed4ac8b3d98e035932be82212e925c343758 Mon Sep 17 00:00:00 2001 From: Todd Grunke Date: Fri, 19 Jan 2024 16:51:47 -0800 Subject: [PATCH] Fix merge issue --- .../{ => Shared}/TimedTelemetryLogBlock.cs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) rename src/VisualStudio/Core/Def/Telemetry/{ => Shared}/TimedTelemetryLogBlock.cs (87%) diff --git a/src/VisualStudio/Core/Def/Telemetry/TimedTelemetryLogBlock.cs b/src/VisualStudio/Core/Def/Telemetry/Shared/TimedTelemetryLogBlock.cs similarity index 87% rename from src/VisualStudio/Core/Def/Telemetry/TimedTelemetryLogBlock.cs rename to src/VisualStudio/Core/Def/Telemetry/Shared/TimedTelemetryLogBlock.cs index 68b52eb12a267..2d4e5dcb45bf9 100644 --- a/src/VisualStudio/Core/Def/Telemetry/TimedTelemetryLogBlock.cs +++ b/src/VisualStudio/Core/Def/Telemetry/Shared/TimedTelemetryLogBlock.cs @@ -15,12 +15,12 @@ namespace Microsoft.CodeAnalysis.Telemetry /// internal sealed class TimedTelemetryLogBlock : IDisposable { +#pragma warning disable IDE0052 // Remove unread private members - Not used in debug builds private readonly KeyValueLogMessage _logMessage; private readonly int _minThresholdMs; -#pragma warning disable IDE0052 // Remove unread private members - Not used in debug builds private readonly ITelemetryLog _telemetryLog; -#pragma warning restore IDE0052 // Remove unread private members private readonly SharedStopwatch _stopwatch; +#pragma warning restore IDE0052 // Remove unread private members public TimedTelemetryLogBlock(KeyValueLogMessage logMessage, int minThresholdMs, ITelemetryLog telemetryLog) { @@ -32,6 +32,11 @@ public TimedTelemetryLogBlock(KeyValueLogMessage logMessage, int minThresholdMs, public void Dispose() { + // Don't add elapsed information in debug bits or while under debugger. +#if !DEBUG + if (Debugger.IsAttached) + return; + var elapsed = (int)_stopwatch.Elapsed.TotalMilliseconds; if (elapsed >= _minThresholdMs) { @@ -42,15 +47,9 @@ public void Dispose() m.AddRange(_logMessage.Properties); }); -#if !DEBUG - // Don't skew telemetry results by logging in debug bits or under debugger. - if (!Debugger.IsAttached) - _telemetryLog.Log(logMessage); -#endif - logMessage.Free(); + _telemetryLog.Log(logMessage); } - - _logMessage.Free(); +#endif } } }