public void Reset(CountdownEvent globalSignal, ManualResetEvent signal, HistogramBase histogram) { _globalSignal = globalSignal; _signal = signal; _histogram = histogram; _counter = 0; }
/// <summary> /// The constructor for the <see cref="LogarithmicEnumerator"/> /// </summary> /// <param name="histogram">The histogram this iterator will operate on</param> /// <param name="valueUnitsInFirstBucket">the size (in value units) of the first value bucket step</param> /// <param name="logBase">the multiplier by which the bucket size is expanded in each iteration step.</param> public LogarithmicEnumerator(HistogramBase histogram, int valueUnitsInFirstBucket, double logBase) : base(histogram) { _logBase = logBase; _nextValueReportingLevel = valueUnitsInFirstBucket; _nextValueReportingLevelLowestEquivalent = histogram.LowestEquivalentValue(_nextValueReportingLevel); }
/////////////////////////////////////////////////////////////////////////////////////////////// public void Run(Stopwatch stopwatch, HistogramBase histogram) { var globalSignal = new CountdownEvent(3); var signal = new ManualResetEvent(false); _pinger.Reset(globalSignal, signal, histogram); _ponger.Reset(globalSignal); var processorTask1 = _pongProcessor.Start(); var processorTask2 = _pingProcessor.Start(); _pongProcessor.WaitUntilStarted(TimeSpan.FromSeconds(5)); _pingProcessor.WaitUntilStarted(TimeSpan.FromSeconds(5)); globalSignal.Signal(); globalSignal.Wait(); stopwatch.Start(); // running here signal.WaitOne(); stopwatch.Stop(); _pingProcessor.Halt(); _pongProcessor.Halt(); Task.WaitAll(processorTask1, processorTask2); }
protected override void RecordLoop(HistogramBase histogram, long loopCount) { for (long i = 0; i<loopCount; i++) { histogram.Record(() => base.Md5HashIncrementingNumber()); } }
private static HistogramBase CompressedEncodeDecode(HistogramBase source) { var targetBuffer = ByteBuffer.Allocate(source.GetNeededByteBufferCapacity()); source.EncodeIntoCompressedByteBuffer(targetBuffer); targetBuffer.Position = 0; return HistogramEncoding.DecodeFromCompressedByteBuffer(targetBuffer, 0); }
static HistogramDataAccessTest() { LongHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits); ScaledHistogram = new LongHistogram(1000, HighestTrackableValue * 512, NumberOfSignificantValueDigits); RawHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits); var scaledRawHistogram = new LongHistogram(1000, HighestTrackableValue * 512, NumberOfSignificantValueDigits); // Log hypothetical scenario: 100 seconds of "perfect" 1msec results, sampled // 100 times per second (10,000 results), followed by a 100 second pause with // a single (100 second) recorded result. Recording is done indicating an expected // interval between samples of 10 msec: for (var i = 0; i < 10000; i++) { LongHistogram.RecordValueWithExpectedInterval(1000 /* 1 msec */, 10000 /* 10 msec expected interval */); ScaledHistogram.RecordValueWithExpectedInterval(1000 * 512 /* 1 msec */, 10000 * 512 /* 10 msec expected interval */); RawHistogram.RecordValue(1000 /* 1 msec */); scaledRawHistogram.RecordValue(1000 * 512 /* 1 msec */); } LongHistogram.RecordValueWithExpectedInterval(100000000L /* 100 sec */, 10000 /* 10 msec expected interval */); ScaledHistogram.RecordValueWithExpectedInterval(100000000L * 512 /* 100 sec */, 10000 * 512 /* 10 msec expected interval */); RawHistogram.RecordValue(100000000L /* 100 sec */); scaledRawHistogram.RecordValue(100000000L * 512 /* 100 sec */); PostCorrectedHistogram = RawHistogram.CopyCorrectedForCoordinatedOmission(10000 /* 10 msec expected interval */); PostCorrectedScaledHistogram = scaledRawHistogram.CopyCorrectedForCoordinatedOmission(10000 * 512 /* 10 msec expected interval */); }
private void UnsafeRefresh(long nowTicks, bool empty) { // don't recycle the current histogram as it is being used by the cached snapshot _intervalHistogram = _recorder.GetIntervalHistogram(); Interlocked.Exchange(ref _lastRefreshTicks, nowTicks); _cachedSnapshot = BuildSnapshot(empty); }
private static void RecordLoop(HistogramBase histogram, long loopCount) { for (long i = 0; i < loopCount; i++) { histogram.RecordValue(TestValueLevel + (i & 0x8000)); } }
protected override void RecordLoop(HistogramBase histogram, long loopCount) { for (long i = 0; i < loopCount; i++) { histogram.Record(IncrementNumber); } }
protected override void RecordLoop(HistogramBase histogram, long loopCount) { for (long i = 0; i < loopCount; i++) { histogram.Record(() => base.Md5HashIncrementingNumber()); } }
public void CanReadv1Logs_Skip_PreStart(string logPath, int skip, int take, int expectedHistogramCount, int expectedCombinedValueCount, int expectedCombined999, long expectedCombinedMaxLength, double expectedStartTime) { var readerStream = GetEmbeddedFileStream(logPath); var reader = new HistogramLogReader(readerStream); int histogramCount = 0; long totalCount = 0; HistogramBase accumulatedHistogram = Create(OneHourOfNanoseconds, DefaultSignificantDigits); var histograms = reader.ReadHistograms() .Where(h => h.StartTimeStamp >= reader.GetStartTime().MillisecondsSinceUnixEpoch()) .Skip(skip) .Take(take); foreach (var histogram in histograms) { histogramCount++; totalCount += histogram.TotalCount; accumulatedHistogram.Add(histogram); } Assert.Equal(expectedHistogramCount, histogramCount); Assert.Equal(expectedCombinedValueCount, totalCount); Assert.Equal(expectedCombined999, accumulatedHistogram.GetValueAtPercentile(99.9)); Assert.Equal(expectedCombinedMaxLength, accumulatedHistogram.GetMaxValue()); Assert.Equal(expectedStartTime, reader.GetStartTime().SecondsSinceUnixEpoch()); }
static HistogramDataAccessTest() { LongHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits); ScaledHistogram = new LongHistogram(1000, HighestTrackableValue * 512, NumberOfSignificantValueDigits); RawHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits); var scaledRawHistogram = new LongHistogram(1000, HighestTrackableValue * 512, NumberOfSignificantValueDigits); // Log hypothetical scenario: 100 seconds of "perfect" 1msec results, sampled // 100 times per second (10,000 results), followed by a 100 second pause with // a single (100 second) recorded result. Recording is done indicating an expected // interval between samples of 10 msec: for (var i = 0; i < 10000; i++) { LongHistogram.RecordValueWithExpectedInterval(1000 /* 1 msec */, 10000 /* 10 msec expected interval */); ScaledHistogram.RecordValueWithExpectedInterval(1000 * 512 /* 1 msec */, 10000 * 512 /* 10 msec expected interval */); RawHistogram.RecordValue(1000 /* 1 msec */); scaledRawHistogram.RecordValue(1000 * 512/* 1 msec */); } LongHistogram.RecordValueWithExpectedInterval(100000000L /* 100 sec */, 10000 /* 10 msec expected interval */); ScaledHistogram.RecordValueWithExpectedInterval(100000000L * 512 /* 100 sec */, 10000 * 512 /* 10 msec expected interval */); RawHistogram.RecordValue(100000000L /* 100 sec */); scaledRawHistogram.RecordValue(100000000L * 512 /* 100 sec */); PostCorrectedHistogram = RawHistogram.CopyCorrectedForCoordinatedOmission(10000 /* 10 msec expected interval */); PostCorrectedScaledHistogram = scaledRawHistogram.CopyCorrectedForCoordinatedOmission(10000 * 512 /* 10 msec expected interval */); }
public void Reset(CountdownEvent startCountdown, ManualResetEvent completedSignal, HistogramBase histogram) { _startCountdown = startCountdown; _completedSignal = completedSignal; _histogram = histogram; _counter = 0; }
private static void LoadHistogram(HistogramBase histogram) { for (int i = 0; i < 10000; i += 1000) { histogram.RecordValue(i); } }
/////////////////////////////////////////////////////////////////////////////////////////////// public void Run(Stopwatch stopwatch, HistogramBase histogram) { var startCountdown = new CountdownEvent(3); var completedSignal = new ManualResetEvent(false); _pinger.Reset(startCountdown, completedSignal, histogram); _ponger.Reset(startCountdown); var processorTask1 = _pongProcessor.Start(); var processorTask2 = _pingProcessor.Start(); _pongProcessor.WaitUntilStarted(TimeSpan.FromSeconds(5)); _pingProcessor.WaitUntilStarted(TimeSpan.FromSeconds(5)); startCountdown.Signal(); startCountdown.Wait(); stopwatch.Start(); completedSignal.WaitOne(); stopwatch.Stop(); _pingProcessor.Halt(); _pongProcessor.Halt(); Task.WaitAll(processorTask1, processorTask2); }
protected override void RecordLoop(HistogramBase histogram, long loopCount) { Action incrementNumber = IncrementNumber; for (long i = 0; i<loopCount; i++) { histogram.Record(incrementNumber); } }
public static void SetTimes(this HistogramBase histogram) { var startTimeWritten = DateTime.Now; var endTimeWritten = startTimeWritten.AddMinutes(30); histogram.StartTimeStamp = startTimeWritten.MillisecondsSinceUnixEpoch(); histogram.EndTimeStamp = endTimeWritten.MillisecondsSinceUnixEpoch(); }
public Histogram(long highestTrackableValueInTicks = -1) { if (highestTrackableValueInTicks < 0) { highestTrackableValueInTicks = DefaultHighestTrackableInTicks; } _hdrHistogram = CreateHdrHistogram(highestTrackableValueInTicks); }
private static HistogramBase CompressedEncodeDecode(HistogramBase source) { var targetBuffer = ByteBuffer.Allocate(source.GetNeededByteBufferCapacity()); source.EncodeIntoCompressedByteBuffer(targetBuffer); targetBuffer.Position = 0; return(HistogramEncoding.DecodeFromCompressedByteBuffer(targetBuffer, 0)); }
private HistogramBase UpdateTotals() { lock (_runningTotals) { _intervalHistogram = _recorder.GetIntervalHistogram(_intervalHistogram); _runningTotals.Add(_intervalHistogram); return(_runningTotals.Copy()); } }
protected override void RecordLoop(HistogramBase histogram, long loopCount) { for (long i = 0; i<loopCount; i++) { long startTimestamp = Stopwatch.GetTimestamp(); var result = base.Md5HashIncrementingNumber(); long ticks = Stopwatch.GetTimestamp() - startTimestamp; histogram.RecordValue(ticks); } }
protected override void RecordLoop(HistogramBase histogram, long loopCount) { for (long i = 0; i < loopCount; i++) { long startTimestamp = Stopwatch.GetTimestamp(); base.IncrementNumber(); long ticks = Stopwatch.GetTimestamp() - startTimestamp; histogram.RecordValue(ticks); } }
/// <summary> /// Initializes a new instance of the <see cref="HdrSnapshot" /> class. /// </summary> /// <param name="histogram">The histogram.</param> /// <param name="minValue">The minimum value.</param> /// <param name="minUserValue">The minimum user value.</param> /// <param name="maxValue">The maximum value.</param> /// <param name="maxUserValue">The maximum user value.</param> public HdrSnapshot(HistogramBase histogram, long minValue, string minUserValue, long maxValue, string maxUserValue) { _histogram = histogram; Min = !string.IsNullOrWhiteSpace(minUserValue) ? minValue : histogram.HighestEquivalentValue(histogram.RecordedValues().Select(hiv => hiv.ValueIteratedTo).FirstOrDefault()); MinUserValue = minUserValue; Max = !string.IsNullOrWhiteSpace(maxUserValue) ? maxValue : _histogram.GetMaxValue(); MaxUserValue = maxUserValue; }
private void CreateAndAdd(HistogramBase source) { source.RecordValueWithCount(1, 100); source.RecordValueWithCount(int.MaxValue - 1, 1000); var target = Create(source.LowestTrackableValue, source.HighestTrackableValue, source.NumberOfSignificantValueDigits); target.Add(source); HistogramAssert.AreValueEqual(source, target); }
private static long TruncateValue(long value, HistogramBase histogram) { if (value > histogram.HighestTrackableValue) { return(histogram.HighestTrackableValue); } else { return(value); } }
public static byte[] WriteLog(this HistogramBase histogram) { var startTimeWritten = histogram.StartTimeStamp.ToDateFromMillisecondsSinceEpoch(); byte[] data; using (var writerStream = new MemoryStream()) { HistogramLogWriter.Write(writerStream, startTimeWritten, histogram); data = writerStream.ToArray(); } return(data); }
public static void AreValueEqual(HistogramBase expected, HistogramBase actual) { Assert.AreEqual(expected.TotalCount, actual.TotalCount); Assert.AreEqual(expected.StartTimeStamp, actual.StartTimeStamp); Assert.AreEqual(expected.EndTimeStamp, actual.EndTimeStamp); Assert.AreEqual(expected.LowestTrackableValue, actual.LowestTrackableValue); Assert.AreEqual(expected.HighestTrackableValue, actual.HighestTrackableValue); Assert.AreEqual(expected.NumberOfSignificantValueDigits, actual.NumberOfSignificantValueDigits); var expectedValues = expected.AllValues().ToArray(); var actualValues = actual.AllValues().ToArray(); CollectionAssert.AreEqual(expectedValues, actualValues, HistogramIterationValueComparer.Instance); }
public static void AreValueEqual(HistogramBase expected, HistogramBase actual) { Assert.AreEqual(expected.TotalCount, actual.TotalCount, "TotalCount property is not equal."); Assert.AreEqual(expected.Tag, actual.Tag, "Tag property is not equal."); Assert.AreEqual(expected.StartTimeStamp, actual.StartTimeStamp, "StartTimeStamp property is not equal."); Assert.AreEqual(expected.EndTimeStamp, actual.EndTimeStamp, "EndTimeStamp property is not equal."); Assert.AreEqual(expected.LowestTrackableValue, actual.LowestTrackableValue, "LowestTrackableValue property is not equal."); Assert.AreEqual(expected.HighestTrackableValue, actual.HighestTrackableValue, "HighestTrackableValue property is not equal."); Assert.AreEqual(expected.NumberOfSignificantValueDigits, actual.NumberOfSignificantValueDigits, "NumberOfSignificantValueDigits property is not equal."); var expectedValues = expected.AllValues().ToArray(); var actualValues = actual.AllValues().ToArray(); CollectionAssert.AreEqual(expectedValues, actualValues, HistogramIterationValueComparer.Instance, "Recorded values differ"); }
private static void AssertEqual(HistogramBase expectedHistogram, HistogramBase actualHistogram) { Assert.AreEqual(expectedHistogram, actualHistogram); Assert.AreEqual( expectedHistogram.GetCountAtValue(TestValueLevel), actualHistogram.GetCountAtValue(TestValueLevel)); Assert.AreEqual( expectedHistogram.GetCountAtValue(TestValueLevel * 10), actualHistogram.GetCountAtValue(TestValueLevel * 10)); Assert.AreEqual( expectedHistogram.TotalCount, actualHistogram.TotalCount); }
public static void AreEqual(HistogramBase expected, HistogramBase actual) { Assert.AreEqual(expected.GetType(), actual.GetType()); Assert.AreEqual(expected.TotalCount, actual.TotalCount); Assert.AreEqual(expected.StartTimeStamp, actual.StartTimeStamp); Assert.AreEqual(expected.EndTimeStamp, actual.EndTimeStamp); Assert.AreEqual(expected.LowestTrackableValue, actual.LowestTrackableValue); Assert.AreEqual(expected.HighestTrackableValue, actual.HighestTrackableValue); Assert.AreEqual(expected.NumberOfSignificantValueDigits, actual.NumberOfSignificantValueDigits); var expectedValues = expected.AllValues().ToArray(); var actualValues = actual.AllValues().ToArray(); CollectionAssert.AreEqual(expectedValues, actualValues, HistogramIterationValueComparer.Instance); }
public static void AreValueEqual(HistogramBase expected, HistogramBase actual) { expected.TotalCount.Should().Be(actual.TotalCount, "TotalCount property is not equal."); expected.Tag.Should().Be(actual.Tag, "Tag property is not equal."); expected.StartTimeStamp.Should().Be(actual.StartTimeStamp, "StartTimeStamp property is not equal."); expected.EndTimeStamp.Should().Be(actual.EndTimeStamp, "EndTimeStamp property is not equal."); expected.LowestTrackableValue.Should().Be(actual.LowestTrackableValue, "LowestTrackableValue property is not equal."); expected.HighestTrackableValue.Should().Be(actual.HighestTrackableValue, "HighestTrackableValue property is not equal."); expected.NumberOfSignificantValueDigits.Should().Be(actual.NumberOfSignificantValueDigits, "NumberOfSignificantValueDigits property is not equal."); var expectedValues = expected.AllValues().ToArray(); var actualValues = actual.AllValues().ToArray(); CollectionEquals(expectedValues, actualValues); }
public void Run(Stopwatch stopwatch, HistogramBase histogram) { var globalSignal = new CountdownEvent(3); _pinger.Reset(globalSignal, histogram); _ponger.Reset(globalSignal); var pingerTask = _pinger.Start(); var pongerTask = _ponger.Start(); globalSignal.Signal(); globalSignal.Wait(); stopwatch.Start(); pingerTask.Wait(); pongerTask.Wait(); stopwatch.Stop(); }
/// <summary> /// Initializes a new instance of the <see cref="HdrHistogramReservoir" /> class. /// </summary> public HdrHistogramReservoir(long lowestTrackableValue, long highestTrackableValue, int numberOfSignificantValueDigits) { _highestTrackableValue = highestTrackableValue; var recorder = HistogramFactory .With64BitBucketSize() .WithValuesFrom(lowestTrackableValue) .WithValuesUpTo(highestTrackableValue) .WithPrecisionOf(numberOfSignificantValueDigits) .WithThreadSafeWrites() .WithThreadSafeReads() .Create(); _recorder = recorder; _intervalHistogram = recorder.GetIntervalHistogram(); _runningTotals = new LongHistogram(lowestTrackableValue, highestTrackableValue, _intervalHistogram.NumberOfSignificantValueDigits); }
/// <summary> /// Initializes a new instance of the <see cref="HdrHistogramReservoir" /> class. /// </summary> public HdrHistogramReservoir( long lowestTrackableValue, long highestTrackableValue, int numberOfSignificantValueDigits, long refreshIntervalMilliseconds) { _highestTrackableValue = highestTrackableValue; _refreshIntervalTicks = TimeSpan.FromMilliseconds(refreshIntervalMilliseconds).Ticks; var recorder = HistogramFactory .With64BitBucketSize() .WithValuesFrom(lowestTrackableValue) .WithValuesUpTo(highestTrackableValue) .WithPrecisionOf(numberOfSignificantValueDigits) .WithThreadSafeWrites() .WithThreadSafeReads() .Create(); _recorder = recorder; _intervalHistogram = recorder.GetIntervalHistogram(); UnsafeRefresh(DateTime.UtcNow.Ticks, true); }
protected AbstractHistogramEnumerator(HistogramBase histogram) { SourceHistogram = histogram; _savedHistogramTotalRawCount = histogram.TotalCount; ArrayTotalCount = histogram.TotalCount; CurrentBucketIndex = 0; CurrentSubBucketIndex = 0; _currentValueAtIndex = 0; _nextBucketIndex = 0; _nextSubBucketIndex = 1; _nextValueAtIndex = 1; _prevValueIteratedTo = 0; _totalCountToPrevIndex = 0; TotalCountToCurrentIndex = 0; _totalValueToCurrentIndex = 0; CountAtThisValue = 0; _freshSubBucket = true; _currentIterationValue = new HistogramIterationValue(); }
public void WriteFooter(HistogramBase histogram) { // Calculate and output mean and std. deviation. // Note: mean/std. deviation numbers are very often completely irrelevant when // data is extremely non-normal in distribution (e.g. in cases of strong multi-modal // response time distribution associated with GC pauses). However, reporting these numbers // can be very useful for contrasting with the detailed percentile distribution // reported by outputPercentileDistribution(). It is not at all surprising to find // percentile distributions where results fall many tens or even hundreds of standard // deviations away from the mean - such results simply indicate that the data sampled // exhibits a very non-normal distribution, highlighting situations for which the std. // deviation metric is a useless indicator. var mean = histogram.GetMean() / _outputValueUnitScalingRatio; var stdDeviation = histogram.GetStdDeviation() / _outputValueUnitScalingRatio; _printStream.Write(_footerLine1FormatString, mean, stdDeviation); _printStream.Write(_footerLine2FormatString, histogram.GetMaxValue() / _outputValueUnitScalingRatio, histogram.TotalCount); _printStream.Write(_footerLine3FormatString, histogram.BucketCount, histogram.SubBucketCount); }
public void Run(Stopwatch stopwatch, HistogramBase histogram) { var cancellationToken = new CancellationTokenSource(); var signal = new ManualResetEvent(false); var globalSignal = new CountdownEvent(3); _pinger.Reset(globalSignal, signal, histogram); _ponger.Reset(globalSignal, cancellationToken.Token); _executor.Execute(_pinger.Run); _executor.Execute(_ponger.Run); globalSignal.Signal(); globalSignal.Wait(); stopwatch.Start(); signal.WaitOne(); stopwatch.Stop(); cancellationToken.Cancel(); }
/// <summary> /// The constructor for the <see cref="PercentileEnumerator"/> /// </summary> /// <param name="histogram">The histogram this iterator will operate on</param> /// <param name="percentileTicksPerHalfDistance">The number of iteration steps per half-distance to 100%.</param> public PercentileEnumerator(HistogramBase histogram, int percentileTicksPerHalfDistance) : base(histogram) { _percentileTicksPerHalfDistance = percentileTicksPerHalfDistance; _percentileLevelToIterateTo = 0.0; _reachedLastRecordedValue = false; }
public static void AreEqual(HistogramBase expected, HistogramBase actual) { Assert.AreEqual(expected.GetType(), actual.GetType()); AreValueEqual(expected, actual); }
private static void RecordLoop(HistogramBase histogram, long loopCount) { for (long i = 0; i < loopCount; i++) histogram.RecordValue(TestValueLevel + (i & 0x8000)); }
/// <summary> /// Constructor for the <see cref="AllValuesEnumerator"/>. /// </summary> /// <param name="histogram">The histogram this iterator will operate on</param> public AllValuesEnumerator(HistogramBase histogram):base(histogram) { _visitedSubBucketIndex = -1; _visitedBucketIndex = -1; }
public void WriteFooter(HistogramBase histogram) { //No op }
protected abstract void RecordLoop(HistogramBase histogram, long loopCount);