|
|
@ -72,10 +72,11 @@ async fn normal(cfg: config::Config) -> eyre::Result<()>
|
|
|
|
match cfg.serialise_output.as_ref().map(|ser_out| {
|
|
|
|
match cfg.serialise_output.as_ref().map(|ser_out| {
|
|
|
|
type BoxedWrite = Box<dyn tokio::io::AsyncWrite + Unpin>;
|
|
|
|
type BoxedWrite = Box<dyn tokio::io::AsyncWrite + Unpin>;
|
|
|
|
use futures::FutureExt;
|
|
|
|
use futures::FutureExt;
|
|
|
|
|
|
|
|
use config::OutputSerialisationMode;
|
|
|
|
match ser_out {
|
|
|
|
match ser_out {
|
|
|
|
Some(output_file) => {
|
|
|
|
OutputSerialisationMode::File(output_file) => {
|
|
|
|
use tokio::fs::OpenOptions;
|
|
|
|
use tokio::fs::OpenOptions;
|
|
|
|
async move {
|
|
|
|
(async move {
|
|
|
|
let stream = OpenOptions::new()
|
|
|
|
let stream = OpenOptions::new()
|
|
|
|
.write(true)
|
|
|
|
.write(true)
|
|
|
|
.truncate(true)
|
|
|
|
.truncate(true)
|
|
|
@ -85,16 +86,42 @@ async fn normal(cfg: config::Config) -> eyre::Result<()>
|
|
|
|
.with_section(|| format!("{:?}", output_file).header("File was"))?;
|
|
|
|
.with_section(|| format!("{:?}", output_file).header("File was"))?;
|
|
|
|
|
|
|
|
|
|
|
|
Ok::<BoxedWrite, eyre::Report>(Box::new(stream))
|
|
|
|
Ok::<BoxedWrite, eyre::Report>(Box::new(stream))
|
|
|
|
}.boxed()
|
|
|
|
}.boxed(), None)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
OutputSerialisationMode::Stdout => (async move { Ok::<BoxedWrite, _>(Box::new(tokio::io::stdout())) }.boxed(), None),
|
|
|
|
|
|
|
|
#[cfg(feature="prealloc")] OutputSerialisationMode::PreallocFile(output_file) => {
|
|
|
|
|
|
|
|
(async move {
|
|
|
|
|
|
|
|
Ok::<BoxedWrite, _>(Box::new(tokio::io::sink())) // we use a sink as a shim stream since it will never be used when tuple item `.1` is Some()
|
|
|
|
|
|
|
|
}.boxed(), Some(output_file))
|
|
|
|
},
|
|
|
|
},
|
|
|
|
None => async move { Ok::<BoxedWrite, _>(Box::new(tokio::io::stdout())) }.boxed(),
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}) {
|
|
|
|
}) {
|
|
|
|
Some(stream_fut) => {
|
|
|
|
// We use tuple item `.1` here to indicate if we're in normal write mode.
|
|
|
|
|
|
|
|
// None -> normal
|
|
|
|
|
|
|
|
// Some(path) -> prealloc
|
|
|
|
|
|
|
|
Some((stream_fut, None)) => {
|
|
|
|
let stream = stream_fut.await?;
|
|
|
|
let stream = stream_fut.await?;
|
|
|
|
serial::write_async(stream, &graph).await
|
|
|
|
serial::write_async(stream, &graph).await
|
|
|
|
.wrap_err(eyre!("Failed to serialise graph to stream"))?;
|
|
|
|
.wrap_err(eyre!("Failed to serialise graph to stream"))?;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
#[cfg(feature="prealloc")] Some((_task_fut, Some(output_file))) => {
|
|
|
|
|
|
|
|
use tokio::fs::OpenOptions;
|
|
|
|
|
|
|
|
let file = OpenOptions::new()
|
|
|
|
|
|
|
|
.write(true)
|
|
|
|
|
|
|
|
.read(true) //needed for map I think?
|
|
|
|
|
|
|
|
.truncate(true)
|
|
|
|
|
|
|
|
.create(true)
|
|
|
|
|
|
|
|
.open(&output_file).await
|
|
|
|
|
|
|
|
.wrap_err(eyre!("Failed to open file for mapping"))
|
|
|
|
|
|
|
|
.with_section(|| format!("{:?}", output_file).header("File was"))?;
|
|
|
|
|
|
|
|
let mut file = file.into_std().await;
|
|
|
|
|
|
|
|
tokio::task::spawn_blocking(move || {
|
|
|
|
|
|
|
|
serial::write_sync_map(&mut file, &graph)
|
|
|
|
|
|
|
|
}).await.wrap_err(eyre!("Prealloc panicked while dumping"))
|
|
|
|
|
|
|
|
.with_section(|| format!("{:?}", output_file).header("File was"))?
|
|
|
|
|
|
|
|
.wrap_err(eyre!("Prealloc failed to dump graph to file"))
|
|
|
|
|
|
|
|
.with_section(|| format!("{:?}", output_file).header("File was"))?;
|
|
|
|
|
|
|
|
},
|
|
|
|
_ => (),
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|