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

Only compute store/caching stats when the memory panel is opened #5274

Merged
merged 2 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 13 additions & 5 deletions crates/re_viewer/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ impl App {
&mut self,
ui: &mut egui::Ui,
gpu_resource_stats: &WgpuResourcePoolStatistics,
store_stats: &StoreHubStats,
store_stats: Option<&StoreHubStats>,
) {
let frame = egui::Frame {
fill: ui.visuals().panel_fill,
Expand Down Expand Up @@ -806,7 +806,7 @@ impl App {
app_blueprint: &AppBlueprint<'_>,
gpu_resource_stats: &WgpuResourcePoolStatistics,
store_context: Option<&StoreContext<'_>>,
store_stats: &StoreHubStats,
store_stats: Option<&StoreHubStats>,
) {
let mut main_panel_frame = egui::Frame::default();
if re_ui::CUSTOM_WINDOW_DECORATIONS {
Expand Down Expand Up @@ -1219,8 +1219,11 @@ impl eframe::App for App {
}
}

// NOTE: GPU resource stats are cheap to compute so we always do.
// TODO(andreas): store the re_renderer somewhere else.
let gpu_resource_stats = {
re_tracing::profile_scope!("gpu_resource_stats");

let egui_renderer = {
let render_state = frame.wgpu_render_state().unwrap();
&mut render_state.renderer.read()
Expand All @@ -1234,10 +1237,15 @@ impl eframe::App for App {
render_ctx.gpu_resources.statistics()
};

let store_stats = store_hub.stats(self.memory_panel.primary_cache_detailed_stats_enabled());
// NOTE: Store and caching stats are very costly to compute: only do so if the memory panel
// is opened.
let store_stats = self
.memory_panel_open
.then(|| store_hub.stats(self.memory_panel.primary_cache_detailed_stats_enabled()));

// do early, before doing too many allocations
self.memory_panel.update(&gpu_resource_stats, &store_stats);
self.memory_panel
.update(&gpu_resource_stats, store_stats.as_ref());

self.check_keyboard_shortcuts(egui_ctx);

Expand Down Expand Up @@ -1275,7 +1283,7 @@ impl eframe::App for App {
&app_blueprint,
&gpu_resource_stats,
store_context.as_ref(),
&store_stats,
store_stats.as_ref(),
);

if re_ui::CUSTOM_WINDOW_DECORATIONS {
Expand Down
2 changes: 2 additions & 0 deletions crates/re_viewer/src/store_hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ impl StoreHub {
// TODO(jleibs): We probably want stats for all recordings, not just
// the currently selected recording.
pub fn stats(&self, detailed_cache_stats: bool) -> StoreHubStats {
re_tracing::profile_function!();

// If we have an app-id, then use it to look up the blueprint.
let blueprint = self
.selected_application_id
Expand Down
54 changes: 28 additions & 26 deletions crates/re_viewer/src/ui/memory_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ impl MemoryPanel {
pub fn update(
&mut self,
gpu_resource_stats: &WgpuResourcePoolStatistics,
store_stats: &StoreHubStats,
store_stats: Option<&StoreHubStats>,
) {
re_tracing::profile_function!();
self.history.capture(
Some(
(gpu_resource_stats.total_buffer_size_in_bytes
+ gpu_resource_stats.total_texture_size_in_bytes) as _,
),
Some(store_stats.recording_stats.total.num_bytes as _),
Some(store_stats.recording_cached_stats.total_size_bytes() as _),
Some(store_stats.blueprint_stats.total.num_bytes as _),
store_stats.map(|stats| stats.recording_stats.total.num_bytes as _),
store_stats.map(|stats| stats.recording_cached_stats.total_size_bytes() as _),
store_stats.map(|stats| stats.blueprint_stats.total.num_bytes as _),
);
}

Expand All @@ -61,7 +61,7 @@ impl MemoryPanel {
re_ui: &re_ui::ReUi,
limit: &MemoryLimit,
gpu_resource_stats: &WgpuResourcePoolStatistics,
store_stats: &StoreHubStats,
store_stats: Option<&StoreHubStats>,
) {
re_tracing::profile_function!();

Expand All @@ -88,7 +88,7 @@ impl MemoryPanel {
re_ui: &re_ui::ReUi,
limit: &MemoryLimit,
gpu_resource_stats: &WgpuResourcePoolStatistics,
store_stats: &StoreHubStats,
store_stats: Option<&StoreHubStats>,
) {
ui.strong("Rerun Viewer resource usage");

Expand All @@ -102,28 +102,30 @@ impl MemoryPanel {
Self::gpu_stats(ui, gpu_resource_stats);
});

ui.separator();
ui.collapsing("Datastore Resources", |ui| {
Self::store_stats(
ui,
&store_stats.recording_config,
&store_stats.recording_stats,
);
});
if let Some(store_stats) = store_stats {
ui.separator();
ui.collapsing("Datastore Resources", |ui| {
Self::store_stats(
ui,
&store_stats.recording_config,
&store_stats.recording_stats,
);
});

ui.separator();
ui.collapsing("Primary Cache Resources", |ui| {
self.caches_stats(ui, re_ui, &store_stats.recording_cached_stats);
});
ui.separator();
ui.collapsing("Primary Cache Resources", |ui| {
self.caches_stats(ui, re_ui, &store_stats.recording_cached_stats);
});

ui.separator();
ui.collapsing("Blueprint Resources", |ui| {
Self::store_stats(
ui,
&store_stats.blueprint_config,
&store_stats.blueprint_stats,
);
});
ui.separator();
ui.collapsing("Blueprint Resources", |ui| {
Self::store_stats(
ui,
&store_stats.blueprint_config,
&store_stats.blueprint_stats,
);
});
}
}

fn cpu_stats(ui: &mut egui::Ui, re_ui: &re_ui::ReUi, limit: &MemoryLimit) {
Expand Down
Loading