Skip to content

Commit b0aa484

Browse files
committed
Log a few timings and a few other small tweaks
1 parent de0231b commit b0aa484

File tree

6 files changed

+58
-16
lines changed

6 files changed

+58
-16
lines changed

src/c_api/ext_fns/handle.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use libc::size_t;
22
use positioned_io::ReadAt;
3+
use std::time::Instant;
34

45
use super::*;
56
use crate::c_api::PossumError::NoError;
@@ -115,6 +116,7 @@ pub extern "C" fn possum_single_read_at(
115116
buf: *mut PossumBuf,
116117
offset: u64,
117118
) -> PossumError {
119+
let started = Instant::now();
118120
let rust_key = key.as_ref();
119121
let value = match unsafe { handle.as_ref() }
120122
.unwrap()
@@ -132,14 +134,15 @@ pub extern "C" fn possum_single_read_at(
132134
Err(err) => return err.into(),
133135
Ok(ok) => ok,
134136
};
135-
// eprintln!(
136-
// "reading single {} bytes at {} from {}, read {}: {}",
137-
// read_buf.len(),
138-
// offset,
139-
// value.length(),
140-
// r_nbyte,
141-
// rust_key.escape_ascii(),
142-
// );
137+
debug!(
138+
"{:?}: reading single {} bytes at {} from {}, read {}: {}",
139+
started.elapsed(),
140+
read_buf.len(),
141+
offset,
142+
value.length(),
143+
r_nbyte,
144+
rust_key.escape_ascii(),
145+
);
143146
buf.size = r_nbyte;
144147
NoError
145148
}

src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,12 @@ pub mod env;
6767
mod reader;
6868
use reader::Reader;
6969

70-
// Concurrency related stuff that's replaced by loom or shuttle.
70+
// Concurrency-related stuff that's replaced by loom or shuttle.
7171
pub mod concurrency;
7272
use concurrency::*;
7373

74+
mod macros;
75+
7476
use self::concurrency::sync::{Arc, Mutex, MutexGuard, RwLock, RwLockReadGuard};
7577
use crate::handle::WithHandle;
7678

@@ -709,7 +711,7 @@ where
709711
}
710712
}
711713

712-
#[derive(Ord, PartialOrd, Eq, PartialEq, Copy, Clone)]
714+
#[derive(Ord, PartialOrd, Eq, PartialEq, Copy, Clone, Debug)]
713715
struct ReadExtent {
714716
pub offset: u64,
715717
pub len: u64,

src/macros.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#[macro_export]
2+
macro_rules! log_time {
3+
($fmt:literal, $expr:expr) => {{
4+
let start = std::time::Instant::now();
5+
let ret = $expr;
6+
let duration = start.elapsed();
7+
tracing::debug!(target: "possum::timing", duration = ?duration, $fmt);
8+
ret
9+
}};
10+
({ $($fields:tt)* }, $($exprs:expr),+; $($stmts:stmt);*) => {
11+
let start = std::time::Instant::now();
12+
$($stmts);+
13+
let duration = start.elapsed();
14+
tracing::debug!(target: "possum::timing", { duration = ?duration, $($fields)* }, $($exprs),+);
15+
};
16+
($($args:expr),+; $($stmt:stmt);+) => {
17+
let start = std::time::Instant::now();
18+
$($stmt);+
19+
let duration = start.elapsed();
20+
tracing::debug!(
21+
target: "possum::timing",
22+
duration = ?duration,
23+
$($args),+
24+
);
25+
};
26+
}

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ enum DatabaseCommands {
4242
file: OsString,
4343
},
4444
ListKeys {
45+
#[arg(default_value = "")]
4546
prefix: String,
4647
},
4748
ReadKey {

src/reader.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,14 @@ where
4141

4242
/// Takes a snapshot and commits the read transaction.
4343
pub fn begin(self) -> Result<Snapshot> {
44-
let file_clones = self.clone_files().context("cloning files")?;
45-
self.owned_tx
46-
.end_tx(|tx| tx.commit())
47-
.context("committing transaction")?
48-
.complete();
44+
log_time!(
45+
{ num_files = self.reads.len() },
46+
"cloning files";
47+
let file_clones = self.clone_files().context("cloning files")?
48+
);
49+
let commit = || self.owned_tx.end_tx(|tx| tx.commit());
50+
let post_work = log_time!("reader commit", commit());
51+
post_work.context("committing transaction")?.complete();
4952
Ok(Snapshot { file_clones })
5053
}
5154

@@ -99,9 +102,14 @@ where
99102
if self.owned_tx.as_handle().dir_supports_file_cloning() {
100103
match self.clone_file(file_id, tempdir, cache, src_dir) {
101104
Err(err) if err.root_cause_is_unsupported_filesystem() => (),
102-
default => return default,
105+
Err(err) => return Err(err),
106+
default @ Ok(_) => {
107+
info!(%file_id, tempdir = %tempdir.as_ref().unwrap().path().display(), "cloned file");
108+
return default;
109+
}
103110
}
104111
}
112+
warn!(%file_id, ?read_extents, "falling back to segment locking to read");
105113
self.get_file_for_read_by_segment_locking(file_id, read_extents)
106114
}
107115

src/timing.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
use std::time::Instant;
2+

0 commit comments

Comments
 (0)