Skip to content

Commit ec25ca9

Browse files
authored
feat: print average speed in forest-cli snapshot export (#5869)
1 parent 5e9a527 commit ec25ca9

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
### Changed
3535

36+
- [#5869](https://github.com/ChainSafe/forest/pull/5869) Updated `forest-cli snapshot export` to print average speed.
37+
3638
### Removed
3739

3840
### Fixed

src/cli/subcommands/snapshot_cmd.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ use anyhow::Context as _;
1212
use chrono::DateTime;
1313
use clap::Subcommand;
1414
use human_repr::HumanCount;
15-
use std::path::{Path, PathBuf};
16-
use std::time::Duration;
15+
use num::Zero as _;
16+
use std::{
17+
path::{Path, PathBuf},
18+
time::{Duration, Instant},
19+
};
1720
use tokio::io::AsyncWriteExt;
1821

1922
#[derive(Debug, Subcommand)]
@@ -92,11 +95,12 @@ impl SnapshotCommands {
9295
};
9396

9497
let handle = tokio::spawn({
98+
let start = Instant::now();
9599
let tmp_file = temp_path.to_owned();
96100
let output_path = output_path.clone();
97101
async move {
98102
let mut interval =
99-
tokio::time::interval(tokio::time::Duration::from_secs_f32(0.25));
103+
tokio::time::interval(tokio::time::Duration::from_secs_f32(0.5));
100104
println!("Getting ready to export...");
101105
loop {
102106
interval.tick().await;
@@ -108,10 +112,17 @@ impl SnapshotCommands {
108112
anes::MoveCursorToPreviousLine(1),
109113
anes::ClearLine::All
110114
);
115+
let elapsed_secs = start.elapsed().as_secs_f64();
111116
println!(
112-
"{}: {}",
117+
"{}: {} ({}/s)",
113118
&output_path.to_string_lossy(),
114-
snapshot_size.human_count_bytes()
119+
snapshot_size.human_count_bytes(),
120+
if elapsed_secs.is_zero() {
121+
0.
122+
} else {
123+
(snapshot_size as f64) / elapsed_secs
124+
}
125+
.human_count_bytes(),
115126
);
116127
let _ = std::io::stdout().flush();
117128
}

0 commit comments

Comments
 (0)