From 7e77fe7a1046944aa5f68b325a1513e2753b686b Mon Sep 17 00:00:00 2001 From: Blake Fitzgerald Date: Wed, 6 Jul 2022 10:32:11 -0500 Subject: [PATCH 1/3] Changed StopwatchToTimeSpanTicks to double to improve stopwatch resolution and prevent exceptions when Stopwatch.Frequency < TimeSpan.TicksPerSecond. --- src/SerilogTimings/Operation.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SerilogTimings/Operation.cs b/src/SerilogTimings/Operation.cs index 7899b77..537af01 100644 --- a/src/SerilogTimings/Operation.cs +++ b/src/SerilogTimings/Operation.cs @@ -55,7 +55,7 @@ public enum Properties }; const string OutcomeCompleted = "completed", OutcomeAbandoned = "abandoned"; - static readonly long StopwatchToTimeSpanTicks = Stopwatch.Frequency / TimeSpan.TicksPerSecond; + static readonly double StopwatchToTimeSpanTicks = (double)Stopwatch.Frequency / TimeSpan.TicksPerSecond; ILogger _target; readonly string _messageTemplate; @@ -87,7 +87,7 @@ internal Operation(ILogger target, string messageTemplate, object[] args, static long GetTimestamp() { - return Stopwatch.GetTimestamp() / StopwatchToTimeSpanTicks; + return unchecked((long)(Stopwatch.GetTimestamp() / StopwatchToTimeSpanTicks)); } /// From f2154d5e3a3d7d9b63440e087d18744385a8310a Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Sat, 9 Jul 2022 07:45:42 +1000 Subject: [PATCH 2/3] Dev version bump [skip ci] --- src/SerilogTimings/SerilogTimings.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SerilogTimings/SerilogTimings.csproj b/src/SerilogTimings/SerilogTimings.csproj index f9c57f4..6eecc18 100644 --- a/src/SerilogTimings/SerilogTimings.csproj +++ b/src/SerilogTimings/SerilogTimings.csproj @@ -2,7 +2,7 @@ Extend Serilog with timed operations. - 3.0.0 + 3.0.1 nblumhardt;SerilogTimings Contributors netstandard2.0;net6.0 true From 4cbddadbdf6a931b64f74d369a855b4d3125ee2f Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Sat, 9 Jul 2022 07:57:05 +1000 Subject: [PATCH 3/3] Loosen up heuristic timing test to deal with very slow CI machines --- src/SerilogTimings/CompletionBehaviour.cs | 2 +- src/SerilogTimings/Extensions/LoggerOperationExtensions.cs | 1 - src/SerilogTimings/Operation.cs | 4 ++-- test/SerilogTimings.Tests/OperationTests.cs | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/SerilogTimings/CompletionBehaviour.cs b/src/SerilogTimings/CompletionBehaviour.cs index 5e3e354..3135f9e 100644 --- a/src/SerilogTimings/CompletionBehaviour.cs +++ b/src/SerilogTimings/CompletionBehaviour.cs @@ -20,4 +20,4 @@ enum CompletionBehaviour Complete, Silent } -} \ No newline at end of file +} diff --git a/src/SerilogTimings/Extensions/LoggerOperationExtensions.cs b/src/SerilogTimings/Extensions/LoggerOperationExtensions.cs index 5c31221..a4bd189 100644 --- a/src/SerilogTimings/Extensions/LoggerOperationExtensions.cs +++ b/src/SerilogTimings/Extensions/LoggerOperationExtensions.cs @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -using System; using Serilog; using Serilog.Events; using SerilogTimings.Configuration; diff --git a/src/SerilogTimings/Operation.cs b/src/SerilogTimings/Operation.cs index 537af01..ef3227e 100644 --- a/src/SerilogTimings/Operation.cs +++ b/src/SerilogTimings/Operation.cs @@ -63,11 +63,11 @@ public enum Properties readonly long _start; long? _stop; - IDisposable _popContext; + readonly IDisposable _popContext; CompletionBehaviour _completionBehaviour; readonly LogEventLevel _completionLevel; readonly LogEventLevel _abandonmentLevel; - private readonly TimeSpan? _warningThreshold; + readonly TimeSpan? _warningThreshold; Exception? _exception; internal Operation(ILogger target, string messageTemplate, object[] args, diff --git a/test/SerilogTimings.Tests/OperationTests.cs b/test/SerilogTimings.Tests/OperationTests.cs index b4937a6..8f5648a 100644 --- a/test/SerilogTimings.Tests/OperationTests.cs +++ b/test/SerilogTimings.Tests/OperationTests.cs @@ -246,7 +246,7 @@ public async Task TimingWithinOrderOfMagnitude(int delay) op.Dispose(); var elapsed = GetElapsedMilliseconds(logger); - Assert.InRange(elapsed, delay * 0.5, delay * 5); + Assert.InRange(elapsed, delay * 0.2, delay * 8); } [Fact]