debug: Drop FPS struct for kms timings
This commit is contained in:
parent
0c11c0f959
commit
cc0bbb61e3
6 changed files with 44 additions and 284 deletions
207
src/state.rs
207
src/state.rs
|
|
@ -24,8 +24,6 @@ use i18n_embed::{
|
|||
};
|
||||
use once_cell::sync::Lazy;
|
||||
use rust_embed::RustEmbed;
|
||||
#[cfg(feature = "debug")]
|
||||
use smithay::utils::Rectangle;
|
||||
use smithay::{
|
||||
backend::{
|
||||
allocator::dmabuf::Dmabuf,
|
||||
|
|
@ -35,7 +33,6 @@ use smithay::{
|
|||
default_primary_scanout_output_compare, utils::select_dmabuf_feedback,
|
||||
RenderElementStates,
|
||||
},
|
||||
glow::GlowRenderer,
|
||||
ImportDma,
|
||||
},
|
||||
},
|
||||
|
|
@ -98,7 +95,6 @@ use smithay::{
|
|||
xwayland::XWaylandClientData,
|
||||
};
|
||||
use time::UtcOffset;
|
||||
use tracing::error;
|
||||
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
|
|
@ -954,206 +950,3 @@ impl Common {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Fps {
|
||||
#[cfg(feature = "debug")]
|
||||
pub rd: Option<renderdoc::RenderDoc<renderdoc::V110>>,
|
||||
#[cfg(feature = "debug")]
|
||||
pub state: smithay_egui::EguiState,
|
||||
pending_frame: Option<PendingFrame>,
|
||||
pub frames: VecDeque<Frame>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct PendingFrame {
|
||||
start: Instant,
|
||||
duration_elements: Option<Duration>,
|
||||
duration_render: Option<Duration>,
|
||||
duration_displayed: Option<Duration>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Frame {
|
||||
pub start: Instant,
|
||||
pub duration_elements: Duration,
|
||||
pub duration_render: Duration,
|
||||
pub duration_displayed: Duration,
|
||||
}
|
||||
|
||||
impl Frame {
|
||||
fn _render_time(&self) -> Duration {
|
||||
self.duration_elements + self.duration_render
|
||||
}
|
||||
|
||||
fn frame_time(&self) -> Duration {
|
||||
self.duration_elements + self.duration_render
|
||||
}
|
||||
|
||||
fn time_to_display(&self) -> Duration {
|
||||
self.duration_elements + self.duration_render + self.duration_displayed
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PendingFrame> for Frame {
|
||||
fn from(pending: PendingFrame) -> Self {
|
||||
Frame {
|
||||
start: pending.start,
|
||||
duration_elements: pending.duration_elements.unwrap_or(Duration::ZERO),
|
||||
duration_render: pending.duration_render.unwrap_or(Duration::ZERO),
|
||||
duration_displayed: pending.duration_displayed.unwrap_or(Duration::ZERO),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Fps {
|
||||
const WINDOW_SIZE: usize = 360;
|
||||
|
||||
pub fn start(&mut self) {
|
||||
self.pending_frame = Some(PendingFrame {
|
||||
start: Instant::now(),
|
||||
duration_elements: None,
|
||||
duration_render: None,
|
||||
duration_displayed: None,
|
||||
});
|
||||
}
|
||||
|
||||
pub fn elements(&mut self) {
|
||||
if let Some(frame) = self.pending_frame.as_mut() {
|
||||
frame.duration_elements = Some(Instant::now().duration_since(frame.start));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render(&mut self) {
|
||||
if let Some(frame) = self.pending_frame.as_mut() {
|
||||
frame.duration_render = Some(
|
||||
Instant::now().duration_since(frame.start)
|
||||
- frame.duration_elements.clone().unwrap_or(Duration::ZERO),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn displayed(&mut self) {
|
||||
if let Some(mut frame) = self.pending_frame.take() {
|
||||
frame.duration_displayed = Some(
|
||||
Instant::now().duration_since(frame.start)
|
||||
- frame.duration_elements.clone().unwrap_or(Duration::ZERO)
|
||||
- frame.duration_render.clone().unwrap_or(Duration::ZERO),
|
||||
);
|
||||
|
||||
self.frames.push_back(frame.into());
|
||||
while self.frames.len() > Fps::WINDOW_SIZE {
|
||||
self.frames.pop_front();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn max_frametime(&self) -> Duration {
|
||||
self.frames
|
||||
.iter()
|
||||
.map(|f| f.frame_time())
|
||||
.max()
|
||||
.unwrap_or(Duration::ZERO)
|
||||
}
|
||||
|
||||
pub fn min_frametime(&self) -> Duration {
|
||||
self.frames
|
||||
.iter()
|
||||
.map(|f| f.frame_time())
|
||||
.min()
|
||||
.unwrap_or(Duration::ZERO)
|
||||
}
|
||||
|
||||
pub fn max_time_to_display(&self) -> Duration {
|
||||
self.frames
|
||||
.iter()
|
||||
.map(|f| f.time_to_display())
|
||||
.max()
|
||||
.unwrap_or(Duration::ZERO)
|
||||
}
|
||||
|
||||
pub fn min_time_to_display(&self) -> Duration {
|
||||
self.frames
|
||||
.iter()
|
||||
.map(|f| f.time_to_display())
|
||||
.min()
|
||||
.unwrap_or(Duration::ZERO)
|
||||
}
|
||||
|
||||
pub fn avg_frametime(&self) -> Duration {
|
||||
if self.frames.is_empty() {
|
||||
return Duration::ZERO;
|
||||
}
|
||||
self.frames.iter().map(|f| f.frame_time()).sum::<Duration>() / (self.frames.len() as u32)
|
||||
}
|
||||
|
||||
pub fn avg_time_to_display(&self, window: usize) -> Duration {
|
||||
self.frames
|
||||
.iter()
|
||||
.rev()
|
||||
.take(window)
|
||||
.map(|f| f.time_to_display())
|
||||
.sum::<Duration>()
|
||||
/ window as u32
|
||||
}
|
||||
|
||||
pub fn avg_fps(&self) -> f64 {
|
||||
if self.frames.is_empty() {
|
||||
return 0.0;
|
||||
}
|
||||
let secs = match (self.frames.front(), self.frames.back()) {
|
||||
(Some(Frame { start, .. }), Some(end_frame)) => {
|
||||
end_frame.start.duration_since(*start) + end_frame.frame_time()
|
||||
}
|
||||
_ => Duration::ZERO,
|
||||
}
|
||||
.as_secs_f64();
|
||||
1.0 / (secs / self.frames.len() as f64)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "debug")]
|
||||
static INTEL_LOGO: &'static [u8] = include_bytes!("../resources/icons/intel.svg");
|
||||
#[cfg(feature = "debug")]
|
||||
static AMD_LOGO: &'static [u8] = include_bytes!("../resources/icons/amd.svg");
|
||||
#[cfg(feature = "debug")]
|
||||
static NVIDIA_LOGO: &'static [u8] = include_bytes!("../resources/icons/nvidia.svg");
|
||||
|
||||
impl Fps {
|
||||
pub fn new(_renderer: &mut GlowRenderer) -> Fps {
|
||||
#[cfg(feature = "debug")]
|
||||
let state = {
|
||||
let state = smithay_egui::EguiState::new(smithay::utils::Rectangle::from_loc_and_size(
|
||||
(0, 0),
|
||||
(400, 800),
|
||||
));
|
||||
let mut visuals: egui::style::Visuals = Default::default();
|
||||
visuals.window_shadow.extrusion = 0.0;
|
||||
state.context().set_visuals(visuals);
|
||||
state
|
||||
.load_svg(_renderer, String::from("intel"), INTEL_LOGO)
|
||||
.unwrap();
|
||||
state
|
||||
.load_svg(_renderer, String::from("amd"), AMD_LOGO)
|
||||
.unwrap();
|
||||
state
|
||||
.load_svg(_renderer, String::from("nvidia"), NVIDIA_LOGO)
|
||||
.unwrap();
|
||||
state
|
||||
};
|
||||
|
||||
Fps {
|
||||
#[cfg(feature = "debug")]
|
||||
state,
|
||||
#[cfg(feature = "debug")]
|
||||
rd: renderdoc::RenderDoc::new().ok(),
|
||||
pending_frame: None,
|
||||
frames: VecDeque::with_capacity(Fps::WINDOW_SIZE + 1),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn avg_fps<'a>(iter: impl Iterator<Item = &'a Duration>) -> f64 {
|
||||
let sum_secs = iter.map(|d| d.as_secs_f64()).sum::<f64>();
|
||||
1.0 / (sum_secs / Fps::WINDOW_SIZE as f64)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue