Skip to content

Commit 73599c5

Browse files
authored
feat: make Debug for useful Session (lancedb#2903)
Right now the `Debug` for `Session` is just `Session()`, which is pretty unhelpful. Needed this recently to debug the cache.
1 parent 65b32d4 commit 73599c5

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

rust/lance-core/src/cache.rs

+4
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ impl FileMetadataCache {
6767
}
6868
}
6969

70+
pub fn size(&self) -> usize {
71+
self.cache.entry_count() as usize
72+
}
73+
7074
pub fn get<T: Send + Sync + 'static>(&self, path: &Path) -> Option<Arc<T>> {
7175
self.cache
7276
.get(&(path.to_owned(), TypeId::of::<T>()))

rust/lance/src/session.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,28 @@ pub struct Session {
3131

3232
impl std::fmt::Debug for Session {
3333
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34-
write!(f, "Session()")
34+
f.debug_struct("Session")
35+
.field(
36+
"index_cache",
37+
&format!(
38+
"IndexCache(items={}, size_bytes={})",
39+
self.index_cache.get_size(),
40+
self.index_cache.deep_size_of()
41+
),
42+
)
43+
.field(
44+
"file_metadata_cache",
45+
&format!(
46+
"FileMetadataCache(items={}, size_bytes={})",
47+
self.file_metadata_cache.size(),
48+
self.file_metadata_cache.deep_size_of()
49+
),
50+
)
51+
.field(
52+
"index_extensions",
53+
&self.index_extensions.keys().collect::<Vec<_>>(),
54+
)
55+
.finish()
3556
}
3657
}
3758

0 commit comments

Comments
 (0)