public void testScalingEquivalence()
 {
     Assert.assertEquals("averages should be equivalent",
                         histogram.getMean() * 512,
                         scaledHistogram.getMean(), scaledHistogram.getMean() * 0.000001);
     Assert.assertEquals("total count should be the same",
                         histogram.getTotalCount(),
                         scaledHistogram.getTotalCount());
     Assert.assertEquals("99%'iles should be equivalent",
                         histogram.lowestEquivalentValue(histogram.getValueAtPercentile(99.0)) * 512,
                         scaledHistogram.lowestEquivalentValue(scaledHistogram.getValueAtPercentile(99.0)));
     Assert.assertEquals("Max should be equivalent",
                         histogram.getMaxValue() * 512,
                         scaledHistogram.getMaxValue());
     // Same for post-corrected:
     Assert.assertEquals("averages should be equivalent",
                         histogram.getMean() * 512,
                         scaledHistogram.getMean(), scaledHistogram.getMean() * 0.000001);
     Assert.assertEquals("total count should be the same",
                         postCorrectedHistogram.getTotalCount(),
                         postCorrectedScaledHistogram.getTotalCount());
     Assert.assertEquals("99%'iles should be equivalent",
                         postCorrectedHistogram.lowestEquivalentValue(postCorrectedHistogram.getValueAtPercentile(99.0)) * 512,
                         postCorrectedScaledHistogram.lowestEquivalentValue(postCorrectedScaledHistogram.getValueAtPercentile(99.0)));
     Assert.assertEquals("Max should be equivalent",
                         postCorrectedHistogram.getMaxValue() * 512,
                         postCorrectedScaledHistogram.getMaxValue());
 }
Example #2
0
        /**
         * Returns true if the iteration has more elements. (In other words, returns true if next would return an
         * element rather than throwing an exception.)
         *
         * @return true if the iterator has more elements.
         */

        public override bool hasNext()
        {
            if (Histogram.getTotalCount() != SavedHistogramTotalRawCount)
            {
                throw new InvalidOperationException("ConcurrentModificationException");
            }
            return(TotalCountToCurrentIndex < ArrayTotalCount);
        }
        public void testPreVsPostCorrectionValues()
        {
            // Loop both ways (one would be enough, but good practice just for fun:

            Assert.assertEquals("pre and post corrected count totals ",
                                histogram.getTotalCount(), postCorrectedHistogram.getTotalCount());

            // The following comparison loops would have worked in a perfect accuracy world, but since post
            // correction is done based on the value extracted from the bucket, and the during-recording is done
            // based on the actual (not pixelized) value, there will be subtle differences due to roundoffs:

            //        for (HistogramIterationValue v : histogram.getHistogramData().allValues()) {
            //            long preCorrectedCount = v.getCountAtValueIteratedTo();
            //            long postCorrectedCount = postCorrectedHistogram.getHistogramData().getCountAtValue(v.getValueIteratedTo());
            //            Assert.assertEquals("pre and post corrected count at value " + v.getValueIteratedTo(),
            //                    preCorrectedCount, postCorrectedCount);
            //        }
            //
            //        for (HistogramIterationValue v : postCorrectedHistogram.getHistogramData().allValues()) {
            //            long preCorrectedCount = v.getCountAtValueIteratedTo();
            //            long postCorrectedCount = histogram.getHistogramData().getCountAtValue(v.getValueIteratedTo());
            //            Assert.assertEquals("pre and post corrected count at value " + v.getValueIteratedTo(),
            //                    preCorrectedCount, postCorrectedCount);
            //        }
        }
Example #4
0
 protected void ResetIterator(AbstractHistogram histogram)
 {
     this.Histogram = histogram;
     this.SavedHistogramTotalRawCount          = histogram.getTotalCount();
     this.ArrayTotalCount                      = histogram.getTotalCount();
     this._integerToDoubleValueConversionRatio = histogram.integerToDoubleValueConversionRatio;
     this.CurrentIndex              = 0;
     this.CurrentValueAtIndex       = 0;
     this.NextValueAtIndex          = 1 << histogram.unitMagnitude;
     this._prevValueIteratedTo      = 0;
     this._totalCountToPrevIndex    = 0;
     this.TotalCountToCurrentIndex  = 0;
     this._totalValueToCurrentIndex = 0;
     this.CountAtThisValue          = 0;
     this._freshSubBucket           = true;
     CurrentIterationValue.Reset();
 }
