diff --git a/application/apps/indexer/session/src/handlers/observing/mod.rs b/application/apps/indexer/session/src/handlers/observing/mod.rs index 9924a45738..0db7c1876a 100644 --- a/application/apps/indexer/session/src/handlers/observing/mod.rs +++ b/application/apps/indexer/session/src/handlers/observing/mod.rs @@ -123,6 +123,7 @@ async fn run_producer, S: ByteSource>( operation_api.processing(); let cancel = operation_api.cancellation_token(); let cancel_on_tail = cancel.clone(); + let mut timer = crate::Timer::new("message stream"); while let Some(next) = select! { next_from_stream = async { match timeout(Duration::from_millis(FLUSH_TIMEOUT_IN_MS as u64), producer.read_next_segment()).await { @@ -172,6 +173,7 @@ async fn run_producer, S: ByteSource>( state.add_attachment(attachment.to_owned())?; } MessageStreamItem::Done => { + timer.done(); trace!("observe, message stream is done"); state.flush_session_file().await?; state.file_read().await?; diff --git a/application/apps/indexer/session/src/lib.rs b/application/apps/indexer/session/src/lib.rs index 81f6bb982d..bbe383c240 100644 --- a/application/apps/indexer/session/src/lib.rs +++ b/application/apps/indexer/session/src/lib.rs @@ -8,7 +8,7 @@ pub mod tail; pub mod tracker; pub mod unbound; -use std::sync::Mutex; +use std::{env, sync::Mutex, time::Instant}; use tokio::sync::mpsc; extern crate lazy_static; @@ -22,3 +22,31 @@ lazy_static::lazy_static! { Mutex::new((tx, Some(rx))) }; } + +/// A Timer that can be used to monitor performance in dev-mode. +struct Timer<'a> { + what: &'a str, + start: Option, +} + +impl<'a> Timer<'a> { + /// Creates a new timer. + fn new(what: &'a str) -> Self { + Timer { + what, + start: if env::var("CHIPMUNK_DEVELOPING_MODE").is_ok() { + Some(std::time::Instant::now()) + } else { + None + }, + } + } + + /// Prints timer result to console if dev-mode is on. + fn done(&mut self) { + if let Some(time) = self.start { + println!("🕑 {} took: {:?}", self.what, time.elapsed()); + self.start = None; + } + } +} diff --git a/application/apps/indexer/session/src/unbound/commands/dlt.rs b/application/apps/indexer/session/src/unbound/commands/dlt.rs index 192fc46d48..3936ece628 100644 --- a/application/apps/indexer/session/src/unbound/commands/dlt.rs +++ b/application/apps/indexer/session/src/unbound/commands/dlt.rs @@ -14,6 +14,7 @@ pub fn stats( ) -> Result, stypes::ComputationError> { let mut stat = StatisticInfo::new(); let mut error: Option = None; + let mut timer = crate::Timer::new("collect statistics"); file_paths.iter().for_each(|file_path| { if error.is_some() { return; @@ -37,6 +38,7 @@ pub fn stats( } } }); + timer.done(); if let Some(err) = error { return Err(stypes::ComputationError::IoOperation(err)); }