@ -10,6 +10,8 @@
# include "monitoring/histogram.h"
# include "monitoring/histogram.h"
# include <stdio.h>
# include <stdio.h>
# include <algorithm>
# include <cassert>
# include <cassert>
# include <cinttypes>
# include <cinttypes>
# include <cmath>
# include <cmath>
@ -23,7 +25,6 @@ HistogramBucketMapper::HistogramBucketMapper() {
// If you change this, you also need to change
// If you change this, you also need to change
// size of array buckets_ in HistogramImpl
// size of array buckets_ in HistogramImpl
bucketValues_ = { 1 , 2 } ;
bucketValues_ = { 1 , 2 } ;
valueIndexMap_ = { { 1 , 0 } , { 2 , 1 } } ;
double bucket_val = static_cast < double > ( bucketValues_ . back ( ) ) ;
double bucket_val = static_cast < double > ( bucketValues_ . back ( ) ) ;
while ( ( bucket_val = 1.5 * bucket_val ) < = static_cast < double > ( port : : kMaxUint64 ) ) {
while ( ( bucket_val = 1.5 * bucket_val ) < = static_cast < double > ( port : : kMaxUint64 ) ) {
bucketValues_ . push_back ( static_cast < uint64_t > ( bucket_val ) ) ;
bucketValues_ . push_back ( static_cast < uint64_t > ( bucket_val ) ) ;
@ -35,26 +36,18 @@ HistogramBucketMapper::HistogramBucketMapper() {
pow_of_ten * = 10 ;
pow_of_ten * = 10 ;
}
}
bucketValues_ . back ( ) * = pow_of_ten ;
bucketValues_ . back ( ) * = pow_of_ten ;
valueIndexMap_ [ bucketValues_ . back ( ) ] = bucketValues_ . size ( ) - 1 ;
}
}
maxBucketValue_ = bucketValues_ . back ( ) ;
maxBucketValue_ = bucketValues_ . back ( ) ;
minBucketValue_ = bucketValues_ . front ( ) ;
minBucketValue_ = bucketValues_ . front ( ) ;
}
}
size_t HistogramBucketMapper : : IndexForValue ( const uint64_t value ) const {
size_t HistogramBucketMapper : : IndexForValue ( const uint64_t value ) const {
if ( value > = maxBucketValue_ ) {
auto beg = bucketValues_ . begin ( ) ;
return bucketValues_ . size ( ) - 1 ;
auto end = bucketValues_ . end ( ) ;
} else if ( value > = minBucketValue_ ) {
if ( value > = maxBucketValue_ )
std : : map < uint64_t , uint64_t > : : const_iterator lowerBound =
return end - beg - 1 ; // bucketValues_.size() - 1
valueIndexMap_ . lower_bound ( value ) ;
else
if ( lowerBound ! = valueIndexMap_ . end ( ) ) {
return std : : lower_bound ( beg , end , value ) - beg ;
return static_cast < size_t > ( lowerBound - > second ) ;
} else {
return 0 ;
}
} else {
return 0 ;
}
}
}
namespace {
namespace {