#![cfg(feature = "cli")]
#[global_allocator]
static ALLOC: dhat::Alloc = dhat::Alloc;
use seqtable::output::{save_csv, save_parquet};
use seqtable::{count_sequences, prepare_records};
use std::path::Path;
const FIXTURE_DIR: &str = "tests/fixtures";
fn fixture_path(name: &str) -> Option<std::path::PathBuf> {
let p = Path::new(FIXTURE_DIR).join(name);
p.exists().then_some(p)
}
#[test]
#[ignore]
fn profile_full_pipeline() {
let Some(path) = fixture_path("bn_short_mid_10000.fastq") else {
eprintln!("skip: run cargo run --example generate_fixtures --release -- --size bench");
return;
};
let _prof = dhat::Profiler::new_heap();
let (counts, total) = count_sequences(&path, 0, false).unwrap();
let records = prepare_records(counts);
let tmp = tempfile::NamedTempFile::with_suffix(".csv").unwrap();
save_csv(&records, tmp.path(), b',', total, false).unwrap();
}
#[test]
fn profile_per_phase() {
let fixtures = [
("short_low_5%", "bn_short_low_10000.fastq"),
("short_mid_50%", "bn_short_mid_10000.fastq"),
("short_high_90%", "bn_short_high_10000.fastq"),
("amp_low_5%", "bn_amp_low_10000.fastq"),
("amp_mid_50%", "bn_amp_mid_10000.fastq"),
("amp_high_90%", "bn_amp_high_10000.fastq"),
];
for (label, file) in fixtures {
let Some(path) = fixture_path(file) else {
eprintln!("skip {file} (not found)");
continue;
};
eprintln!("\n=== {label} ===");
{
let _prof = dhat::Profiler::builder().testing().build();
let (_counts, _total) = count_sequences(&path, 0, false).unwrap();
let s = dhat::HeapStats::get();
eprintln!(
" count: peak={:>10} bytes ({:>6} blocks), total={:>10} bytes ({:>6} allocs)",
s.max_bytes, s.max_blocks, s.total_bytes, s.total_blocks
);
}
let (counts, total) = {
let _prof = dhat::Profiler::builder().testing().build();
count_sequences(&path, 0, false).unwrap()
};
{
let _prof = dhat::Profiler::builder().testing().build();
let _records = prepare_records(counts.clone());
let s = dhat::HeapStats::get();
eprintln!(
" prepare: peak={:>10} bytes ({:>6} blocks), total={:>10} bytes ({:>6} allocs)",
s.max_bytes, s.max_blocks, s.total_bytes, s.total_blocks
);
}
let records = prepare_records(counts);
{
let _prof = dhat::Profiler::builder().testing().build();
let tmp = tempfile::NamedTempFile::with_suffix(".csv").unwrap();
save_csv(&records, tmp.path(), b',', total, false).unwrap();
let s = dhat::HeapStats::get();
eprintln!(
" csv: peak={:>10} bytes ({:>6} blocks), total={:>10} bytes ({:>6} allocs)",
s.max_bytes, s.max_blocks, s.total_bytes, s.total_blocks
);
}
{
let _prof = dhat::Profiler::builder().testing().build();
let tmp = tempfile::NamedTempFile::with_suffix(".parquet").unwrap();
save_parquet(
&records,
tmp.path(),
parquet::basic::Compression::ZSTD(Default::default()),
total,
false,
)
.unwrap();
let s = dhat::HeapStats::get();
eprintln!(
" parquet: peak={:>10} bytes ({:>6} blocks), total={:>10} bytes ({:>6} allocs)",
s.max_bytes, s.max_blocks, s.total_bytes, s.total_blocks
);
}
}
}