Function febug::install_handler
source · pub fn install_handler() -> bool
Expand description
Call debug_handler()
with FEBUG_SIGNUM
(SIGUSR2
by default)
Examples found in repository?
examples/string-sorts.rs (line 20)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
fn main() {
febug::start();
if febug::install_handler() {
// Normal registration by TypeId, variables use .wrap(...)
let mut fmt = febug::FORMATTERS.lock().unwrap();
fmt.insert(TypeId::of::<String>().into(), |of, vid| {
let data = unsafe { &*(vid as *const String) };
let _ = of.write_all(data.as_bytes());
let _ = of.write_all(b"\n");
});
// Custom registration with an explicit type number and Wrapper::new()
fmt.insert(0.into(), |of: &mut File, _| {
let _ = write!(of, "{}\n", COMPARISONS.load(Ordering::Relaxed));
});
}
let _comparisons_wrapper = Wrapper::new(0, &COMPARISONS, format_args!("comparisons"));
let threads = (0..10)
.map(|i| {
thread::spawn(move || {
let mut sorteing = "The quick red fox jumps over the lazy brown \
dog... tHE QUICK RED FOX JUMPS OVER THE \
LAZY BROWN DOG!!"
[0..(i + 1) * 10]
.to_string();
let _sorteing_w = sorteing.wrap(format_args!("cool_data_{}", i));
unsafe { sorteing.as_bytes_mut() }.sort_unstable_by(|a, b| {
thread::sleep(Duration::from_millis(250));
COMPARISONS.fetch_add(1, Ordering::Relaxed);
a.cmp(b)
});
thread::sleep(Duration::from_secs(2));
})
})
.collect::<Vec<_>>();
for t in threads {
let _ = t.join();
}
}