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 ; } // Driver expects values for all buckets in the range, not just the range of buckets that // 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 ( ) ; }
Take a snapshot of the statistics which can be returned to the driver .