Search in sources :

Example 1 with LogarithmicIterator

use of org.HdrHistogram.LogarithmicIterator in project grpc-java by grpc.

the class LoadClient method getStats.

/**
   * Take a snapshot of the statistics which can be returned to the driver.
   */
Stats.ClientStats getStats() {
    Histogram intervalHistogram = recorder.getIntervalHistogram();
    Stats.ClientStats.Builder statsBuilder = Stats.ClientStats.newBuilder();
    Stats.HistogramData.Builder latenciesBuilder = statsBuilder.getLatenciesBuilder();
    double resolution = 1.0 + Math.max(config.getHistogramParams().getResolution(), 0.01);
    LogarithmicIterator logIterator = new LogarithmicIterator(intervalHistogram, 1, resolution);
    double base = 1;
    while (logIterator.hasNext()) {
        latenciesBuilder.addBucket((int) logIterator.next().getCountAddedInThisIterationStep());
        base = base * resolution;
    }
    // have values.
    while (base < config.getHistogramParams().getMaxPossible()) {
        latenciesBuilder.addBucket(0);
        base = base * resolution;
    }
    latenciesBuilder.setMaxSeen(intervalHistogram.getMaxValue());
    latenciesBuilder.setMinSeen(intervalHistogram.getMinNonZeroValue());
    latenciesBuilder.setCount(intervalHistogram.getTotalCount());
    latenciesBuilder.setSum(intervalHistogram.getMean() * intervalHistogram.getTotalCount());
    // TODO: No support for sum of squares
    statsBuilder.setTimeElapsed((intervalHistogram.getEndTimeStamp() - intervalHistogram.getStartTimeStamp()) / 1000.0);
    if (osBean != null) {
        // Report all the CPU time as user-time  (which is intentionally incorrect)
        long nowCpu = osBean.getProcessCpuTime();
        statsBuilder.setTimeUser(((double) nowCpu - lastMarkCpuTime) / 1000000000.0);
        lastMarkCpuTime = nowCpu;
    }
    return statsBuilder.build();
}
Also used : Histogram(org.HdrHistogram.Histogram) LogarithmicIterator(org.HdrHistogram.LogarithmicIterator)

Aggregations

Histogram (org.HdrHistogram.Histogram)1 LogarithmicIterator (org.HdrHistogram.LogarithmicIterator)1