2025-10-30 11:17:20 -07:00
|
|
|
use rply_codec::{Counter, Frame, Timer, counts, decode, encode, stats};
|
2025-10-28 15:38:00 -07:00
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
let args: Vec<_> = std::env::args().collect();
|
|
|
|
|
let file =
|
|
|
|
|
std::fs::File::open(args.get(1).unwrap_or(&"examples/bobl.replay".to_string())).unwrap();
|
2025-10-29 12:37:33 -07:00
|
|
|
let outfile = std::fs::File::create(
|
2025-10-28 15:38:00 -07:00
|
|
|
args.get(2)
|
|
|
|
|
.unwrap_or(&"examples/bobl_smallblocks.replay".to_string()),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
let mut file = std::io::BufReader::new(file);
|
|
|
|
|
let mut outfile = std::io::BufWriter::new(outfile);
|
|
|
|
|
let mut rply = decode(&mut file).unwrap();
|
|
|
|
|
let header = &rply.header;
|
|
|
|
|
println!("{header:?}");
|
|
|
|
|
let mut header_out = header.clone();
|
|
|
|
|
header_out.set_block_size(64);
|
2025-10-30 11:17:20 -07:00
|
|
|
header_out.set_superblock_size(32);
|
2025-10-28 15:38:00 -07:00
|
|
|
let mut out = encode(header_out, &rply.initial_state, &mut outfile).unwrap();
|
|
|
|
|
let mut frame = Frame::default();
|
|
|
|
|
while let Ok(()) = rply
|
|
|
|
|
.read_frame(&mut frame)
|
|
|
|
|
.inspect_err(|e| println!("Err: {e}"))
|
|
|
|
|
{
|
|
|
|
|
println!(
|
|
|
|
|
" {}{:08} {}",
|
|
|
|
|
if frame.checkpoint_bytes.is_empty() {
|
|
|
|
|
" "
|
|
|
|
|
} else {
|
|
|
|
|
"*"
|
|
|
|
|
},
|
|
|
|
|
rply.frame_number,
|
|
|
|
|
frame.inputs(),
|
|
|
|
|
);
|
|
|
|
|
out.write_frame(&frame).unwrap();
|
|
|
|
|
if Some(rply.frame_number) == rply.header.frame_count() {
|
|
|
|
|
println!("Done!");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
out.finish().unwrap();
|
|
|
|
|
assert_eq!(out.frame_number, rply.frame_number);
|
|
|
|
|
assert_eq!(out.header.frame_count(), rply.header.frame_count());
|
2025-10-29 12:37:33 -07:00
|
|
|
assert_eq!(out.header.frame_count(), Some(out.frame_number));
|
2025-10-30 11:17:20 -07:00
|
|
|
for timer in [
|
|
|
|
|
Timer::DecodeFrame,
|
|
|
|
|
Timer::DecodeCheckpoint,
|
|
|
|
|
Timer::DecodeStatestream,
|
|
|
|
|
Timer::EncodeStatestream,
|
|
|
|
|
Timer::EncodeCheckpoint,
|
|
|
|
|
Timer::EncodeStatestream,
|
|
|
|
|
] {
|
|
|
|
|
let times = stats(timer);
|
2025-10-30 12:53:59 -07:00
|
|
|
#[allow(clippy::cast_precision_loss)]
|
|
|
|
|
let avg_time = (times.micros as f64 / times.count as f64) / 1000.0;
|
|
|
|
|
println!("{timer:?}: {} ({avg_time:.8}ms avg)", times.count,);
|
2025-10-30 11:17:20 -07:00
|
|
|
}
|
|
|
|
|
for counter in [
|
|
|
|
|
Counter::EncReusedBlocks,
|
|
|
|
|
Counter::EncReusedSuperblocks,
|
|
|
|
|
Counter::EncSkippedBlocks,
|
|
|
|
|
Counter::EncMemCmps,
|
|
|
|
|
Counter::EncHashes,
|
|
|
|
|
Counter::EncTotalBlocks,
|
|
|
|
|
Counter::EncTotalSuperblocks,
|
|
|
|
|
Counter::EncTotalKBsIn,
|
|
|
|
|
Counter::EncTotalKBsOut,
|
|
|
|
|
] {
|
|
|
|
|
println!("{counter:?}: {}", counts(counter));
|
|
|
|
|
}
|
2025-10-28 15:38:00 -07:00
|
|
|
}
|