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

Persist viewer state #186

Merged
merged 5 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
2 changes: 1 addition & 1 deletion puffin_egui/src/flamegraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl Default for Options {
frame_list_height: 48.0,
frame_width: 10.0,

merge_scopes: true,
merge_scopes: false, // off, because it really only works well for single-threaded profiling
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am currently unchecking this one each time I start puffin 🤦

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep me too


sorting: Default::default(),
filter: Default::default(),
Expand Down
4 changes: 3 additions & 1 deletion puffin_viewer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ include = ["**/*.rs", "Cargo.toml", "README.md", "icon.png"]
crate-type = ["cdylib", "rlib"]

[dependencies]
puffin_egui = { version = "0.25.0", path = "../puffin_egui" }
puffin_egui = { version = "0.25.0", path = "../puffin_egui", features = [
"serde",
] }
puffin = { version = "0.19.0", path = "../puffin", features = [
"packing",
"serialization",
Expand Down
12 changes: 10 additions & 2 deletions puffin_viewer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,13 @@ pub struct PuffinViewer {
}

impl PuffinViewer {
pub fn new(source: Source) -> Self {
pub fn new(source: Source, storage: Option<&dyn eframe::Storage>) -> Self {
let profiler_ui = storage
.and_then(|storage| eframe::get_value(storage, eframe::APP_KEY))
.unwrap_or_default();

Self {
profiler_ui: Default::default(),
profiler_ui,
source,
error: None,
profile_self: false,
Expand Down Expand Up @@ -211,6 +215,10 @@ impl PuffinViewer {
}

impl eframe::App for PuffinViewer {
fn save(&mut self, storage: &mut dyn eframe::Storage) {
eframe::set_value(storage, eframe::APP_KEY, &self.profiler_ui);
}

fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
puffin::GlobalProfiler::lock().new_frame();

Expand Down
2 changes: 1 addition & 1 deletion puffin_viewer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn main() -> Result<(), eframe::Error> {
eframe::run_native(
"puffin viewer",
native_options,
Box::new(|_cc| Box::new(PuffinViewer::new(source))),
Box::new(|cc| Box::new(PuffinViewer::new(source, cc.storage))),
)
}

Expand Down
Loading