diff --git a/libafl/src/stats/mod.rs b/libafl/src/stats/mod.rs index 709ecccda5..876a222e8c 100644 --- a/libafl/src/stats/mod.rs +++ b/libafl/src/stats/mod.rs @@ -688,6 +688,32 @@ impl ClientPerfStats { // Set that the current stage is being used self.stages_used[stage_index] = true; } + + pub fn elapsed_cycles(&self) -> u64 { + self.current_time - self.start_time + } + + pub fn manager_cycles(&self) -> u64 { + self.manager + } + + pub fn scheduler_cycles(&self) -> u64 { + self.scheduler + } + + pub fn used_stages( + &self, + ) -> impl Iterator { + let used = self.stages_used.clone(); + self.stages + .iter() + .enumerate() + .filter(move |(stage_index, _)| used[*stage_index as usize]) + } + + pub fn feedbacks(&self) -> impl Iterator { + self.feedbacks.iter().enumerate() + } } #[cfg(feature = "introspection")] @@ -695,7 +721,7 @@ impl core::fmt::Display for ClientPerfStats { #[allow(clippy::cast_precision_loss)] fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> { // Calculate the elapsed time from the stats - let elapsed: f64 = (self.current_time - self.start_time) as f64; + let elapsed: f64 = self.elapsed_cycles() as f64; // Calculate the percentages for each benchmark let scheduler_percent = self.scheduler as f64 / elapsed; @@ -714,12 +740,8 @@ impl core::fmt::Display for ClientPerfStats { )?; // Calculate each stage - for (stage_index, features) in self.stages.iter().enumerate() { - // Make sure this stage is actually used before dumping its information - if !self.stages_used[stage_index as usize] { - continue; - } - + // Make sure we only iterate over used stages + for (stage_index, features) in self.used_stages() { // Write the stage header writeln!(f, " Stage {}:", stage_index)?; @@ -742,7 +764,7 @@ impl core::fmt::Display for ClientPerfStats { writeln!(f, " {:6.4}: {:?}", feature_percent, feature)?; } - for (feedback_index, feedback) in self.feedbacks.iter().enumerate() { + for (feedback_index, feedback) in self.feedbacks() { // Calculate this current stage's percentage let feedback_percent = *feedback as f64 / elapsed;