Fix aggreagator ui (#1693)

* fix

* more

---------

Co-authored-by: Andrea Fioraldi <andreafioraldi@gmail.com>
This commit is contained in:
Dongjia "toka" Zhang 2023-11-24 13:50:57 +01:00 committed by GitHub
parent b4e987a640
commit 16af5debbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 19 deletions

View File

@ -163,6 +163,8 @@ pub enum UserStatsValue {
String(String), String(String),
/// A ratio of two values /// A ratio of two values
Ratio(u64, u64), Ratio(u64, u64),
/// Percent
Percent(f64),
} }
impl UserStatsValue { impl UserStatsValue {
@ -170,7 +172,7 @@ impl UserStatsValue {
#[must_use] #[must_use]
pub fn is_numeric(&self) -> bool { pub fn is_numeric(&self) -> bool {
match &self { match &self {
Self::Number(_) | Self::Float(_) | Self::Ratio(_, _) => true, Self::Number(_) | Self::Float(_) | Self::Ratio(_, _) | Self::Percent(_) => true,
Self::String(_) => false, Self::String(_) => false,
} }
} }
@ -181,7 +183,8 @@ impl UserStatsValue {
match self { match self {
Self::Number(x) => Some(Self::Float(*x as f64 / divisor as f64)), Self::Number(x) => Some(Self::Float(*x as f64 / divisor as f64)),
Self::Float(x) => Some(Self::Float(*x / divisor as f64)), Self::Float(x) => Some(Self::Float(*x / divisor as f64)),
Self::Ratio(x, y) => Some(Self::Float((*x as f64 / divisor as f64) / *y as f64)), Self::Percent(x) => Some(Self::Percent(*x / divisor as f64)),
Self::Ratio(x, y) => Some(Self::Percent((*x as f64 / divisor as f64) / *y as f64)),
Self::String(_) => None, Self::String(_) => None,
} }
} }
@ -208,9 +211,16 @@ impl UserStatsValue {
let first = *x as f64 / *a as f64; let first = *x as f64 / *a as f64;
let second = *y as f64 / *b as f64; let second = *y as f64 / *b as f64;
if first > second { if first > second {
Some(Self::Float(first)) Some(Self::Percent(first))
} else { } else {
Some(Self::Float(second)) Some(Self::Percent(second))
}
}
(Self::Percent(x), Self::Percent(y)) => {
if y > x {
Some(Self::Percent(*y))
} else {
Some(Self::Percent(*x))
} }
} }
_ => None, _ => None,
@ -239,9 +249,16 @@ impl UserStatsValue {
let first = *x as f64 / *a as f64; let first = *x as f64 / *a as f64;
let second = *y as f64 / *b as f64; let second = *y as f64 / *b as f64;
if first > second { if first > second {
Some(Self::Float(second)) Some(Self::Percent(second))
} else { } else {
Some(Self::Float(first)) Some(Self::Percent(first))
}
}
(Self::Percent(x), Self::Percent(y)) => {
if y > x {
Some(Self::Percent(*x))
} else {
Some(Self::Percent(*y))
} }
} }
_ => None, _ => None,
@ -254,10 +271,11 @@ impl UserStatsValue {
match (self, other) { match (self, other) {
(Self::Number(x), Self::Number(y)) => Some(Self::Number(*x + *y)), (Self::Number(x), Self::Number(y)) => Some(Self::Number(*x + *y)),
(Self::Float(x), Self::Float(y)) => Some(Self::Float(*x + *y)), (Self::Float(x), Self::Float(y)) => Some(Self::Float(*x + *y)),
(Self::Percent(x), Self::Percent(y)) => Some(Self::Percent(*x + *y)),
(Self::Ratio(x, a), Self::Ratio(y, b)) => { (Self::Ratio(x, a), Self::Ratio(y, b)) => {
let first = *x as f64 / *a as f64; let first = *x as f64 / *a as f64;
let second = *y as f64 / *b as f64; let second = *y as f64 / *b as f64;
Some(Self::Float(first + second)) Some(Self::Percent(first + second))
} }
_ => None, _ => None,
} }
@ -274,7 +292,8 @@ impl fmt::Display for UserStatsValue {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self { match &self {
UserStatsValue::Number(n) => write!(f, "{n}"), UserStatsValue::Number(n) => write!(f, "{n}"),
UserStatsValue::Float(n) => write!(f, "{n}"), UserStatsValue::Float(n) => write!(f, "{}", prettify_float(*n)),
UserStatsValue::Percent(n) => write!(f, "{:.3}%", n * 100.0),
UserStatsValue::String(s) => write!(f, "{s}"), UserStatsValue::String(s) => write!(f, "{s}"),
UserStatsValue::Ratio(a, b) => { UserStatsValue::Ratio(a, b) => {
if *b == 0 { if *b == 0 {

View File

@ -74,7 +74,7 @@ where
String::new() String::new()
}; };
let head = format!("{event_msg}{pad} {sender}"); let head = format!("{event_msg}{pad} {sender}");
let global_fmt = format!( let mut global_fmt = format!(
"[{}] (GLOBAL) run time: {}, clients: {}, corpus: {}, objectives: {}, executions: {}, exec/sec: {}", "[{}] (GLOBAL) run time: {}, clients: {}, corpus: {}, objectives: {}, executions: {}, exec/sec: {}",
head, head,
format_duration_hms(&(current_time() - self.start_time)), format_duration_hms(&(current_time() - self.start_time)),
@ -84,6 +84,12 @@ where
self.total_execs(), self.total_execs(),
self.execs_per_sec_pretty() self.execs_per_sec_pretty()
); );
let mut aggregated_fmt = " (Aggregated):".to_string();
for (key, val) in &self.aggregator.aggregated {
write!(aggregated_fmt, " {key}: {val}").unwrap();
}
write!(global_fmt, "{aggregated_fmt}").unwrap();
(self.print_fn)(global_fmt); (self.print_fn)(global_fmt);
self.client_stats_insert(sender_id); self.client_stats_insert(sender_id);
@ -101,12 +107,6 @@ where
} }
(self.print_fn)(fmt); (self.print_fn)(fmt);
let mut aggregated_fmt = "(Aggregated): ".to_string();
for (key, val) in &self.aggregator.aggregated {
write!(aggregated_fmt, " {key}: {val}").unwrap();
}
(self.print_fn)(aggregated_fmt);
// Only print perf monitor if the feature is enabled // Only print perf monitor if the feature is enabled
#[cfg(feature = "introspection")] #[cfg(feature = "introspection")]
{ {

View File

@ -178,6 +178,7 @@ where
UserStatsValue::Float(f) => *f, UserStatsValue::Float(f) => *f,
UserStatsValue::String(_s) => 0.0, UserStatsValue::String(_s) => 0.0,
UserStatsValue::Ratio(a, b) => (*a as f64 / *b as f64) * 100.0, UserStatsValue::Ratio(a, b) => (*a as f64 / *b as f64) * 100.0,
UserStatsValue::Percent(p) => *p * 100.0,
}; };
self.custom_stat self.custom_stat
.get_or_create(&Labels { .get_or_create(&Labels {

View File

@ -84,10 +84,6 @@ llmp_small_maps = ["alloc"]
[build-dependencies] [build-dependencies]
rustversion = "1.0" rustversion = "1.0"
[dev-dependencies]
# clippy-suggested optimised byte counter
bytecount = "0.6.3"
[dependencies] [dependencies]
libafl_derive = { version = "0.11.1", optional = true, path = "../libafl_derive" } libafl_derive = { version = "0.11.1", optional = true, path = "../libafl_derive" }