Improve profiler interface

This commit is contained in:
Simon Gellis 2025-09-01 17:38:00 -04:00
parent 8f9922473e
commit 6e89a0c988
1 changed files with 55 additions and 19 deletions

View File

@ -1,17 +1,18 @@
use std::{fs, time::Duration}; use std::{fs, time::Duration};
use anyhow::Result; use anyhow::Result;
use egui::{Button, CentralPanel, Checkbox, ViewportBuilder, ViewportId}; use egui::{Button, CentralPanel, Checkbox, Label, ViewportBuilder, ViewportId};
use egui_notify::{Anchor, Toast, Toasts}; use egui_notify::{Anchor, Toast, Toasts};
use crate::{ use crate::{
emulator::{EmulatorClient, SimId}, emulator::{EmulatorClient, EmulatorCommand, EmulatorState, SimId},
profiler::{Profiler, ProfilerStatus}, profiler::{Profiler, ProfilerStatus},
window::AppWindow, window::AppWindow,
}; };
pub struct ProfileWindow { pub struct ProfileWindow {
sim_id: SimId, sim_id: SimId,
client: EmulatorClient,
profiler: Profiler, profiler: Profiler,
toasts: Toasts, toasts: Toasts,
} }
@ -20,6 +21,7 @@ impl ProfileWindow {
pub fn new(sim_id: SimId, client: EmulatorClient) -> Self { pub fn new(sim_id: SimId, client: EmulatorClient) -> Self {
Self { Self {
sim_id, sim_id,
client: client.clone(),
profiler: Profiler::new(sim_id, client), profiler: Profiler::new(sim_id, client),
toasts: Toasts::new() toasts: Toasts::new()
.with_anchor(Anchor::BottomLeft) .with_anchor(Anchor::BottomLeft)
@ -33,6 +35,10 @@ impl ProfileWindow {
} }
fn finish_recording(&mut self) { fn finish_recording(&mut self) {
let pause = matches!(self.client.emulator_state(), EmulatorState::Running);
if pause {
self.client.send_command(EmulatorCommand::Pause);
}
match self.try_finish_recording() { match self.try_finish_recording() {
Ok(Some(path)) => { Ok(Some(path)) => {
let mut toast = Toast::info(format!("Saved to {path}")); let mut toast = Toast::info(format!("Saved to {path}"));
@ -46,6 +52,9 @@ impl ProfileWindow {
self.toasts.add(toast); self.toasts.add(toast);
} }
} }
if pause {
self.client.send_command(EmulatorCommand::Resume);
}
} }
fn try_finish_recording(&mut self) -> Result<Option<String>> { fn try_finish_recording(&mut self) -> Result<Option<String>> {
@ -84,8 +93,32 @@ impl AppWindow for ProfileWindow {
let status = self.profiler.status(); let status = self.profiler.status();
let recording = matches!(status, ProfilerStatus::Recording); let recording = matches!(status, ProfilerStatus::Recording);
CentralPanel::default().show(ctx, |ui| { CentralPanel::default().show(ctx, |ui| {
ui.horizontal_wrapped(|ui| {
ui.spacing_mut().item_spacing.x = 0.0;
ui.add(
Label::new(
"Use this tool to record performance profiles of your game, for use in ",
)
.wrap_mode(egui::TextWrapMode::Wrap),
);
ui.hyperlink("https://profiler.firefox.com");
ui.label(".");
});
ui.horizontal_wrapped(|ui| {
ui.spacing_mut().item_spacing.x = 0.0;
ui.add(
Label::new("For more instructions, see ").wrap_mode(egui::TextWrapMode::Wrap),
);
ui.hyperlink_to(
"the Lemur wiki",
"https://git.virtual-boy.com/PVB/lemur/wiki/Profiling-with-Lemur",
);
ui.label(".");
});
ui.separator();
let mut enabled = status.enabled(); let mut enabled = status.enabled();
let enabled_checkbox = Checkbox::new(&mut enabled, "Profiling enabled?"); let enabled_checkbox = Checkbox::new(&mut enabled, "Enable profiling");
if ui.add_enabled(!recording, enabled_checkbox).changed() { if ui.add_enabled(!recording, enabled_checkbox).changed() {
if enabled { if enabled {
self.profiler.enable(); self.profiler.enable();
@ -93,7 +126,9 @@ impl AppWindow for ProfileWindow {
self.profiler.disable(); self.profiler.disable();
} }
} }
if !enabled {
ui.label("Enabling profiling will restart your current game.");
} else {
ui.horizontal(|ui| { ui.horizontal(|ui| {
if !recording { if !recording {
let record_button = Button::new("Record"); let record_button = Button::new("Record");
@ -110,6 +145,7 @@ impl AppWindow for ProfileWindow {
} }
} }
}); });
}
match &status { match &status {
ProfilerStatus::Recording => { ProfilerStatus::Recording => {