Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 package io.tehuti.metrics.stats;
 import java.util.List;
A compound stat that reports one or more percentiles
 public class Percentiles extends SampledStat implements CompoundStat {
     public static enum BucketSizing {
     private final int buckets;
     private final Percentile[] percentiles;
     private final Histogram.BinScheme binScheme;
     public Percentiles(int sizeInBytesdouble maxBucketSizing bucketingPercentile... percentiles) {
         this(sizeInBytes, 0.0, maxbucketingpercentiles);
     public Percentiles(int sizeInBytesdouble mindouble maxBucketSizing bucketingPercentile... percentiles) {
         this. = percentiles;
         this. = sizeInBytes / 4;
         if (bucketing == .) {
             this. = new Histogram.ConstantBinScheme(minmax);
         } else if (bucketing == .) {
             if (min != 0.0d)
                 throw new IllegalArgumentException("Linear bucket sizing requires min to be 0.0.");
             this. = new Histogram.LinearBinScheme(max);
         } else {
             throw new IllegalArgumentException("Unknown bucket type: " + bucketing);
     public List<NamedMeasurablestats() {
         List<NamedMeasurablems = new ArrayList<NamedMeasurable>(this..length);
         for (Percentile percentile : this.) {
             final double pct = percentile.percentile();
             ms.add(new NamedMeasurable(, percentile.description(), new Measurable() {
                 public double measure(MetricConfig configlong now) {
                     return value(confignowpct / 100.0);
         return ms;
     public double value(MetricConfig configlong nowdouble quantile) {
         float count = 0.0f;
         for (Sample sample : this.)
             count += sample.eventCount;
         if (count == 0.0f)
             return .;
         float sum = 0.0f;
         float quant = (floatquantile;
         for (int b = 0; b < b++) {
             for (int s = 0; s < this..size(); s++) {
                 HistogramSample sample = (HistogramSamplethis..get(s);
                 float[] hist = sample.histogram.counts();
                 sum += hist[b];
                 if (sum / count > quant)
                     return .fromBin(b);
         return .;
     public double combine(List<SamplesamplesMetricConfig configlong now) {
         return value(confignow, 0.5);
     protected HistogramSample newSample(long timeMs) {
         return new HistogramSample(this.timeMs);
     protected void update(Sample sampleMetricConfig configdouble valuelong timeMs) {
        HistogramSample hist = (HistogramSamplesample;
    private static class HistogramSample extends SampledStat.Sample {
        private final Histogram histogram;
        private HistogramSample(Histogram.BinScheme schemelong now) {
            super(0.0, now);
            this. = new Histogram(scheme);
        public void reset(long now) {
New to GrepCode? Check out our FAQ X