Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

gpui: Frame time debug overlay (#62749)

Cameron Mcloughlin07a0bd1220bd
diff --git a/assets/keymaps/default-linux.json b/assets/keymaps/default-linux.json
index 239129d9d4a..9b940924714 100644
--- a/assets/keymaps/default-linux.json
+++ b/assets/keymaps/default-linux.json
@@ -891,6 +891,10 @@
"ctrl-alt-shift-f": "workspace::FollowNextCollaborator",
// Only available in debug builds: opens an element inspector for development.
"ctrl-alt-i": "dev::ToggleInspector",
+ // Cycles the frame-time debug overlay between hidden, frame-time-only, and detailed modes.
+ "ctrl-alt-shift-p": "dev::ToggleFpsOverlay",
+ // Clears the frame-time overlay's statistics, except the total frame count.
+ "ctrl-alt-shift-o": "dev::ResetFrameOverlayStats",
},
},
{
diff --git a/assets/keymaps/default-macos.json b/assets/keymaps/default-macos.json
index e2048107f6d..b82f06de467 100644
--- a/assets/keymaps/default-macos.json
+++ b/assets/keymaps/default-macos.json
@@ -946,6 +946,10 @@
"cmd-shift-c": "collab_panel::ToggleFocus",
// Only available in debug builds: opens an element inspector for development.
"cmd-alt-i": "dev::ToggleInspector",
+ // Cycles the frame-time debug overlay between hidden, frame-time-only, and detailed modes.
+ "ctrl-alt-shift-p": "dev::ToggleFpsOverlay",
+ // Clears the frame-time overlay's statistics, except the total frame count.
+ "ctrl-alt-shift-o": "dev::ResetFrameOverlayStats",
},
},
{
diff --git a/assets/keymaps/default-windows.json b/assets/keymaps/default-windows.json
index 3de7be2cf45..e9c0f12ba69 100644
--- a/assets/keymaps/default-windows.json
+++ b/assets/keymaps/default-windows.json
@@ -889,6 +889,10 @@
"ctrl-shift-alt-f": "workspace::FollowNextCollaborator",
// Only available in debug builds: opens an element inspector for development.
"shift-alt-i": "dev::ToggleInspector",
+ // Cycles the frame-time debug overlay between hidden, frame-time-only, and detailed modes.
+ "ctrl-alt-shift-p": "dev::ToggleFpsOverlay",
+ // Clears the frame-time overlay's statistics, except the total frame count.
+ "ctrl-alt-shift-d": "dev::ResetFrameOverlayStats",
},
},
{
diff --git a/crates/gpui/src/debug_overlay.rs b/crates/gpui/src/debug_overlay.rs
new file mode 100644
index 00000000000..0cca543ea5d
--- /dev/null
+++ b/crates/gpui/src/debug_overlay.rs
@@ -0,0 +1,428 @@
+//! A developer overlay that paints frame-time statistics directly into the
+//! scene, bypassing layout, text, and view invalidation entirely (to avoid
+//! infinitely triggering new frames).
+
+use crate::{
+ BorderStyle, Bounds, ContentMask, Corners, Edges, Hsla, Pixels, Quad, ScaledPixels, Scene,
+ Size, point, rgba, size, transparent_black,
+};
+use std::{collections::VecDeque, time::Duration};
+
+#[allow(missing_docs)]
+#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
+pub enum DebugFrameOverlayMode {
+ #[default]
+ Hidden,
+ Minimal,
+ Full,
+}
+
+impl DebugFrameOverlayMode {
+ /// Returns the next mode in the Hidden → FrameTime → Detailed cycle.
+ pub fn next(self) -> Self {
+ match self {
+ Self::Hidden => Self::Minimal,
+ Self::Minimal => Self::Full,
+ Self::Full => Self::Hidden,
+ }
+ }
+}
+
+/// The number of most recent draw durations retained for percentile statistics.
+const MAX_SAMPLES: usize = 1000;
+
+const GLYPH_WIDTH: usize = 5;
+const GLYPH_HEIGHT: usize = 7;
+/// Glyph advance and line advance, in font cells.
+const CHAR_ADVANCE: f32 = (GLYPH_WIDTH + 1) as f32;
+const LINE_ADVANCE: f32 = (GLYPH_HEIGHT + 2) as f32;
+/// Padding between the panel edge and the text, in font cells.
+const PANEL_PADDING: f32 = 2.0;
+/// Margin between the panel and the window corner, in font cells.
+const PANEL_MARGIN: f32 = 4.0;
+/// Side of one square font cell, in logical pixels.
+const CELL_SIZE: f32 = 2.0;
+
+fn text_color() -> Hsla {
+ rgba(0x33ff33ff).into()
+}
+
+fn panel_color() -> Hsla {
+ rgba(0x000000aa).into()
+}
+
+pub(crate) struct DebugFrameOverlay {
+ mode: DebugFrameOverlayMode,
+ draw_durations: VecDeque<Duration>,
+ total_frame_count: u64,
+}
+
+impl DebugFrameOverlay {
+ pub(crate) fn new() -> Self {
+ Self {
+ mode: DebugFrameOverlayMode::default(),
+ draw_durations: VecDeque::new(),
+ total_frame_count: 0,
+ }
+ }
+
+ pub(crate) fn mode(&self) -> DebugFrameOverlayMode {
+ self.mode
+ }
+
+ pub(crate) fn set_mode(&mut self, mode: DebugFrameOverlayMode) {
+ self.mode = mode;
+ }
+
+ /// Clears the draw-duration samples, restarting the percentile window.
+ /// The total frame count is left untouched.
+ pub(crate) fn reset_stats(&mut self) {
+ self.draw_durations.clear();
+ }
+
+ pub(crate) fn is_enabled(&self) -> bool {
+ self.mode != DebugFrameOverlayMode::Hidden
+ }
+
+ pub(crate) fn record_frame(&mut self, draw_duration: Duration) {
+ self.total_frame_count += 1;
+ if self.draw_durations.len() >= MAX_SAMPLES {
+ self.draw_durations.pop_front();
+ }
+ self.draw_durations.push_back(draw_duration);
+ }
+
+ pub(crate) fn paint(&self, scene: &mut Scene, viewport_size: Size<Pixels>, scale_factor: f32) {
+ if !self.is_enabled() {
+ return;
+ }
+
+ let lines = self.lines();
+ let max_line_chars = lines.iter().map(|line| line.len()).max().unwrap_or(0);
+ // Ensure at least one physical pixel per cell so the text stays legible
+ // at fractional downscale factors.
+ let cell = (CELL_SIZE * scale_factor).max(1.0);
+
+ let panel_width = cell * (max_line_chars as f32 * CHAR_ADVANCE + 2.0 * PANEL_PADDING);
+ let panel_height = cell * (lines.len() as f32 * LINE_ADVANCE + 2.0 * PANEL_PADDING);
+ let viewport = viewport_size.scale(scale_factor);
+ let panel_left = viewport.width.0 - panel_width - cell * PANEL_MARGIN;
+ let panel_top = cell * PANEL_MARGIN;
+
+ let content_mask = ContentMask {
+ bounds: Bounds {
+ origin: point(ScaledPixels(0.), ScaledPixels(0.)),
+ size: viewport,
+ },
+ };
+
+ scene.insert_primitive(solid_quad(
+ scaled_bounds(panel_left, panel_top, panel_width, panel_height),
+ &content_mask,
+ panel_color(),
+ ));
+
+ let text_color = text_color();
+ for (line_index, line) in lines.iter().enumerate() {
+ let line_top = panel_top + cell * (PANEL_PADDING + line_index as f32 * LINE_ADVANCE);
+ for (char_index, character) in line.chars().enumerate() {
+ let Some(rows) = glyph(character) else {
+ continue;
+ };
+ let glyph_left =
+ panel_left + cell * (PANEL_PADDING + char_index as f32 * CHAR_ADVANCE);
+ for (row_index, row) in rows.iter().enumerate() {
+ let row_top = line_top + cell * row_index as f32;
+ // Merge horizontal runs of lit cells into single quads.
+ let mut column = 0;
+ while column < GLYPH_WIDTH {
+ if row & (1 << (GLYPH_WIDTH - 1 - column)) == 0 {
+ column += 1;
+ continue;
+ }
+ let run_start = column;
+ while column < GLYPH_WIDTH && row & (1 << (GLYPH_WIDTH - 1 - column)) != 0 {
+ column += 1;
+ }
+ scene.insert_primitive(solid_quad(
+ scaled_bounds(
+ glyph_left + cell * run_start as f32,
+ row_top,
+ cell * (column - run_start) as f32,
+ cell,
+ ),
+ &content_mask,
+ text_color,
+ ));
+ }
+ }
+ }
+ }
+ }
+
+ fn lines(&self) -> Vec<String> {
+ let current = self.draw_durations.back().copied();
+ match self.mode {
+ DebugFrameOverlayMode::Hidden => Vec::new(),
+ DebugFrameOverlayMode::Minimal => vec![format_ms(current)],
+ DebugFrameOverlayMode::Full => {
+ let mut sorted: Vec<Duration> = self.draw_durations.iter().copied().collect();
+ sorted.sort_unstable();
+ let percentile = |numerator: usize| {
+ (!sorted.is_empty()).then(|| sorted[(sorted.len() - 1) * numerator / 100])
+ };
+ // Past five digits the count would break the column
+ // alignment, so it saturates instead.
+ let frame_count = if self.total_frame_count > 99_999 {
+ "LOTS".to_string()
+ } else {
+ self.total_frame_count.to_string()
+ };
+ // Labels are padded to a uniform width so the fixed-width
+ // durations start in the same column on every line.
+ vec![
+ format!("CUR {}", format_ms(current)),
+ format!("1% {}", format_ms(percentile(99))),
+ format!("10% {}", format_ms(percentile(90))),
+ format!("MAX {}", format_ms(sorted.last().copied())),
+ format!("FRAMES {frame_count:>5}"),
+ ]
+ }
+ }
+ }
+}
+
+/// Formats as `abc.d MS`, right-aligned in room for three integer digits and
+/// one decimal (padded with spaces, not zeroes), so stacked readouts align.
+fn format_ms(duration: Option<Duration>) -> String {
+ match duration {
+ Some(duration) => {
+ let ms = duration.as_secs_f32() * 1000.0;
+ format!("{ms:>5.1} MS")
+ }
+ None => " -- MS".into(),
+ }
+}
+
+fn scaled_bounds(left: f32, top: f32, width: f32, height: f32) -> Bounds<ScaledPixels> {
+ Bounds {
+ origin: point(ScaledPixels(left), ScaledPixels(top)),
+ size: size(ScaledPixels(width), ScaledPixels(height)),
+ }
+}
+
+fn solid_quad(
+ bounds: Bounds<ScaledPixels>,
+ content_mask: &ContentMask<ScaledPixels>,
+ color: Hsla,
+) -> Quad {
+ Quad {
+ order: 0,
+ border_style: BorderStyle::Solid,
+ bounds,
+ content_mask: *content_mask,
+ background: color.into(),
+ border_color: transparent_black(),
+ corner_radii: Corners::default(),
+ border_widths: Edges::default(),
+ }
+}
+
+/// Returns the 5x7 bitmap for the given character, one `u8` of column bits per
+/// row with the most significant of the 5 bits leftmost. Only the characters
+/// used by the overlay's readouts are defined.
+fn glyph(character: char) -> Option<[u8; GLYPH_HEIGHT]> {
+ Some(match character {
+ '0' => [
+ 0b01110, 0b10001, 0b10011, 0b10101, 0b11001, 0b10001, 0b01110,
+ ],
+ '1' => [
+ 0b00100, 0b01100, 0b00100, 0b00100, 0b00100, 0b00100, 0b01110,
+ ],
+ '2' => [
+ 0b01110, 0b10001, 0b00001, 0b00010, 0b00100, 0b01000, 0b11111,
+ ],
+ '3' => [
+ 0b11111, 0b00010, 0b00100, 0b00010, 0b00001, 0b10001, 0b01110,
+ ],
+ '4' => [
+ 0b00010, 0b00110, 0b01010, 0b10010, 0b11111, 0b00010, 0b00010,
+ ],
+ '5' => [
+ 0b11111, 0b10000, 0b11110, 0b00001, 0b00001, 0b10001, 0b01110,
+ ],
+ '6' => [
+ 0b00110, 0b01000, 0b10000, 0b11110, 0b10001, 0b10001, 0b01110,
+ ],
+ '7' => [
+ 0b11111, 0b00001, 0b00010, 0b00100, 0b01000, 0b01000, 0b01000,
+ ],
+ '8' => [
+ 0b01110, 0b10001, 0b10001, 0b01110, 0b10001, 0b10001, 0b01110,
+ ],
+ '9' => [
+ 0b01110, 0b10001, 0b10001, 0b01111, 0b00001, 0b00010, 0b01100,
+ ],
+ '.' => [
+ 0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b01100, 0b01100,
+ ],
+ '-' => [
+ 0b00000, 0b00000, 0b00000, 0b11111, 0b00000, 0b00000, 0b00000,
+ ],
+ '%' => [
+ 0b11001, 0b11001, 0b00010, 0b00100, 0b01000, 0b10011, 0b10011,
+ ],
+ 'A' => [
+ 0b01110, 0b10001, 0b10001, 0b11111, 0b10001, 0b10001, 0b10001,
+ ],
+ 'C' => [
+ 0b01110, 0b10001, 0b10000, 0b10000, 0b10000, 0b10001, 0b01110,
+ ],
+ 'E' => [
+ 0b11111, 0b10000, 0b10000, 0b11110, 0b10000, 0b10000, 0b11111,
+ ],
+ 'F' => [
+ 0b11111, 0b10000, 0b10000, 0b11110, 0b10000, 0b10000, 0b10000,
+ ],
+ 'L' => [
+ 0b10000, 0b10000, 0b10000, 0b10000, 0b10000, 0b10000, 0b11111,
+ ],
+ 'M' => [
+ 0b10001, 0b11011, 0b10101, 0b10101, 0b10001, 0b10001, 0b10001,
+ ],
+ 'N' => [
+ 0b10001, 0b11001, 0b10101, 0b10011, 0b10001, 0b10001, 0b10001,
+ ],
+ 'O' => [
+ 0b01110, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b01110,
+ ],
+ 'R' => [
+ 0b11110, 0b10001, 0b10001, 0b11110, 0b10100, 0b10010, 0b10001,
+ ],
+ 'S' => [
+ 0b01111, 0b10000, 0b10000, 0b01110, 0b00001, 0b00001, 0b11110,
+ ],
+ 'T' => [
+ 0b11111, 0b00100, 0b00100, 0b00100, 0b00100, 0b00100, 0b00100,
+ ],
+ 'U' => [
+ 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b01110,
+ ],
+ 'X' => [
+ 0b10001, 0b10001, 0b01010, 0b00100, 0b01010, 0b10001, 0b10001,
+ ],
+ _ => return None,
+ })
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ /// Every character the readouts can produce must have a glyph, or it
+ /// would silently render as blank space.
+ #[test]
+ fn all_rendered_characters_have_glyphs() {
+ let mut overlay = DebugFrameOverlay::new();
+ overlay.set_mode(DebugFrameOverlayMode::Full);
+
+ let mut lines = Vec::new();
+ for duration in [
+ Duration::ZERO,
+ Duration::from_micros(1),
+ Duration::from_micros(8_333),
+ Duration::from_millis(123),
+ Duration::from_secs(2),
+ ] {
+ overlay.record_frame(duration);
+ lines.extend(overlay.lines());
+ }
+ // Counts beyond five digits render as "LOTS".
+ overlay.total_frame_count = 100_000;
+ lines.extend(overlay.lines());
+
+ // An enabled overlay with no samples yet renders placeholders.
+ let mut empty = DebugFrameOverlay::new();
+ empty.set_mode(DebugFrameOverlayMode::Full);
+ lines.extend(empty.lines());
+
+ for line in lines {
+ for character in line.chars() {
+ assert!(
+ character == ' ' || glyph(character).is_some(),
+ "no glyph for {character:?} in line {line:?}"
+ );
+ }
+ }
+ }
+
+ #[test]
+ fn percentile_lows_are_reported_as_times() {
+ let mut overlay = DebugFrameOverlay::new();
+ overlay.set_mode(DebugFrameOverlayMode::Full);
+ for milliseconds in 1..=100 {
+ overlay.record_frame(Duration::from_millis(milliseconds));
+ }
+ let lines = overlay.lines();
+ assert_eq!(lines[0], "CUR 100.0 MS");
+ assert_eq!(lines[1], "1% 99.0 MS");
+ assert_eq!(lines[2], "10% 90.0 MS");
+ assert_eq!(lines[3], "MAX 100.0 MS");
+ assert_eq!(lines[4], "FRAMES 100");
+ }
+
+ #[test]
+ fn reset_clears_durations_but_keeps_frame_count() {
+ let mut overlay = DebugFrameOverlay::new();
+ overlay.set_mode(DebugFrameOverlayMode::Full);
+ for _ in 0..10 {
+ overlay.record_frame(Duration::from_millis(10));
+ }
+ overlay.reset_stats();
+ let lines = overlay.lines();
+ assert_eq!(lines[0], "CUR -- MS");
+ assert_eq!(lines[3], "MAX -- MS");
+ assert_eq!(lines[4], "FRAMES 10");
+ overlay.record_frame(Duration::from_millis(20));
+ let lines = overlay.lines();
+ assert_eq!(lines[0], "CUR 20.0 MS");
+ assert_eq!(lines[4], "FRAMES 11");
+ }
+
+ #[test]
+ fn frame_count_accumulates_across_mode_changes() {
+ let mut overlay = DebugFrameOverlay::new();
+ for _ in 0..3 {
+ overlay.record_frame(Duration::from_millis(10));
+ }
+ overlay.set_mode(DebugFrameOverlayMode::Minimal);
+ assert_eq!(overlay.lines(), vec![" 10.0 MS".to_string()]);
+ overlay.set_mode(DebugFrameOverlayMode::Full);
+ overlay.record_frame(Duration::from_millis(10));
+ assert_eq!(overlay.lines()[4], "FRAMES 4");
+ overlay.set_mode(DebugFrameOverlayMode::Hidden);
+ overlay.record_frame(Duration::from_millis(10));
+ overlay.set_mode(DebugFrameOverlayMode::Full);
+ assert_eq!(overlay.lines()[4], "FRAMES 5");
+ }
+
+ #[test]
+ fn frame_count_is_right_aligned_and_saturates() {
+ let mut overlay = DebugFrameOverlay::new();
+ overlay.set_mode(DebugFrameOverlayMode::Full);
+ overlay.record_frame(Duration::from_millis(10));
+ assert_eq!(overlay.lines()[4], "FRAMES 1");
+ overlay.total_frame_count = 99_999;
+ assert_eq!(overlay.lines()[4], "FRAMES 99999");
+ overlay.total_frame_count = 100_000;
+ assert_eq!(overlay.lines()[4], "FRAMES LOTS");
+ }
+
+ #[test]
+ fn toggling_on_shows_previous_frame_immediately() {
+ let mut overlay = DebugFrameOverlay::new();
+ overlay.record_frame(Duration::from_millis(10));
+ overlay.set_mode(DebugFrameOverlayMode::Minimal);
+ assert_eq!(overlay.lines(), vec![" 10.0 MS".to_string()]);
+ }
+}
diff --git a/crates/gpui/src/gpui.rs b/crates/gpui/src/gpui.rs
index 04264a6e153..927f6344e6a 100644
--- a/crates/gpui/src/gpui.rs
+++ b/crates/gpui/src/gpui.rs
@@ -18,6 +18,8 @@ mod bounds_tree;
mod color;
/// The default colors used by GPUI.
pub mod colors;
+#[cfg(feature = "profiler")]
+mod debug_overlay;
mod element;
mod elements;
mod executor;
@@ -96,6 +98,8 @@ pub use asset_cache::*;
pub use assets::*;
pub use color::*;
pub use ctor::ctor;
+#[cfg(feature = "profiler")]
+pub use debug_overlay::*;
pub use element::*;
pub use elements::*;
pub use executor::*;
diff --git a/crates/gpui/src/profiler.rs b/crates/gpui/src/profiler.rs
index e850901330e..433db4ecf55 100644
--- a/crates/gpui/src/profiler.rs
+++ b/crates/gpui/src/profiler.rs
@@ -952,19 +952,20 @@ impl WindowProfiler {
});
}
- /// Records the end of a window draw.
- pub fn end_draw(&mut self, dirty_at: Option<Instant>, invalidations: u64) {
+ /// Records the end of a window draw and returns the draw duration.
+ pub fn end_draw(&mut self, dirty_at: Option<Instant>, invalidations: u64) -> Duration {
let Some(WindowActivity::Draw {
started_at: draw_start,
}) = self.active_activities.pop()
else {
debug_assert!(false, "draw activity must be the current window activity");
- return;
+ return Duration::ZERO;
};
self.drew_since_last_present = true;
let draw_end = Instant::now();
- self.record_draw_duration(draw_end.duration_since(draw_start));
+ let draw_duration = draw_end.duration_since(draw_start);
+ self.record_draw_duration(draw_duration);
record_frame_event(FrameEvent::Draw(FrameTiming {
window_id: self.window_id,
dirty_at,
@@ -972,6 +973,7 @@ impl WindowProfiler {
draw_start,
draw_end,
}));
+ draw_duration
}
/// Records that a frame was presented.
diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs
index fe40b9b7dee..d0e0b378b7d 100644
--- a/crates/gpui/src/window.rs
+++ b/crates/gpui/src/window.rs
@@ -1,3 +1,5 @@
+#[cfg(feature = "profiler")]
+use crate::DebugFrameOverlayMode;
#[cfg(any(feature = "inspector", debug_assertions))]
use crate::Inspector;
#[cfg(feature = "profiler")]
@@ -1185,6 +1187,8 @@ pub struct Window {
captured_hitbox: Option<HitboxId>,
#[cfg(any(feature = "inspector", debug_assertions))]
inspector: Option<Entity<Inspector>>,
+ #[cfg(feature = "profiler")]
+ debug_frame_overlay: crate::debug_overlay::DebugFrameOverlay,
pub(crate) a11y: A11y,
}
@@ -1864,6 +1868,8 @@ impl Window {
captured_hitbox: None,
#[cfg(any(feature = "inspector", debug_assertions))]
inspector: None,
+ #[cfg(feature = "profiler")]
+ debug_frame_overlay: crate::debug_overlay::DebugFrameOverlay::new(),
a11y: A11y::new(
a11y_active_flag,
accessibility_force_disabled,
@@ -2857,6 +2863,16 @@ impl Window {
}
if !cx.mode.skip_drawing() {
self.draw_roots(cx);
+ #[cfg(feature = "profiler")]
+ {
+ let viewport_size = self.viewport_size;
+ let scale_factor = self.scale_factor();
+ self.debug_frame_overlay.paint(
+ &mut self.next_frame.scene,
+ viewport_size,
+ scale_factor,
+ );
+ }
}
self.dirty_views.clear();
self.next_frame.window_active = self.active.get();
@@ -2937,8 +2953,12 @@ impl Window {
self.needs_present.set(true);
#[cfg(feature = "profiler")]
- self.window_profiler
- .end_draw(frame_dirty.dirty_at, frame_dirty.invalidations);
+ {
+ let draw_duration = self
+ .window_profiler
+ .end_draw(frame_dirty.dirty_at, frame_dirty.invalidations);
+ self.debug_frame_overlay.record_frame(draw_duration);
+ }
// Exit the scope to obtain the arena-clear token this draw owes; the
// scope's teardown itself happens in `ElementArenaScope::drop`.
@@ -3003,6 +3023,34 @@ impl Window {
self.window_profiler.frame_duration_snapshot()
}
+ /// Returns the current mode of the debug frame overlay.
+ #[cfg(feature = "profiler")]
+ pub fn debug_frame_overlay_mode(&self) -> DebugFrameOverlayMode {
+ self.debug_frame_overlay.mode()
+ }
+
+ /// Sets the mode of the debug frame overlay and schedules a redraw.
+ #[cfg(feature = "profiler")]
+ pub fn set_debug_frame_overlay_mode(&mut self, mode: DebugFrameOverlayMode) {
+ self.debug_frame_overlay.set_mode(mode);
+ self.refresh();
+ }
+
+ /// Advances the debug frame overlay through its hidden, frame-time-only,
+ /// and detailed modes.
+ #[cfg(feature = "profiler")]
+ pub fn cycle_debug_frame_overlay_mode(&mut self) {
+ self.set_debug_frame_overlay_mode(self.debug_frame_overlay.mode().next());
+ }
+
+ /// Clears the debug frame overlay's frame-time statistics, except for the
+ /// total frame count, and schedules a redraw.
+ #[cfg(feature = "profiler")]
+ pub fn reset_debug_frame_overlay_stats(&mut self) {
+ self.debug_frame_overlay.reset_stats();
+ self.refresh();
+ }
+
fn draw_roots(&mut self, cx: &mut App) {
self.invalidator.set_phase(DrawPhase::Prepaint);
self.tooltip_bounds.take();
diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs
index 98831ab874b..b79d4af6059 100644
--- a/crates/zed/src/zed.rs
+++ b/crates/zed/src/zed.rs
@@ -1028,6 +1028,14 @@ fn register_actions(
.register_action(|_, _: &ToggleFullScreen, window, _| {
window.toggle_fullscreen();
})
+ .register_action(|_, _: &zed_actions::dev::ToggleFpsOverlay, window, _| {
+ window.cycle_debug_frame_overlay_mode();
+ })
+ .register_action(
+ |_, _: &zed_actions::dev::ResetFrameOverlayStats, window, _| {
+ window.reset_debug_frame_overlay_stats();
+ },
+ )
.register_action(|_, action: &OpenZedUrl, _, cx| {
OpenListener::global(cx).open(RawOpenRequest {
urls: vec![String::from(&*action.url)],
diff --git a/crates/zed_actions/src/lib.rs b/crates/zed_actions/src/lib.rs
index b082a687a23..13ea37d6612 100644
--- a/crates/zed_actions/src/lib.rs
+++ b/crates/zed_actions/src/lib.rs
@@ -248,7 +248,13 @@ pub mod dev {
dev,
[
/// Toggles the developer inspector for debugging UI elements.
- ToggleInspector
+ ToggleInspector,
+ /// Cycles the debug frame-time overlay between hidden, current
+ /// frame-time, and detailed frame-time statistics.
+ ToggleFpsOverlay,
+ /// Resets the debug frame-time overlay's statistics, except for the
+ /// total frame count.
+ ResetFrameOverlayStats
]
);
}