notedeck: include frame history
for debugging. Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -2,8 +2,8 @@ use crate::persist::{AppSizeHandler, ZoomHandler};
|
||||
use crate::wallet::GlobalWallet;
|
||||
use crate::zaps::Zaps;
|
||||
use crate::{
|
||||
AccountStorage, Accounts, AppContext, Args, DataPath, DataPathType, Directory, Images,
|
||||
NoteCache, RelayDebugView, ThemeHandler, UnknownIds,
|
||||
frame_history::FrameHistory, AccountStorage, Accounts, AppContext, Args, DataPath,
|
||||
DataPathType, Directory, Images, NoteCache, RelayDebugView, ThemeHandler, UnknownIds,
|
||||
};
|
||||
use egui::ThemePreference;
|
||||
use egui_winit::clipboard::Clipboard;
|
||||
@@ -37,6 +37,7 @@ pub struct Notedeck {
|
||||
unrecognized_args: BTreeSet<String>,
|
||||
clipboard: Clipboard,
|
||||
zaps: Zaps,
|
||||
frame_history: FrameHistory,
|
||||
}
|
||||
|
||||
/// Our chrome, which is basically nothing
|
||||
@@ -79,8 +80,10 @@ fn render_notedeck(notedeck: &mut Notedeck, ctx: &egui::Context) {
|
||||
}
|
||||
|
||||
impl eframe::App for Notedeck {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
||||
profiling::finish_frame!();
|
||||
self.frame_history
|
||||
.on_new_frame(ctx.input(|i| i.time), frame.info().cpu_usage);
|
||||
|
||||
// handle account updates
|
||||
self.accounts.update(&mut self.ndb, &mut self.pool, ctx);
|
||||
@@ -227,6 +230,7 @@ impl Notedeck {
|
||||
zoom,
|
||||
app_size,
|
||||
unrecognized_args,
|
||||
frame_history: FrameHistory::default(),
|
||||
clipboard: Clipboard::new(None),
|
||||
zaps,
|
||||
}
|
||||
@@ -251,6 +255,7 @@ impl Notedeck {
|
||||
theme: &mut self.theme,
|
||||
clipboard: &mut self.clipboard,
|
||||
zaps: &mut self.zaps,
|
||||
frame_history: &mut self.frame_history,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
wallet::GlobalWallet, zaps::Zaps, Accounts, Args, DataPath, Images, NoteCache, ThemeHandler,
|
||||
UnknownIds,
|
||||
frame_history::FrameHistory, wallet::GlobalWallet, zaps::Zaps, Accounts, Args, DataPath,
|
||||
Images, NoteCache, ThemeHandler, UnknownIds,
|
||||
};
|
||||
use egui_winit::clipboard::Clipboard;
|
||||
|
||||
@@ -22,4 +22,5 @@ pub struct AppContext<'a> {
|
||||
pub theme: &'a mut ThemeHandler,
|
||||
pub clipboard: &'a mut Clipboard,
|
||||
pub zaps: &'a mut Zaps,
|
||||
pub frame_history: &'a mut FrameHistory,
|
||||
}
|
||||
|
||||
48
crates/notedeck/src/frame_history.rs
Normal file
48
crates/notedeck/src/frame_history.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
use egui::util::History;
|
||||
|
||||
pub struct FrameHistory {
|
||||
frame_times: History<f32>,
|
||||
}
|
||||
|
||||
impl Default for FrameHistory {
|
||||
fn default() -> Self {
|
||||
let max_age: f32 = 1.0;
|
||||
let max_len = (max_age * 300.0).round() as usize;
|
||||
Self {
|
||||
frame_times: History::new(0..max_len, max_age),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FrameHistory {
|
||||
// Called first
|
||||
pub fn on_new_frame(&mut self, now: f64, previous_frame_time: Option<f32>) {
|
||||
let previous_frame_time = previous_frame_time.unwrap_or_default();
|
||||
if let Some(latest) = self.frame_times.latest_mut() {
|
||||
*latest = previous_frame_time; // rewrite history now that we know
|
||||
}
|
||||
self.frame_times.add(now, previous_frame_time); // projected
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn mean_frame_time(&self) -> f32 {
|
||||
self.frame_times.average().unwrap_or_default()
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn fps(&self) -> f32 {
|
||||
1.0 / self.frame_times.mean_time_interval().unwrap_or_default()
|
||||
}
|
||||
|
||||
pub fn _ui(&mut self, ui: &mut egui::Ui) {
|
||||
ui.label(format!(
|
||||
"Mean CPU usage: {:.2} ms / frame",
|
||||
1e3 * self.mean_frame_time()
|
||||
))
|
||||
.on_hover_text(
|
||||
"Includes egui layout and tessellation time.\n\
|
||||
Does not include GPU usage, nor overhead for sending data to GPU.",
|
||||
);
|
||||
egui::warn_if_debug_build(ui);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ pub mod debouncer;
|
||||
mod error;
|
||||
pub mod filter;
|
||||
pub mod fonts;
|
||||
mod frame_history;
|
||||
mod imgcache;
|
||||
mod muted;
|
||||
pub mod note;
|
||||
|
||||
Reference in New Issue
Block a user