Skip to content

Commit 4b0bbdf

Browse files
committed
write time and duration to LOG file
1 parent 7f46f09 commit 4b0bbdf

File tree

1 file changed

+37
-26
lines changed
  • turbopack/crates/turbo-persistence/src

1 file changed

+37
-26
lines changed

turbopack/crates/turbo-persistence/src/db.rs

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::{
99
atomic::{AtomicBool, AtomicU32, Ordering},
1010
Arc,
1111
},
12+
time::Instant,
1213
};
1314

1415
use anyhow::{bail, Context, Result};
@@ -436,6 +437,9 @@ impl TurboPersistence {
436437
mut indicies_to_delete: Vec<usize>,
437438
mut seq: u32,
438439
) -> Result<(), anyhow::Error> {
440+
let time = Local::now();
441+
let start = Instant::now();
442+
439443
new_sst_files.sort_unstable_by_key(|(seq, _)| *seq);
440444

441445
let mut new_sst_files = new_sst_files
@@ -450,34 +454,18 @@ impl TurboPersistence {
450454
file.sync_all()?;
451455
}
452456

453-
if !indicies_to_delete.is_empty() {
454-
seq += 1;
455-
}
456-
457-
{
458-
let mut log = self.open_log()?;
459-
let time = Local::now();
460-
writeln!(log, "Commit {seq:08} {}", time.format("%Y-%m-%d %H:%M"))?;
461-
for sst in new_sst_files.iter() {
462-
let index = sst.sequence_number();
457+
let new_sst_info = new_sst_files
458+
.iter()
459+
.map(|sst| {
460+
let seq = sst.sequence_number();
463461
let range = sst.range()?;
464462
let size = sst.size();
465-
writeln!(
466-
log,
467-
"{:08} SST family:{} {:016x}-{:016x} {} MiB",
468-
index,
469-
range.family,
470-
range.min_hash,
471-
range.max_hash,
472-
size / 1024 / 1024
473-
)?;
474-
}
475-
for (seq, _) in new_blob_files.iter() {
476-
writeln!(log, "{:08} BLOB", seq)?;
477-
}
478-
for index in indicies_to_delete.iter() {
479-
writeln!(log, "{:08} DELETED", index)?;
480-
}
463+
Ok((seq, range.family, range.min_hash, range.max_hash, size))
464+
})
465+
.collect::<Result<Vec<_>>>()?;
466+
467+
if !indicies_to_delete.is_empty() {
468+
seq += 1;
481469
}
482470

483471
let removed_ssts;
@@ -519,6 +507,29 @@ impl TurboPersistence {
519507
fs::remove_file(self.path.join(format!("{seq:08}.sst")))?;
520508
}
521509

510+
{
511+
let mut log = self.open_log()?;
512+
writeln!(log, "Time {}", time.format("%Y-%m-%d %H:%M"))?;
513+
writeln!(log, "Commit {seq:08} {:?}", start.elapsed())?;
514+
for (index, family, min, max, size) in new_sst_info.iter() {
515+
writeln!(
516+
log,
517+
"{:08} SST family:{} {:016x}-{:016x} {} MiB",
518+
index,
519+
family,
520+
min,
521+
max,
522+
size / 1024 / 1024
523+
)?;
524+
}
525+
for (seq, _) in new_blob_files.iter() {
526+
writeln!(log, "{:08} BLOB", seq)?;
527+
}
528+
for index in indicies_to_delete.iter() {
529+
writeln!(log, "{:08} DELETED", index)?;
530+
}
531+
}
532+
522533
Ok(())
523534
}
524535

0 commit comments

Comments
 (0)