Move to tracing with tracy support
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Has been cancelled

This commit is contained in:
Florian RICHER 2025-05-30 23:27:03 +02:00
parent 8a57094478
commit d765e78da4
Signed by: florian.richer
GPG key ID: C73D37CBED7BFC77
8 changed files with 369 additions and 158 deletions

View file

@ -91,7 +91,7 @@ impl ApplicationContext {
})
.collect();
log::trace!(
tracing::trace!(
"Modes vidéo trouvés pour {:?}: {:?}",
monitor.name(),
resolutions

View file

@ -129,7 +129,7 @@ impl ApplicationHandler<UserEvent> for App {
match event {
WindowEvent::CloseRequested => {
log::debug!("The close button was pressed; stopping");
tracing::debug!("The close button was pressed; stopping");
event_loop.exit();
}
WindowEvent::Resized(_) | WindowEvent::ScaleFactorChanged { .. } => {
@ -137,7 +137,10 @@ impl ApplicationHandler<UserEvent> for App {
vulkano_windows.get_renderer_mut(id).unwrap().resize();
}
WindowEvent::RedrawRequested => {
let _frame_span = tracing::info_span!("frame").entered();
{
let _input_span = tracing::debug_span!("input_update").entered();
let mut input_manager = self
.input_manager
.write()
@ -145,6 +148,7 @@ impl ApplicationHandler<UserEvent> for App {
input_manager.update();
}
{
let _timer_span = tracing::debug_span!("timer_update").entered();
let mut timer = self.timer.write().expect("Failed to lock timer");
timer.update();
}
@ -170,6 +174,7 @@ impl ApplicationHandler<UserEvent> for App {
// Utiliser le contexte partagé pour les scènes
{
let _scene_span = tracing::info_span!("scene_processing").entered();
let mut context = app_context.write().unwrap();
scene_manager
@ -177,18 +182,31 @@ impl ApplicationHandler<UserEvent> for App {
.unwrap();
if let Some(scene) = scene_manager.current_scene_mut() {
scene.update(&mut context).unwrap();
{
let _update_span = tracing::debug_span!("scene_update").entered();
scene.update(&mut context).unwrap();
}
let acquire_future = context
.with_renderer_mut(|renderer| renderer.acquire(None, |_| {}).unwrap());
let acquire_future = {
let _acquire_span = tracing::debug_span!("acquire_swapchain").entered();
context.with_renderer_mut(|renderer| {
renderer.acquire(None, |_| {}).unwrap()
})
};
let acquire_future = scene.render(acquire_future, &mut context).unwrap();
let acquire_future = {
let _render_span = tracing::debug_span!("scene_render").entered();
scene.render(acquire_future, &mut context).unwrap()
};
context.with_renderer_mut(|renderer| {
renderer.present(acquire_future, true);
});
{
let _present_span = tracing::debug_span!("present_frame").entered();
context.with_renderer_mut(|renderer| {
renderer.present(acquire_future, true);
});
}
} else {
log::warn!("No current scene found for update!");
tracing::warn!("No current scene found for update!");
}
}
}
@ -208,7 +226,7 @@ impl ApplicationHandler<UserEvent> for App {
let vulkano_windows = self.vulkano_windows.read().unwrap();
let window = vulkano_windows.get_window(window_id).unwrap();
if let Err(e) = window.set_cursor_grab(grab) {
log::error!("Failed to set cursor grab: {}", e);
tracing::error!("Failed to set cursor grab: {}", e);
}
}
UserEvent::CursorVisible(window_id, visible) => {
@ -227,7 +245,7 @@ impl ApplicationHandler<UserEvent> for App {
let _ = window.request_inner_size(winit::dpi::LogicalSize::new(width, height));
let renderer = vulkano_windows.get_renderer_mut(window_id).unwrap();
renderer.resize();
log::info!(
tracing::info!(
"Resolution changed to {}x{} for window {:?}",
width,
height,
@ -235,7 +253,7 @@ impl ApplicationHandler<UserEvent> for App {
);
}
UserEvent::Exit(window_id) => {
log::info!("Exit requested for window {:?}", window_id);
tracing::info!("Exit requested for window {:?}", window_id);
event_loop.exit();
}
}

View file

@ -31,8 +31,10 @@ impl Texture {
builder: &mut AutoCommandBufferBuilder<PrimaryAutoCommandBuffer>,
path: &str,
) -> Result<Self, Error> {
let image = image::open(path)?;
Self::from_dynamic_image(device, memory_allocator, builder, image)
let _span = tracing::info_span!("texture_load_from_file", path = path);
let bytes = std::fs::read(path)?;
Self::from_bytes(device, memory_allocator, builder, &bytes)
}
pub fn from_bytes(
@ -51,8 +53,11 @@ impl Texture {
builder: &mut AutoCommandBufferBuilder<PrimaryAutoCommandBuffer>,
image: DynamicImage,
) -> Result<Self, Error> {
let _span = tracing::info_span!("texture_from_dynamic_image");
let image_data = image.to_rgba8();
let image_dimensions = image_data.dimensions();
let image_data = image_data.into_raw();
let upload_buffer = Buffer::new_slice(
memory_allocator.clone(),
@ -70,7 +75,7 @@ impl Texture {
{
let buffer_data = &mut *upload_buffer.write()?;
buffer_data.copy_from_slice(image_data.as_raw());
buffer_data.copy_from_slice(&image_data);
}
let image = Image::new(
@ -103,7 +108,7 @@ impl Texture {
let image_view = ImageView::new_default(image)?;
log::trace!("Texture loaded with dimensions {:?}", image_dimensions);
tracing::trace!("Texture loaded with dimensions {:?}", image_dimensions);
Ok(Self::new(image_view, sampler))
}

View file

@ -58,7 +58,7 @@ impl SceneManager {
scene.load(app_context)?;
}
} else {
log::warn!("No scene found in SceneManager!");
tracing::warn!("No scene found in SceneManager!");
}
Ok(())
}

View file

@ -13,7 +13,23 @@ mod core;
mod game;
fn main() {
env_logger::init();
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
tracing_subscriber::registry()
.with(
tracing_subscriber::fmt::layer()
.with_target(true)
.with_thread_ids(true)
.with_file(true)
.with_line_number(true),
)
.with(tracing_tracy::TracyLayer::default())
.with(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info")),
)
.init();
let input_manager = InputManager::new(HashMap::from([
(
@ -86,7 +102,7 @@ fn main() {
match event_loop.run_app(&mut app) {
Ok(_) => {}
Err(e) => {
log::error!("Error running old app: {e}");
tracing::error!("Error running old app: {e}");
}
}
}