Skip to content

Commit

Permalink
feat(tasks): add task timing to run command
Browse files Browse the repository at this point in the history
  • Loading branch information
Ajpantuso committed Jan 29, 2024
1 parent 711110c commit 8797e92
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ impl Run {
self.validate_task(task)?;
}

let timer = std::time::Instant::now();

let pool = rayon::ThreadPoolBuilder::new()
.num_threads(self.jobs() + 1)
.build()?;
Expand All @@ -195,6 +197,9 @@ impl Run {
run(&task);
}
});

miseprintln!("finished in {}", format_duration(timer.elapsed()));

Ok(())
}

Expand All @@ -211,6 +216,8 @@ impl Run {
.map(|(k, v)| (k.clone(), v.clone()))
.collect();

let timer = std::time::Instant::now();

if let Some(file) = &task.file {
self.exec_file(file, task, &env, &prefix)?;
} else {
Expand All @@ -223,6 +230,12 @@ impl Run {
}
}

miseprintln!(
"{} finished in {}",
prefix,
format_duration(timer.elapsed())
);

self.save_checksum(task)?;

Ok(())
Expand Down Expand Up @@ -531,6 +544,15 @@ fn get_color() -> Color {
static COLOR_IDX: AtomicUsize = AtomicUsize::new(0);
COLORS[COLOR_IDX.fetch_add(1, Ordering::Relaxed) % COLORS.len()]
}

fn format_duration(dur: std::time::Duration) -> String {
if dur < std::time::Duration::new(1, 0) {
format!("{:.0?}", dur)
} else {
format!("{:.2?}", dur)
}
}

#[cfg(test)]
mod tests {
use crate::file;
Expand Down

0 comments on commit 8797e92

Please sign in to comment.