Add debug feature to print latency

This commit is contained in:
Skye Jensen 2020-06-13 20:11:48 -04:00
parent aec10c000d
commit dc78dfe4d6
3 changed files with 18 additions and 1 deletions

View file

@ -4,6 +4,8 @@ version = "0.1.0"
authors = ["Artemis Tosini <me@artem.ist>"] authors = ["Artemis Tosini <me@artem.ist>"]
edition = "2018" edition = "2018"
[features]
check_latency = []
[dependencies] [dependencies]
async-trait = "0.1" async-trait = "0.1"

View file

@ -17,7 +17,6 @@ pub trait AsyncIter {
} }
} }
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;

View file

@ -2,6 +2,8 @@ use serde::{ser::Serializer, Serialize};
use smart_default::SmartDefault; use smart_default::SmartDefault;
use std::fmt::Debug; use std::fmt::Debug;
use std::sync::Arc; use std::sync::Arc;
#[cfg(feature = "check_latency")]
use std::time::Instant;
//use tokio::sync::mpsc::{error::SendError, Sender}; //use tokio::sync::mpsc::{error::SendError, Sender};
#[allow(unused)] #[allow(unused)]
@ -40,6 +42,16 @@ where
serializer.serialize_str(arc) serializer.serialize_str(arc)
} }
#[cfg(feature = "check_latency")]
fn time_diff<S>(&instant: &Instant, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let duration = Instant::now() - instant;
//let duration = duration.as_secs_f32();
serializer.serialize_str(&format!("{:?}", duration))
}
#[derive(Clone, Serialize, Debug, SmartDefault)] #[derive(Clone, Serialize, Debug, SmartDefault)]
pub struct Block { pub struct Block {
pub full_text: Box<str>, pub full_text: Box<str>,
@ -75,6 +87,10 @@ pub struct Block {
pub separator_block_width: Option<u32>, pub separator_block_width: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub markup: Option<Markup>, pub markup: Option<Markup>,
#[serde(serialize_with = "time_diff")]
#[default(Instant::now())]
#[cfg(feature = "check_latency")]
pub latency: Instant,
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]