Example #5
0
 protected void resetIterator(AbstractHistogram histogram)
 {
     this.histogram = histogram;
     this.savedHistogramTotalRawCount         = histogram.getTotalCount();
     this.arrayTotalCount                     = histogram.getTotalCount();
     this.integerToDoubleValueConversionRatio = histogram.integerToDoubleValueConversionRatio;
     this.currentIndex             = 0;
     this.currentValueAtIndex      = 0;
     this.nextValueAtIndex         = 1 << histogram.unitMagnitude;
     this.prevValueIteratedTo      = 0;
     this.totalCountToPrevIndex    = 0;
     this.totalCountToCurrentIndex = 0;
     this.totalValueToCurrentIndex = 0;
     this.countAtThisValue         = 0;
     this.freshSubBucket           = true;
     currentIterationValue.reset();
 }
Example #6
0
        //void testAbstractSerialization(AbstractHistogram histogram) throws Exception {
        //    histogram.recordValue(testValueLevel);
        //    histogram.recordValue(testValueLevel * 10);
        //    histogram.recordValueWithExpectedInterval(histogram.getHighestTrackableValue() - 1, 31);
        //    ByteArrayOutputStream bos = new ByteArrayOutputStream();
        //    ObjectOutput out = null;
        //    ByteArrayInputStream bis = null;
        //    ObjectInput in = null;
        //    AbstractHistogram newHistogram = null;
        //    try {
        //        out = new ObjectOutputStream(bos);
        //        out.writeObject(histogram);
        //        Deflater compresser = new Deflater();
        //        compresser.setInput(bos.toByteArray());
        //        compresser.finish();
        //        byte [] compressedOutput = new byte[1024*1024];
        //        int compressedDataLength = compresser.deflate(compressedOutput);
        //        Console.WriteLine("Serialized form of " + histogram.getClass() + " with highestTrackableValue = " +
        //                histogram.getHighestTrackableValue() + "\n and a numberOfSignificantValueDigits = " +
        //                histogram.getNumberOfSignificantValueDigits() + " is " + bos.toByteArray().length +
        //                " bytes long. Compressed form is " + compressedDataLength + " bytes long.");
        //        Console.WriteLine("   (estimated footprint was " + histogram.getEstimatedFootprintInBytes() + " bytes)");
        //        bis = new ByteArrayInputStream(bos.toByteArray());
        //        in = new ObjectInputStream(bis);
        //        newHistogram = (AbstractHistogram) in.readObject();
        //    } finally {
        //        if (out != null) out.close();
        //        bos.close();
        //        if (in !=null) in.close();
        //        if (bis != null) bis.close();
        //    }
        //    Assert.assertNotNull(newHistogram);
        //    assertEqual(histogram, newHistogram);
        //}

        private void assertEqual(AbstractHistogram expectedHistogram, AbstractHistogram actualHistogram)
        {
            Assert.assertEquals(expectedHistogram, actualHistogram);
            Assert.assertEquals(
                expectedHistogram.getCountAtValue(testValueLevel),
                actualHistogram.getCountAtValue(testValueLevel));
            Assert.assertEquals(
                expectedHistogram.getCountAtValue(testValueLevel * 10),
                actualHistogram.getCountAtValue(testValueLevel * 10));
            Assert.assertEquals(
                expectedHistogram.getTotalCount(),
                actualHistogram.getTotalCount());
        }
 protected void resetIterator(/*final*/ AbstractHistogram histogram)
 {
     this.histogram = histogram;
     this.savedHistogramTotalRawCount = histogram.getTotalCount();
     this.arrayTotalCount             = histogram.getTotalCount();
     this.currentBucketIndex          = 0;
     this.currentSubBucketIndex       = 0;
     this.currentValueAtIndex         = 0;
     this.nextBucketIndex             = 0;
     this.nextSubBucketIndex          = 1;
     this.nextValueAtIndex            = 1;
     this.prevValueIteratedTo         = 0;
     this.totalCountToPrevIndex       = 0;
     this.totalCountToCurrentIndex    = 0;
     this.totalValueToCurrentIndex    = 0;
     this.countAtThisValue            = 0;
     this.freshSubBucket = true;
     if (this.currentIterationValue == null)
     {
         this.currentIterationValue = new HistogramIterationValue();
     }
     this.currentIterationValue.reset();
 }
        private void testRawRecordingSpeedAtExpectedInterval(String label, AbstractHistogram histogram,
                                                            long expectedInterval, long timingLoopCount,
                                                            bool assertNoGC = true, bool multiThreaded = false)
        {
            Console.WriteLine("\nTiming recording speed with expectedInterval = " + expectedInterval + " :");
            // Warm up:
            var timer = Stopwatch.StartNew();
            recordLoopWithExpectedInterval(histogram, warmupLoopLength, expectedInterval);
            timer.Stop();
            // 1 millisecond (ms) = 1000 microsoecond (µs or usec)
            // 1 microsecond (µs or usec) = 1000 nanosecond (ns or nsec)
            // 1 second = 1,000,000 usec or 1,000 ms
            long deltaUsec = timer.ElapsedMilliseconds * 1000L;
            long rate = 1000000 * warmupLoopLength / deltaUsec;
            Console.WriteLine("{0}Warmup:\n{1:N0} value recordings completed in {2:N0} usec, rate = {3:N0} value recording calls per sec.",
                                label, warmupLoopLength, deltaUsec, rate);
            histogram.reset();
            // Wait a bit to make sure compiler had a chance to do it's stuff:
            try
            {
                Thread.Sleep(1000);
            }
            catch (Exception)
            {
            }

            var gcBefore = PrintGCAndMemoryStats("GC Before");
            timer = Stopwatch.StartNew();
            recordLoopWithExpectedInterval(histogram, timingLoopCount, expectedInterval);
            timer.Stop();
            var gcAfter = PrintGCAndMemoryStats("GC After ");
            deltaUsec = timer.ElapsedMilliseconds * 1000L;
            rate = 1000000 * timingLoopCount / deltaUsec;

            Console.WriteLine(label + "Hot code timing:");
            Console.WriteLine("{0}{1:N0} value recordings completed in {2:N0} usec, rate = {3:N0} value recording calls per sec.",
                                label, timingLoopCount, deltaUsec, rate);
            if (multiThreaded == false)
            {
                rate = 1000000 * histogram.getTotalCount() / deltaUsec;
                Console.WriteLine("{0}{1:N0} raw recorded entries completed in {2:N0} usec, rate = {3:N0} recorded values per sec.",
                                    label, histogram.getTotalCount(), deltaUsec, rate);
            }

            if (assertNoGC)
            {
                //// TODO work out why we always seems to get at least 1 GC here, maybe it's due to the length of the test run??
                //Assert.LessOrEqual(gcAfter.Item1 - gcBefore.Item1, 1, "There should be at MOST 1 Gen1 GC Collections");
                //Assert.LessOrEqual(gcAfter.Item2 - gcBefore.Item2, 1, "There should be at MOST 1 Gen2 GC Collections");
                //Assert.LessOrEqual(gcAfter.Item3 - gcBefore.Item3, 1, "There should be at MOST 1 Gen3 GC Collections");

                // TODO work out why we always seems to get at least 1 GC here, maybe it's due to the length of the test run??
                Assert.LessOrEqual(gcAfter.Gen1 - gcBefore.Gen1, 1, "There should be at MOST 1 Gen1 GC Collections");
                Assert.LessOrEqual(gcAfter.Gen1 - gcBefore.Gen1, 1, "There should be at MOST 1 Gen2 GC Collections");
                Assert.LessOrEqual(gcAfter.Gen3 - gcBefore.Gen3, 1, "There should be at MOST 1 Gen3 GC Collections");
            }
        }
