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
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
Ignore thread name in stats view
  • Loading branch information
emilk committed Jul 31, 2024
commit 816259534748deb42d5153d59608d13c7aa3e679
48 changes: 18 additions & 30 deletions puffin_egui/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ pub fn ui(

for frame in frames {
threads.extend(frame.thread_streams.keys());
for (thread_info, stream) in &frame.thread_streams {
collect_stream(&mut stats, &thread_info.name, &stream.stream).ok();
for stream in frame.thread_streams.values() {
collect_stream(&mut stats, &stream.stream).ok();
}
}

Expand Down Expand Up @@ -58,39 +58,39 @@ pub fn ui(

egui::ScrollArea::horizontal().show(ui, |ui| {
ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Extend);
ui.spacing_mut().item_spacing.x = 16.0;

egui_extras::TableBuilder::new(ui)
.striped(true)
.columns(
egui_extras::Column::auto_with_initial_suggestion(200.0).resizable(true),
9,
3,
)
.columns(egui_extras::Column::auto().resizable(false), 6)
.header(20.0, |mut header| {
header.col(|ui| {
ui.heading("Thread");
ui.strong("Location");
});
header.col(|ui| {
ui.heading("Location");
ui.strong("Function Name");
});
header.col(|ui| {
ui.heading("Function Name");
ui.strong("Scope Name");
});
header.col(|ui| {
ui.heading("Scope Name");
ui.strong("Count");
});
header.col(|ui| {
ui.heading("Count");
ui.strong("Size");
});
header.col(|ui| {
ui.heading("Size");
ui.strong("Total self time");
});
header.col(|ui| {
ui.heading("Total self time");
ui.strong("Mean self time");
});
header.col(|ui| {
ui.heading("Mean self time");
});
header.col(|ui| {
ui.heading("Max self time");
ui.strong("Max self time");
});
})
.body(|mut body| {
Expand All @@ -104,9 +104,6 @@ pub fn ui(
}

body.row(14.0, |mut row| {
row.col(|ui| {
ui.label(&key.thread_name);
});
row.col(|ui| {
ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Truncate);
ui.label(scope_details.location());
Expand Down Expand Up @@ -154,7 +151,6 @@ struct Stats {
#[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
struct Key {
id: ScopeId,
thread_name: String,
}

#[derive(Copy, Clone, Default)]
Expand All @@ -169,36 +165,28 @@ struct ScopeStats {
max_ns: NanoSecond,
}

fn collect_stream(
stats: &mut Stats,
thread_name: &str,
stream: &puffin::Stream,
) -> puffin::Result<()> {
fn collect_stream(stats: &mut Stats, stream: &puffin::Stream) -> puffin::Result<()> {
for scope in puffin::Reader::from_start(stream) {
collect_scope(stats, thread_name, stream, &scope?)?;
collect_scope(stats, stream, &scope?)?;
}
Ok(())
}

fn collect_scope<'s>(
stats: &mut Stats,
thread_name: &str,
stream: &'s puffin::Stream,
scope: &puffin::Scope<'s>,
) -> puffin::Result<()> {
let mut ns_used_by_children = 0;
for child_scope in Reader::with_offset(stream, scope.child_begin_position)? {
let child_scope = &child_scope?;
collect_scope(stats, thread_name, stream, child_scope)?;
collect_scope(stats, stream, child_scope)?;
ns_used_by_children += child_scope.record.duration_ns;
}

let self_time = scope.record.duration_ns.saturating_sub(ns_used_by_children);

let key = Key {
id: scope.id,
thread_name: thread_name.to_owned(),
};
let key = Key { id: scope.id };
let scope_stats = stats.scopes.entry(key).or_default();
scope_stats.count += 1;
scope_stats.bytes += scope_byte_size(scope);
Expand Down