public void CanAppendHistogram() { var histogram1 = Create(DefaultHighestTrackableValue, DefaultSignificantDigits); histogram1.RecordValue(1); histogram1.RecordValue((long.MaxValue / 2) + 1); histogram1.SetTimes(); var histogram2 = Create(DefaultHighestTrackableValue, DefaultSignificantDigits); histogram2.RecordValue(2); histogram2.SetTimes(); byte[] data; using (var writerStream = new MemoryStream()) using (var log = new HistogramLogWriter(writerStream)) { log.Append(histogram1); log.Append(histogram2); data = writerStream.ToArray(); } var actualHistograms = data.ReadHistograms(); Assert.Equal(2, actualHistograms.Length); HistogramAssert.AreValueEqual(histogram1, actualHistograms.First()); HistogramAssert.AreValueEqual(histogram2, actualHistograms.Skip(1).First()); }
private void WriteToDisk(Recorder recorder) { //Sample every second until flagged as completed. var accumulatingHistogram = new LongHistogram(TimeStamp.Hours(1), 3); while (_isCompleted == 0) { Thread.Sleep(1000); var histogram = recorder.GetIntervalHistogram(); accumulatingHistogram.Add(histogram); _logWriter.Append(histogram); Console.WriteLine($"{DateTime.Now:o} Interval.TotalCount = {histogram.TotalCount,10:G}. Accumulated.TotalCount = {accumulatingHistogram.TotalCount,10:G}."); } _logWriter.Dispose(); _outputStream.Dispose(); Console.WriteLine("Log contents"); Console.WriteLine(File.ReadAllText(LogPath)); Console.WriteLine(); Console.WriteLine("Percentile distribution (values reported in milliseconds)"); accumulatingHistogram.OutputPercentileDistribution(Console.Out, outputValueUnitScalingRatio: OutputScalingFactor.TimeStampToMilliseconds); Console.WriteLine("Output thread finishing."); }
static void DocumentResults(LongHistogram accumulatingHistogram, Recorder recorder) { recorder?.RecordValue(GC.GetTotalMemory(false)); var histogram = recorder?.GetIntervalHistogram(); accumulatingHistogram?.Add(histogram); _logWriter?.Append(histogram); RILogManager.Default?.SendDebug($"Accumulated.TotalCount = {accumulatingHistogram.TotalCount,10:G}."); RILogManager.Default?.SendDebug("Mean: " + BytesToString(accumulatingHistogram.GetMean()) + ", StdDev: " + BytesToString(accumulatingHistogram.GetStdDeviation())); }
public void CanAppendHistogram() { var histogram1 = Create(DefaultHighestTrackableValue, DefaultSignificantDigits); histogram1.RecordValue(1); histogram1.RecordValue((long.MaxValue / 2) + 1); histogram1.SetTimes(); var histogram2 = Create(DefaultHighestTrackableValue, DefaultSignificantDigits); histogram2.RecordValue(2); histogram2.SetTimes(); byte[] data; using (var writerStream = new MemoryStream()) using (var log = new HistogramLogWriter(writerStream)) { log.Append(histogram1); log.Append(histogram2); data = writerStream.ToArray(); } var actualHistograms = data.ReadHistograms(); Assert.AreEqual(2, actualHistograms.Length); HistogramAssert.AreValueEqual(histogram1, actualHistograms.First()); HistogramAssert.AreValueEqual(histogram2, actualHistograms.Skip(1).First()); }