Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ async fn run_producer<T: LogMessage, P: Parser<T>, 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 {
Expand Down Expand Up @@ -172,6 +173,7 @@ async fn run_producer<T: LogMessage, P: Parser<T>, 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?;
Expand Down
30 changes: 29 additions & 1 deletion application/apps/indexer/session/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Instant>,
}

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;
}
}
}
2 changes: 2 additions & 0 deletions application/apps/indexer/session/src/unbound/commands/dlt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub fn stats(
) -> Result<stypes::CommandOutcome<stypes::DltStatisticInfo>, stypes::ComputationError> {
let mut stat = StatisticInfo::new();
let mut error: Option<String> = None;
let mut timer = crate::Timer::new("collect statistics");
file_paths.iter().for_each(|file_path| {
if error.is_some() {
return;
Expand All @@ -37,6 +38,7 @@ pub fn stats(
}
}
});
timer.done();
if let Some(err) = error {
return Err(stypes::ComputationError::IoOperation(err));
}
Expand Down
Loading