@Test public void percentilesWithNoSamples() { double[] percentiles = new double[]{0.5, 0.9, 0.95}; RollingHistogram histogram = new RollingHistogram(Clock.DEFAULT, StatisticConfig.builder() .percentiles(percentiles) .expiry(Duration.ofDays(1)).buckets(3).build()); Snapshot snapshot = histogram.getSnapshot(); PercentileValue[] percentileValues = snapshot.getPercentileValues(); for (int i = 0; i < percentiles.length; i++) { Assert.assertEquals(percentileValues[i].getPercentile(), percentiles[i]); Assert.assertEquals(percentileValues[i].getValue(), 0.0); } }
public Snapshot getSnapshot() { rotate(); synchronized (this) { accumulateIfStale(); PercentileValue[] percentileValues = null; final double[] monitoredPercentiles = statisticConfig.getPercentiles(); if (monitoredPercentiles != null) { percentileValues = new PercentileValue[monitoredPercentiles.length]; for (int i = 0; i < monitoredPercentiles.length; i++) { final double p = monitoredPercentiles[i]; percentileValues[i] = new PercentileValue(p, accumulatedHistogram.getValueAtPercentile(p * 100)); } } return new Snapshot(statisticConfig.getTimeWindow(), accumulatedHistogram.getMinValue(), accumulatedHistogram.getMean(), accumulatedHistogram.getStdDeviation(), accumulatedHistogram.getMaxValue(), percentileValues); } }
RollingHistogram { public Snapshot getSnapshot() { rotate(); synchronized (this) { accumulateIfStale(); PercentileValue[] percentileValues = null; final double[] monitoredPercentiles = statisticConfig.getPercentiles(); if (monitoredPercentiles != null) { percentileValues = new PercentileValue[monitoredPercentiles.length]; for (int i = 0; i < monitoredPercentiles.length; i++) { final double p = monitoredPercentiles[i]; percentileValues[i] = new PercentileValue(p, accumulatedHistogram.getValueAtPercentile(p * 100)); } } return new Snapshot(statisticConfig.getTimeWindow(), accumulatedHistogram.getMinValue(), accumulatedHistogram.getMean(), accumulatedHistogram.getStdDeviation(), accumulatedHistogram.getMaxValue(), percentileValues); } } }
RollingHistogram { public Snapshot getSnapshot() { rotate(); synchronized (this) { accumulateIfStale(); PercentileValue[] percentileValues = null; final double[] monitoredPercentiles = statisticConfig.getPercentiles(); if (monitoredPercentiles != null) { percentileValues = new PercentileValue[monitoredPercentiles.length]; for (int i = 0; i < monitoredPercentiles.length; i++) { final double p = monitoredPercentiles[i]; percentileValues[i] = new PercentileValue(p, accumulatedHistogram.getValueAtPercentile(p * 100)); } } return new Snapshot(statisticConfig.getTimeWindow(), accumulatedHistogram.getMinValue(), accumulatedHistogram.getMean(), accumulatedHistogram.getStdDeviation(), accumulatedHistogram.getMaxValue(), percentileValues); } } RollingHistogram(Clock clock, StatisticConfig statisticConfig); }
RollingHistogram { public Snapshot getSnapshot() { rotate(); synchronized (this) { accumulateIfStale(); PercentileValue[] percentileValues = null; final double[] monitoredPercentiles = statisticConfig.getPercentiles(); if (monitoredPercentiles != null) { percentileValues = new PercentileValue[monitoredPercentiles.length]; for (int i = 0; i < monitoredPercentiles.length; i++) { final double p = monitoredPercentiles[i]; percentileValues[i] = new PercentileValue(p, accumulatedHistogram.getValueAtPercentile(p * 100)); } } return new Snapshot(statisticConfig.getTimeWindow(), accumulatedHistogram.getMinValue(), accumulatedHistogram.getMean(), accumulatedHistogram.getStdDeviation(), accumulatedHistogram.getMaxValue(), percentileValues); } } RollingHistogram(Clock clock, StatisticConfig statisticConfig); void record(double value); StatisticConfig getStatisticConfig(); Snapshot getSnapshot(); }
RollingHistogram { public Snapshot getSnapshot() { rotate(); synchronized (this) { accumulateIfStale(); PercentileValue[] percentileValues = null; final double[] monitoredPercentiles = statisticConfig.getPercentiles(); if (monitoredPercentiles != null) { percentileValues = new PercentileValue[monitoredPercentiles.length]; for (int i = 0; i < monitoredPercentiles.length; i++) { final double p = monitoredPercentiles[i]; percentileValues[i] = new PercentileValue(p, accumulatedHistogram.getValueAtPercentile(p * 100)); } } return new Snapshot(statisticConfig.getTimeWindow(), accumulatedHistogram.getMinValue(), accumulatedHistogram.getMean(), accumulatedHistogram.getStdDeviation(), accumulatedHistogram.getMaxValue(), percentileValues); } } RollingHistogram(Clock clock, StatisticConfig statisticConfig); void record(double value); StatisticConfig getStatisticConfig(); Snapshot getSnapshot();  }