Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the puffin_viewer UI #228

Merged
merged 20 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Tweak spacing
  • Loading branch information
emilk committed Jul 31, 2024
commit 448fd9ba0adfd4aef05d7eb7cbedb83e4f149d2d
6 changes: 4 additions & 2 deletions puffin_egui/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ pub struct Filter {
impl Filter {
pub fn ui(&mut self, ui: &mut egui::Ui) {
ui.horizontal(|ui| {
ui.label("Scope filter:");
ui.text_edit_singleline(&mut self.filter);
ui.spacing_mut().item_spacing.x = 4.0;

ui.add(egui::TextEdit::singleline(&mut self.filter).hint_text("Scope filter"));
self.filter = self.filter.to_lowercase();

if ui.button("x").clicked() {
self.filter.clear();
}
Expand Down
33 changes: 13 additions & 20 deletions puffin_egui/src/flamegraph.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::vec;

use super::{SelectedFrames, ERROR_COLOR, HOVER_COLOR};
use crate::{add_space, filter::Filter};
use crate::filter::Filter;
use egui::*;
use indexmap::IndexMap;
use puffin::*;
Expand Down Expand Up @@ -231,9 +231,9 @@ pub fn ui(
ui.horizontal(|ui| {
options.scope_name_filter.ui(ui);

add_space(ui);

ui.menu_button("🔧 Settings", |ui| {
ui.set_max_height(500.0);

{
let changed = ui
.checkbox(&mut options.merge_scopes, "Merge children with same ID")
Expand All @@ -260,23 +260,18 @@ pub fn ui(

ui.group(|ui| {
ui.strong("Visible Threads");
egui::ScrollArea::vertical()
.max_height(150.0)
.id_source("f")
.show(ui, |ui| {
for f in frames.threads.keys() {
let entry = options
.flamegraph_threads
.entry(f.name.clone())
.or_default();
ui.checkbox(&mut entry.flamegraph_show, f.name.clone());
}
});
egui::ScrollArea::vertical().id_source("f").show(ui, |ui| {
for f in frames.threads.keys() {
let entry = options
.flamegraph_threads
.entry(f.name.clone())
.or_default();
ui.checkbox(&mut entry.flamegraph_show, f.name.clone());
}
});
});
});

add_space(ui);

ui.menu_button("❓", |ui| {
ui.label(
"Drag to pan.\n\
Expand Down Expand Up @@ -788,7 +783,7 @@ fn paint_scope(
Id::new("puffin_profiler_tooltip"),
|ui| {
paint_scope_details(ui, scope.id, scope.record.data, scope_details);
add_space(ui);

ui.monospace(format!(
"duration: {:7.3} ms",
to_ms(scope.record.duration_ns)
Expand Down Expand Up @@ -911,8 +906,6 @@ fn merge_scope_tooltip(

paint_scope_details(ui, merge.id, &merge.data, scope_details);

add_space(ui);

if num_frames <= 1 {
if merge.num_pieces <= 1 {
ui.monospace(format!(
Expand Down
18 changes: 8 additions & 10 deletions puffin_egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,13 +444,19 @@ impl ProfilerUi {
return;
};

ui.scope(|ui| {
ui.spacing_mut().item_spacing.y = 6.0;
self.ui_impl(ui, frame_view);
});
}

fn ui_impl(&mut self, ui: &mut egui::Ui, frame_view: &mut MaybeMutRef<'_, FrameView>) {
let mut hovered_frame = None;

egui::CollapsingHeader::new("Frame history")
.default_open(false)
.show(ui, |ui| {
hovered_frame = self.show_frames(ui, frame_view);
ui.add_space(4.0);
});

let frames = if let Some(frame) = hovered_frame {
Expand Down Expand Up @@ -519,7 +525,7 @@ impl ProfilerUi {
}
});
}
add_space(ui);

frames_info_ui(ui, &frames);
});

Expand All @@ -541,16 +547,12 @@ impl ProfilerUi {
ui.ctx().request_repaint(); // keep refreshing to see latest data
}

add_space(ui);

ui.horizontal(|ui| {
ui.label("View:");
ui.selectable_value(&mut self.view, View::Flamegraph, "Flamegraph");
ui.selectable_value(&mut self.view, View::Stats, "Table");
});

add_space(ui);

match self.view {
View::Flamegraph => flamegraph::ui(
ui,
Expand Down Expand Up @@ -880,7 +882,3 @@ fn max_num_latest_ui(ui: &mut egui::Ui, max_num_latest: &mut usize) {
ui.add(egui::Slider::new(max_num_latest, 1..=100).logarithmic(true));
});
}

fn add_space(ui: &mut Ui) {
ui.add_space(8.0); // Looks better than a separator
}
12 changes: 4 additions & 8 deletions puffin_egui/src/stats.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use egui::TextBuffer;
use puffin::*;

use crate::{add_space, filter::Filter};
use crate::filter::Filter;

#[derive(Clone, Debug, Default)]
pub struct Options {
Expand Down Expand Up @@ -31,23 +31,19 @@ pub fn ui(
total_ns += scope.total_self_ns;
}

ui.label("This view can be used to find functions that are called a lot.");
ui.label("The overhead of a profile scope is around ~50ns, so remove profile scopes from fast functions that are called often.");
ui.label("This view can be used to find functions that are called a lot.\n\
The overhead of a profile scope is around ~50ns, so remove profile scopes from fast functions that are called often.");

ui.label(format!(
"Current frame: {} unique scopes, using a total of {:.1} kB, covering {:.1} ms over {} thread(s)",
"Currently viewing {} unique scopes, using a total of {:.1} kB, covering {:.1} ms over {} thread(s)",
stats.scopes.len(),
total_bytes as f32 * 1e-3,
total_ns as f32 * 1e-6,
threads.len()
));

add_space(ui);

options.filter.ui(ui);

add_space(ui);

let mut scopes: Vec<_> = stats
.scopes
.iter()
Expand Down
1 change: 0 additions & 1 deletion puffin_viewer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ impl PuffinViewer {
egui::TopBottomPanel::top("menu_bar").show(ctx, |ui| {
egui::menu::bar(ui, |ui| {
egui::widgets::global_dark_light_mode_switch(ui);
ui.add_space(4.0);

ui.menu_button("File", |ui| {
if ui.button("Open…").clicked() {
Expand Down
Loading