use std::time::Duration;
use icedwright_trace::{
RawTaskId, RawWindowId, RealSpan, SourceLocation, StepKind, StepOutcome, TaskOrdinal,
TraceConfig, TraceMeta, TraceReader, TraceStart, TraceWriter, WindowOrdinal,
};
use icedwright_types::VirtualDuration;
fn main() -> Result<(), icedwright_trace::TraceError> {
let mut writer = TraceWriter::new(
TraceMeta::default(),
&TraceConfig::new(),
TraceStart {
boot: None,
tree: String::new(),
frame: None,
},
);
let _: WindowOrdinal = writer.ordinal(RawWindowId(7));
let mut step = writer.begin_step(
StepKind::Advance {
by: Duration::from_millis(5).into(),
},
SourceLocation::from(std::panic::Location::caller()),
VirtualDuration::ZERO,
);
let _: TaskOrdinal = step.ordinal(RawTaskId(3));
step.tree("- role: window\n".to_owned());
let real = RealSpan {
start: Duration::ZERO,
end: Duration::ZERO,
};
let _ = step.end(StepOutcome::Passed, VirtualDuration::from_millis(5), real);
let mut bytes = Vec::new();
writer.write(&mut bytes)?;
let reader = TraceReader::from_bytes(bytes)?;
for step in reader.steps() {
let _: String = reader.tree(&step.tree_after)?;
if let Some(frame) = &step.frame_after {
let _ = reader.frame(frame)?;
}
}
Ok(())
}