Skip to content

Commit

Permalink
Add DTrace probe for write count
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeeter committed Oct 17, 2023
1 parent e90250b commit f26fb58
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
17 changes: 14 additions & 3 deletions downstairs/src/extent_inner_raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,30 +776,40 @@ impl RawInner {
}

let mut start = 0;
let mut write_count = 0;
for i in 0..block_contexts.len() {
if i + 1 == block_contexts.len()
|| block_contexts[i].block + 1 != block_contexts[i + 1].block
{
self.set_block_contexts_contiguous(&block_contexts[start..=i])?;
write_count += self.set_block_contexts_contiguous(
&block_contexts[start..=i],
)?;
start = i + 1;
}
}
cdt::extent__set__block__contexts__write__count!(|| (
self.extent_number,
write_count as u64,
));
Ok(())
}

/// Efficiently sets block contexts in bulk
///
/// Returns the number of writes, for profiling
///
/// # Panics
/// `block_contexts` must represent a contiguous set of blocks
fn set_block_contexts_contiguous(
&mut self,
block_contexts: &[DownstairsBlockContext],
) -> Result<()> {
) -> Result<usize> {
for (a, b) in block_contexts.iter().zip(block_contexts.iter().skip(1)) {
assert_eq!(a.block + 1, b.block, "blocks must be contiguous");
}

let mut buf = vec![];
let mut writes = 0;
for (slot, group) in block_contexts
.iter()
.group_by(|block_context|
Expand All @@ -822,9 +832,10 @@ impl RawInner {
let offset = self.context_slot_offset(block_start, slot);
nix::sys::uio::pwrite(self.file.as_raw_fd(), &buf, offset as i64)
.map_err(|e| CrucibleError::IoError(e.to_string()))?;
writes += 1;
}

Ok(())
Ok(writes)
}

fn get_metadata(&self) -> Result<OnDiskMeta, CrucibleError> {
Expand Down
5 changes: 5 additions & 0 deletions downstairs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,11 @@ pub mod cdt {

fn extent__context__truncate__start(n_deletions: u64) {}
fn extent__context__truncate__done() {}
fn extent__set__block__contexts__write__count(
extent_id: u32,
n_blocks: u64,
) {
}
fn submit__el__close__done(_: u64) {}
fn submit__el__flush__close__done(_: u64) {}
fn submit__el__repair__done(_: u64) {}
Expand Down

0 comments on commit f26fb58

Please sign in to comment.