SimpleMonitor optionally displays user_monitor stats (#970)
* Adding with_user_monitor() to SimpleMonitor * Satisfy clippy * Satisfy fmt and pylibafl * Fix leading whitespace
This commit is contained in:
parent
476cb7e7dc
commit
2b092f40fa
@ -195,13 +195,16 @@ fn fuzz(
|
|||||||
let file_null = File::open("/dev/null")?;
|
let file_null = File::open("/dev/null")?;
|
||||||
|
|
||||||
// 'While the stats are state, they are usually used in the broker - which is likely never restarted
|
// 'While the stats are state, they are usually used in the broker - which is likely never restarted
|
||||||
let monitor = SimpleMonitor::new(|s| {
|
let monitor = SimpleMonitor::with_user_monitor(
|
||||||
#[cfg(unix)]
|
|s| {
|
||||||
writeln!(&mut stdout_cpy, "{}", s).unwrap();
|
#[cfg(unix)]
|
||||||
#[cfg(windows)]
|
writeln!(&mut stdout_cpy, "{s}").unwrap();
|
||||||
println!("{s}");
|
#[cfg(windows)]
|
||||||
writeln!(log.borrow_mut(), "{:?} {}", current_time(), s).unwrap();
|
println!("{s}");
|
||||||
});
|
writeln!(log.borrow_mut(), "{:?} {s}", current_time()).unwrap();
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
|
||||||
let mut shmem_provider = StdShMemProvider::new()?;
|
let mut shmem_provider = StdShMemProvider::new()?;
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ pub use prometheus::PrometheusMonitor;
|
|||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub mod disk;
|
pub mod disk;
|
||||||
use alloc::{fmt::Debug, string::String, vec::Vec};
|
use alloc::{fmt::Debug, string::String, vec::Vec};
|
||||||
|
use core::fmt::Write;
|
||||||
use core::{fmt, time::Duration};
|
use core::{fmt, time::Duration};
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
@ -386,6 +387,7 @@ where
|
|||||||
{
|
{
|
||||||
print_fn: F,
|
print_fn: F,
|
||||||
start_time: Duration,
|
start_time: Duration,
|
||||||
|
print_user_monitor: bool,
|
||||||
client_stats: Vec<ClientStats>,
|
client_stats: Vec<ClientStats>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -421,7 +423,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn display(&mut self, event_msg: String, sender_id: u32) {
|
fn display(&mut self, event_msg: String, sender_id: u32) {
|
||||||
let fmt = format!(
|
let mut fmt = format!(
|
||||||
"[{} #{}] run time: {}, clients: {}, corpus: {}, objectives: {}, executions: {}, exec/sec: {}",
|
"[{} #{}] run time: {}, clients: {}, corpus: {}, objectives: {}, executions: {}, exec/sec: {}",
|
||||||
event_msg,
|
event_msg,
|
||||||
sender_id,
|
sender_id,
|
||||||
@ -432,6 +434,14 @@ where
|
|||||||
self.total_execs(),
|
self.total_execs(),
|
||||||
self.execs_per_sec_pretty()
|
self.execs_per_sec_pretty()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if self.print_user_monitor {
|
||||||
|
let client = self.client_stats_mut_for(sender_id);
|
||||||
|
for (key, val) in &client.user_monitor {
|
||||||
|
write!(fmt, ", {key}: {val}").unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
(self.print_fn)(fmt);
|
(self.print_fn)(fmt);
|
||||||
|
|
||||||
// Only print perf monitor if the feature is enabled
|
// Only print perf monitor if the feature is enabled
|
||||||
@ -459,6 +469,7 @@ where
|
|||||||
Self {
|
Self {
|
||||||
print_fn,
|
print_fn,
|
||||||
start_time: current_time(),
|
start_time: current_time(),
|
||||||
|
print_user_monitor: false,
|
||||||
client_stats: vec![],
|
client_stats: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -468,6 +479,17 @@ where
|
|||||||
Self {
|
Self {
|
||||||
print_fn,
|
print_fn,
|
||||||
start_time,
|
start_time,
|
||||||
|
print_user_monitor: false,
|
||||||
|
client_stats: vec![],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates the monitor that also prints the user monitor
|
||||||
|
pub fn with_user_monitor(print_fn: F, print_user_monitor: bool) -> Self {
|
||||||
|
Self {
|
||||||
|
print_fn,
|
||||||
|
start_time: current_time(),
|
||||||
|
print_user_monitor,
|
||||||
client_stats: vec![],
|
client_stats: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -971,6 +993,7 @@ pub mod pybind {
|
|||||||
inner: SimpleMonitor {
|
inner: SimpleMonitor {
|
||||||
print_fn: Box::new(closure),
|
print_fn: Box::new(closure),
|
||||||
start_time: self.inner.start_time,
|
start_time: self.inner.start_time,
|
||||||
|
print_user_monitor: false,
|
||||||
client_stats: self.inner.client_stats.clone(),
|
client_stats: self.inner.client_stats.clone(),
|
||||||
},
|
},
|
||||||
print_fn: self.print_fn.clone(),
|
print_fn: self.print_fn.clone(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user