Skip to content

Commit

Permalink
learnings from range integration
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Jan 11, 2024
1 parent 4b7de83 commit dca31b8
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 61 deletions.
28 changes: 16 additions & 12 deletions crates/re_query_cache/src/cache_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{collections::BTreeMap, sync::atomic::AtomicBool};
use re_log_types::EntityPath;
use re_types_core::ComponentName;

use crate::{cache::LatestAtCache, Caches};
use crate::{Caches, LatestAtCache};

// ---

Expand Down Expand Up @@ -36,14 +36,18 @@ impl CachesStats {
re_tracing::profile_function!();

let Self { latest_at } = self;
latest_at.values().map(|stats| stats.total_size_bytes).sum()

let latest_at_size_bytes: u64 =
latest_at.values().map(|stats| stats.total_size_bytes).sum();

latest_at_size_bytes
}
}

/// Stats for a cached entity.
#[derive(Debug, Clone)]
pub struct CachedEntityStats {
pub total_times: u64,
pub total_rows: u64,
pub total_size_bytes: u64,

/// Only if [`detailed_stats`] returns `true` (see [`set_detailed_stats`]).
Expand All @@ -53,8 +57,8 @@ pub struct CachedEntityStats {
/// Stats for a cached component.
#[derive(Default, Debug, Clone)]
pub struct CachedComponentStats {
pub total_times: u64,
pub total_values: u64,
pub total_rows: u64,
pub total_instances: u64,
}

impl Caches {
Expand All @@ -72,7 +76,7 @@ impl Caches {
.map(|(key, caches_per_arch)| {
(key.entity_path.clone(), {
let mut total_size_bytes = 0u64;
let mut total_times = 0u64;
let mut total_rows = 0u64;
let mut per_component = detailed_stats().then(BTreeMap::default);

for latest_at_cache in
Expand All @@ -86,32 +90,32 @@ impl Caches {
} = &*latest_at_cache.read();

total_size_bytes += latest_at_cache.total_size_bytes;
total_times = per_data_time.len() as u64 + timeless.is_some() as u64;
total_rows = per_data_time.len() as u64 + timeless.is_some() as u64;

if let Some(per_component) = per_component.as_mut() {
for bucket in per_data_time.values() {
for (component_name, data) in &bucket.read().components {
let stats: &mut CachedComponentStats =
per_component.entry(*component_name).or_default();
stats.total_times += data.dyn_num_entries() as u64;
stats.total_values += data.dyn_num_values() as u64;
stats.total_rows += data.dyn_num_entries() as u64;
stats.total_instances += data.dyn_num_values() as u64;
}
}

if let Some(bucket) = &timeless {
for (component_name, data) in &bucket.components {
let stats: &mut CachedComponentStats =
per_component.entry(*component_name).or_default();
stats.total_times += data.dyn_num_entries() as u64;
stats.total_values += data.dyn_num_values() as u64;
stats.total_rows += data.dyn_num_entries() as u64;
stats.total_instances += data.dyn_num_values() as u64;
}
}
}
}

CachedEntityStats {
total_size_bytes,
total_times,
total_rows,

per_component,
}
Expand Down
102 changes: 53 additions & 49 deletions crates/re_viewer/src/ui/memory_panel.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use re_data_store::{DataStoreConfig, DataStoreRowStats, DataStoreStats};
use re_format::{format_bytes, format_number};
use re_log_types::EntityPath;
use re_memory::{util::sec_since_start, MemoryHistory, MemoryLimit, MemoryUse};
use re_query_cache::{CachedComponentStats, CachedEntityStats, CachesStats};
use re_renderer::WgpuResourcePoolStatistics;
Expand Down Expand Up @@ -317,63 +316,68 @@ impl MemoryPanel {
.on_hover_text("Show detailed statistics when hovering entity paths below.\nThis will slow down the program.");
re_query_cache::set_detailed_stats(detailed_stats);

egui::Grid::new("cache stats grid")
let CachesStats { latest_at } = caches_stats;

// NOTE: This is a debug tool: do _not_ hide empty things. Empty things are a bug.

ui.separator();

ui.strong("LatestAt");
egui::Grid::new("latest_at cache stats grid")
.num_columns(3)
.show(ui, |ui| {
let CachesStats { latest_at } = caches_stats;

ui.label("Entity");
ui.label("Timestamps")
ui.label(egui::RichText::new("Entity").underline());
ui.label(egui::RichText::new("Rows").underline())
.on_hover_text("How many distinct data timestamps have been cached?");
ui.label("Size");
ui.label(egui::RichText::new("Size").underline());
ui.end_row();

fn label_entity_stats(
ui: &mut egui::Ui,
cache_stats: &CachedEntityStats,
entity_path: &EntityPath,
) {
let CachedEntityStats {
total_size_bytes,
total_times,
per_component,
} = cache_stats;

for (entity_path, stats) in latest_at {
let res = ui.label(entity_path.to_string());
if let Some(per_component) = per_component.as_ref() {
res.on_hover_ui_at_pointer(|ui| {
egui::Grid::new("component cache stats grid")
.num_columns(3)
.show(ui, |ui| {
ui.label("Component");
ui.label("Timestamps");
ui.label("Count");
ui.end_row();

for (component_name, stats) in per_component {
let &CachedComponentStats {
total_times,
total_values,
} = stats;

ui.label(component_name.to_string());
ui.label(re_format::format_number(total_times as _));
ui.label(re_format::format_number(total_values as _));
ui.end_row();
}
});
});
}

ui.label(re_format::format_number(*total_times as _));
ui.label(re_format::format_bytes(*total_size_bytes as _));
entity_stats_ui(ui, res, stats);
ui.end_row();
}

for (entity_path, stats) in latest_at {
label_entity_stats(ui, stats, entity_path);
}
});

fn entity_stats_ui(
ui: &mut egui::Ui,
hover_response: egui::Response,
entity_stats: &CachedEntityStats,
) {
let CachedEntityStats {
total_size_bytes,
total_rows,
per_component,
} = entity_stats;

if let Some(per_component) = per_component.as_ref() {
hover_response.on_hover_ui_at_pointer(|ui| {
egui::Grid::new("component cache stats grid")
.num_columns(3)
.show(ui, |ui| {
ui.label(egui::RichText::new("Component").underline());
ui.label(egui::RichText::new("Rows").underline());
ui.label(egui::RichText::new("Instances").underline());
ui.end_row();

for (component_name, stats) in per_component {
let &CachedComponentStats {
total_rows,
total_instances,
} = stats;

ui.label(component_name.to_string());
ui.label(re_format::format_number(total_rows as _));
ui.label(re_format::format_number(total_instances as _));
ui.end_row();
}
});
});
}

ui.label(re_format::format_number(*total_rows as _));
ui.label(re_format::format_bytes(*total_size_bytes as _));
}
}

fn tracking_stats(
Expand Down

0 comments on commit dca31b8

Please sign in to comment.