better already

This commit is contained in:
2025-12-11 06:40:15 +01:00
parent 4930d86e23
commit 06b8cac896
3 changed files with 362 additions and 66 deletions

View File

@@ -2,6 +2,7 @@ use minifb::{Key, Window, WindowOptions};
use std::thread;
use std::time::{Duration, Instant};
use std::sync::{Arc, Mutex};
use std::sync::atomic::{AtomicUsize, Ordering};
use rand::Rng;
use teleprof::instrument;
@@ -9,6 +10,8 @@ const WIDTH: usize = 800;
const HEIGHT: usize = 600;
const BALL_RADIUS: usize = 20;
static COLOR_PICKER_COUNTER: AtomicUsize = AtomicUsize::new(0);
struct Ball {
x: f32,
y: f32,
@@ -94,8 +97,9 @@ fn main_frame(
// If we hit a wall, spawn a thread to pick a new color
if hit_wall {
let ball_clone = Arc::clone(ball);
let id = COLOR_PICKER_COUNTER.fetch_add(1, Ordering::Relaxed);
thread::spawn(move || {
teleprof::set_thread_name("ColorPicker");
teleprof::set_thread_name(format!("ColorPicker-{}", id));
pick_new_color(ball_clone);
});
}

View File

@@ -5,6 +5,9 @@ use teleprof::instrument;
fn main() {
// Start the telemetry window
teleprof::start();
// Name the main thread
teleprof::set_thread_name("Main");
println!("Teleprof demo running...");
println!("Press Space in the profiler window to pause/unpause");
@@ -44,6 +47,7 @@ fn physics_update() {
// Spawn some worker threads
let handles: Vec<_> = (0..3).map(|i| {
thread::spawn(move || {
teleprof::set_thread_name(format!("Physics-{}", i));
physics_worker(i);
})
}).collect();