use hdrhistogram::Histogram;
use self::time_stamp::seconds;
pub struct LatencyMetricsEntry {
pub latency: Histogram<u64>,
}
impl Default for LatencyMetricsEntry {
fn default() -> Self {
Self::new()
}
}
impl LatencyMetricsEntry {
pub const HISTOGRAM_LOWER_BOUND: u64 = 1;
pub const HISTOGRAM_UPPER_BOUND: u64 = seconds(100);
pub fn new() -> Self {
Self {
latency: Histogram::new_with_bounds(
Self::HISTOGRAM_LOWER_BOUND,
Self::HISTOGRAM_UPPER_BOUND,
2,
)
.expect("直方图边界为编译期常量,构造必成功"),
}
}
pub fn return_to_pool(&mut self) {
self.latency.reset();
}
}
pub mod time_stamp {
pub const TICKS_PER_SECOND: u64 = 10_000_000;
pub const TICKS_PER_MICROSECOND: u64 = TICKS_PER_SECOND / 1_000_000;
pub const TICKS_PER_SECOND_UNIT: u64 = TICKS_PER_SECOND;
#[inline]
pub const fn seconds(secs: u64) -> u64 {
secs * TICKS_PER_SECOND
}
}