#[vor::profile]
fn foo() {
std::thread::sleep(std::time::Duration::from_micros(100));
}
#[test]
fn macro_chain_records_scopes() {
vor::enable();
let view = puffin::GlobalFrameView::default();
foo();
vor::frame_mark();
foo();
vor::frame_mark();
let view = view.lock();
assert!(puffin::are_scopes_on());
assert!(view.recent_frames().count() > 0);
assert!(!view.scope_collection().scopes_by_id().is_empty());
let mut total_scopes = 0usize;
for f in view.recent_frames() {
let unpacked = f.unpacked().unwrap();
for stream in unpacked.thread_streams.values() {
total_scopes += puffin::Reader::from_start(&stream.stream)
.read_top_scopes()
.unwrap()
.len();
}
}
assert!(total_scopes > 0);
}
struct Widget;
#[vor::all_functions]
impl Widget {
fn work(&self) {
std::thread::sleep(std::time::Duration::from_micros(100));
}
const fn answer() -> u32 {
42
}
#[vor::skip]
fn untracked(&self) {
std::thread::yield_now();
}
}
#[test]
fn all_functions_instruments_methods() {
vor::enable();
let view = puffin::GlobalFrameView::default();
let widget = Widget;
widget.work();
widget.untracked();
vor::frame_mark();
assert_eq!(Widget::answer(), 42);
let view = view.lock();
let mut total_scopes = 0usize;
for f in view.recent_frames() {
let unpacked = f.unpacked().unwrap();
for stream in unpacked.thread_streams.values() {
total_scopes += puffin::Reader::from_start(&stream.stream)
.read_top_scopes()
.unwrap()
.len();
}
}
assert!(total_scopes > 0);
}
#[test]
fn io_acc_round_trip() {
vor::record_io(123_456, 1024);
vor::record_io(7_654_321, 2048);
let tick = vor::drain_io();
assert_eq!(tick.elapsed_ns, 123_456 + 7_654_321);
assert_eq!(tick.bytes, 1024 + 2048);
let after = vor::drain_io();
assert_eq!(after.elapsed_ns, 0);
assert_eq!(after.bytes, 0);
}