some preliminary schwags at making flamegraphs

turns out, they're pretty useless. I mean, for debugging actual
running code. it tells us basically what we know already which is
99.99% of the time is spent waiting on inter-thread messaging
in hosted mode.
This commit is contained in:
bunnie 2022-08-01 01:32:19 +08:00
parent 0166bc3d4a
commit 7d62ca85b8
5 changed files with 104 additions and 1 deletions

1
Cargo.lock generated
View file

@ -2364,6 +2364,7 @@ dependencies = [
"cipher 0.4.3",
"digest 0.9.0",
"gam",
"hex 0.4.3",
"hkdf",
"llio",
"locales",

View file

@ -52,6 +52,8 @@ utralib = { path = "../../utralib"}
rand = "0.7.3"
rand_chacha = "0.3.1"
hex = { version = "0.4.3", default-features = false, features = ["alloc"], optional = true }
[features]
# when selected, physical disk addresses are set to 64 bits, otherwise, they are 32 bits.
# 32 bit addressing is recommended for Precursor, as its disk is only 128MiB and it has limited RAM for bookkeeping.
@ -76,4 +78,6 @@ migration1 = []
# hazardous debug flag decorates any debug paths that might accidentally leak key material
hazardous-debug = []
test-rekey = []
default = ["mbbb"]
# routines to help with performance profiling of the PDDB in hosted mode
pddb-flamegraph = ["hex"]
default = ["mbbb", "pddb-flamegraph"]

View file

@ -381,6 +381,9 @@ mod tests;
#[allow(unused_imports)]
use tests::*;
#[cfg(feature="pddb-flamegraph")]
mod profiling;
use num_traits::*;
use xous::{send_message, Message, msg_blocking_scalar_unpack};
use xous_ipc::Buffer;
@ -663,6 +666,8 @@ fn wrapped_main() -> ! {
latest_cache = basis_cache.cache_size();
log::info!("PDDB post-mount caching stats: {} heap, {} cache", latest_heap, latest_cache);
scrub_run.store(true, Ordering::SeqCst);
#[cfg(feature="pddb-flamegraph")]
profiling::do_query_work();
}
}
}),

View file

@ -0,0 +1,66 @@
use std::thread;
#[allow(unused_imports)]
use std::io::{Error, ErrorKind, Write, Read};
const PROFILING_DICT: &'static str = "pdict";
const NUMKEYS: usize = 200;
const PROFILE_ITERS: usize = 200;
fn gen_guid(trng: &mut trng::Trng) -> String {
let mut guid = [0u8; 16];
trng.fill_bytes(&mut guid);
hex::encode(guid)
}
/// A test that repeatedly queries a dictionary with many entries
pub fn do_query_work() {
let _ = thread::spawn(|| {
let xns = xous_names::XousNames::new().unwrap();
let pddb = pddb::Pddb::new();
let mut trng = trng::Trng::new(&xns).unwrap();
let key_count = match pddb.list_keys(PROFILING_DICT, None) {
Ok(kl) => kl.len(),
Err(_e) => {
0
}
};
// populate the dictionary if we're short the number of keys we want to have
log::info!("test setup");
if key_count < NUMKEYS {
for _ in 0..NUMKEYS - key_count {
let guid = gen_guid(&mut trng);
match pddb.get(
PROFILING_DICT,
&guid,
None,
true,
true,
Some(256),
None::<fn()>
) {
Ok(mut key) => {
let mut rdata = [0u8; 192];
trng.fill_bytes(&mut rdata);
key.write_all(&rdata).ok();
}
Err(e) => log::error!("couldn't create test key {:?}", e),
}
}
}
log::info!("starting main loop");
let modals = modals::Modals::new(&xns).unwrap();
modals.show_notification("press any key to start profiling run.", None).ok();
modals.dynamic_notification(Some("running"), None).ok();
for i in 0..PROFILE_ITERS {
let klist = pddb.list_keys(PROFILING_DICT, None).unwrap();
log::info!("iter {}, klist: {}", i, klist.len());
}
modals.dynamic_notification_close().ok();
modals.show_notification("done", None).ok();
log::info!("quitting");
});
}

View file

@ -382,6 +382,33 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Some(&["--features", "renode-bypass"]),
)?;
}
Some("pddb-flamegraph") => {
let mut args = env::args();
args.nth(1);
let mut pkgs = pddb_dev_pkgs.to_vec();
// add pkgs required for functional testing. Quite a bit. :-/
pkgs.push("llio");
pkgs.push("root-keys");
pkgs.push("jtag");
pkgs.push("com");
pkgs.push("gam");
pkgs.push("net");
pkgs.push("dns");
pkgs.push("graphics-server");
pkgs.push("modals");
pkgs.push("keyboard");
pkgs.push("ime-frontend");
pkgs.push("ime-plugin-shell");
pkgs.push("status");
pkgs.push("usb-device-xous");
generate_app_menus(&vec![]);
run(false, &pkgs,
Some(&[
"--features", "pddbtest",
"--features", "pddb-flamegraph",
]), false)?
}
Some("renode-aes-test") => {
generate_app_menus(&Vec::<String>::new());
renode_image(false, &aestest_pkgs, &[], None, None)?