From 0d4b8b51816a238fa67c092674d99a75d9622a4f Mon Sep 17 00:00:00 2001 From: pauliusnorkus Date: Sun, 22 Nov 2015 16:50:39 +0200 Subject: [PATCH] resetting reservoir's count only when snapshot was created --- Src/Metrics/Sampling/SlidingWindowReservoir.cs | 10 +++++----- Src/Metrics/Sampling/UniformReservoir.cs | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Src/Metrics/Sampling/SlidingWindowReservoir.cs b/Src/Metrics/Sampling/SlidingWindowReservoir.cs index 3d8f11f7..f44deff7 100644 --- a/Src/Metrics/Sampling/SlidingWindowReservoir.cs +++ b/Src/Metrics/Sampling/SlidingWindowReservoir.cs @@ -45,16 +45,16 @@ public Snapshot GetSnapshot(bool resetReservoir = false) UserValueWrapper[] values = new UserValueWrapper[size]; Array.Copy(this.values, values, size); + Array.Sort(values, UserValueWrapper.Comparer); + var minValue = values[0].UserValue; + var maxValue = values[size - 1].UserValue; + var snapshot = new UniformSnapshot(this.count.Value, values.Select(v => v.Value), valuesAreSorted: true, minUserValue: minValue, maxUserValue: maxValue); if (resetReservoir) { Array.Clear(this.values, 0, values.Length); count.SetValue(0L); } - - Array.Sort(values, UserValueWrapper.Comparer); - var minValue = values[0].UserValue; - var maxValue = values[size - 1].UserValue; - return new UniformSnapshot(this.count.Value, values.Select(v => v.Value), valuesAreSorted: true, minUserValue: minValue, maxUserValue: maxValue); + return snapshot; } } } diff --git a/Src/Metrics/Sampling/UniformReservoir.cs b/Src/Metrics/Sampling/UniformReservoir.cs index 0ad04436..3db5bf95 100644 --- a/Src/Metrics/Sampling/UniformReservoir.cs +++ b/Src/Metrics/Sampling/UniformReservoir.cs @@ -43,15 +43,15 @@ public Snapshot GetSnapshot(bool resetReservoir = false) UserValueWrapper[] values = new UserValueWrapper[size]; Array.Copy(this.values, values, size); + Array.Sort(values, UserValueWrapper.Comparer); + var minValue = values[0].UserValue; + var maxValue = values[size - 1].UserValue; + var snapshot = new UniformSnapshot(this.count.Value, values.Select(v => v.Value), valuesAreSorted: true, minUserValue: minValue, maxUserValue: maxValue); if (resetReservoir) { count.SetValue(0L); } - - Array.Sort(values, UserValueWrapper.Comparer); - var minValue = values[0].UserValue; - var maxValue = values[size - 1].UserValue; - return new UniformSnapshot(this.count.Value, values.Select(v => v.Value), valuesAreSorted: true, minUserValue: minValue, maxUserValue: maxValue); + return snapshot; } public void Update(long value, string userValue = null)