diff --git a/libafl/Cargo.toml b/libafl/Cargo.toml index ed37ce0fe4..02d9762715 100644 --- a/libafl/Cargo.toml +++ b/libafl/Cargo.toml @@ -44,6 +44,7 @@ num_cpus = "1.0" # cpu count, for llmp example serial_test = "0.5" [dependencies] +time = { version = "0.3.5", default-features = false, features = ["alloc"] } tuple_list = { version = "0.1.3" } hashbrown = { version = "0.11", features = ["serde", "ahash-compile-time-rng"], default-features=false } # A faster hashmap, nostd compatible num-traits = { version = "0.2", default-features = false } diff --git a/libafl/src/bolts/mod.rs b/libafl/src/bolts/mod.rs index 0c1f0c9221..68b2a9f939 100644 --- a/libafl/src/bolts/mod.rs +++ b/libafl/src/bolts/mod.rs @@ -20,6 +20,7 @@ pub mod shmem; pub mod staterestore; pub mod tuples; +use alloc::string::String; use core::time; #[cfg(feature = "std")] use std::time::{SystemTime, UNIX_EPOCH}; @@ -85,3 +86,9 @@ pub fn current_nanos() -> u64 { pub fn current_milliseconds() -> u64 { current_time().as_millis() as u64 } + +/// Format a `Duration` into a HMS string +pub fn format_duration_hms(duration: &time::Duration) -> String { + let secs = duration.as_secs(); + format!("{}h-{}m-{}s", (secs / 60) / 60, (secs / 60) % 60, secs % 60) +} diff --git a/libafl/src/monitors/mod.rs b/libafl/src/monitors/mod.rs index 476a4cb22a..7a7c47aa32 100644 --- a/libafl/src/monitors/mod.rs +++ b/libafl/src/monitors/mod.rs @@ -13,7 +13,7 @@ use hashbrown::HashMap; #[cfg(feature = "introspection")] use alloc::string::ToString; -use crate::bolts::current_time; +use crate::bolts::{current_time, format_duration_hms}; const CLIENT_STATS_TIME_WINDOW_SECS: u64 = 5; // 5 seconds @@ -269,10 +269,10 @@ where fn display(&mut self, event_msg: String, sender_id: u32) { let fmt = format!( - "{}: [{} #{}] clients: {}, corpus: {}, objectives: {}, executions: {}, exec/sec: {}", - (current_time() - self.start_time).as_millis(), + "[{} #{}] run time: {}, clients: {}, corpus: {}, objectives: {}, executions: {}, exec/sec: {}", event_msg, sender_id, + format_duration_hms(&(current_time() - self.start_time)), self.client_stats().len(), self.corpus_size(), self.objective_size(), diff --git a/libafl/src/monitors/multi.rs b/libafl/src/monitors/multi.rs index c767800b4f..5f4dbab134 100644 --- a/libafl/src/monitors/multi.rs +++ b/libafl/src/monitors/multi.rs @@ -7,7 +7,7 @@ use core::{time, time::Duration}; use alloc::string::ToString; use crate::{ - bolts::current_time, + bolts::{current_time, format_duration_hms}, monitors::{ClientStats, Monitor}, }; @@ -50,8 +50,9 @@ where }; let head = format!("{}{} {}", event_msg, pad, sender); let global_fmt = format!( - "[{}] (GLOBAL) clients: {}, corpus: {}, objectives: {}, executions: {}, exec/sec: {}", + "[{}] (GLOBAL) run time: {}, clients: {}, corpus: {}, objectives: {}, executions: {}, exec/sec: {}", head, + format_duration_hms(&(current_time() - self.start_time)), self.client_stats().len(), self.corpus_size(), self.objective_size(), diff --git a/libafl/src/stages/sync.rs b/libafl/src/stages/sync.rs index 69708e10f3..b3d29feef8 100644 --- a/libafl/src/stages/sync.rs +++ b/libafl/src/stages/sync.rs @@ -19,9 +19,6 @@ use crate::{ Error, }; -#[cfg(feature = "introspection")] -use crate::monitors::PerfFeature; - #[derive(Serialize, Deserialize)] pub struct SyncFromDiskMetadata { pub last_time: SystemTime,