first commit, not pretty
This commit is contained in:
83
examples/demo.rs
Normal file
83
examples/demo.rs
Normal file
@@ -0,0 +1,83 @@
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
fn main() {
|
||||
// Start the telemetry window
|
||||
teleprof::start();
|
||||
|
||||
println!("Teleprof demo running...");
|
||||
println!("Press Space in the profiler window to pause/unpause");
|
||||
println!("Press Escape in the profiler window to quit");
|
||||
|
||||
// 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));
|
||||
}
|
||||
}
|
||||
|
||||
fn frame_work(frame: u32) {
|
||||
teleprof::span!("frame_work");
|
||||
|
||||
physics_update();
|
||||
render();
|
||||
|
||||
if frame % 10 == 0 {
|
||||
occasional_task();
|
||||
}
|
||||
}
|
||||
|
||||
fn physics_update() {
|
||||
teleprof::span!("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();
|
||||
}
|
||||
}
|
||||
|
||||
fn physics_worker(id: u32) {
|
||||
teleprof::span!("physics_worker");
|
||||
|
||||
// Simulate work
|
||||
let work_ms = 5 + (id * 2);
|
||||
thread::sleep(Duration::from_millis(work_ms as u64));
|
||||
}
|
||||
|
||||
fn render() {
|
||||
teleprof::span!("render");
|
||||
|
||||
build_command_buffer();
|
||||
submit_to_gpu();
|
||||
}
|
||||
|
||||
fn build_command_buffer() {
|
||||
teleprof::span!("build_command_buffer");
|
||||
thread::sleep(Duration::from_millis(3));
|
||||
}
|
||||
|
||||
fn submit_to_gpu() {
|
||||
teleprof::span!("submit_to_gpu");
|
||||
thread::sleep(Duration::from_millis(2));
|
||||
}
|
||||
|
||||
fn occasional_task() {
|
||||
teleprof::span!("occasional_task");
|
||||
thread::sleep(Duration::from_millis(10));
|
||||
}
|
||||
Reference in New Issue
Block a user