From 625aae74a5f45d5647a86191d53f3ac260680c01 Mon Sep 17 00:00:00 2001 From: Nicholas Gates Date: Fri, 10 Jan 2025 22:29:50 +0000 Subject: [PATCH] Better buffer debug --- vortex-buffer/src/buffer.rs | 29 +++++++++++++++++++--------- vortex-buffer/src/lib.rs | 1 + vortex-file/src/v2/file.rs | 2 ++ vortex-file/src/v2/segments/cache.rs | 2 ++ vortex-layout/src/segments/mod.rs | 7 +++++++ 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/vortex-buffer/src/buffer.rs b/vortex-buffer/src/buffer.rs index 74530f55b..13ad4f874 100644 --- a/vortex-buffer/src/buffer.rs +++ b/vortex-buffer/src/buffer.rs @@ -1,3 +1,4 @@ +use std::any::type_name; use std::collections::Bound; use std::fmt::{Debug, Formatter}; use std::ops::{Deref, RangeBounds}; @@ -281,21 +282,31 @@ impl Buffer { } } -impl Debug for Buffer { +impl Debug for Buffer +where + T: Debug, +{ fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - const TRUNC_SIZE: usize = 512; - let mut binding = f.debug_struct("Buffer"); - let mut fields = binding + let mut binding = f.debug_struct(&format!("Buffer<{}>", type_name::())); + let fields = binding .field("length", &self.length) .field("alignment", &self.alignment); - let mut bytes = self.bytes.clone(); - if bytes.len() > TRUNC_SIZE { - fields = fields.field("truncated", &true); + const TRUNC_SIZE: usize = 16; + if self.len() <= TRUNC_SIZE { + fields.field("as_slice", &self.as_slice()); + } else { + fields.field_with(&"as_slice", |f| { + write!(f, "[")?; + for elem in self.as_slice().iter().take(TRUNC_SIZE) { + write!(f, "{:?}, ", *elem)?; + } + write!(f, "...")?; + write!(f, "]") + }); } - bytes.truncate(TRUNC_SIZE); - fields.field("bytes", &bytes).finish() + fields.finish() } } diff --git a/vortex-buffer/src/lib.rs b/vortex-buffer/src/lib.rs index 641bcd410..e2263c4fd 100644 --- a/vortex-buffer/src/lib.rs +++ b/vortex-buffer/src/lib.rs @@ -1,4 +1,5 @@ #![feature(unsigned_is_multiple_of)] +#![feature(debug_closure_helpers)] #![deny(missing_docs)] //! A library for working with custom aligned buffers of sized values. diff --git a/vortex-file/src/v2/file.rs b/vortex-file/src/v2/file.rs index 8cf5f97f5..fe65ffc65 100644 --- a/vortex-file/src/v2/file.rs +++ b/vortex-file/src/v2/file.rs @@ -48,6 +48,8 @@ impl VortexFile { /// Performs a scan operation over the file. pub fn scan(self, scan: Arc) -> VortexResult { + println!("File Layout: {:#?}", self.file_layout); + // Create a shared reader for the scan. let reader: Arc = self .file_layout() diff --git a/vortex-file/src/v2/segments/cache.rs b/vortex-file/src/v2/segments/cache.rs index bb04b6b5a..0fc75b478 100644 --- a/vortex-file/src/v2/segments/cache.rs +++ b/vortex-file/src/v2/segments/cache.rs @@ -69,10 +69,12 @@ impl SegmentCache { let segments = self.segments.clone(); async move { let segment = &segments[*request.id as usize]; + println!("Reading segment {} {:?}", *request.id, segment); let bytes = read .read_byte_range(segment.offset, segment.length as u64) .map_ok(|bytes| ByteBuffer::from(bytes).aligned(segment.alignment)) .await?; + println!("Completed segment {} read", *request.id); request .callback .send(bytes) diff --git a/vortex-layout/src/segments/mod.rs b/vortex-layout/src/segments/mod.rs index 143b0fa47..7b66f4c8d 100644 --- a/vortex-layout/src/segments/mod.rs +++ b/vortex-layout/src/segments/mod.rs @@ -1,3 +1,4 @@ +use std::fmt::Display; use std::ops::Deref; use async_trait::async_trait; @@ -9,6 +10,12 @@ use vortex_error::VortexResult; #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct SegmentId(u32); +impl Display for SegmentId { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "SegmentId({})", self.0) + } +} + impl From for SegmentId { fn from(value: u32) -> Self { Self(value)