Skip to content

Commit

Permalink
feat: make Debug for useful Session (#2903)
Browse files Browse the repository at this point in the history
Right now the `Debug` for `Session` is just `Session()`, which is pretty
unhelpful. Needed this recently to debug the cache.
  • Loading branch information
wjones127 authored Sep 18, 2024
1 parent 65b32d4 commit 73599c5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions rust/lance-core/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ impl FileMetadataCache {
}
}

pub fn size(&self) -> usize {
self.cache.entry_count() as usize
}

pub fn get<T: Send + Sync + 'static>(&self, path: &Path) -> Option<Arc<T>> {
self.cache
.get(&(path.to_owned(), TypeId::of::<T>()))
Expand Down
23 changes: 22 additions & 1 deletion rust/lance/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,28 @@ pub struct Session {

impl std::fmt::Debug for Session {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Session()")
f.debug_struct("Session")
.field(
"index_cache",
&format!(
"IndexCache(items={}, size_bytes={})",
self.index_cache.get_size(),
self.index_cache.deep_size_of()
),
)
.field(
"file_metadata_cache",
&format!(
"FileMetadataCache(items={}, size_bytes={})",
self.file_metadata_cache.size(),
self.file_metadata_cache.deep_size_of()
),
)
.field(
"index_extensions",
&self.index_extensions.keys().collect::<Vec<_>>(),
)
.finish()
}
}

Expand Down

0 comments on commit 73599c5

Please sign in to comment.