mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Log how long it took to download/upload a file
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use super::{FileTransferActivity, FsEntry, InputMode, LogLevel, PopupType};
|
use super::{FileTransferActivity, FsEntry, InputMode, LogLevel, PopupType};
|
||||||
|
use crate::utils::fmt_millis;
|
||||||
|
|
||||||
use std::io::{Read, Seek, Write};
|
use std::io::{Read, Seek, Write};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
@@ -239,9 +240,10 @@ impl FileTransferActivity {
|
|||||||
self.log(
|
self.log(
|
||||||
LogLevel::Info,
|
LogLevel::Info,
|
||||||
format!(
|
format!(
|
||||||
"Saved file \"{}\" to \"{}\"",
|
"Saved file \"{}\" to \"{}\" (took {} seconds)",
|
||||||
file.abs_path.display(),
|
file.abs_path.display(),
|
||||||
remote_path.display()
|
remote_path.display(),
|
||||||
|
fmt_millis(self.transfer.started.elapsed()),
|
||||||
)
|
)
|
||||||
.as_ref(),
|
.as_ref(),
|
||||||
);
|
);
|
||||||
@@ -548,9 +550,10 @@ impl FileTransferActivity {
|
|||||||
self.log(
|
self.log(
|
||||||
LogLevel::Info,
|
LogLevel::Info,
|
||||||
format!(
|
format!(
|
||||||
"Saved file \"{}\" to \"{}\"",
|
"Saved file \"{}\" to \"{}\" (took {} seconds)",
|
||||||
file.abs_path.display(),
|
file.abs_path.display(),
|
||||||
local_file_path.display()
|
local_file_path.display(),
|
||||||
|
fmt_millis(self.transfer.started.elapsed()),
|
||||||
)
|
)
|
||||||
.as_ref(),
|
.as_ref(),
|
||||||
);
|
);
|
||||||
|
|||||||
16
src/utils.rs
16
src/utils.rs
@@ -203,6 +203,15 @@ pub fn time_to_str(time: SystemTime, fmt: &str) -> String {
|
|||||||
format!("{}", datetime.format(fmt))
|
format!("{}", datetime.format(fmt))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// ### fmt_millis
|
||||||
|
///
|
||||||
|
/// Format duration as {secs}.{millis}
|
||||||
|
pub fn fmt_millis(duration: Duration) -> String {
|
||||||
|
let seconds: u128 = duration.as_millis() / 1000;
|
||||||
|
let millis: u128 = duration.as_millis() % 1000;
|
||||||
|
format!("{}.{:0width$}", seconds, millis, width = 3)
|
||||||
|
}
|
||||||
|
|
||||||
/// ### lstime_to_systime
|
/// ### lstime_to_systime
|
||||||
///
|
///
|
||||||
/// Convert ls syntax time to System Time
|
/// Convert ls syntax time to System Time
|
||||||
@@ -431,4 +440,11 @@ mod tests {
|
|||||||
String::from("hello world!")
|
String::from("hello world!")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_utils_fmt_millis() {
|
||||||
|
assert_eq!(fmt_millis(Duration::from_millis(2048)), String::from("2.048"));
|
||||||
|
assert_eq!(fmt_millis(Duration::from_millis(8192)), String::from("8.192"));
|
||||||
|
assert_eq!(fmt_millis(Duration::from_millis(18192)), String::from("18.192"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user