Example #9
0
        //void testAbstractSerialization(AbstractHistogram histogram) throws Exception {
        //    histogram.recordValue(testValueLevel);
        //    histogram.recordValue(testValueLevel * 10);
        //    histogram.recordValueWithExpectedInterval(histogram.getHighestTrackableValue() - 1, 31);
        //    ByteArrayOutputStream bos = new ByteArrayOutputStream();
        //    ObjectOutput out = null;
        //    ByteArrayInputStream bis = null;
        //    ObjectInput in = null;
        //    AbstractHistogram newHistogram = null;
        //    try {
        //        out = new ObjectOutputStream(bos);
        //        out.writeObject(histogram);
        //        Deflater compresser = new Deflater();
        //        compresser.setInput(bos.toByteArray());
        //        compresser.finish();
        //        byte [] compressedOutput = new byte[1024*1024];
        //        int compressedDataLength = compresser.deflate(compressedOutput);
        //        Console.WriteLine("Serialized form of " + histogram.getClass() + " with highestTrackableValue = " +
        //                histogram.getHighestTrackableValue() + "\n and a numberOfSignificantValueDigits = " +
        //                histogram.getNumberOfSignificantValueDigits() + " is " + bos.toByteArray().length +
        //                " bytes long. Compressed form is " + compressedDataLength + " bytes long.");
        //        Console.WriteLine("   (estimated footprint was " + histogram.getEstimatedFootprintInBytes() + " bytes)");
        //        bis = new ByteArrayInputStream(bos.toByteArray());
        //        in = new ObjectInputStream(bis);
        //        newHistogram = (AbstractHistogram) in.readObject();
        //    } finally {
        //        if (out != null) out.close();
        //        bos.close();
        //        if (in !=null) in.close();
        //        if (bis != null) bis.close();
        //    }
        //    Assert.assertNotNull(newHistogram);
        //    assertEqual(histogram, newHistogram);
        //}

        private void assertEqual(AbstractHistogram expectedHistogram, AbstractHistogram actualHistogram)
        {
            Assert.assertEquals(expectedHistogram, actualHistogram);
            Assert.assertEquals(
                    expectedHistogram.getCountAtValue(testValueLevel),
                    actualHistogram.getCountAtValue(testValueLevel));
            Assert.assertEquals(
                    expectedHistogram.getCountAtValue(testValueLevel * 10),
                    actualHistogram.getCountAtValue(testValueLevel * 10));
            Assert.assertEquals(
                    expectedHistogram.getTotalCount(),
                    actualHistogram.getTotalCount());
        }
