Skip to content

Commit

Permalink
Better buffer debug
Browse files Browse the repository at this point in the history
  • Loading branch information
gatesn committed Jan 10, 2025
1 parent 545108d commit 625aae7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
29 changes: 20 additions & 9 deletions vortex-buffer/src/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::any::type_name;
use std::collections::Bound;
use std::fmt::{Debug, Formatter};
use std::ops::{Deref, RangeBounds};
Expand Down Expand Up @@ -281,21 +282,31 @@ impl<T> Buffer<T> {
}
}

impl<T> Debug for Buffer<T> {
impl<T> Debug for Buffer<T>
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::<T>()));
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()
}
}

Expand Down
1 change: 1 addition & 0 deletions vortex-buffer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 2 additions & 0 deletions vortex-file/src/v2/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ impl<R: VortexReadAt + Unpin> VortexFile<R> {

/// Performs a scan operation over the file.
pub fn scan(self, scan: Arc<Scan>) -> VortexResult<impl ArrayStream + 'static> {
println!("File Layout: {:#?}", self.file_layout);

// Create a shared reader for the scan.
let reader: Arc<dyn LayoutReader> = self
.file_layout()
Expand Down
2 changes: 2 additions & 0 deletions vortex-file/src/v2/segments/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ impl<R: VortexReadAt + Unpin> SegmentCache<R> {
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)
Expand Down
7 changes: 7 additions & 0 deletions vortex-layout/src/segments/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::fmt::Display;
use std::ops::Deref;

use async_trait::async_trait;
Expand All @@ -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<u32> for SegmentId {
fn from(value: u32) -> Self {
Self(value)
Expand Down

0 comments on commit 625aae7

Please sign in to comment.