-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New data APIs 10: stats and debug tools for new caches (#5990)
Title. The new cache being natively component-based makes things much smoothier than before. --- Part of a PR series to completely revamp the data APIs in preparation for the removal of instance keys and the introduction of promises: - #5573 - #5574 - #5581 - #5605 - #5606 - #5633 - #5673 - #5679 - #5687 - #5755 - #5990 - #5992 - #5993 - #5994 - #6035 - #6036 - #6037 Builds on top of the static data PR series: - #5534
- Loading branch information
Showing
13 changed files
with
322 additions
and
149 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
use std::collections::BTreeMap; | ||
|
||
use re_log_types::TimeRange; | ||
use re_types_core::SizeBytes as _; | ||
|
||
use crate::{CacheKey, Caches}; | ||
|
||
// --- | ||
|
||
/// Stats for all primary caches. | ||
/// | ||
/// Fetch them via [`Caches::stats`]. | ||
#[derive(Default, Debug, Clone)] | ||
pub struct CachesStats { | ||
pub latest_at: BTreeMap<CacheKey, CachedComponentStats>, | ||
pub range: BTreeMap<CacheKey, (Option<TimeRange>, CachedComponentStats)>, | ||
} | ||
|
||
impl CachesStats { | ||
#[inline] | ||
pub fn total_size_bytes(&self) -> u64 { | ||
re_tracing::profile_function!(); | ||
|
||
let Self { latest_at, range } = self; | ||
|
||
let latest_at_size_bytes: u64 = | ||
latest_at.values().map(|stats| stats.total_size_bytes).sum(); | ||
let range_size_bytes: u64 = range | ||
.values() | ||
.map(|(_, stats)| stats.total_size_bytes) | ||
.sum(); | ||
|
||
latest_at_size_bytes + range_size_bytes | ||
} | ||
} | ||
|
||
/// Stats for a cached component. | ||
#[derive(Default, Debug, Clone)] | ||
pub struct CachedComponentStats { | ||
pub total_indices: u64, | ||
pub total_instances: u64, | ||
pub total_size_bytes: u64, | ||
} | ||
|
||
impl Caches { | ||
/// Computes the stats for all primary caches. | ||
pub fn stats(&self) -> CachesStats { | ||
re_tracing::profile_function!(); | ||
|
||
let latest_at = { | ||
let latest_at = self.latest_at_per_cache_key.read_recursive().clone(); | ||
// Implicitly releasing top-level cache mappings -- concurrent queries can run once again. | ||
|
||
latest_at | ||
.iter() | ||
.map(|(key, cache)| { | ||
let cache = cache.read_recursive(); | ||
( | ||
key.clone(), | ||
CachedComponentStats { | ||
total_indices: cache.per_data_time.len() as _, | ||
total_instances: cache | ||
.per_data_time | ||
.values() | ||
.map(|results| results.num_instances()) | ||
.sum(), | ||
total_size_bytes: cache.total_size_bytes(), | ||
}, | ||
) | ||
}) | ||
.collect() | ||
}; | ||
|
||
let range = { | ||
let range = self.range_per_cache_key.read_recursive().clone(); | ||
// Implicitly releasing top-level cache mappings -- concurrent queries can run once again. | ||
|
||
range | ||
.iter() | ||
.map(|(key, cache)| { | ||
let cache = cache.read_recursive(); | ||
let cache = cache.per_data_time.read_recursive(); | ||
( | ||
key.clone(), | ||
( | ||
cache.time_range(), | ||
CachedComponentStats { | ||
total_indices: cache.indices.len() as _, | ||
total_instances: cache.num_instances(), | ||
total_size_bytes: cache.total_size_bytes(), | ||
}, | ||
), | ||
) | ||
}) | ||
.collect() | ||
}; | ||
|
||
CachesStats { latest_at, range } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.