Example #10
0
        private void testRawRecordingSpeedAtExpectedInterval(String label, AbstractHistogram histogram,
                                                             long expectedInterval, long timingLoopCount,
                                                             bool assertNoGC = true, bool multiThreaded = false)
        {
            Console.WriteLine("\nTiming recording speed with expectedInterval = " + expectedInterval + " :");
            // Warm up:
            var timer = Stopwatch.StartNew();

            recordLoopWithExpectedInterval(histogram, warmupLoopLength, expectedInterval);
            timer.Stop();
            // 1 millisecond (ms) = 1000 microsoecond (µs or usec)
            // 1 microsecond (µs or usec) = 1000 nanosecond (ns or nsec)
            // 1 second = 1,000,000 usec or 1,000 ms
            long deltaUsec = timer.ElapsedMilliseconds * 1000L;
            long rate      = 1000000 * warmupLoopLength / deltaUsec;

            Console.WriteLine("{0}Warmup:\n{1:N0} value recordings completed in {2:N0} usec, rate = {3:N0} value recording calls per sec.",
                              label, warmupLoopLength, deltaUsec, rate);
            histogram.reset();
            // Wait a bit to make sure compiler had a chance to do it's stuff:
            try
            {
                Thread.Sleep(1000);
            }
            catch (Exception)
            {
            }

            var gcBefore = PrintGCAndMemoryStats("GC Before");

            timer = Stopwatch.StartNew();
            recordLoopWithExpectedInterval(histogram, timingLoopCount, expectedInterval);
            timer.Stop();
            var gcAfter = PrintGCAndMemoryStats("GC After ");

            deltaUsec = timer.ElapsedMilliseconds * 1000L;
            rate      = 1000000 * timingLoopCount / deltaUsec;

            Console.WriteLine(label + "Hot code timing:");
            Console.WriteLine("{0}{1:N0} value recordings completed in {2:N0} usec, rate = {3:N0} value recording calls per sec.",
                              label, timingLoopCount, deltaUsec, rate);
            if (multiThreaded == false)
            {
                rate = 1000000 * histogram.getTotalCount() / deltaUsec;
                Console.WriteLine("{0}{1:N0} raw recorded entries completed in {2:N0} usec, rate = {3:N0} recorded values per sec.",
                                  label, histogram.getTotalCount(), deltaUsec, rate);
            }

            if (assertNoGC)
            {
                //// TODO work out why we always seems to get at least 1 GC here, maybe it's due to the length of the test run??
                //Assert.LessOrEqual(gcAfter.Item1 - gcBefore.Item1, 1, "There should be at MOST 1 Gen1 GC Collections");
                //Assert.LessOrEqual(gcAfter.Item2 - gcBefore.Item2, 1, "There should be at MOST 1 Gen2 GC Collections");
                //Assert.LessOrEqual(gcAfter.Item3 - gcBefore.Item3, 1, "There should be at MOST 1 Gen3 GC Collections");

                // TODO work out why we always seems to get at least 1 GC here, maybe it's due to the length of the test run??
                Assert.LessOrEqual(gcAfter.Gen1 - gcBefore.Gen1, 1, "There should be at MOST 1 Gen1 GC Collections");
                Assert.LessOrEqual(gcAfter.Gen1 - gcBefore.Gen1, 1, "There should be at MOST 1 Gen2 GC Collections");
                Assert.LessOrEqual(gcAfter.Gen3 - gcBefore.Gen3, 1, "There should be at MOST 1 Gen3 GC Collections");
            }
        }