Skip to content

Commit

Permalink
Show time of day in logs
Browse files Browse the repository at this point in the history
  • Loading branch information
mbuesch committed Feb 13, 2024
1 parent 4ad61fb commit 269c626
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ edition = "2021"

[dependencies]
anyhow = "1.0.0"
chrono = "0.4.0"
clap = "4.0.0"
libc = "0.2.0"
movavg = "2.0.0"
Expand Down
8 changes: 6 additions & 2 deletions src/disktest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::rawio::{RawIo, RawIoResult, DEFAULT_SECTOR_SIZE};
use crate::stream_aggregator::{DtStreamAgg, DtStreamAggChunk};
use crate::util::{prettybytes, Hhmmss};
use anyhow as ah;
use chrono::prelude::*;
use movavg::MovAvg;
use std::cmp::min;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -271,6 +272,8 @@ impl Disktest {
let expired = now.duration_since(self.log_time).as_secs() >= LOG_SEC_THRES;

if (expired && self.quiet_level == DisktestQuiet::Normal) || final_step {
let tod = Local::now().format("%R");

let dur_elapsed = now - self.begin_time;

let rate = if final_step {
Expand Down Expand Up @@ -299,11 +302,12 @@ impl Disktest {
let suffix = if final_step { "." } else { " ..." };

println!(
"{}{}{} ({}){}",
"[{} / {}] {}{}{}{}",
tod,
dur_elapsed.hhmmss(),
prefix,
prettybytes(abs_processed, true, true, final_step),
rate_string,
dur_elapsed.hhmmss(),
suffix
);
self.log_time = now;
Expand Down
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ mod util;
use crate::seed::print_generated_seed;
use anyhow as ah;
use args::{parse_args, Args};
use chrono::prelude::*;
use disktest::{Disktest, DisktestFile, DisktestQuiet};
use std::env::args_os;
use std::sync::atomic::AtomicBool;
Expand Down Expand Up @@ -87,9 +88,11 @@ fn main() -> ah::Result<()> {
let mut result = Ok(());
for round in args.start_round..args.rounds {
if args.rounds > 1 {
let tod = Local::now().format("%F %R");
println!(
"{}Round {} in range [{}, {}) ...",
"{}[{}] Round {} in range [{}, {}) ...",
if round > args.start_round { "\n" } else { "" },
tod,
round,
args.start_round,
args.rounds
Expand Down
12 changes: 6 additions & 6 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl Hhmmss for Duration {
let rem = secs % (60 * 60);
let m = rem / 60;
let s = rem % 60;
format!("{}{:02}:{:02}:{:02}", lim, h, m, s)
format!("{}{:02}h:{:02}m:{:02}s", lim, h, m, s)
}
}

Expand Down Expand Up @@ -382,22 +382,22 @@ mod tests {

#[test]
fn test_hhmmss() {
assert_eq!(Duration::from_secs(0).hhmmss(), "00:00:00");
assert_eq!(Duration::from_secs(0).hhmmss(), "00h:00m:00s");
assert_eq!(
Duration::from_secs((2 * 60 * 60) + (3 * 60) + 4).hhmmss(),
"02:03:04"
"02h:03m:04s"
);
assert_eq!(
Duration::from_secs((23 * 60 * 60) + (59 * 60) + 59).hhmmss(),
"23:59:59"
"23h:59m:59s"
);
assert_eq!(
Duration::from_secs((99 * 60 * 60) + (59 * 60) + 59).hhmmss(),
"99:59:59"
"99h:59m:59s"
);
assert_eq!(
Duration::from_secs((99 * 60 * 60) + (59 * 60) + 59 + 1).hhmmss(),
">99:59:59"
">99h:59m:59s"
);
}

Expand Down

0 comments on commit 269c626

Please sign in to comment.