Skip to content

Commit

Permalink
Show/hide flamegraph puffin threads
Browse files Browse the repository at this point in the history
  • Loading branch information
TimonPost committed Sep 28, 2022
1 parent cad6a20 commit 14ed357
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 24 deletions.
19 changes: 18 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions puffin_egui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ once_cell = "1.7"
puffin = { version = "0.13.3", path = "../puffin", features = ["packing"] }
serde = { version = "1.0", features = ["derive"], optional = true }
vec1 = "1.8"
indexmap = "1.9.1"

[dev-dependencies]
eframe = "0.18.0"
Expand Down
81 changes: 58 additions & 23 deletions puffin_egui/src/flamegraph.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
use std::{
vec,
};

use super::{SelectedFrames, ERROR_COLOR, HOVER_COLOR};
use egui::*;
use indexmap::IndexMap;
use puffin::*;

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -132,6 +137,8 @@ pub struct Options {

pub sorting: Sorting,

show_flamegraph_threads: IndexMap<String, bool>,

#[cfg_attr(feature = "serde", serde(skip))]
filter: Filter,

Expand Down Expand Up @@ -164,6 +171,7 @@ impl Default for Options {
filter: Default::default(),

zoom_to_relative_ns_range: None,
show_flamegraph_threads: IndexMap::new(),
}
}
}
Expand Down Expand Up @@ -224,35 +232,54 @@ pub fn ui(ui: &mut egui::Ui, options: &mut Options, frames: &SelectedFrames) {
ui.memory().data.insert_temp(num_frames_id, num_frames);
}

ui.horizontal(|ui| {
ui.horizontal(|ui| {
let changed = ui
.checkbox(&mut options.merge_scopes, "Merge children with same ID")
.changed();

// If we have multiple frames selected this will toggle
// if we view all the frames, or an average of them,
// and that difference is pretty massive, so help the user:
if changed && num_frames > 1 {
reset_view = true;
}
});
ui.separator();
ui.colored_label(ui.visuals().widgets.inactive.text_color(), "Help!")
.on_hover_text(
"Drag to pan.\n\
ui.columns(2, |ui| {
ui[0].set_width(80.0);

egui::ScrollArea::vertical()
.id_source("first_s")
.max_height(150.0)
.show(&mut ui[0], |ui| {
ui.label("show threads:");
for f in frames.threads.keys() {
let entry = options
.show_flamegraph_threads
.entry(f.name.clone())
.or_insert(true);
ui.checkbox(entry, f.name.clone());
}
});

egui::ScrollArea::vertical()
.id_source("second_s")
.max_height(150.0)
.show(&mut ui[1], |ui| {
let changed = ui
.checkbox(&mut options.merge_scopes, "Merge children with same ID")
.changed();
// If we have multiple frames selected this will toggle
// if we view all the frames, or an average of them,
// and that difference is pretty massive, so help the user:
if changed && num_frames > 1 {
reset_view = true;
}

ui.colored_label(ui.visuals().widgets.inactive.text_color(), "Help!")
.on_hover_text(
"Drag to pan.\n\
Zoom: Ctrl/cmd + scroll, or drag with secondary mouse button.\n\
Click on a scope to zoom to it.\n\
Double-click to reset view.\n\
Press spacebar to pause/resume.",
);
ui.separator();
);

// The number of threads can change between frames, so always show this even if there currently is only one thread:
options.sorting.ui(ui);

// The number of threads can change between frames, so always show this even if there currently is only one thread:
options.sorting.ui(ui);
options.filter.ui(ui);
});
});

options.filter.ui(ui);
ui.separator();

Frame::dark_canvas(ui.style()).show(ui, |ui| {
let available_height = ui.max_rect().bottom() - ui.min_rect().bottom();
Expand Down Expand Up @@ -326,13 +353,21 @@ fn ui_canvas(
let threads = options.sorting.sort(threads);

for thread_info in threads {
if !*options
.show_flamegraph_threads
.get(&thread_info.name)
.unwrap_or(&false)
{
continue;
}

// Visual separator between threads:
cursor_y += 2.0;
let line_y = cursor_y;
cursor_y += 2.0;

let text_pos = pos2(info.canvas.min.x, cursor_y);
paint_thread_info(info, &thread_info, text_pos);
paint_thread_info(info, &thread_info, text_pos);
cursor_y += info.text_height;

// draw on top of thread info background:
Expand Down

0 comments on commit 14ed357

Please sign in to comment.