Move duration util fn to stats

Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
Nick Cameron 2020-10-28 11:59:19 +13:00
parent 1f5387ddfe
commit e7bd456722
2 changed files with 10 additions and 12 deletions

View File

@ -1,8 +1,8 @@
// Copyright 2018 TiKV Project Authors. Licensed under Apache-2.0.
use crate::{util::duration_to_sec, Result};
use crate::Result;
use prometheus::{Histogram, HistogramVec, IntCounterVec};
use std::time::Instant;
use std::time::{Duration, Instant};
pub struct RequestStats {
start: Instant,
@ -125,3 +125,11 @@ lazy_static! {
)
.unwrap();
}
/// Convert Duration to seconds.
#[inline]
fn duration_to_sec(d: Duration) -> f64 {
let nanos = f64::from(d.subsec_nanos());
// In most cases, we can't have so large Duration, so here just panic if overflow now.
d.as_secs() as f64 + (nanos / 1_000_000_000.0)
}

View File

@ -1,7 +1,5 @@
// Copyright 2018 TiKV Project Authors. Licensed under Apache-2.0.
use std::time::Duration;
#[macro_export]
macro_rules! internal_err {
($e:expr) => ({
@ -14,11 +12,3 @@ macro_rules! internal_err {
internal_err!(format!($f, $($arg),+))
});
}
/// Convert Duration to seconds.
#[inline]
pub fn duration_to_sec(d: Duration) -> f64 {
let nanos = f64::from(d.subsec_nanos());
// In most cases, we can't have so large Duration, so here just panic if overflow now.
d.as_secs() as f64 + (nanos / 1_000_000_000.0)
}