add performance monitoring in for bulk reads

This commit is contained in:
bunnie 2022-10-27 16:45:04 +08:00
parent 9856f60fbb
commit c82a79dab9
2 changed files with 29 additions and 4 deletions

View file

@ -684,12 +684,18 @@ impl<'a> ActionManager<'a> {
match self.mode_cache { match self.mode_cache {
VaultMode::Password => { VaultMode::Password => {
let start = self.tt.elapsed_ms(); let start = self.tt.elapsed_ms();
#[cfg(feature="vaultperf")]
self.perfentry(&self.pm, PERFMETA_STARTBLOCK, 1, std::line!());
let mut klen = 0; let mut klen = 0;
match self.pddb.borrow().read_dict(VAULT_PASSWORD_DICT, None, Some(256 * 1024)) { match self.pddb.borrow().read_dict(VAULT_PASSWORD_DICT, None, Some(256 * 1024)) {
Ok(keys) => { Ok(keys) => {
#[cfg(feature="vaultperf")]
self.perfentry(&self.pm, PERFMETA_NONE, 1, std::line!());
let mut oom_keys = 0; let mut oom_keys = 0;
il.reserve(keys.len()); il.reserve(keys.len());
for key in keys { for key in keys {
#[cfg(feature="vaultperf")]
self.perfentry(&self.pm, PERFMETA_NONE, 1, std::line!());
if let Some(data) = key.data { if let Some(data) = key.data {
if let Some(pw) = storage::PasswordRecord::try_from(data).ok() { if let Some(pw) = storage::PasswordRecord::try_from(data).ok() {
let extra = format!("{}; {}{}", let extra = format!("{}; {}{}",
@ -728,6 +734,9 @@ impl<'a> ActionManager<'a> {
} }
}, },
} }
#[cfg(feature="vaultperf")]
self.perfentry(&self.pm, PERFMETA_ENDBLOCK, 1, std::line!());
/* DELETEME: kept around for quick debugging without having to look through commit history /* DELETEME: kept around for quick debugging without having to look through commit history
once we have confidence in the new method, we can drop this code right away. once we have confidence in the new method, we can drop this code right away.

View file

@ -1406,16 +1406,22 @@ fn wrapped_main() -> ! {
// Optimized bulk data read handler. See lib.rs for documentation. // Optimized bulk data read handler. See lib.rs for documentation.
Opcode::DictBulkRead => { Opcode::DictBulkRead => {
const BULKREAD_TIMEOUT_MS: u64 = 5000; const BULKREAD_TIMEOUT_MS: u64 = 5000;
#[cfg(feature="perfcounter")]
pddb_os.perf_entry(FILE_ID_SERVICES_PDDB_SRC_MAIN, perflib::PERFMETA_STARTBLOCK, 5, std::line!());
let range = msg.body.memory_message_mut().unwrap(); let range = msg.body.memory_message_mut().unwrap();
let buf = unsafe { core::slice::from_raw_parts_mut( let buf = unsafe { core::slice::from_raw_parts_mut(
range.buf.as_mut_ptr(), range.buf.as_mut_ptr(),
range.buf.len(), range.buf.len(),
)}; )};
// unpack the descriptor // unpack the descriptor
#[cfg(feature="perfcounter")]
pddb_os.perf_entry(FILE_ID_SERVICES_PDDB_SRC_MAIN, perflib::PERFMETA_NONE, 5, std::line!());
let pos = range.offset.map(|o| o.get()).unwrap_or_default(); let pos = range.offset.map(|o| o.get()).unwrap_or_default();
let r = unsafe { rkyv::archived_value::<PddbDictRequest>(buf, pos) }; let r = unsafe { rkyv::archived_value::<PddbDictRequest>(buf, pos) };
let bulk_descriptor = r.deserialize(&mut AllocDeserializer).unwrap(); let bulk_descriptor = r.deserialize(&mut AllocDeserializer).unwrap();
// check for a timeout; retire state if we did timeout // check for a timeout; retire state if we did timeout
#[cfg(feature="perfcounter")]
pddb_os.perf_entry(FILE_ID_SERVICES_PDDB_SRC_MAIN, perflib::PERFMETA_NONE, 5, std::line!());
let mut timed_out = false; let mut timed_out = false;
if let Some(state) = &bulkread_state { if let Some(state) = &bulkread_state {
if tt.elapsed_ms() - state.last_time > BULKREAD_TIMEOUT_MS { if tt.elapsed_ms() - state.last_time > BULKREAD_TIMEOUT_MS {
@ -1426,6 +1432,8 @@ fn wrapped_main() -> ! {
bulkread_state = None; bulkread_state = None;
} }
// handle state initialization, if no call was previously initiated // handle state initialization, if no call was previously initiated
#[cfg(feature="perfcounter")]
pddb_os.perf_entry(FILE_ID_SERVICES_PDDB_SRC_MAIN, perflib::PERFMETA_NONE, 5, std::line!());
let mut first_call = false; let mut first_call = false;
if bulkread_state.is_none() { if bulkread_state.is_none() {
first_call = true; first_call = true;
@ -1470,6 +1478,8 @@ fn wrapped_main() -> ! {
let mut finished = false; let mut finished = false;
// handle data packing into the structure // handle data packing into the structure
if let Some(state) = &mut bulkread_state { if let Some(state) = &mut bulkread_state {
#[cfg(feature="perfcounter")]
pddb_os.perf_entry(FILE_ID_SERVICES_PDDB_SRC_MAIN, perflib::PERFMETA_NONE, 5, std::line!());
// check that the token matches, if this isn't a first call to the function // check that the token matches, if this isn't a first call to the function
if !first_call { if !first_call {
if state.token != bulk_descriptor.token { if state.token != bulk_descriptor.token {
@ -1490,6 +1500,8 @@ fn wrapped_main() -> ! {
Failure(String) Failure(String)
} }
loop { loop {
#[cfg(feature="perfcounter")]
pddb_os.perf_entry(FILE_ID_SERVICES_PDDB_SRC_MAIN, perflib::PERFMETA_STARTBLOCK, 6, std::line!());
let ser_result: SerializeResult = let ser_result: SerializeResult =
if let Some(key_name) = state.key_list.pop() { if let Some(key_name) = state.key_list.pop() {
let attr = basis_cache.key_attributes(&mut pddb_os, let attr = basis_cache.key_attributes(&mut pddb_os,
@ -1508,6 +1520,8 @@ fn wrapped_main() -> ! {
Some(&attr.basis), Some(&attr.basis),
) { ) {
Ok(readlen) => { Ok(readlen) => {
#[cfg(feature="perfcounter")]
pddb_os.perf_entry(FILE_ID_SERVICES_PDDB_SRC_MAIN, perflib::PERFMETA_NONE, 6, std::line!());
assert!(readlen == attr.len, "Bulk read key length did not match expected length"); assert!(readlen == attr.len, "Bulk read key length did not match expected length");
let rec = PddbKeyRecord { let rec = PddbKeyRecord {
name: key_name.to_string(), name: key_name.to_string(),
@ -1557,10 +1571,8 @@ fn wrapped_main() -> ! {
break; break;
}; };
// HERE'S THE PROBLEM: the `buf` returned is the inner of the allocated buf. the overall length #[cfg(feature="perfcounter")]
// of the record serialized isn't exposed anywhere. So we can't know where to advance the buffer pddb_os.perf_entry(FILE_ID_SERVICES_PDDB_SRC_MAIN, perflib::PERFMETA_NONE, 6, std::line!());
// pointer to, to stack the next archived result. The other option would be to use the .write()
// method but then we'd need to...make a serializer for the structure. which is agains the whole point of it...
match ser_result { match ser_result {
SerializeResult::Success(pos, len, sbuf, _key_name, pre_buf) => { SerializeResult::Success(pos, len, sbuf, _key_name, pre_buf) => {
log::debug!("packing message of {}({})", len + pos, pos); log::debug!("packing message of {}({})", len + pos, pos);
@ -1584,6 +1596,8 @@ fn wrapped_main() -> ! {
break; break;
} }
} }
#[cfg(feature="perfcounter")]
pddb_os.perf_entry(FILE_ID_SERVICES_PDDB_SRC_MAIN, perflib::PERFMETA_ENDBLOCK, 6, std::line!());
} }
if finished { if finished {
header.code = PddbBulkReadCode::Last as u32; header.code = PddbBulkReadCode::Last as u32;
@ -1601,6 +1615,8 @@ fn wrapped_main() -> ! {
if finished { if finished {
bulkread_state = None; bulkread_state = None;
} }
#[cfg(feature="perfcounter")]
pddb_os.perf_entry(FILE_ID_SERVICES_PDDB_SRC_MAIN, perflib::PERFMETA_ENDBLOCK, 5, std::line!());
} }
Opcode::SeekKeyStd => { Opcode::SeekKeyStd => {