use std::thread; use std::time::Duration; use teleprof::instrument; fn main() { // Start the telemetry window teleprof::start(); println!("Teleprof demo running..."); println!("Press Space in the profiler window to pause/unpause"); println!("Mouse wheel to zoom, drag to pan"); println!("Press Escape in the profiler window to quit"); println!(); // Simulate some work for i in 0..1000 { frame_work(i); // Check if paused if teleprof::PAUSE.try_lock().is_err() { println!("Paused!"); while teleprof::PAUSE.try_lock().is_err() { thread::sleep(Duration::from_millis(100)); } println!("Resumed!"); } thread::sleep(Duration::from_millis(16)); } } #[instrument] fn frame_work(frame: u32) { physics_update(); render(); if frame % 10 == 0 { occasional_task(); } } #[instrument] fn physics_update() { // Spawn some worker threads let handles: Vec<_> = (0..3).map(|i| { thread::spawn(move || { physics_worker(i); }) }).collect(); for handle in handles { handle.join().ok(); } } #[instrument] fn physics_worker(id: u32) { // Simulate work let work_ms = 5 + (id * 2); thread::sleep(Duration::from_millis(work_ms as u64)); } #[instrument] fn render() { build_command_buffer(); submit_to_gpu(); } #[instrument] fn build_command_buffer() { thread::sleep(Duration::from_millis(3)); } #[instrument] fn submit_to_gpu() { thread::sleep(Duration::from_millis(2)); } #[instrument] fn occasional_task() { thread::sleep(Duration::from_millis(10)); }