public double getValueAtPercentile(GaugeMetricValue value, int p) { SparseHistogram histo = value.getHistogram(); int binNo = histo.getBinAfterPercentile(p); if (binNo == -1) { return Double.NaN; } return INSIGHT_HISTO.getBinDefinition(binNo).getStart(); }
private Bin emptyBinAt(int index) { BinDefinition binDef = definition.getBinDefinition(index); return new Bin(0, binDef.getStart(), binDef.getEnd()); }
private List<Bin> growTo(List<Bin> bins, double endValue, int minCount) { int neededBins = Double.POSITIVE_INFINITY != endValue ? definition.getBinForValue(endValue) : minCount; if (neededBins < minCount) { neededBins = minCount; } List<Bin> grownBins = new ArrayList<Bin>(bins); if (grownBins.isEmpty()) { grownBins.add(emptyBinAt(0)); } if (grownBins.get(0).getStart() != 0) { // fill bins from 0 to start double fillTo = grownBins.get(0).getStart(); List<Bin> prefixBins = new ArrayList<Bin>(); BinDefinition binDef; int count = 0; do { binDef = definition.getBinDefinition(count); count++; prefixBins.add(new Bin(0, binDef.getStart(), binDef.getEnd())); } while (fillTo > binDef.getEnd()); grownBins.addAll(0, prefixBins); } // fill bins from end to needed bins while (grownBins.size() < neededBins) { grownBins.add(emptyBinAt(grownBins.size())); } return Collections.unmodifiableList(grownBins); }
for (IndexedBin indexBin : populatedBins) { int mappedIndex=indexBin.getBinNumber(); BinDefinition mappedBin=def.getBinDefinition(mappedIndex); long mappedValue=indexBin.getCount(); if (mappedValue == 0L) { Bin binValue=binsMap.get(Integer.valueOf(mappedIndex)); if (binValue == null) { BinDefinition mappedBin=def.getBinDefinition(mappedIndex); binValue = new Bin(0L, mappedBin.getStart(), mappedBin.getEnd());
for (IndexedBin indexedBin : bins) { int binIndex=indexedBin.getBinNumber(); BinDefinition binDef=histogramDefinition.getBinDefinition(binIndex); double binStart=binDef.getStart(), binEnd=binDef.getEnd(); BinDefinition mappedBin=def.getBinDefinition(mappedIndex); double mappedBinStart=mappedBin.getStart(), mappedBinEnd=mappedBin.getEnd(); double mappedBinSize=mappedBinEnd - mappedBinStart;
public Histogram build() { SparseHistogram sparseMetric=metricValue.getHistogram(); Histogram metricHistogram=sparseMetric.getFullHistogram(definition); List<Bin> rawBins = growTo(metricHistogram.getBins(), end, binsCount); List<Bin> histBins = new ArrayList<Bin>(); int binCount = this.binsCount; // force start and end to bin boundaries double startHistory = definition.getBinDefinition(definition.getBinForValue(this.start)).getStart(); double endHistory = definition.getBinDefinition(definition.getBinForValue(this.end)).getEnd(); if (lowOutliers) { binCount--; histBins.add(new Bin(collapse(collect(rawBins, Double.NEGATIVE_INFINITY, startHistory)).getCount(), Double.NEGATIVE_INFINITY, startHistory)); } if (highOutliers) { binCount--; histBins.add(new Bin(collapse(collect(rawBins, endHistory, Double.POSITIVE_INFINITY)).getCount(), endHistory, Double.POSITIVE_INFINITY)); } histBins.addAll(toSize(collect(rawBins, startHistory, endHistory), binCount)); Collections.sort(histBins); return new Histogram(histBins); }