Skip to content

Commit 269c626

Browse files
committed
Show time of day in logs
1 parent 4ad61fb commit 269c626

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ edition = "2021"
1717

1818
[dependencies]
1919
anyhow = "1.0.0"
20+
chrono = "0.4.0"
2021
clap = "4.0.0"
2122
libc = "0.2.0"
2223
movavg = "2.0.0"

src/disktest.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use crate::rawio::{RawIo, RawIoResult, DEFAULT_SECTOR_SIZE};
2323
use crate::stream_aggregator::{DtStreamAgg, DtStreamAggChunk};
2424
use crate::util::{prettybytes, Hhmmss};
2525
use anyhow as ah;
26+
use chrono::prelude::*;
2627
use movavg::MovAvg;
2728
use std::cmp::min;
2829
use std::path::{Path, PathBuf};
@@ -271,6 +272,8 @@ impl Disktest {
271272
let expired = now.duration_since(self.log_time).as_secs() >= LOG_SEC_THRES;
272273

273274
if (expired && self.quiet_level == DisktestQuiet::Normal) || final_step {
275+
let tod = Local::now().format("%R");
276+
274277
let dur_elapsed = now - self.begin_time;
275278

276279
let rate = if final_step {
@@ -299,11 +302,12 @@ impl Disktest {
299302
let suffix = if final_step { "." } else { " ..." };
300303

301304
println!(
302-
"{}{}{} ({}){}",
305+
"[{} / {}] {}{}{}{}",
306+
tod,
307+
dur_elapsed.hhmmss(),
303308
prefix,
304309
prettybytes(abs_processed, true, true, final_step),
305310
rate_string,
306-
dur_elapsed.hhmmss(),
307311
suffix
308312
);
309313
self.log_time = now;

src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ mod util;
3333
use crate::seed::print_generated_seed;
3434
use anyhow as ah;
3535
use args::{parse_args, Args};
36+
use chrono::prelude::*;
3637
use disktest::{Disktest, DisktestFile, DisktestQuiet};
3738
use std::env::args_os;
3839
use std::sync::atomic::AtomicBool;
@@ -87,9 +88,11 @@ fn main() -> ah::Result<()> {
8788
let mut result = Ok(());
8889
for round in args.start_round..args.rounds {
8990
if args.rounds > 1 {
91+
let tod = Local::now().format("%F %R");
9092
println!(
91-
"{}Round {} in range [{}, {}) ...",
93+
"{}[{}] Round {} in range [{}, {}) ...",
9294
if round > args.start_round { "\n" } else { "" },
95+
tod,
9396
round,
9497
args.start_round,
9598
args.rounds

src/util.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl Hhmmss for Duration {
189189
let rem = secs % (60 * 60);
190190
let m = rem / 60;
191191
let s = rem % 60;
192-
format!("{}{:02}:{:02}:{:02}", lim, h, m, s)
192+
format!("{}{:02}h:{:02}m:{:02}s", lim, h, m, s)
193193
}
194194
}
195195

@@ -382,22 +382,22 @@ mod tests {
382382

383383
#[test]
384384
fn test_hhmmss() {
385-
assert_eq!(Duration::from_secs(0).hhmmss(), "00:00:00");
385+
assert_eq!(Duration::from_secs(0).hhmmss(), "00h:00m:00s");
386386
assert_eq!(
387387
Duration::from_secs((2 * 60 * 60) + (3 * 60) + 4).hhmmss(),
388-
"02:03:04"
388+
"02h:03m:04s"
389389
);
390390
assert_eq!(
391391
Duration::from_secs((23 * 60 * 60) + (59 * 60) + 59).hhmmss(),
392-
"23:59:59"
392+
"23h:59m:59s"
393393
);
394394
assert_eq!(
395395
Duration::from_secs((99 * 60 * 60) + (59 * 60) + 59).hhmmss(),
396-
"99:59:59"
396+
"99h:59m:59s"
397397
);
398398
assert_eq!(
399399
Duration::from_secs((99 * 60 * 60) + (59 * 60) + 59 + 1).hhmmss(),
400-
">99:59:59"
400+
">99h:59m:59s"
401401
);
402402
}
403403

0 commit comments

Comments
 (0)