Skip to content

Commit

Permalink
Improve logging around blueprint saving during shutdown (#5664)
Browse files Browse the repository at this point in the history
### What
* Part of #5629

Ignore whitespace when reading the diff

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested the web demo (if applicable):
* Using newly built examples:
[app.rerun.io](https://app.rerun.io/pr/5664/index.html)
* Using examples from latest `main` build:
[app.rerun.io](https://app.rerun.io/pr/5664/index.html?manifest_url=https://app.rerun.io/version/main/examples_manifest.json)
* Using full set of examples from `nightly` build:
[app.rerun.io](https://app.rerun.io/pr/5664/index.html?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG
* [x] If applicable, add a new check to the [release
checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)!

- [PR Build Summary](https://build.rerun.io/pr/5664)
- [Docs
preview](https://rerun.io/preview/3661ee3766211d083f381da0ad1d912c1382d5ef/docs)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/3661ee3766211d083f381da0ad1d912c1382d5ef/examples)
<!--EXAMPLES-PREVIEW-->
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)
  • Loading branch information
emilk authored Mar 25, 2024
1 parent 10f963c commit 71ecddb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 36 deletions.
38 changes: 23 additions & 15 deletions crates/re_viewer/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -974,8 +974,10 @@ impl App {
store_hub.set_active_recording_id(store_id.clone());
}
StoreKind::Blueprint => {
re_log::debug!("Activating newly loaded blueprint");
if let Some(info) = entity_db.store_info() {
re_log::debug!(
"Activating blueprint that was loaded from {channel_source}"
);
let app_id = info.application_id.clone();
store_hub.set_blueprint_for_app_id(store_id.clone(), app_id);
} else {
Expand Down Expand Up @@ -1179,20 +1181,26 @@ impl eframe::App for App {
}

fn save(&mut self, storage: &mut dyn eframe::Storage) {
if self.startup_options.persist_state {
// Save the app state
eframe::set_value(storage, eframe::APP_KEY, &self.state);

// Save the blueprints
// TODO(#2579): implement web-storage for blueprints as well
if let Some(hub) = &mut self.store_hub {
match hub.gc_and_persist_app_blueprints(&self.state.app_options) {
Ok(f) => f,
Err(err) => {
re_log::error!("Saving blueprints failed: {err}");
}
};
}
if !self.startup_options.persist_state {
return;
}

re_tracing::profile_function!();

// Save the app state
eframe::set_value(storage, eframe::APP_KEY, &self.state);

// Save the blueprints
// TODO(#2579): implement web-storage for blueprints as well
if let Some(hub) = &mut self.store_hub {
match hub.gc_and_persist_app_blueprints(&self.state.app_options) {
Ok(f) => f,
Err(err) => {
re_log::error!("Saving blueprints failed: {err}");
}
};
} else {
re_log::error!("Could not save blueprints: the store hub is not available");
}
}

Expand Down
49 changes: 28 additions & 21 deletions crates/re_viewer/src/store_hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,33 +367,40 @@ impl StoreHub {
// there may be other Blueprints in the Hub.

for (app_id, blueprint_id) in &self.blueprint_by_app_id {
if let Some(blueprint) = self.store_bundle.get_mut(blueprint_id) {
if self.blueprint_last_save.get(blueprint_id) != Some(&blueprint.generation()) {
if app_options.blueprint_gc {
blueprint.gc_everything_but_the_latest_row();
}
let Some(blueprint) = self.store_bundle.get_mut(blueprint_id) else {
re_log::debug!("Failed to find blueprint {blueprint_id}.");
continue;
};
if self.blueprint_last_save.get(blueprint_id) == Some(&blueprint.generation()) {
continue; // no change since last save
}

#[cfg(not(target_arch = "wasm32"))]
{
let blueprint_path = default_blueprint_path(app_id)?;
re_log::debug_once!("Saving blueprint for {app_id} to {blueprint_path:?}");
if app_options.blueprint_gc {
blueprint.gc_everything_but_the_latest_row();
}

let messages = blueprint.to_messages(None)?;
#[cfg(not(target_arch = "wasm32"))]
{
let blueprint_path = default_blueprint_path(app_id)?;

// TODO(jleibs): Should we push this into a background thread? Blueprints should generally
// be small & fast to save, but maybe not once we start adding big pieces of user data?
crate::saving::encode_to_file(&blueprint_path, messages.iter())?;
let messages = blueprint.to_messages(None)?;

self.blueprint_last_save
.insert(blueprint_id.clone(), blueprint.generation());
}
#[cfg(target_arch = "wasm32")]
{
_ = app_id;
}
}
// TODO(jleibs): Should we push this into a background thread? Blueprints should generally
// be small & fast to save, but maybe not once we start adding big pieces of user data?
crate::saving::encode_to_file(&blueprint_path, messages.iter())?;

re_log::debug!("Saved blueprint for {app_id} to {blueprint_path:?}");

self.blueprint_last_save
.insert(blueprint_id.clone(), blueprint.generation());
}

#[cfg(target_arch = "wasm32")]
{
_ = app_id;
}
}

Ok(())
}

Expand Down

0 comments on commit 71ecddb

Please sign in to comment.