/// <summary> /// Get an interval histogram, which will include a stable, consistent view of all value counts /// accumulated since the last interval histogram was taken. /// {@link Recorder#GetIntervalHistogram(Histogram histogramToRecycle) /// GetIntervalHistogram(histogramToRecycle)} /// accepts a previously returned interval histogram that can be recycled internally to avoid allocation /// and content copying operations, and is therefore significantly more efficient for repeated use than /// {@link Recorder#GetIntervalHistogram()} and /// {@link Recorder#getIntervalHistogramInto getIntervalHistogramInto()}. The provided /// {@code histogramToRecycle} must /// be either be null or an interval histogram returned by a previous call to /// {@link Recorder#GetIntervalHistogram(Histogram histogramToRecycle) /// GetIntervalHistogram(histogramToRecycle)} or /// {@link Recorder#GetIntervalHistogram()}. /// NOTE: The caller is responsible for not recycling the same returned interval histogram more than once. If /// the same interval histogram instance is recycled more than once, behavior is undefined. /// Calling {@link Recorder#GetIntervalHistogram(Histogram histogramToRecycle) /// GetIntervalHistogram(histogramToRecycle)} will reset the value counts, and start accumulating value /// counts for the next interval /// </summary> /// <param name="histogramToRecycle"> /// a previously returned interval histogram that may be recycled to avoid allocation and /// copy operations. /// </param> /// <returns>a histogram containing the value counts accumulated since the last interval histogram was taken.</returns> public HdrHistogram GetIntervalHistogram(HdrHistogram histogramToRecycle) { lock (syncLock) { if (histogramToRecycle == null) { histogramToRecycle = new InternalConcurrentHistogram( instanceId, inactiveHistogram.getNumberOfSignificantValueDigits()); } // Verify that replacement histogram can validly be used as an inactive histogram replacement: ValidateFitAsReplacementHistogram(histogramToRecycle); try { recordingPhaser.ReaderLock(); inactiveHistogram = histogramToRecycle; PerformIntervalSample(); return(inactiveHistogram); } finally { recordingPhaser.ReaderUnlock(); } } }
private void PerformIntervalSample() { inactiveHistogram.reset(); try { recordingPhaser.ReaderLock(); // Swap active and inactive histograms: var tempHistogram = inactiveHistogram; inactiveHistogram = activeHistogram; activeHistogram = tempHistogram; // Mark end time of previous interval and start time of new one: var now = CurentTimeInMilis(); activeHistogram.setStartTimeStamp(now); inactiveHistogram.setEndTimeStamp(now); // Make sure we are not in the middle of recording a value on the previously active histogram: // Flip phase to make sure no recordings that were in flight pre-flip are still active: recordingPhaser.FlipPhase(500000L /* yield in 0.5 msec units if needed */); } finally { recordingPhaser.ReaderUnlock(); } }
public override AbstractHistogram copyCorrectedForCoordinatedOmission(long expectedIntervalBetweenValueSamples) { var copy = new HdrHistogram(this); copy.addWhileCorrectingForCoordinatedOmission(this, expectedIntervalBetweenValueSamples); return(copy); }
public override AbstractHistogram copy() { var copy = new HdrHistogram(this); copy.add(this); return(copy); }
/// <summary> /// Initializes a new instance of the <see cref="HdrHistogramReservoir" /> class. /// </summary> /// <param name="recorder"> /// Records integer values, and provides stable interval <see cref="Histogram">histogram</see> samples from /// live recorded data without interrupting or stalling active recording of values /// </param> internal HdrHistogramReservoir(Recorder recorder) { _recorder = recorder; _intervalHistogram = recorder.GetIntervalHistogram(); _runningTotals = new HdrHistogram.HdrHistogram(_intervalHistogram.NumberOfSignificantValueDigits); }
private HdrHistogram.HdrHistogram UpdateTotals() { lock (_runningTotals) { _intervalHistogram = _recorder.GetIntervalHistogram(_intervalHistogram); _runningTotals.add(_intervalHistogram); return(_runningTotals.copy() as HdrHistogram.HdrHistogram); } }
private void ValidateFitAsReplacementHistogram(HdrHistogram replacementHistogram) { var replacementConcurrentHistogram = replacementHistogram as InternalConcurrentHistogram; if (replacementConcurrentHistogram != null) { var activeConcurrentHistogram = activeHistogram as InternalConcurrentHistogram; if (activeConcurrentHistogram != null && replacementConcurrentHistogram.ContainingInstanceId == activeConcurrentHistogram.ContainingInstanceId) { return; } } throw new ArgumentException("replacement histogram must have been obtained via a previous" + "GetIntervalHistogram() call from this " + GetType().Name + " instance"); }
/// <summary> /// Construct an auto-resizing Recorder with a lowest discernible value of /// 1 and an auto-adjusting highestTrackableValue. Can auto-resize up to track values up to (long.MaxValue / 2). /// </summary> /// <param name="numberOfSignificantValueDigits"> /// Specifies the precision to use. This is the number of significant decimal /// digits to which the histogram will maintain value resolution and separation. Must be a non-negative integer between /// 0 and 5. /// </param> public Recorder(int numberOfSignificantValueDigits) { activeHistogram = new InternalConcurrentHistogram(instanceId, numberOfSignificantValueDigits); inactiveHistogram = new InternalConcurrentHistogram(instanceId, numberOfSignificantValueDigits); activeHistogram.setStartTimeStamp(CurentTimeInMilis()); }