Use UserStats for Stability (#451)
* stability:serstats * tostring * fix no_std * fix * fmt * clippy
This commit is contained in:
parent
250ec8d1e0
commit
87cd44b762
@ -170,15 +170,11 @@ where
|
|||||||
Event::UpdateExecStats {
|
Event::UpdateExecStats {
|
||||||
time,
|
time,
|
||||||
executions,
|
executions,
|
||||||
stability,
|
|
||||||
phantom: _,
|
phantom: _,
|
||||||
} => {
|
} => {
|
||||||
// TODO: The monitor buffer should be added on client add.
|
// TODO: The monitor buffer should be added on client add.
|
||||||
let client = monitor.client_stats_mut_for(client_id);
|
let client = monitor.client_stats_mut_for(client_id);
|
||||||
client.update_executions(*executions as u64, *time);
|
client.update_executions(*executions as u64, *time);
|
||||||
if let Some(stability) = stability {
|
|
||||||
client.update_stability(*stability);
|
|
||||||
}
|
|
||||||
monitor.display(event.name().to_string(), client_id);
|
monitor.display(event.name().to_string(), client_id);
|
||||||
Ok(BrokerEventResult::Handled)
|
Ok(BrokerEventResult::Handled)
|
||||||
}
|
}
|
||||||
@ -196,7 +192,6 @@ where
|
|||||||
Event::UpdatePerfMonitor {
|
Event::UpdatePerfMonitor {
|
||||||
time,
|
time,
|
||||||
executions,
|
executions,
|
||||||
stability,
|
|
||||||
introspection_monitor,
|
introspection_monitor,
|
||||||
phantom: _,
|
phantom: _,
|
||||||
} => {
|
} => {
|
||||||
@ -208,10 +203,6 @@ where
|
|||||||
// Update the normal monitor for this client
|
// Update the normal monitor for this client
|
||||||
client.update_executions(*executions as u64, *time);
|
client.update_executions(*executions as u64, *time);
|
||||||
|
|
||||||
if let Some(stability) = stability {
|
|
||||||
client.update_stability(*stability);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the performance monitor for this client
|
// Update the performance monitor for this client
|
||||||
client.update_introspection_monitor((**introspection_monitor).clone());
|
client.update_introspection_monitor((**introspection_monitor).clone());
|
||||||
|
|
||||||
|
@ -6,7 +6,10 @@ pub mod llmp;
|
|||||||
pub use llmp::*;
|
pub use llmp::*;
|
||||||
|
|
||||||
use ahash::AHasher;
|
use ahash::AHasher;
|
||||||
use alloc::{string::String, vec::Vec};
|
use alloc::{
|
||||||
|
string::{String, ToString},
|
||||||
|
vec::Vec,
|
||||||
|
};
|
||||||
use core::{fmt, hash::Hasher, marker::PhantomData, time::Duration};
|
use core::{fmt, hash::Hasher, marker::PhantomData, time::Duration};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
@ -187,8 +190,6 @@ where
|
|||||||
UpdateExecStats {
|
UpdateExecStats {
|
||||||
/// The time of generation of the [`Event`]
|
/// The time of generation of the [`Event`]
|
||||||
time: Duration,
|
time: Duration,
|
||||||
/// The stability of this fuzzer node, if known
|
|
||||||
stability: Option<f32>,
|
|
||||||
/// The executions of this client
|
/// The executions of this client
|
||||||
executions: usize,
|
executions: usize,
|
||||||
/// [`PhantomData`]
|
/// [`PhantomData`]
|
||||||
@ -210,8 +211,6 @@ where
|
|||||||
time: Duration,
|
time: Duration,
|
||||||
/// The executions of this client
|
/// The executions of this client
|
||||||
executions: usize,
|
executions: usize,
|
||||||
/// The stability of this fuzzer node, if known
|
|
||||||
stability: Option<f32>,
|
|
||||||
/// Current performance statistics
|
/// Current performance statistics
|
||||||
introspection_monitor: Box<ClientPerfMonitor>,
|
introspection_monitor: Box<ClientPerfMonitor>,
|
||||||
|
|
||||||
@ -256,7 +255,6 @@ where
|
|||||||
} => "Testcase",
|
} => "Testcase",
|
||||||
Event::UpdateExecStats {
|
Event::UpdateExecStats {
|
||||||
time: _,
|
time: _,
|
||||||
stability: _,
|
|
||||||
executions: _,
|
executions: _,
|
||||||
phantom: _,
|
phantom: _,
|
||||||
}
|
}
|
||||||
@ -269,7 +267,6 @@ where
|
|||||||
Event::UpdatePerfMonitor {
|
Event::UpdatePerfMonitor {
|
||||||
time: _,
|
time: _,
|
||||||
executions: _,
|
executions: _,
|
||||||
stability: _,
|
|
||||||
introspection_monitor: _,
|
introspection_monitor: _,
|
||||||
phantom: _,
|
phantom: _,
|
||||||
} => "PerfMonitor",
|
} => "PerfMonitor",
|
||||||
@ -351,7 +348,6 @@ where
|
|||||||
S: HasExecutions + HasClientPerfMonitor,
|
S: HasExecutions + HasClientPerfMonitor,
|
||||||
{
|
{
|
||||||
let executions = *state.executions();
|
let executions = *state.executions();
|
||||||
let stability = *state.stability();
|
|
||||||
let cur = current_time();
|
let cur = current_time();
|
||||||
// default to 0 here to avoid crashes on clock skew
|
// default to 0 here to avoid crashes on clock skew
|
||||||
if cur.checked_sub(last_report_time).unwrap_or_default() > monitor_timeout {
|
if cur.checked_sub(last_report_time).unwrap_or_default() > monitor_timeout {
|
||||||
@ -361,12 +357,23 @@ where
|
|||||||
state,
|
state,
|
||||||
Event::UpdateExecStats {
|
Event::UpdateExecStats {
|
||||||
executions,
|
executions,
|
||||||
stability,
|
|
||||||
time: cur,
|
time: cur,
|
||||||
phantom: PhantomData,
|
phantom: PhantomData,
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
if let Some(x) = state.stability() {
|
||||||
|
let stability = f64::from(*x);
|
||||||
|
self.fire(
|
||||||
|
state,
|
||||||
|
Event::UpdateUserStats {
|
||||||
|
name: "stability".to_string(),
|
||||||
|
value: UserStats::Float(stability),
|
||||||
|
phantom: PhantomData,
|
||||||
|
},
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
|
||||||
// If performance monitor are requested, fire the `UpdatePerfMonitor` event
|
// If performance monitor are requested, fire the `UpdatePerfMonitor` event
|
||||||
#[cfg(feature = "introspection")]
|
#[cfg(feature = "introspection")]
|
||||||
{
|
{
|
||||||
@ -381,7 +388,6 @@ where
|
|||||||
Event::UpdatePerfMonitor {
|
Event::UpdatePerfMonitor {
|
||||||
executions,
|
executions,
|
||||||
time: cur,
|
time: cur,
|
||||||
stability,
|
|
||||||
introspection_monitor: Box::new(state.introspection_monitor().clone()),
|
introspection_monitor: Box::new(state.introspection_monitor().clone()),
|
||||||
phantom: PhantomData,
|
phantom: PhantomData,
|
||||||
},
|
},
|
||||||
|
@ -150,16 +150,12 @@ where
|
|||||||
Event::UpdateExecStats {
|
Event::UpdateExecStats {
|
||||||
time,
|
time,
|
||||||
executions,
|
executions,
|
||||||
stability,
|
|
||||||
phantom: _,
|
phantom: _,
|
||||||
} => {
|
} => {
|
||||||
// TODO: The monitor buffer should be added on client add.
|
// TODO: The monitor buffer should be added on client add.
|
||||||
let client = monitor.client_stats_mut_for(0);
|
let client = monitor.client_stats_mut_for(0);
|
||||||
|
|
||||||
client.update_executions(*executions as u64, *time);
|
client.update_executions(*executions as u64, *time);
|
||||||
if let Some(stability) = stability {
|
|
||||||
client.update_stability(*stability);
|
|
||||||
}
|
|
||||||
|
|
||||||
monitor.display(event.name().to_string(), 0);
|
monitor.display(event.name().to_string(), 0);
|
||||||
Ok(BrokerEventResult::Handled)
|
Ok(BrokerEventResult::Handled)
|
||||||
@ -179,7 +175,6 @@ where
|
|||||||
Event::UpdatePerfMonitor {
|
Event::UpdatePerfMonitor {
|
||||||
time,
|
time,
|
||||||
executions,
|
executions,
|
||||||
stability,
|
|
||||||
introspection_monitor,
|
introspection_monitor,
|
||||||
phantom: _,
|
phantom: _,
|
||||||
} => {
|
} => {
|
||||||
@ -187,9 +182,6 @@ where
|
|||||||
let client = &mut monitor.client_stats_mut()[0];
|
let client = &mut monitor.client_stats_mut()[0];
|
||||||
client.update_executions(*executions as u64, *time);
|
client.update_executions(*executions as u64, *time);
|
||||||
client.update_introspection_monitor((**introspection_monitor).clone());
|
client.update_introspection_monitor((**introspection_monitor).clone());
|
||||||
if let Some(stability) = stability {
|
|
||||||
client.update_stability(*stability);
|
|
||||||
}
|
|
||||||
monitor.display(event.name().to_string(), 0);
|
monitor.display(event.name().to_string(), 0);
|
||||||
Ok(BrokerEventResult::Handled)
|
Ok(BrokerEventResult::Handled)
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,11 @@
|
|||||||
pub mod multi;
|
pub mod multi;
|
||||||
pub use multi::MultiMonitor;
|
pub use multi::MultiMonitor;
|
||||||
|
|
||||||
use alloc::{
|
use alloc::{string::String, vec::Vec};
|
||||||
string::{String, ToString},
|
|
||||||
vec::Vec,
|
#[cfg(feature = "introspection")]
|
||||||
};
|
use alloc::string::ToString;
|
||||||
|
|
||||||
use core::{fmt, time::Duration};
|
use core::{fmt, time::Duration};
|
||||||
use hashbrown::HashMap;
|
use hashbrown::HashMap;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@ -20,6 +21,8 @@ const CLIENT_STATS_TIME_WINDOW_SECS: u64 = 5; // 5 seconds
|
|||||||
pub enum UserStats {
|
pub enum UserStats {
|
||||||
/// A numerical value
|
/// A numerical value
|
||||||
Number(u64),
|
Number(u64),
|
||||||
|
/// A Float value
|
||||||
|
Float(f64),
|
||||||
/// A `String`
|
/// A `String`
|
||||||
String(String),
|
String(String),
|
||||||
/// A ratio of two values
|
/// A ratio of two values
|
||||||
@ -30,6 +33,7 @@ impl fmt::Display for UserStats {
|
|||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
UserStats::Number(n) => write!(f, "{}", n),
|
UserStats::Number(n) => write!(f, "{}", n),
|
||||||
|
UserStats::Float(n) => write!(f, "{}", n),
|
||||||
UserStats::String(s) => write!(f, "{}", s),
|
UserStats::String(s) => write!(f, "{}", s),
|
||||||
UserStats::Ratio(a, b) => {
|
UserStats::Ratio(a, b) => {
|
||||||
if *b == 0 {
|
if *b == 0 {
|
||||||
@ -60,8 +64,6 @@ pub struct ClientStats {
|
|||||||
pub last_execs_per_sec: f32,
|
pub last_execs_per_sec: f32,
|
||||||
/// User-defined monitor
|
/// User-defined monitor
|
||||||
pub user_monitor: HashMap<String, UserStats>,
|
pub user_monitor: HashMap<String, UserStats>,
|
||||||
/// Stability, and if we ever received a stability value
|
|
||||||
pub stability: Option<f32>,
|
|
||||||
/// Client performance statistics
|
/// Client performance statistics
|
||||||
#[cfg(feature = "introspection")]
|
#[cfg(feature = "introspection")]
|
||||||
pub introspection_monitor: ClientPerfMonitor,
|
pub introspection_monitor: ClientPerfMonitor,
|
||||||
@ -91,11 +93,6 @@ impl ClientStats {
|
|||||||
self.objective_size = objective_size;
|
self.objective_size = objective_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// we got a new information about stability for this client, insert it.
|
|
||||||
pub fn update_stability(&mut self, stability: f32) {
|
|
||||||
self.stability = Some(stability);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the calculated executions per second for this client
|
/// Get the calculated executions per second for this client
|
||||||
#[allow(clippy::cast_sign_loss, clippy::cast_precision_loss)]
|
#[allow(clippy::cast_sign_loss, clippy::cast_precision_loss)]
|
||||||
pub fn execs_per_sec(&mut self, cur_time: Duration) -> u64 {
|
pub fn execs_per_sec(&mut self, cur_time: Duration) -> u64 {
|
||||||
@ -157,24 +154,6 @@ pub trait Monitor {
|
|||||||
/// show the monitor to the user
|
/// show the monitor to the user
|
||||||
fn display(&mut self, event_msg: String, sender_id: u32);
|
fn display(&mut self, event_msg: String, sender_id: u32);
|
||||||
|
|
||||||
/// Show the Stabiliity
|
|
||||||
fn stability(&self) -> Option<f32> {
|
|
||||||
let mut stability_total = 0_f32;
|
|
||||||
let mut num = 0_usize;
|
|
||||||
for stat in self.client_stats() {
|
|
||||||
if let Some(stability) = stat.stability {
|
|
||||||
stability_total += stability;
|
|
||||||
num += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if num == 0 {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
#[allow(clippy::cast_precision_loss)]
|
|
||||||
Some(stability_total / num as f32)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Amount of elements in the corpus (combined for all children)
|
/// Amount of elements in the corpus (combined for all children)
|
||||||
fn corpus_size(&self) -> u64 {
|
fn corpus_size(&self) -> u64 {
|
||||||
self.client_stats()
|
self.client_stats()
|
||||||
@ -295,7 +274,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 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,
|
||||||
format_duration_hms(&(current_time() - self.start_time)),
|
format_duration_hms(&(current_time() - self.start_time)),
|
||||||
@ -303,11 +282,6 @@ where
|
|||||||
self.corpus_size(),
|
self.corpus_size(),
|
||||||
self.objective_size(),
|
self.objective_size(),
|
||||||
self.total_execs(),
|
self.total_execs(),
|
||||||
if let Some(stability) = self.stability() {
|
|
||||||
format!(", stability: {:.2}", stability)
|
|
||||||
} else {
|
|
||||||
"".to_string()
|
|
||||||
},
|
|
||||||
self.execs_per_sec()
|
self.execs_per_sec()
|
||||||
);
|
);
|
||||||
(self.print_fn)(fmt);
|
(self.print_fn)(fmt);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user