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());
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            List <Thread> threadList = new List <Thread>();

            for (int i = 0; i < threadCount; i++)
            {
                Thread t = new Thread(WorkerJob);
                t.Start();
                threadList.Add(t);
            }

            foreach (Thread t in threadList)
            {
                t.Join();
            }

            Console.WriteLine("Total operations: " + throughput);
            double[] percentiles = new double[] { 50, 90, 95, 99, 99.9, 99.99, 100 };
            foreach (double percentile in percentiles)
            {
                Console.WriteLine($"{percentile} : {histogram.GetValueAtPercentile(percentile)}");
            }

            Console.WriteLine("Results:");

            // Write the results to console
            histogram.OutputPercentileDistribution(
                Console.Out,
                percentileTicksPerHalfDistance: 3,
                outputValueUnitScalingRatio: OutputScalingFactor.TimeStampToMilliseconds);

            // Save the results to a file
            using (StreamWriter writer = new StreamWriter("HistogramResults.hgrm"))
            {
                histogram.OutputPercentileDistribution(
                    writer,
                    percentileTicksPerHalfDistance: 3,
                    outputValueUnitScalingRatio: OutputScalingFactor.TimeStampToMilliseconds);
            }

            Console.WriteLine();
            Console.WriteLine("These results have been saved to HistogramResults.hgrm");
        }
 public void TestScalingEquivalence()
 {
     Assert.AreEqual(
         LongHistogram.GetMean() * 512,
         ScaledHistogram.GetMean(), ScaledHistogram.GetMean() * 0.000001,
         "averages should be equivalent");
     Assert.AreEqual(
         LongHistogram.TotalCount,
         ScaledHistogram.TotalCount,
         "total count should be the same");
     Assert.AreEqual(
         LongHistogram.LowestEquivalentValue(LongHistogram.GetValueAtPercentile(99.0)) * 512,
         ScaledHistogram.LowestEquivalentValue(ScaledHistogram.GetValueAtPercentile(99.0)),
         "99%'iles should be equivalent");
     Assert.AreEqual(
         ScaledHistogram.HighestEquivalentValue(LongHistogram.GetMaxValue() * 512),
         ScaledHistogram.GetMaxValue(),
         "Max should be equivalent for scaled data");
     // Same for post-corrected:
     Assert.AreEqual(
         LongHistogram.GetMean() * 512,
         ScaledHistogram.GetMean(), ScaledHistogram.GetMean() * 0.000001,
         "averages should be equivalent");
     Assert.AreEqual(
         PostCorrectedHistogram.TotalCount,
         PostCorrectedScaledHistogram.TotalCount,
         "total count should be the same");
     Assert.AreEqual(
         PostCorrectedHistogram.LowestEquivalentValue(PostCorrectedHistogram.GetValueAtPercentile(99.0)) * 512,
         PostCorrectedScaledHistogram.LowestEquivalentValue(PostCorrectedScaledHistogram.GetValueAtPercentile(99.0)),
         "99%'iles should be equivalent");
     Assert.AreEqual(
         PostCorrectedScaledHistogram.HighestEquivalentValue(PostCorrectedHistogram.GetMaxValue() * 512),
         PostCorrectedScaledHistogram.GetMaxValue(),
         "Max should be equivalent for post-corrected data");
 }
Ejemplo n.º 4
0
 /// <inheritdoc cref="IReservoirSnapshot" />
 public double GetValue(double quantile)
 {
     return(_histogram.GetValueAtPercentile(quantile * 100));
 }
Ejemplo n.º 5
0
 public long GetValueAtPercentile(double percentile)
 {
     return(_hdrHistogram.GetValueAtPercentile(percentile));
 }